924b6431eb2ba42744acb4add590c171dff73d52
[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.net.URL;
32 import java.util.ArrayList;
33 import java.util.Date;
34 import java.util.HashSet;
35 import java.util.Iterator;
36 import java.util.List;
37 import java.util.Locale;
38 import java.util.Set;
39 import java.util.SortedSet;
40
41 import org.forester.application.support_transfer;
42 import org.forester.archaeopteryx.TreePanelUtil;
43 import org.forester.archaeopteryx.webservices.WebserviceUtil;
44 import org.forester.development.DevelopmentTools;
45 import org.forester.evoinference.TestPhylogenyReconstruction;
46 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
47 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
48 import org.forester.go.TestGo;
49 import org.forester.io.parsers.FastaParser;
50 import org.forester.io.parsers.GeneralMsaParser;
51 import org.forester.io.parsers.HmmscanPerDomainTableParser;
52 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
53 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
54 import org.forester.io.parsers.nexus.NexusCharactersParser;
55 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
56 import org.forester.io.parsers.nhx.NHXParser;
57 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
58 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
59 import org.forester.io.parsers.tol.TolParser;
60 import org.forester.io.parsers.util.ParserUtils;
61 import org.forester.io.writers.PhylogenyWriter;
62 import org.forester.io.writers.SequenceWriter;
63 import org.forester.msa.BasicMsa;
64 import org.forester.msa.Mafft;
65 import org.forester.msa.Msa;
66 import org.forester.msa.MsaInferrer;
67 import org.forester.msa.MsaMethods;
68 import org.forester.pccx.TestPccx;
69 import org.forester.phylogeny.Phylogeny;
70 import org.forester.phylogeny.PhylogenyBranch;
71 import org.forester.phylogeny.PhylogenyMethods;
72 import org.forester.phylogeny.PhylogenyNode;
73 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
74 import org.forester.phylogeny.data.Accession;
75 import org.forester.phylogeny.data.Accession.Source;
76 import org.forester.phylogeny.data.BinaryCharacters;
77 import org.forester.phylogeny.data.BranchWidth;
78 import org.forester.phylogeny.data.Confidence;
79 import org.forester.phylogeny.data.Distribution;
80 import org.forester.phylogeny.data.DomainArchitecture;
81 import org.forester.phylogeny.data.Event;
82 import org.forester.phylogeny.data.Identifier;
83 import org.forester.phylogeny.data.PhylogenyData;
84 import org.forester.phylogeny.data.PhylogenyDataUtil;
85 import org.forester.phylogeny.data.Polygon;
86 import org.forester.phylogeny.data.PropertiesMap;
87 import org.forester.phylogeny.data.Property;
88 import org.forester.phylogeny.data.Property.AppliesTo;
89 import org.forester.phylogeny.data.ProteinDomain;
90 import org.forester.phylogeny.data.Taxonomy;
91 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
92 import org.forester.phylogeny.factories.PhylogenyFactory;
93 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
94 import org.forester.protein.BasicDomain;
95 import org.forester.protein.BasicProtein;
96 import org.forester.protein.Domain;
97 import org.forester.protein.Protein;
98 import org.forester.protein.ProteinId;
99 import org.forester.rio.TestRIO;
100 import org.forester.sdi.SDI;
101 import org.forester.sdi.SDIR;
102 import org.forester.sdi.TestGSDI;
103 import org.forester.sequence.BasicSequence;
104 import org.forester.sequence.Sequence;
105 import org.forester.species.BasicSpecies;
106 import org.forester.species.Species;
107 import org.forester.surfacing.TestSurfacing;
108 import org.forester.tools.ConfidenceAssessor;
109 import org.forester.tools.SupportCount;
110 import org.forester.tools.TreeSplitMatrix;
111 import org.forester.util.AsciiHistogram;
112 import org.forester.util.BasicDescriptiveStatistics;
113 import org.forester.util.BasicTable;
114 import org.forester.util.BasicTableParser;
115 import org.forester.util.DescriptiveStatistics;
116 import org.forester.util.ForesterConstants;
117 import org.forester.util.ForesterUtil;
118 import org.forester.util.GeneralTable;
119 import org.forester.util.SequenceAccessionTools;
120 import org.forester.ws.seqdb.SequenceDatabaseEntry;
121 import org.forester.ws.seqdb.SequenceDbWsTools;
122 import org.forester.ws.seqdb.UniProtTaxonomy;
123 import org.forester.ws.wabi.TxSearch;
124 import org.forester.ws.wabi.TxSearch.RANKS;
125 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
126 import org.forester.ws.wabi.TxSearch.TAX_RANK;
127
128 @SuppressWarnings( "unused")
129 public final class Test {
130
131     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
132                                                                    + ForesterUtil.getFileSeparator() + "resources"
133                                                                    + ForesterUtil.getFileSeparator();
134     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
135                                                                    + ForesterUtil.getFileSeparator() + "test_data"
136                                                                    + ForesterUtil.getFileSeparator();
137     private final static boolean PERFORM_DB_TESTS          = false;
138     private static final boolean PERFORM_WEB_TREE_ACCESS   = true;
139     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
140                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
141                                                                    + ForesterConstants.PHYLO_XML_XSD;
142     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
143                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
144                                                                    + ForesterConstants.PHYLO_XML_XSD;
145     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
146     private final static double  ZERO_DIFF                 = 1.0E-9;
147
148     public static boolean isEqual( final double a, final double b ) {
149         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
150     }
151
152     public static void main( final String[] args ) {
153         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
154         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
155                 + "]" );
156         Locale.setDefault( Locale.US );
157         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
158         int failed = 0;
159         int succeeded = 0;
160         System.out.print( "[Test if directory with files for testing exists/is readable: " );
161         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
162             System.out.println( "OK.]" );
163         }
164         else {
165             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
166             System.out.println( "Testing aborted." );
167             System.exit( -1 );
168         }
169         System.out.print( "[Test if resources directory exists/is readable: " );
170         if ( testDir( PATH_TO_RESOURCES ) ) {
171             System.out.println( "OK.]" );
172         }
173         else {
174             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
175             System.out.println( "Testing aborted." );
176             System.exit( -1 );
177         }
178         final long start_time = new Date().getTime();
179         System.out.print( "Basic node methods: " );
180         if ( Test.testBasicNodeMethods() ) {
181             System.out.println( "OK." );
182             succeeded++;
183         }
184         else {
185             System.out.println( "failed." );
186             failed++;
187         }
188         System.out.print( "Protein id: " );
189         if ( !testProteinId() ) {
190             System.out.println( "failed." );
191             failed++;
192         }
193         else {
194             succeeded++;
195         }
196         System.out.println( "OK." );
197         System.out.print( "Species: " );
198         if ( !testSpecies() ) {
199             System.out.println( "failed." );
200             failed++;
201         }
202         else {
203             succeeded++;
204         }
205         System.out.println( "OK." );
206         System.out.print( "Basic domain: " );
207         if ( !testBasicDomain() ) {
208             System.out.println( "failed." );
209             failed++;
210         }
211         else {
212             succeeded++;
213         }
214         System.out.println( "OK." );
215         System.out.print( "Basic protein: " );
216         if ( !testBasicProtein() ) {
217             System.out.println( "failed." );
218             failed++;
219         }
220         else {
221             succeeded++;
222         }
223         System.out.println( "OK." );
224         System.out.print( "Sequence writer: " );
225         if ( testSequenceWriter() ) {
226             System.out.println( "OK." );
227             succeeded++;
228         }
229         else {
230             System.out.println( "failed." );
231             failed++;
232         }
233         System.out.print( "Sequence id parsing: " );
234         if ( testSequenceIdParsing() ) {
235             System.out.println( "OK." );
236             succeeded++;
237         }
238         else {
239             System.out.println( "failed." );
240             failed++;
241         }
242         System.out.print( "UniProtKB id extraction: " );
243         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
244             System.out.println( "OK." );
245             succeeded++;
246         }
247         else {
248             System.out.println( "failed." );
249             failed++;
250         }
251         System.out.print( "Sequence DB tools 1: " );
252         if ( testSequenceDbWsTools1() ) {
253             System.out.println( "OK." );
254             succeeded++;
255         }
256         else {
257             System.out.println( "failed." );
258             failed++;
259         }
260         System.out.print( "Hmmscan output parser: " );
261         if ( testHmmscanOutputParser() ) {
262             System.out.println( "OK." );
263             succeeded++;
264         }
265         else {
266             System.out.println( "failed." );
267             failed++;
268         }
269         System.out.print( "Overlap removal: " );
270         if ( !org.forester.test.Test.testOverlapRemoval() ) {
271             System.out.println( "failed." );
272             failed++;
273         }
274         else {
275             succeeded++;
276         }
277         System.out.println( "OK." );
278         System.out.print( "Engulfing overlap removal: " );
279         if ( !Test.testEngulfingOverlapRemoval() ) {
280             System.out.println( "failed." );
281             failed++;
282         }
283         else {
284             succeeded++;
285         }
286         System.out.println( "OK." );
287         System.out.print( "Taxonomy code extraction: " );
288         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
289             System.out.println( "OK." );
290             succeeded++;
291         }
292         else {
293             System.out.println( "failed." );
294             failed++;
295         }
296         System.out.print( "SN extraction: " );
297         if ( Test.testExtractSNFromNodeName() ) {
298             System.out.println( "OK." );
299             succeeded++;
300         }
301         else {
302             System.out.println( "failed." );
303             failed++;
304         }
305         System.out.print( "Taxonomy extraction (general): " );
306         if ( Test.testTaxonomyExtraction() ) {
307             System.out.println( "OK." );
308             succeeded++;
309         }
310         else {
311             System.out.println( "failed." );
312             failed++;
313         }
314         System.out.print( "Uri for Aptx web sequence accession: " );
315         if ( Test.testCreateUriForSeqWeb() ) {
316             System.out.println( "OK." );
317             succeeded++;
318         }
319         else {
320             System.out.println( "failed." );
321             failed++;
322         }
323         System.out.print( "Basic node construction and parsing of NHX (node level): " );
324         if ( Test.testNHXNodeParsing() ) {
325             System.out.println( "OK." );
326             succeeded++;
327         }
328         else {
329             System.out.println( "failed." );
330             failed++;
331         }
332         System.out.print( "NHX parsing iterating: " );
333         if ( Test.testNHParsingIter() ) {
334             System.out.println( "OK." );
335             succeeded++;
336         }
337         else {
338             System.out.println( "failed." );
339             failed++;
340         }
341         System.out.print( "NH parsing: " );
342         if ( Test.testNHParsing() ) {
343             System.out.println( "OK." );
344             succeeded++;
345         }
346         else {
347             System.out.println( "failed." );
348             failed++;
349         }
350         System.out.print( "Conversion to NHX (node level): " );
351         if ( Test.testNHXconversion() ) {
352             System.out.println( "OK." );
353             succeeded++;
354         }
355         else {
356             System.out.println( "failed." );
357             failed++;
358         }
359         System.out.print( "NHX parsing: " );
360         if ( Test.testNHXParsing() ) {
361             System.out.println( "OK." );
362             succeeded++;
363         }
364         else {
365             System.out.println( "failed." );
366             failed++;
367         }
368         System.out.print( "NHX parsing with quotes: " );
369         if ( Test.testNHXParsingQuotes() ) {
370             System.out.println( "OK." );
371             succeeded++;
372         }
373         else {
374             System.out.println( "failed." );
375             failed++;
376         }
377         System.out.print( "NHX parsing (MrBayes): " );
378         if ( Test.testNHXParsingMB() ) {
379             System.out.println( "OK." );
380             succeeded++;
381         }
382         else {
383             System.out.println( "failed." );
384             failed++;
385         }
386         System.out.print( "Nexus characters parsing: " );
387         if ( Test.testNexusCharactersParsing() ) {
388             System.out.println( "OK." );
389             succeeded++;
390         }
391         else {
392             System.out.println( "failed." );
393             failed++;
394         }
395         System.out.print( "Nexus tree parsing iterating: " );
396         if ( Test.testNexusTreeParsingIterating() ) {
397             System.out.println( "OK." );
398             succeeded++;
399         }
400         else {
401             System.out.println( "failed." );
402             failed++;
403         }
404         System.out.print( "Nexus tree parsing: " );
405         if ( Test.testNexusTreeParsing() ) {
406             System.out.println( "OK." );
407             succeeded++;
408         }
409         else {
410             System.out.println( "failed." );
411             failed++;
412         }
413         System.out.print( "Nexus tree parsing (translating): " );
414         if ( Test.testNexusTreeParsingTranslating() ) {
415             System.out.println( "OK." );
416             succeeded++;
417         }
418         else {
419             System.out.println( "failed." );
420             failed++;
421         }
422         System.out.print( "Nexus matrix parsing: " );
423         if ( Test.testNexusMatrixParsing() ) {
424             System.out.println( "OK." );
425             succeeded++;
426         }
427         else {
428             System.out.println( "failed." );
429             failed++;
430         }
431         System.out.print( "Basic phyloXML parsing: " );
432         if ( Test.testBasicPhyloXMLparsing() ) {
433             System.out.println( "OK." );
434             succeeded++;
435         }
436         else {
437             System.out.println( "failed." );
438             failed++;
439         }
440         System.out.print( "Basic phyloXML parsing (validating against schema): " );
441         if ( testBasicPhyloXMLparsingValidating() ) {
442             System.out.println( "OK." );
443             succeeded++;
444         }
445         else {
446             System.out.println( "failed." );
447             failed++;
448         }
449         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
450         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
451             System.out.println( "OK." );
452             succeeded++;
453         }
454         else {
455             System.out.println( "failed." );
456             failed++;
457         }
458         System.out.print( "phyloXML Distribution Element: " );
459         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
460             System.out.println( "OK." );
461             succeeded++;
462         }
463         else {
464             System.out.println( "failed." );
465             failed++;
466         }
467         System.out.print( "Tol XML parsing: " );
468         if ( Test.testBasicTolXMLparsing() ) {
469             System.out.println( "OK." );
470             succeeded++;
471         }
472         else {
473             System.out.println( "failed." );
474             failed++;
475         }
476         System.out.print( "Copying of node data: " );
477         if ( Test.testCopyOfNodeData() ) {
478             System.out.println( "OK." );
479             succeeded++;
480         }
481         else {
482             System.out.println( "failed." );
483             failed++;
484         }
485         System.out.print( "Tree copy: " );
486         if ( Test.testTreeCopy() ) {
487             System.out.println( "OK." );
488             succeeded++;
489         }
490         else {
491             System.out.println( "failed." );
492             failed++;
493         }
494         System.out.print( "Basic tree methods: " );
495         if ( Test.testBasicTreeMethods() ) {
496             System.out.println( "OK." );
497             succeeded++;
498         }
499         else {
500             System.out.println( "failed." );
501             failed++;
502         }
503         System.out.print( "Tree methods: " );
504         if ( Test.testTreeMethods() ) {
505             System.out.println( "OK." );
506             succeeded++;
507         }
508         else {
509             System.out.println( "failed." );
510             failed++;
511         }
512         System.out.print( "Postorder Iterator: " );
513         if ( Test.testPostOrderIterator() ) {
514             System.out.println( "OK." );
515             succeeded++;
516         }
517         else {
518             System.out.println( "failed." );
519             failed++;
520         }
521         System.out.print( "Preorder Iterator: " );
522         if ( Test.testPreOrderIterator() ) {
523             System.out.println( "OK." );
524             succeeded++;
525         }
526         else {
527             System.out.println( "failed." );
528             failed++;
529         }
530         System.out.print( "Levelorder Iterator: " );
531         if ( Test.testLevelOrderIterator() ) {
532             System.out.println( "OK." );
533             succeeded++;
534         }
535         else {
536             System.out.println( "failed." );
537             failed++;
538         }
539         System.out.print( "Re-id methods: " );
540         if ( Test.testReIdMethods() ) {
541             System.out.println( "OK." );
542             succeeded++;
543         }
544         else {
545             System.out.println( "failed." );
546             failed++;
547         }
548         System.out.print( "Methods on last external nodes: " );
549         if ( Test.testLastExternalNodeMethods() ) {
550             System.out.println( "OK." );
551             succeeded++;
552         }
553         else {
554             System.out.println( "failed." );
555             failed++;
556         }
557         System.out.print( "Methods on external nodes: " );
558         if ( Test.testExternalNodeRelatedMethods() ) {
559             System.out.println( "OK." );
560             succeeded++;
561         }
562         else {
563             System.out.println( "failed." );
564             failed++;
565         }
566         System.out.print( "Deletion of external nodes: " );
567         if ( Test.testDeletionOfExternalNodes() ) {
568             System.out.println( "OK." );
569             succeeded++;
570         }
571         else {
572             System.out.println( "failed." );
573             failed++;
574         }
575         System.out.print( "Subtree deletion: " );
576         if ( Test.testSubtreeDeletion() ) {
577             System.out.println( "OK." );
578             succeeded++;
579         }
580         else {
581             System.out.println( "failed." );
582             failed++;
583         }
584         System.out.print( "Phylogeny branch: " );
585         if ( Test.testPhylogenyBranch() ) {
586             System.out.println( "OK." );
587             succeeded++;
588         }
589         else {
590             System.out.println( "failed." );
591             failed++;
592         }
593         System.out.print( "Rerooting: " );
594         if ( Test.testRerooting() ) {
595             System.out.println( "OK." );
596             succeeded++;
597         }
598         else {
599             System.out.println( "failed." );
600             failed++;
601         }
602         System.out.print( "Mipoint rooting: " );
603         if ( Test.testMidpointrooting() ) {
604             System.out.println( "OK." );
605             succeeded++;
606         }
607         else {
608             System.out.println( "failed." );
609             failed++;
610         }
611         System.out.print( "Node removal: " );
612         if ( Test.testNodeRemoval() ) {
613             System.out.println( "OK." );
614             succeeded++;
615         }
616         else {
617             System.out.println( "failed." );
618             failed++;
619         }
620         System.out.print( "Support count: " );
621         if ( Test.testSupportCount() ) {
622             System.out.println( "OK." );
623             succeeded++;
624         }
625         else {
626             System.out.println( "failed." );
627             failed++;
628         }
629         System.out.print( "Support transfer: " );
630         if ( Test.testSupportTransfer() ) {
631             System.out.println( "OK." );
632             succeeded++;
633         }
634         else {
635             System.out.println( "failed." );
636             failed++;
637         }
638         System.out.print( "Finding of LCA: " );
639         if ( Test.testGetLCA() ) {
640             System.out.println( "OK." );
641             succeeded++;
642         }
643         else {
644             System.out.println( "failed." );
645             failed++;
646         }
647         System.out.print( "Finding of LCA 2: " );
648         if ( Test.testGetLCA2() ) {
649             System.out.println( "OK." );
650             succeeded++;
651         }
652         else {
653             System.out.println( "failed." );
654             failed++;
655         }
656         System.out.print( "Calculation of distance between nodes: " );
657         if ( Test.testGetDistance() ) {
658             System.out.println( "OK." );
659             succeeded++;
660         }
661         else {
662             System.out.println( "failed." );
663             failed++;
664         }
665         System.out.print( "Descriptive statistics: " );
666         if ( Test.testDescriptiveStatistics() ) {
667             System.out.println( "OK." );
668             succeeded++;
669         }
670         else {
671             System.out.println( "failed." );
672             failed++;
673         }
674         System.out.print( "Data objects and methods: " );
675         if ( Test.testDataObjects() ) {
676             System.out.println( "OK." );
677             succeeded++;
678         }
679         else {
680             System.out.println( "failed." );
681             failed++;
682         }
683         System.out.print( "Properties map: " );
684         if ( Test.testPropertiesMap() ) {
685             System.out.println( "OK." );
686             succeeded++;
687         }
688         else {
689             System.out.println( "failed." );
690             failed++;
691         }
692         System.out.print( "SDIse: " );
693         if ( Test.testSDIse() ) {
694             System.out.println( "OK." );
695             succeeded++;
696         }
697         else {
698             System.out.println( "failed." );
699             failed++;
700         }
701         System.out.print( "SDIunrooted: " );
702         if ( Test.testSDIunrooted() ) {
703             System.out.println( "OK." );
704             succeeded++;
705         }
706         else {
707             System.out.println( "failed." );
708             failed++;
709         }
710         System.out.print( "GSDI: " );
711         if ( TestGSDI.test() ) {
712             System.out.println( "OK." );
713             succeeded++;
714         }
715         else {
716             System.out.println( "failed." );
717             failed++;
718         }
719         System.out.print( "RIO: " );
720         if ( TestRIO.test() ) {
721             System.out.println( "OK." );
722             succeeded++;
723         }
724         else {
725             System.out.println( "failed." );
726             failed++;
727         }
728         System.out.print( "Phylogeny reconstruction:" );
729         System.out.println();
730         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
731             System.out.println( "OK." );
732             succeeded++;
733         }
734         else {
735             System.out.println( "failed." );
736             failed++;
737         }
738         System.out.print( "Analysis of domain architectures: " );
739         System.out.println();
740         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
741             System.out.println( "OK." );
742             succeeded++;
743         }
744         else {
745             System.out.println( "failed." );
746             failed++;
747         }
748         System.out.print( "GO: " );
749         System.out.println();
750         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
751             System.out.println( "OK." );
752             succeeded++;
753         }
754         else {
755             System.out.println( "failed." );
756             failed++;
757         }
758         System.out.print( "Modeling tools: " );
759         if ( TestPccx.test() ) {
760             System.out.println( "OK." );
761             succeeded++;
762         }
763         else {
764             System.out.println( "failed." );
765             failed++;
766         }
767         System.out.print( "Split Matrix strict: " );
768         if ( Test.testSplitStrict() ) {
769             System.out.println( "OK." );
770             succeeded++;
771         }
772         else {
773             System.out.println( "failed." );
774             failed++;
775         }
776         System.out.print( "Split Matrix: " );
777         if ( Test.testSplit() ) {
778             System.out.println( "OK." );
779             succeeded++;
780         }
781         else {
782             System.out.println( "failed." );
783             failed++;
784         }
785         System.out.print( "Confidence Assessor: " );
786         if ( Test.testConfidenceAssessor() ) {
787             System.out.println( "OK." );
788             succeeded++;
789         }
790         else {
791             System.out.println( "failed." );
792             failed++;
793         }
794         System.out.print( "Basic table: " );
795         if ( Test.testBasicTable() ) {
796             System.out.println( "OK." );
797             succeeded++;
798         }
799         else {
800             System.out.println( "failed." );
801             failed++;
802         }
803         System.out.print( "General table: " );
804         if ( Test.testGeneralTable() ) {
805             System.out.println( "OK." );
806             succeeded++;
807         }
808         else {
809             System.out.println( "failed." );
810             failed++;
811         }
812         System.out.print( "Amino acid sequence: " );
813         if ( Test.testAminoAcidSequence() ) {
814             System.out.println( "OK." );
815             succeeded++;
816         }
817         else {
818             System.out.println( "failed." );
819             failed++;
820         }
821         System.out.print( "General MSA parser: " );
822         if ( Test.testGeneralMsaParser() ) {
823             System.out.println( "OK." );
824             succeeded++;
825         }
826         else {
827             System.out.println( "failed." );
828             failed++;
829         }
830         System.out.print( "Fasta parser for msa: " );
831         if ( Test.testFastaParser() ) {
832             System.out.println( "OK." );
833             succeeded++;
834         }
835         else {
836             System.out.println( "failed." );
837             failed++;
838         }
839         System.out.print( "Creation of balanced phylogeny: " );
840         if ( Test.testCreateBalancedPhylogeny() ) {
841             System.out.println( "OK." );
842             succeeded++;
843         }
844         else {
845             System.out.println( "failed." );
846             failed++;
847         }
848         System.out.print( "Genbank accessor parsing: " );
849         if ( Test.testGenbankAccessorParsing() ) {
850             System.out.println( "OK." );
851             succeeded++;
852         }
853         else {
854             System.out.println( "failed." );
855             failed++;
856         }
857         String path = "";
858         final String os = ForesterUtil.OS_NAME.toLowerCase();
859         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
860             path = "/usr/local/bin/mafft";
861         }
862         else if ( os.indexOf( "win" ) >= 0 ) {
863             path = "C:\\Program Files\\mafft-win\\mafft.bat";
864         }
865         else {
866             path = "mafft";
867             if ( !MsaInferrer.isInstalled( path ) ) {
868                 path = "/usr/bin/mafft";
869             }
870             if ( !MsaInferrer.isInstalled( path ) ) {
871                 path = "/usr/local/bin/mafft";
872             }
873         }
874         if ( MsaInferrer.isInstalled( path ) ) {
875             System.out.print( "MAFFT (external program): " );
876             if ( Test.testMafft( path ) ) {
877                 System.out.println( "OK." );
878                 succeeded++;
879             }
880             else {
881                 System.out.println( "failed [will not count towards failed tests]" );
882             }
883         }
884         System.out.print( "Next nodes with collapsed: " );
885         if ( Test.testNextNodeWithCollapsing() ) {
886             System.out.println( "OK." );
887             succeeded++;
888         }
889         else {
890             System.out.println( "failed." );
891             failed++;
892         }
893         System.out.print( "Simple MSA quality: " );
894         if ( Test.testMsaQualityMethod() ) {
895             System.out.println( "OK." );
896             succeeded++;
897         }
898         else {
899             System.out.println( "failed." );
900             failed++;
901         }
902         if ( PERFORM_DB_TESTS ) {
903             System.out.print( "Uniprot Entry Retrieval: " );
904             if ( Test.testUniprotEntryRetrieval() ) {
905                 System.out.println( "OK." );
906                 succeeded++;
907             }
908             else {
909                 System.out.println( "failed." );
910                 failed++;
911             }
912             System.out.print( "Ebi Entry Retrieval: " );
913             if ( Test.testEbiEntryRetrieval() ) {
914                 System.out.println( "OK." );
915                 succeeded++;
916             }
917             else {
918                 System.out.println( "failed." );
919                 failed++;
920             }
921             System.out.print( "Sequence DB tools 2: " );
922             if ( testSequenceDbWsTools2() ) {
923                 System.out.println( "OK." );
924                 succeeded++;
925             }
926             else {
927                 System.out.println( "failed." );
928                 failed++;
929                 System.exit( -1 );
930             }
931             System.out.print( "Uniprot Taxonomy Search: " );
932             if ( Test.testUniprotTaxonomySearch() ) {
933                 System.out.println( "OK." );
934                 succeeded++;
935             }
936             else {
937                 System.out.println( "failed." );
938                 failed++;
939             }
940         }
941         if ( PERFORM_WEB_TREE_ACCESS ) {
942             System.out.print( "NHX parsing from URL: " );
943             if ( Test.testNHXparsingFromURL() ) {
944                 System.out.println( "OK." );
945                 succeeded++;
946             }
947             else {
948                 System.out.println( "failed." );
949                 failed++;
950             }
951             System.out.print( "phyloXML parsing from URL: " );
952             if ( Test.testPhyloXMLparsingFromURL() ) {
953                 System.out.println( "OK." );
954                 succeeded++;
955             }
956             else {
957                 System.out.println( "failed." );
958                 failed++;
959             }
960             System.out.print( "TreeBase acccess: " );
961             if ( Test.testTreeBaseReading() ) {
962                 System.out.println( "OK." );
963                 succeeded++;
964             }
965             else {
966                 System.out.println( "failed." );
967                 failed++;
968             }
969             //
970             System.out.print( "ToL access: " );
971             if ( Test.testToLReading() ) {
972                 System.out.println( "OK." );
973                 succeeded++;
974             }
975             else {
976                 System.out.println( "failed." );
977                 failed++;
978             }
979             //
980             System.out.print( "TreeFam access: " );
981             if ( Test.testTreeFamReading() ) {
982                 System.out.println( "OK." );
983                 succeeded++;
984             }
985             else {
986                 System.out.println( "failed." );
987                 failed++;
988             }
989             //
990             //
991             System.out.print( "Pfam tree access: " );
992             if ( Test.testPfamTreeReading() ) {
993                 System.out.println( "OK." );
994                 succeeded++;
995             }
996             else {
997                 System.out.println( "failed." );
998                 failed++;
999             }
1000         }
1001         System.out.println();
1002         final Runtime rt = java.lang.Runtime.getRuntime();
1003         final long free_memory = rt.freeMemory() / 1000000;
1004         final long total_memory = rt.totalMemory() / 1000000;
1005         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1006                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1007         System.out.println();
1008         System.out.println( "Successful tests: " + succeeded );
1009         System.out.println( "Failed     tests: " + failed );
1010         System.out.println();
1011         if ( failed < 1 ) {
1012             System.out.println( "OK." );
1013         }
1014         else {
1015             System.out.println( "Not OK." );
1016         }
1017     }
1018
1019     public static boolean testEngulfingOverlapRemoval() {
1020         try {
1021             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1022             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1023             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1024             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1025             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1026             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1027             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1028             final List<Boolean> covered = new ArrayList<Boolean>();
1029             covered.add( true ); // 0
1030             covered.add( false ); // 1
1031             covered.add( true ); // 2
1032             covered.add( false ); // 3
1033             covered.add( true ); // 4
1034             covered.add( true ); // 5
1035             covered.add( false ); // 6
1036             covered.add( true ); // 7
1037             covered.add( true ); // 8
1038             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1039                 return false;
1040             }
1041             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1042                 return false;
1043             }
1044             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1045                 return false;
1046             }
1047             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1048                 return false;
1049             }
1050             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1051                 return false;
1052             }
1053             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1054                 return false;
1055             }
1056             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1057                 return false;
1058             }
1059             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1060             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1061             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1062             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1063             abc.addProteinDomain( a );
1064             abc.addProteinDomain( b );
1065             abc.addProteinDomain( c );
1066             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1067             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1068             if ( abc.getNumberOfProteinDomains() != 3 ) {
1069                 return false;
1070             }
1071             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1072                 return false;
1073             }
1074             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1075                 return false;
1076             }
1077             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1078                 return false;
1079             }
1080             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1081                 return false;
1082             }
1083             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1084             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1085             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1086             final Protein def = new BasicProtein( "def", "nemve", 0 );
1087             def.addProteinDomain( d );
1088             def.addProteinDomain( e );
1089             def.addProteinDomain( f );
1090             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1091             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1092             if ( def.getNumberOfProteinDomains() != 3 ) {
1093                 return false;
1094             }
1095             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1096                 return false;
1097             }
1098             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1099                 return false;
1100             }
1101             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1102                 return false;
1103             }
1104             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1105                 return false;
1106             }
1107             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1108                 return false;
1109             }
1110         }
1111         catch ( final Exception e ) {
1112             e.printStackTrace( System.out );
1113             return false;
1114         }
1115         return true;
1116     }
1117
1118     public static final boolean testNHXparsingFromURL() {
1119         try {
1120             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1121             final URL u = new URL( s );
1122             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1123             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1124             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1125                 return false;
1126             }
1127             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1128                 System.out.println( phys[ 0 ].toNewHampshire() );
1129                 return false;
1130             }
1131             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1132                 System.out.println( phys[ 1 ].toNewHampshire() );
1133                 return false;
1134             }
1135             final Phylogeny[] phys2 = factory.create( u.openStream(), new NHXParser() );
1136             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1137                 return false;
1138             }
1139             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1140                 System.out.println( phys2[ 0 ].toNewHampshire() );
1141                 return false;
1142             }
1143             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1144             final NHXParser p = new NHXParser();
1145             final URL u2 = new URL( s );
1146             p.setSource( u2 );
1147             if ( !p.hasNext() ) {
1148                 return false;
1149             }
1150             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1151                 return false;
1152             }
1153             if ( !p.hasNext() ) {
1154                 return false;
1155             }
1156             p.reset();
1157             if ( !p.hasNext() ) {
1158                 return false;
1159             }
1160             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1161                 return false;
1162             }
1163             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1164                 return false;
1165             }
1166             p.reset();
1167             if ( !p.hasNext() ) {
1168                 return false;
1169             }
1170             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1171                 return false;
1172             }
1173             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1174                 return false;
1175             }
1176         }
1177         catch ( final Exception e ) {
1178             e.printStackTrace();
1179         }
1180         return true;
1181     }
1182
1183     public static boolean testOverlapRemoval() {
1184         try {
1185             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1186             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1187             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1188             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1189             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1190             final List<Boolean> covered = new ArrayList<Boolean>();
1191             covered.add( true ); // 0
1192             covered.add( false ); // 1
1193             covered.add( true ); // 2
1194             covered.add( false ); // 3
1195             covered.add( true ); // 4
1196             covered.add( true ); // 5
1197             covered.add( false ); // 6
1198             covered.add( true ); // 7
1199             covered.add( true ); // 8
1200             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1201                 return false;
1202             }
1203             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1204                 return false;
1205             }
1206             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1207                 return false;
1208             }
1209             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1210                 return false;
1211             }
1212             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1213                 return false;
1214             }
1215             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1216             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1217             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1218             ab.addProteinDomain( a );
1219             ab.addProteinDomain( b );
1220             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1221             if ( ab.getNumberOfProteinDomains() != 2 ) {
1222                 return false;
1223             }
1224             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1225                 return false;
1226             }
1227             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1228                 return false;
1229             }
1230             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1231             if ( ab.getNumberOfProteinDomains() != 2 ) {
1232                 return false;
1233             }
1234             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1235                 return false;
1236             }
1237             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1238             final Domain d = new BasicDomain( "d",
1239                                               ( short ) 10000,
1240                                               ( short ) 10500,
1241                                               ( short ) 1,
1242                                               ( short ) 1,
1243                                               0.0000001,
1244                                               1 );
1245             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1246             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1247             cde.addProteinDomain( c );
1248             cde.addProteinDomain( d );
1249             cde.addProteinDomain( e );
1250             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1251             if ( cde.getNumberOfProteinDomains() != 3 ) {
1252                 return false;
1253             }
1254             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1255                 return false;
1256             }
1257             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1258             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1259             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1260             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1261             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1262             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1263             fghi.addProteinDomain( f );
1264             fghi.addProteinDomain( g );
1265             fghi.addProteinDomain( h );
1266             fghi.addProteinDomain( i );
1267             fghi.addProteinDomain( i );
1268             fghi.addProteinDomain( i );
1269             fghi.addProteinDomain( i2 );
1270             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1271             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1272                 return false;
1273             }
1274             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1275                 return false;
1276             }
1277             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1278                 return false;
1279             }
1280             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1281             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1282                 return false;
1283             }
1284             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1285                 return false;
1286             }
1287             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1288             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1289             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1290             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1291             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1292             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1293             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1294             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1295             jklm.addProteinDomain( j );
1296             jklm.addProteinDomain( k );
1297             jklm.addProteinDomain( l );
1298             jklm.addProteinDomain( m );
1299             jklm.addProteinDomain( m0 );
1300             jklm.addProteinDomain( m1 );
1301             jklm.addProteinDomain( m2 );
1302             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1303             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1304                 return false;
1305             }
1306             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1307                 return false;
1308             }
1309             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1310                 return false;
1311             }
1312             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1313             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1314                 return false;
1315             }
1316             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1317                 return false;
1318             }
1319             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1320             final Protein od = new BasicProtein( "od", "varanus", 0 );
1321             od.addProteinDomain( only );
1322             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1323             if ( od.getNumberOfProteinDomains() != 1 ) {
1324                 return false;
1325             }
1326             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1327                 return false;
1328             }
1329         }
1330         catch ( final Exception e ) {
1331             e.printStackTrace( System.out );
1332             return false;
1333         }
1334         return true;
1335     }
1336
1337     public static final boolean testPfamTreeReading() {
1338         try {
1339             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1340             final NHXParser parser = new NHXParser();
1341             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1342             parser.setReplaceUnderscores( false );
1343             parser.setGuessRootedness( true );
1344             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1345             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1346             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1347                 return false;
1348             }
1349             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1350                 return false;
1351             }
1352         }
1353         catch ( final Exception e ) {
1354             e.printStackTrace();
1355         }
1356         return true;
1357     }
1358
1359     public static final boolean testPhyloXMLparsingFromURL() {
1360         try {
1361             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1362             final URL u = new URL( s );
1363             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1364             final Phylogeny[] phys = factory.create( u.openStream(), PhyloXmlParser.createPhyloXmlParser() );
1365             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1366                 return false;
1367             }
1368         }
1369         catch ( final Exception e ) {
1370             e.printStackTrace();
1371         }
1372         return true;
1373     }
1374
1375     public static final boolean testToLReading() {
1376         try {
1377             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1378             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1379             final Phylogeny[] phys = factory.create( u.openStream(), new TolParser() );
1380             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1381                 return false;
1382             }
1383             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1384                 return false;
1385             }
1386             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Protacanthopterygii" ) ) {
1387                 return false;
1388             }
1389             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1390                 return false;
1391             }
1392         }
1393         catch ( final Exception e ) {
1394             e.printStackTrace();
1395         }
1396         return true;
1397     }
1398
1399     public static final boolean testTreeBaseReading() {
1400         try {
1401             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );
1402             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1403             parser.setReplaceUnderscores( true );
1404             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1405             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1406             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1407                 return false;
1408             }
1409             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1410             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1411             parser2.setReplaceUnderscores( true );
1412             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1413             final Phylogeny[] phys2 = factory2.create( u2.openStream(), parser2 );
1414             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1415                 return false;
1416             }
1417         }
1418         catch ( final Exception e ) {
1419             e.printStackTrace();
1420         }
1421         return true;
1422     }
1423
1424     public static final boolean testTreeFamReading() {
1425         try {
1426             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1427             final NHXParser parser = new NHXParser();
1428             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1429             parser.setReplaceUnderscores( false );
1430             parser.setGuessRootedness( true );
1431             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1432             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1433             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1434                 return false;
1435             }
1436             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1437                 return false;
1438             }
1439         }
1440         catch ( final Exception e ) {
1441             e.printStackTrace();
1442         }
1443         return true;
1444     }
1445
1446     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1447         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1448         return p;
1449     }
1450
1451     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1452         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1453     }
1454
1455     private static boolean testAminoAcidSequence() {
1456         try {
1457             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1458             if ( aa1.getLength() != 13 ) {
1459                 return false;
1460             }
1461             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1462                 return false;
1463             }
1464             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1465                 return false;
1466             }
1467             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1468                 return false;
1469             }
1470             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1471             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
1472                 return false;
1473             }
1474             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1475             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1476                 return false;
1477             }
1478             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1479             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1480                 return false;
1481             }
1482         }
1483         catch ( final Exception e ) {
1484             e.printStackTrace();
1485             return false;
1486         }
1487         return true;
1488     }
1489
1490     private static boolean testBasicDomain() {
1491         try {
1492             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1493             if ( !pd.getDomainId().equals( "id" ) ) {
1494                 return false;
1495             }
1496             if ( pd.getNumber() != 1 ) {
1497                 return false;
1498             }
1499             if ( pd.getTotalCount() != 4 ) {
1500                 return false;
1501             }
1502             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1503                 return false;
1504             }
1505             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1506             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1507             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1508             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1509             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1510             if ( !a1.equals( a1 ) ) {
1511                 return false;
1512             }
1513             if ( !a1.equals( a1_copy ) ) {
1514                 return false;
1515             }
1516             if ( !a1.equals( a1_equal ) ) {
1517                 return false;
1518             }
1519             if ( !a1.equals( a2 ) ) {
1520                 return false;
1521             }
1522             if ( a1.equals( a3 ) ) {
1523                 return false;
1524             }
1525             if ( a1.compareTo( a1 ) != 0 ) {
1526                 return false;
1527             }
1528             if ( a1.compareTo( a1_copy ) != 0 ) {
1529                 return false;
1530             }
1531             if ( a1.compareTo( a1_equal ) != 0 ) {
1532                 return false;
1533             }
1534             if ( a1.compareTo( a2 ) != 0 ) {
1535                 return false;
1536             }
1537             if ( a1.compareTo( a3 ) == 0 ) {
1538                 return false;
1539             }
1540         }
1541         catch ( final Exception e ) {
1542             e.printStackTrace( System.out );
1543             return false;
1544         }
1545         return true;
1546     }
1547
1548     private static boolean testBasicNodeMethods() {
1549         try {
1550             if ( PhylogenyNode.getNodeCount() != 0 ) {
1551                 return false;
1552             }
1553             final PhylogenyNode n1 = new PhylogenyNode();
1554             final PhylogenyNode n2 = PhylogenyNode
1555                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1556             final PhylogenyNode n3 = PhylogenyNode
1557                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1558             final PhylogenyNode n4 = PhylogenyNode
1559                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1560             if ( n1.isHasAssignedEvent() ) {
1561                 return false;
1562             }
1563             if ( PhylogenyNode.getNodeCount() != 4 ) {
1564                 return false;
1565             }
1566             if ( n3.getIndicator() != 0 ) {
1567                 return false;
1568             }
1569             if ( n3.getNumberOfExternalNodes() != 1 ) {
1570                 return false;
1571             }
1572             if ( !n3.isExternal() ) {
1573                 return false;
1574             }
1575             if ( !n3.isRoot() ) {
1576                 return false;
1577             }
1578             if ( !n4.getName().equals( "n4" ) ) {
1579                 return false;
1580             }
1581         }
1582         catch ( final Exception e ) {
1583             e.printStackTrace( System.out );
1584             return false;
1585         }
1586         return true;
1587     }
1588
1589     private static boolean testBasicPhyloXMLparsing() {
1590         try {
1591             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1592             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1593             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1594                                                               xml_parser );
1595             if ( xml_parser.getErrorCount() > 0 ) {
1596                 System.out.println( xml_parser.getErrorMessages().toString() );
1597                 return false;
1598             }
1599             if ( phylogenies_0.length != 4 ) {
1600                 return false;
1601             }
1602             final Phylogeny t1 = phylogenies_0[ 0 ];
1603             final Phylogeny t2 = phylogenies_0[ 1 ];
1604             final Phylogeny t3 = phylogenies_0[ 2 ];
1605             final Phylogeny t4 = phylogenies_0[ 3 ];
1606             if ( t1.getNumberOfExternalNodes() != 1 ) {
1607                 return false;
1608             }
1609             if ( !t1.isRooted() ) {
1610                 return false;
1611             }
1612             if ( t1.isRerootable() ) {
1613                 return false;
1614             }
1615             if ( !t1.getType().equals( "gene_tree" ) ) {
1616                 return false;
1617             }
1618             if ( t2.getNumberOfExternalNodes() != 2 ) {
1619                 return false;
1620             }
1621             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1622                 return false;
1623             }
1624             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1625                 return false;
1626             }
1627             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1628                 return false;
1629             }
1630             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1631                 return false;
1632             }
1633             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1634                 return false;
1635             }
1636             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1637                 return false;
1638             }
1639             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1640                     .startsWith( "actgtgggggt" ) ) {
1641                 return false;
1642             }
1643             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1644                     .startsWith( "ctgtgatgcat" ) ) {
1645                 return false;
1646             }
1647             if ( t3.getNumberOfExternalNodes() != 4 ) {
1648                 return false;
1649             }
1650             if ( !t1.getName().equals( "t1" ) ) {
1651                 return false;
1652             }
1653             if ( !t2.getName().equals( "t2" ) ) {
1654                 return false;
1655             }
1656             if ( !t3.getName().equals( "t3" ) ) {
1657                 return false;
1658             }
1659             if ( !t4.getName().equals( "t4" ) ) {
1660                 return false;
1661             }
1662             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1663                 return false;
1664             }
1665             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1666                 return false;
1667             }
1668             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1669                 return false;
1670             }
1671             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1672                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1673                 return false;
1674             }
1675             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1676                 return false;
1677             }
1678             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1679                 return false;
1680             }
1681             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1682                 return false;
1683             }
1684             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1685                     .equals( "apoptosis" ) ) {
1686                 return false;
1687             }
1688             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1689                     .equals( "GO:0006915" ) ) {
1690                 return false;
1691             }
1692             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1693                     .equals( "UniProtKB" ) ) {
1694                 return false;
1695             }
1696             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1697                     .equals( "experimental" ) ) {
1698                 return false;
1699             }
1700             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1701                     .equals( "function" ) ) {
1702                 return false;
1703             }
1704             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1705                     .getValue() != 1 ) {
1706                 return false;
1707             }
1708             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1709                     .getType().equals( "ml" ) ) {
1710                 return false;
1711             }
1712             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1713                     .equals( "apoptosis" ) ) {
1714                 return false;
1715             }
1716             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1717                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1718                 return false;
1719             }
1720             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1721                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1722                 return false;
1723             }
1724             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1725                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1726                 return false;
1727             }
1728             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1729                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1730                 return false;
1731             }
1732             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1733                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1734                 return false;
1735             }
1736             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1737                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1738                 return false;
1739             }
1740             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1741                     .equals( "GO:0005829" ) ) {
1742                 return false;
1743             }
1744             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1745                     .equals( "intracellular organelle" ) ) {
1746                 return false;
1747             }
1748             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1749                 return false;
1750             }
1751             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1752                     .equals( "UniProt link" ) ) ) {
1753                 return false;
1754             }
1755             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1756                 return false;
1757             }
1758             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1759             if ( x.size() != 4 ) {
1760                 return false;
1761             }
1762             int c = 0;
1763             for( final Accession acc : x ) {
1764                 if ( c == 0 ) {
1765                     if ( !acc.getSource().equals( "KEGG" ) ) {
1766                         return false;
1767                     }
1768                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1769                         return false;
1770                     }
1771                 }
1772                 c++;
1773             }
1774         }
1775         catch ( final Exception e ) {
1776             e.printStackTrace( System.out );
1777             return false;
1778         }
1779         return true;
1780     }
1781
1782     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1783         try {
1784             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1785             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1786             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1787                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1788             }
1789             else {
1790                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1791             }
1792             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1793                                                               xml_parser );
1794             if ( xml_parser.getErrorCount() > 0 ) {
1795                 System.out.println( xml_parser.getErrorMessages().toString() );
1796                 return false;
1797             }
1798             if ( phylogenies_0.length != 4 ) {
1799                 return false;
1800             }
1801             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1802             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1803             if ( phylogenies_t1.length != 1 ) {
1804                 return false;
1805             }
1806             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1807             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1808                 return false;
1809             }
1810             if ( !t1_rt.isRooted() ) {
1811                 return false;
1812             }
1813             if ( t1_rt.isRerootable() ) {
1814                 return false;
1815             }
1816             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1817                 return false;
1818             }
1819             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1820             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1821             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1822             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1823                 return false;
1824             }
1825             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1826                 return false;
1827             }
1828             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1829                 return false;
1830             }
1831             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1832                 return false;
1833             }
1834             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1835                     .startsWith( "actgtgggggt" ) ) {
1836                 return false;
1837             }
1838             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1839                     .startsWith( "ctgtgatgcat" ) ) {
1840                 return false;
1841             }
1842             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1843             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1844             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1845             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1846             if ( phylogenies_1.length != 1 ) {
1847                 return false;
1848             }
1849             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1850             if ( !t3_rt.getName().equals( "t3" ) ) {
1851                 return false;
1852             }
1853             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1854                 return false;
1855             }
1856             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1857                 return false;
1858             }
1859             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1860                 return false;
1861             }
1862             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1863                 return false;
1864             }
1865             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1866                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1867                 return false;
1868             }
1869             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1870                 return false;
1871             }
1872             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1873                 return false;
1874             }
1875             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1876                     .equals( "UniProtKB" ) ) {
1877                 return false;
1878             }
1879             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1880                     .equals( "apoptosis" ) ) {
1881                 return false;
1882             }
1883             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1884                     .equals( "GO:0006915" ) ) {
1885                 return false;
1886             }
1887             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1888                     .equals( "UniProtKB" ) ) {
1889                 return false;
1890             }
1891             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1892                     .equals( "experimental" ) ) {
1893                 return false;
1894             }
1895             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1896                     .equals( "function" ) ) {
1897                 return false;
1898             }
1899             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1900                     .getValue() != 1 ) {
1901                 return false;
1902             }
1903             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1904                     .getType().equals( "ml" ) ) {
1905                 return false;
1906             }
1907             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1908                     .equals( "apoptosis" ) ) {
1909                 return false;
1910             }
1911             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1912                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1913                 return false;
1914             }
1915             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1916                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1917                 return false;
1918             }
1919             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1920                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1921                 return false;
1922             }
1923             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1924                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1925                 return false;
1926             }
1927             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1928                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1929                 return false;
1930             }
1931             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1932                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1933                 return false;
1934             }
1935             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1936                     .equals( "GO:0005829" ) ) {
1937                 return false;
1938             }
1939             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1940                     .equals( "intracellular organelle" ) ) {
1941                 return false;
1942             }
1943             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1944                 return false;
1945             }
1946             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1947                     .equals( "UniProt link" ) ) ) {
1948                 return false;
1949             }
1950             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1951                 return false;
1952             }
1953             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1954                 return false;
1955             }
1956             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1957                     .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." ) ) ) {
1958                 return false;
1959             }
1960             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1961                 return false;
1962             }
1963             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1964                 return false;
1965             }
1966             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1967                 return false;
1968             }
1969             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1970                 return false;
1971             }
1972             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1973                     .equals( "ncbi" ) ) {
1974                 return false;
1975             }
1976             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1977                 return false;
1978             }
1979             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1980                     .getName().equals( "B" ) ) {
1981                 return false;
1982             }
1983             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1984                     .getFrom() != 21 ) {
1985                 return false;
1986             }
1987             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1988                 return false;
1989             }
1990             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1991                     .getLength() != 24 ) {
1992                 return false;
1993             }
1994             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1995                     .getConfidence() != 2144 ) {
1996                 return false;
1997             }
1998             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1999                     .equals( "pfam" ) ) {
2000                 return false;
2001             }
2002             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2003                 return false;
2004             }
2005             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2006                 return false;
2007             }
2008             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2009                 return false;
2010             }
2011             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2012                 return false;
2013             }
2014             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2015             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2016                 return false;
2017             }
2018             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2019                 return false;
2020             }
2021             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2022                 return false;
2023             }
2024             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2025                 return false;
2026             }
2027             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2028                 return false;
2029             }
2030             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2031                 return false;
2032             }
2033             if ( taxbb.getSynonyms().size() != 2 ) {
2034                 return false;
2035             }
2036             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2037                 return false;
2038             }
2039             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2040                 return false;
2041             }
2042             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2043                 return false;
2044             }
2045             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2046                 return false;
2047             }
2048             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2049                 return false;
2050             }
2051             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2052                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2053                 return false;
2054             }
2055             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2056                 return false;
2057             }
2058             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2059                 return false;
2060             }
2061             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2062                 return false;
2063             }
2064             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2065                 return false;
2066             }
2067             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2068                 return false;
2069             }
2070             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2071                 return false;
2072             }
2073             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2074                 return false;
2075             }
2076             //
2077             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2078                 return false;
2079             }
2080             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2081                     .equalsIgnoreCase( "435" ) ) {
2082                 return false;
2083             }
2084             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
2085                 return false;
2086             }
2087             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2088                     .equalsIgnoreCase( "443.7" ) ) {
2089                 return false;
2090             }
2091             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2092                 return false;
2093             }
2094             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2095                 return false;
2096             }
2097             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2098                     .equalsIgnoreCase( "433" ) ) {
2099                 return false;
2100             }
2101             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2102                     .getCrossReferences();
2103             if ( x.size() != 4 ) {
2104                 return false;
2105             }
2106             int c = 0;
2107             for( final Accession acc : x ) {
2108                 if ( c == 0 ) {
2109                     if ( !acc.getSource().equals( "KEGG" ) ) {
2110                         return false;
2111                     }
2112                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2113                         return false;
2114                     }
2115                 }
2116                 c++;
2117             }
2118         }
2119         catch ( final Exception e ) {
2120             e.printStackTrace( System.out );
2121             return false;
2122         }
2123         return true;
2124     }
2125
2126     private static boolean testBasicPhyloXMLparsingValidating() {
2127         try {
2128             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2129             PhyloXmlParser xml_parser = null;
2130             try {
2131                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2132             }
2133             catch ( final Exception e ) {
2134                 // Do nothing -- means were not running from jar.
2135             }
2136             if ( xml_parser == null ) {
2137                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2138                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2139                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2140                 }
2141                 else {
2142                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2143                 }
2144             }
2145             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
2146                                                               xml_parser );
2147             if ( xml_parser.getErrorCount() > 0 ) {
2148                 System.out.println( xml_parser.getErrorMessages().toString() );
2149                 return false;
2150             }
2151             if ( phylogenies_0.length != 4 ) {
2152                 return false;
2153             }
2154             final Phylogeny t1 = phylogenies_0[ 0 ];
2155             final Phylogeny t2 = phylogenies_0[ 1 ];
2156             final Phylogeny t3 = phylogenies_0[ 2 ];
2157             final Phylogeny t4 = phylogenies_0[ 3 ];
2158             if ( !t1.getName().equals( "t1" ) ) {
2159                 return false;
2160             }
2161             if ( !t2.getName().equals( "t2" ) ) {
2162                 return false;
2163             }
2164             if ( !t3.getName().equals( "t3" ) ) {
2165                 return false;
2166             }
2167             if ( !t4.getName().equals( "t4" ) ) {
2168                 return false;
2169             }
2170             if ( t1.getNumberOfExternalNodes() != 1 ) {
2171                 return false;
2172             }
2173             if ( t2.getNumberOfExternalNodes() != 2 ) {
2174                 return false;
2175             }
2176             if ( t3.getNumberOfExternalNodes() != 4 ) {
2177                 return false;
2178             }
2179             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2180             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
2181             if ( xml_parser.getErrorCount() > 0 ) {
2182                 System.out.println( "errors:" );
2183                 System.out.println( xml_parser.getErrorMessages().toString() );
2184                 return false;
2185             }
2186             if ( phylogenies_1.length != 4 ) {
2187                 return false;
2188             }
2189             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
2190                                                               xml_parser );
2191             if ( xml_parser.getErrorCount() > 0 ) {
2192                 System.out.println( "errors:" );
2193                 System.out.println( xml_parser.getErrorMessages().toString() );
2194                 return false;
2195             }
2196             if ( phylogenies_2.length != 1 ) {
2197                 return false;
2198             }
2199             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2200                 return false;
2201             }
2202             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
2203                                                               xml_parser );
2204             if ( xml_parser.getErrorCount() > 0 ) {
2205                 System.out.println( xml_parser.getErrorMessages().toString() );
2206                 return false;
2207             }
2208             if ( phylogenies_3.length != 2 ) {
2209                 return false;
2210             }
2211             final Phylogeny a = phylogenies_3[ 0 ];
2212             if ( !a.getName().equals( "tree 4" ) ) {
2213                 return false;
2214             }
2215             if ( a.getNumberOfExternalNodes() != 3 ) {
2216                 return false;
2217             }
2218             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2219                 return false;
2220             }
2221             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2222                 return false;
2223             }
2224             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
2225                                                               xml_parser );
2226             if ( xml_parser.getErrorCount() > 0 ) {
2227                 System.out.println( xml_parser.getErrorMessages().toString() );
2228                 return false;
2229             }
2230             if ( phylogenies_4.length != 1 ) {
2231                 return false;
2232             }
2233             final Phylogeny s = phylogenies_4[ 0 ];
2234             if ( s.getNumberOfExternalNodes() != 6 ) {
2235                 return false;
2236             }
2237             s.getNode( "first" );
2238             s.getNode( "<>" );
2239             s.getNode( "\"<a'b&c'd\">\"" );
2240             s.getNode( "'''\"" );
2241             s.getNode( "\"\"\"" );
2242             s.getNode( "dick & doof" );
2243         }
2244         catch ( final Exception e ) {
2245             e.printStackTrace( System.out );
2246             return false;
2247         }
2248         return true;
2249     }
2250
2251     private static boolean testBasicProtein() {
2252         try {
2253             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2254             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2255             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2256             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2257             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2258             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2259             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2260             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2261             p0.addProteinDomain( y );
2262             p0.addProteinDomain( e );
2263             p0.addProteinDomain( b );
2264             p0.addProteinDomain( c );
2265             p0.addProteinDomain( d );
2266             p0.addProteinDomain( a );
2267             p0.addProteinDomain( x );
2268             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2269                 return false;
2270             }
2271             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2272                 return false;
2273             }
2274             //
2275             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2276             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2277             aa0.addProteinDomain( a1 );
2278             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2279                 return false;
2280             }
2281             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2282                 return false;
2283             }
2284             //
2285             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2286             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2287             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2288             aa1.addProteinDomain( a11 );
2289             aa1.addProteinDomain( a12 );
2290             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2291                 return false;
2292             }
2293             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2294                 return false;
2295             }
2296             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2297             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2298                 return false;
2299             }
2300             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2301                 return false;
2302             }
2303             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2304                 return false;
2305             }
2306             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2307             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2308                 return false;
2309             }
2310             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2311                 return false;
2312             }
2313             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2314                 return false;
2315             }
2316             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2317                 return false;
2318             }
2319             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2320             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2321                 return false;
2322             }
2323             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2324                 return false;
2325             }
2326             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2327                 return false;
2328             }
2329             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2330                 return false;
2331             }
2332             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2333             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2334                 return false;
2335             }
2336             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2337                 return false;
2338             }
2339             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2340                 return false;
2341             }
2342             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2343                 return false;
2344             }
2345             //
2346             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2347             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2348             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2349             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2350             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2351             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2352             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2353             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2354             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2355             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2356             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2357             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2358             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2359             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2360             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2361             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2362             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2363             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2364             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2365             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2366             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2367             p00.addProteinDomain( y0 );
2368             p00.addProteinDomain( e0 );
2369             p00.addProteinDomain( b0 );
2370             p00.addProteinDomain( c0 );
2371             p00.addProteinDomain( d0 );
2372             p00.addProteinDomain( a0 );
2373             p00.addProteinDomain( x0 );
2374             p00.addProteinDomain( y1 );
2375             p00.addProteinDomain( y2 );
2376             p00.addProteinDomain( y3 );
2377             p00.addProteinDomain( e1 );
2378             p00.addProteinDomain( e2 );
2379             p00.addProteinDomain( e3 );
2380             p00.addProteinDomain( e4 );
2381             p00.addProteinDomain( e5 );
2382             p00.addProteinDomain( z0 );
2383             p00.addProteinDomain( z1 );
2384             p00.addProteinDomain( z2 );
2385             p00.addProteinDomain( zz0 );
2386             p00.addProteinDomain( zz1 );
2387             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2388                 return false;
2389             }
2390             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2391                 return false;
2392             }
2393             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2394                 return false;
2395             }
2396             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2397                 return false;
2398             }
2399             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" ) ) {
2400                 return false;
2401             }
2402             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2403             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2404             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2405             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2406             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2407             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2408             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2409             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2410             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2411             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2412             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2413             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2414             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2415             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2416             p.addProteinDomain( B15 );
2417             p.addProteinDomain( C50 );
2418             p.addProteinDomain( A60 );
2419             p.addProteinDomain( A30 );
2420             p.addProteinDomain( C70 );
2421             p.addProteinDomain( B35 );
2422             p.addProteinDomain( B40 );
2423             p.addProteinDomain( A0 );
2424             p.addProteinDomain( A10 );
2425             p.addProteinDomain( A20 );
2426             p.addProteinDomain( B25 );
2427             p.addProteinDomain( D80 );
2428             List<String> domains_ids = new ArrayList<String>();
2429             domains_ids.add( "A" );
2430             domains_ids.add( "B" );
2431             domains_ids.add( "C" );
2432             if ( !p.contains( domains_ids, false ) ) {
2433                 return false;
2434             }
2435             if ( !p.contains( domains_ids, true ) ) {
2436                 return false;
2437             }
2438             domains_ids.add( "X" );
2439             if ( p.contains( domains_ids, false ) ) {
2440                 return false;
2441             }
2442             if ( p.contains( domains_ids, true ) ) {
2443                 return false;
2444             }
2445             domains_ids = new ArrayList<String>();
2446             domains_ids.add( "A" );
2447             domains_ids.add( "C" );
2448             domains_ids.add( "D" );
2449             if ( !p.contains( domains_ids, false ) ) {
2450                 return false;
2451             }
2452             if ( !p.contains( domains_ids, true ) ) {
2453                 return false;
2454             }
2455             domains_ids = new ArrayList<String>();
2456             domains_ids.add( "A" );
2457             domains_ids.add( "D" );
2458             domains_ids.add( "C" );
2459             if ( !p.contains( domains_ids, false ) ) {
2460                 return false;
2461             }
2462             if ( p.contains( domains_ids, true ) ) {
2463                 return false;
2464             }
2465             domains_ids = new ArrayList<String>();
2466             domains_ids.add( "A" );
2467             domains_ids.add( "A" );
2468             domains_ids.add( "B" );
2469             if ( !p.contains( domains_ids, false ) ) {
2470                 return false;
2471             }
2472             if ( !p.contains( domains_ids, true ) ) {
2473                 return false;
2474             }
2475             domains_ids = new ArrayList<String>();
2476             domains_ids.add( "A" );
2477             domains_ids.add( "A" );
2478             domains_ids.add( "A" );
2479             domains_ids.add( "B" );
2480             domains_ids.add( "B" );
2481             if ( !p.contains( domains_ids, false ) ) {
2482                 return false;
2483             }
2484             if ( !p.contains( domains_ids, true ) ) {
2485                 return false;
2486             }
2487             domains_ids = new ArrayList<String>();
2488             domains_ids.add( "A" );
2489             domains_ids.add( "A" );
2490             domains_ids.add( "B" );
2491             domains_ids.add( "A" );
2492             domains_ids.add( "B" );
2493             domains_ids.add( "B" );
2494             domains_ids.add( "A" );
2495             domains_ids.add( "B" );
2496             domains_ids.add( "C" );
2497             domains_ids.add( "A" );
2498             domains_ids.add( "C" );
2499             domains_ids.add( "D" );
2500             if ( !p.contains( domains_ids, false ) ) {
2501                 return false;
2502             }
2503             if ( p.contains( domains_ids, true ) ) {
2504                 return false;
2505             }
2506         }
2507         catch ( final Exception e ) {
2508             e.printStackTrace( System.out );
2509             return false;
2510         }
2511         return true;
2512     }
2513
2514     private static boolean testBasicTable() {
2515         try {
2516             final BasicTable<String> t0 = new BasicTable<String>();
2517             if ( t0.getNumberOfColumns() != 0 ) {
2518                 return false;
2519             }
2520             if ( t0.getNumberOfRows() != 0 ) {
2521                 return false;
2522             }
2523             t0.setValue( 3, 2, "23" );
2524             t0.setValue( 10, 1, "error" );
2525             t0.setValue( 10, 1, "110" );
2526             t0.setValue( 9, 1, "19" );
2527             t0.setValue( 1, 10, "101" );
2528             t0.setValue( 10, 10, "1010" );
2529             t0.setValue( 100, 10, "10100" );
2530             t0.setValue( 0, 0, "00" );
2531             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2532                 return false;
2533             }
2534             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2535                 return false;
2536             }
2537             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2538                 return false;
2539             }
2540             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2541                 return false;
2542             }
2543             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2544                 return false;
2545             }
2546             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2547                 return false;
2548             }
2549             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2550                 return false;
2551             }
2552             if ( t0.getNumberOfColumns() != 101 ) {
2553                 return false;
2554             }
2555             if ( t0.getNumberOfRows() != 11 ) {
2556                 return false;
2557             }
2558             if ( t0.getValueAsString( 49, 4 ) != null ) {
2559                 return false;
2560             }
2561             final String l = ForesterUtil.getLineSeparator();
2562             final StringBuffer source = new StringBuffer();
2563             source.append( "" + l );
2564             source.append( "# 1 1 1 1 1 1 1 1" + l );
2565             source.append( " 00 01 02 03" + l );
2566             source.append( "   10 11 12 13  " + l );
2567             source.append( "20 21 22 23 " + l );
2568             source.append( "    30  31    32 33" + l );
2569             source.append( "40 41 42 43" + l );
2570             source.append( "  # 1 1 1 1 1 " + l );
2571             source.append( "50 51 52 53 54" + l );
2572             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2573             if ( t1.getNumberOfColumns() != 5 ) {
2574                 return false;
2575             }
2576             if ( t1.getNumberOfRows() != 6 ) {
2577                 return false;
2578             }
2579             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2580                 return false;
2581             }
2582             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2583                 return false;
2584             }
2585             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2586                 return false;
2587             }
2588             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2589                 return false;
2590             }
2591             final StringBuffer source1 = new StringBuffer();
2592             source1.append( "" + l );
2593             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2594             source1.append( " 00; 01 ;02;03" + l );
2595             source1.append( "   10; 11; 12; 13  " + l );
2596             source1.append( "20; 21; 22; 23 " + l );
2597             source1.append( "    30;  31;    32; 33" + l );
2598             source1.append( "40;41;42;43" + l );
2599             source1.append( "  # 1 1 1 1 1 " + l );
2600             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2601             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2602             if ( t2.getNumberOfColumns() != 5 ) {
2603                 return false;
2604             }
2605             if ( t2.getNumberOfRows() != 6 ) {
2606                 return false;
2607             }
2608             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2609                 return false;
2610             }
2611             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2612                 return false;
2613             }
2614             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2615                 return false;
2616             }
2617             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2618                 return false;
2619             }
2620             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2621                 return false;
2622             }
2623             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2624                 return false;
2625             }
2626             final StringBuffer source2 = new StringBuffer();
2627             source2.append( "" + l );
2628             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2629             source2.append( " 00; 01 ;02;03" + l );
2630             source2.append( "   10; 11; 12; 13  " + l );
2631             source2.append( "20; 21; 22; 23 " + l );
2632             source2.append( "                     " + l );
2633             source2.append( "    30;  31;    32; 33" + l );
2634             source2.append( "40;41;42;43" + l );
2635             source2.append( "  comment: 1 1 1 1 1 " + l );
2636             source2.append( ";;;50  ;   52; 53;;54   " + l );
2637             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2638                                                                         ';',
2639                                                                         false,
2640                                                                         false,
2641                                                                         "comment:",
2642                                                                         false );
2643             if ( tl.size() != 2 ) {
2644                 return false;
2645             }
2646             final BasicTable<String> t3 = tl.get( 0 );
2647             final BasicTable<String> t4 = tl.get( 1 );
2648             if ( t3.getNumberOfColumns() != 4 ) {
2649                 return false;
2650             }
2651             if ( t3.getNumberOfRows() != 3 ) {
2652                 return false;
2653             }
2654             if ( t4.getNumberOfColumns() != 4 ) {
2655                 return false;
2656             }
2657             if ( t4.getNumberOfRows() != 3 ) {
2658                 return false;
2659             }
2660             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2661                 return false;
2662             }
2663             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2664                 return false;
2665             }
2666         }
2667         catch ( final Exception e ) {
2668             e.printStackTrace( System.out );
2669             return false;
2670         }
2671         return true;
2672     }
2673
2674     private static boolean testBasicTolXMLparsing() {
2675         try {
2676             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2677             final TolParser parser = new TolParser();
2678             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2679             if ( parser.getErrorCount() > 0 ) {
2680                 System.out.println( parser.getErrorMessages().toString() );
2681                 return false;
2682             }
2683             if ( phylogenies_0.length != 1 ) {
2684                 return false;
2685             }
2686             final Phylogeny t1 = phylogenies_0[ 0 ];
2687             if ( t1.getNumberOfExternalNodes() != 5 ) {
2688                 return false;
2689             }
2690             if ( !t1.isRooted() ) {
2691                 return false;
2692             }
2693             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2694                 return false;
2695             }
2696             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2697                 return false;
2698             }
2699             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2700                 return false;
2701             }
2702             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2703                 return false;
2704             }
2705             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2706             if ( parser.getErrorCount() > 0 ) {
2707                 System.out.println( parser.getErrorMessages().toString() );
2708                 return false;
2709             }
2710             if ( phylogenies_1.length != 1 ) {
2711                 return false;
2712             }
2713             final Phylogeny t2 = phylogenies_1[ 0 ];
2714             if ( t2.getNumberOfExternalNodes() != 664 ) {
2715                 return false;
2716             }
2717             if ( !t2.isRooted() ) {
2718                 return false;
2719             }
2720             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2721                 return false;
2722             }
2723             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2724                 return false;
2725             }
2726             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2727                 return false;
2728             }
2729             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2730                 return false;
2731             }
2732             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2733                 return false;
2734             }
2735             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2736                     .equals( "Aquifex" ) ) {
2737                 return false;
2738             }
2739             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2740             if ( parser.getErrorCount() > 0 ) {
2741                 System.out.println( parser.getErrorMessages().toString() );
2742                 return false;
2743             }
2744             if ( phylogenies_2.length != 1 ) {
2745                 return false;
2746             }
2747             final Phylogeny t3 = phylogenies_2[ 0 ];
2748             if ( t3.getNumberOfExternalNodes() != 184 ) {
2749                 return false;
2750             }
2751             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2752                 return false;
2753             }
2754             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2755                 return false;
2756             }
2757             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2758                 return false;
2759             }
2760             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2761             if ( parser.getErrorCount() > 0 ) {
2762                 System.out.println( parser.getErrorMessages().toString() );
2763                 return false;
2764             }
2765             if ( phylogenies_3.length != 1 ) {
2766                 return false;
2767             }
2768             final Phylogeny t4 = phylogenies_3[ 0 ];
2769             if ( t4.getNumberOfExternalNodes() != 1 ) {
2770                 return false;
2771             }
2772             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2773                 return false;
2774             }
2775             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2776                 return false;
2777             }
2778             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2779                 return false;
2780             }
2781             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2782             if ( parser.getErrorCount() > 0 ) {
2783                 System.out.println( parser.getErrorMessages().toString() );
2784                 return false;
2785             }
2786             if ( phylogenies_4.length != 1 ) {
2787                 return false;
2788             }
2789             final Phylogeny t5 = phylogenies_4[ 0 ];
2790             if ( t5.getNumberOfExternalNodes() != 13 ) {
2791                 return false;
2792             }
2793             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2794                 return false;
2795             }
2796             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2797                 return false;
2798             }
2799             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2800                 return false;
2801             }
2802         }
2803         catch ( final Exception e ) {
2804             e.printStackTrace( System.out );
2805             return false;
2806         }
2807         return true;
2808     }
2809
2810     private static boolean testBasicTreeMethods() {
2811         try {
2812             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2813             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2814             if ( t2.getNumberOfExternalNodes() != 4 ) {
2815                 return false;
2816             }
2817             if ( t2.getHeight() != 8.5 ) {
2818                 return false;
2819             }
2820             if ( !t2.isCompletelyBinary() ) {
2821                 return false;
2822             }
2823             if ( t2.isEmpty() ) {
2824                 return false;
2825             }
2826             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2827             if ( t3.getNumberOfExternalNodes() != 5 ) {
2828                 return false;
2829             }
2830             if ( t3.getHeight() != 11 ) {
2831                 return false;
2832             }
2833             if ( t3.isCompletelyBinary() ) {
2834                 return false;
2835             }
2836             final PhylogenyNode n = t3.getNode( "ABC" );
2837             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 ];
2838             if ( t4.getNumberOfExternalNodes() != 9 ) {
2839                 return false;
2840             }
2841             if ( t4.getHeight() != 11 ) {
2842                 return false;
2843             }
2844             if ( t4.isCompletelyBinary() ) {
2845                 return false;
2846             }
2847             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)" );
2848             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2849             if ( t5.getNumberOfExternalNodes() != 8 ) {
2850                 return false;
2851             }
2852             if ( t5.getHeight() != 15 ) {
2853                 return false;
2854             }
2855             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)" );
2856             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2857             if ( t6.getHeight() != 15 ) {
2858                 return false;
2859             }
2860             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)" );
2861             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2862             if ( t7.getHeight() != 15 ) {
2863                 return false;
2864             }
2865             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)" );
2866             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2867             if ( t8.getNumberOfExternalNodes() != 10 ) {
2868                 return false;
2869             }
2870             if ( t8.getHeight() != 15 ) {
2871                 return false;
2872             }
2873             final char[] a9 = new char[] { 'a' };
2874             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2875             if ( t9.getHeight() != 0 ) {
2876                 return false;
2877             }
2878             final char[] a10 = new char[] { 'a', ':', '6' };
2879             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2880             if ( t10.getHeight() != 6 ) {
2881                 return false;
2882             }
2883         }
2884         catch ( final Exception e ) {
2885             e.printStackTrace( System.out );
2886             return false;
2887         }
2888         return true;
2889     }
2890
2891     private static boolean testConfidenceAssessor() {
2892         try {
2893             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2894             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2895             final Phylogeny[] ev0 = factory
2896                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2897                              new NHXParser() );
2898             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2899             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2900                 return false;
2901             }
2902             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2903                 return false;
2904             }
2905             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2906             final Phylogeny[] ev1 = factory
2907                     .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)));",
2908                              new NHXParser() );
2909             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2910             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2911                 return false;
2912             }
2913             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2914                 return false;
2915             }
2916             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2917             final Phylogeny[] ev_b = factory
2918                     .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",
2919                              new NHXParser() );
2920             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2921             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2922                 return false;
2923             }
2924             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2925                 return false;
2926             }
2927             //
2928             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2929             final Phylogeny[] ev1x = factory
2930                     .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)));",
2931                              new NHXParser() );
2932             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2933             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2934                 return false;
2935             }
2936             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2937                 return false;
2938             }
2939             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2940             final Phylogeny[] ev_bx = factory
2941                     .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",
2942                              new NHXParser() );
2943             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2944             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2945                 return false;
2946             }
2947             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2948                 return false;
2949             }
2950             //
2951             final Phylogeny[] t2 = factory
2952                     .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);",
2953                              new NHXParser() );
2954             final Phylogeny[] ev2 = factory
2955                     .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);",
2956                              new NHXParser() );
2957             for( final Phylogeny target : t2 ) {
2958                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2959             }
2960             //
2961             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2962                                                  new NHXParser() )[ 0 ];
2963             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2964             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2965             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2966                 return false;
2967             }
2968             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2969                 return false;
2970             }
2971             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2972                 return false;
2973             }
2974         }
2975         catch ( final Exception e ) {
2976             e.printStackTrace();
2977             return false;
2978         }
2979         return true;
2980     }
2981
2982     private static boolean testCopyOfNodeData() {
2983         try {
2984             final PhylogenyNode n1 = PhylogenyNode
2985                     .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]" );
2986             final PhylogenyNode n2 = n1.copyNodeData();
2987             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2988                 return false;
2989             }
2990         }
2991         catch ( final Exception e ) {
2992             e.printStackTrace();
2993             return false;
2994         }
2995         return true;
2996     }
2997
2998     private static boolean testCreateBalancedPhylogeny() {
2999         try {
3000             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3001             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3002                 return false;
3003             }
3004             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3005                 return false;
3006             }
3007             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3008             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3009                 return false;
3010             }
3011             if ( p1.getNumberOfExternalNodes() != 100 ) {
3012                 return false;
3013             }
3014         }
3015         catch ( final Exception e ) {
3016             e.printStackTrace();
3017             return false;
3018         }
3019         return true;
3020     }
3021
3022     private static boolean testCreateUriForSeqWeb() {
3023         try {
3024             final PhylogenyNode n = new PhylogenyNode();
3025             n.setName( "tr|B3RJ64" );
3026             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3027                 return false;
3028             }
3029             n.setName( "B0LM41_HUMAN" );
3030             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3031                 return false;
3032             }
3033             n.setName( "NP_001025424" );
3034             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3035                 return false;
3036             }
3037             n.setName( "_NM_001030253-" );
3038             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3039                 return false;
3040             }
3041             n.setName( "XM_002122186" );
3042             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3043                 return false;
3044             }
3045             n.setName( "dgh_AAA34956_gdg" );
3046             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3047                 return false;
3048             }
3049             n.setName( "AAA34956" );
3050             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3051                 return false;
3052             }
3053             n.setName( "GI:394892" );
3054             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3055                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3056                 return false;
3057             }
3058             n.setName( "gi_394892" );
3059             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3060                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3061                 return false;
3062             }
3063             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3064             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3065                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3066                 return false;
3067             }
3068             n.setName( "P12345" );
3069             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3070                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3071                 return false;
3072             }
3073             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3074             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3075                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3076                 return false;
3077             }
3078         }
3079         catch ( final Exception e ) {
3080             e.printStackTrace( System.out );
3081             return false;
3082         }
3083         return true;
3084     }
3085
3086     private static boolean testDataObjects() {
3087         try {
3088             final Confidence s0 = new Confidence();
3089             final Confidence s1 = new Confidence();
3090             if ( !s0.isEqual( s1 ) ) {
3091                 return false;
3092             }
3093             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3094             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3095             if ( s2.isEqual( s1 ) ) {
3096                 return false;
3097             }
3098             if ( !s2.isEqual( s3 ) ) {
3099                 return false;
3100             }
3101             final Confidence s4 = ( Confidence ) s3.copy();
3102             if ( !s4.isEqual( s3 ) ) {
3103                 return false;
3104             }
3105             s3.asSimpleText();
3106             s3.asText();
3107             // Taxonomy
3108             // ----------
3109             final Taxonomy t1 = new Taxonomy();
3110             final Taxonomy t2 = new Taxonomy();
3111             final Taxonomy t3 = new Taxonomy();
3112             final Taxonomy t4 = new Taxonomy();
3113             final Taxonomy t5 = new Taxonomy();
3114             t1.setIdentifier( new Identifier( "ecoli" ) );
3115             t1.setTaxonomyCode( "ECOLI" );
3116             t1.setScientificName( "E. coli" );
3117             t1.setCommonName( "coli" );
3118             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3119             if ( !t1.isEqual( t0 ) ) {
3120                 return false;
3121             }
3122             t2.setIdentifier( new Identifier( "ecoli" ) );
3123             t2.setTaxonomyCode( "OTHER" );
3124             t2.setScientificName( "what" );
3125             t2.setCommonName( "something" );
3126             if ( !t1.isEqual( t2 ) ) {
3127                 return false;
3128             }
3129             t2.setIdentifier( new Identifier( "nemve" ) );
3130             if ( t1.isEqual( t2 ) ) {
3131                 return false;
3132             }
3133             t1.setIdentifier( null );
3134             t3.setTaxonomyCode( "ECOLI" );
3135             t3.setScientificName( "what" );
3136             t3.setCommonName( "something" );
3137             if ( !t1.isEqual( t3 ) ) {
3138                 return false;
3139             }
3140             t1.setIdentifier( null );
3141             t1.setTaxonomyCode( "" );
3142             t4.setScientificName( "E. ColI" );
3143             t4.setCommonName( "something" );
3144             if ( !t1.isEqual( t4 ) ) {
3145                 return false;
3146             }
3147             t4.setScientificName( "B. subtilis" );
3148             t4.setCommonName( "something" );
3149             if ( t1.isEqual( t4 ) ) {
3150                 return false;
3151             }
3152             t1.setIdentifier( null );
3153             t1.setTaxonomyCode( "" );
3154             t1.setScientificName( "" );
3155             t5.setCommonName( "COLI" );
3156             if ( !t1.isEqual( t5 ) ) {
3157                 return false;
3158             }
3159             t5.setCommonName( "vibrio" );
3160             if ( t1.isEqual( t5 ) ) {
3161                 return false;
3162             }
3163             // Identifier
3164             // ----------
3165             final Identifier id0 = new Identifier( "123", "pfam" );
3166             final Identifier id1 = ( Identifier ) id0.copy();
3167             if ( !id1.isEqual( id1 ) ) {
3168                 return false;
3169             }
3170             if ( !id1.isEqual( id0 ) ) {
3171                 return false;
3172             }
3173             if ( !id0.isEqual( id1 ) ) {
3174                 return false;
3175             }
3176             id1.asSimpleText();
3177             id1.asText();
3178             // ProteinDomain
3179             // ---------------
3180             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3181             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3182             if ( !pd1.isEqual( pd1 ) ) {
3183                 return false;
3184             }
3185             if ( !pd1.isEqual( pd0 ) ) {
3186                 return false;
3187             }
3188             pd1.asSimpleText();
3189             pd1.asText();
3190             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3191             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3192             if ( !pd3.isEqual( pd3 ) ) {
3193                 return false;
3194             }
3195             if ( !pd2.isEqual( pd3 ) ) {
3196                 return false;
3197             }
3198             if ( !pd0.isEqual( pd3 ) ) {
3199                 return false;
3200             }
3201             pd3.asSimpleText();
3202             pd3.asText();
3203             // DomainArchitecture
3204             // ------------------
3205             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3206             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3207             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3208             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3209             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3210             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3211             domains0.add( d2 );
3212             domains0.add( d0 );
3213             domains0.add( d3 );
3214             domains0.add( d1 );
3215             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3216             if ( ds0.getNumberOfDomains() != 4 ) {
3217                 return false;
3218             }
3219             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3220             if ( !ds0.isEqual( ds0 ) ) {
3221                 return false;
3222             }
3223             if ( !ds0.isEqual( ds1 ) ) {
3224                 return false;
3225             }
3226             if ( ds1.getNumberOfDomains() != 4 ) {
3227                 return false;
3228             }
3229             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3230             domains1.add( d1 );
3231             domains1.add( d2 );
3232             domains1.add( d4 );
3233             domains1.add( d0 );
3234             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3235             if ( ds0.isEqual( ds2 ) ) {
3236                 return false;
3237             }
3238             ds1.asSimpleText();
3239             ds1.asText();
3240             ds1.toNHX();
3241             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3242             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3243                 System.out.println( ds3.toNHX() );
3244                 return false;
3245             }
3246             if ( ds3.getNumberOfDomains() != 3 ) {
3247                 return false;
3248             }
3249             // Event
3250             // -----
3251             final Event e1 = new Event( Event.EventType.fusion );
3252             if ( e1.isDuplication() ) {
3253                 return false;
3254             }
3255             if ( !e1.isFusion() ) {
3256                 return false;
3257             }
3258             if ( !e1.asText().toString().equals( "fusion" ) ) {
3259                 return false;
3260             }
3261             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3262                 return false;
3263             }
3264             final Event e11 = new Event( Event.EventType.fusion );
3265             if ( !e11.isEqual( e1 ) ) {
3266                 return false;
3267             }
3268             if ( !e11.toNHX().toString().equals( "" ) ) {
3269                 return false;
3270             }
3271             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3272             if ( e2.isDuplication() ) {
3273                 return false;
3274             }
3275             if ( !e2.isSpeciationOrDuplication() ) {
3276                 return false;
3277             }
3278             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3279                 return false;
3280             }
3281             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3282                 return false;
3283             }
3284             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3285                 return false;
3286             }
3287             if ( e11.isEqual( e2 ) ) {
3288                 return false;
3289             }
3290             final Event e2c = ( Event ) e2.copy();
3291             if ( !e2c.isEqual( e2 ) ) {
3292                 return false;
3293             }
3294             Event e3 = new Event( 1, 2, 3 );
3295             if ( e3.isDuplication() ) {
3296                 return false;
3297             }
3298             if ( e3.isSpeciation() ) {
3299                 return false;
3300             }
3301             if ( e3.isGeneLoss() ) {
3302                 return false;
3303             }
3304             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3305                 return false;
3306             }
3307             final Event e3c = ( Event ) e3.copy();
3308             final Event e3cc = ( Event ) e3c.copy();
3309             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3310                 return false;
3311             }
3312             e3 = null;
3313             if ( !e3c.isEqual( e3cc ) ) {
3314                 return false;
3315             }
3316             Event e4 = new Event( 1, 2, 3 );
3317             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3318                 return false;
3319             }
3320             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3321                 return false;
3322             }
3323             final Event e4c = ( Event ) e4.copy();
3324             e4 = null;
3325             final Event e4cc = ( Event ) e4c.copy();
3326             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3327                 return false;
3328             }
3329             if ( !e4c.isEqual( e4cc ) ) {
3330                 return false;
3331             }
3332             final Event e5 = new Event();
3333             if ( !e5.isUnassigned() ) {
3334                 return false;
3335             }
3336             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3337                 return false;
3338             }
3339             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3340                 return false;
3341             }
3342             final Event e6 = new Event( 1, 0, 0 );
3343             if ( !e6.asText().toString().equals( "duplication" ) ) {
3344                 return false;
3345             }
3346             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3347                 return false;
3348             }
3349             final Event e7 = new Event( 0, 1, 0 );
3350             if ( !e7.asText().toString().equals( "speciation" ) ) {
3351                 return false;
3352             }
3353             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3354                 return false;
3355             }
3356             final Event e8 = new Event( 0, 0, 1 );
3357             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3358                 return false;
3359             }
3360             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3361                 return false;
3362             }
3363         }
3364         catch ( final Exception e ) {
3365             e.printStackTrace( System.out );
3366             return false;
3367         }
3368         return true;
3369     }
3370
3371     private static boolean testDeletionOfExternalNodes() {
3372         try {
3373             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3374             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3375             final PhylogenyWriter w = new PhylogenyWriter();
3376             if ( t0.isEmpty() ) {
3377                 return false;
3378             }
3379             if ( t0.getNumberOfExternalNodes() != 1 ) {
3380                 return false;
3381             }
3382             t0.deleteSubtree( t0.getNode( "A" ), false );
3383             if ( t0.getNumberOfExternalNodes() != 0 ) {
3384                 return false;
3385             }
3386             if ( !t0.isEmpty() ) {
3387                 return false;
3388             }
3389             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3390             if ( t1.getNumberOfExternalNodes() != 2 ) {
3391                 return false;
3392             }
3393             t1.deleteSubtree( t1.getNode( "A" ), false );
3394             if ( t1.getNumberOfExternalNodes() != 1 ) {
3395                 return false;
3396             }
3397             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3398                 return false;
3399             }
3400             t1.deleteSubtree( t1.getNode( "B" ), false );
3401             if ( t1.getNumberOfExternalNodes() != 1 ) {
3402                 return false;
3403             }
3404             t1.deleteSubtree( t1.getNode( "r" ), false );
3405             if ( !t1.isEmpty() ) {
3406                 return false;
3407             }
3408             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3409             if ( t2.getNumberOfExternalNodes() != 3 ) {
3410                 return false;
3411             }
3412             t2.deleteSubtree( t2.getNode( "B" ), false );
3413             if ( t2.getNumberOfExternalNodes() != 2 ) {
3414                 return false;
3415             }
3416             t2.toNewHampshireX();
3417             PhylogenyNode n = t2.getNode( "A" );
3418             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3419                 return false;
3420             }
3421             t2.deleteSubtree( t2.getNode( "A" ), false );
3422             if ( t2.getNumberOfExternalNodes() != 2 ) {
3423                 return false;
3424             }
3425             t2.deleteSubtree( t2.getNode( "C" ), true );
3426             if ( t2.getNumberOfExternalNodes() != 1 ) {
3427                 return false;
3428             }
3429             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3430             if ( t3.getNumberOfExternalNodes() != 4 ) {
3431                 return false;
3432             }
3433             t3.deleteSubtree( t3.getNode( "B" ), true );
3434             if ( t3.getNumberOfExternalNodes() != 3 ) {
3435                 return false;
3436             }
3437             n = t3.getNode( "A" );
3438             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3439                 return false;
3440             }
3441             n = n.getNextExternalNode();
3442             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3443                 return false;
3444             }
3445             t3.deleteSubtree( t3.getNode( "A" ), true );
3446             if ( t3.getNumberOfExternalNodes() != 2 ) {
3447                 return false;
3448             }
3449             n = t3.getNode( "C" );
3450             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3451                 return false;
3452             }
3453             t3.deleteSubtree( t3.getNode( "C" ), true );
3454             if ( t3.getNumberOfExternalNodes() != 1 ) {
3455                 return false;
3456             }
3457             t3.deleteSubtree( t3.getNode( "D" ), true );
3458             if ( t3.getNumberOfExternalNodes() != 0 ) {
3459                 return false;
3460             }
3461             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3462             if ( t4.getNumberOfExternalNodes() != 6 ) {
3463                 return false;
3464             }
3465             t4.deleteSubtree( t4.getNode( "B2" ), true );
3466             if ( t4.getNumberOfExternalNodes() != 5 ) {
3467                 return false;
3468             }
3469             String s = w.toNewHampshire( t4, true ).toString();
3470             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3471                 return false;
3472             }
3473             t4.deleteSubtree( t4.getNode( "B11" ), true );
3474             if ( t4.getNumberOfExternalNodes() != 4 ) {
3475                 return false;
3476             }
3477             t4.deleteSubtree( t4.getNode( "C" ), true );
3478             if ( t4.getNumberOfExternalNodes() != 3 ) {
3479                 return false;
3480             }
3481             n = t4.getNode( "A" );
3482             n = n.getNextExternalNode();
3483             if ( !n.getName().equals( "B12" ) ) {
3484                 return false;
3485             }
3486             n = n.getNextExternalNode();
3487             if ( !n.getName().equals( "D" ) ) {
3488                 return false;
3489             }
3490             s = w.toNewHampshire( t4, true ).toString();
3491             if ( !s.equals( "((A,B12),D);" ) ) {
3492                 return false;
3493             }
3494             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3495             t5.deleteSubtree( t5.getNode( "A" ), true );
3496             if ( t5.getNumberOfExternalNodes() != 5 ) {
3497                 return false;
3498             }
3499             s = w.toNewHampshire( t5, true ).toString();
3500             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3501                 return false;
3502             }
3503             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3504             t6.deleteSubtree( t6.getNode( "B11" ), true );
3505             if ( t6.getNumberOfExternalNodes() != 5 ) {
3506                 return false;
3507             }
3508             s = w.toNewHampshire( t6, false ).toString();
3509             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3510                 return false;
3511             }
3512             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3513             t7.deleteSubtree( t7.getNode( "B12" ), true );
3514             if ( t7.getNumberOfExternalNodes() != 5 ) {
3515                 return false;
3516             }
3517             s = w.toNewHampshire( t7, true ).toString();
3518             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3519                 return false;
3520             }
3521             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3522             t8.deleteSubtree( t8.getNode( "B2" ), true );
3523             if ( t8.getNumberOfExternalNodes() != 5 ) {
3524                 return false;
3525             }
3526             s = w.toNewHampshire( t8, false ).toString();
3527             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3528                 return false;
3529             }
3530             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3531             t9.deleteSubtree( t9.getNode( "C" ), true );
3532             if ( t9.getNumberOfExternalNodes() != 5 ) {
3533                 return false;
3534             }
3535             s = w.toNewHampshire( t9, true ).toString();
3536             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3537                 return false;
3538             }
3539             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3540             t10.deleteSubtree( t10.getNode( "D" ), true );
3541             if ( t10.getNumberOfExternalNodes() != 5 ) {
3542                 return false;
3543             }
3544             s = w.toNewHampshire( t10, true ).toString();
3545             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3546                 return false;
3547             }
3548             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3549             t11.deleteSubtree( t11.getNode( "A" ), true );
3550             if ( t11.getNumberOfExternalNodes() != 2 ) {
3551                 return false;
3552             }
3553             s = w.toNewHampshire( t11, true ).toString();
3554             if ( !s.equals( "(B,C);" ) ) {
3555                 return false;
3556             }
3557             t11.deleteSubtree( t11.getNode( "C" ), true );
3558             if ( t11.getNumberOfExternalNodes() != 1 ) {
3559                 return false;
3560             }
3561             s = w.toNewHampshire( t11, false ).toString();
3562             if ( !s.equals( "B;" ) ) {
3563                 return false;
3564             }
3565             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3566             t12.deleteSubtree( t12.getNode( "B2" ), true );
3567             if ( t12.getNumberOfExternalNodes() != 8 ) {
3568                 return false;
3569             }
3570             s = w.toNewHampshire( t12, true ).toString();
3571             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3572                 return false;
3573             }
3574             t12.deleteSubtree( t12.getNode( "B3" ), true );
3575             if ( t12.getNumberOfExternalNodes() != 7 ) {
3576                 return false;
3577             }
3578             s = w.toNewHampshire( t12, true ).toString();
3579             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3580                 return false;
3581             }
3582             t12.deleteSubtree( t12.getNode( "C3" ), true );
3583             if ( t12.getNumberOfExternalNodes() != 6 ) {
3584                 return false;
3585             }
3586             s = w.toNewHampshire( t12, true ).toString();
3587             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3588                 return false;
3589             }
3590             t12.deleteSubtree( t12.getNode( "A1" ), true );
3591             if ( t12.getNumberOfExternalNodes() != 5 ) {
3592                 return false;
3593             }
3594             s = w.toNewHampshire( t12, true ).toString();
3595             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3596                 return false;
3597             }
3598             t12.deleteSubtree( t12.getNode( "B1" ), true );
3599             if ( t12.getNumberOfExternalNodes() != 4 ) {
3600                 return false;
3601             }
3602             s = w.toNewHampshire( t12, true ).toString();
3603             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3604                 return false;
3605             }
3606             t12.deleteSubtree( t12.getNode( "A3" ), true );
3607             if ( t12.getNumberOfExternalNodes() != 3 ) {
3608                 return false;
3609             }
3610             s = w.toNewHampshire( t12, true ).toString();
3611             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3612                 return false;
3613             }
3614             t12.deleteSubtree( t12.getNode( "A2" ), true );
3615             if ( t12.getNumberOfExternalNodes() != 2 ) {
3616                 return false;
3617             }
3618             s = w.toNewHampshire( t12, true ).toString();
3619             if ( !s.equals( "(C1,C2);" ) ) {
3620                 return false;
3621             }
3622             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3623             t13.deleteSubtree( t13.getNode( "D" ), true );
3624             if ( t13.getNumberOfExternalNodes() != 4 ) {
3625                 return false;
3626             }
3627             s = w.toNewHampshire( t13, true ).toString();
3628             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3629                 return false;
3630             }
3631             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3632             t14.deleteSubtree( t14.getNode( "E" ), true );
3633             if ( t14.getNumberOfExternalNodes() != 5 ) {
3634                 return false;
3635             }
3636             s = w.toNewHampshire( t14, true ).toString();
3637             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3638                 return false;
3639             }
3640             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3641             t15.deleteSubtree( t15.getNode( "B2" ), true );
3642             if ( t15.getNumberOfExternalNodes() != 11 ) {
3643                 return false;
3644             }
3645             t15.deleteSubtree( t15.getNode( "B1" ), true );
3646             if ( t15.getNumberOfExternalNodes() != 10 ) {
3647                 return false;
3648             }
3649             t15.deleteSubtree( t15.getNode( "B3" ), true );
3650             if ( t15.getNumberOfExternalNodes() != 9 ) {
3651                 return false;
3652             }
3653             t15.deleteSubtree( t15.getNode( "B4" ), true );
3654             if ( t15.getNumberOfExternalNodes() != 8 ) {
3655                 return false;
3656             }
3657             t15.deleteSubtree( t15.getNode( "A1" ), true );
3658             if ( t15.getNumberOfExternalNodes() != 7 ) {
3659                 return false;
3660             }
3661             t15.deleteSubtree( t15.getNode( "C4" ), true );
3662             if ( t15.getNumberOfExternalNodes() != 6 ) {
3663                 return false;
3664             }
3665         }
3666         catch ( final Exception e ) {
3667             e.printStackTrace( System.out );
3668             return false;
3669         }
3670         return true;
3671     }
3672
3673     private static boolean testDescriptiveStatistics() {
3674         try {
3675             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3676             dss1.addValue( 82 );
3677             dss1.addValue( 78 );
3678             dss1.addValue( 70 );
3679             dss1.addValue( 58 );
3680             dss1.addValue( 42 );
3681             if ( dss1.getN() != 5 ) {
3682                 return false;
3683             }
3684             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3685                 return false;
3686             }
3687             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3688                 return false;
3689             }
3690             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3691                 return false;
3692             }
3693             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3694                 return false;
3695             }
3696             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3697                 return false;
3698             }
3699             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3700                 return false;
3701             }
3702             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3703                 return false;
3704             }
3705             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3706                 return false;
3707             }
3708             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3709                 return false;
3710             }
3711             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3712                 return false;
3713             }
3714             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3715                 return false;
3716             }
3717             dss1.addValue( 123 );
3718             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3719                 return false;
3720             }
3721             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3722                 return false;
3723             }
3724             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3725                 return false;
3726             }
3727             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3728             dss2.addValue( -1.85 );
3729             dss2.addValue( 57.5 );
3730             dss2.addValue( 92.78 );
3731             dss2.addValue( 57.78 );
3732             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3733                 return false;
3734             }
3735             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3736                 return false;
3737             }
3738             final double[] a = dss2.getDataAsDoubleArray();
3739             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3740                 return false;
3741             }
3742             dss2.addValue( -100 );
3743             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3744                 return false;
3745             }
3746             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3747                 return false;
3748             }
3749             final double[] ds = new double[ 14 ];
3750             ds[ 0 ] = 34;
3751             ds[ 1 ] = 23;
3752             ds[ 2 ] = 1;
3753             ds[ 3 ] = 32;
3754             ds[ 4 ] = 11;
3755             ds[ 5 ] = 2;
3756             ds[ 6 ] = 12;
3757             ds[ 7 ] = 33;
3758             ds[ 8 ] = 13;
3759             ds[ 9 ] = 22;
3760             ds[ 10 ] = 21;
3761             ds[ 11 ] = 35;
3762             ds[ 12 ] = 24;
3763             ds[ 13 ] = 31;
3764             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3765             if ( bins.length != 4 ) {
3766                 return false;
3767             }
3768             if ( bins[ 0 ] != 2 ) {
3769                 return false;
3770             }
3771             if ( bins[ 1 ] != 3 ) {
3772                 return false;
3773             }
3774             if ( bins[ 2 ] != 4 ) {
3775                 return false;
3776             }
3777             if ( bins[ 3 ] != 5 ) {
3778                 return false;
3779             }
3780             final double[] ds1 = new double[ 9 ];
3781             ds1[ 0 ] = 10.0;
3782             ds1[ 1 ] = 19.0;
3783             ds1[ 2 ] = 9.999;
3784             ds1[ 3 ] = 0.0;
3785             ds1[ 4 ] = 39.9;
3786             ds1[ 5 ] = 39.999;
3787             ds1[ 6 ] = 30.0;
3788             ds1[ 7 ] = 19.999;
3789             ds1[ 8 ] = 30.1;
3790             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3791             if ( bins1.length != 4 ) {
3792                 return false;
3793             }
3794             if ( bins1[ 0 ] != 2 ) {
3795                 return false;
3796             }
3797             if ( bins1[ 1 ] != 3 ) {
3798                 return false;
3799             }
3800             if ( bins1[ 2 ] != 0 ) {
3801                 return false;
3802             }
3803             if ( bins1[ 3 ] != 4 ) {
3804                 return false;
3805             }
3806             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3807             if ( bins1_1.length != 3 ) {
3808                 return false;
3809             }
3810             if ( bins1_1[ 0 ] != 3 ) {
3811                 return false;
3812             }
3813             if ( bins1_1[ 1 ] != 2 ) {
3814                 return false;
3815             }
3816             if ( bins1_1[ 2 ] != 4 ) {
3817                 return false;
3818             }
3819             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3820             if ( bins1_2.length != 3 ) {
3821                 return false;
3822             }
3823             if ( bins1_2[ 0 ] != 2 ) {
3824                 return false;
3825             }
3826             if ( bins1_2[ 1 ] != 2 ) {
3827                 return false;
3828             }
3829             if ( bins1_2[ 2 ] != 2 ) {
3830                 return false;
3831             }
3832             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3833             dss3.addValue( 1 );
3834             dss3.addValue( 1 );
3835             dss3.addValue( 1 );
3836             dss3.addValue( 2 );
3837             dss3.addValue( 3 );
3838             dss3.addValue( 4 );
3839             dss3.addValue( 5 );
3840             dss3.addValue( 5 );
3841             dss3.addValue( 5 );
3842             dss3.addValue( 6 );
3843             dss3.addValue( 7 );
3844             dss3.addValue( 8 );
3845             dss3.addValue( 9 );
3846             dss3.addValue( 10 );
3847             dss3.addValue( 10 );
3848             dss3.addValue( 10 );
3849             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3850             histo.toStringBuffer( 10, '=', 40, 5 );
3851             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3852         }
3853         catch ( final Exception e ) {
3854             e.printStackTrace( System.out );
3855             return false;
3856         }
3857         return true;
3858     }
3859
3860     private static boolean testDir( final String file ) {
3861         try {
3862             final File f = new File( file );
3863             if ( !f.exists() ) {
3864                 return false;
3865             }
3866             if ( !f.isDirectory() ) {
3867                 return false;
3868             }
3869             if ( !f.canRead() ) {
3870                 return false;
3871             }
3872         }
3873         catch ( final Exception e ) {
3874             return false;
3875         }
3876         return true;
3877     }
3878
3879     private static boolean testEbiEntryRetrieval() {
3880         try {
3881             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
3882             if ( !entry.getAccession().equals( "AAK41263" ) ) {
3883                 System.out.println( entry.getAccession() );
3884                 return false;
3885             }
3886             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
3887                 System.out.println( entry.getTaxonomyScientificName() );
3888                 return false;
3889             }
3890             if ( !entry.getSequenceName()
3891                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
3892                 System.out.println( entry.getSequenceName() );
3893                 return false;
3894             }
3895             // if ( !entry.getSequenceSymbol().equals( "" ) ) {
3896             //     System.out.println( entry.getSequenceSymbol() );
3897             //     return false;
3898             // }
3899             if ( !entry.getGeneName().equals( "treX-like" ) ) {
3900                 System.out.println( entry.getGeneName() );
3901                 return false;
3902             }
3903             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
3904                 System.out.println( entry.getTaxonomyIdentifier() );
3905                 return false;
3906             }
3907             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
3908                 System.out.println( entry.getAnnotations().first().getRefValue() );
3909                 return false;
3910             }
3911             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
3912                 System.out.println( entry.getAnnotations().first().getRefSource() );
3913                 return false;
3914             }
3915             if ( entry.getCrossReferences().size() != 5 ) {
3916                 return false;
3917             }
3918             //
3919             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
3920             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
3921                 return false;
3922             }
3923             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
3924                 System.out.println( entry1.getTaxonomyScientificName() );
3925                 return false;
3926             }
3927             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
3928                 System.out.println( entry1.getSequenceName() );
3929                 return false;
3930             }
3931             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
3932                 System.out.println( entry1.getTaxonomyIdentifier() );
3933                 return false;
3934             }
3935             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
3936                 System.out.println( entry1.getGeneName() );
3937                 return false;
3938             }
3939             if ( entry1.getCrossReferences().size() != 6 ) {
3940                 return false;
3941             }
3942             //
3943             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
3944             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
3945                 return false;
3946             }
3947             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
3948                 System.out.println( entry2.getTaxonomyScientificName() );
3949                 return false;
3950             }
3951             if ( !entry2.getSequenceName()
3952                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
3953                 System.out.println( entry2.getSequenceName() );
3954                 return false;
3955             }
3956             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
3957                 System.out.println( entry2.getTaxonomyIdentifier() );
3958                 return false;
3959             }
3960             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
3961                 System.out.println( entry2.getGeneName() );
3962                 return false;
3963             }
3964             if ( entry2.getCrossReferences().size() != 3 ) {
3965                 return false;
3966             }
3967             //
3968             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
3969             if ( !entry3.getAccession().equals( "HM043801" ) ) {
3970                 return false;
3971             }
3972             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
3973                 System.out.println( entry3.getTaxonomyScientificName() );
3974                 return false;
3975             }
3976             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
3977                 System.out.println( entry3.getSequenceName() );
3978                 return false;
3979             }
3980             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
3981                 System.out.println( entry3.getTaxonomyIdentifier() );
3982                 return false;
3983             }
3984             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
3985                 System.out.println( entry3.getSequenceSymbol() );
3986                 return false;
3987             }
3988             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
3989                 return false;
3990             }
3991             if ( entry3.getCrossReferences().size() != 8 ) {
3992                 return false;
3993             }
3994             //
3995             //
3996             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
3997             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
3998                 return false;
3999             }
4000             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4001                 System.out.println( entry4.getTaxonomyScientificName() );
4002                 return false;
4003             }
4004             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4005                 System.out.println( entry4.getSequenceName() );
4006                 return false;
4007             }
4008             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4009                 System.out.println( entry4.getTaxonomyIdentifier() );
4010                 return false;
4011             }
4012             if ( !entry4.getGeneName().equals( "ras" ) ) {
4013                 System.out.println( entry4.getGeneName() );
4014                 return false;
4015             }
4016             //   if ( !entry4.getChromosome().equals( "ras" ) ) {
4017             //     System.out.println( entry4.getChromosome() );
4018             //     return false;
4019             // }
4020             // if ( !entry4.getMap().equals( "ras" ) ) {
4021             //     System.out.println( entry4.getMap() );
4022             //     return false;
4023             // }
4024             //TODO FIXME gi...
4025             //
4026             //TODO fails:
4027             //            final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "M30539" );
4028             //            if ( !entry5.getAccession().equals( "HM043801" ) ) {
4029             //                return false;
4030             //            }
4031             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4032             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4033                 return false;
4034             }
4035             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4036                 System.out.println( entry5.getTaxonomyScientificName() );
4037                 return false;
4038             }
4039             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4040                 System.out.println( entry5.getSequenceName() );
4041                 return false;
4042             }
4043             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4044                 System.out.println( entry5.getTaxonomyIdentifier() );
4045                 return false;
4046             }
4047         }
4048         catch ( final IOException e ) {
4049             System.out.println();
4050             System.out.println( "the following might be due to absence internet connection:" );
4051             e.printStackTrace( System.out );
4052             return true;
4053         }
4054         catch ( final Exception e ) {
4055             e.printStackTrace();
4056             return false;
4057         }
4058         return true;
4059     }
4060
4061     private static boolean testExternalNodeRelatedMethods() {
4062         try {
4063             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4064             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4065             PhylogenyNode n = t1.getNode( "A" );
4066             n = n.getNextExternalNode();
4067             if ( !n.getName().equals( "B" ) ) {
4068                 return false;
4069             }
4070             n = n.getNextExternalNode();
4071             if ( !n.getName().equals( "C" ) ) {
4072                 return false;
4073             }
4074             n = n.getNextExternalNode();
4075             if ( !n.getName().equals( "D" ) ) {
4076                 return false;
4077             }
4078             n = t1.getNode( "B" );
4079             while ( !n.isLastExternalNode() ) {
4080                 n = n.getNextExternalNode();
4081             }
4082             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4083             n = t2.getNode( "A" );
4084             n = n.getNextExternalNode();
4085             if ( !n.getName().equals( "B" ) ) {
4086                 return false;
4087             }
4088             n = n.getNextExternalNode();
4089             if ( !n.getName().equals( "C" ) ) {
4090                 return false;
4091             }
4092             n = n.getNextExternalNode();
4093             if ( !n.getName().equals( "D" ) ) {
4094                 return false;
4095             }
4096             n = t2.getNode( "B" );
4097             while ( !n.isLastExternalNode() ) {
4098                 n = n.getNextExternalNode();
4099             }
4100             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4101             n = t3.getNode( "A" );
4102             n = n.getNextExternalNode();
4103             if ( !n.getName().equals( "B" ) ) {
4104                 return false;
4105             }
4106             n = n.getNextExternalNode();
4107             if ( !n.getName().equals( "C" ) ) {
4108                 return false;
4109             }
4110             n = n.getNextExternalNode();
4111             if ( !n.getName().equals( "D" ) ) {
4112                 return false;
4113             }
4114             n = n.getNextExternalNode();
4115             if ( !n.getName().equals( "E" ) ) {
4116                 return false;
4117             }
4118             n = n.getNextExternalNode();
4119             if ( !n.getName().equals( "F" ) ) {
4120                 return false;
4121             }
4122             n = n.getNextExternalNode();
4123             if ( !n.getName().equals( "G" ) ) {
4124                 return false;
4125             }
4126             n = n.getNextExternalNode();
4127             if ( !n.getName().equals( "H" ) ) {
4128                 return false;
4129             }
4130             n = t3.getNode( "B" );
4131             while ( !n.isLastExternalNode() ) {
4132                 n = n.getNextExternalNode();
4133             }
4134             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4135             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4136                 final PhylogenyNode node = iter.next();
4137             }
4138             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4139             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4140                 final PhylogenyNode node = iter.next();
4141             }
4142             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4143             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4144             if ( !iter.next().getName().equals( "A" ) ) {
4145                 return false;
4146             }
4147             if ( !iter.next().getName().equals( "B" ) ) {
4148                 return false;
4149             }
4150             if ( !iter.next().getName().equals( "C" ) ) {
4151                 return false;
4152             }
4153             if ( !iter.next().getName().equals( "D" ) ) {
4154                 return false;
4155             }
4156             if ( !iter.next().getName().equals( "E" ) ) {
4157                 return false;
4158             }
4159             if ( !iter.next().getName().equals( "F" ) ) {
4160                 return false;
4161             }
4162             if ( iter.hasNext() ) {
4163                 return false;
4164             }
4165         }
4166         catch ( final Exception e ) {
4167             e.printStackTrace( System.out );
4168             return false;
4169         }
4170         return true;
4171     }
4172
4173     private static boolean testExtractSNFromNodeName() {
4174         try {
4175             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4176                 return false;
4177             }
4178             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4179                 return false;
4180             }
4181             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4182                 return false;
4183             }
4184             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4185                     .equals( "Mus musculus musculus" ) ) {
4186                 return false;
4187             }
4188             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4189                     .equals( "Mus musculus musculus" ) ) {
4190                 return false;
4191             }
4192             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4193                     .equals( "Mus musculus musculus" ) ) {
4194                 return false;
4195             }
4196             if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4197                     .equals( "Mus musculus musculus" ) ) {
4198                 return false;
4199             }
4200             if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4201                 return false;
4202             }
4203             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4204                     .equals( "Mus musculus musculus" ) ) {
4205                 return false;
4206             }
4207             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4208                     .equals( "Mus musculus musculus" ) ) {
4209                 return false;
4210             }
4211             if ( ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
4212                 return false;
4213             }
4214             if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
4215                 return false;
4216             }
4217             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
4218                 return false;
4219             }
4220             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
4221                 return false;
4222             }
4223             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
4224                     .equals( "Mus musculus musculus" ) ) {
4225                 return false;
4226             }
4227             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
4228                 return false;
4229             }
4230             if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
4231                 return false;
4232             }
4233             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
4234                 return false;
4235             }
4236             if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
4237                 return false;
4238             }
4239             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
4240                 return false;
4241             }
4242             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
4243                 return false;
4244             }
4245             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
4246                 return false;
4247             }
4248             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
4249                 return false;
4250             }
4251             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
4252                     .equals( "Mus musculus" ) ) {
4253                 return false;
4254             }
4255             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
4256                     .equals( "Mus musculus" ) ) {
4257                 return false;
4258             }
4259             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4260                 return false;
4261             }
4262             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4263                     .equals( "Mus musculus musculus" ) ) {
4264                 return false;
4265             }
4266             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4267                     .equals( "Mus musculus musculus" ) ) {
4268                 return false;
4269             }
4270             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
4271                     .equals( "Mus musculus musculus" ) ) {
4272                 return false;
4273             }
4274             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4275                 return false;
4276             }
4277             if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
4278                     .equals( "Pilostyles mexicana" ) ) {
4279                 return false;
4280             }
4281             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
4282                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
4283                 return false;
4284             }
4285             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
4286                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4287                 return false;
4288             }
4289             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
4290                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4291                 return false;
4292             }
4293             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
4294                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4295                 return false;
4296             }
4297             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
4298                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4299                 return false;
4300             }
4301             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
4302                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4303                 return false;
4304             }
4305             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
4306                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4307                 return false;
4308             }
4309             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
4310                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4311                 return false;
4312             }
4313             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
4314                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
4315                 return false;
4316             }
4317             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
4318                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
4319                 return false;
4320             }
4321             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
4322                     .equals( "Escherichia coli (strain K12)" ) ) {
4323                 return false;
4324             }
4325             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
4326                     .equals( "Escherichia coli (strain K12)" ) ) {
4327                 return false;
4328             }
4329             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
4330                     .equals( "Escherichia coli (str. K12)" ) ) {
4331                 return false;
4332             }
4333             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
4334                     .equals( "Escherichia coli (str. K12)" ) ) {
4335                 return false;
4336             }
4337             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
4338                     .equals( "Escherichia coli (str. K12)" ) ) {
4339                 return false;
4340             }
4341             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
4342                     .equals( "Escherichia coli (var. K12)" ) ) {
4343                 return false;
4344             }
4345             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K-12 substr. MG1655star" )
4346                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4347                 return false;
4348             }
4349             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star" )
4350                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4351                 return false;
4352             }
4353             if ( !ParserUtils
4354                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star" )
4355                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4356                 return false;
4357             }
4358             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
4359                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4360                 return false;
4361             }
4362             if ( !ParserUtils
4363                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
4364                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4365                 return false;
4366             }
4367             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4368                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4369                 return false;
4370             }
4371             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4372                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4373                 return false;
4374             }
4375             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
4376                 return false;
4377             }
4378             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
4379                 return false;
4380             }
4381             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
4382                 return false;
4383             }
4384             if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
4385                     .equals( "Macrocera sp." ) ) {
4386                 return false;
4387             }
4388             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
4389                 return false;
4390             }
4391             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
4392                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4393                 return false;
4394             }
4395             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
4396                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4397                 return false;
4398             }
4399             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
4400                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4401                 return false;
4402             }
4403             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
4404                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4405                 return false;
4406             }
4407         }
4408         catch ( final Exception e ) {
4409             e.printStackTrace( System.out );
4410             return false;
4411         }
4412         return true;
4413     }
4414
4415     private static boolean testExtractTaxonomyCodeFromNodeName() {
4416         try {
4417             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4418                 return false;
4419             }
4420             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4421                     .equals( "SOYBN" ) ) {
4422                 return false;
4423             }
4424             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4425                     .equals( "ARATH" ) ) {
4426                 return false;
4427             }
4428             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4429                     .equals( "ARATH" ) ) {
4430                 return false;
4431             }
4432             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4433                 return false;
4434             }
4435             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4436                 return false;
4437             }
4438             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4439                 return false;
4440             }
4441             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4442                     .equals( "SOYBN" ) ) {
4443                 return false;
4444             }
4445             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4446                     .equals( "SOYBN" ) ) {
4447                 return false;
4448             }
4449             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4450                     .equals( "SOYBN" ) ) {
4451                 return false;
4452             }
4453             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4454                     .equals( "SOYBN" ) ) {
4455                 return false;
4456             }
4457             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4458                     .equals( "SOYBN" ) ) {
4459                 return false;
4460             }
4461             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4462                     .equals( "SOYBN" ) ) {
4463                 return false;
4464             }
4465             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4466                     .equals( "SOYBN" ) ) {
4467                 return false;
4468             }
4469             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
4470                     .equals( "SOYBN" ) ) {
4471                 return false;
4472             }
4473             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
4474                 return false;
4475             }
4476             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
4477                     .equals( "SOYBN" ) ) {
4478                 return false;
4479             }
4480             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
4481                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
4482                 return false;
4483             }
4484             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
4485                     .equals( "9YX45" ) ) {
4486                 return false;
4487             }
4488             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
4489                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4490                     .equals( "MOUSE" ) ) {
4491                 return false;
4492             }
4493             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
4494                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4495                     .equals( "MOUSE" ) ) {
4496                 return false;
4497             }
4498             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
4499                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4500                     .equals( "MOUSE" ) ) {
4501                 return false;
4502             }
4503             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
4504                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4505                 return false;
4506             }
4507             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
4508                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4509                 return false;
4510             }
4511             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4512                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4513                 return false;
4514             }
4515             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4516                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4517                 return false;
4518             }
4519             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
4520                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4521                 return false;
4522             }
4523             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
4524                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4525                 return false;
4526             }
4527             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
4528                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4529                 return false;
4530             }
4531             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4532                     .equals( "RAT" ) ) {
4533                 return false;
4534             }
4535             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4536                     .equals( "PIG" ) ) {
4537                 return false;
4538             }
4539             if ( !ParserUtils
4540                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4541                     .equals( "MOUSE" ) ) {
4542                 return false;
4543             }
4544             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4545                     .equals( "MOUSE" ) ) {
4546                 return false;
4547             }
4548             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4549                 return false;
4550             }
4551         }
4552         catch ( final Exception e ) {
4553             e.printStackTrace( System.out );
4554             return false;
4555         }
4556         return true;
4557     }
4558
4559     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
4560         try {
4561             PhylogenyNode n = new PhylogenyNode();
4562             n.setName( "tr|B3RJ64" );
4563             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4564                 return false;
4565             }
4566             n.setName( "tr.B3RJ64" );
4567             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4568                 return false;
4569             }
4570             n.setName( "tr=B3RJ64" );
4571             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4572                 return false;
4573             }
4574             n.setName( "tr-B3RJ64" );
4575             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4576                 return false;
4577             }
4578             n.setName( "tr/B3RJ64" );
4579             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4580                 return false;
4581             }
4582             n.setName( "tr\\B3RJ64" );
4583             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4584                 return false;
4585             }
4586             n.setName( "tr_B3RJ64" );
4587             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4588                 return false;
4589             }
4590             n.setName( " tr|B3RJ64 " );
4591             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4592                 return false;
4593             }
4594             n.setName( "-tr|B3RJ64-" );
4595             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4596                 return false;
4597             }
4598             n.setName( "-tr=B3RJ64-" );
4599             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4600                 return false;
4601             }
4602             n.setName( "_tr=B3RJ64_" );
4603             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4604                 return false;
4605             }
4606             n.setName( " tr_tr|B3RJ64_sp|123 " );
4607             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4608                 return false;
4609             }
4610             n.setName( "B3RJ64" );
4611             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4612                 return false;
4613             }
4614             n.setName( "sp|B3RJ64" );
4615             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4616                 return false;
4617             }
4618             n.setName( "sp|B3RJ64C" );
4619             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4620                 return false;
4621             }
4622             n.setName( "sp B3RJ64" );
4623             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4624                 return false;
4625             }
4626             n.setName( "sp|B3RJ6X" );
4627             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4628                 return false;
4629             }
4630             n.setName( "sp|B3RJ6" );
4631             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4632                 return false;
4633             }
4634             n.setName( "K1PYK7_CRAGI" );
4635             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4636                 return false;
4637             }
4638             n.setName( "K1PYK7_PEA" );
4639             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
4640                 return false;
4641             }
4642             n.setName( "K1PYK7_RAT" );
4643             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
4644                 return false;
4645             }
4646             n.setName( "K1PYK7_PIG" );
4647             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4648                 return false;
4649             }
4650             n.setName( "~K1PYK7_PIG~" );
4651             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4652                 return false;
4653             }
4654             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
4655             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4656                 return false;
4657             }
4658             n.setName( "K1PYKX_CRAGI" );
4659             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4660                 return false;
4661             }
4662             n.setName( "XXXXX_CRAGI" );
4663             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
4664                 return false;
4665             }
4666             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
4667             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
4668                 return false;
4669             }
4670             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
4671             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4672                 return false;
4673             }
4674             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
4675             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
4676                 return false;
4677             }
4678             n = new PhylogenyNode();
4679             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
4680             seq.setSymbol( "K1PYK7_CRAGI" );
4681             n.getNodeData().addSequence( seq );
4682             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4683                 return false;
4684             }
4685             seq.setSymbol( "tr|B3RJ64" );
4686             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4687                 return false;
4688             }
4689             n = new PhylogenyNode();
4690             seq = new org.forester.phylogeny.data.Sequence();
4691             seq.setName( "K1PYK7_CRAGI" );
4692             n.getNodeData().addSequence( seq );
4693             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4694                 return false;
4695             }
4696             seq.setName( "tr|B3RJ64" );
4697             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4698                 return false;
4699             }
4700             n = new PhylogenyNode();
4701             seq = new org.forester.phylogeny.data.Sequence();
4702             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4703             n.getNodeData().addSequence( seq );
4704             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
4705                 return false;
4706             }
4707             n = new PhylogenyNode();
4708             seq = new org.forester.phylogeny.data.Sequence();
4709             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4710             n.getNodeData().addSequence( seq );
4711             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4712                 return false;
4713             }
4714             //
4715             n = new PhylogenyNode();
4716             n.setName( "ACP19736" );
4717             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4718                 return false;
4719             }
4720             n = new PhylogenyNode();
4721             n.setName( "|ACP19736|" );
4722             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4723                 return false;
4724             }
4725         }
4726         catch ( final Exception e ) {
4727             e.printStackTrace( System.out );
4728             return false;
4729         }
4730         return true;
4731     }
4732
4733     private static boolean testFastaParser() {
4734         try {
4735             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
4736                 return false;
4737             }
4738             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
4739                 return false;
4740             }
4741             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
4742             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
4743                 return false;
4744             }
4745             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
4746                 return false;
4747             }
4748             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
4749                 return false;
4750             }
4751             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
4752                 return false;
4753             }
4754             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
4755                 return false;
4756             }
4757             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
4758                 return false;
4759             }
4760         }
4761         catch ( final Exception e ) {
4762             e.printStackTrace();
4763             return false;
4764         }
4765         return true;
4766     }
4767
4768     private static boolean testGenbankAccessorParsing() {
4769         //The format for GenBank Accession numbers are:
4770         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
4771         //Protein:    3 letters + 5 numerals
4772         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
4773         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
4774             return false;
4775         }
4776         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
4777             return false;
4778         }
4779         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
4780             return false;
4781         }
4782         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
4783             return false;
4784         }
4785         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
4786             return false;
4787         }
4788         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
4789             return false;
4790         }
4791         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
4792             return false;
4793         }
4794         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
4795             return false;
4796         }
4797         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
4798             return false;
4799         }
4800         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
4801             return false;
4802         }
4803         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
4804             return false;
4805         }
4806         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
4807             return false;
4808         }
4809         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
4810             return false;
4811         }
4812         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
4813             return false;
4814         }
4815         return true;
4816     }
4817
4818     private static boolean testGeneralMsaParser() {
4819         try {
4820             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
4821             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
4822             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
4823             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
4824             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
4825             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
4826             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
4827             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
4828             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4829                 return false;
4830             }
4831             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4832                 return false;
4833             }
4834             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4835                 return false;
4836             }
4837             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4838                 return false;
4839             }
4840             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4841                 return false;
4842             }
4843             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4844                 return false;
4845             }
4846             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4847                 return false;
4848             }
4849             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4850                 return false;
4851             }
4852             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4853                 return false;
4854             }
4855             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4856                 return false;
4857             }
4858             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4859                 return false;
4860             }
4861             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4862                 return false;
4863             }
4864             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
4865             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4866                 return false;
4867             }
4868             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4869                 return false;
4870             }
4871             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4872                 return false;
4873             }
4874             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
4875             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
4876                 return false;
4877             }
4878             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
4879                 return false;
4880             }
4881             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
4882                 return false;
4883             }
4884             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
4885             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4886                 return false;
4887             }
4888             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4889                 return false;
4890             }
4891             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
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 testGeneralTable() {
4903         try {
4904             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
4905             t0.setValue( 3, 2, "23" );
4906             t0.setValue( 10, 1, "error" );
4907             t0.setValue( 10, 1, "110" );
4908             t0.setValue( 9, 1, "19" );
4909             t0.setValue( 1, 10, "101" );
4910             t0.setValue( 10, 10, "1010" );
4911             t0.setValue( 100, 10, "10100" );
4912             t0.setValue( 0, 0, "00" );
4913             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
4914                 return false;
4915             }
4916             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
4917                 return false;
4918             }
4919             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
4920                 return false;
4921             }
4922             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
4923                 return false;
4924             }
4925             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
4926                 return false;
4927             }
4928             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
4929                 return false;
4930             }
4931             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
4932                 return false;
4933             }
4934             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
4935                 return false;
4936             }
4937             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
4938                 return false;
4939             }
4940             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
4941             t1.setValue( "3", "2", "23" );
4942             t1.setValue( "10", "1", "error" );
4943             t1.setValue( "10", "1", "110" );
4944             t1.setValue( "9", "1", "19" );
4945             t1.setValue( "1", "10", "101" );
4946             t1.setValue( "10", "10", "1010" );
4947             t1.setValue( "100", "10", "10100" );
4948             t1.setValue( "0", "0", "00" );
4949             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
4950             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
4951                 return false;
4952             }
4953             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
4954                 return false;
4955             }
4956             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
4957                 return false;
4958             }
4959             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
4960                 return false;
4961             }
4962             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
4963                 return false;
4964             }
4965             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
4966                 return false;
4967             }
4968             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
4969                 return false;
4970             }
4971             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
4972                 return false;
4973             }
4974             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
4975                 return false;
4976             }
4977             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
4978                 return false;
4979             }
4980         }
4981         catch ( final Exception e ) {
4982             e.printStackTrace( System.out );
4983             return false;
4984         }
4985         return true;
4986     }
4987
4988     private static boolean testGetDistance() {
4989         try {
4990             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4991             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",
4992                                                  new NHXParser() )[ 0 ];
4993             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
4994                 return false;
4995             }
4996             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
4997                 return false;
4998             }
4999             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5000                 return false;
5001             }
5002             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5003                 return false;
5004             }
5005             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5006                 return false;
5007             }
5008             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5009                 return false;
5010             }
5011             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5012                 return false;
5013             }
5014             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5015                 return false;
5016             }
5017             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5018                 return false;
5019             }
5020             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5021                 return false;
5022             }
5023             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5024                 return false;
5025             }
5026             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5027                 return false;
5028             }
5029             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5030                 return false;
5031             }
5032             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5033                 return false;
5034             }
5035             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5036                 return false;
5037             }
5038             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5039                 return false;
5040             }
5041             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5042                 return false;
5043             }
5044             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5045                 return false;
5046             }
5047             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5048                 return false;
5049             }
5050             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5051                 return false;
5052             }
5053             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5054                 return false;
5055             }
5056             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5057                 return false;
5058             }
5059             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5060                 return false;
5061             }
5062             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5063                 return false;
5064             }
5065             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5066                 return false;
5067             }
5068             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5069                 return false;
5070             }
5071             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5072                 return false;
5073             }
5074             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5075                 return false;
5076             }
5077             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5078                 return false;
5079             }
5080             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5081                 return false;
5082             }
5083             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5084                 return false;
5085             }
5086             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",
5087                                                  new NHXParser() )[ 0 ];
5088             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5089                 return false;
5090             }
5091             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5092                 return false;
5093             }
5094             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5095                 return false;
5096             }
5097             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5098                 return false;
5099             }
5100             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5101                 return false;
5102             }
5103             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5104                 return false;
5105             }
5106             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5107                 return false;
5108             }
5109             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5110                 return false;
5111             }
5112             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5113                 return false;
5114             }
5115             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5116                 return false;
5117             }
5118             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5119                 return false;
5120             }
5121         }
5122         catch ( final Exception e ) {
5123             e.printStackTrace( System.out );
5124             return false;
5125         }
5126         return true;
5127     }
5128
5129     private static boolean testGetLCA() {
5130         try {
5131             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5132             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5133                                                  new NHXParser() )[ 0 ];
5134             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5135             if ( !A.getName().equals( "A" ) ) {
5136                 return false;
5137             }
5138             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5139             if ( !gh.getName().equals( "gh" ) ) {
5140                 return false;
5141             }
5142             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5143             if ( !ab.getName().equals( "ab" ) ) {
5144                 return false;
5145             }
5146             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5147             if ( !ab2.getName().equals( "ab" ) ) {
5148                 return false;
5149             }
5150             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5151             if ( !gh2.getName().equals( "gh" ) ) {
5152                 return false;
5153             }
5154             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5155             if ( !gh3.getName().equals( "gh" ) ) {
5156                 return false;
5157             }
5158             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5159             if ( !abc.getName().equals( "abc" ) ) {
5160                 return false;
5161             }
5162             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5163             if ( !abc2.getName().equals( "abc" ) ) {
5164                 return false;
5165             }
5166             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5167             if ( !abcd.getName().equals( "abcd" ) ) {
5168                 return false;
5169             }
5170             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5171             if ( !abcd2.getName().equals( "abcd" ) ) {
5172                 return false;
5173             }
5174             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5175             if ( !abcdef.getName().equals( "abcdef" ) ) {
5176                 return false;
5177             }
5178             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5179             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5180                 return false;
5181             }
5182             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5183             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5184                 return false;
5185             }
5186             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5187             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5188                 return false;
5189             }
5190             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
5191             if ( !abcde.getName().equals( "abcde" ) ) {
5192                 return false;
5193             }
5194             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
5195             if ( !abcde2.getName().equals( "abcde" ) ) {
5196                 return false;
5197             }
5198             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
5199             if ( !r.getName().equals( "abcdefgh" ) ) {
5200                 return false;
5201             }
5202             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5203             if ( !r2.getName().equals( "abcdefgh" ) ) {
5204                 return false;
5205             }
5206             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5207             if ( !r3.getName().equals( "abcdefgh" ) ) {
5208                 return false;
5209             }
5210             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5211             if ( !abcde3.getName().equals( "abcde" ) ) {
5212                 return false;
5213             }
5214             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5215             if ( !abcde4.getName().equals( "abcde" ) ) {
5216                 return false;
5217             }
5218             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5219             if ( !ab3.getName().equals( "ab" ) ) {
5220                 return false;
5221             }
5222             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5223             if ( !ab4.getName().equals( "ab" ) ) {
5224                 return false;
5225             }
5226             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5227             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5228             if ( !cd.getName().equals( "cd" ) ) {
5229                 return false;
5230             }
5231             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5232             if ( !cd2.getName().equals( "cd" ) ) {
5233                 return false;
5234             }
5235             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5236             if ( !cde.getName().equals( "cde" ) ) {
5237                 return false;
5238             }
5239             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5240             if ( !cde2.getName().equals( "cde" ) ) {
5241                 return false;
5242             }
5243             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5244             if ( !cdef.getName().equals( "cdef" ) ) {
5245                 return false;
5246             }
5247             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5248             if ( !cdef2.getName().equals( "cdef" ) ) {
5249                 return false;
5250             }
5251             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5252             if ( !cdef3.getName().equals( "cdef" ) ) {
5253                 return false;
5254             }
5255             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5256             if ( !rt.getName().equals( "r" ) ) {
5257                 return false;
5258             }
5259             final Phylogeny p3 = factory
5260                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5261                              new NHXParser() )[ 0 ];
5262             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5263             if ( !bc_3.getName().equals( "bc" ) ) {
5264                 return false;
5265             }
5266             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5267             if ( !ac_3.getName().equals( "abc" ) ) {
5268                 return false;
5269             }
5270             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5271             if ( !ad_3.getName().equals( "abcde" ) ) {
5272                 return false;
5273             }
5274             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5275             if ( !af_3.getName().equals( "abcdef" ) ) {
5276                 return false;
5277             }
5278             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5279             if ( !ag_3.getName().equals( "" ) ) {
5280                 return false;
5281             }
5282             if ( !ag_3.isRoot() ) {
5283                 return false;
5284             }
5285             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5286             if ( !al_3.getName().equals( "" ) ) {
5287                 return false;
5288             }
5289             if ( !al_3.isRoot() ) {
5290                 return false;
5291             }
5292             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5293             if ( !kl_3.getName().equals( "" ) ) {
5294                 return false;
5295             }
5296             if ( !kl_3.isRoot() ) {
5297                 return false;
5298             }
5299             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5300             if ( !fl_3.getName().equals( "" ) ) {
5301                 return false;
5302             }
5303             if ( !fl_3.isRoot() ) {
5304                 return false;
5305             }
5306             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5307             if ( !gk_3.getName().equals( "ghijk" ) ) {
5308                 return false;
5309             }
5310             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5311             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5312             if ( !r_4.getName().equals( "r" ) ) {
5313                 return false;
5314             }
5315             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5316             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5317             if ( !r_5.getName().equals( "root" ) ) {
5318                 return false;
5319             }
5320             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5321             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5322             if ( !r_6.getName().equals( "rot" ) ) {
5323                 return false;
5324             }
5325             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5326             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5327             if ( !r_7.getName().equals( "rott" ) ) {
5328                 return false;
5329             }
5330         }
5331         catch ( final Exception e ) {
5332             e.printStackTrace( System.out );
5333             return false;
5334         }
5335         return true;
5336     }
5337
5338     private static boolean testGetLCA2() {
5339         try {
5340             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5341             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5342             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5343             PhylogenyMethods.preOrderReId( p_a );
5344             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5345                                                                                               p_a.getNode( "a" ) );
5346             if ( !p_a_1.getName().equals( "a" ) ) {
5347                 return false;
5348             }
5349             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5350             PhylogenyMethods.preOrderReId( p_b );
5351             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5352                                                                                               p_b.getNode( "a" ) );
5353             if ( !p_b_1.getName().equals( "b" ) ) {
5354                 return false;
5355             }
5356             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5357                                                                                               p_b.getNode( "b" ) );
5358             if ( !p_b_2.getName().equals( "b" ) ) {
5359                 return false;
5360             }
5361             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5362             PhylogenyMethods.preOrderReId( p_c );
5363             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5364                                                                                               p_c.getNode( "a" ) );
5365             if ( !p_c_1.getName().equals( "b" ) ) {
5366                 return false;
5367             }
5368             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5369                                                                                               p_c.getNode( "c" ) );
5370             if ( !p_c_2.getName().equals( "c" ) ) {
5371                 System.out.println( p_c_2.getName() );
5372                 System.exit( -1 );
5373                 return false;
5374             }
5375             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5376                                                                                               p_c.getNode( "b" ) );
5377             if ( !p_c_3.getName().equals( "b" ) ) {
5378                 return false;
5379             }
5380             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5381                                                                                               p_c.getNode( "a" ) );
5382             if ( !p_c_4.getName().equals( "c" ) ) {
5383                 return false;
5384             }
5385             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5386                                                  new NHXParser() )[ 0 ];
5387             PhylogenyMethods.preOrderReId( p1 );
5388             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5389                                                                                           p1.getNode( "A" ) );
5390             if ( !A.getName().equals( "A" ) ) {
5391                 return false;
5392             }
5393             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5394                                                                                            p1.getNode( "gh" ) );
5395             if ( !gh.getName().equals( "gh" ) ) {
5396                 return false;
5397             }
5398             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5399                                                                                            p1.getNode( "B" ) );
5400             if ( !ab.getName().equals( "ab" ) ) {
5401                 return false;
5402             }
5403             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5404                                                                                             p1.getNode( "A" ) );
5405             if ( !ab2.getName().equals( "ab" ) ) {
5406                 return false;
5407             }
5408             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5409                                                                                             p1.getNode( "G" ) );
5410             if ( !gh2.getName().equals( "gh" ) ) {
5411                 return false;
5412             }
5413             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5414                                                                                             p1.getNode( "H" ) );
5415             if ( !gh3.getName().equals( "gh" ) ) {
5416                 return false;
5417             }
5418             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5419                                                                                             p1.getNode( "A" ) );
5420             if ( !abc.getName().equals( "abc" ) ) {
5421                 return false;
5422             }
5423             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5424                                                                                              p1.getNode( "C" ) );
5425             if ( !abc2.getName().equals( "abc" ) ) {
5426                 return false;
5427             }
5428             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5429                                                                                              p1.getNode( "D" ) );
5430             if ( !abcd.getName().equals( "abcd" ) ) {
5431                 return false;
5432             }
5433             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5434                                                                                               p1.getNode( "A" ) );
5435             if ( !abcd2.getName().equals( "abcd" ) ) {
5436                 return false;
5437             }
5438             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5439                                                                                                p1.getNode( "F" ) );
5440             if ( !abcdef.getName().equals( "abcdef" ) ) {
5441                 return false;
5442             }
5443             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5444                                                                                                 p1.getNode( "A" ) );
5445             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5446                 return false;
5447             }
5448             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5449                                                                                                 p1.getNode( "F" ) );
5450             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5451                 return false;
5452             }
5453             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5454                                                                                                 p1.getNode( "ab" ) );
5455             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5456                 return false;
5457             }
5458             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5459                                                                                               p1.getNode( "E" ) );
5460             if ( !abcde.getName().equals( "abcde" ) ) {
5461                 return false;
5462             }
5463             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5464                                                                                                p1.getNode( "A" ) );
5465             if ( !abcde2.getName().equals( "abcde" ) ) {
5466                 return false;
5467             }
5468             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
5469                                                                                           p1.getNode( "abcdefgh" ) );
5470             if ( !r.getName().equals( "abcdefgh" ) ) {
5471                 return false;
5472             }
5473             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5474                                                                                            p1.getNode( "H" ) );
5475             if ( !r2.getName().equals( "abcdefgh" ) ) {
5476                 return false;
5477             }
5478             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5479                                                                                            p1.getNode( "A" ) );
5480             if ( !r3.getName().equals( "abcdefgh" ) ) {
5481                 return false;
5482             }
5483             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5484                                                                                                p1.getNode( "abcde" ) );
5485             if ( !abcde3.getName().equals( "abcde" ) ) {
5486                 return false;
5487             }
5488             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
5489                                                                                                p1.getNode( "E" ) );
5490             if ( !abcde4.getName().equals( "abcde" ) ) {
5491                 return false;
5492             }
5493             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5494                                                                                             p1.getNode( "B" ) );
5495             if ( !ab3.getName().equals( "ab" ) ) {
5496                 return false;
5497             }
5498             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5499                                                                                             p1.getNode( "ab" ) );
5500             if ( !ab4.getName().equals( "ab" ) ) {
5501                 return false;
5502             }
5503             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5504             PhylogenyMethods.preOrderReId( p2 );
5505             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5506                                                                                            p2.getNode( "d" ) );
5507             if ( !cd.getName().equals( "cd" ) ) {
5508                 return false;
5509             }
5510             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5511                                                                                             p2.getNode( "c" ) );
5512             if ( !cd2.getName().equals( "cd" ) ) {
5513                 return false;
5514             }
5515             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5516                                                                                             p2.getNode( "e" ) );
5517             if ( !cde.getName().equals( "cde" ) ) {
5518                 return false;
5519             }
5520             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
5521                                                                                              p2.getNode( "c" ) );
5522             if ( !cde2.getName().equals( "cde" ) ) {
5523                 return false;
5524             }
5525             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5526                                                                                              p2.getNode( "f" ) );
5527             if ( !cdef.getName().equals( "cdef" ) ) {
5528                 return false;
5529             }
5530             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5531                                                                                               p2.getNode( "f" ) );
5532             if ( !cdef2.getName().equals( "cdef" ) ) {
5533                 return false;
5534             }
5535             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
5536                                                                                               p2.getNode( "d" ) );
5537             if ( !cdef3.getName().equals( "cdef" ) ) {
5538                 return false;
5539             }
5540             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5541                                                                                            p2.getNode( "a" ) );
5542             if ( !rt.getName().equals( "r" ) ) {
5543                 return false;
5544             }
5545             final Phylogeny p3 = factory
5546                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5547                              new NHXParser() )[ 0 ];
5548             PhylogenyMethods.preOrderReId( p3 );
5549             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
5550                                                                                              p3.getNode( "c" ) );
5551             if ( !bc_3.getName().equals( "bc" ) ) {
5552                 return false;
5553             }
5554             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5555                                                                                              p3.getNode( "c" ) );
5556             if ( !ac_3.getName().equals( "abc" ) ) {
5557                 return false;
5558             }
5559             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5560                                                                                              p3.getNode( "d" ) );
5561             if ( !ad_3.getName().equals( "abcde" ) ) {
5562                 return false;
5563             }
5564             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5565                                                                                              p3.getNode( "f" ) );
5566             if ( !af_3.getName().equals( "abcdef" ) ) {
5567                 return false;
5568             }
5569             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5570                                                                                              p3.getNode( "g" ) );
5571             if ( !ag_3.getName().equals( "" ) ) {
5572                 return false;
5573             }
5574             if ( !ag_3.isRoot() ) {
5575                 return false;
5576             }
5577             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5578                                                                                              p3.getNode( "l" ) );
5579             if ( !al_3.getName().equals( "" ) ) {
5580                 return false;
5581             }
5582             if ( !al_3.isRoot() ) {
5583                 return false;
5584             }
5585             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
5586                                                                                              p3.getNode( "l" ) );
5587             if ( !kl_3.getName().equals( "" ) ) {
5588                 return false;
5589             }
5590             if ( !kl_3.isRoot() ) {
5591                 return false;
5592             }
5593             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
5594                                                                                              p3.getNode( "l" ) );
5595             if ( !fl_3.getName().equals( "" ) ) {
5596                 return false;
5597             }
5598             if ( !fl_3.isRoot() ) {
5599                 return false;
5600             }
5601             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
5602                                                                                              p3.getNode( "k" ) );
5603             if ( !gk_3.getName().equals( "ghijk" ) ) {
5604                 return false;
5605             }
5606             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5607             PhylogenyMethods.preOrderReId( p4 );
5608             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
5609                                                                                             p4.getNode( "c" ) );
5610             if ( !r_4.getName().equals( "r" ) ) {
5611                 return false;
5612             }
5613             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5614             PhylogenyMethods.preOrderReId( p5 );
5615             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
5616                                                                                             p5.getNode( "c" ) );
5617             if ( !r_5.getName().equals( "root" ) ) {
5618                 return false;
5619             }
5620             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5621             PhylogenyMethods.preOrderReId( p6 );
5622             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
5623                                                                                             p6.getNode( "a" ) );
5624             if ( !r_6.getName().equals( "rot" ) ) {
5625                 return false;
5626             }
5627             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5628             PhylogenyMethods.preOrderReId( p7 );
5629             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
5630                                                                                             p7.getNode( "e" ) );
5631             if ( !r_7.getName().equals( "rott" ) ) {
5632                 return false;
5633             }
5634             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5635                                                                                              p7.getNode( "a" ) );
5636             if ( !r_71.getName().equals( "rott" ) ) {
5637                 return false;
5638             }
5639             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5640                                                                                              p7.getNode( "rott" ) );
5641             if ( !r_72.getName().equals( "rott" ) ) {
5642                 return false;
5643             }
5644             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5645                                                                                              p7.getNode( "a" ) );
5646             if ( !r_73.getName().equals( "rott" ) ) {
5647                 return false;
5648             }
5649             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5650                                                                                              p7.getNode( "rott" ) );
5651             if ( !r_74.getName().equals( "rott" ) ) {
5652                 return false;
5653             }
5654             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5655                                                                                              p7.getNode( "e" ) );
5656             if ( !r_75.getName().equals( "e" ) ) {
5657                 return false;
5658             }
5659         }
5660         catch ( final Exception e ) {
5661             e.printStackTrace( System.out );
5662             return false;
5663         }
5664         return true;
5665     }
5666
5667     private static boolean testHmmscanOutputParser() {
5668         final String test_dir = Test.PATH_TO_TEST_DATA;
5669         try {
5670             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
5671                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5672             parser1.parse();
5673             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
5674                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5675             final List<Protein> proteins = parser2.parse();
5676             if ( parser2.getProteinsEncountered() != 4 ) {
5677                 return false;
5678             }
5679             if ( proteins.size() != 4 ) {
5680                 return false;
5681             }
5682             if ( parser2.getDomainsEncountered() != 69 ) {
5683                 return false;
5684             }
5685             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
5686                 return false;
5687             }
5688             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
5689                 return false;
5690             }
5691             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
5692                 return false;
5693             }
5694             final Protein p1 = proteins.get( 0 );
5695             if ( p1.getNumberOfProteinDomains() != 15 ) {
5696                 return false;
5697             }
5698             if ( p1.getLength() != 850 ) {
5699                 return false;
5700             }
5701             final Protein p2 = proteins.get( 1 );
5702             if ( p2.getNumberOfProteinDomains() != 51 ) {
5703                 return false;
5704             }
5705             if ( p2.getLength() != 1291 ) {
5706                 return false;
5707             }
5708             final Protein p3 = proteins.get( 2 );
5709             if ( p3.getNumberOfProteinDomains() != 2 ) {
5710                 return false;
5711             }
5712             final Protein p4 = proteins.get( 3 );
5713             if ( p4.getNumberOfProteinDomains() != 1 ) {
5714                 return false;
5715             }
5716             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
5717                 return false;
5718             }
5719             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
5720                 return false;
5721             }
5722             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
5723                 return false;
5724             }
5725             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
5726                 return false;
5727             }
5728             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
5729                 return false;
5730             }
5731             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
5732                 return false;
5733             }
5734             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
5735                 return false;
5736             }
5737         }
5738         catch ( final Exception e ) {
5739             e.printStackTrace( System.out );
5740             return false;
5741         }
5742         return true;
5743     }
5744
5745     private static boolean testLastExternalNodeMethods() {
5746         try {
5747             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5748             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
5749             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
5750             final PhylogenyNode n1 = t0.getNode( "A" );
5751             if ( n1.isLastExternalNode() ) {
5752                 return false;
5753             }
5754             final PhylogenyNode n2 = t0.getNode( "B" );
5755             if ( n2.isLastExternalNode() ) {
5756                 return false;
5757             }
5758             final PhylogenyNode n3 = t0.getNode( "C" );
5759             if ( n3.isLastExternalNode() ) {
5760                 return false;
5761             }
5762             final PhylogenyNode n4 = t0.getNode( "D" );
5763             if ( !n4.isLastExternalNode() ) {
5764                 return false;
5765             }
5766         }
5767         catch ( final Exception e ) {
5768             e.printStackTrace( System.out );
5769             return false;
5770         }
5771         return true;
5772     }
5773
5774     private static boolean testLevelOrderIterator() {
5775         try {
5776             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5777             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5778             PhylogenyNodeIterator it0;
5779             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
5780                 it0.next();
5781             }
5782             for( it0.reset(); it0.hasNext(); ) {
5783                 it0.next();
5784             }
5785             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
5786             if ( !it.next().getName().equals( "r" ) ) {
5787                 return false;
5788             }
5789             if ( !it.next().getName().equals( "ab" ) ) {
5790                 return false;
5791             }
5792             if ( !it.next().getName().equals( "cd" ) ) {
5793                 return false;
5794             }
5795             if ( !it.next().getName().equals( "A" ) ) {
5796                 return false;
5797             }
5798             if ( !it.next().getName().equals( "B" ) ) {
5799                 return false;
5800             }
5801             if ( !it.next().getName().equals( "C" ) ) {
5802                 return false;
5803             }
5804             if ( !it.next().getName().equals( "D" ) ) {
5805                 return false;
5806             }
5807             if ( it.hasNext() ) {
5808                 return false;
5809             }
5810             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",
5811                                                  new NHXParser() )[ 0 ];
5812             PhylogenyNodeIterator it2;
5813             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
5814                 it2.next();
5815             }
5816             for( it2.reset(); it2.hasNext(); ) {
5817                 it2.next();
5818             }
5819             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
5820             if ( !it3.next().getName().equals( "r" ) ) {
5821                 return false;
5822             }
5823             if ( !it3.next().getName().equals( "abc" ) ) {
5824                 return false;
5825             }
5826             if ( !it3.next().getName().equals( "defg" ) ) {
5827                 return false;
5828             }
5829             if ( !it3.next().getName().equals( "A" ) ) {
5830                 return false;
5831             }
5832             if ( !it3.next().getName().equals( "B" ) ) {
5833                 return false;
5834             }
5835             if ( !it3.next().getName().equals( "C" ) ) {
5836                 return false;
5837             }
5838             if ( !it3.next().getName().equals( "D" ) ) {
5839                 return false;
5840             }
5841             if ( !it3.next().getName().equals( "E" ) ) {
5842                 return false;
5843             }
5844             if ( !it3.next().getName().equals( "F" ) ) {
5845                 return false;
5846             }
5847             if ( !it3.next().getName().equals( "G" ) ) {
5848                 return false;
5849             }
5850             if ( !it3.next().getName().equals( "1" ) ) {
5851                 return false;
5852             }
5853             if ( !it3.next().getName().equals( "2" ) ) {
5854                 return false;
5855             }
5856             if ( !it3.next().getName().equals( "3" ) ) {
5857                 return false;
5858             }
5859             if ( !it3.next().getName().equals( "4" ) ) {
5860                 return false;
5861             }
5862             if ( !it3.next().getName().equals( "5" ) ) {
5863                 return false;
5864             }
5865             if ( !it3.next().getName().equals( "6" ) ) {
5866                 return false;
5867             }
5868             if ( !it3.next().getName().equals( "f1" ) ) {
5869                 return false;
5870             }
5871             if ( !it3.next().getName().equals( "f2" ) ) {
5872                 return false;
5873             }
5874             if ( !it3.next().getName().equals( "f3" ) ) {
5875                 return false;
5876             }
5877             if ( !it3.next().getName().equals( "a" ) ) {
5878                 return false;
5879             }
5880             if ( !it3.next().getName().equals( "b" ) ) {
5881                 return false;
5882             }
5883             if ( !it3.next().getName().equals( "f21" ) ) {
5884                 return false;
5885             }
5886             if ( !it3.next().getName().equals( "X" ) ) {
5887                 return false;
5888             }
5889             if ( !it3.next().getName().equals( "Y" ) ) {
5890                 return false;
5891             }
5892             if ( !it3.next().getName().equals( "Z" ) ) {
5893                 return false;
5894             }
5895             if ( it3.hasNext() ) {
5896                 return false;
5897             }
5898             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
5899             PhylogenyNodeIterator it4;
5900             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
5901                 it4.next();
5902             }
5903             for( it4.reset(); it4.hasNext(); ) {
5904                 it4.next();
5905             }
5906             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
5907             if ( !it5.next().getName().equals( "r" ) ) {
5908                 return false;
5909             }
5910             if ( !it5.next().getName().equals( "A" ) ) {
5911                 return false;
5912             }
5913             if ( !it5.next().getName().equals( "B" ) ) {
5914                 return false;
5915             }
5916             if ( !it5.next().getName().equals( "C" ) ) {
5917                 return false;
5918             }
5919             if ( !it5.next().getName().equals( "D" ) ) {
5920                 return false;
5921             }
5922             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
5923             PhylogenyNodeIterator it6;
5924             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
5925                 it6.next();
5926             }
5927             for( it6.reset(); it6.hasNext(); ) {
5928                 it6.next();
5929             }
5930             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
5931             if ( !it7.next().getName().equals( "A" ) ) {
5932                 return false;
5933             }
5934             if ( it.hasNext() ) {
5935                 return false;
5936             }
5937         }
5938         catch ( final Exception e ) {
5939             e.printStackTrace( System.out );
5940             return false;
5941         }
5942         return true;
5943     }
5944
5945     private static boolean testMafft( final String path ) {
5946         try {
5947             final List<String> opts = new ArrayList<String>();
5948             opts.add( "--maxiterate" );
5949             opts.add( "1000" );
5950             opts.add( "--localpair" );
5951             opts.add( "--quiet" );
5952             Msa msa = null;
5953             final MsaInferrer mafft = Mafft.createInstance( path );
5954             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
5955             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
5956                 return false;
5957             }
5958             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
5959                 return false;
5960             }
5961         }
5962         catch ( final Exception e ) {
5963             e.printStackTrace( System.out );
5964             return false;
5965         }
5966         return true;
5967     }
5968
5969     private static boolean testMidpointrooting() {
5970         try {
5971             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5972             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
5973             PhylogenyMethods.midpointRoot( t0 );
5974             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
5975                 return false;
5976             }
5977             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
5978                 return false;
5979             }
5980             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
5981                            1 ) ) {
5982                 return false;
5983             }
5984             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",
5985                                                  new NHXParser() )[ 0 ];
5986             if ( !t1.isRooted() ) {
5987                 return false;
5988             }
5989             PhylogenyMethods.midpointRoot( t1 );
5990             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5991                 return false;
5992             }
5993             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5994                 return false;
5995             }
5996             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5997                 return false;
5998             }
5999             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6000                 return false;
6001             }
6002             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6003                 return false;
6004             }
6005             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6006                 return false;
6007             }
6008             t1.reRoot( t1.getNode( "A" ) );
6009             PhylogenyMethods.midpointRoot( t1 );
6010             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6011                 return false;
6012             }
6013             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6014                 return false;
6015             }
6016             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6017                 return false;
6018             }
6019             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6020                 return false;
6021             }
6022             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6023                 System.exit( -1 );
6024                 return false;
6025             }
6026             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6027                 return false;
6028             }
6029         }
6030         catch ( final Exception e ) {
6031             e.printStackTrace( System.out );
6032             return false;
6033         }
6034         return true;
6035     }
6036
6037     private static boolean testMsaQualityMethod() {
6038         try {
6039             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6040             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6041             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6042             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6043             final List<Sequence> l = new ArrayList<Sequence>();
6044             l.add( s0 );
6045             l.add( s1 );
6046             l.add( s2 );
6047             l.add( s3 );
6048             final Msa msa = BasicMsa.createInstance( l );
6049             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6050                 return false;
6051             }
6052             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6053                 return false;
6054             }
6055             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6056                 return false;
6057             }
6058             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6059                 return false;
6060             }
6061             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6062                 return false;
6063             }
6064             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6065                 return false;
6066             }
6067             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6068                 return false;
6069             }
6070         }
6071         catch ( final Exception e ) {
6072             e.printStackTrace( System.out );
6073             return false;
6074         }
6075         return true;
6076     }
6077
6078     private static boolean testNextNodeWithCollapsing() {
6079         try {
6080             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6081             PhylogenyNode n;
6082             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
6083             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6084             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
6085             t0.getNode( "cd" ).setCollapse( true );
6086             t0.getNode( "cde" ).setCollapse( true );
6087             n = t0.getFirstExternalNode();
6088             while ( n != null ) {
6089                 ext.add( n );
6090                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6091             }
6092             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6093                 return false;
6094             }
6095             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6096                 return false;
6097             }
6098             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
6099                 return false;
6100             }
6101             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
6102                 return false;
6103             }
6104             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
6105                 return false;
6106             }
6107             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
6108                 return false;
6109             }
6110             ext.clear();
6111             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6112             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
6113             t1.getNode( "ab" ).setCollapse( true );
6114             t1.getNode( "cd" ).setCollapse( true );
6115             t1.getNode( "cde" ).setCollapse( true );
6116             n = t1.getNode( "ab" );
6117             ext = new ArrayList<PhylogenyNode>();
6118             while ( n != null ) {
6119                 ext.add( n );
6120                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6121             }
6122             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6123                 return false;
6124             }
6125             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6126                 return false;
6127             }
6128             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6129                 return false;
6130             }
6131             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
6132                 return false;
6133             }
6134             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
6135                 return false;
6136             }
6137             //
6138             //
6139             ext.clear();
6140             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6141             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
6142             t2.getNode( "ab" ).setCollapse( true );
6143             t2.getNode( "cd" ).setCollapse( true );
6144             t2.getNode( "cde" ).setCollapse( true );
6145             t2.getNode( "c" ).setCollapse( true );
6146             t2.getNode( "d" ).setCollapse( true );
6147             t2.getNode( "e" ).setCollapse( true );
6148             t2.getNode( "gh" ).setCollapse( true );
6149             n = t2.getNode( "ab" );
6150             ext = new ArrayList<PhylogenyNode>();
6151             while ( n != null ) {
6152                 ext.add( n );
6153                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6154             }
6155             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6156                 return false;
6157             }
6158             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6159                 return false;
6160             }
6161             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6162                 return false;
6163             }
6164             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
6165                 return false;
6166             }
6167             //
6168             //
6169             ext.clear();
6170             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6171             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
6172             t3.getNode( "ab" ).setCollapse( true );
6173             t3.getNode( "cd" ).setCollapse( true );
6174             t3.getNode( "cde" ).setCollapse( true );
6175             t3.getNode( "c" ).setCollapse( true );
6176             t3.getNode( "d" ).setCollapse( true );
6177             t3.getNode( "e" ).setCollapse( true );
6178             t3.getNode( "gh" ).setCollapse( true );
6179             t3.getNode( "fgh" ).setCollapse( true );
6180             n = t3.getNode( "ab" );
6181             ext = new ArrayList<PhylogenyNode>();
6182             while ( n != null ) {
6183                 ext.add( n );
6184                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6185             }
6186             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6187                 return false;
6188             }
6189             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6190                 return false;
6191             }
6192             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
6193                 return false;
6194             }
6195             //
6196             //
6197             ext.clear();
6198             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6199             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
6200             t4.getNode( "ab" ).setCollapse( true );
6201             t4.getNode( "cd" ).setCollapse( true );
6202             t4.getNode( "cde" ).setCollapse( true );
6203             t4.getNode( "c" ).setCollapse( true );
6204             t4.getNode( "d" ).setCollapse( true );
6205             t4.getNode( "e" ).setCollapse( true );
6206             t4.getNode( "gh" ).setCollapse( true );
6207             t4.getNode( "fgh" ).setCollapse( true );
6208             t4.getNode( "abcdefgh" ).setCollapse( true );
6209             n = t4.getNode( "abcdefgh" );
6210             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
6211                 return false;
6212             }
6213             //
6214             //
6215             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6216             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
6217             ext.clear();
6218             n = t5.getFirstExternalNode();
6219             while ( n != null ) {
6220                 ext.add( n );
6221                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6222             }
6223             if ( ext.size() != 8 ) {
6224                 return false;
6225             }
6226             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6227                 return false;
6228             }
6229             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6230                 return false;
6231             }
6232             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6233                 return false;
6234             }
6235             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6236                 return false;
6237             }
6238             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6239                 return false;
6240             }
6241             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6242                 return false;
6243             }
6244             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
6245                 return false;
6246             }
6247             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
6248                 return false;
6249             }
6250             //
6251             //
6252             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6253             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
6254             ext.clear();
6255             t6.getNode( "ab" ).setCollapse( true );
6256             n = t6.getNode( "ab" );
6257             while ( n != null ) {
6258                 ext.add( n );
6259                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6260             }
6261             if ( ext.size() != 7 ) {
6262                 return false;
6263             }
6264             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6265                 return false;
6266             }
6267             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6268                 return false;
6269             }
6270             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6271                 return false;
6272             }
6273             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6274                 return false;
6275             }
6276             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6277                 return false;
6278             }
6279             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6280                 return false;
6281             }
6282             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6283                 return false;
6284             }
6285             //
6286             //
6287             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6288             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
6289             ext.clear();
6290             t7.getNode( "cd" ).setCollapse( true );
6291             n = t7.getNode( "a" );
6292             while ( n != null ) {
6293                 ext.add( n );
6294                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6295             }
6296             if ( ext.size() != 7 ) {
6297                 return false;
6298             }
6299             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6300                 return false;
6301             }
6302             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6303                 return false;
6304             }
6305             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6306                 return false;
6307             }
6308             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6309                 return false;
6310             }
6311             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6312                 return false;
6313             }
6314             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6315                 return false;
6316             }
6317             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6318                 return false;
6319             }
6320             //
6321             //
6322             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6323             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
6324             ext.clear();
6325             t8.getNode( "cd" ).setCollapse( true );
6326             t8.getNode( "c" ).setCollapse( true );
6327             t8.getNode( "d" ).setCollapse( true );
6328             n = t8.getNode( "a" );
6329             while ( n != null ) {
6330                 ext.add( n );
6331                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6332             }
6333             if ( ext.size() != 7 ) {
6334                 return false;
6335             }
6336             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6337                 return false;
6338             }
6339             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6340                 return false;
6341             }
6342             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6343                 System.out.println( "2 fail" );
6344                 return false;
6345             }
6346             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6347                 return false;
6348             }
6349             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6350                 return false;
6351             }
6352             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6353                 return false;
6354             }
6355             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6356                 return false;
6357             }
6358             //
6359             //
6360             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6361             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
6362             ext.clear();
6363             t9.getNode( "gh" ).setCollapse( true );
6364             n = t9.getNode( "a" );
6365             while ( n != null ) {
6366                 ext.add( n );
6367                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6368             }
6369             if ( ext.size() != 7 ) {
6370                 return false;
6371             }
6372             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6373                 return false;
6374             }
6375             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6376                 return false;
6377             }
6378             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6379                 return false;
6380             }
6381             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6382                 return false;
6383             }
6384             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6385                 return false;
6386             }
6387             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6388                 return false;
6389             }
6390             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6391                 return false;
6392             }
6393             //
6394             //
6395             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6396             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
6397             ext.clear();
6398             t10.getNode( "gh" ).setCollapse( true );
6399             t10.getNode( "g" ).setCollapse( true );
6400             t10.getNode( "h" ).setCollapse( true );
6401             n = t10.getNode( "a" );
6402             while ( n != null ) {
6403                 ext.add( n );
6404                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6405             }
6406             if ( ext.size() != 7 ) {
6407                 return false;
6408             }
6409             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6410                 return false;
6411             }
6412             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6413                 return false;
6414             }
6415             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6416                 return false;
6417             }
6418             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6419                 return false;
6420             }
6421             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6422                 return false;
6423             }
6424             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6425                 return false;
6426             }
6427             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6428                 return false;
6429             }
6430             //
6431             //
6432             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6433             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
6434             ext.clear();
6435             t11.getNode( "gh" ).setCollapse( true );
6436             t11.getNode( "fgh" ).setCollapse( true );
6437             n = t11.getNode( "a" );
6438             while ( n != null ) {
6439                 ext.add( n );
6440                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6441             }
6442             if ( ext.size() != 6 ) {
6443                 return false;
6444             }
6445             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6446                 return false;
6447             }
6448             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6449                 return false;
6450             }
6451             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6452                 return false;
6453             }
6454             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6455                 return false;
6456             }
6457             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6458                 return false;
6459             }
6460             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6461                 return false;
6462             }
6463             //
6464             //
6465             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6466             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
6467             ext.clear();
6468             t12.getNode( "gh" ).setCollapse( true );
6469             t12.getNode( "fgh" ).setCollapse( true );
6470             t12.getNode( "g" ).setCollapse( true );
6471             t12.getNode( "h" ).setCollapse( true );
6472             t12.getNode( "f" ).setCollapse( true );
6473             n = t12.getNode( "a" );
6474             while ( n != null ) {
6475                 ext.add( n );
6476                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6477             }
6478             if ( ext.size() != 6 ) {
6479                 return false;
6480             }
6481             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6482                 return false;
6483             }
6484             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6485                 return false;
6486             }
6487             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6488                 return false;
6489             }
6490             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6491                 return false;
6492             }
6493             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6494                 return false;
6495             }
6496             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6497                 return false;
6498             }
6499             //
6500             //
6501             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6502             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
6503             ext.clear();
6504             t13.getNode( "ab" ).setCollapse( true );
6505             t13.getNode( "b" ).setCollapse( true );
6506             t13.getNode( "fgh" ).setCollapse( true );
6507             t13.getNode( "gh" ).setCollapse( true );
6508             n = t13.getNode( "ab" );
6509             while ( n != null ) {
6510                 ext.add( n );
6511                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6512             }
6513             if ( ext.size() != 5 ) {
6514                 return false;
6515             }
6516             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6517                 return false;
6518             }
6519             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6520                 return false;
6521             }
6522             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6523                 return false;
6524             }
6525             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6526                 return false;
6527             }
6528             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6529                 return false;
6530             }
6531             //
6532             //
6533             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
6534             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
6535             ext.clear();
6536             t14.getNode( "ab" ).setCollapse( true );
6537             t14.getNode( "a" ).setCollapse( true );
6538             t14.getNode( "fgh" ).setCollapse( true );
6539             t14.getNode( "gh" ).setCollapse( true );
6540             n = t14.getNode( "ab" );
6541             while ( n != null ) {
6542                 ext.add( n );
6543                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6544             }
6545             if ( ext.size() != 5 ) {
6546                 return false;
6547             }
6548             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6549                 return false;
6550             }
6551             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6552                 return false;
6553             }
6554             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6555                 return false;
6556             }
6557             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6558                 return false;
6559             }
6560             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6561                 return false;
6562             }
6563             //
6564             //
6565             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" );
6566             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
6567             ext.clear();
6568             t15.getNode( "ab" ).setCollapse( true );
6569             t15.getNode( "a" ).setCollapse( true );
6570             t15.getNode( "fgh" ).setCollapse( true );
6571             t15.getNode( "gh" ).setCollapse( true );
6572             n = t15.getNode( "ab" );
6573             while ( n != null ) {
6574                 ext.add( n );
6575                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6576             }
6577             if ( ext.size() != 6 ) {
6578                 return false;
6579             }
6580             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6581                 return false;
6582             }
6583             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6584                 return false;
6585             }
6586             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6587                 return false;
6588             }
6589             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6590                 return false;
6591             }
6592             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
6593                 return false;
6594             }
6595             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6596                 return false;
6597             }
6598             //
6599             //
6600             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" );
6601             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
6602             ext.clear();
6603             t16.getNode( "ab" ).setCollapse( true );
6604             t16.getNode( "a" ).setCollapse( true );
6605             t16.getNode( "fgh" ).setCollapse( true );
6606             t16.getNode( "gh" ).setCollapse( true );
6607             t16.getNode( "cd" ).setCollapse( true );
6608             t16.getNode( "cde" ).setCollapse( true );
6609             t16.getNode( "d" ).setCollapse( true );
6610             t16.getNode( "x" ).setCollapse( true );
6611             n = t16.getNode( "ab" );
6612             while ( n != null ) {
6613                 ext.add( n );
6614                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6615             }
6616             if ( ext.size() != 4 ) {
6617                 return false;
6618             }
6619             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6620                 return false;
6621             }
6622             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6623                 return false;
6624             }
6625             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
6626                 return false;
6627             }
6628             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
6629                 return false;
6630             }
6631         }
6632         catch ( final Exception e ) {
6633             e.printStackTrace( System.out );
6634             return false;
6635         }
6636         return true;
6637     }
6638
6639     private static boolean testNexusCharactersParsing() {
6640         try {
6641             final NexusCharactersParser parser = new NexusCharactersParser();
6642             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
6643             parser.parse();
6644             String[] labels = parser.getCharStateLabels();
6645             if ( labels.length != 7 ) {
6646                 return false;
6647             }
6648             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6649                 return false;
6650             }
6651             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6652                 return false;
6653             }
6654             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6655                 return false;
6656             }
6657             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6658                 return false;
6659             }
6660             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6661                 return false;
6662             }
6663             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6664                 return false;
6665             }
6666             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6667                 return false;
6668             }
6669             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6670             parser.parse();
6671             labels = parser.getCharStateLabels();
6672             if ( labels.length != 7 ) {
6673                 return false;
6674             }
6675             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6676                 return false;
6677             }
6678             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6679                 return false;
6680             }
6681             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6682                 return false;
6683             }
6684             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6685                 return false;
6686             }
6687             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6688                 return false;
6689             }
6690             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6691                 return false;
6692             }
6693             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6694                 return false;
6695             }
6696         }
6697         catch ( final Exception e ) {
6698             e.printStackTrace( System.out );
6699             return false;
6700         }
6701         return true;
6702     }
6703
6704     private static boolean testNexusMatrixParsing() {
6705         try {
6706             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
6707             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
6708             parser.parse();
6709             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
6710             if ( m.getNumberOfCharacters() != 9 ) {
6711                 return false;
6712             }
6713             if ( m.getNumberOfIdentifiers() != 5 ) {
6714                 return false;
6715             }
6716             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
6717                 return false;
6718             }
6719             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
6720                 return false;
6721             }
6722             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
6723                 return false;
6724             }
6725             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
6726                 return false;
6727             }
6728             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
6729                 return false;
6730             }
6731             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
6732                 return false;
6733             }
6734             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
6735                 return false;
6736             }
6737             //            if ( labels.length != 7 ) {
6738             //                return false;
6739             //            }
6740             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6741             //                return false;
6742             //            }
6743             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6744             //                return false;
6745             //            }
6746             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6747             //                return false;
6748             //            }
6749             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6750             //                return false;
6751             //            }
6752             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6753             //                return false;
6754             //            }
6755             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6756             //                return false;
6757             //            }
6758             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6759             //                return false;
6760             //            }
6761             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6762             //            parser.parse();
6763             //            labels = parser.getCharStateLabels();
6764             //            if ( labels.length != 7 ) {
6765             //                return false;
6766             //            }
6767             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6768             //                return false;
6769             //            }
6770             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6771             //                return false;
6772             //            }
6773             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6774             //                return false;
6775             //            }
6776             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6777             //                return false;
6778             //            }
6779             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6780             //                return false;
6781             //            }
6782             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6783             //                return false;
6784             //            }
6785             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6786             //                return false;
6787             //            }
6788         }
6789         catch ( final Exception e ) {
6790             e.printStackTrace( System.out );
6791             return false;
6792         }
6793         return true;
6794     }
6795
6796     private static boolean testNexusTreeParsing() {
6797         try {
6798             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6799             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
6800             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
6801             if ( phylogenies.length != 1 ) {
6802                 return false;
6803             }
6804             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
6805                 return false;
6806             }
6807             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6808                 return false;
6809             }
6810             phylogenies = null;
6811             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
6812             if ( phylogenies.length != 1 ) {
6813                 return false;
6814             }
6815             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6816                 return false;
6817             }
6818             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
6819                 return false;
6820             }
6821             phylogenies = null;
6822             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
6823             if ( phylogenies.length != 1 ) {
6824                 return false;
6825             }
6826             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6827                 return false;
6828             }
6829             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6830                 return false;
6831             }
6832             if ( phylogenies[ 0 ].isRooted() ) {
6833                 return false;
6834             }
6835             phylogenies = null;
6836             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
6837             if ( phylogenies.length != 18 ) {
6838                 return false;
6839             }
6840             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6841                 return false;
6842             }
6843             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
6844                 return false;
6845             }
6846             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
6847                 return false;
6848             }
6849             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
6850                 return false;
6851             }
6852             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6853                 return false;
6854             }
6855             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
6856                 return false;
6857             }
6858             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
6859                 return false;
6860             }
6861             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
6862                 return false;
6863             }
6864             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
6865                 return false;
6866             }
6867             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
6868                 return false;
6869             }
6870             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
6871                 return false;
6872             }
6873             if ( phylogenies[ 8 ].isRooted() ) {
6874                 return false;
6875             }
6876             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
6877                 return false;
6878             }
6879             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
6880                 return false;
6881             }
6882             if ( !phylogenies[ 9 ].isRooted() ) {
6883                 return false;
6884             }
6885             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
6886                 return false;
6887             }
6888             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
6889                 return false;
6890             }
6891             if ( !phylogenies[ 10 ].isRooted() ) {
6892                 return false;
6893             }
6894             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
6895                 return false;
6896             }
6897             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
6898                 return false;
6899             }
6900             if ( phylogenies[ 11 ].isRooted() ) {
6901                 return false;
6902             }
6903             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
6904                 return false;
6905             }
6906             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
6907                 return false;
6908             }
6909             if ( !phylogenies[ 12 ].isRooted() ) {
6910                 return false;
6911             }
6912             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
6913                 return false;
6914             }
6915             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
6916                 return false;
6917             }
6918             if ( !phylogenies[ 13 ].isRooted() ) {
6919                 return false;
6920             }
6921             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
6922                 return false;
6923             }
6924             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
6925                 return false;
6926             }
6927             if ( !phylogenies[ 14 ].isRooted() ) {
6928                 return false;
6929             }
6930             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
6931                 return false;
6932             }
6933             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
6934                 return false;
6935             }
6936             if ( phylogenies[ 15 ].isRooted() ) {
6937                 return false;
6938             }
6939             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
6940                 return false;
6941             }
6942             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
6943                 return false;
6944             }
6945             if ( !phylogenies[ 16 ].isRooted() ) {
6946                 return false;
6947             }
6948             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
6949                 return false;
6950             }
6951             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
6952                 return false;
6953             }
6954             if ( phylogenies[ 17 ].isRooted() ) {
6955                 return false;
6956             }
6957             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
6958                 return false;
6959             }
6960             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
6961             phylogenies = null;
6962             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
6963             if ( phylogenies.length != 9 ) {
6964                 return false;
6965             }
6966             if ( !isEqual( 0.48039661496919533, phylogenies[ 0 ].getNode( "Diadocidia_spinosula" )
6967                     .getDistanceToParent() ) ) {
6968                 return false;
6969             }
6970             if ( !isEqual( 0.3959796191512233, phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" )
6971                     .getDistanceToParent() ) ) {
6972                 return false;
6973             }
6974             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
6975                 return false;
6976             }
6977             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
6978                 return false;
6979             }
6980             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
6981                 return false;
6982             }
6983             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
6984                 return false;
6985             }
6986             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
6987                 return false;
6988             }
6989         }
6990         catch ( final Exception e ) {
6991             e.printStackTrace( System.out );
6992             return false;
6993         }
6994         return true;
6995     }
6996
6997     private static boolean testNexusTreeParsingIterating() {
6998         try {
6999             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
7000             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
7001             if ( !p.hasNext() ) {
7002                 return false;
7003             }
7004             Phylogeny phy = p.next();
7005             if ( phy == null ) {
7006                 return false;
7007             }
7008             if ( phy.getNumberOfExternalNodes() != 25 ) {
7009                 return false;
7010             }
7011             if ( !phy.getName().equals( "" ) ) {
7012                 return false;
7013             }
7014             if ( p.hasNext() ) {
7015                 return false;
7016             }
7017             phy = p.next();
7018             if ( phy != null ) {
7019                 return false;
7020             }
7021             //
7022             p.reset();
7023             if ( !p.hasNext() ) {
7024                 return false;
7025             }
7026             phy = p.next();
7027             if ( phy == null ) {
7028                 return false;
7029             }
7030             if ( phy.getNumberOfExternalNodes() != 25 ) {
7031                 return false;
7032             }
7033             if ( !phy.getName().equals( "" ) ) {
7034                 return false;
7035             }
7036             if ( p.hasNext() ) {
7037                 return false;
7038             }
7039             phy = p.next();
7040             if ( phy != null ) {
7041                 return false;
7042             }
7043             ////
7044             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
7045             if ( !p.hasNext() ) {
7046                 return false;
7047             }
7048             phy = p.next();
7049             if ( phy == null ) {
7050                 return false;
7051             }
7052             if ( phy.getNumberOfExternalNodes() != 10 ) {
7053                 return false;
7054             }
7055             if ( !phy.getName().equals( "name" ) ) {
7056                 return false;
7057             }
7058             if ( p.hasNext() ) {
7059                 return false;
7060             }
7061             phy = p.next();
7062             if ( phy != null ) {
7063                 return false;
7064             }
7065             //
7066             p.reset();
7067             if ( !p.hasNext() ) {
7068                 return false;
7069             }
7070             phy = p.next();
7071             if ( phy == null ) {
7072                 return false;
7073             }
7074             if ( phy.getNumberOfExternalNodes() != 10 ) {
7075                 return false;
7076             }
7077             if ( !phy.getName().equals( "name" ) ) {
7078                 return false;
7079             }
7080             if ( p.hasNext() ) {
7081                 return false;
7082             }
7083             phy = p.next();
7084             if ( phy != null ) {
7085                 return false;
7086             }
7087             //
7088             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
7089             if ( !p.hasNext() ) {
7090                 return false;
7091             }
7092             phy = p.next();
7093             if ( phy == null ) {
7094                 return false;
7095             }
7096             if ( phy.getNumberOfExternalNodes() != 3 ) {
7097                 return false;
7098             }
7099             if ( !phy.getName().equals( "" ) ) {
7100                 return false;
7101             }
7102             if ( phy.isRooted() ) {
7103                 return false;
7104             }
7105             if ( p.hasNext() ) {
7106                 return false;
7107             }
7108             phy = p.next();
7109             if ( phy != null ) {
7110                 return false;
7111             }
7112             //
7113             p.reset();
7114             if ( !p.hasNext() ) {
7115                 return false;
7116             }
7117             phy = p.next();
7118             if ( phy == null ) {
7119                 return false;
7120             }
7121             if ( phy.getNumberOfExternalNodes() != 3 ) {
7122                 return false;
7123             }
7124             if ( !phy.getName().equals( "" ) ) {
7125                 return false;
7126             }
7127             if ( p.hasNext() ) {
7128                 return false;
7129             }
7130             phy = p.next();
7131             if ( phy != null ) {
7132                 return false;
7133             }
7134             //
7135             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
7136             if ( !p.hasNext() ) {
7137                 return false;
7138             }
7139             //0
7140             phy = p.next();
7141             if ( phy == null ) {
7142                 return false;
7143             }
7144             if ( phy.getNumberOfExternalNodes() != 10 ) {
7145                 return false;
7146             }
7147             if ( !phy.getName().equals( "tree 0" ) ) {
7148                 return false;
7149             }
7150             //1
7151             if ( !p.hasNext() ) {
7152                 return false;
7153             }
7154             phy = p.next();
7155             if ( phy == null ) {
7156                 return false;
7157             }
7158             if ( phy.getNumberOfExternalNodes() != 10 ) {
7159                 return false;
7160             }
7161             if ( !phy.getName().equals( "tree 1" ) ) {
7162                 return false;
7163             }
7164             //2
7165             if ( !p.hasNext() ) {
7166                 return false;
7167             }
7168             phy = p.next();
7169             if ( phy == null ) {
7170                 return false;
7171             }
7172             if ( phy.getNumberOfExternalNodes() != 3 ) {
7173                 System.out.println( phy.toString() );
7174                 return false;
7175             }
7176             if ( !phy.getName().equals( "" ) ) {
7177                 return false;
7178             }
7179             if ( phy.isRooted() ) {
7180                 return false;
7181             }
7182             //3
7183             if ( !p.hasNext() ) {
7184                 return false;
7185             }
7186             phy = p.next();
7187             if ( phy == null ) {
7188                 return false;
7189             }
7190             if ( phy.getNumberOfExternalNodes() != 4 ) {
7191                 return false;
7192             }
7193             if ( !phy.getName().equals( "" ) ) {
7194                 return false;
7195             }
7196             if ( !phy.isRooted() ) {
7197                 return false;
7198             }
7199             //4
7200             if ( !p.hasNext() ) {
7201                 return false;
7202             }
7203             phy = p.next();
7204             if ( phy == null ) {
7205                 return false;
7206             }
7207             if ( phy.getNumberOfExternalNodes() != 5 ) {
7208                 System.out.println( phy.getNumberOfExternalNodes() );
7209                 return false;
7210             }
7211             if ( !phy.getName().equals( "" ) ) {
7212                 return false;
7213             }
7214             if ( !phy.isRooted() ) {
7215                 return false;
7216             }
7217             //5
7218             if ( !p.hasNext() ) {
7219                 return false;
7220             }
7221             phy = p.next();
7222             if ( phy == null ) {
7223                 return false;
7224             }
7225             if ( phy.getNumberOfExternalNodes() != 3 ) {
7226                 return false;
7227             }
7228             if ( !phy.getName().equals( "" ) ) {
7229                 return false;
7230             }
7231             if ( phy.isRooted() ) {
7232                 return false;
7233             }
7234             //6
7235             if ( !p.hasNext() ) {
7236                 return false;
7237             }
7238             phy = p.next();
7239             if ( phy == null ) {
7240                 return false;
7241             }
7242             if ( phy.getNumberOfExternalNodes() != 2 ) {
7243                 return false;
7244             }
7245             if ( !phy.getName().equals( "" ) ) {
7246                 return false;
7247             }
7248             if ( !phy.isRooted() ) {
7249                 return false;
7250             }
7251             //7
7252             if ( !p.hasNext() ) {
7253                 return false;
7254             }
7255             phy = p.next();
7256             if ( phy.getNumberOfExternalNodes() != 3 ) {
7257                 return false;
7258             }
7259             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7260                 return false;
7261             }
7262             if ( !phy.isRooted() ) {
7263                 return false;
7264             }
7265             //8
7266             if ( !p.hasNext() ) {
7267                 return false;
7268             }
7269             phy = p.next();
7270             if ( phy.getNumberOfExternalNodes() != 3 ) {
7271                 return false;
7272             }
7273             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
7274                 return false;
7275             }
7276             if ( !phy.getName().equals( "tree 8" ) ) {
7277                 return false;
7278             }
7279             //9
7280             if ( !p.hasNext() ) {
7281                 return false;
7282             }
7283             phy = p.next();
7284             if ( phy.getNumberOfExternalNodes() != 3 ) {
7285                 return false;
7286             }
7287             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
7288                 return false;
7289             }
7290             if ( !phy.getName().equals( "tree 9" ) ) {
7291                 return false;
7292             }
7293             //10
7294             if ( !p.hasNext() ) {
7295                 return false;
7296             }
7297             phy = p.next();
7298             if ( phy.getNumberOfExternalNodes() != 3 ) {
7299                 return false;
7300             }
7301             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7302                 return false;
7303             }
7304             if ( !phy.getName().equals( "tree 10" ) ) {
7305                 return false;
7306             }
7307             if ( !phy.isRooted() ) {
7308                 return false;
7309             }
7310             //11
7311             if ( !p.hasNext() ) {
7312                 return false;
7313             }
7314             phy = p.next();
7315             if ( phy.getNumberOfExternalNodes() != 3 ) {
7316                 return false;
7317             }
7318             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
7319                 return false;
7320             }
7321             if ( !phy.getName().equals( "tree 11" ) ) {
7322                 return false;
7323             }
7324             if ( phy.isRooted() ) {
7325                 return false;
7326             }
7327             //12
7328             if ( !p.hasNext() ) {
7329                 return false;
7330             }
7331             phy = p.next();
7332             if ( phy.getNumberOfExternalNodes() != 3 ) {
7333                 return false;
7334             }
7335             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
7336                 return false;
7337             }
7338             if ( !phy.getName().equals( "tree 12" ) ) {
7339                 return false;
7340             }
7341             if ( !phy.isRooted() ) {
7342                 return false;
7343             }
7344             //13
7345             if ( !p.hasNext() ) {
7346                 return false;
7347             }
7348             phy = p.next();
7349             if ( phy.getNumberOfExternalNodes() != 3 ) {
7350                 return false;
7351             }
7352             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7353                 return false;
7354             }
7355             if ( !phy.getName().equals( "tree 13" ) ) {
7356                 return false;
7357             }
7358             if ( !phy.isRooted() ) {
7359                 return false;
7360             }
7361             //14
7362             if ( !p.hasNext() ) {
7363                 return false;
7364             }
7365             phy = p.next();
7366             if ( phy.getNumberOfExternalNodes() != 10 ) {
7367                 System.out.println( phy.getNumberOfExternalNodes() );
7368                 return false;
7369             }
7370             if ( !phy
7371                     .toNewHampshire()
7372                     .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;" ) ) {
7373                 System.out.println( phy.toNewHampshire() );
7374                 return false;
7375             }
7376             if ( !phy.getName().equals( "tree 14" ) ) {
7377                 return false;
7378             }
7379             if ( !phy.isRooted() ) {
7380                 return false;
7381             }
7382             //15
7383             if ( !p.hasNext() ) {
7384                 return false;
7385             }
7386             phy = p.next();
7387             if ( phy.getNumberOfExternalNodes() != 10 ) {
7388                 System.out.println( phy.getNumberOfExternalNodes() );
7389                 return false;
7390             }
7391             if ( !phy
7392                     .toNewHampshire()
7393                     .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;" ) ) {
7394                 System.out.println( phy.toNewHampshire() );
7395                 return false;
7396             }
7397             if ( !phy.getName().equals( "tree 15" ) ) {
7398                 return false;
7399             }
7400             if ( phy.isRooted() ) {
7401                 return false;
7402             }
7403             //16
7404             if ( !p.hasNext() ) {
7405                 return false;
7406             }
7407             phy = p.next();
7408             if ( phy.getNumberOfExternalNodes() != 10 ) {
7409                 System.out.println( phy.getNumberOfExternalNodes() );
7410                 return false;
7411             }
7412             if ( !phy
7413                     .toNewHampshire()
7414                     .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;" ) ) {
7415                 System.out.println( phy.toNewHampshire() );
7416                 return false;
7417             }
7418             if ( !phy.getName().equals( "tree 16" ) ) {
7419                 return false;
7420             }
7421             if ( !phy.isRooted() ) {
7422                 return false;
7423             }
7424             //17
7425             if ( !p.hasNext() ) {
7426                 return false;
7427             }
7428             phy = p.next();
7429             if ( phy.getNumberOfExternalNodes() != 10 ) {
7430                 System.out.println( phy.getNumberOfExternalNodes() );
7431                 return false;
7432             }
7433             if ( !phy
7434                     .toNewHampshire()
7435                     .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;" ) ) {
7436                 System.out.println( phy.toNewHampshire() );
7437                 return false;
7438             }
7439             if ( !phy.getName().equals( "tree 17" ) ) {
7440                 return false;
7441             }
7442             if ( phy.isRooted() ) {
7443                 return false;
7444             }
7445             //
7446             if ( p.hasNext() ) {
7447                 return false;
7448             }
7449             phy = p.next();
7450             if ( phy != null ) {
7451                 return false;
7452             }
7453             p.reset();
7454             //0
7455             if ( !p.hasNext() ) {
7456                 return false;
7457             }
7458             phy = p.next();
7459             if ( phy == null ) {
7460                 return false;
7461             }
7462             if ( phy.getNumberOfExternalNodes() != 10 ) {
7463                 return false;
7464             }
7465             if ( !phy.getName().equals( "tree 0" ) ) {
7466                 return false;
7467             }
7468             //1
7469             if ( !p.hasNext() ) {
7470                 return false;
7471             }
7472             phy = p.next();
7473             if ( phy == null ) {
7474                 return false;
7475             }
7476             if ( phy.getNumberOfExternalNodes() != 10 ) {
7477                 return false;
7478             }
7479             if ( !phy.getName().equals( "tree 1" ) ) {
7480                 return false;
7481             }
7482             //2
7483             if ( !p.hasNext() ) {
7484                 return false;
7485             }
7486             phy = p.next();
7487             if ( phy == null ) {
7488                 return false;
7489             }
7490             if ( phy.getNumberOfExternalNodes() != 3 ) {
7491                 return false;
7492             }
7493             if ( !phy.getName().equals( "" ) ) {
7494                 return false;
7495             }
7496             if ( phy.isRooted() ) {
7497                 return false;
7498             }
7499             //3
7500             if ( !p.hasNext() ) {
7501                 return false;
7502             }
7503             phy = p.next();
7504             if ( phy == null ) {
7505                 return false;
7506             }
7507             if ( phy.getNumberOfExternalNodes() != 4 ) {
7508                 return false;
7509             }
7510             if ( !phy.getName().equals( "" ) ) {
7511                 return false;
7512             }
7513             if ( !phy.isRooted() ) {
7514                 return false;
7515             }
7516             //4
7517             if ( !p.hasNext() ) {
7518                 return false;
7519             }
7520             phy = p.next();
7521             if ( phy == null ) {
7522                 return false;
7523             }
7524             if ( phy.getNumberOfExternalNodes() != 5 ) {
7525                 System.out.println( phy.getNumberOfExternalNodes() );
7526                 return false;
7527             }
7528             if ( !phy.getName().equals( "" ) ) {
7529                 return false;
7530             }
7531             if ( !phy.isRooted() ) {
7532                 return false;
7533             }
7534             //5
7535             if ( !p.hasNext() ) {
7536                 return false;
7537             }
7538             phy = p.next();
7539             if ( phy == null ) {
7540                 return false;
7541             }
7542             if ( phy.getNumberOfExternalNodes() != 3 ) {
7543                 return false;
7544             }
7545             if ( !phy.getName().equals( "" ) ) {
7546                 return false;
7547             }
7548             if ( phy.isRooted() ) {
7549                 return false;
7550             }
7551             //
7552             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7553             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
7554             // 0
7555             if ( !p2.hasNext() ) {
7556                 return false;
7557             }
7558             phy = p2.next();
7559             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7560                 return false;
7561             }
7562             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7563                 return false;
7564             }
7565             // 1
7566             if ( !p2.hasNext() ) {
7567                 return false;
7568             }
7569             phy = p2.next();
7570             // 2
7571             if ( !p2.hasNext() ) {
7572                 return false;
7573             }
7574             phy = p2.next();
7575             // 3
7576             if ( !p2.hasNext() ) {
7577                 return false;
7578             }
7579             phy = p2.next();
7580             // 4
7581             if ( !p2.hasNext() ) {
7582                 return false;
7583             }
7584             phy = p2.next();
7585             // 5
7586             if ( !p2.hasNext() ) {
7587                 return false;
7588             }
7589             phy = p2.next();
7590             // 6
7591             if ( !p2.hasNext() ) {
7592                 return false;
7593             }
7594             phy = p2.next();
7595             // 7
7596             if ( !p2.hasNext() ) {
7597                 return false;
7598             }
7599             phy = p2.next();
7600             // 8
7601             if ( !p2.hasNext() ) {
7602                 return false;
7603             }
7604             phy = p2.next();
7605             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7606                 return false;
7607             }
7608             if ( p2.hasNext() ) {
7609                 return false;
7610             }
7611             phy = p2.next();
7612             if ( phy != null ) {
7613                 return false;
7614             }
7615             // 0
7616             p2.reset();
7617             if ( !p2.hasNext() ) {
7618                 return false;
7619             }
7620             phy = p2.next();
7621             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7622                 return false;
7623             }
7624             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7625                 return false;
7626             }
7627         }
7628         catch ( final Exception e ) {
7629             e.printStackTrace( System.out );
7630             return false;
7631         }
7632         return true;
7633     }
7634
7635     private static boolean testNexusTreeParsingTranslating() {
7636         try {
7637             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7638             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7639             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
7640             if ( phylogenies.length != 1 ) {
7641                 return false;
7642             }
7643             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7644                 return false;
7645             }
7646             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7647                 return false;
7648             }
7649             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7650                 return false;
7651             }
7652             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7653                 return false;
7654             }
7655             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7656                     .equals( "Aranaeus" ) ) {
7657                 return false;
7658             }
7659             phylogenies = null;
7660             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
7661             if ( phylogenies.length != 3 ) {
7662                 return false;
7663             }
7664             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7665                 return false;
7666             }
7667             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7668                 return false;
7669             }
7670             if ( phylogenies[ 0 ].isRooted() ) {
7671                 return false;
7672             }
7673             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7674                 return false;
7675             }
7676             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7677                 return false;
7678             }
7679             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7680                     .equals( "Aranaeus" ) ) {
7681                 return false;
7682             }
7683             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7684                 return false;
7685             }
7686             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7687                 return false;
7688             }
7689             if ( phylogenies[ 1 ].isRooted() ) {
7690                 return false;
7691             }
7692             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7693                 return false;
7694             }
7695             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7696                 return false;
7697             }
7698             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7699                     .equals( "Aranaeus" ) ) {
7700                 return false;
7701             }
7702             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7703                 return false;
7704             }
7705             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7706                 return false;
7707             }
7708             if ( !phylogenies[ 2 ].isRooted() ) {
7709                 return false;
7710             }
7711             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7712                 return false;
7713             }
7714             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7715                 return false;
7716             }
7717             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7718                     .equals( "Aranaeus" ) ) {
7719                 return false;
7720             }
7721             phylogenies = null;
7722             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
7723             if ( phylogenies.length != 3 ) {
7724                 return false;
7725             }
7726             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7727                 return false;
7728             }
7729             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7730                 return false;
7731             }
7732             if ( phylogenies[ 0 ].isRooted() ) {
7733                 return false;
7734             }
7735             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7736                 return false;
7737             }
7738             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7739                 return false;
7740             }
7741             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7742                     .equals( "Aranaeus" ) ) {
7743                 return false;
7744             }
7745             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7746                 return false;
7747             }
7748             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7749                 return false;
7750             }
7751             if ( phylogenies[ 1 ].isRooted() ) {
7752                 return false;
7753             }
7754             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7755                 return false;
7756             }
7757             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7758                 return false;
7759             }
7760             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7761                     .equals( "Aranaeus" ) ) {
7762                 return false;
7763             }
7764             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7765                 return false;
7766             }
7767             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7768                 return false;
7769             }
7770             if ( !phylogenies[ 2 ].isRooted() ) {
7771                 return false;
7772             }
7773             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7774                 return false;
7775             }
7776             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7777                 return false;
7778             }
7779             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7780                     .equals( "Aranaeus" ) ) {
7781                 return false;
7782             }
7783             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
7784             if ( phylogenies.length != 3 ) {
7785                 return false;
7786             }
7787             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
7788                            0.00100049 ) ) {
7789                 return false;
7790             }
7791         }
7792         catch ( final Exception e ) {
7793             e.printStackTrace( System.out );
7794             return false;
7795         }
7796         return true;
7797     }
7798
7799     private static boolean testNHParsing() {
7800         try {
7801             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7802             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
7803             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
7804                 return false;
7805             }
7806             final NHXParser nhxp = new NHXParser();
7807             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
7808             nhxp.setReplaceUnderscores( true );
7809             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
7810             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
7811                 return false;
7812             }
7813             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
7814                 return false;
7815             }
7816             final Phylogeny p1b = factory
7817                     .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 ",
7818                              new NHXParser() )[ 0 ];
7819             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
7820                 return false;
7821             }
7822             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
7823                 return false;
7824             }
7825             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
7826             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
7827             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
7828             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
7829             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
7830             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
7831             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
7832             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
7833             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
7834             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
7835             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
7836                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
7837                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
7838                                                     new NHXParser() );
7839             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
7840                 return false;
7841             }
7842             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
7843                 return false;
7844             }
7845             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
7846                 return false;
7847             }
7848             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
7849                 return false;
7850             }
7851             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
7852             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
7853             final String p16_S = "((A,B),C)";
7854             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
7855             if ( p16.length != 1 ) {
7856                 return false;
7857             }
7858             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
7859                 return false;
7860             }
7861             final String p17_S = "(C,(A,B))";
7862             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
7863             if ( p17.length != 1 ) {
7864                 return false;
7865             }
7866             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
7867                 return false;
7868             }
7869             final String p18_S = "((A,B),(C,D))";
7870             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
7871             if ( p18.length != 1 ) {
7872                 return false;
7873             }
7874             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
7875                 return false;
7876             }
7877             final String p19_S = "(((A,B),C),D)";
7878             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
7879             if ( p19.length != 1 ) {
7880                 return false;
7881             }
7882             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
7883                 return false;
7884             }
7885             final String p20_S = "(A,(B,(C,D)))";
7886             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
7887             if ( p20.length != 1 ) {
7888                 return false;
7889             }
7890             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
7891                 return false;
7892             }
7893             final String p21_S = "(A,(B,(C,(D,E))))";
7894             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
7895             if ( p21.length != 1 ) {
7896                 return false;
7897             }
7898             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
7899                 return false;
7900             }
7901             final String p22_S = "((((A,B),C),D),E)";
7902             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
7903             if ( p22.length != 1 ) {
7904                 return false;
7905             }
7906             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
7907                 return false;
7908             }
7909             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7910             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
7911             if ( p23.length != 1 ) {
7912                 System.out.println( "xl=" + p23.length );
7913                 System.exit( -1 );
7914                 return false;
7915             }
7916             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
7917                 return false;
7918             }
7919             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7920             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
7921             if ( p24.length != 1 ) {
7922                 return false;
7923             }
7924             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
7925                 return false;
7926             }
7927             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7928             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7929             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
7930             if ( p241.length != 2 ) {
7931                 return false;
7932             }
7933             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
7934                 return false;
7935             }
7936             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
7937                 return false;
7938             }
7939             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
7940                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
7941                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
7942                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
7943                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
7944                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
7945                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
7946                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
7947             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
7948             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
7949                 return false;
7950             }
7951             final String p26_S = "(A,B)ab";
7952             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
7953             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
7954                 return false;
7955             }
7956             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7957             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
7958             if ( p27s.length != 1 ) {
7959                 System.out.println( "xxl=" + p27s.length );
7960                 System.exit( -1 );
7961                 return false;
7962             }
7963             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
7964                 System.out.println( p27s[ 0 ].toNewHampshireX() );
7965                 System.exit( -1 );
7966                 return false;
7967             }
7968             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
7969                                                     new NHXParser() );
7970             if ( p27.length != 1 ) {
7971                 System.out.println( "yl=" + p27.length );
7972                 System.exit( -1 );
7973                 return false;
7974             }
7975             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
7976                 System.out.println( p27[ 0 ].toNewHampshireX() );
7977                 System.exit( -1 );
7978                 return false;
7979             }
7980             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7981             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7982             final String p28_S3 = "(A,B)ab";
7983             final String p28_S4 = "((((A,B),C),D),;E;)";
7984             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
7985                                                     new NHXParser() );
7986             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
7987                 return false;
7988             }
7989             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
7990                 return false;
7991             }
7992             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
7993                 return false;
7994             }
7995             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
7996                 return false;
7997             }
7998             if ( p28.length != 4 ) {
7999                 return false;
8000             }
8001             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";
8002             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
8003             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
8004                 return false;
8005             }
8006             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";
8007             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
8008             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
8009                 return false;
8010             }
8011             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
8012             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
8013             if ( ( p32.length != 0 ) ) {
8014                 return false;
8015             }
8016             final String p33_S = "A";
8017             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
8018             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
8019                 return false;
8020             }
8021             final String p34_S = "B;";
8022             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
8023             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
8024                 return false;
8025             }
8026             final String p35_S = "B:0.2";
8027             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
8028             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
8029                 return false;
8030             }
8031             final String p36_S = "(A)";
8032             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
8033             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
8034                 return false;
8035             }
8036             final String p37_S = "((A))";
8037             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
8038             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
8039                 return false;
8040             }
8041             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8042             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
8043             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
8044                 return false;
8045             }
8046             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8047             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
8048             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
8049                 return false;
8050             }
8051             final String p40_S = "(A,B,C)";
8052             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
8053             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
8054                 return false;
8055             }
8056             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
8057             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
8058             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
8059                 return false;
8060             }
8061             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
8062             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
8063             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
8064                 return false;
8065             }
8066             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)";
8067             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
8068             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
8069                 return false;
8070             }
8071             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)))";
8072             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
8073             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
8074                 return false;
8075             }
8076             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
8077             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
8078             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
8079                 return false;
8080             }
8081             final String p46_S = "";
8082             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
8083             if ( p46.length != 0 ) {
8084                 return false;
8085             }
8086             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
8087             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8088                 return false;
8089             }
8090             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8091             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8092                 return false;
8093             }
8094             final Phylogeny p49 = factory
8095                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
8096                              new NHXParser() )[ 0 ];
8097             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8098                 return false;
8099             }
8100             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8101             if ( p50.getNode( "A" ) == null ) {
8102                 return false;
8103             }
8104             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8105                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
8106                 return false;
8107             }
8108             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
8109                 return false;
8110             }
8111             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
8112                     .equals( "((A,B)88:2.0,C);" ) ) {
8113                 return false;
8114             }
8115             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8116             if ( p51.getNode( "A(A" ) == null ) {
8117                 return false;
8118             }
8119             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8120             if ( p52.getNode( "A(A" ) == null ) {
8121                 return false;
8122             }
8123             final Phylogeny p53 = factory
8124                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
8125                              new NHXParser() )[ 0 ];
8126             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
8127                 return false;
8128             }
8129             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
8130             if ( p54.getNode( "A" ) == null ) {
8131                 return false;
8132             }
8133             if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ).equals( "((A,B)[88],C);" ) ) {
8134                 return false;
8135             }
8136             final Phylogeny p55 = factory
8137                     .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);" ),
8138                              new NHXParser() )[ 0 ];
8139             if ( !p55
8140                     .toNewHampshire()
8141                     .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);" ) ) {
8142                 System.out.println( p55.toNewHampshire() );
8143                 return false;
8144             }
8145             final Phylogeny p56 = factory
8146                     .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);" ),
8147                              new NHXParser() )[ 0 ];
8148             if ( !p56
8149                     .toNewHampshire()
8150                     .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);" ) ) {
8151                 System.out.println( p56.toNewHampshire() );
8152                 return false;
8153             }
8154             final Phylogeny p57 = factory
8155                     .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);" ),
8156                              new NHXParser() )[ 0 ];
8157             if ( !p57
8158                     .toNewHampshire()
8159                     .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);" ) ) {
8160                 System.out.println( p56.toNewHampshire() );
8161                 return false;
8162             }
8163             final String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
8164             final Phylogeny p58 = factory.create( new StringBuffer( s58 ), new NHXParser() )[ 0 ];
8165             if ( !p58.toNewHampshire().equals( s58 ) ) {
8166                 System.out.println( p58.toNewHampshire() );
8167                 return false;
8168             }
8169             final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
8170             final Phylogeny p59 = factory.create( new StringBuffer( s59 ), new NHXParser() )[ 0 ];
8171             if ( !p59.toNewHampshire().equals( s59 ) ) {
8172                 System.out.println( p59.toNewHampshire() );
8173                 return false;
8174             }
8175             final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
8176             final Phylogeny p60 = factory.create( new StringBuffer( s60 ), new NHXParser() )[ 0 ];
8177             if ( !p60.toNewHampshire().equals( s60 ) ) {
8178                 System.out.println( p60.toNewHampshire() );
8179                 return false;
8180             }
8181             final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
8182             final Phylogeny p61 = factory.create( new StringBuffer( s61 ), new NHXParser() )[ 0 ];
8183             if ( !p61.toNewHampshire()
8184                     .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
8185                 System.out.println( p61.toNewHampshire() );
8186                 return false;
8187             }
8188         }
8189         catch ( final Exception e ) {
8190             e.printStackTrace( System.out );
8191             return false;
8192         }
8193         return true;
8194     }
8195
8196     private static boolean testNHParsingIter() {
8197         try {
8198             final String p0_str = "(A,B);";
8199             final NHXParser p = new NHXParser();
8200             p.setSource( p0_str );
8201             if ( !p.hasNext() ) {
8202                 return false;
8203             }
8204             final Phylogeny p0 = p.next();
8205             if ( !p0.toNewHampshire().equals( p0_str ) ) {
8206                 System.out.println( p0.toNewHampshire() );
8207                 return false;
8208             }
8209             if ( p.hasNext() ) {
8210                 return false;
8211             }
8212             if ( p.next() != null ) {
8213                 return false;
8214             }
8215             //
8216             final String p00_str = "(A,B)root;";
8217             p.setSource( p00_str );
8218             final Phylogeny p00 = p.next();
8219             if ( !p00.toNewHampshire().equals( p00_str ) ) {
8220                 System.out.println( p00.toNewHampshire() );
8221                 return false;
8222             }
8223             //
8224             final String p000_str = "A;";
8225             p.setSource( p000_str );
8226             final Phylogeny p000 = p.next();
8227             if ( !p000.toNewHampshire().equals( p000_str ) ) {
8228                 System.out.println( p000.toNewHampshire() );
8229                 return false;
8230             }
8231             //
8232             final String p0000_str = "A";
8233             p.setSource( p0000_str );
8234             final Phylogeny p0000 = p.next();
8235             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
8236                 System.out.println( p0000.toNewHampshire() );
8237                 return false;
8238             }
8239             //
8240             p.setSource( "(A)" );
8241             final Phylogeny p00000 = p.next();
8242             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
8243                 System.out.println( p00000.toNewHampshire() );
8244                 return false;
8245             }
8246             //
8247             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
8248             p.setSource( p1_str );
8249             if ( !p.hasNext() ) {
8250                 return false;
8251             }
8252             final Phylogeny p1_0 = p.next();
8253             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
8254                 System.out.println( p1_0.toNewHampshire() );
8255                 return false;
8256             }
8257             if ( !p.hasNext() ) {
8258                 return false;
8259             }
8260             final Phylogeny p1_1 = p.next();
8261             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
8262                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
8263                 return false;
8264             }
8265             if ( !p.hasNext() ) {
8266                 return false;
8267             }
8268             final Phylogeny p1_2 = p.next();
8269             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
8270                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
8271                 return false;
8272             }
8273             if ( !p.hasNext() ) {
8274                 return false;
8275             }
8276             final Phylogeny p1_3 = p.next();
8277             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
8278                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
8279                 return false;
8280             }
8281             if ( p.hasNext() ) {
8282                 return false;
8283             }
8284             if ( p.next() != null ) {
8285                 return false;
8286             }
8287             //
8288             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
8289             p.setSource( p2_str );
8290             if ( !p.hasNext() ) {
8291                 return false;
8292             }
8293             Phylogeny p2_0 = p.next();
8294             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8295                 System.out.println( p2_0.toNewHampshire() );
8296                 return false;
8297             }
8298             if ( !p.hasNext() ) {
8299                 return false;
8300             }
8301             Phylogeny p2_1 = p.next();
8302             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8303                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8304                 return false;
8305             }
8306             if ( !p.hasNext() ) {
8307                 return false;
8308             }
8309             Phylogeny p2_2 = p.next();
8310             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8311                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8312                 return false;
8313             }
8314             if ( !p.hasNext() ) {
8315                 return false;
8316             }
8317             Phylogeny p2_3 = p.next();
8318             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8319                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8320                 return false;
8321             }
8322             if ( !p.hasNext() ) {
8323                 return false;
8324             }
8325             Phylogeny p2_4 = p.next();
8326             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8327                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8328                 return false;
8329             }
8330             if ( p.hasNext() ) {
8331                 return false;
8332             }
8333             if ( p.next() != null ) {
8334                 return false;
8335             }
8336             ////
8337             p.reset();
8338             if ( !p.hasNext() ) {
8339                 return false;
8340             }
8341             p2_0 = p.next();
8342             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8343                 System.out.println( p2_0.toNewHampshire() );
8344                 return false;
8345             }
8346             if ( !p.hasNext() ) {
8347                 return false;
8348             }
8349             p2_1 = p.next();
8350             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8351                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8352                 return false;
8353             }
8354             if ( !p.hasNext() ) {
8355                 return false;
8356             }
8357             p2_2 = p.next();
8358             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8359                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8360                 return false;
8361             }
8362             if ( !p.hasNext() ) {
8363                 return false;
8364             }
8365             p2_3 = p.next();
8366             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8367                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8368                 return false;
8369             }
8370             if ( !p.hasNext() ) {
8371                 return false;
8372             }
8373             p2_4 = p.next();
8374             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8375                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8376                 return false;
8377             }
8378             if ( p.hasNext() ) {
8379                 return false;
8380             }
8381             if ( p.next() != null ) {
8382                 return false;
8383             }
8384             //
8385             final String p3_str = "((A,B),C)abc";
8386             p.setSource( p3_str );
8387             if ( !p.hasNext() ) {
8388                 return false;
8389             }
8390             final Phylogeny p3_0 = p.next();
8391             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
8392                 return false;
8393             }
8394             if ( p.hasNext() ) {
8395                 return false;
8396             }
8397             if ( p.next() != null ) {
8398                 return false;
8399             }
8400             //
8401             final String p4_str = "((A,B)ab,C)abc";
8402             p.setSource( p4_str );
8403             if ( !p.hasNext() ) {
8404                 return false;
8405             }
8406             final Phylogeny p4_0 = p.next();
8407             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
8408                 return false;
8409             }
8410             if ( p.hasNext() ) {
8411                 return false;
8412             }
8413             if ( p.next() != null ) {
8414                 return false;
8415             }
8416             //
8417             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
8418             p.setSource( p5_str );
8419             if ( !p.hasNext() ) {
8420                 return false;
8421             }
8422             final Phylogeny p5_0 = p.next();
8423             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
8424                 return false;
8425             }
8426             if ( p.hasNext() ) {
8427                 return false;
8428             }
8429             if ( p.next() != null ) {
8430                 return false;
8431             }
8432             //
8433             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8434             p.setSource( p6_str );
8435             if ( !p.hasNext() ) {
8436                 return false;
8437             }
8438             Phylogeny p6_0 = p.next();
8439             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8440                 return false;
8441             }
8442             if ( p.hasNext() ) {
8443                 return false;
8444             }
8445             if ( p.next() != null ) {
8446                 return false;
8447             }
8448             p.reset();
8449             if ( !p.hasNext() ) {
8450                 return false;
8451             }
8452             p6_0 = p.next();
8453             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8454                 return false;
8455             }
8456             if ( p.hasNext() ) {
8457                 return false;
8458             }
8459             if ( p.next() != null ) {
8460                 return false;
8461             }
8462             //
8463             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8464             p.setSource( p7_str );
8465             if ( !p.hasNext() ) {
8466                 return false;
8467             }
8468             Phylogeny p7_0 = p.next();
8469             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8470                 return false;
8471             }
8472             if ( p.hasNext() ) {
8473                 return false;
8474             }
8475             if ( p.next() != null ) {
8476                 return false;
8477             }
8478             p.reset();
8479             if ( !p.hasNext() ) {
8480                 return false;
8481             }
8482             p7_0 = p.next();
8483             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8484                 return false;
8485             }
8486             if ( p.hasNext() ) {
8487                 return false;
8488             }
8489             if ( p.next() != null ) {
8490                 return false;
8491             }
8492             //
8493             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
8494             p.setSource( p8_str );
8495             if ( !p.hasNext() ) {
8496                 return false;
8497             }
8498             Phylogeny p8_0 = p.next();
8499             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8500                 return false;
8501             }
8502             if ( !p.hasNext() ) {
8503                 return false;
8504             }
8505             if ( !p.hasNext() ) {
8506                 return false;
8507             }
8508             Phylogeny p8_1 = p.next();
8509             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8510                 return false;
8511             }
8512             if ( p.hasNext() ) {
8513                 return false;
8514             }
8515             if ( p.next() != null ) {
8516                 return false;
8517             }
8518             p.reset();
8519             if ( !p.hasNext() ) {
8520                 return false;
8521             }
8522             p8_0 = p.next();
8523             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8524                 return false;
8525             }
8526             if ( !p.hasNext() ) {
8527                 return false;
8528             }
8529             p8_1 = p.next();
8530             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8531                 return false;
8532             }
8533             if ( p.hasNext() ) {
8534                 return false;
8535             }
8536             if ( p.next() != null ) {
8537                 return false;
8538             }
8539             p.reset();
8540             //
8541             p.setSource( "" );
8542             if ( p.hasNext() ) {
8543                 return false;
8544             }
8545             //
8546             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
8547             if ( !p.hasNext() ) {
8548                 return false;
8549             }
8550             Phylogeny p_27 = p.next();
8551             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8552                 System.out.println( p_27.toNewHampshireX() );
8553                 System.exit( -1 );
8554                 return false;
8555             }
8556             if ( p.hasNext() ) {
8557                 return false;
8558             }
8559             if ( p.next() != null ) {
8560                 return false;
8561             }
8562             p.reset();
8563             if ( !p.hasNext() ) {
8564                 return false;
8565             }
8566             p_27 = p.next();
8567             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8568                 System.out.println( p_27.toNewHampshireX() );
8569                 System.exit( -1 );
8570                 return false;
8571             }
8572             if ( p.hasNext() ) {
8573                 return false;
8574             }
8575             if ( p.next() != null ) {
8576                 return false;
8577             }
8578             //
8579             final String p30_str = "(A,B);(C,D)";
8580             final NHXParser p30 = new NHXParser();
8581             p30.setSource( p30_str );
8582             if ( !p30.hasNext() ) {
8583                 return false;
8584             }
8585             Phylogeny phy30 = p30.next();
8586             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8587                 System.out.println( phy30.toNewHampshire() );
8588                 return false;
8589             }
8590             if ( !p30.hasNext() ) {
8591                 return false;
8592             }
8593             Phylogeny phy301 = p30.next();
8594             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8595                 System.out.println( phy301.toNewHampshire() );
8596                 return false;
8597             }
8598             if ( p30.hasNext() ) {
8599                 return false;
8600             }
8601             if ( p30.hasNext() ) {
8602                 return false;
8603             }
8604             if ( p30.next() != null ) {
8605                 return false;
8606             }
8607             if ( p30.next() != null ) {
8608                 return false;
8609             }
8610             p30.reset();
8611             if ( !p30.hasNext() ) {
8612                 return false;
8613             }
8614             phy30 = p30.next();
8615             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8616                 System.out.println( phy30.toNewHampshire() );
8617                 return false;
8618             }
8619             if ( !p30.hasNext() ) {
8620                 return false;
8621             }
8622             phy301 = p30.next();
8623             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8624                 System.out.println( phy301.toNewHampshire() );
8625                 return false;
8626             }
8627             if ( p30.hasNext() ) {
8628                 return false;
8629             }
8630             if ( p30.hasNext() ) {
8631                 return false;
8632             }
8633             if ( p30.next() != null ) {
8634                 return false;
8635             }
8636             if ( p30.next() != null ) {
8637                 return false;
8638             }
8639         }
8640         catch ( final Exception e ) {
8641             e.printStackTrace( System.out );
8642             return false;
8643         }
8644         return true;
8645     }
8646
8647     private static boolean testNHXconversion() {
8648         try {
8649             final PhylogenyNode n1 = new PhylogenyNode();
8650             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8651             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8652             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8653             final PhylogenyNode n5 = PhylogenyNode
8654                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
8655             final PhylogenyNode n6 = PhylogenyNode
8656                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
8657             if ( !n1.toNewHampshireX().equals( "" ) ) {
8658                 return false;
8659             }
8660             if ( !n2.toNewHampshireX().equals( "" ) ) {
8661                 return false;
8662             }
8663             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
8664                 return false;
8665             }
8666             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
8667                 return false;
8668             }
8669             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
8670                 return false;
8671             }
8672             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
8673                 System.out.println( n6.toNewHampshireX() );
8674                 return false;
8675             }
8676             final PhylogenyNode n7 = new PhylogenyNode();
8677             n7.setName( "   gks:dr-m4 \"    '    `@:[]sadq04 " );
8678             if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8679                     .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
8680                 System.out.println( n7
8681                         .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
8682                 return false;
8683             }
8684         }
8685         catch ( final Exception e ) {
8686             e.printStackTrace( System.out );
8687             return false;
8688         }
8689         return true;
8690     }
8691
8692     private static boolean testNHXNodeParsing() {
8693         try {
8694             final PhylogenyNode n1 = new PhylogenyNode();
8695             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8696             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8697             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8698             final PhylogenyNode n5 = PhylogenyNode
8699                     .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]" );
8700             if ( !n3.getName().equals( "n3" ) ) {
8701                 return false;
8702             }
8703             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8704                 return false;
8705             }
8706             if ( n3.isDuplication() ) {
8707                 return false;
8708             }
8709             if ( n3.isHasAssignedEvent() ) {
8710                 return false;
8711             }
8712             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
8713                 return false;
8714             }
8715             if ( !n4.getName().equals( "n4" ) ) {
8716                 return false;
8717             }
8718             if ( n4.getDistanceToParent() != 0.01 ) {
8719                 return false;
8720             }
8721             if ( !n5.getName().equals( "n5" ) ) {
8722                 return false;
8723             }
8724             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
8725                 return false;
8726             }
8727             if ( n5.getDistanceToParent() != 0.1 ) {
8728                 return false;
8729             }
8730             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
8731                 return false;
8732             }
8733             if ( !n5.isDuplication() ) {
8734                 return false;
8735             }
8736             if ( !n5.isHasAssignedEvent() ) {
8737                 return false;
8738             }
8739             final PhylogenyNode n8 = PhylogenyNode
8740                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
8741                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8742             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8743                 return false;
8744             }
8745             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
8746                 return false;
8747             }
8748             final PhylogenyNode n9 = PhylogenyNode
8749                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
8750                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8751             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
8752                 return false;
8753             }
8754             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
8755                 return false;
8756             }
8757             final PhylogenyNode n10 = PhylogenyNode
8758                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8759             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
8760                 return false;
8761             }
8762             final PhylogenyNode n20 = PhylogenyNode
8763                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8764             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8765                 return false;
8766             }
8767             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
8768                 return false;
8769             }
8770             final PhylogenyNode n20x = PhylogenyNode
8771                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8772             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
8773                 return false;
8774             }
8775             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
8776                 return false;
8777             }
8778             final PhylogenyNode n20xx = PhylogenyNode
8779                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8780             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
8781                 return false;
8782             }
8783             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
8784                 return false;
8785             }
8786             final PhylogenyNode n20xxx = PhylogenyNode
8787                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8788             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
8789                 return false;
8790             }
8791             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
8792                 return false;
8793             }
8794             final PhylogenyNode n20xxxx = PhylogenyNode
8795                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8796             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
8797                 return false;
8798             }
8799             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
8800                 return false;
8801             }
8802             final PhylogenyNode n21 = PhylogenyNode
8803                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8804             if ( !n21.getName().equals( "N21_PIG" ) ) {
8805                 return false;
8806             }
8807             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
8808                 return false;
8809             }
8810             final PhylogenyNode n21x = PhylogenyNode
8811                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8812             if ( !n21x.getName().equals( "n21_PIG" ) ) {
8813                 return false;
8814             }
8815             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
8816                 return false;
8817             }
8818             final PhylogenyNode n22 = PhylogenyNode
8819                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8820             if ( !n22.getName().equals( "n22/PIG" ) ) {
8821                 return false;
8822             }
8823             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
8824                 return false;
8825             }
8826             final PhylogenyNode n23 = PhylogenyNode
8827                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8828             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
8829                 return false;
8830             }
8831             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
8832                 return false;
8833             }
8834             final PhylogenyNode a = PhylogenyNode
8835                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8836             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8837                 return false;
8838             }
8839             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
8840                 return false;
8841             }
8842             final PhylogenyNode c1 = PhylogenyNode
8843                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
8844                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8845             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
8846                 return false;
8847             }
8848             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
8849                 return false;
8850             }
8851             final PhylogenyNode c2 = PhylogenyNode
8852                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
8853                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8854             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
8855                 return false;
8856             }
8857             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
8858                 return false;
8859             }
8860             final PhylogenyNode e3 = PhylogenyNode
8861                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8862             if ( !e3.getName().equals( "n10_RAT~" ) ) {
8863                 return false;
8864             }
8865             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
8866                 return false;
8867             }
8868             final PhylogenyNode n11 = PhylogenyNode
8869                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
8870                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8871             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
8872                 return false;
8873             }
8874             if ( n11.getDistanceToParent() != 0.4 ) {
8875                 return false;
8876             }
8877             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
8878                 return false;
8879             }
8880             final PhylogenyNode n12 = PhylogenyNode
8881                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
8882                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8883             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
8884                 return false;
8885             }
8886             if ( n12.getDistanceToParent() != 0.4 ) {
8887                 return false;
8888             }
8889             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
8890                 return false;
8891             }
8892             final PhylogenyNode o = PhylogenyNode
8893                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8894             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
8895                 return false;
8896             }
8897             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
8898                 return false;
8899             }
8900             if ( n1.getName().compareTo( "" ) != 0 ) {
8901                 return false;
8902             }
8903             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
8904                 return false;
8905             }
8906             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8907                 return false;
8908             }
8909             if ( n2.getName().compareTo( "" ) != 0 ) {
8910                 return false;
8911             }
8912             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
8913                 return false;
8914             }
8915             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8916                 return false;
8917             }
8918             final PhylogenyNode n00 = PhylogenyNode
8919                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
8920             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
8921                 return false;
8922             }
8923             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
8924                 return false;
8925             }
8926             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
8927             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
8928                 return false;
8929             }
8930             final PhylogenyNode n13 = PhylogenyNode
8931                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8932             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
8933                 return false;
8934             }
8935             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
8936                 return false;
8937             }
8938             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
8939                 return false;
8940             }
8941             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8942                 return false;
8943             }
8944             final PhylogenyNode n14 = PhylogenyNode
8945                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8946             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
8947                 return false;
8948             }
8949             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
8950                 return false;
8951             }
8952             final PhylogenyNode n15 = PhylogenyNode
8953                     .createInstanceFromNhxString( "something_wicked[123]",
8954                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8955             if ( !n15.getName().equals( "something_wicked" ) ) {
8956                 return false;
8957             }
8958             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
8959                 return false;
8960             }
8961             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
8962                 return false;
8963             }
8964             final PhylogenyNode n16 = PhylogenyNode
8965                     .createInstanceFromNhxString( "something_wicked2[9]",
8966                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8967             if ( !n16.getName().equals( "something_wicked2" ) ) {
8968                 return false;
8969             }
8970             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
8971                 return false;
8972             }
8973             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
8974                 return false;
8975             }
8976             final PhylogenyNode n17 = PhylogenyNode
8977                     .createInstanceFromNhxString( "something_wicked3[a]",
8978                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8979             if ( !n17.getName().equals( "something_wicked3" ) ) {
8980                 return false;
8981             }
8982             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
8983                 return false;
8984             }
8985             final PhylogenyNode n18 = PhylogenyNode
8986                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8987             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
8988                 return false;
8989             }
8990             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
8991                 return false;
8992             }
8993             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
8994                 return false;
8995             }
8996             final PhylogenyNode n19 = PhylogenyNode
8997                     .createInstanceFromNhxString( "BLAH_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8998             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
8999                 return false;
9000             }
9001             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9002                 return false;
9003             }
9004             final PhylogenyNode n30 = PhylogenyNode
9005                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
9006                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9007             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
9008                 return false;
9009             }
9010             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9011                 return false;
9012             }
9013             final PhylogenyNode n31 = PhylogenyNode
9014                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
9015                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9016             if ( n31.getNodeData().isHasTaxonomy() ) {
9017                 return false;
9018             }
9019             final PhylogenyNode n32 = PhylogenyNode
9020                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9021             if ( n32.getNodeData().isHasTaxonomy() ) {
9022                 return false;
9023             }
9024             final PhylogenyNode n40 = PhylogenyNode
9025                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9026             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9027                 return false;
9028             }
9029             final PhylogenyNode n41 = PhylogenyNode
9030                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9031             if ( n41.getNodeData().isHasTaxonomy() ) {
9032                 return false;
9033             }
9034             final PhylogenyNode n42 = PhylogenyNode
9035                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9036             if ( n42.getNodeData().isHasTaxonomy() ) {
9037                 return false;
9038             }
9039             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
9040                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
9041             if ( n43.getNodeData().isHasTaxonomy() ) {
9042                 return false;
9043             }
9044             final PhylogenyNode n44 = PhylogenyNode
9045                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9046             if ( n44.getNodeData().isHasTaxonomy() ) {
9047                 return false;
9048             }
9049         }
9050         catch ( final Exception e ) {
9051             e.printStackTrace( System.out );
9052             return false;
9053         }
9054         return true;
9055     }
9056
9057     private static boolean testNHXParsing() {
9058         try {
9059             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9060             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
9061             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
9062                 return false;
9063             }
9064             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]";
9065             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
9066             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9067                 return false;
9068             }
9069             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]";
9070             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
9071             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
9072                 return false;
9073             }
9074             final Phylogeny[] p3 = factory
9075                     .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]",
9076                              new NHXParser() );
9077             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9078                 return false;
9079             }
9080             final Phylogeny[] p4 = factory
9081                     .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(]",
9082                              new NHXParser() );
9083             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9084                 return false;
9085             }
9086             final Phylogeny[] p5 = factory
9087                     .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(((]",
9088                              new NHXParser() );
9089             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9090                 return false;
9091             }
9092             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)";
9093             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)";
9094             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
9095             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
9096                 return false;
9097             }
9098             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)))";
9099             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)))";
9100             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
9101             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
9102                 return false;
9103             }
9104             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])   ))[,,, ])))))))";
9105             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
9106             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
9107             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
9108                 return false;
9109             }
9110             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
9111             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9112                 return false;
9113             }
9114             final Phylogeny p10 = factory
9115                     .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]",
9116                              new NHXParser() )[ 0 ];
9117             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9118                 return false;
9119             }
9120             final Phylogeny p11 = factory
9121                     .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]",
9122                              new NHXParser() )[ 0 ];
9123             if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9124                 return false;
9125             }
9126         }
9127         catch ( final Exception e ) {
9128             e.printStackTrace( System.out );
9129             return false;
9130         }
9131         return true;
9132     }
9133
9134     private static boolean testNHXParsingMB() {
9135         try {
9136             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9137             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
9138                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9139                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9140                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9141                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9142                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9143                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9144                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9145                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
9146             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
9147                 return false;
9148             }
9149             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
9150                 return false;
9151             }
9152             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
9153                            0.1100000000000000e+00 ) ) {
9154                 return false;
9155             }
9156             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
9157                 return false;
9158             }
9159             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
9160                 return false;
9161             }
9162             final Phylogeny p2 = factory
9163                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
9164                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9165                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9166                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9167                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9168                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9169                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9170                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9171                                      + "7.369400000000000e-02}])",
9172                              new NHXParser() )[ 0 ];
9173             if ( p2.getNode( "1" ) == null ) {
9174                 return false;
9175             }
9176             if ( p2.getNode( "2" ) == null ) {
9177                 return false;
9178             }
9179         }
9180         catch ( final Exception e ) {
9181             e.printStackTrace( System.out );
9182             System.exit( -1 );
9183             return false;
9184         }
9185         return true;
9186     }
9187
9188     private static boolean testNHXParsingQuotes() {
9189         try {
9190             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9191             final NHXParser p = new NHXParser();
9192             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
9193             if ( phylogenies_0.length != 5 ) {
9194                 return false;
9195             }
9196             final Phylogeny phy = phylogenies_0[ 4 ];
9197             if ( phy.getNumberOfExternalNodes() != 7 ) {
9198                 return false;
9199             }
9200             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
9201                 return false;
9202             }
9203             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
9204                 return false;
9205             }
9206             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
9207                     .getScientificName().equals( "hsapiens" ) ) {
9208                 return false;
9209             }
9210             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
9211                 return false;
9212             }
9213             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
9214                 return false;
9215             }
9216             if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
9217                 return false;
9218             }
9219             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
9220                 return false;
9221             }
9222             if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
9223                 return false;
9224             }
9225             final NHXParser p1p = new NHXParser();
9226             p1p.setIgnoreQuotes( true );
9227             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
9228             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
9229                 return false;
9230             }
9231             final NHXParser p2p = new NHXParser();
9232             p1p.setIgnoreQuotes( false );
9233             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
9234             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
9235                 return false;
9236             }
9237             final NHXParser p3p = new NHXParser();
9238             p3p.setIgnoreQuotes( false );
9239             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
9240             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
9241                 return false;
9242             }
9243             final NHXParser p4p = new NHXParser();
9244             p4p.setIgnoreQuotes( false );
9245             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
9246             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
9247                 return false;
9248             }
9249             final Phylogeny p10 = factory
9250                     .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]",
9251                              new NHXParser() )[ 0 ];
9252             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]";
9253             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
9254                 return false;
9255             }
9256             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
9257             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
9258                 return false;
9259             }
9260             final Phylogeny p12 = factory
9261                     .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]",
9262                              new NHXParser() )[ 0 ];
9263             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]";
9264             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
9265                 return false;
9266             }
9267             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
9268             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
9269                 return false;
9270             }
9271             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;";
9272             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
9273                 return false;
9274             }
9275             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
9276             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
9277                 return false;
9278             }
9279         }
9280         catch ( final Exception e ) {
9281             e.printStackTrace( System.out );
9282             return false;
9283         }
9284         return true;
9285     }
9286
9287     private static boolean testNodeRemoval() {
9288         try {
9289             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9290             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
9291             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
9292             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
9293                 return false;
9294             }
9295             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
9296             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
9297             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
9298                 return false;
9299             }
9300             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
9301             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
9302             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
9303                 return false;
9304             }
9305         }
9306         catch ( final Exception e ) {
9307             e.printStackTrace( System.out );
9308             return false;
9309         }
9310         return true;
9311     }
9312
9313     private static boolean testPhylogenyBranch() {
9314         try {
9315             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
9316             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
9317             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
9318             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
9319             if ( !a1b1.equals( a1b1 ) ) {
9320                 return false;
9321             }
9322             if ( !a1b1.equals( b1a1 ) ) {
9323                 return false;
9324             }
9325             if ( !b1a1.equals( a1b1 ) ) {
9326                 return false;
9327             }
9328             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
9329             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
9330             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
9331             if ( a1_b1.equals( b1_a1 ) ) {
9332                 return false;
9333             }
9334             if ( a1_b1.equals( a1_b1_ ) ) {
9335                 return false;
9336             }
9337             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
9338             if ( !a1_b1.equals( b1_a1_ ) ) {
9339                 return false;
9340             }
9341             if ( a1_b1_.equals( b1_a1_ ) ) {
9342                 return false;
9343             }
9344             if ( !a1_b1_.equals( b1_a1 ) ) {
9345                 return false;
9346             }
9347         }
9348         catch ( final Exception e ) {
9349             e.printStackTrace( System.out );
9350             return false;
9351         }
9352         return true;
9353     }
9354
9355     private static boolean testPhyloXMLparsingOfDistributionElement() {
9356         try {
9357             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9358             PhyloXmlParser xml_parser = null;
9359             try {
9360                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
9361             }
9362             catch ( final Exception e ) {
9363                 // Do nothing -- means were not running from jar.
9364             }
9365             if ( xml_parser == null ) {
9366                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
9367                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
9368                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
9369                 }
9370                 else {
9371                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
9372                 }
9373             }
9374             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
9375                                                               xml_parser );
9376             if ( xml_parser.getErrorCount() > 0 ) {
9377                 System.out.println( xml_parser.getErrorMessages().toString() );
9378                 return false;
9379             }
9380             if ( phylogenies_0.length != 1 ) {
9381                 return false;
9382             }
9383             final Phylogeny t1 = phylogenies_0[ 0 ];
9384             PhylogenyNode n = null;
9385             Distribution d = null;
9386             n = t1.getNode( "root node" );
9387             if ( !n.getNodeData().isHasDistribution() ) {
9388                 return false;
9389             }
9390             if ( n.getNodeData().getDistributions().size() != 1 ) {
9391                 return false;
9392             }
9393             d = n.getNodeData().getDistribution();
9394             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9395                 return false;
9396             }
9397             if ( d.getPoints().size() != 1 ) {
9398                 return false;
9399             }
9400             if ( d.getPolygons() != null ) {
9401                 return false;
9402             }
9403             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9404                 return false;
9405             }
9406             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9407                 return false;
9408             }
9409             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9410                 return false;
9411             }
9412             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9413                 return false;
9414             }
9415             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9416                 return false;
9417             }
9418             n = t1.getNode( "node a" );
9419             if ( !n.getNodeData().isHasDistribution() ) {
9420                 return false;
9421             }
9422             if ( n.getNodeData().getDistributions().size() != 2 ) {
9423                 return false;
9424             }
9425             d = n.getNodeData().getDistribution( 1 );
9426             if ( !d.getDesc().equals( "San Diego" ) ) {
9427                 return false;
9428             }
9429             if ( d.getPoints().size() != 1 ) {
9430                 return false;
9431             }
9432             if ( d.getPolygons() != null ) {
9433                 return false;
9434             }
9435             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9436                 return false;
9437             }
9438             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9439                 return false;
9440             }
9441             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9442                 return false;
9443             }
9444             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9445                 return false;
9446             }
9447             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9448                 return false;
9449             }
9450             n = t1.getNode( "node bb" );
9451             if ( !n.getNodeData().isHasDistribution() ) {
9452                 return false;
9453             }
9454             if ( n.getNodeData().getDistributions().size() != 1 ) {
9455                 return false;
9456             }
9457             d = n.getNodeData().getDistribution( 0 );
9458             if ( d.getPoints().size() != 3 ) {
9459                 return false;
9460             }
9461             if ( d.getPolygons().size() != 2 ) {
9462                 return false;
9463             }
9464             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9465                 return false;
9466             }
9467             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9468                 return false;
9469             }
9470             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9471                 return false;
9472             }
9473             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9474                 return false;
9475             }
9476             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9477                 return false;
9478             }
9479             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9480                 return false;
9481             }
9482             Polygon p = d.getPolygons().get( 0 );
9483             if ( p.getPoints().size() != 3 ) {
9484                 return false;
9485             }
9486             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9487                 return false;
9488             }
9489             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9490                 return false;
9491             }
9492             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9493                 return false;
9494             }
9495             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9496                 return false;
9497             }
9498             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9499                 return false;
9500             }
9501             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9502                 return false;
9503             }
9504             p = d.getPolygons().get( 1 );
9505             if ( p.getPoints().size() != 3 ) {
9506                 return false;
9507             }
9508             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9509                 return false;
9510             }
9511             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9512                 return false;
9513             }
9514             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9515                 return false;
9516             }
9517             // Roundtrip:
9518             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
9519             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
9520             if ( rt.length != 1 ) {
9521                 return false;
9522             }
9523             final Phylogeny t1_rt = rt[ 0 ];
9524             n = t1_rt.getNode( "root node" );
9525             if ( !n.getNodeData().isHasDistribution() ) {
9526                 return false;
9527             }
9528             if ( n.getNodeData().getDistributions().size() != 1 ) {
9529                 return false;
9530             }
9531             d = n.getNodeData().getDistribution();
9532             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9533                 return false;
9534             }
9535             if ( d.getPoints().size() != 1 ) {
9536                 return false;
9537             }
9538             if ( d.getPolygons() != null ) {
9539                 return false;
9540             }
9541             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9542                 return false;
9543             }
9544             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9545                 return false;
9546             }
9547             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9548                 return false;
9549             }
9550             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9551                 return false;
9552             }
9553             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9554                 return false;
9555             }
9556             n = t1_rt.getNode( "node a" );
9557             if ( !n.getNodeData().isHasDistribution() ) {
9558                 return false;
9559             }
9560             if ( n.getNodeData().getDistributions().size() != 2 ) {
9561                 return false;
9562             }
9563             d = n.getNodeData().getDistribution( 1 );
9564             if ( !d.getDesc().equals( "San Diego" ) ) {
9565                 return false;
9566             }
9567             if ( d.getPoints().size() != 1 ) {
9568                 return false;
9569             }
9570             if ( d.getPolygons() != null ) {
9571                 return false;
9572             }
9573             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9574                 return false;
9575             }
9576             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9577                 return false;
9578             }
9579             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9580                 return false;
9581             }
9582             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9583                 return false;
9584             }
9585             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9586                 return false;
9587             }
9588             n = t1_rt.getNode( "node bb" );
9589             if ( !n.getNodeData().isHasDistribution() ) {
9590                 return false;
9591             }
9592             if ( n.getNodeData().getDistributions().size() != 1 ) {
9593                 return false;
9594             }
9595             d = n.getNodeData().getDistribution( 0 );
9596             if ( d.getPoints().size() != 3 ) {
9597                 return false;
9598             }
9599             if ( d.getPolygons().size() != 2 ) {
9600                 return false;
9601             }
9602             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9603                 return false;
9604             }
9605             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9606                 return false;
9607             }
9608             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9609                 return false;
9610             }
9611             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9612                 return false;
9613             }
9614             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9615                 return false;
9616             }
9617             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9618                 return false;
9619             }
9620             p = d.getPolygons().get( 0 );
9621             if ( p.getPoints().size() != 3 ) {
9622                 return false;
9623             }
9624             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9625                 return false;
9626             }
9627             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9628                 return false;
9629             }
9630             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9631                 return false;
9632             }
9633             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9634                 return false;
9635             }
9636             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9637                 return false;
9638             }
9639             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9640                 return false;
9641             }
9642             p = d.getPolygons().get( 1 );
9643             if ( p.getPoints().size() != 3 ) {
9644                 return false;
9645             }
9646             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9647                 return false;
9648             }
9649             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9650                 return false;
9651             }
9652             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9653                 return false;
9654             }
9655         }
9656         catch ( final Exception e ) {
9657             e.printStackTrace( System.out );
9658             return false;
9659         }
9660         return true;
9661     }
9662
9663     private static boolean testPostOrderIterator() {
9664         try {
9665             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9666             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9667             PhylogenyNodeIterator it0;
9668             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
9669                 it0.next();
9670             }
9671             for( it0.reset(); it0.hasNext(); ) {
9672                 it0.next();
9673             }
9674             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9675             final PhylogenyNodeIterator it = t1.iteratorPostorder();
9676             if ( !it.next().getName().equals( "A" ) ) {
9677                 return false;
9678             }
9679             if ( !it.next().getName().equals( "B" ) ) {
9680                 return false;
9681             }
9682             if ( !it.next().getName().equals( "ab" ) ) {
9683                 return false;
9684             }
9685             if ( !it.next().getName().equals( "C" ) ) {
9686                 return false;
9687             }
9688             if ( !it.next().getName().equals( "D" ) ) {
9689                 return false;
9690             }
9691             if ( !it.next().getName().equals( "cd" ) ) {
9692                 return false;
9693             }
9694             if ( !it.next().getName().equals( "abcd" ) ) {
9695                 return false;
9696             }
9697             if ( !it.next().getName().equals( "E" ) ) {
9698                 return false;
9699             }
9700             if ( !it.next().getName().equals( "F" ) ) {
9701                 return false;
9702             }
9703             if ( !it.next().getName().equals( "ef" ) ) {
9704                 return false;
9705             }
9706             if ( !it.next().getName().equals( "G" ) ) {
9707                 return false;
9708             }
9709             if ( !it.next().getName().equals( "H" ) ) {
9710                 return false;
9711             }
9712             if ( !it.next().getName().equals( "gh" ) ) {
9713                 return false;
9714             }
9715             if ( !it.next().getName().equals( "efgh" ) ) {
9716                 return false;
9717             }
9718             if ( !it.next().getName().equals( "r" ) ) {
9719                 return false;
9720             }
9721             if ( it.hasNext() ) {
9722                 return false;
9723             }
9724         }
9725         catch ( final Exception e ) {
9726             e.printStackTrace( System.out );
9727             return false;
9728         }
9729         return true;
9730     }
9731
9732     private static boolean testPreOrderIterator() {
9733         try {
9734             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9735             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9736             PhylogenyNodeIterator it0;
9737             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
9738                 it0.next();
9739             }
9740             for( it0.reset(); it0.hasNext(); ) {
9741                 it0.next();
9742             }
9743             PhylogenyNodeIterator it = t0.iteratorPreorder();
9744             if ( !it.next().getName().equals( "r" ) ) {
9745                 return false;
9746             }
9747             if ( !it.next().getName().equals( "ab" ) ) {
9748                 return false;
9749             }
9750             if ( !it.next().getName().equals( "A" ) ) {
9751                 return false;
9752             }
9753             if ( !it.next().getName().equals( "B" ) ) {
9754                 return false;
9755             }
9756             if ( !it.next().getName().equals( "cd" ) ) {
9757                 return false;
9758             }
9759             if ( !it.next().getName().equals( "C" ) ) {
9760                 return false;
9761             }
9762             if ( !it.next().getName().equals( "D" ) ) {
9763                 return false;
9764             }
9765             if ( it.hasNext() ) {
9766                 return false;
9767             }
9768             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9769             it = t1.iteratorPreorder();
9770             if ( !it.next().getName().equals( "r" ) ) {
9771                 return false;
9772             }
9773             if ( !it.next().getName().equals( "abcd" ) ) {
9774                 return false;
9775             }
9776             if ( !it.next().getName().equals( "ab" ) ) {
9777                 return false;
9778             }
9779             if ( !it.next().getName().equals( "A" ) ) {
9780                 return false;
9781             }
9782             if ( !it.next().getName().equals( "B" ) ) {
9783                 return false;
9784             }
9785             if ( !it.next().getName().equals( "cd" ) ) {
9786                 return false;
9787             }
9788             if ( !it.next().getName().equals( "C" ) ) {
9789                 return false;
9790             }
9791             if ( !it.next().getName().equals( "D" ) ) {
9792                 return false;
9793             }
9794             if ( !it.next().getName().equals( "efgh" ) ) {
9795                 return false;
9796             }
9797             if ( !it.next().getName().equals( "ef" ) ) {
9798                 return false;
9799             }
9800             if ( !it.next().getName().equals( "E" ) ) {
9801                 return false;
9802             }
9803             if ( !it.next().getName().equals( "F" ) ) {
9804                 return false;
9805             }
9806             if ( !it.next().getName().equals( "gh" ) ) {
9807                 return false;
9808             }
9809             if ( !it.next().getName().equals( "G" ) ) {
9810                 return false;
9811             }
9812             if ( !it.next().getName().equals( "H" ) ) {
9813                 return false;
9814             }
9815             if ( it.hasNext() ) {
9816                 return false;
9817             }
9818         }
9819         catch ( final Exception e ) {
9820             e.printStackTrace( System.out );
9821             return false;
9822         }
9823         return true;
9824     }
9825
9826     private static boolean testPropertiesMap() {
9827         try {
9828             final PropertiesMap pm = new PropertiesMap();
9829             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
9830             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
9831             final Property p2 = new Property( "something:else",
9832                                               "?",
9833                                               "improbable:research",
9834                                               "xsd:decimal",
9835                                               AppliesTo.NODE );
9836             pm.addProperty( p0 );
9837             pm.addProperty( p1 );
9838             pm.addProperty( p2 );
9839             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
9840                 return false;
9841             }
9842             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
9843                 return false;
9844             }
9845             if ( pm.getProperties().size() != 3 ) {
9846                 return false;
9847             }
9848             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
9849                 return false;
9850             }
9851             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
9852                 return false;
9853             }
9854             if ( pm.getProperties().size() != 3 ) {
9855                 return false;
9856             }
9857             pm.removeProperty( "dimensions:diameter" );
9858             if ( pm.getProperties().size() != 2 ) {
9859                 return false;
9860             }
9861             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
9862                 return false;
9863             }
9864             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
9865                 return false;
9866             }
9867         }
9868         catch ( final Exception e ) {
9869             e.printStackTrace( System.out );
9870             return false;
9871         }
9872         return true;
9873     }
9874
9875     private static boolean testProteinId() {
9876         try {
9877             final ProteinId id1 = new ProteinId( "a" );
9878             final ProteinId id2 = new ProteinId( "a" );
9879             final ProteinId id3 = new ProteinId( "A" );
9880             final ProteinId id4 = new ProteinId( "b" );
9881             if ( !id1.equals( id1 ) ) {
9882                 return false;
9883             }
9884             if ( id1.getId().equals( "x" ) ) {
9885                 return false;
9886             }
9887             if ( id1.getId().equals( null ) ) {
9888                 return false;
9889             }
9890             if ( !id1.equals( id2 ) ) {
9891                 return false;
9892             }
9893             if ( id1.equals( id3 ) ) {
9894                 return false;
9895             }
9896             if ( id1.hashCode() != id1.hashCode() ) {
9897                 return false;
9898             }
9899             if ( id1.hashCode() != id2.hashCode() ) {
9900                 return false;
9901             }
9902             if ( id1.hashCode() == id3.hashCode() ) {
9903                 return false;
9904             }
9905             if ( id1.compareTo( id1 ) != 0 ) {
9906                 return false;
9907             }
9908             if ( id1.compareTo( id2 ) != 0 ) {
9909                 return false;
9910             }
9911             if ( id1.compareTo( id3 ) != 0 ) {
9912                 return false;
9913             }
9914             if ( id1.compareTo( id4 ) >= 0 ) {
9915                 return false;
9916             }
9917             if ( id4.compareTo( id1 ) <= 0 ) {
9918                 return false;
9919             }
9920             if ( !id4.getId().equals( "b" ) ) {
9921                 return false;
9922             }
9923             final ProteinId id5 = new ProteinId( " C " );
9924             if ( !id5.getId().equals( "C" ) ) {
9925                 return false;
9926             }
9927             if ( id5.equals( id1 ) ) {
9928                 return false;
9929             }
9930         }
9931         catch ( final Exception e ) {
9932             e.printStackTrace( System.out );
9933             return false;
9934         }
9935         return true;
9936     }
9937
9938     private static boolean testReIdMethods() {
9939         try {
9940             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9941             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
9942             final long count = PhylogenyNode.getNodeCount();
9943             p.levelOrderReID();
9944             if ( p.getNode( "r" ).getId() != count ) {
9945                 return false;
9946             }
9947             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
9948                 return false;
9949             }
9950             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
9951                 return false;
9952             }
9953             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
9954                 return false;
9955             }
9956             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
9957                 return false;
9958             }
9959             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
9960                 return false;
9961             }
9962             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
9963                 return false;
9964             }
9965             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
9966                 return false;
9967             }
9968             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
9969                 return false;
9970             }
9971             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
9972                 return false;
9973             }
9974             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
9975                 return false;
9976             }
9977             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
9978                 return false;
9979             }
9980             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
9981                 return false;
9982             }
9983             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
9984                 return false;
9985             }
9986             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
9987                 return false;
9988             }
9989         }
9990         catch ( final Exception e ) {
9991             e.printStackTrace( System.out );
9992             return false;
9993         }
9994         return true;
9995     }
9996
9997     private static boolean testRerooting() {
9998         try {
9999             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10000             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",
10001                                                  new NHXParser() )[ 0 ];
10002             if ( !t1.isRooted() ) {
10003                 return false;
10004             }
10005             t1.reRoot( t1.getNode( "D" ) );
10006             t1.reRoot( t1.getNode( "CD" ) );
10007             t1.reRoot( t1.getNode( "A" ) );
10008             t1.reRoot( t1.getNode( "B" ) );
10009             t1.reRoot( t1.getNode( "AB" ) );
10010             t1.reRoot( t1.getNode( "D" ) );
10011             t1.reRoot( t1.getNode( "C" ) );
10012             t1.reRoot( t1.getNode( "CD" ) );
10013             t1.reRoot( t1.getNode( "A" ) );
10014             t1.reRoot( t1.getNode( "B" ) );
10015             t1.reRoot( t1.getNode( "AB" ) );
10016             t1.reRoot( t1.getNode( "D" ) );
10017             t1.reRoot( t1.getNode( "D" ) );
10018             t1.reRoot( t1.getNode( "C" ) );
10019             t1.reRoot( t1.getNode( "A" ) );
10020             t1.reRoot( t1.getNode( "B" ) );
10021             t1.reRoot( t1.getNode( "AB" ) );
10022             t1.reRoot( t1.getNode( "C" ) );
10023             t1.reRoot( t1.getNode( "D" ) );
10024             t1.reRoot( t1.getNode( "CD" ) );
10025             t1.reRoot( t1.getNode( "D" ) );
10026             t1.reRoot( t1.getNode( "A" ) );
10027             t1.reRoot( t1.getNode( "B" ) );
10028             t1.reRoot( t1.getNode( "AB" ) );
10029             t1.reRoot( t1.getNode( "C" ) );
10030             t1.reRoot( t1.getNode( "D" ) );
10031             t1.reRoot( t1.getNode( "CD" ) );
10032             t1.reRoot( t1.getNode( "D" ) );
10033             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
10034                 return false;
10035             }
10036             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
10037                 return false;
10038             }
10039             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
10040                 return false;
10041             }
10042             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
10043                 return false;
10044             }
10045             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
10046                 return false;
10047             }
10048             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
10049                 return false;
10050             }
10051             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",
10052                                                  new NHXParser() )[ 0 ];
10053             t2.reRoot( t2.getNode( "A" ) );
10054             t2.reRoot( t2.getNode( "D" ) );
10055             t2.reRoot( t2.getNode( "ABC" ) );
10056             t2.reRoot( t2.getNode( "A" ) );
10057             t2.reRoot( t2.getNode( "B" ) );
10058             t2.reRoot( t2.getNode( "D" ) );
10059             t2.reRoot( t2.getNode( "C" ) );
10060             t2.reRoot( t2.getNode( "ABC" ) );
10061             t2.reRoot( t2.getNode( "A" ) );
10062             t2.reRoot( t2.getNode( "B" ) );
10063             t2.reRoot( t2.getNode( "AB" ) );
10064             t2.reRoot( t2.getNode( "AB" ) );
10065             t2.reRoot( t2.getNode( "D" ) );
10066             t2.reRoot( t2.getNode( "C" ) );
10067             t2.reRoot( t2.getNode( "B" ) );
10068             t2.reRoot( t2.getNode( "AB" ) );
10069             t2.reRoot( t2.getNode( "D" ) );
10070             t2.reRoot( t2.getNode( "D" ) );
10071             t2.reRoot( t2.getNode( "ABC" ) );
10072             t2.reRoot( t2.getNode( "A" ) );
10073             t2.reRoot( t2.getNode( "B" ) );
10074             t2.reRoot( t2.getNode( "AB" ) );
10075             t2.reRoot( t2.getNode( "D" ) );
10076             t2.reRoot( t2.getNode( "C" ) );
10077             t2.reRoot( t2.getNode( "ABC" ) );
10078             t2.reRoot( t2.getNode( "A" ) );
10079             t2.reRoot( t2.getNode( "B" ) );
10080             t2.reRoot( t2.getNode( "AB" ) );
10081             t2.reRoot( t2.getNode( "D" ) );
10082             t2.reRoot( t2.getNode( "D" ) );
10083             t2.reRoot( t2.getNode( "C" ) );
10084             t2.reRoot( t2.getNode( "A" ) );
10085             t2.reRoot( t2.getNode( "B" ) );
10086             t2.reRoot( t2.getNode( "AB" ) );
10087             t2.reRoot( t2.getNode( "C" ) );
10088             t2.reRoot( t2.getNode( "D" ) );
10089             t2.reRoot( t2.getNode( "ABC" ) );
10090             t2.reRoot( t2.getNode( "D" ) );
10091             t2.reRoot( t2.getNode( "A" ) );
10092             t2.reRoot( t2.getNode( "B" ) );
10093             t2.reRoot( t2.getNode( "AB" ) );
10094             t2.reRoot( t2.getNode( "C" ) );
10095             t2.reRoot( t2.getNode( "D" ) );
10096             t2.reRoot( t2.getNode( "ABC" ) );
10097             t2.reRoot( t2.getNode( "D" ) );
10098             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10099                 return false;
10100             }
10101             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10102                 return false;
10103             }
10104             t2.reRoot( t2.getNode( "ABC" ) );
10105             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10106                 return false;
10107             }
10108             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10109                 return false;
10110             }
10111             t2.reRoot( t2.getNode( "AB" ) );
10112             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10113                 return false;
10114             }
10115             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10116                 return false;
10117             }
10118             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10119                 return false;
10120             }
10121             t2.reRoot( t2.getNode( "AB" ) );
10122             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10123                 return false;
10124             }
10125             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10126                 return false;
10127             }
10128             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10129                 return false;
10130             }
10131             t2.reRoot( t2.getNode( "D" ) );
10132             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10133                 return false;
10134             }
10135             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10136                 return false;
10137             }
10138             t2.reRoot( t2.getNode( "ABC" ) );
10139             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10140                 return false;
10141             }
10142             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10143                 return false;
10144             }
10145             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
10146                                                  new NHXParser() )[ 0 ];
10147             t3.reRoot( t3.getNode( "B" ) );
10148             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10149                 return false;
10150             }
10151             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10152                 return false;
10153             }
10154             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10155                 return false;
10156             }
10157             t3.reRoot( t3.getNode( "B" ) );
10158             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10159                 return false;
10160             }
10161             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10162                 return false;
10163             }
10164             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10165                 return false;
10166             }
10167             t3.reRoot( t3.getRoot() );
10168             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10169                 return false;
10170             }
10171             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10172                 return false;
10173             }
10174             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10175                 return false;
10176             }
10177         }
10178         catch ( final Exception e ) {
10179             e.printStackTrace( System.out );
10180             return false;
10181         }
10182         return true;
10183     }
10184
10185     private static boolean testSDIse() {
10186         try {
10187             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10188             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
10189             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
10190             gene1.setRooted( true );
10191             species1.setRooted( true );
10192             final SDI sdi = new SDI( gene1, species1 );
10193             if ( !gene1.getRoot().isDuplication() ) {
10194                 return false;
10195             }
10196             final Phylogeny species2 = factory
10197                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10198                              new NHXParser() )[ 0 ];
10199             final Phylogeny gene2 = factory
10200                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10201                              new NHXParser() )[ 0 ];
10202             species2.setRooted( true );
10203             gene2.setRooted( true );
10204             final SDI sdi2 = new SDI( gene2, species2 );
10205             if ( sdi2.getDuplicationsSum() != 0 ) {
10206                 return false;
10207             }
10208             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
10209                 return false;
10210             }
10211             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
10212                 return false;
10213             }
10214             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
10215                 return false;
10216             }
10217             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
10218                 return false;
10219             }
10220             if ( !gene2.getNode( "r" ).isSpeciation() ) {
10221                 return false;
10222             }
10223             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
10224                 return false;
10225             }
10226             final Phylogeny species3 = factory
10227                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10228                              new NHXParser() )[ 0 ];
10229             final Phylogeny gene3 = factory
10230                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10231                              new NHXParser() )[ 0 ];
10232             species3.setRooted( true );
10233             gene3.setRooted( true );
10234             final SDI sdi3 = new SDI( gene3, species3 );
10235             if ( sdi3.getDuplicationsSum() != 1 ) {
10236                 return false;
10237             }
10238             if ( !gene3.getNode( "aa" ).isDuplication() ) {
10239                 return false;
10240             }
10241             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
10242                 return false;
10243             }
10244             final Phylogeny species4 = factory
10245                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10246                              new NHXParser() )[ 0 ];
10247             final Phylogeny gene4 = factory
10248                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10249                              new NHXParser() )[ 0 ];
10250             species4.setRooted( true );
10251             gene4.setRooted( true );
10252             final SDI sdi4 = new SDI( gene4, species4 );
10253             if ( sdi4.getDuplicationsSum() != 1 ) {
10254                 return false;
10255             }
10256             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
10257                 return false;
10258             }
10259             if ( !gene4.getNode( "abc" ).isDuplication() ) {
10260                 return false;
10261             }
10262             if ( gene4.getNode( "abcd" ).isDuplication() ) {
10263                 return false;
10264             }
10265             if ( species4.getNumberOfExternalNodes() != 6 ) {
10266                 return false;
10267             }
10268             if ( gene4.getNumberOfExternalNodes() != 6 ) {
10269                 return false;
10270             }
10271             final Phylogeny species5 = factory
10272                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10273                              new NHXParser() )[ 0 ];
10274             final Phylogeny gene5 = factory
10275                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10276                              new NHXParser() )[ 0 ];
10277             species5.setRooted( true );
10278             gene5.setRooted( true );
10279             final SDI sdi5 = new SDI( gene5, species5 );
10280             if ( sdi5.getDuplicationsSum() != 2 ) {
10281                 return false;
10282             }
10283             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
10284                 return false;
10285             }
10286             if ( !gene5.getNode( "adc" ).isDuplication() ) {
10287                 return false;
10288             }
10289             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
10290                 return false;
10291             }
10292             if ( species5.getNumberOfExternalNodes() != 6 ) {
10293                 return false;
10294             }
10295             if ( gene5.getNumberOfExternalNodes() != 6 ) {
10296                 return false;
10297             }
10298             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
10299             // Conjecture for Comparing Molecular Phylogenies"
10300             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
10301             final Phylogeny species6 = factory
10302                     .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,"
10303                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10304                              new NHXParser() )[ 0 ];
10305             final Phylogeny gene6 = factory
10306                     .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,"
10307                                      + "((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,"
10308                                      + "(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;",
10309                              new NHXParser() )[ 0 ];
10310             species6.setRooted( true );
10311             gene6.setRooted( true );
10312             final SDI sdi6 = new SDI( gene6, species6 );
10313             if ( sdi6.getDuplicationsSum() != 3 ) {
10314                 return false;
10315             }
10316             if ( !gene6.getNode( "r" ).isDuplication() ) {
10317                 return false;
10318             }
10319             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
10320                 return false;
10321             }
10322             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
10323                 return false;
10324             }
10325             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
10326                 return false;
10327             }
10328             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
10329                 return false;
10330             }
10331             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
10332                 return false;
10333             }
10334             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
10335                 return false;
10336             }
10337             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
10338                 return false;
10339             }
10340             sdi6.computeMappingCostL();
10341             if ( sdi6.computeMappingCostL() != 17 ) {
10342                 return false;
10343             }
10344             if ( species6.getNumberOfExternalNodes() != 9 ) {
10345                 return false;
10346             }
10347             if ( gene6.getNumberOfExternalNodes() != 9 ) {
10348                 return false;
10349             }
10350             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
10351                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
10352                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
10353                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
10354                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
10355             species7.setRooted( true );
10356             final Phylogeny gene7_1 = Test
10357                     .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])" );
10358             gene7_1.setRooted( true );
10359             final SDI sdi7 = new SDI( gene7_1, species7 );
10360             if ( sdi7.getDuplicationsSum() != 0 ) {
10361                 return false;
10362             }
10363             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
10364                 return false;
10365             }
10366             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
10367                 return false;
10368             }
10369             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
10370                 return false;
10371             }
10372             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
10373                 return false;
10374             }
10375             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
10376                 return false;
10377             }
10378             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
10379                 return false;
10380             }
10381             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
10382                 return false;
10383             }
10384             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
10385                 return false;
10386             }
10387             final Phylogeny gene7_2 = Test
10388                     .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])" );
10389             gene7_2.setRooted( true );
10390             final SDI sdi7_2 = new SDI( gene7_2, species7 );
10391             if ( sdi7_2.getDuplicationsSum() != 1 ) {
10392                 return false;
10393             }
10394             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
10395                 return false;
10396             }
10397             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
10398                 return false;
10399             }
10400             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
10401                 return false;
10402             }
10403             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
10404                 return false;
10405             }
10406             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
10407                 return false;
10408             }
10409             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
10410                 return false;
10411             }
10412             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
10413                 return false;
10414             }
10415             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
10416                 return false;
10417             }
10418             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
10419                 return false;
10420             }
10421         }
10422         catch ( final Exception e ) {
10423             return false;
10424         }
10425         return true;
10426     }
10427
10428     private static boolean testSDIunrooted() {
10429         try {
10430             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10431             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
10432             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
10433             final Iterator<PhylogenyBranch> iter = l.iterator();
10434             PhylogenyBranch br = iter.next();
10435             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
10436                 return false;
10437             }
10438             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
10439                 return false;
10440             }
10441             br = iter.next();
10442             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10443                 return false;
10444             }
10445             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10446                 return false;
10447             }
10448             br = iter.next();
10449             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
10450                 return false;
10451             }
10452             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
10453                 return false;
10454             }
10455             br = iter.next();
10456             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10457                 return false;
10458             }
10459             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10460                 return false;
10461             }
10462             br = iter.next();
10463             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10464                 return false;
10465             }
10466             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10467                 return false;
10468             }
10469             br = iter.next();
10470             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10471                 return false;
10472             }
10473             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10474                 return false;
10475             }
10476             br = iter.next();
10477             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10478                 return false;
10479             }
10480             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10481                 return false;
10482             }
10483             br = iter.next();
10484             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10485                 return false;
10486             }
10487             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10488                 return false;
10489             }
10490             br = iter.next();
10491             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10492                 return false;
10493             }
10494             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10495                 return false;
10496             }
10497             br = iter.next();
10498             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10499                 return false;
10500             }
10501             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10502                 return false;
10503             }
10504             br = iter.next();
10505             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10506                 return false;
10507             }
10508             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10509                 return false;
10510             }
10511             br = iter.next();
10512             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
10513                 return false;
10514             }
10515             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
10516                 return false;
10517             }
10518             br = iter.next();
10519             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10520                 return false;
10521             }
10522             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10523                 return false;
10524             }
10525             br = iter.next();
10526             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
10527                 return false;
10528             }
10529             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
10530                 return false;
10531             }
10532             br = iter.next();
10533             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
10534                 return false;
10535             }
10536             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
10537                 return false;
10538             }
10539             if ( iter.hasNext() ) {
10540                 return false;
10541             }
10542             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
10543             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
10544             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
10545             br = iter1.next();
10546             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10547                 return false;
10548             }
10549             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10550                 return false;
10551             }
10552             br = iter1.next();
10553             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10554                 return false;
10555             }
10556             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10557                 return false;
10558             }
10559             br = iter1.next();
10560             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10561                 return false;
10562             }
10563             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10564                 return false;
10565             }
10566             if ( iter1.hasNext() ) {
10567                 return false;
10568             }
10569             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
10570             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
10571             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
10572             br = iter2.next();
10573             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10574                 return false;
10575             }
10576             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10577                 return false;
10578             }
10579             br = iter2.next();
10580             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10581                 return false;
10582             }
10583             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10584                 return false;
10585             }
10586             br = iter2.next();
10587             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10588                 return false;
10589             }
10590             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10591                 return false;
10592             }
10593             if ( iter2.hasNext() ) {
10594                 return false;
10595             }
10596             final Phylogeny species0 = factory
10597                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10598                              new NHXParser() )[ 0 ];
10599             final Phylogeny gene1 = factory
10600                     .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])",
10601                              new NHXParser() )[ 0 ];
10602             species0.setRooted( true );
10603             gene1.setRooted( true );
10604             final SDIR sdi_unrooted = new SDIR();
10605             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
10606             if ( sdi_unrooted.getCount() != 1 ) {
10607                 return false;
10608             }
10609             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
10610                 return false;
10611             }
10612             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
10613                 return false;
10614             }
10615             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
10616                 return false;
10617             }
10618             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10619                 return false;
10620             }
10621             final Phylogeny gene2 = factory
10622                     .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])",
10623                              new NHXParser() )[ 0 ];
10624             gene2.setRooted( true );
10625             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
10626             if ( sdi_unrooted.getCount() != 1 ) {
10627                 return false;
10628             }
10629             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10630                 return false;
10631             }
10632             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10633                 return false;
10634             }
10635             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
10636                 return false;
10637             }
10638             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10639                 return false;
10640             }
10641             final Phylogeny species6 = factory
10642                     .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,"
10643                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10644                              new NHXParser() )[ 0 ];
10645             final Phylogeny gene6 = factory
10646                     .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],"
10647                                      + "(((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],"
10648                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10649                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10650                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10651                              new NHXParser() )[ 0 ];
10652             species6.setRooted( true );
10653             gene6.setRooted( true );
10654             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
10655             if ( sdi_unrooted.getCount() != 1 ) {
10656                 return false;
10657             }
10658             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10659                 return false;
10660             }
10661             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10662                 return false;
10663             }
10664             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10665                 return false;
10666             }
10667             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10668                 return false;
10669             }
10670             if ( !p6[ 0 ].getRoot().isDuplication() ) {
10671                 return false;
10672             }
10673             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10674                 return false;
10675             }
10676             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10677                 return false;
10678             }
10679             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
10680                 return false;
10681             }
10682             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10683                 return false;
10684             }
10685             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
10686                 return false;
10687             }
10688             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
10689                 return false;
10690             }
10691             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10692                 return false;
10693             }
10694             p6 = null;
10695             final Phylogeny species7 = factory
10696                     .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,"
10697                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10698                              new NHXParser() )[ 0 ];
10699             final Phylogeny gene7 = factory
10700                     .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],"
10701                                      + "(((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],"
10702                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10703                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10704                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10705                              new NHXParser() )[ 0 ];
10706             species7.setRooted( true );
10707             gene7.setRooted( true );
10708             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
10709             if ( sdi_unrooted.getCount() != 1 ) {
10710                 return false;
10711             }
10712             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10713                 return false;
10714             }
10715             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10716                 return false;
10717             }
10718             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10719                 return false;
10720             }
10721             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
10722                 return false;
10723             }
10724             if ( !p7[ 0 ].getRoot().isDuplication() ) {
10725                 return false;
10726             }
10727             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10728                 return false;
10729             }
10730             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10731                 return false;
10732             }
10733             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
10734                 return false;
10735             }
10736             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10737                 return false;
10738             }
10739             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
10740                 return false;
10741             }
10742             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
10743                 return false;
10744             }
10745             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10746                 return false;
10747             }
10748             p7 = null;
10749             final Phylogeny species8 = factory
10750                     .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,"
10751                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10752                              new NHXParser() )[ 0 ];
10753             final Phylogeny gene8 = factory
10754                     .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],"
10755                                      + "(((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],"
10756                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10757                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10758                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10759                              new NHXParser() )[ 0 ];
10760             species8.setRooted( true );
10761             gene8.setRooted( true );
10762             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
10763             if ( sdi_unrooted.getCount() != 1 ) {
10764                 return false;
10765             }
10766             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10767                 return false;
10768             }
10769             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10770                 return false;
10771             }
10772             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10773                 return false;
10774             }
10775             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10776                 return false;
10777             }
10778             if ( !p8[ 0 ].getRoot().isDuplication() ) {
10779                 return false;
10780             }
10781             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10782                 return false;
10783             }
10784             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10785                 return false;
10786             }
10787             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
10788                 return false;
10789             }
10790             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10791                 return false;
10792             }
10793             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
10794                 return false;
10795             }
10796             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
10797                 return false;
10798             }
10799             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10800                 return false;
10801             }
10802             p8 = null;
10803         }
10804         catch ( final Exception e ) {
10805             e.printStackTrace( System.out );
10806             return false;
10807         }
10808         return true;
10809     }
10810
10811     private static boolean testSequenceDbWsTools1() {
10812         try {
10813             final PhylogenyNode n = new PhylogenyNode();
10814             n.setName( "NP_001025424" );
10815             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
10816             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10817                     || !acc.getValue().equals( "NP_001025424" ) ) {
10818                 return false;
10819             }
10820             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
10821             acc = SequenceDbWsTools.obtainSeqAccession( n );
10822             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10823                     || !acc.getValue().equals( "NP_001025424" ) ) {
10824                 return false;
10825             }
10826             n.setName( "NP_001025424.1" );
10827             acc = SequenceDbWsTools.obtainSeqAccession( n );
10828             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10829                     || !acc.getValue().equals( "NP_001025424" ) ) {
10830                 return false;
10831             }
10832             n.setName( "NM_001030253" );
10833             acc = SequenceDbWsTools.obtainSeqAccession( n );
10834             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10835                     || !acc.getValue().equals( "NM_001030253" ) ) {
10836                 return false;
10837             }
10838             n.setName( "BCL2_HUMAN" );
10839             acc = SequenceDbWsTools.obtainSeqAccession( n );
10840             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10841                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
10842                 System.out.println( acc.toString() );
10843                 return false;
10844             }
10845             n.setName( "P10415" );
10846             acc = SequenceDbWsTools.obtainSeqAccession( n );
10847             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10848                     || !acc.getValue().equals( "P10415" ) ) {
10849                 System.out.println( acc.toString() );
10850                 return false;
10851             }
10852             n.setName( " P10415 " );
10853             acc = SequenceDbWsTools.obtainSeqAccession( n );
10854             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10855                     || !acc.getValue().equals( "P10415" ) ) {
10856                 System.out.println( acc.toString() );
10857                 return false;
10858             }
10859             n.setName( "_P10415|" );
10860             acc = SequenceDbWsTools.obtainSeqAccession( n );
10861             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
10862                     || !acc.getValue().equals( "P10415" ) ) {
10863                 System.out.println( acc.toString() );
10864                 return false;
10865             }
10866             n.setName( "AY695820" );
10867             acc = SequenceDbWsTools.obtainSeqAccession( n );
10868             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10869                     || !acc.getValue().equals( "AY695820" ) ) {
10870                 System.out.println( acc.toString() );
10871                 return false;
10872             }
10873             n.setName( "_AY695820_" );
10874             acc = SequenceDbWsTools.obtainSeqAccession( n );
10875             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10876                     || !acc.getValue().equals( "AY695820" ) ) {
10877                 System.out.println( acc.toString() );
10878                 return false;
10879             }
10880             n.setName( "AAA59452" );
10881             acc = SequenceDbWsTools.obtainSeqAccession( n );
10882             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10883                     || !acc.getValue().equals( "AAA59452" ) ) {
10884                 System.out.println( acc.toString() );
10885                 return false;
10886             }
10887             n.setName( "_AAA59452_" );
10888             acc = SequenceDbWsTools.obtainSeqAccession( n );
10889             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10890                     || !acc.getValue().equals( "AAA59452" ) ) {
10891                 System.out.println( acc.toString() );
10892                 return false;
10893             }
10894             n.setName( "AAA59452.1" );
10895             acc = SequenceDbWsTools.obtainSeqAccession( n );
10896             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10897                     || !acc.getValue().equals( "AAA59452.1" ) ) {
10898                 System.out.println( acc.toString() );
10899                 return false;
10900             }
10901             n.setName( "_AAA59452.1_" );
10902             acc = SequenceDbWsTools.obtainSeqAccession( n );
10903             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10904                     || !acc.getValue().equals( "AAA59452.1" ) ) {
10905                 System.out.println( acc.toString() );
10906                 return false;
10907             }
10908             n.setName( "GI:94894583" );
10909             acc = SequenceDbWsTools.obtainSeqAccession( n );
10910             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
10911                     || !acc.getValue().equals( "94894583" ) ) {
10912                 System.out.println( acc.toString() );
10913                 return false;
10914             }
10915             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
10916             acc = SequenceDbWsTools.obtainSeqAccession( n );
10917             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
10918                     || !acc.getValue().equals( "71845847" ) ) {
10919                 System.out.println( acc.toString() );
10920                 return false;
10921             }
10922             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
10923             acc = SequenceDbWsTools.obtainSeqAccession( n );
10924             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
10925                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
10926                 System.out.println( acc.toString() );
10927                 return false;
10928             }
10929         }
10930         catch ( final Exception e ) {
10931             return false;
10932         }
10933         return true;
10934     }
10935
10936     private static boolean testSequenceDbWsTools2() {
10937         try {
10938             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
10939             SequenceDbWsTools.obtainSeqInformation( n1 );
10940             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
10941                 return false;
10942             }
10943             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
10944                 return false;
10945             }
10946             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
10947                 return false;
10948             }
10949             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
10950                 return false;
10951             }
10952             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
10953             SequenceDbWsTools.obtainSeqInformation( n2 );
10954             if ( !n2.getNodeData().getSequence().getName()
10955                     .equals( "Danio rerio B-cell leukemia/lymphoma 2 (bcl2), mRNA" ) ) {
10956                 return false;
10957             }
10958             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
10959                 return false;
10960             }
10961             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
10962                 return false;
10963             }
10964             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
10965                 return false;
10966             }
10967             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
10968             SequenceDbWsTools.obtainSeqInformation( n3 );
10969             if ( !n3.getNodeData().getSequence().getName()
10970                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
10971                 return false;
10972             }
10973             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
10974                 return false;
10975             }
10976             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
10977                 return false;
10978             }
10979             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
10980                 return false;
10981             }
10982         }
10983         catch ( final IOException e ) {
10984             System.out.println();
10985             System.out.println( "the following might be due to absence internet connection:" );
10986             e.printStackTrace( System.out );
10987             return true;
10988         }
10989         catch ( final Exception e ) {
10990             e.printStackTrace();
10991             return false;
10992         }
10993         return true;
10994     }
10995
10996     private static boolean testSequenceIdParsing() {
10997         try {
10998             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
10999             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11000                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11001                 if ( id != null ) {
11002                     System.out.println( "value   =" + id.getValue() );
11003                     System.out.println( "provider=" + id.getSource() );
11004                 }
11005                 return false;
11006             }
11007             //
11008             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
11009             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11010                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11011                 if ( id != null ) {
11012                     System.out.println( "value   =" + id.getValue() );
11013                     System.out.println( "provider=" + id.getSource() );
11014                 }
11015                 return false;
11016             }
11017             //
11018             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
11019             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11020                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11021                 if ( id != null ) {
11022                     System.out.println( "value   =" + id.getValue() );
11023                     System.out.println( "provider=" + id.getSource() );
11024                 }
11025                 return false;
11026             }
11027             // 
11028             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
11029             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11030                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
11031                 if ( id != null ) {
11032                     System.out.println( "value   =" + id.getValue() );
11033                     System.out.println( "provider=" + id.getSource() );
11034                 }
11035                 return false;
11036             }
11037             // 
11038             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
11039             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11040                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
11041                 if ( id != null ) {
11042                     System.out.println( "value   =" + id.getValue() );
11043                     System.out.println( "provider=" + id.getSource() );
11044                 }
11045                 return false;
11046             }
11047             // 
11048             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
11049             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11050                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
11051                 if ( id != null ) {
11052                     System.out.println( "value   =" + id.getValue() );
11053                     System.out.println( "provider=" + id.getSource() );
11054                 }
11055                 return false;
11056             }
11057             // 
11058             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
11059             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11060                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
11061                 if ( id != null ) {
11062                     System.out.println( "value   =" + id.getValue() );
11063                     System.out.println( "provider=" + id.getSource() );
11064                 }
11065                 return false;
11066             }
11067             // 
11068             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
11069             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11070                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11071                 if ( id != null ) {
11072                     System.out.println( "value   =" + id.getValue() );
11073                     System.out.println( "provider=" + id.getSource() );
11074                 }
11075                 return false;
11076             }
11077             // 
11078             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
11079             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11080                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11081                 if ( id != null ) {
11082                     System.out.println( "value   =" + id.getValue() );
11083                     System.out.println( "provider=" + id.getSource() );
11084                 }
11085                 return false;
11086             }
11087             // 
11088             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
11089             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11090                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
11091                 if ( id != null ) {
11092                     System.out.println( "value   =" + id.getValue() );
11093                     System.out.println( "provider=" + id.getSource() );
11094                 }
11095                 return false;
11096             }
11097             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
11098             if ( id != null ) {
11099                 System.out.println( "value   =" + id.getValue() );
11100                 System.out.println( "provider=" + id.getSource() );
11101                 return false;
11102             }
11103         }
11104         catch ( final Exception e ) {
11105             e.printStackTrace( System.out );
11106             return false;
11107         }
11108         return true;
11109     }
11110
11111     private static boolean testSequenceWriter() {
11112         try {
11113             final String n = ForesterUtil.LINE_SEPARATOR;
11114             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
11115                 return false;
11116             }
11117             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
11118                 return false;
11119             }
11120             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
11121                 return false;
11122             }
11123             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
11124                 return false;
11125             }
11126             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
11127                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
11128                 return false;
11129             }
11130             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
11131                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
11132                 return false;
11133             }
11134         }
11135         catch ( final Exception e ) {
11136             e.printStackTrace();
11137             return false;
11138         }
11139         return true;
11140     }
11141
11142     private static boolean testSpecies() {
11143         try {
11144             final Species s1 = new BasicSpecies( "a" );
11145             final Species s2 = new BasicSpecies( "a" );
11146             final Species s3 = new BasicSpecies( "A" );
11147             final Species s4 = new BasicSpecies( "b" );
11148             if ( !s1.equals( s1 ) ) {
11149                 return false;
11150             }
11151             if ( s1.getSpeciesId().equals( "x" ) ) {
11152                 return false;
11153             }
11154             if ( s1.getSpeciesId().equals( null ) ) {
11155                 return false;
11156             }
11157             if ( !s1.equals( s2 ) ) {
11158                 return false;
11159             }
11160             if ( s1.equals( s3 ) ) {
11161                 return false;
11162             }
11163             if ( s1.hashCode() != s1.hashCode() ) {
11164                 return false;
11165             }
11166             if ( s1.hashCode() != s2.hashCode() ) {
11167                 return false;
11168             }
11169             if ( s1.hashCode() == s3.hashCode() ) {
11170                 return false;
11171             }
11172             if ( s1.compareTo( s1 ) != 0 ) {
11173                 return false;
11174             }
11175             if ( s1.compareTo( s2 ) != 0 ) {
11176                 return false;
11177             }
11178             if ( s1.compareTo( s3 ) != 0 ) {
11179                 return false;
11180             }
11181             if ( s1.compareTo( s4 ) >= 0 ) {
11182                 return false;
11183             }
11184             if ( s4.compareTo( s1 ) <= 0 ) {
11185                 return false;
11186             }
11187             if ( !s4.getSpeciesId().equals( "b" ) ) {
11188                 return false;
11189             }
11190             final Species s5 = new BasicSpecies( " C " );
11191             if ( !s5.getSpeciesId().equals( "C" ) ) {
11192                 return false;
11193             }
11194             if ( s5.equals( s1 ) ) {
11195                 return false;
11196             }
11197         }
11198         catch ( final Exception e ) {
11199             e.printStackTrace( System.out );
11200             return false;
11201         }
11202         return true;
11203     }
11204
11205     private static boolean testSplit() {
11206         try {
11207             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11208             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11209             //Archaeopteryx.createApplication( p0 );
11210             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11211             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11212             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11213             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11214             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11215             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11216             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11217             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11218             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11219             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11220             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
11221             // System.out.println( s0.toString() );
11222             //
11223             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11224             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11225             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11226             if ( s0.match( query_nodes ) ) {
11227                 return false;
11228             }
11229             query_nodes = new HashSet<PhylogenyNode>();
11230             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11231             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11232             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11233             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11234             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11235             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11236             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11237             if ( !s0.match( query_nodes ) ) {
11238                 return false;
11239             }
11240             //
11241             query_nodes = new HashSet<PhylogenyNode>();
11242             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11243             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11244             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11245             if ( !s0.match( query_nodes ) ) {
11246                 return false;
11247             }
11248             //
11249             query_nodes = new HashSet<PhylogenyNode>();
11250             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11251             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11252             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11253             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11254             if ( !s0.match( query_nodes ) ) {
11255                 return false;
11256             }
11257             //
11258             query_nodes = new HashSet<PhylogenyNode>();
11259             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11260             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11261             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11262             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11263             if ( !s0.match( query_nodes ) ) {
11264                 return false;
11265             }
11266             //
11267             query_nodes = new HashSet<PhylogenyNode>();
11268             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11269             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11270             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11271             if ( !s0.match( query_nodes ) ) {
11272                 return false;
11273             }
11274             //
11275             query_nodes = new HashSet<PhylogenyNode>();
11276             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11277             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11278             if ( !s0.match( query_nodes ) ) {
11279                 return false;
11280             }
11281             //
11282             query_nodes = new HashSet<PhylogenyNode>();
11283             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11284             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11285             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11286             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11287             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11288             if ( !s0.match( query_nodes ) ) {
11289                 return false;
11290             }
11291             //
11292             query_nodes = new HashSet<PhylogenyNode>();
11293             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11294             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11295             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11296             if ( !s0.match( query_nodes ) ) {
11297                 return false;
11298             }
11299             //
11300             query_nodes = new HashSet<PhylogenyNode>();
11301             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11302             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11303             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11304             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11305             if ( !s0.match( query_nodes ) ) {
11306                 return false;
11307             }
11308             //
11309             query_nodes = new HashSet<PhylogenyNode>();
11310             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11311             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11312             if ( s0.match( query_nodes ) ) {
11313                 return false;
11314             }
11315             //
11316             query_nodes = new HashSet<PhylogenyNode>();
11317             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11318             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11319             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11320             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11321             if ( s0.match( query_nodes ) ) {
11322                 return false;
11323             }
11324             //
11325             query_nodes = new HashSet<PhylogenyNode>();
11326             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11327             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11328             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11329             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11330             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11331             if ( s0.match( query_nodes ) ) {
11332                 return false;
11333             }
11334             //
11335             query_nodes = new HashSet<PhylogenyNode>();
11336             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11337             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11338             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11339             if ( s0.match( query_nodes ) ) {
11340                 return false;
11341             }
11342             //
11343             query_nodes = new HashSet<PhylogenyNode>();
11344             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11345             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11346             if ( s0.match( query_nodes ) ) {
11347                 return false;
11348             }
11349             //
11350             query_nodes = new HashSet<PhylogenyNode>();
11351             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11352             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11353             if ( s0.match( query_nodes ) ) {
11354                 return false;
11355             }
11356             //
11357             query_nodes = new HashSet<PhylogenyNode>();
11358             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11359             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11360             if ( s0.match( query_nodes ) ) {
11361                 return false;
11362             }
11363             //
11364             query_nodes = new HashSet<PhylogenyNode>();
11365             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11366             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11367             if ( s0.match( query_nodes ) ) {
11368                 return false;
11369             }
11370             //
11371             query_nodes = new HashSet<PhylogenyNode>();
11372             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11373             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11374             if ( s0.match( query_nodes ) ) {
11375                 return false;
11376             }
11377             //
11378             query_nodes = new HashSet<PhylogenyNode>();
11379             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11380             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11381             if ( s0.match( query_nodes ) ) {
11382                 return false;
11383             }
11384             //
11385             query_nodes = new HashSet<PhylogenyNode>();
11386             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11387             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11388             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11389             if ( s0.match( query_nodes ) ) {
11390                 return false;
11391             }
11392             //
11393             query_nodes = new HashSet<PhylogenyNode>();
11394             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11395             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11396             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11397             if ( s0.match( query_nodes ) ) {
11398                 return false;
11399             }
11400             //
11401             query_nodes = new HashSet<PhylogenyNode>();
11402             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11403             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11404             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11405             if ( s0.match( query_nodes ) ) {
11406                 return false;
11407             }
11408             //
11409             query_nodes = new HashSet<PhylogenyNode>();
11410             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11411             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11412             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11413             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11414             if ( s0.match( query_nodes ) ) {
11415                 return false;
11416             }
11417             /////////
11418             //            query_nodes = new HashSet<PhylogenyNode>();
11419             //            query_nodes.add( new PhylogenyNode( "X" ) );
11420             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11421             //            query_nodes.add( new PhylogenyNode( "A" ) );
11422             //            query_nodes.add( new PhylogenyNode( "B" ) );
11423             //            query_nodes.add( new PhylogenyNode( "C" ) );
11424             //            query_nodes.add( new PhylogenyNode( "D" ) );
11425             //            query_nodes.add( new PhylogenyNode( "E" ) );
11426             //            query_nodes.add( new PhylogenyNode( "F" ) );
11427             //            query_nodes.add( new PhylogenyNode( "G" ) );
11428             //            if ( !s0.match( query_nodes ) ) {
11429             //                return false;
11430             //            }
11431             //            query_nodes = new HashSet<PhylogenyNode>();
11432             //            query_nodes.add( new PhylogenyNode( "X" ) );
11433             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11434             //            query_nodes.add( new PhylogenyNode( "A" ) );
11435             //            query_nodes.add( new PhylogenyNode( "B" ) );
11436             //            query_nodes.add( new PhylogenyNode( "C" ) );
11437             //            if ( !s0.match( query_nodes ) ) {
11438             //                return false;
11439             //            }
11440             //            //
11441             //            query_nodes = new HashSet<PhylogenyNode>();
11442             //            query_nodes.add( new PhylogenyNode( "X" ) );
11443             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11444             //            query_nodes.add( new PhylogenyNode( "D" ) );
11445             //            query_nodes.add( new PhylogenyNode( "E" ) );
11446             //            query_nodes.add( new PhylogenyNode( "F" ) );
11447             //            query_nodes.add( new PhylogenyNode( "G" ) );
11448             //            if ( !s0.match( query_nodes ) ) {
11449             //                return false;
11450             //            }
11451             //            //
11452             //            query_nodes = new HashSet<PhylogenyNode>();
11453             //            query_nodes.add( new PhylogenyNode( "X" ) );
11454             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11455             //            query_nodes.add( new PhylogenyNode( "A" ) );
11456             //            query_nodes.add( new PhylogenyNode( "B" ) );
11457             //            query_nodes.add( new PhylogenyNode( "C" ) );
11458             //            query_nodes.add( new PhylogenyNode( "D" ) );
11459             //            if ( !s0.match( query_nodes ) ) {
11460             //                return false;
11461             //            }
11462             //            //
11463             //            query_nodes = new HashSet<PhylogenyNode>();
11464             //            query_nodes.add( new PhylogenyNode( "X" ) );
11465             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11466             //            query_nodes.add( new PhylogenyNode( "E" ) );
11467             //            query_nodes.add( new PhylogenyNode( "F" ) );
11468             //            query_nodes.add( new PhylogenyNode( "G" ) );
11469             //            if ( !s0.match( query_nodes ) ) {
11470             //                return false;
11471             //            }
11472             //            //
11473             //            query_nodes = new HashSet<PhylogenyNode>();
11474             //            query_nodes.add( new PhylogenyNode( "X" ) );
11475             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11476             //            query_nodes.add( new PhylogenyNode( "F" ) );
11477             //            query_nodes.add( new PhylogenyNode( "G" ) );
11478             //            if ( !s0.match( query_nodes ) ) {
11479             //                return false;
11480             //            }
11481             //
11482             query_nodes = new HashSet<PhylogenyNode>();
11483             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11484             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11485             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11486             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11487             if ( s0.match( query_nodes ) ) {
11488                 return false;
11489             }
11490             //
11491             query_nodes = new HashSet<PhylogenyNode>();
11492             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11493             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11494             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11495             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11496             if ( s0.match( query_nodes ) ) {
11497                 return false;
11498             }
11499             ///////////////////////////
11500             //
11501             query_nodes = new HashSet<PhylogenyNode>();
11502             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11503             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11504             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11505             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11506             if ( s0.match( query_nodes ) ) {
11507                 return false;
11508             }
11509             //
11510             query_nodes = new HashSet<PhylogenyNode>();
11511             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11512             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11513             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11514             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11515             if ( s0.match( query_nodes ) ) {
11516                 return false;
11517             }
11518             //
11519             query_nodes = new HashSet<PhylogenyNode>();
11520             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11521             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11522             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11523             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11524             if ( s0.match( query_nodes ) ) {
11525                 return false;
11526             }
11527             //
11528             query_nodes = new HashSet<PhylogenyNode>();
11529             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11530             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11531             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11532             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11533             if ( s0.match( query_nodes ) ) {
11534                 return false;
11535             }
11536             //
11537             query_nodes = new HashSet<PhylogenyNode>();
11538             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11539             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11540             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11541             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11542             if ( s0.match( query_nodes ) ) {
11543                 return false;
11544             }
11545             //
11546             query_nodes = new HashSet<PhylogenyNode>();
11547             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11548             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11549             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11550             if ( s0.match( query_nodes ) ) {
11551                 return false;
11552             }
11553             //
11554             query_nodes = new HashSet<PhylogenyNode>();
11555             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11556             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11557             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11558             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11559             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11560             if ( s0.match( query_nodes ) ) {
11561                 return false;
11562             }
11563             //
11564             query_nodes = new HashSet<PhylogenyNode>();
11565             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11566             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11567             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11568             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11569             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11570             if ( s0.match( query_nodes ) ) {
11571                 return false;
11572             }
11573             //
11574             query_nodes = new HashSet<PhylogenyNode>();
11575             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11576             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11577             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11578             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11579             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11580             if ( s0.match( query_nodes ) ) {
11581                 return false;
11582             }
11583             //
11584             query_nodes = new HashSet<PhylogenyNode>();
11585             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11586             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11587             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11588             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11589             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11590             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11591             if ( s0.match( query_nodes ) ) {
11592                 return false;
11593             }
11594         }
11595         catch ( final Exception e ) {
11596             e.printStackTrace();
11597             return false;
11598         }
11599         return true;
11600     }
11601
11602     private static boolean testSplitStrict() {
11603         try {
11604             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11605             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11606             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11607             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11608             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11609             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11610             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11611             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11612             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11613             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11614             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
11615             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11616             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11617             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11618             if ( s0.match( query_nodes ) ) {
11619                 return false;
11620             }
11621             query_nodes = new HashSet<PhylogenyNode>();
11622             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11623             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11624             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11625             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11626             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11627             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11628             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11629             if ( !s0.match( query_nodes ) ) {
11630                 return false;
11631             }
11632             //
11633             query_nodes = new HashSet<PhylogenyNode>();
11634             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11635             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11636             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11637             if ( !s0.match( query_nodes ) ) {
11638                 return false;
11639             }
11640             //
11641             query_nodes = new HashSet<PhylogenyNode>();
11642             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11643             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11644             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11645             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11646             if ( !s0.match( query_nodes ) ) {
11647                 return false;
11648             }
11649             //
11650             query_nodes = new HashSet<PhylogenyNode>();
11651             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11652             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11653             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11654             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11655             if ( !s0.match( query_nodes ) ) {
11656                 return false;
11657             }
11658             //
11659             query_nodes = new HashSet<PhylogenyNode>();
11660             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11661             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11662             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11663             if ( !s0.match( query_nodes ) ) {
11664                 return false;
11665             }
11666             //
11667             query_nodes = new HashSet<PhylogenyNode>();
11668             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11669             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11670             if ( !s0.match( query_nodes ) ) {
11671                 return false;
11672             }
11673             //
11674             query_nodes = new HashSet<PhylogenyNode>();
11675             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11676             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11677             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11678             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11679             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11680             if ( !s0.match( query_nodes ) ) {
11681                 return false;
11682             }
11683             //
11684             query_nodes = new HashSet<PhylogenyNode>();
11685             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11686             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11687             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11688             if ( !s0.match( query_nodes ) ) {
11689                 return false;
11690             }
11691             //
11692             query_nodes = new HashSet<PhylogenyNode>();
11693             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11694             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11695             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11696             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11697             if ( !s0.match( query_nodes ) ) {
11698                 return false;
11699             }
11700             //
11701             query_nodes = new HashSet<PhylogenyNode>();
11702             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11703             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11704             if ( s0.match( query_nodes ) ) {
11705                 return false;
11706             }
11707             //
11708             query_nodes = new HashSet<PhylogenyNode>();
11709             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11710             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11711             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11712             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11713             if ( s0.match( query_nodes ) ) {
11714                 return false;
11715             }
11716             //
11717             query_nodes = new HashSet<PhylogenyNode>();
11718             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11719             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11720             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11721             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11722             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11723             if ( s0.match( query_nodes ) ) {
11724                 return false;
11725             }
11726             //
11727             query_nodes = new HashSet<PhylogenyNode>();
11728             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11729             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11730             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11731             if ( s0.match( query_nodes ) ) {
11732                 return false;
11733             }
11734             //
11735             query_nodes = new HashSet<PhylogenyNode>();
11736             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11737             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11738             if ( s0.match( query_nodes ) ) {
11739                 return false;
11740             }
11741             //
11742             query_nodes = new HashSet<PhylogenyNode>();
11743             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11744             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11745             if ( s0.match( query_nodes ) ) {
11746                 return false;
11747             }
11748             //
11749             query_nodes = new HashSet<PhylogenyNode>();
11750             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11751             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11752             if ( s0.match( query_nodes ) ) {
11753                 return false;
11754             }
11755             //
11756             query_nodes = new HashSet<PhylogenyNode>();
11757             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11758             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11759             if ( s0.match( query_nodes ) ) {
11760                 return false;
11761             }
11762             //
11763             query_nodes = new HashSet<PhylogenyNode>();
11764             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11765             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11766             if ( s0.match( query_nodes ) ) {
11767                 return false;
11768             }
11769             //
11770             query_nodes = new HashSet<PhylogenyNode>();
11771             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11772             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11773             if ( s0.match( query_nodes ) ) {
11774                 return false;
11775             }
11776             //
11777             query_nodes = new HashSet<PhylogenyNode>();
11778             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11779             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11780             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11781             if ( s0.match( query_nodes ) ) {
11782                 return false;
11783             }
11784             //
11785             query_nodes = new HashSet<PhylogenyNode>();
11786             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11787             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11788             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11789             if ( s0.match( query_nodes ) ) {
11790                 return false;
11791             }
11792             //
11793             query_nodes = new HashSet<PhylogenyNode>();
11794             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11795             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11796             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11797             if ( s0.match( query_nodes ) ) {
11798                 return false;
11799             }
11800             //
11801             query_nodes = new HashSet<PhylogenyNode>();
11802             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11803             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11804             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11805             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11806             if ( s0.match( query_nodes ) ) {
11807                 return false;
11808             }
11809         }
11810         catch ( final Exception e ) {
11811             e.printStackTrace();
11812             return false;
11813         }
11814         return true;
11815     }
11816
11817     private static boolean testSubtreeDeletion() {
11818         try {
11819             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11820             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
11821             t1.deleteSubtree( t1.getNode( "A" ), false );
11822             if ( t1.getNumberOfExternalNodes() != 5 ) {
11823                 return false;
11824             }
11825             t1.toNewHampshireX();
11826             t1.deleteSubtree( t1.getNode( "E" ), false );
11827             if ( t1.getNumberOfExternalNodes() != 4 ) {
11828                 return false;
11829             }
11830             t1.toNewHampshireX();
11831             t1.deleteSubtree( t1.getNode( "F" ), false );
11832             if ( t1.getNumberOfExternalNodes() != 3 ) {
11833                 return false;
11834             }
11835             t1.toNewHampshireX();
11836             t1.deleteSubtree( t1.getNode( "D" ), false );
11837             t1.toNewHampshireX();
11838             if ( t1.getNumberOfExternalNodes() != 3 ) {
11839                 return false;
11840             }
11841             t1.deleteSubtree( t1.getNode( "def" ), false );
11842             t1.toNewHampshireX();
11843             if ( t1.getNumberOfExternalNodes() != 2 ) {
11844                 return false;
11845             }
11846             t1.deleteSubtree( t1.getNode( "B" ), false );
11847             t1.toNewHampshireX();
11848             if ( t1.getNumberOfExternalNodes() != 1 ) {
11849                 return false;
11850             }
11851             t1.deleteSubtree( t1.getNode( "C" ), false );
11852             t1.toNewHampshireX();
11853             if ( t1.getNumberOfExternalNodes() != 1 ) {
11854                 return false;
11855             }
11856             t1.deleteSubtree( t1.getNode( "abc" ), false );
11857             t1.toNewHampshireX();
11858             if ( t1.getNumberOfExternalNodes() != 1 ) {
11859                 return false;
11860             }
11861             t1.deleteSubtree( t1.getNode( "r" ), false );
11862             if ( t1.getNumberOfExternalNodes() != 0 ) {
11863                 return false;
11864             }
11865             if ( !t1.isEmpty() ) {
11866                 return false;
11867             }
11868             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
11869             t2.deleteSubtree( t2.getNode( "A" ), false );
11870             t2.toNewHampshireX();
11871             if ( t2.getNumberOfExternalNodes() != 5 ) {
11872                 return false;
11873             }
11874             t2.deleteSubtree( t2.getNode( "abc" ), false );
11875             t2.toNewHampshireX();
11876             if ( t2.getNumberOfExternalNodes() != 3 ) {
11877                 return false;
11878             }
11879             t2.deleteSubtree( t2.getNode( "def" ), false );
11880             t2.toNewHampshireX();
11881             if ( t2.getNumberOfExternalNodes() != 1 ) {
11882                 return false;
11883             }
11884         }
11885         catch ( final Exception e ) {
11886             e.printStackTrace( System.out );
11887             return false;
11888         }
11889         return true;
11890     }
11891
11892     private static boolean testSupportCount() {
11893         try {
11894             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11895             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
11896             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
11897                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
11898                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
11899                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
11900                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
11901                                                               new NHXParser() );
11902             SupportCount.count( t0_1, phylogenies_1, true, false );
11903             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
11904             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
11905                                                                       + "(((((A,B),C),D),E),((F,G),X))"
11906                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
11907                                                                       + "(((((A,B),C),D),E),(F,G))"
11908                                                                       + "(((((A,B),C),D),E),(F,G))"
11909                                                                       + "(((((A,B),C),D),E),(F,G))"
11910                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
11911                                                                       + "(((((A,B),C),D),E),(F,G))"
11912                                                                       + "((((((A,B),C),D),E),F),G)"
11913                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
11914                                                               new NHXParser() );
11915             SupportCount.count( t0_2, phylogenies_2, true, false );
11916             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
11917             while ( it.hasNext() ) {
11918                 final PhylogenyNode n = it.next();
11919                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
11920                     return false;
11921                 }
11922             }
11923             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
11924             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
11925                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
11926             SupportCount.count( t0_3, phylogenies_3, true, false );
11927             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
11928             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
11929                 return false;
11930             }
11931             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
11932                 return false;
11933             }
11934             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
11935                 return false;
11936             }
11937             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
11938                 return false;
11939             }
11940             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
11941                 return false;
11942             }
11943             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
11944                 return false;
11945             }
11946             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
11947                 return false;
11948             }
11949             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
11950                 return false;
11951             }
11952             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
11953                 return false;
11954             }
11955             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
11956                 return false;
11957             }
11958             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11959             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
11960                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
11961             SupportCount.count( t0_4, phylogenies_4, true, false );
11962             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
11963             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
11964                 return false;
11965             }
11966             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
11967                 return false;
11968             }
11969             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
11970                 return false;
11971             }
11972             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
11973                 return false;
11974             }
11975             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
11976                 return false;
11977             }
11978             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
11979                 return false;
11980             }
11981             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
11982                 return false;
11983             }
11984             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
11985                 return false;
11986             }
11987             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
11988                 return false;
11989             }
11990             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
11991                 return false;
11992             }
11993             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11994             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11995             double d = SupportCount.compare( b1, a, true, true, true );
11996             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
11997                 return false;
11998             }
11999             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12000             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12001             d = SupportCount.compare( b2, a, true, true, true );
12002             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
12003                 return false;
12004             }
12005             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12006             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
12007             d = SupportCount.compare( b3, a, true, true, true );
12008             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
12009                 return false;
12010             }
12011             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
12012             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
12013             d = SupportCount.compare( b4, a, true, true, false );
12014             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
12015                 return false;
12016             }
12017         }
12018         catch ( final Exception e ) {
12019             e.printStackTrace( System.out );
12020             return false;
12021         }
12022         return true;
12023     }
12024
12025     private static boolean testSupportTransfer() {
12026         try {
12027             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12028             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)",
12029                                                  new NHXParser() )[ 0 ];
12030             final Phylogeny p2 = factory
12031                     .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 ];
12032             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
12033                 return false;
12034             }
12035             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
12036                 return false;
12037             }
12038             support_transfer.moveBranchLengthsToBootstrap( p1 );
12039             support_transfer.transferSupportValues( p1, p2 );
12040             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
12041                 return false;
12042             }
12043             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
12044                 return false;
12045             }
12046             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
12047                 return false;
12048             }
12049             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
12050                 return false;
12051             }
12052             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
12053                 return false;
12054             }
12055             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
12056                 return false;
12057             }
12058             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
12059                 return false;
12060             }
12061             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
12062                 return false;
12063             }
12064         }
12065         catch ( final Exception e ) {
12066             e.printStackTrace( System.out );
12067             return false;
12068         }
12069         return true;
12070     }
12071
12072     private static boolean testTaxonomyExtraction() {
12073         try {
12074             final PhylogenyNode n0 = PhylogenyNode
12075                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12076             if ( n0.getNodeData().isHasTaxonomy() ) {
12077                 return false;
12078             }
12079             final PhylogenyNode n1 = PhylogenyNode
12080                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12081             if ( n1.getNodeData().isHasTaxonomy() ) {
12082                 System.out.println( n1.toString() );
12083                 return false;
12084             }
12085             final PhylogenyNode n2x = PhylogenyNode
12086                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12087             if ( n2x.getNodeData().isHasTaxonomy() ) {
12088                 return false;
12089             }
12090             final PhylogenyNode n3 = PhylogenyNode
12091                     .createInstanceFromNhxString( "BLAG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12092             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12093                 System.out.println( n3.toString() );
12094                 return false;
12095             }
12096             final PhylogenyNode n4 = PhylogenyNode
12097                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12098             if ( n4.getNodeData().isHasTaxonomy() ) {
12099                 System.out.println( n4.toString() );
12100                 return false;
12101             }
12102             final PhylogenyNode n5 = PhylogenyNode
12103                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12104             if ( n5.getNodeData().isHasTaxonomy() ) {
12105                 System.out.println( n5.toString() );
12106                 return false;
12107             }
12108             final PhylogenyNode n6 = PhylogenyNode
12109                     .createInstanceFromNhxString( "BLAG-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12110             if ( n6.getNodeData().isHasTaxonomy() ) {
12111                 System.out.println( n6.toString() );
12112                 return false;
12113             }
12114             final PhylogenyNode n7 = PhylogenyNode
12115                     .createInstanceFromNhxString( "BLAG-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12116             if ( n7.getNodeData().isHasTaxonomy() ) {
12117                 System.out.println( n7.toString() );
12118                 return false;
12119             }
12120             final PhylogenyNode n8 = PhylogenyNode
12121                     .createInstanceFromNhxString( "BLAG_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12122             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12123                 System.out.println( n8.toString() );
12124                 return false;
12125             }
12126             final PhylogenyNode n9 = PhylogenyNode
12127                     .createInstanceFromNhxString( "BLAG_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12128             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12129                 System.out.println( n9.toString() );
12130                 return false;
12131             }
12132             final PhylogenyNode n10x = PhylogenyNode
12133                     .createInstanceFromNhxString( "BLAG_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12134             if ( n10x.getNodeData().isHasTaxonomy() ) {
12135                 System.out.println( n10x.toString() );
12136                 return false;
12137             }
12138             final PhylogenyNode n10xx = PhylogenyNode
12139                     .createInstanceFromNhxString( "BLAG_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12140             if ( n10xx.getNodeData().isHasTaxonomy() ) {
12141                 System.out.println( n10xx.toString() );
12142                 return false;
12143             }
12144             final PhylogenyNode n10 = PhylogenyNode
12145                     .createInstanceFromNhxString( "BLAG_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12146             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
12147                 System.out.println( n10.toString() );
12148                 return false;
12149             }
12150             final PhylogenyNode n11 = PhylogenyNode
12151                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12152             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12153                 System.out.println( n11.toString() );
12154                 return false;
12155             }
12156             final PhylogenyNode n12 = PhylogenyNode
12157                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
12158                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12159             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12160                 System.out.println( n12.toString() );
12161                 return false;
12162             }
12163             final PhylogenyNode n13 = PhylogenyNode
12164                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12165             if ( n13.getNodeData().isHasTaxonomy() ) {
12166                 System.out.println( n13.toString() );
12167                 return false;
12168             }
12169             final PhylogenyNode n14 = PhylogenyNode
12170                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12171             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12172                 System.out.println( n14.toString() );
12173                 return false;
12174             }
12175             final PhylogenyNode n15 = PhylogenyNode
12176                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12177             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12178                 System.out.println( n15.toString() );
12179                 return false;
12180             }
12181             final PhylogenyNode n16 = PhylogenyNode
12182                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12183             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12184                 System.out.println( n16.toString() );
12185                 return false;
12186             }
12187             final PhylogenyNode n17 = PhylogenyNode
12188                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12189             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12190                 System.out.println( n17.toString() );
12191                 return false;
12192             }
12193             //
12194             final PhylogenyNode n18 = PhylogenyNode
12195                     .createInstanceFromNhxString( "Mus_musculus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12196             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12197                 System.out.println( n18.toString() );
12198                 return false;
12199             }
12200             final PhylogenyNode n19 = PhylogenyNode
12201                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
12202                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12203             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12204                 System.out.println( n19.toString() );
12205                 return false;
12206             }
12207             final PhylogenyNode n20 = PhylogenyNode
12208                     .createInstanceFromNhxString( "Mus musculus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12209             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12210                 System.out.println( n20.toString() );
12211                 return false;
12212             }
12213             final PhylogenyNode n21 = PhylogenyNode
12214                     .createInstanceFromNhxString( "Mus musculus musculus K392",
12215                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12216             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12217                 System.out.println( n21.toString() );
12218                 return false;
12219             }
12220             final PhylogenyNode n22 = PhylogenyNode
12221                     .createInstanceFromNhxString( "NEMVE_Nematostella_vectensis",
12222                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12223             if ( !n22.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12224                 System.out.println( n22.toString() );
12225                 return false;
12226             }
12227             final PhylogenyNode n23 = PhylogenyNode
12228                     .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
12229                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12230             if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12231                 System.out.println( n23.toString() );
12232                 return false;
12233             }
12234             final PhylogenyNode n24 = PhylogenyNode
12235                     .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12236             if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12237                 System.out.println( n24.toString() );
12238                 return false;
12239             }
12240             //
12241             final PhylogenyNode n25 = PhylogenyNode
12242                     .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
12243                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12244             if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12245                 System.out.println( n25.toString() );
12246                 return false;
12247             }
12248             final PhylogenyNode n26 = PhylogenyNode
12249                     .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
12250                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12251             if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12252                 System.out.println( n26.toString() );
12253                 return false;
12254             }
12255             final PhylogenyNode n27 = PhylogenyNode
12256                     .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12257             if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12258                 System.out.println( n27.toString() );
12259                 return false;
12260             }
12261         }
12262         catch ( final Exception e ) {
12263             e.printStackTrace( System.out );
12264             return false;
12265         }
12266         return true;
12267     }
12268
12269     private static boolean testTreeCopy() {
12270         try {
12271             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
12272             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
12273             final Phylogeny t1 = t0.copy();
12274             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
12275                 return false;
12276             }
12277             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12278                 return false;
12279             }
12280             t0.deleteSubtree( t0.getNode( "c" ), true );
12281             t0.deleteSubtree( t0.getNode( "a" ), true );
12282             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
12283             t0.getNode( "b" ).setName( "Bee" );
12284             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
12285                 return false;
12286             }
12287             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12288                 return false;
12289             }
12290             t0.deleteSubtree( t0.getNode( "e" ), true );
12291             t0.deleteSubtree( t0.getNode( "Bee" ), true );
12292             t0.deleteSubtree( t0.getNode( "d" ), true );
12293             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12294                 return false;
12295             }
12296         }
12297         catch ( final Exception e ) {
12298             e.printStackTrace();
12299             return false;
12300         }
12301         return true;
12302     }
12303
12304     private static boolean testTreeMethods() {
12305         try {
12306             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12307             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
12308             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
12309             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
12310                 System.out.println( t0.toNewHampshireX() );
12311                 return false;
12312             }
12313             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
12314             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
12315             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
12316                 return false;
12317             }
12318             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
12319                 return false;
12320             }
12321             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
12322                 return false;
12323             }
12324         }
12325         catch ( final Exception e ) {
12326             e.printStackTrace( System.out );
12327             return false;
12328         }
12329         return true;
12330     }
12331
12332     private static boolean testUniprotEntryRetrieval() {
12333         try {
12334             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
12335             if ( !entry.getAccession().equals( "P12345" ) ) {
12336                 return false;
12337             }
12338             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
12339                 return false;
12340             }
12341             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
12342                 return false;
12343             }
12344             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
12345                 return false;
12346             }
12347             if ( !entry.getGeneName().equals( "GOT2" ) ) {
12348                 return false;
12349             }
12350             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
12351                 return false;
12352             }
12353         }
12354         catch ( final IOException e ) {
12355             System.out.println();
12356             System.out.println( "the following might be due to absence internet connection:" );
12357             e.printStackTrace( System.out );
12358             return true;
12359         }
12360         catch ( final Exception e ) {
12361             return false;
12362         }
12363         return true;
12364     }
12365
12366     private static boolean testUniprotTaxonomySearch() {
12367         try {
12368             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
12369                                                                                                  10 );
12370             if ( results.size() != 1 ) {
12371                 return false;
12372             }
12373             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12374                 return false;
12375             }
12376             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12377                 return false;
12378             }
12379             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12380                 return false;
12381             }
12382             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12383                 return false;
12384             }
12385             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12386                 return false;
12387             }
12388             results = null;
12389             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
12390             if ( results.size() != 1 ) {
12391                 return false;
12392             }
12393             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12394                 return false;
12395             }
12396             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12397                 return false;
12398             }
12399             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12400                 return false;
12401             }
12402             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12403                 return false;
12404             }
12405             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12406                 return false;
12407             }
12408             results = null;
12409             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
12410             if ( results.size() != 1 ) {
12411                 return false;
12412             }
12413             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12414                 return false;
12415             }
12416             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12417                 return false;
12418             }
12419             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12420                 return false;
12421             }
12422             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12423                 return false;
12424             }
12425             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12426                 return false;
12427             }
12428             results = null;
12429             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
12430             if ( results.size() != 1 ) {
12431                 return false;
12432             }
12433             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12434                 return false;
12435             }
12436             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12437                 return false;
12438             }
12439             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12440                 return false;
12441             }
12442             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12443                 return false;
12444             }
12445             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12446                 return false;
12447             }
12448             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
12449                 return false;
12450             }
12451             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
12452                 return false;
12453             }
12454             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12455                     .equals( "Nematostella vectensis" ) ) {
12456                 System.out.println( results.get( 0 ).getLineage() );
12457                 return false;
12458             }
12459             //
12460             results = null;
12461             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
12462             if ( results.size() != 1 ) {
12463                 return false;
12464             }
12465             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12466                 return false;
12467             }
12468             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12469                 return false;
12470             }
12471             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12472                 return false;
12473             }
12474             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12475                 return false;
12476             }
12477             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12478                 return false;
12479             }
12480             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12481                     .equals( "Xenopus tropicalis" ) ) {
12482                 System.out.println( results.get( 0 ).getLineage() );
12483                 return false;
12484             }
12485             //
12486             results = null;
12487             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
12488             if ( results.size() != 1 ) {
12489                 return false;
12490             }
12491             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12492                 return false;
12493             }
12494             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12495                 return false;
12496             }
12497             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12498                 return false;
12499             }
12500             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12501                 return false;
12502             }
12503             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12504                 return false;
12505             }
12506             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12507                     .equals( "Xenopus tropicalis" ) ) {
12508                 System.out.println( results.get( 0 ).getLineage() );
12509                 return false;
12510             }
12511             //
12512             results = null;
12513             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
12514             if ( results.size() != 1 ) {
12515                 return false;
12516             }
12517             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12518                 return false;
12519             }
12520             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12521                 return false;
12522             }
12523             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12524                 return false;
12525             }
12526             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12527                 return false;
12528             }
12529             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12530                 return false;
12531             }
12532             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12533                     .equals( "Xenopus tropicalis" ) ) {
12534                 System.out.println( results.get( 0 ).getLineage() );
12535                 return false;
12536             }
12537         }
12538         catch ( final IOException e ) {
12539             System.out.println();
12540             System.out.println( "the following might be due to absence internet connection:" );
12541             e.printStackTrace( System.out );
12542             return true;
12543         }
12544         catch ( final Exception e ) {
12545             return false;
12546         }
12547         return true;
12548     }
12549
12550     private static boolean testWabiTxSearch() {
12551         try {
12552             String result = "";
12553             result = TxSearch.searchSimple( "nematostella" );
12554             result = TxSearch.getTxId( "nematostella" );
12555             if ( !result.equals( "45350" ) ) {
12556                 return false;
12557             }
12558             result = TxSearch.getTxName( "45350" );
12559             if ( !result.equals( "Nematostella" ) ) {
12560                 return false;
12561             }
12562             result = TxSearch.getTxId( "nematostella vectensis" );
12563             if ( !result.equals( "45351" ) ) {
12564                 return false;
12565             }
12566             result = TxSearch.getTxName( "45351" );
12567             if ( !result.equals( "Nematostella vectensis" ) ) {
12568                 return false;
12569             }
12570             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
12571             if ( !result.equals( "536089" ) ) {
12572                 return false;
12573             }
12574             result = TxSearch.getTxName( "536089" );
12575             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
12576                 return false;
12577             }
12578             final List<String> queries = new ArrayList<String>();
12579             queries.add( "Campylobacter coli" );
12580             queries.add( "Escherichia coli" );
12581             queries.add( "Arabidopsis" );
12582             queries.add( "Trichoplax" );
12583             queries.add( "Samanea saman" );
12584             queries.add( "Kluyveromyces marxianus" );
12585             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
12586             queries.add( "Bornavirus parrot/PDD/2008" );
12587             final List<RANKS> ranks = new ArrayList<RANKS>();
12588             ranks.add( RANKS.SUPERKINGDOM );
12589             ranks.add( RANKS.KINGDOM );
12590             ranks.add( RANKS.FAMILY );
12591             ranks.add( RANKS.GENUS );
12592             ranks.add( RANKS.TRIBE );
12593             result = TxSearch.searchLineage( queries, ranks );
12594             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
12595             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
12596         }
12597         catch ( final Exception e ) {
12598             System.out.println();
12599             System.out.println( "the following might be due to absence internet connection:" );
12600             e.printStackTrace( System.out );
12601             return false;
12602         }
12603         return true;
12604     }
12605 }