cleanup
[jalview.git] / forester / java / src / org / forester / test / Test.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2014 Christian M. Zmasek
6 // Copyright (C) 2014 Sanford-Burnham Medical Research Institute
7 // All rights reserved
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 //
23 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
24
25 package org.forester.test;
26
27 import java.io.ByteArrayInputStream;
28 import java.io.File;
29 import java.io.FileInputStream;
30 import java.io.IOException;
31 import java.io.StringWriter;
32 import java.io.Writer;
33 import java.net.URL;
34 import java.util.ArrayList;
35 import java.util.Date;
36 import java.util.HashSet;
37 import java.util.Iterator;
38 import java.util.List;
39 import java.util.Locale;
40 import java.util.Set;
41 import java.util.SortedSet;
42
43 import org.forester.application.support_transfer;
44 import org.forester.archaeopteryx.TreePanelUtil;
45 import org.forester.archaeopteryx.webservices.WebserviceUtil;
46 import org.forester.development.DevelopmentTools;
47 import org.forester.evoinference.TestPhylogenyReconstruction;
48 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
49 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
50 import org.forester.go.TestGo;
51 import org.forester.io.parsers.FastaParser;
52 import org.forester.io.parsers.GeneralMsaParser;
53 import org.forester.io.parsers.HmmscanPerDomainTableParser;
54 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
55 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
56 import org.forester.io.parsers.nexus.NexusCharactersParser;
57 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
58 import org.forester.io.parsers.nhx.NHXParser;
59 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
60 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
61 import org.forester.io.parsers.tol.TolParser;
62 import org.forester.io.parsers.util.ParserUtils;
63 import org.forester.io.writers.PhylogenyWriter;
64 import org.forester.io.writers.SequenceWriter;
65 import org.forester.msa.BasicMsa;
66 import org.forester.msa.DeleteableMsa;
67 import org.forester.msa.Mafft;
68 import org.forester.msa.Msa;
69 import org.forester.msa.Msa.MSA_FORMAT;
70 import org.forester.msa.MsaInferrer;
71 import org.forester.msa.MsaMethods;
72 import org.forester.pccx.TestPccx;
73 import org.forester.phylogeny.Phylogeny;
74 import org.forester.phylogeny.PhylogenyBranch;
75 import org.forester.phylogeny.PhylogenyMethods;
76 import org.forester.phylogeny.PhylogenyNode;
77 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
78 import org.forester.phylogeny.data.Accession;
79 import org.forester.phylogeny.data.Accession.Source;
80 import org.forester.phylogeny.data.BinaryCharacters;
81 import org.forester.phylogeny.data.BranchWidth;
82 import org.forester.phylogeny.data.Confidence;
83 import org.forester.phylogeny.data.Distribution;
84 import org.forester.phylogeny.data.DomainArchitecture;
85 import org.forester.phylogeny.data.Event;
86 import org.forester.phylogeny.data.Identifier;
87 import org.forester.phylogeny.data.PhylogenyData;
88 import org.forester.phylogeny.data.PhylogenyDataUtil;
89 import org.forester.phylogeny.data.Polygon;
90 import org.forester.phylogeny.data.PropertiesMap;
91 import org.forester.phylogeny.data.Property;
92 import org.forester.phylogeny.data.Property.AppliesTo;
93 import org.forester.phylogeny.data.ProteinDomain;
94 import org.forester.phylogeny.data.Taxonomy;
95 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
96 import org.forester.phylogeny.factories.PhylogenyFactory;
97 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
98 import org.forester.protein.BasicDomain;
99 import org.forester.protein.BasicProtein;
100 import org.forester.protein.Domain;
101 import org.forester.protein.Protein;
102 import org.forester.protein.ProteinId;
103 import org.forester.rio.TestRIO;
104 import org.forester.sdi.SDI;
105 import org.forester.sdi.SDIR;
106 import org.forester.sdi.TestGSDI;
107 import org.forester.sequence.BasicSequence;
108 import org.forester.sequence.Sequence;
109 import org.forester.species.BasicSpecies;
110 import org.forester.species.Species;
111 import org.forester.surfacing.TestSurfacing;
112 import org.forester.tools.ConfidenceAssessor;
113 import org.forester.tools.SupportCount;
114 import org.forester.tools.TreeSplitMatrix;
115 import org.forester.util.AsciiHistogram;
116 import org.forester.util.BasicDescriptiveStatistics;
117 import org.forester.util.BasicTable;
118 import org.forester.util.BasicTableParser;
119 import org.forester.util.DescriptiveStatistics;
120 import org.forester.util.ForesterConstants;
121 import org.forester.util.ForesterUtil;
122 import org.forester.util.GeneralTable;
123 import org.forester.util.SequenceAccessionTools;
124 import org.forester.ws.seqdb.SequenceDatabaseEntry;
125 import org.forester.ws.seqdb.SequenceDbWsTools;
126 import org.forester.ws.seqdb.UniProtTaxonomy;
127 import org.forester.ws.wabi.TxSearch;
128 import org.forester.ws.wabi.TxSearch.RANKS;
129 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
130 import org.forester.ws.wabi.TxSearch.TAX_RANK;
131
132 @SuppressWarnings( "unused")
133 public final class Test {
134
135     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
136                                                                    + ForesterUtil.getFileSeparator() + "resources"
137                                                                    + ForesterUtil.getFileSeparator();
138     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
139                                                                    + ForesterUtil.getFileSeparator() + "test_data"
140                                                                    + ForesterUtil.getFileSeparator();
141     private final static boolean PERFORM_DB_TESTS          = false;
142     private static final boolean PERFORM_WEB_TREE_ACCESS   = true;
143     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
144                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
145                                                                    + ForesterConstants.PHYLO_XML_XSD;
146     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
147                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
148                                                                    + ForesterConstants.PHYLO_XML_XSD;
149     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
150     private final static double  ZERO_DIFF                 = 1.0E-9;
151
152     public static boolean isEqual( final double a, final double b ) {
153         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
154     }
155
156     public static void main( final String[] args ) {
157         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
158         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
159                 + "]" );
160         Locale.setDefault( Locale.US );
161         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
162         int failed = 0;
163         int succeeded = 0;
164         System.out.print( "[Test if directory with files for testing exists/is readable: " );
165         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
166             System.out.println( "OK.]" );
167         }
168         else {
169             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
170             System.out.println( "Testing aborted." );
171             System.exit( -1 );
172         }
173         System.out.print( "[Test if resources directory exists/is readable: " );
174         if ( testDir( PATH_TO_RESOURCES ) ) {
175             System.out.println( "OK.]" );
176         }
177         else {
178             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
179             System.out.println( "Testing aborted." );
180             System.exit( -1 );
181         }
182         final long start_time = new Date().getTime();
183         System.out.print( "Basic node methods: " );
184         if ( Test.testBasicNodeMethods() ) {
185             System.out.println( "OK." );
186             succeeded++;
187         }
188         else {
189             System.out.println( "failed." );
190             failed++;
191         }
192         System.out.print( "Protein id: " );
193         if ( !testProteinId() ) {
194             System.out.println( "failed." );
195             failed++;
196         }
197         else {
198             succeeded++;
199         }
200         System.out.println( "OK." );
201         System.out.print( "Species: " );
202         if ( !testSpecies() ) {
203             System.out.println( "failed." );
204             failed++;
205         }
206         else {
207             succeeded++;
208         }
209         System.out.println( "OK." );
210         System.out.print( "Basic domain: " );
211         if ( !testBasicDomain() ) {
212             System.out.println( "failed." );
213             failed++;
214         }
215         else {
216             succeeded++;
217         }
218         System.out.println( "OK." );
219         System.out.print( "Basic protein: " );
220         if ( !testBasicProtein() ) {
221             System.out.println( "failed." );
222             failed++;
223         }
224         else {
225             succeeded++;
226         }
227         System.out.println( "OK." );
228         System.out.print( "Sequence writer: " );
229         if ( testSequenceWriter() ) {
230             System.out.println( "OK." );
231             succeeded++;
232         }
233         else {
234             System.out.println( "failed." );
235             failed++;
236         }
237         System.out.print( "Sequence id parsing: " );
238         if ( testSequenceIdParsing() ) {
239             System.out.println( "OK." );
240             succeeded++;
241         }
242         else {
243             System.out.println( "failed." );
244             failed++;
245         }
246         System.out.print( "UniProtKB id extraction: " );
247         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
248             System.out.println( "OK." );
249             succeeded++;
250         }
251         else {
252             System.out.println( "failed." );
253             failed++;
254         }
255         System.out.print( "Sequence DB tools 1: " );
256         if ( testSequenceDbWsTools1() ) {
257             System.out.println( "OK." );
258             succeeded++;
259         }
260         else {
261             System.out.println( "failed." );
262             failed++;
263         }
264         System.out.print( "Hmmscan output parser: " );
265         if ( testHmmscanOutputParser() ) {
266             System.out.println( "OK." );
267             succeeded++;
268         }
269         else {
270             System.out.println( "failed." );
271             failed++;
272         }
273         System.out.print( "Overlap removal: " );
274         if ( !org.forester.test.Test.testOverlapRemoval() ) {
275             System.out.println( "failed." );
276             failed++;
277         }
278         else {
279             succeeded++;
280         }
281         System.out.println( "OK." );
282         System.out.print( "Engulfing overlap removal: " );
283         if ( !Test.testEngulfingOverlapRemoval() ) {
284             System.out.println( "failed." );
285             failed++;
286         }
287         else {
288             succeeded++;
289         }
290         System.out.println( "OK." );
291         System.out.print( "Taxonomy code extraction: " );
292         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
293             System.out.println( "OK." );
294             succeeded++;
295         }
296         else {
297             System.out.println( "failed." );
298             failed++;
299         }
300         System.out.print( "SN extraction: " );
301         if ( Test.testExtractSNFromNodeName() ) {
302             System.out.println( "OK." );
303             succeeded++;
304         }
305         else {
306             System.out.println( "failed." );
307             failed++;
308         }
309         System.out.print( "Taxonomy extraction (general): " );
310         if ( Test.testTaxonomyExtraction() ) {
311             System.out.println( "OK." );
312             succeeded++;
313         }
314         else {
315             System.out.println( "failed." );
316             failed++;
317         }
318         System.out.print( "Uri for Aptx web sequence accession: " );
319         if ( Test.testCreateUriForSeqWeb() ) {
320             System.out.println( "OK." );
321             succeeded++;
322         }
323         else {
324             System.out.println( "failed." );
325             failed++;
326         }
327         System.out.print( "Basic node construction and parsing of NHX (node level): " );
328         if ( Test.testNHXNodeParsing() ) {
329             System.out.println( "OK." );
330             succeeded++;
331         }
332         else {
333             System.out.println( "failed." );
334             failed++;
335         }
336         System.out.print( "NHX parsing iterating: " );
337         if ( Test.testNHParsingIter() ) {
338             System.out.println( "OK." );
339             succeeded++;
340         }
341         else {
342             System.out.println( "failed." );
343             failed++;
344         }
345         System.out.print( "NH parsing: " );
346         if ( Test.testNHParsing() ) {
347             System.out.println( "OK." );
348             succeeded++;
349         }
350         else {
351             System.out.println( "failed." );
352             failed++;
353         }
354         System.out.print( "Conversion to NHX (node level): " );
355         if ( Test.testNHXconversion() ) {
356             System.out.println( "OK." );
357             succeeded++;
358         }
359         else {
360             System.out.println( "failed." );
361             failed++;
362         }
363         System.out.print( "NHX parsing: " );
364         if ( Test.testNHXParsing() ) {
365             System.out.println( "OK." );
366             succeeded++;
367         }
368         else {
369             System.out.println( "failed." );
370             failed++;
371         }
372         System.out.print( "NHX parsing with quotes: " );
373         if ( Test.testNHXParsingQuotes() ) {
374             System.out.println( "OK." );
375             succeeded++;
376         }
377         else {
378             System.out.println( "failed." );
379             failed++;
380         }
381         System.out.print( "NHX parsing (MrBayes): " );
382         if ( Test.testNHXParsingMB() ) {
383             System.out.println( "OK." );
384             succeeded++;
385         }
386         else {
387             System.out.println( "failed." );
388             failed++;
389         }
390         System.out.print( "Nexus characters parsing: " );
391         if ( Test.testNexusCharactersParsing() ) {
392             System.out.println( "OK." );
393             succeeded++;
394         }
395         else {
396             System.out.println( "failed." );
397             failed++;
398         }
399         System.out.print( "Nexus tree parsing iterating: " );
400         if ( Test.testNexusTreeParsingIterating() ) {
401             System.out.println( "OK." );
402             succeeded++;
403         }
404         else {
405             System.out.println( "failed." );
406             failed++;
407         }
408         System.out.print( "Nexus tree parsing: " );
409         if ( Test.testNexusTreeParsing() ) {
410             System.out.println( "OK." );
411             succeeded++;
412         }
413         else {
414             System.out.println( "failed." );
415             failed++;
416         }
417         System.out.print( "Nexus tree parsing (translating): " );
418         if ( Test.testNexusTreeParsingTranslating() ) {
419             System.out.println( "OK." );
420             succeeded++;
421         }
422         else {
423             System.out.println( "failed." );
424             failed++;
425         }
426         System.out.print( "Nexus matrix parsing: " );
427         if ( Test.testNexusMatrixParsing() ) {
428             System.out.println( "OK." );
429             succeeded++;
430         }
431         else {
432             System.out.println( "failed." );
433             failed++;
434         }
435         System.out.print( "Basic phyloXML parsing: " );
436         if ( Test.testBasicPhyloXMLparsing() ) {
437             System.out.println( "OK." );
438             succeeded++;
439         }
440         else {
441             System.out.println( "failed." );
442             failed++;
443         }
444         System.out.print( "Basic phyloXML parsing (validating against schema): " );
445         if ( testBasicPhyloXMLparsingValidating() ) {
446             System.out.println( "OK." );
447             succeeded++;
448         }
449         else {
450             System.out.println( "failed." );
451             failed++;
452         }
453         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
454         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
455             System.out.println( "OK." );
456             succeeded++;
457         }
458         else {
459             System.out.println( "failed." );
460             failed++;
461         }
462         System.out.print( "phyloXML Distribution Element: " );
463         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
464             System.out.println( "OK." );
465             succeeded++;
466         }
467         else {
468             System.out.println( "failed." );
469             failed++;
470         }
471         System.out.print( "Tol XML parsing: " );
472         if ( Test.testBasicTolXMLparsing() ) {
473             System.out.println( "OK." );
474             succeeded++;
475         }
476         else {
477             System.out.println( "failed." );
478             failed++;
479         }
480         System.out.print( "Copying of node data: " );
481         if ( Test.testCopyOfNodeData() ) {
482             System.out.println( "OK." );
483             succeeded++;
484         }
485         else {
486             System.out.println( "failed." );
487             failed++;
488         }
489         System.out.print( "Tree copy: " );
490         if ( Test.testTreeCopy() ) {
491             System.out.println( "OK." );
492             succeeded++;
493         }
494         else {
495             System.out.println( "failed." );
496             failed++;
497         }
498         System.out.print( "Basic tree methods: " );
499         if ( Test.testBasicTreeMethods() ) {
500             System.out.println( "OK." );
501             succeeded++;
502         }
503         else {
504             System.out.println( "failed." );
505             failed++;
506         }
507         System.out.print( "Tree methods: " );
508         if ( Test.testTreeMethods() ) {
509             System.out.println( "OK." );
510             succeeded++;
511         }
512         else {
513             System.out.println( "failed." );
514             failed++;
515         }
516         System.out.print( "Postorder Iterator: " );
517         if ( Test.testPostOrderIterator() ) {
518             System.out.println( "OK." );
519             succeeded++;
520         }
521         else {
522             System.out.println( "failed." );
523             failed++;
524         }
525         System.out.print( "Preorder Iterator: " );
526         if ( Test.testPreOrderIterator() ) {
527             System.out.println( "OK." );
528             succeeded++;
529         }
530         else {
531             System.out.println( "failed." );
532             failed++;
533         }
534         System.out.print( "Levelorder Iterator: " );
535         if ( Test.testLevelOrderIterator() ) {
536             System.out.println( "OK." );
537             succeeded++;
538         }
539         else {
540             System.out.println( "failed." );
541             failed++;
542         }
543         System.out.print( "Re-id methods: " );
544         if ( Test.testReIdMethods() ) {
545             System.out.println( "OK." );
546             succeeded++;
547         }
548         else {
549             System.out.println( "failed." );
550             failed++;
551         }
552         System.out.print( "Methods on last external nodes: " );
553         if ( Test.testLastExternalNodeMethods() ) {
554             System.out.println( "OK." );
555             succeeded++;
556         }
557         else {
558             System.out.println( "failed." );
559             failed++;
560         }
561         System.out.print( "Methods on external nodes: " );
562         if ( Test.testExternalNodeRelatedMethods() ) {
563             System.out.println( "OK." );
564             succeeded++;
565         }
566         else {
567             System.out.println( "failed." );
568             failed++;
569         }
570         System.out.print( "Deletion of external nodes: " );
571         if ( Test.testDeletionOfExternalNodes() ) {
572             System.out.println( "OK." );
573             succeeded++;
574         }
575         else {
576             System.out.println( "failed." );
577             failed++;
578         }
579         System.out.print( "Subtree deletion: " );
580         if ( Test.testSubtreeDeletion() ) {
581             System.out.println( "OK." );
582             succeeded++;
583         }
584         else {
585             System.out.println( "failed." );
586             failed++;
587         }
588         System.out.print( "Phylogeny branch: " );
589         if ( Test.testPhylogenyBranch() ) {
590             System.out.println( "OK." );
591             succeeded++;
592         }
593         else {
594             System.out.println( "failed." );
595             failed++;
596         }
597         System.out.print( "Rerooting: " );
598         if ( Test.testRerooting() ) {
599             System.out.println( "OK." );
600             succeeded++;
601         }
602         else {
603             System.out.println( "failed." );
604             failed++;
605         }
606         System.out.print( "Mipoint rooting: " );
607         if ( Test.testMidpointrooting() ) {
608             System.out.println( "OK." );
609             succeeded++;
610         }
611         else {
612             System.out.println( "failed." );
613             failed++;
614         }
615         System.out.print( "Node removal: " );
616         if ( Test.testNodeRemoval() ) {
617             System.out.println( "OK." );
618             succeeded++;
619         }
620         else {
621             System.out.println( "failed." );
622             failed++;
623         }
624         System.out.print( "Support count: " );
625         if ( Test.testSupportCount() ) {
626             System.out.println( "OK." );
627             succeeded++;
628         }
629         else {
630             System.out.println( "failed." );
631             failed++;
632         }
633         System.out.print( "Support transfer: " );
634         if ( Test.testSupportTransfer() ) {
635             System.out.println( "OK." );
636             succeeded++;
637         }
638         else {
639             System.out.println( "failed." );
640             failed++;
641         }
642         System.out.print( "Finding of LCA: " );
643         if ( Test.testGetLCA() ) {
644             System.out.println( "OK." );
645             succeeded++;
646         }
647         else {
648             System.out.println( "failed." );
649             failed++;
650         }
651         System.out.print( "Finding of LCA 2: " );
652         if ( Test.testGetLCA2() ) {
653             System.out.println( "OK." );
654             succeeded++;
655         }
656         else {
657             System.out.println( "failed." );
658             failed++;
659         }
660         System.out.print( "Calculation of distance between nodes: " );
661         if ( Test.testGetDistance() ) {
662             System.out.println( "OK." );
663             succeeded++;
664         }
665         else {
666             System.out.println( "failed." );
667             failed++;
668         }
669         System.out.print( "Descriptive statistics: " );
670         if ( Test.testDescriptiveStatistics() ) {
671             System.out.println( "OK." );
672             succeeded++;
673         }
674         else {
675             System.out.println( "failed." );
676             failed++;
677         }
678         System.out.print( "Data objects and methods: " );
679         if ( Test.testDataObjects() ) {
680             System.out.println( "OK." );
681             succeeded++;
682         }
683         else {
684             System.out.println( "failed." );
685             failed++;
686         }
687         System.out.print( "Properties map: " );
688         if ( Test.testPropertiesMap() ) {
689             System.out.println( "OK." );
690             succeeded++;
691         }
692         else {
693             System.out.println( "failed." );
694             failed++;
695         }
696         System.out.print( "SDIse: " );
697         if ( Test.testSDIse() ) {
698             System.out.println( "OK." );
699             succeeded++;
700         }
701         else {
702             System.out.println( "failed." );
703             failed++;
704         }
705         System.out.print( "SDIunrooted: " );
706         if ( Test.testSDIunrooted() ) {
707             System.out.println( "OK." );
708             succeeded++;
709         }
710         else {
711             System.out.println( "failed." );
712             failed++;
713         }
714         System.out.print( "GSDI: " );
715         if ( TestGSDI.test() ) {
716             System.out.println( "OK." );
717             succeeded++;
718         }
719         else {
720             System.out.println( "failed." );
721             failed++;
722         }
723         System.out.print( "RIO: " );
724         if ( TestRIO.test() ) {
725             System.out.println( "OK." );
726             succeeded++;
727         }
728         else {
729             System.out.println( "failed." );
730             failed++;
731         }
732         System.out.print( "Phylogeny reconstruction:" );
733         System.out.println();
734         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
735             System.out.println( "OK." );
736             succeeded++;
737         }
738         else {
739             System.out.println( "failed." );
740             failed++;
741         }
742         System.out.print( "Analysis of domain architectures: " );
743         System.out.println();
744         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
745             System.out.println( "OK." );
746             succeeded++;
747         }
748         else {
749             System.out.println( "failed." );
750             failed++;
751         }
752         System.out.print( "GO: " );
753         System.out.println();
754         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
755             System.out.println( "OK." );
756             succeeded++;
757         }
758         else {
759             System.out.println( "failed." );
760             failed++;
761         }
762         System.out.print( "Modeling tools: " );
763         if ( TestPccx.test() ) {
764             System.out.println( "OK." );
765             succeeded++;
766         }
767         else {
768             System.out.println( "failed." );
769             failed++;
770         }
771         System.out.print( "Split Matrix strict: " );
772         if ( Test.testSplitStrict() ) {
773             System.out.println( "OK." );
774             succeeded++;
775         }
776         else {
777             System.out.println( "failed." );
778             failed++;
779         }
780         System.out.print( "Split Matrix: " );
781         if ( Test.testSplit() ) {
782             System.out.println( "OK." );
783             succeeded++;
784         }
785         else {
786             System.out.println( "failed." );
787             failed++;
788         }
789         System.out.print( "Confidence Assessor: " );
790         if ( Test.testConfidenceAssessor() ) {
791             System.out.println( "OK." );
792             succeeded++;
793         }
794         else {
795             System.out.println( "failed." );
796             failed++;
797         }
798         System.out.print( "Basic table: " );
799         if ( Test.testBasicTable() ) {
800             System.out.println( "OK." );
801             succeeded++;
802         }
803         else {
804             System.out.println( "failed." );
805             failed++;
806         }
807         System.out.print( "General table: " );
808         if ( Test.testGeneralTable() ) {
809             System.out.println( "OK." );
810             succeeded++;
811         }
812         else {
813             System.out.println( "failed." );
814             failed++;
815         }
816         System.out.print( "Amino acid sequence: " );
817         if ( Test.testAminoAcidSequence() ) {
818             System.out.println( "OK." );
819             succeeded++;
820         }
821         else {
822             System.out.println( "failed." );
823             failed++;
824         }
825         System.out.print( "General MSA parser: " );
826         if ( Test.testGeneralMsaParser() ) {
827             System.out.println( "OK." );
828             succeeded++;
829         }
830         else {
831             System.out.println( "failed." );
832             failed++;
833         }
834         System.out.print( "Fasta parser for msa: " );
835         if ( Test.testFastaParser() ) {
836             System.out.println( "OK." );
837             succeeded++;
838         }
839         else {
840             System.out.println( "failed." );
841             failed++;
842         }
843         System.out.print( "Creation of balanced phylogeny: " );
844         if ( Test.testCreateBalancedPhylogeny() ) {
845             System.out.println( "OK." );
846             succeeded++;
847         }
848         else {
849             System.out.println( "failed." );
850             failed++;
851         }
852         System.out.print( "Genbank accessor parsing: " );
853         if ( Test.testGenbankAccessorParsing() ) {
854             System.out.println( "OK." );
855             succeeded++;
856         }
857         else {
858             System.out.println( "failed." );
859             failed++;
860         }
861         String path = "";
862         final String os = ForesterUtil.OS_NAME.toLowerCase();
863         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
864             path = "/usr/local/bin/mafft";
865         }
866         else if ( os.indexOf( "win" ) >= 0 ) {
867             path = "C:\\Program Files\\mafft-win\\mafft.bat";
868         }
869         else {
870             path = "mafft";
871             if ( !MsaInferrer.isInstalled( path ) ) {
872                 path = "/usr/bin/mafft";
873             }
874             if ( !MsaInferrer.isInstalled( path ) ) {
875                 path = "/usr/local/bin/mafft";
876             }
877         }
878         if ( MsaInferrer.isInstalled( path ) ) {
879             System.out.print( "MAFFT (external program): " );
880             if ( Test.testMafft( path ) ) {
881                 System.out.println( "OK." );
882                 succeeded++;
883             }
884             else {
885                 System.out.println( "failed [will not count towards failed tests]" );
886             }
887         }
888         System.out.print( "Next nodes with collapsed: " );
889         if ( Test.testNextNodeWithCollapsing() ) {
890             System.out.println( "OK." );
891             succeeded++;
892         }
893         else {
894             System.out.println( "failed." );
895             failed++;
896         }
897         System.out.print( "Simple MSA quality: " );
898         if ( Test.testMsaQualityMethod() ) {
899             System.out.println( "OK." );
900             succeeded++;
901         }
902         else {
903             System.out.println( "failed." );
904             failed++;
905         }
906         System.out.print( "Deleteable MSA: " );
907         if ( Test.testDeleteableMsa() ) {
908             System.out.println( "OK." );
909             succeeded++;
910         }
911         else {
912             System.out.println( "failed." );
913             failed++;
914         }
915         if ( PERFORM_DB_TESTS ) {
916             System.out.print( "Uniprot Entry Retrieval: " );
917             if ( Test.testUniprotEntryRetrieval() ) {
918                 System.out.println( "OK." );
919                 succeeded++;
920             }
921             else {
922                 System.out.println( "failed." );
923                 failed++;
924             }
925             System.out.print( "Ebi Entry Retrieval: " );
926             if ( Test.testEbiEntryRetrieval() ) {
927                 System.out.println( "OK." );
928                 succeeded++;
929             }
930             else {
931                 System.out.println( "failed." );
932                 failed++;
933             }
934             System.out.print( "Sequence DB tools 2: " );
935             if ( testSequenceDbWsTools2() ) {
936                 System.out.println( "OK." );
937                 succeeded++;
938             }
939             else {
940                 System.out.println( "failed." );
941                 failed++;
942                 System.exit( -1 );
943             }
944             System.out.print( "Uniprot Taxonomy Search: " );
945             if ( Test.testUniprotTaxonomySearch() ) {
946                 System.out.println( "OK." );
947                 succeeded++;
948             }
949             else {
950                 System.out.println( "failed." );
951                 failed++;
952             }
953         }
954         if ( PERFORM_WEB_TREE_ACCESS ) {
955             System.out.print( "NHX parsing from URL: " );
956             if ( Test.testNHXparsingFromURL() ) {
957                 System.out.println( "OK." );
958                 succeeded++;
959             }
960             else {
961                 System.out.println( "failed." );
962                 failed++;
963             }
964             System.out.print( "phyloXML parsing from URL: " );
965             if ( Test.testPhyloXMLparsingFromURL() ) {
966                 System.out.println( "OK." );
967                 succeeded++;
968             }
969             else {
970                 System.out.println( "failed." );
971                 failed++;
972             }
973             System.out.print( "TreeBase acccess: " );
974             if ( Test.testTreeBaseReading() ) {
975                 System.out.println( "OK." );
976                 succeeded++;
977             }
978             else {
979                 System.out.println( "failed." );
980                 failed++;
981             }
982             //
983             System.out.print( "ToL access: " );
984             if ( Test.testToLReading() ) {
985                 System.out.println( "OK." );
986                 succeeded++;
987             }
988             else {
989                 System.out.println( "failed." );
990                 failed++;
991             }
992             //
993             System.out.print( "TreeFam access: " );
994             if ( Test.testTreeFamReading() ) {
995                 System.out.println( "OK." );
996                 succeeded++;
997             }
998             else {
999                 System.out.println( "failed." );
1000                 failed++;
1001             }
1002             //
1003             //
1004             System.out.print( "Pfam tree access: " );
1005             if ( Test.testPfamTreeReading() ) {
1006                 System.out.println( "OK." );
1007                 succeeded++;
1008             }
1009             else {
1010                 System.out.println( "failed." );
1011                 failed++;
1012             }
1013         }
1014         System.out.println();
1015         final Runtime rt = java.lang.Runtime.getRuntime();
1016         final long free_memory = rt.freeMemory() / 1000000;
1017         final long total_memory = rt.totalMemory() / 1000000;
1018         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1019                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1020         System.out.println();
1021         System.out.println( "Successful tests: " + succeeded );
1022         System.out.println( "Failed     tests: " + failed );
1023         System.out.println();
1024         if ( failed < 1 ) {
1025             System.out.println( "OK." );
1026         }
1027         else {
1028             System.out.println( "Not OK." );
1029         }
1030     }
1031
1032     public static boolean testEngulfingOverlapRemoval() {
1033         try {
1034             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1035             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1036             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1037             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1038             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1039             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1040             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1041             final List<Boolean> covered = new ArrayList<Boolean>();
1042             covered.add( true ); // 0
1043             covered.add( false ); // 1
1044             covered.add( true ); // 2
1045             covered.add( false ); // 3
1046             covered.add( true ); // 4
1047             covered.add( true ); // 5
1048             covered.add( false ); // 6
1049             covered.add( true ); // 7
1050             covered.add( true ); // 8
1051             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1052                 return false;
1053             }
1054             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1055                 return false;
1056             }
1057             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1058                 return false;
1059             }
1060             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1061                 return false;
1062             }
1063             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1064                 return false;
1065             }
1066             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1067                 return false;
1068             }
1069             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1070                 return false;
1071             }
1072             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1073             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1074             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1075             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1076             abc.addProteinDomain( a );
1077             abc.addProteinDomain( b );
1078             abc.addProteinDomain( c );
1079             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1080             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1081             if ( abc.getNumberOfProteinDomains() != 3 ) {
1082                 return false;
1083             }
1084             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1085                 return false;
1086             }
1087             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1088                 return false;
1089             }
1090             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1091                 return false;
1092             }
1093             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1094                 return false;
1095             }
1096             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1097             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1098             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1099             final Protein def = new BasicProtein( "def", "nemve", 0 );
1100             def.addProteinDomain( d );
1101             def.addProteinDomain( e );
1102             def.addProteinDomain( f );
1103             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1104             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1105             if ( def.getNumberOfProteinDomains() != 3 ) {
1106                 return false;
1107             }
1108             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1109                 return false;
1110             }
1111             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1112                 return false;
1113             }
1114             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1115                 return false;
1116             }
1117             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1118                 return false;
1119             }
1120             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1121                 return false;
1122             }
1123         }
1124         catch ( final Exception e ) {
1125             e.printStackTrace( System.out );
1126             return false;
1127         }
1128         return true;
1129     }
1130
1131     public static final boolean testNHXparsingFromURL() {
1132         try {
1133             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1134             final URL u = new URL( s );
1135             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1136             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1137             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1138                 return false;
1139             }
1140             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1141                 System.out.println( phys[ 0 ].toNewHampshire() );
1142                 return false;
1143             }
1144             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1145                 System.out.println( phys[ 1 ].toNewHampshire() );
1146                 return false;
1147             }
1148             final Phylogeny[] phys2 = factory.create( u.openStream(), new NHXParser() );
1149             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1150                 return false;
1151             }
1152             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1153                 System.out.println( phys2[ 0 ].toNewHampshire() );
1154                 return false;
1155             }
1156             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1157             final NHXParser p = new NHXParser();
1158             final URL u2 = new URL( s );
1159             p.setSource( u2 );
1160             if ( !p.hasNext() ) {
1161                 return false;
1162             }
1163             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1164                 return false;
1165             }
1166             if ( !p.hasNext() ) {
1167                 return false;
1168             }
1169             p.reset();
1170             if ( !p.hasNext() ) {
1171                 return false;
1172             }
1173             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1174                 return false;
1175             }
1176             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1177                 return false;
1178             }
1179             p.reset();
1180             if ( !p.hasNext() ) {
1181                 return false;
1182             }
1183             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1184                 return false;
1185             }
1186             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1187                 return false;
1188             }
1189         }
1190         catch ( final Exception e ) {
1191             e.printStackTrace();
1192         }
1193         return true;
1194     }
1195
1196     public static boolean testOverlapRemoval() {
1197         try {
1198             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1199             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1200             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1201             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1202             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1203             final List<Boolean> covered = new ArrayList<Boolean>();
1204             covered.add( true ); // 0
1205             covered.add( false ); // 1
1206             covered.add( true ); // 2
1207             covered.add( false ); // 3
1208             covered.add( true ); // 4
1209             covered.add( true ); // 5
1210             covered.add( false ); // 6
1211             covered.add( true ); // 7
1212             covered.add( true ); // 8
1213             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1214                 return false;
1215             }
1216             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1217                 return false;
1218             }
1219             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1220                 return false;
1221             }
1222             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1223                 return false;
1224             }
1225             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1226                 return false;
1227             }
1228             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1229             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1230             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1231             ab.addProteinDomain( a );
1232             ab.addProteinDomain( b );
1233             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1234             if ( ab.getNumberOfProteinDomains() != 2 ) {
1235                 return false;
1236             }
1237             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1238                 return false;
1239             }
1240             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1241                 return false;
1242             }
1243             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1244             if ( ab.getNumberOfProteinDomains() != 2 ) {
1245                 return false;
1246             }
1247             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1248                 return false;
1249             }
1250             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1251             final Domain d = new BasicDomain( "d",
1252                                               ( short ) 10000,
1253                                               ( short ) 10500,
1254                                               ( short ) 1,
1255                                               ( short ) 1,
1256                                               0.0000001,
1257                                               1 );
1258             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1259             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1260             cde.addProteinDomain( c );
1261             cde.addProteinDomain( d );
1262             cde.addProteinDomain( e );
1263             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1264             if ( cde.getNumberOfProteinDomains() != 3 ) {
1265                 return false;
1266             }
1267             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1268                 return false;
1269             }
1270             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1271             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1272             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1273             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1274             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1275             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1276             fghi.addProteinDomain( f );
1277             fghi.addProteinDomain( g );
1278             fghi.addProteinDomain( h );
1279             fghi.addProteinDomain( i );
1280             fghi.addProteinDomain( i );
1281             fghi.addProteinDomain( i );
1282             fghi.addProteinDomain( i2 );
1283             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1284             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1285                 return false;
1286             }
1287             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1288                 return false;
1289             }
1290             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1291                 return false;
1292             }
1293             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1294             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1295                 return false;
1296             }
1297             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1298                 return false;
1299             }
1300             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1301             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1302             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1303             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1304             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1305             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1306             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1307             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1308             jklm.addProteinDomain( j );
1309             jklm.addProteinDomain( k );
1310             jklm.addProteinDomain( l );
1311             jklm.addProteinDomain( m );
1312             jklm.addProteinDomain( m0 );
1313             jklm.addProteinDomain( m1 );
1314             jklm.addProteinDomain( m2 );
1315             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1316             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1317                 return false;
1318             }
1319             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1320                 return false;
1321             }
1322             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1323                 return false;
1324             }
1325             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1326             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1327                 return false;
1328             }
1329             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1330                 return false;
1331             }
1332             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1333             final Protein od = new BasicProtein( "od", "varanus", 0 );
1334             od.addProteinDomain( only );
1335             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1336             if ( od.getNumberOfProteinDomains() != 1 ) {
1337                 return false;
1338             }
1339             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1340                 return false;
1341             }
1342         }
1343         catch ( final Exception e ) {
1344             e.printStackTrace( System.out );
1345             return false;
1346         }
1347         return true;
1348     }
1349
1350     public static final boolean testPfamTreeReading() {
1351         try {
1352             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1353             final NHXParser parser = new NHXParser();
1354             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1355             parser.setReplaceUnderscores( false );
1356             parser.setGuessRootedness( true );
1357             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1358             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1359             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1360                 return false;
1361             }
1362             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1363                 return false;
1364             }
1365         }
1366         catch ( final Exception e ) {
1367             e.printStackTrace();
1368         }
1369         return true;
1370     }
1371
1372     public static final boolean testPhyloXMLparsingFromURL() {
1373         try {
1374             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1375             final URL u = new URL( s );
1376             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1377             final Phylogeny[] phys = factory.create( u.openStream(), PhyloXmlParser.createPhyloXmlParser() );
1378             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1379                 return false;
1380             }
1381         }
1382         catch ( final Exception e ) {
1383             e.printStackTrace();
1384         }
1385         return true;
1386     }
1387
1388     public static final boolean testToLReading() {
1389         try {
1390             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1391             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1392             final Phylogeny[] phys = factory.create( u.openStream(), new TolParser() );
1393             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1394                 return false;
1395             }
1396             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1397                 return false;
1398             }
1399             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Protacanthopterygii" ) ) {
1400                 return false;
1401             }
1402             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1403                 return false;
1404             }
1405         }
1406         catch ( final Exception e ) {
1407             e.printStackTrace();
1408         }
1409         return true;
1410     }
1411
1412     public static final boolean testTreeBaseReading() {
1413         try {
1414             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );
1415             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1416             parser.setReplaceUnderscores( true );
1417             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1418             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1419             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1420                 return false;
1421             }
1422             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1423             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1424             parser2.setReplaceUnderscores( true );
1425             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1426             final Phylogeny[] phys2 = factory2.create( u2.openStream(), parser2 );
1427             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1428                 return false;
1429             }
1430         }
1431         catch ( final Exception e ) {
1432             e.printStackTrace();
1433         }
1434         return true;
1435     }
1436
1437     public static final boolean testTreeFamReading() {
1438         try {
1439             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1440             final NHXParser parser = new NHXParser();
1441             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1442             parser.setReplaceUnderscores( false );
1443             parser.setGuessRootedness( true );
1444             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1445             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1446             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1447                 return false;
1448             }
1449             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1450                 return false;
1451             }
1452         }
1453         catch ( final Exception e ) {
1454             e.printStackTrace();
1455         }
1456         return true;
1457     }
1458
1459     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1460         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1461         return p;
1462     }
1463
1464     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1465         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1466     }
1467
1468     private static boolean testAminoAcidSequence() {
1469         try {
1470             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1471             if ( aa1.getLength() != 13 ) {
1472                 return false;
1473             }
1474             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1475                 return false;
1476             }
1477             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1478                 return false;
1479             }
1480             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1481                 return false;
1482             }
1483             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1484             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
1485                 return false;
1486             }
1487             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1488             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1489                 return false;
1490             }
1491             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1492             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1493                 return false;
1494             }
1495         }
1496         catch ( final Exception e ) {
1497             e.printStackTrace();
1498             return false;
1499         }
1500         return true;
1501     }
1502
1503     private static boolean testBasicDomain() {
1504         try {
1505             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1506             if ( !pd.getDomainId().equals( "id" ) ) {
1507                 return false;
1508             }
1509             if ( pd.getNumber() != 1 ) {
1510                 return false;
1511             }
1512             if ( pd.getTotalCount() != 4 ) {
1513                 return false;
1514             }
1515             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1516                 return false;
1517             }
1518             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1519             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1520             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1521             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1522             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1523             if ( !a1.equals( a1 ) ) {
1524                 return false;
1525             }
1526             if ( !a1.equals( a1_copy ) ) {
1527                 return false;
1528             }
1529             if ( !a1.equals( a1_equal ) ) {
1530                 return false;
1531             }
1532             if ( !a1.equals( a2 ) ) {
1533                 return false;
1534             }
1535             if ( a1.equals( a3 ) ) {
1536                 return false;
1537             }
1538             if ( a1.compareTo( a1 ) != 0 ) {
1539                 return false;
1540             }
1541             if ( a1.compareTo( a1_copy ) != 0 ) {
1542                 return false;
1543             }
1544             if ( a1.compareTo( a1_equal ) != 0 ) {
1545                 return false;
1546             }
1547             if ( a1.compareTo( a2 ) != 0 ) {
1548                 return false;
1549             }
1550             if ( a1.compareTo( a3 ) == 0 ) {
1551                 return false;
1552             }
1553         }
1554         catch ( final Exception e ) {
1555             e.printStackTrace( System.out );
1556             return false;
1557         }
1558         return true;
1559     }
1560
1561     private static boolean testBasicNodeMethods() {
1562         try {
1563             if ( PhylogenyNode.getNodeCount() != 0 ) {
1564                 return false;
1565             }
1566             final PhylogenyNode n1 = new PhylogenyNode();
1567             final PhylogenyNode n2 = PhylogenyNode
1568                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1569             final PhylogenyNode n3 = PhylogenyNode
1570                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1571             final PhylogenyNode n4 = PhylogenyNode
1572                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1573             if ( n1.isHasAssignedEvent() ) {
1574                 return false;
1575             }
1576             if ( PhylogenyNode.getNodeCount() != 4 ) {
1577                 return false;
1578             }
1579             if ( n3.getIndicator() != 0 ) {
1580                 return false;
1581             }
1582             if ( n3.getNumberOfExternalNodes() != 1 ) {
1583                 return false;
1584             }
1585             if ( !n3.isExternal() ) {
1586                 return false;
1587             }
1588             if ( !n3.isRoot() ) {
1589                 return false;
1590             }
1591             if ( !n4.getName().equals( "n4" ) ) {
1592                 return false;
1593             }
1594         }
1595         catch ( final Exception e ) {
1596             e.printStackTrace( System.out );
1597             return false;
1598         }
1599         return true;
1600     }
1601
1602     private static boolean testBasicPhyloXMLparsing() {
1603         try {
1604             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1605             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1606             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1607                                                               xml_parser );
1608             if ( xml_parser.getErrorCount() > 0 ) {
1609                 System.out.println( xml_parser.getErrorMessages().toString() );
1610                 return false;
1611             }
1612             if ( phylogenies_0.length != 4 ) {
1613                 return false;
1614             }
1615             final Phylogeny t1 = phylogenies_0[ 0 ];
1616             final Phylogeny t2 = phylogenies_0[ 1 ];
1617             final Phylogeny t3 = phylogenies_0[ 2 ];
1618             final Phylogeny t4 = phylogenies_0[ 3 ];
1619             if ( t1.getNumberOfExternalNodes() != 1 ) {
1620                 return false;
1621             }
1622             if ( !t1.isRooted() ) {
1623                 return false;
1624             }
1625             if ( t1.isRerootable() ) {
1626                 return false;
1627             }
1628             if ( !t1.getType().equals( "gene_tree" ) ) {
1629                 return false;
1630             }
1631             if ( t2.getNumberOfExternalNodes() != 2 ) {
1632                 return false;
1633             }
1634             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1635                 return false;
1636             }
1637             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1638                 return false;
1639             }
1640             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1641                 return false;
1642             }
1643             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1644                 return false;
1645             }
1646             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1647                 return false;
1648             }
1649             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1650                 return false;
1651             }
1652             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1653                     .startsWith( "actgtgggggt" ) ) {
1654                 return false;
1655             }
1656             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1657                     .startsWith( "ctgtgatgcat" ) ) {
1658                 return false;
1659             }
1660             if ( t3.getNumberOfExternalNodes() != 4 ) {
1661                 return false;
1662             }
1663             if ( !t1.getName().equals( "t1" ) ) {
1664                 return false;
1665             }
1666             if ( !t2.getName().equals( "t2" ) ) {
1667                 return false;
1668             }
1669             if ( !t3.getName().equals( "t3" ) ) {
1670                 return false;
1671             }
1672             if ( !t4.getName().equals( "t4" ) ) {
1673                 return false;
1674             }
1675             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1676                 return false;
1677             }
1678             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1679                 return false;
1680             }
1681             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1682                 return false;
1683             }
1684             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1685                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1686                 return false;
1687             }
1688             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1689                 return false;
1690             }
1691             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1692                 return false;
1693             }
1694             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1695                 return false;
1696             }
1697             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1698                     .equals( "apoptosis" ) ) {
1699                 return false;
1700             }
1701             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1702                     .equals( "GO:0006915" ) ) {
1703                 return false;
1704             }
1705             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1706                     .equals( "UniProtKB" ) ) {
1707                 return false;
1708             }
1709             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1710                     .equals( "experimental" ) ) {
1711                 return false;
1712             }
1713             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1714                     .equals( "function" ) ) {
1715                 return false;
1716             }
1717             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1718                     .getValue() != 1 ) {
1719                 return false;
1720             }
1721             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1722                     .getType().equals( "ml" ) ) {
1723                 return false;
1724             }
1725             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1726                     .equals( "apoptosis" ) ) {
1727                 return false;
1728             }
1729             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1730                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1731                 return false;
1732             }
1733             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1734                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1735                 return false;
1736             }
1737             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1738                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1739                 return false;
1740             }
1741             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1742                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1743                 return false;
1744             }
1745             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1746                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1747                 return false;
1748             }
1749             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1750                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1751                 return false;
1752             }
1753             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1754                     .equals( "GO:0005829" ) ) {
1755                 return false;
1756             }
1757             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1758                     .equals( "intracellular organelle" ) ) {
1759                 return false;
1760             }
1761             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1762                 return false;
1763             }
1764             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1765                     .equals( "UniProt link" ) ) ) {
1766                 return false;
1767             }
1768             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1769                 return false;
1770             }
1771             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1772             if ( x.size() != 4 ) {
1773                 return false;
1774             }
1775             int c = 0;
1776             for( final Accession acc : x ) {
1777                 if ( c == 0 ) {
1778                     if ( !acc.getSource().equals( "KEGG" ) ) {
1779                         return false;
1780                     }
1781                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1782                         return false;
1783                     }
1784                 }
1785                 c++;
1786             }
1787         }
1788         catch ( final Exception e ) {
1789             e.printStackTrace( System.out );
1790             return false;
1791         }
1792         return true;
1793     }
1794
1795     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1796         try {
1797             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1798             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1799             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1800                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1801             }
1802             else {
1803                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1804             }
1805             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1806                                                               xml_parser );
1807             if ( xml_parser.getErrorCount() > 0 ) {
1808                 System.out.println( xml_parser.getErrorMessages().toString() );
1809                 return false;
1810             }
1811             if ( phylogenies_0.length != 4 ) {
1812                 return false;
1813             }
1814             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1815             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1816             if ( phylogenies_t1.length != 1 ) {
1817                 return false;
1818             }
1819             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1820             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1821                 return false;
1822             }
1823             if ( !t1_rt.isRooted() ) {
1824                 return false;
1825             }
1826             if ( t1_rt.isRerootable() ) {
1827                 return false;
1828             }
1829             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1830                 return false;
1831             }
1832             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1833             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1834             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1835             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1836                 return false;
1837             }
1838             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1839                 return false;
1840             }
1841             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1842                 return false;
1843             }
1844             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1845                 return false;
1846             }
1847             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1848                     .startsWith( "actgtgggggt" ) ) {
1849                 return false;
1850             }
1851             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1852                     .startsWith( "ctgtgatgcat" ) ) {
1853                 return false;
1854             }
1855             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1856             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1857             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1858             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1859             if ( phylogenies_1.length != 1 ) {
1860                 return false;
1861             }
1862             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1863             if ( !t3_rt.getName().equals( "t3" ) ) {
1864                 return false;
1865             }
1866             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1867                 return false;
1868             }
1869             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1870                 return false;
1871             }
1872             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1873                 return false;
1874             }
1875             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1876                 return false;
1877             }
1878             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1879                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1880                 return false;
1881             }
1882             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1883                 return false;
1884             }
1885             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1886                 return false;
1887             }
1888             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1889                     .equals( "UniProtKB" ) ) {
1890                 return false;
1891             }
1892             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1893                     .equals( "apoptosis" ) ) {
1894                 return false;
1895             }
1896             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1897                     .equals( "GO:0006915" ) ) {
1898                 return false;
1899             }
1900             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1901                     .equals( "UniProtKB" ) ) {
1902                 return false;
1903             }
1904             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1905                     .equals( "experimental" ) ) {
1906                 return false;
1907             }
1908             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1909                     .equals( "function" ) ) {
1910                 return false;
1911             }
1912             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1913                     .getValue() != 1 ) {
1914                 return false;
1915             }
1916             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1917                     .getType().equals( "ml" ) ) {
1918                 return false;
1919             }
1920             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1921                     .equals( "apoptosis" ) ) {
1922                 return false;
1923             }
1924             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1925                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1926                 return false;
1927             }
1928             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1929                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1930                 return false;
1931             }
1932             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1933                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1934                 return false;
1935             }
1936             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1937                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1938                 return false;
1939             }
1940             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1941                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1942                 return false;
1943             }
1944             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1945                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1946                 return false;
1947             }
1948             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1949                     .equals( "GO:0005829" ) ) {
1950                 return false;
1951             }
1952             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1953                     .equals( "intracellular organelle" ) ) {
1954                 return false;
1955             }
1956             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1957                 return false;
1958             }
1959             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1960                     .equals( "UniProt link" ) ) ) {
1961                 return false;
1962             }
1963             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1964                 return false;
1965             }
1966             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1967                 return false;
1968             }
1969             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1970                     .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." ) ) ) {
1971                 return false;
1972             }
1973             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1974                 return false;
1975             }
1976             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1977                 return false;
1978             }
1979             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1980                 return false;
1981             }
1982             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1983                 return false;
1984             }
1985             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1986                     .equals( "ncbi" ) ) {
1987                 return false;
1988             }
1989             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1990                 return false;
1991             }
1992             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1993                     .getName().equals( "B" ) ) {
1994                 return false;
1995             }
1996             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1997                     .getFrom() != 21 ) {
1998                 return false;
1999             }
2000             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
2001                 return false;
2002             }
2003             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2004                     .getLength() != 24 ) {
2005                 return false;
2006             }
2007             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2008                     .getConfidence() != 2144 ) {
2009                 return false;
2010             }
2011             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2012                     .equals( "pfam" ) ) {
2013                 return false;
2014             }
2015             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2016                 return false;
2017             }
2018             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2019                 return false;
2020             }
2021             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2022                 return false;
2023             }
2024             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2025                 return false;
2026             }
2027             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2028             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2029                 return false;
2030             }
2031             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2032                 return false;
2033             }
2034             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2035                 return false;
2036             }
2037             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2038                 return false;
2039             }
2040             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2041                 return false;
2042             }
2043             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2044                 return false;
2045             }
2046             if ( taxbb.getSynonyms().size() != 2 ) {
2047                 return false;
2048             }
2049             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2050                 return false;
2051             }
2052             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2053                 return false;
2054             }
2055             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2056                 return false;
2057             }
2058             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2059                 return false;
2060             }
2061             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2062                 return false;
2063             }
2064             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2065                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2066                 return false;
2067             }
2068             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2069                 return false;
2070             }
2071             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2072                 return false;
2073             }
2074             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2075                 return false;
2076             }
2077             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2078                 return false;
2079             }
2080             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2081                 return false;
2082             }
2083             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2084                 return false;
2085             }
2086             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2087                 return false;
2088             }
2089             //
2090             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2091                 return false;
2092             }
2093             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2094                     .equalsIgnoreCase( "435" ) ) {
2095                 return false;
2096             }
2097             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
2098                 return false;
2099             }
2100             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2101                     .equalsIgnoreCase( "443.7" ) ) {
2102                 return false;
2103             }
2104             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2105                 return false;
2106             }
2107             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2108                 return false;
2109             }
2110             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2111                     .equalsIgnoreCase( "433" ) ) {
2112                 return false;
2113             }
2114             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2115                     .getCrossReferences();
2116             if ( x.size() != 4 ) {
2117                 return false;
2118             }
2119             int c = 0;
2120             for( final Accession acc : x ) {
2121                 if ( c == 0 ) {
2122                     if ( !acc.getSource().equals( "KEGG" ) ) {
2123                         return false;
2124                     }
2125                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2126                         return false;
2127                     }
2128                 }
2129                 c++;
2130             }
2131         }
2132         catch ( final Exception e ) {
2133             e.printStackTrace( System.out );
2134             return false;
2135         }
2136         return true;
2137     }
2138
2139     private static boolean testBasicPhyloXMLparsingValidating() {
2140         try {
2141             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2142             PhyloXmlParser xml_parser = null;
2143             try {
2144                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2145             }
2146             catch ( final Exception e ) {
2147                 // Do nothing -- means were not running from jar.
2148             }
2149             if ( xml_parser == null ) {
2150                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2151                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2152                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2153                 }
2154                 else {
2155                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2156                 }
2157             }
2158             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
2159                                                               xml_parser );
2160             if ( xml_parser.getErrorCount() > 0 ) {
2161                 System.out.println( xml_parser.getErrorMessages().toString() );
2162                 return false;
2163             }
2164             if ( phylogenies_0.length != 4 ) {
2165                 return false;
2166             }
2167             final Phylogeny t1 = phylogenies_0[ 0 ];
2168             final Phylogeny t2 = phylogenies_0[ 1 ];
2169             final Phylogeny t3 = phylogenies_0[ 2 ];
2170             final Phylogeny t4 = phylogenies_0[ 3 ];
2171             if ( !t1.getName().equals( "t1" ) ) {
2172                 return false;
2173             }
2174             if ( !t2.getName().equals( "t2" ) ) {
2175                 return false;
2176             }
2177             if ( !t3.getName().equals( "t3" ) ) {
2178                 return false;
2179             }
2180             if ( !t4.getName().equals( "t4" ) ) {
2181                 return false;
2182             }
2183             if ( t1.getNumberOfExternalNodes() != 1 ) {
2184                 return false;
2185             }
2186             if ( t2.getNumberOfExternalNodes() != 2 ) {
2187                 return false;
2188             }
2189             if ( t3.getNumberOfExternalNodes() != 4 ) {
2190                 return false;
2191             }
2192             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2193             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
2194             if ( xml_parser.getErrorCount() > 0 ) {
2195                 System.out.println( "errors:" );
2196                 System.out.println( xml_parser.getErrorMessages().toString() );
2197                 return false;
2198             }
2199             if ( phylogenies_1.length != 4 ) {
2200                 return false;
2201             }
2202             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
2203                                                               xml_parser );
2204             if ( xml_parser.getErrorCount() > 0 ) {
2205                 System.out.println( "errors:" );
2206                 System.out.println( xml_parser.getErrorMessages().toString() );
2207                 return false;
2208             }
2209             if ( phylogenies_2.length != 1 ) {
2210                 return false;
2211             }
2212             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2213                 return false;
2214             }
2215             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
2216                                                               xml_parser );
2217             if ( xml_parser.getErrorCount() > 0 ) {
2218                 System.out.println( xml_parser.getErrorMessages().toString() );
2219                 return false;
2220             }
2221             if ( phylogenies_3.length != 2 ) {
2222                 return false;
2223             }
2224             final Phylogeny a = phylogenies_3[ 0 ];
2225             if ( !a.getName().equals( "tree 4" ) ) {
2226                 return false;
2227             }
2228             if ( a.getNumberOfExternalNodes() != 3 ) {
2229                 return false;
2230             }
2231             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2232                 return false;
2233             }
2234             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2235                 return false;
2236             }
2237             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
2238                                                               xml_parser );
2239             if ( xml_parser.getErrorCount() > 0 ) {
2240                 System.out.println( xml_parser.getErrorMessages().toString() );
2241                 return false;
2242             }
2243             if ( phylogenies_4.length != 1 ) {
2244                 return false;
2245             }
2246             final Phylogeny s = phylogenies_4[ 0 ];
2247             if ( s.getNumberOfExternalNodes() != 6 ) {
2248                 return false;
2249             }
2250             s.getNode( "first" );
2251             s.getNode( "<>" );
2252             s.getNode( "\"<a'b&c'd\">\"" );
2253             s.getNode( "'''\"" );
2254             s.getNode( "\"\"\"" );
2255             s.getNode( "dick & doof" );
2256         }
2257         catch ( final Exception e ) {
2258             e.printStackTrace( System.out );
2259             return false;
2260         }
2261         return true;
2262     }
2263
2264     private static boolean testBasicProtein() {
2265         try {
2266             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2267             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2268             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2269             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2270             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2271             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2272             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2273             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2274             p0.addProteinDomain( y );
2275             p0.addProteinDomain( e );
2276             p0.addProteinDomain( b );
2277             p0.addProteinDomain( c );
2278             p0.addProteinDomain( d );
2279             p0.addProteinDomain( a );
2280             p0.addProteinDomain( x );
2281             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2282                 return false;
2283             }
2284             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2285                 return false;
2286             }
2287             //
2288             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2289             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2290             aa0.addProteinDomain( a1 );
2291             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2292                 return false;
2293             }
2294             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2295                 return false;
2296             }
2297             //
2298             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2299             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2300             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2301             aa1.addProteinDomain( a11 );
2302             aa1.addProteinDomain( a12 );
2303             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2304                 return false;
2305             }
2306             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2307                 return false;
2308             }
2309             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2310             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2311                 return false;
2312             }
2313             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2314                 return false;
2315             }
2316             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2317                 return false;
2318             }
2319             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2320             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2321                 return false;
2322             }
2323             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2324                 return false;
2325             }
2326             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2327                 return false;
2328             }
2329             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2330                 return false;
2331             }
2332             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2333             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2334                 return false;
2335             }
2336             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2337                 return false;
2338             }
2339             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2340                 return false;
2341             }
2342             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2343                 return false;
2344             }
2345             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2346             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2347                 return false;
2348             }
2349             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2350                 return false;
2351             }
2352             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2353                 return false;
2354             }
2355             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2356                 return false;
2357             }
2358             //
2359             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2360             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2361             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2362             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2363             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2364             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2365             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2366             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2367             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2368             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2369             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2370             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2371             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2372             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2373             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2374             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2375             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2376             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2377             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2378             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2379             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2380             p00.addProteinDomain( y0 );
2381             p00.addProteinDomain( e0 );
2382             p00.addProteinDomain( b0 );
2383             p00.addProteinDomain( c0 );
2384             p00.addProteinDomain( d0 );
2385             p00.addProteinDomain( a0 );
2386             p00.addProteinDomain( x0 );
2387             p00.addProteinDomain( y1 );
2388             p00.addProteinDomain( y2 );
2389             p00.addProteinDomain( y3 );
2390             p00.addProteinDomain( e1 );
2391             p00.addProteinDomain( e2 );
2392             p00.addProteinDomain( e3 );
2393             p00.addProteinDomain( e4 );
2394             p00.addProteinDomain( e5 );
2395             p00.addProteinDomain( z0 );
2396             p00.addProteinDomain( z1 );
2397             p00.addProteinDomain( z2 );
2398             p00.addProteinDomain( zz0 );
2399             p00.addProteinDomain( zz1 );
2400             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2401                 return false;
2402             }
2403             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2404                 return false;
2405             }
2406             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2407                 return false;
2408             }
2409             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2410                 return false;
2411             }
2412             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" ) ) {
2413                 return false;
2414             }
2415             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2416             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2417             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2418             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2419             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2420             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2421             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2422             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2423             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2424             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2425             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2426             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2427             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2428             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2429             p.addProteinDomain( B15 );
2430             p.addProteinDomain( C50 );
2431             p.addProteinDomain( A60 );
2432             p.addProteinDomain( A30 );
2433             p.addProteinDomain( C70 );
2434             p.addProteinDomain( B35 );
2435             p.addProteinDomain( B40 );
2436             p.addProteinDomain( A0 );
2437             p.addProteinDomain( A10 );
2438             p.addProteinDomain( A20 );
2439             p.addProteinDomain( B25 );
2440             p.addProteinDomain( D80 );
2441             List<String> domains_ids = new ArrayList<String>();
2442             domains_ids.add( "A" );
2443             domains_ids.add( "B" );
2444             domains_ids.add( "C" );
2445             if ( !p.contains( domains_ids, false ) ) {
2446                 return false;
2447             }
2448             if ( !p.contains( domains_ids, true ) ) {
2449                 return false;
2450             }
2451             domains_ids.add( "X" );
2452             if ( p.contains( domains_ids, false ) ) {
2453                 return false;
2454             }
2455             if ( p.contains( domains_ids, true ) ) {
2456                 return false;
2457             }
2458             domains_ids = new ArrayList<String>();
2459             domains_ids.add( "A" );
2460             domains_ids.add( "C" );
2461             domains_ids.add( "D" );
2462             if ( !p.contains( domains_ids, false ) ) {
2463                 return false;
2464             }
2465             if ( !p.contains( domains_ids, true ) ) {
2466                 return false;
2467             }
2468             domains_ids = new ArrayList<String>();
2469             domains_ids.add( "A" );
2470             domains_ids.add( "D" );
2471             domains_ids.add( "C" );
2472             if ( !p.contains( domains_ids, false ) ) {
2473                 return false;
2474             }
2475             if ( p.contains( domains_ids, true ) ) {
2476                 return false;
2477             }
2478             domains_ids = new ArrayList<String>();
2479             domains_ids.add( "A" );
2480             domains_ids.add( "A" );
2481             domains_ids.add( "B" );
2482             if ( !p.contains( domains_ids, false ) ) {
2483                 return false;
2484             }
2485             if ( !p.contains( domains_ids, true ) ) {
2486                 return false;
2487             }
2488             domains_ids = new ArrayList<String>();
2489             domains_ids.add( "A" );
2490             domains_ids.add( "A" );
2491             domains_ids.add( "A" );
2492             domains_ids.add( "B" );
2493             domains_ids.add( "B" );
2494             if ( !p.contains( domains_ids, false ) ) {
2495                 return false;
2496             }
2497             if ( !p.contains( domains_ids, true ) ) {
2498                 return false;
2499             }
2500             domains_ids = new ArrayList<String>();
2501             domains_ids.add( "A" );
2502             domains_ids.add( "A" );
2503             domains_ids.add( "B" );
2504             domains_ids.add( "A" );
2505             domains_ids.add( "B" );
2506             domains_ids.add( "B" );
2507             domains_ids.add( "A" );
2508             domains_ids.add( "B" );
2509             domains_ids.add( "C" );
2510             domains_ids.add( "A" );
2511             domains_ids.add( "C" );
2512             domains_ids.add( "D" );
2513             if ( !p.contains( domains_ids, false ) ) {
2514                 return false;
2515             }
2516             if ( p.contains( domains_ids, true ) ) {
2517                 return false;
2518             }
2519         }
2520         catch ( final Exception e ) {
2521             e.printStackTrace( System.out );
2522             return false;
2523         }
2524         return true;
2525     }
2526
2527     private static boolean testBasicTable() {
2528         try {
2529             final BasicTable<String> t0 = new BasicTable<String>();
2530             if ( t0.getNumberOfColumns() != 0 ) {
2531                 return false;
2532             }
2533             if ( t0.getNumberOfRows() != 0 ) {
2534                 return false;
2535             }
2536             t0.setValue( 3, 2, "23" );
2537             t0.setValue( 10, 1, "error" );
2538             t0.setValue( 10, 1, "110" );
2539             t0.setValue( 9, 1, "19" );
2540             t0.setValue( 1, 10, "101" );
2541             t0.setValue( 10, 10, "1010" );
2542             t0.setValue( 100, 10, "10100" );
2543             t0.setValue( 0, 0, "00" );
2544             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2545                 return false;
2546             }
2547             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2548                 return false;
2549             }
2550             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2551                 return false;
2552             }
2553             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2554                 return false;
2555             }
2556             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2557                 return false;
2558             }
2559             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2560                 return false;
2561             }
2562             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2563                 return false;
2564             }
2565             if ( t0.getNumberOfColumns() != 101 ) {
2566                 return false;
2567             }
2568             if ( t0.getNumberOfRows() != 11 ) {
2569                 return false;
2570             }
2571             if ( t0.getValueAsString( 49, 4 ) != null ) {
2572                 return false;
2573             }
2574             final String l = ForesterUtil.getLineSeparator();
2575             final StringBuffer source = new StringBuffer();
2576             source.append( "" + l );
2577             source.append( "# 1 1 1 1 1 1 1 1" + l );
2578             source.append( " 00 01 02 03" + l );
2579             source.append( "   10 11 12 13  " + l );
2580             source.append( "20 21 22 23 " + l );
2581             source.append( "    30  31    32 33" + l );
2582             source.append( "40 41 42 43" + l );
2583             source.append( "  # 1 1 1 1 1 " + l );
2584             source.append( "50 51 52 53 54" + l );
2585             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2586             if ( t1.getNumberOfColumns() != 5 ) {
2587                 return false;
2588             }
2589             if ( t1.getNumberOfRows() != 6 ) {
2590                 return false;
2591             }
2592             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2593                 return false;
2594             }
2595             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2596                 return false;
2597             }
2598             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2599                 return false;
2600             }
2601             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2602                 return false;
2603             }
2604             final StringBuffer source1 = new StringBuffer();
2605             source1.append( "" + l );
2606             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2607             source1.append( " 00; 01 ;02;03" + l );
2608             source1.append( "   10; 11; 12; 13  " + l );
2609             source1.append( "20; 21; 22; 23 " + l );
2610             source1.append( "    30;  31;    32; 33" + l );
2611             source1.append( "40;41;42;43" + l );
2612             source1.append( "  # 1 1 1 1 1 " + l );
2613             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2614             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2615             if ( t2.getNumberOfColumns() != 5 ) {
2616                 return false;
2617             }
2618             if ( t2.getNumberOfRows() != 6 ) {
2619                 return false;
2620             }
2621             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2622                 return false;
2623             }
2624             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2625                 return false;
2626             }
2627             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2628                 return false;
2629             }
2630             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2631                 return false;
2632             }
2633             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2634                 return false;
2635             }
2636             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2637                 return false;
2638             }
2639             final StringBuffer source2 = new StringBuffer();
2640             source2.append( "" + l );
2641             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2642             source2.append( " 00; 01 ;02;03" + l );
2643             source2.append( "   10; 11; 12; 13  " + l );
2644             source2.append( "20; 21; 22; 23 " + l );
2645             source2.append( "                     " + l );
2646             source2.append( "    30;  31;    32; 33" + l );
2647             source2.append( "40;41;42;43" + l );
2648             source2.append( "  comment: 1 1 1 1 1 " + l );
2649             source2.append( ";;;50  ;   52; 53;;54   " + l );
2650             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2651                                                                         ';',
2652                                                                         false,
2653                                                                         false,
2654                                                                         "comment:",
2655                                                                         false );
2656             if ( tl.size() != 2 ) {
2657                 return false;
2658             }
2659             final BasicTable<String> t3 = tl.get( 0 );
2660             final BasicTable<String> t4 = tl.get( 1 );
2661             if ( t3.getNumberOfColumns() != 4 ) {
2662                 return false;
2663             }
2664             if ( t3.getNumberOfRows() != 3 ) {
2665                 return false;
2666             }
2667             if ( t4.getNumberOfColumns() != 4 ) {
2668                 return false;
2669             }
2670             if ( t4.getNumberOfRows() != 3 ) {
2671                 return false;
2672             }
2673             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2674                 return false;
2675             }
2676             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2677                 return false;
2678             }
2679         }
2680         catch ( final Exception e ) {
2681             e.printStackTrace( System.out );
2682             return false;
2683         }
2684         return true;
2685     }
2686
2687     private static boolean testBasicTolXMLparsing() {
2688         try {
2689             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2690             final TolParser parser = new TolParser();
2691             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2692             if ( parser.getErrorCount() > 0 ) {
2693                 System.out.println( parser.getErrorMessages().toString() );
2694                 return false;
2695             }
2696             if ( phylogenies_0.length != 1 ) {
2697                 return false;
2698             }
2699             final Phylogeny t1 = phylogenies_0[ 0 ];
2700             if ( t1.getNumberOfExternalNodes() != 5 ) {
2701                 return false;
2702             }
2703             if ( !t1.isRooted() ) {
2704                 return false;
2705             }
2706             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2707                 return false;
2708             }
2709             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2710                 return false;
2711             }
2712             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2713                 return false;
2714             }
2715             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2716                 return false;
2717             }
2718             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2719             if ( parser.getErrorCount() > 0 ) {
2720                 System.out.println( parser.getErrorMessages().toString() );
2721                 return false;
2722             }
2723             if ( phylogenies_1.length != 1 ) {
2724                 return false;
2725             }
2726             final Phylogeny t2 = phylogenies_1[ 0 ];
2727             if ( t2.getNumberOfExternalNodes() != 664 ) {
2728                 return false;
2729             }
2730             if ( !t2.isRooted() ) {
2731                 return false;
2732             }
2733             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2734                 return false;
2735             }
2736             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2737                 return false;
2738             }
2739             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2740                 return false;
2741             }
2742             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2743                 return false;
2744             }
2745             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2746                 return false;
2747             }
2748             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2749                     .equals( "Aquifex" ) ) {
2750                 return false;
2751             }
2752             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2753             if ( parser.getErrorCount() > 0 ) {
2754                 System.out.println( parser.getErrorMessages().toString() );
2755                 return false;
2756             }
2757             if ( phylogenies_2.length != 1 ) {
2758                 return false;
2759             }
2760             final Phylogeny t3 = phylogenies_2[ 0 ];
2761             if ( t3.getNumberOfExternalNodes() != 184 ) {
2762                 return false;
2763             }
2764             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2765                 return false;
2766             }
2767             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2768                 return false;
2769             }
2770             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2771                 return false;
2772             }
2773             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2774             if ( parser.getErrorCount() > 0 ) {
2775                 System.out.println( parser.getErrorMessages().toString() );
2776                 return false;
2777             }
2778             if ( phylogenies_3.length != 1 ) {
2779                 return false;
2780             }
2781             final Phylogeny t4 = phylogenies_3[ 0 ];
2782             if ( t4.getNumberOfExternalNodes() != 1 ) {
2783                 return false;
2784             }
2785             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2786                 return false;
2787             }
2788             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2789                 return false;
2790             }
2791             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2792                 return false;
2793             }
2794             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2795             if ( parser.getErrorCount() > 0 ) {
2796                 System.out.println( parser.getErrorMessages().toString() );
2797                 return false;
2798             }
2799             if ( phylogenies_4.length != 1 ) {
2800                 return false;
2801             }
2802             final Phylogeny t5 = phylogenies_4[ 0 ];
2803             if ( t5.getNumberOfExternalNodes() != 13 ) {
2804                 return false;
2805             }
2806             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2807                 return false;
2808             }
2809             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2810                 return false;
2811             }
2812             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2813                 return false;
2814             }
2815         }
2816         catch ( final Exception e ) {
2817             e.printStackTrace( System.out );
2818             return false;
2819         }
2820         return true;
2821     }
2822
2823     private static boolean testBasicTreeMethods() {
2824         try {
2825             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2826             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2827             if ( t2.getNumberOfExternalNodes() != 4 ) {
2828                 return false;
2829             }
2830             if ( t2.getHeight() != 8.5 ) {
2831                 return false;
2832             }
2833             if ( !t2.isCompletelyBinary() ) {
2834                 return false;
2835             }
2836             if ( t2.isEmpty() ) {
2837                 return false;
2838             }
2839             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2840             if ( t3.getNumberOfExternalNodes() != 5 ) {
2841                 return false;
2842             }
2843             if ( t3.getHeight() != 11 ) {
2844                 return false;
2845             }
2846             if ( t3.isCompletelyBinary() ) {
2847                 return false;
2848             }
2849             final PhylogenyNode n = t3.getNode( "ABC" );
2850             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 ];
2851             if ( t4.getNumberOfExternalNodes() != 9 ) {
2852                 return false;
2853             }
2854             if ( t4.getHeight() != 11 ) {
2855                 return false;
2856             }
2857             if ( t4.isCompletelyBinary() ) {
2858                 return false;
2859             }
2860             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)" );
2861             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2862             if ( t5.getNumberOfExternalNodes() != 8 ) {
2863                 return false;
2864             }
2865             if ( t5.getHeight() != 15 ) {
2866                 return false;
2867             }
2868             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)" );
2869             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2870             if ( t6.getHeight() != 15 ) {
2871                 return false;
2872             }
2873             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)" );
2874             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2875             if ( t7.getHeight() != 15 ) {
2876                 return false;
2877             }
2878             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)" );
2879             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2880             if ( t8.getNumberOfExternalNodes() != 10 ) {
2881                 return false;
2882             }
2883             if ( t8.getHeight() != 15 ) {
2884                 return false;
2885             }
2886             final char[] a9 = new char[] { 'a' };
2887             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2888             if ( t9.getHeight() != 0 ) {
2889                 return false;
2890             }
2891             final char[] a10 = new char[] { 'a', ':', '6' };
2892             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2893             if ( t10.getHeight() != 6 ) {
2894                 return false;
2895             }
2896         }
2897         catch ( final Exception e ) {
2898             e.printStackTrace( System.out );
2899             return false;
2900         }
2901         return true;
2902     }
2903
2904     private static boolean testConfidenceAssessor() {
2905         try {
2906             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2907             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2908             final Phylogeny[] ev0 = factory
2909                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2910                              new NHXParser() );
2911             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2912             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2913                 return false;
2914             }
2915             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2916                 return false;
2917             }
2918             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2919             final Phylogeny[] ev1 = factory
2920                     .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)));",
2921                              new NHXParser() );
2922             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2923             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2924                 return false;
2925             }
2926             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2927                 return false;
2928             }
2929             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2930             final Phylogeny[] ev_b = factory
2931                     .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",
2932                              new NHXParser() );
2933             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2934             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2935                 return false;
2936             }
2937             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2938                 return false;
2939             }
2940             //
2941             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2942             final Phylogeny[] ev1x = factory
2943                     .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)));",
2944                              new NHXParser() );
2945             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2946             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2947                 return false;
2948             }
2949             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2950                 return false;
2951             }
2952             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2953             final Phylogeny[] ev_bx = factory
2954                     .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",
2955                              new NHXParser() );
2956             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2957             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2958                 return false;
2959             }
2960             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2961                 return false;
2962             }
2963             //
2964             final Phylogeny[] t2 = factory
2965                     .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);",
2966                              new NHXParser() );
2967             final Phylogeny[] ev2 = factory
2968                     .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);",
2969                              new NHXParser() );
2970             for( final Phylogeny target : t2 ) {
2971                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2972             }
2973             //
2974             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2975                                                  new NHXParser() )[ 0 ];
2976             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2977             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2978             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2979                 return false;
2980             }
2981             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2982                 return false;
2983             }
2984             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2985                 return false;
2986             }
2987         }
2988         catch ( final Exception e ) {
2989             e.printStackTrace();
2990             return false;
2991         }
2992         return true;
2993     }
2994
2995     private static boolean testCopyOfNodeData() {
2996         try {
2997             final PhylogenyNode n1 = PhylogenyNode
2998                     .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]" );
2999             final PhylogenyNode n2 = n1.copyNodeData();
3000             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
3001                 return false;
3002             }
3003         }
3004         catch ( final Exception e ) {
3005             e.printStackTrace();
3006             return false;
3007         }
3008         return true;
3009     }
3010
3011     private static boolean testCreateBalancedPhylogeny() {
3012         try {
3013             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3014             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3015                 return false;
3016             }
3017             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3018                 return false;
3019             }
3020             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3021             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3022                 return false;
3023             }
3024             if ( p1.getNumberOfExternalNodes() != 100 ) {
3025                 return false;
3026             }
3027         }
3028         catch ( final Exception e ) {
3029             e.printStackTrace();
3030             return false;
3031         }
3032         return true;
3033     }
3034
3035     private static boolean testCreateUriForSeqWeb() {
3036         try {
3037             final PhylogenyNode n = new PhylogenyNode();
3038             n.setName( "tr|B3RJ64" );
3039             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3040                 return false;
3041             }
3042             n.setName( "B0LM41_HUMAN" );
3043             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3044                 return false;
3045             }
3046             n.setName( "NP_001025424" );
3047             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3048                 return false;
3049             }
3050             n.setName( "_NM_001030253-" );
3051             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3052                 return false;
3053             }
3054             n.setName( "XM_002122186" );
3055             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3056                 return false;
3057             }
3058             n.setName( "dgh_AAA34956_gdg" );
3059             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3060                 return false;
3061             }
3062             n.setName( "AAA34956" );
3063             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3064                 return false;
3065             }
3066             n.setName( "GI:394892" );
3067             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3068                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3069                 return false;
3070             }
3071             n.setName( "gi_394892" );
3072             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3073                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3074                 return false;
3075             }
3076             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3077             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3078                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3079                 return false;
3080             }
3081             n.setName( "P12345" );
3082             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3083                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3084                 return false;
3085             }
3086             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3087             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3088                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3089                 return false;
3090             }
3091         }
3092         catch ( final Exception e ) {
3093             e.printStackTrace( System.out );
3094             return false;
3095         }
3096         return true;
3097     }
3098
3099     private static boolean testDataObjects() {
3100         try {
3101             final Confidence s0 = new Confidence();
3102             final Confidence s1 = new Confidence();
3103             if ( !s0.isEqual( s1 ) ) {
3104                 return false;
3105             }
3106             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3107             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3108             if ( s2.isEqual( s1 ) ) {
3109                 return false;
3110             }
3111             if ( !s2.isEqual( s3 ) ) {
3112                 return false;
3113             }
3114             final Confidence s4 = ( Confidence ) s3.copy();
3115             if ( !s4.isEqual( s3 ) ) {
3116                 return false;
3117             }
3118             s3.asSimpleText();
3119             s3.asText();
3120             // Taxonomy
3121             // ----------
3122             final Taxonomy t1 = new Taxonomy();
3123             final Taxonomy t2 = new Taxonomy();
3124             final Taxonomy t3 = new Taxonomy();
3125             final Taxonomy t4 = new Taxonomy();
3126             final Taxonomy t5 = new Taxonomy();
3127             t1.setIdentifier( new Identifier( "ecoli" ) );
3128             t1.setTaxonomyCode( "ECOLI" );
3129             t1.setScientificName( "E. coli" );
3130             t1.setCommonName( "coli" );
3131             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3132             if ( !t1.isEqual( t0 ) ) {
3133                 return false;
3134             }
3135             t2.setIdentifier( new Identifier( "ecoli" ) );
3136             t2.setTaxonomyCode( "OTHER" );
3137             t2.setScientificName( "what" );
3138             t2.setCommonName( "something" );
3139             if ( !t1.isEqual( t2 ) ) {
3140                 return false;
3141             }
3142             t2.setIdentifier( new Identifier( "nemve" ) );
3143             if ( t1.isEqual( t2 ) ) {
3144                 return false;
3145             }
3146             t1.setIdentifier( null );
3147             t3.setTaxonomyCode( "ECOLI" );
3148             t3.setScientificName( "what" );
3149             t3.setCommonName( "something" );
3150             if ( !t1.isEqual( t3 ) ) {
3151                 return false;
3152             }
3153             t1.setIdentifier( null );
3154             t1.setTaxonomyCode( "" );
3155             t4.setScientificName( "E. ColI" );
3156             t4.setCommonName( "something" );
3157             if ( !t1.isEqual( t4 ) ) {
3158                 return false;
3159             }
3160             t4.setScientificName( "B. subtilis" );
3161             t4.setCommonName( "something" );
3162             if ( t1.isEqual( t4 ) ) {
3163                 return false;
3164             }
3165             t1.setIdentifier( null );
3166             t1.setTaxonomyCode( "" );
3167             t1.setScientificName( "" );
3168             t5.setCommonName( "COLI" );
3169             if ( !t1.isEqual( t5 ) ) {
3170                 return false;
3171             }
3172             t5.setCommonName( "vibrio" );
3173             if ( t1.isEqual( t5 ) ) {
3174                 return false;
3175             }
3176             // Identifier
3177             // ----------
3178             final Identifier id0 = new Identifier( "123", "pfam" );
3179             final Identifier id1 = ( Identifier ) id0.copy();
3180             if ( !id1.isEqual( id1 ) ) {
3181                 return false;
3182             }
3183             if ( !id1.isEqual( id0 ) ) {
3184                 return false;
3185             }
3186             if ( !id0.isEqual( id1 ) ) {
3187                 return false;
3188             }
3189             id1.asSimpleText();
3190             id1.asText();
3191             // ProteinDomain
3192             // ---------------
3193             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3194             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3195             if ( !pd1.isEqual( pd1 ) ) {
3196                 return false;
3197             }
3198             if ( !pd1.isEqual( pd0 ) ) {
3199                 return false;
3200             }
3201             pd1.asSimpleText();
3202             pd1.asText();
3203             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3204             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3205             if ( !pd3.isEqual( pd3 ) ) {
3206                 return false;
3207             }
3208             if ( !pd2.isEqual( pd3 ) ) {
3209                 return false;
3210             }
3211             if ( !pd0.isEqual( pd3 ) ) {
3212                 return false;
3213             }
3214             pd3.asSimpleText();
3215             pd3.asText();
3216             // DomainArchitecture
3217             // ------------------
3218             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3219             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3220             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3221             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3222             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3223             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3224             domains0.add( d2 );
3225             domains0.add( d0 );
3226             domains0.add( d3 );
3227             domains0.add( d1 );
3228             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3229             if ( ds0.getNumberOfDomains() != 4 ) {
3230                 return false;
3231             }
3232             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3233             if ( !ds0.isEqual( ds0 ) ) {
3234                 return false;
3235             }
3236             if ( !ds0.isEqual( ds1 ) ) {
3237                 return false;
3238             }
3239             if ( ds1.getNumberOfDomains() != 4 ) {
3240                 return false;
3241             }
3242             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3243             domains1.add( d1 );
3244             domains1.add( d2 );
3245             domains1.add( d4 );
3246             domains1.add( d0 );
3247             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3248             if ( ds0.isEqual( ds2 ) ) {
3249                 return false;
3250             }
3251             ds1.asSimpleText();
3252             ds1.asText();
3253             ds1.toNHX();
3254             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3255             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3256                 System.out.println( ds3.toNHX() );
3257                 return false;
3258             }
3259             if ( ds3.getNumberOfDomains() != 3 ) {
3260                 return false;
3261             }
3262             // Event
3263             // -----
3264             final Event e1 = new Event( Event.EventType.fusion );
3265             if ( e1.isDuplication() ) {
3266                 return false;
3267             }
3268             if ( !e1.isFusion() ) {
3269                 return false;
3270             }
3271             if ( !e1.asText().toString().equals( "fusion" ) ) {
3272                 return false;
3273             }
3274             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3275                 return false;
3276             }
3277             final Event e11 = new Event( Event.EventType.fusion );
3278             if ( !e11.isEqual( e1 ) ) {
3279                 return false;
3280             }
3281             if ( !e11.toNHX().toString().equals( "" ) ) {
3282                 return false;
3283             }
3284             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3285             if ( e2.isDuplication() ) {
3286                 return false;
3287             }
3288             if ( !e2.isSpeciationOrDuplication() ) {
3289                 return false;
3290             }
3291             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3292                 return false;
3293             }
3294             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3295                 return false;
3296             }
3297             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3298                 return false;
3299             }
3300             if ( e11.isEqual( e2 ) ) {
3301                 return false;
3302             }
3303             final Event e2c = ( Event ) e2.copy();
3304             if ( !e2c.isEqual( e2 ) ) {
3305                 return false;
3306             }
3307             Event e3 = new Event( 1, 2, 3 );
3308             if ( e3.isDuplication() ) {
3309                 return false;
3310             }
3311             if ( e3.isSpeciation() ) {
3312                 return false;
3313             }
3314             if ( e3.isGeneLoss() ) {
3315                 return false;
3316             }
3317             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3318                 return false;
3319             }
3320             final Event e3c = ( Event ) e3.copy();
3321             final Event e3cc = ( Event ) e3c.copy();
3322             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3323                 return false;
3324             }
3325             e3 = null;
3326             if ( !e3c.isEqual( e3cc ) ) {
3327                 return false;
3328             }
3329             Event e4 = new Event( 1, 2, 3 );
3330             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3331                 return false;
3332             }
3333             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3334                 return false;
3335             }
3336             final Event e4c = ( Event ) e4.copy();
3337             e4 = null;
3338             final Event e4cc = ( Event ) e4c.copy();
3339             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3340                 return false;
3341             }
3342             if ( !e4c.isEqual( e4cc ) ) {
3343                 return false;
3344             }
3345             final Event e5 = new Event();
3346             if ( !e5.isUnassigned() ) {
3347                 return false;
3348             }
3349             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3350                 return false;
3351             }
3352             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3353                 return false;
3354             }
3355             final Event e6 = new Event( 1, 0, 0 );
3356             if ( !e6.asText().toString().equals( "duplication" ) ) {
3357                 return false;
3358             }
3359             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3360                 return false;
3361             }
3362             final Event e7 = new Event( 0, 1, 0 );
3363             if ( !e7.asText().toString().equals( "speciation" ) ) {
3364                 return false;
3365             }
3366             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3367                 return false;
3368             }
3369             final Event e8 = new Event( 0, 0, 1 );
3370             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3371                 return false;
3372             }
3373             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3374                 return false;
3375             }
3376         }
3377         catch ( final Exception e ) {
3378             e.printStackTrace( System.out );
3379             return false;
3380         }
3381         return true;
3382     }
3383
3384     private static boolean testDeletionOfExternalNodes() {
3385         try {
3386             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3387             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3388             final PhylogenyWriter w = new PhylogenyWriter();
3389             if ( t0.isEmpty() ) {
3390                 return false;
3391             }
3392             if ( t0.getNumberOfExternalNodes() != 1 ) {
3393                 return false;
3394             }
3395             t0.deleteSubtree( t0.getNode( "A" ), false );
3396             if ( t0.getNumberOfExternalNodes() != 0 ) {
3397                 return false;
3398             }
3399             if ( !t0.isEmpty() ) {
3400                 return false;
3401             }
3402             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3403             if ( t1.getNumberOfExternalNodes() != 2 ) {
3404                 return false;
3405             }
3406             t1.deleteSubtree( t1.getNode( "A" ), false );
3407             if ( t1.getNumberOfExternalNodes() != 1 ) {
3408                 return false;
3409             }
3410             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3411                 return false;
3412             }
3413             t1.deleteSubtree( t1.getNode( "B" ), false );
3414             if ( t1.getNumberOfExternalNodes() != 1 ) {
3415                 return false;
3416             }
3417             t1.deleteSubtree( t1.getNode( "r" ), false );
3418             if ( !t1.isEmpty() ) {
3419                 return false;
3420             }
3421             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3422             if ( t2.getNumberOfExternalNodes() != 3 ) {
3423                 return false;
3424             }
3425             t2.deleteSubtree( t2.getNode( "B" ), false );
3426             if ( t2.getNumberOfExternalNodes() != 2 ) {
3427                 return false;
3428             }
3429             t2.toNewHampshireX();
3430             PhylogenyNode n = t2.getNode( "A" );
3431             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3432                 return false;
3433             }
3434             t2.deleteSubtree( t2.getNode( "A" ), false );
3435             if ( t2.getNumberOfExternalNodes() != 2 ) {
3436                 return false;
3437             }
3438             t2.deleteSubtree( t2.getNode( "C" ), true );
3439             if ( t2.getNumberOfExternalNodes() != 1 ) {
3440                 return false;
3441             }
3442             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3443             if ( t3.getNumberOfExternalNodes() != 4 ) {
3444                 return false;
3445             }
3446             t3.deleteSubtree( t3.getNode( "B" ), true );
3447             if ( t3.getNumberOfExternalNodes() != 3 ) {
3448                 return false;
3449             }
3450             n = t3.getNode( "A" );
3451             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3452                 return false;
3453             }
3454             n = n.getNextExternalNode();
3455             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3456                 return false;
3457             }
3458             t3.deleteSubtree( t3.getNode( "A" ), true );
3459             if ( t3.getNumberOfExternalNodes() != 2 ) {
3460                 return false;
3461             }
3462             n = t3.getNode( "C" );
3463             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3464                 return false;
3465             }
3466             t3.deleteSubtree( t3.getNode( "C" ), true );
3467             if ( t3.getNumberOfExternalNodes() != 1 ) {
3468                 return false;
3469             }
3470             t3.deleteSubtree( t3.getNode( "D" ), true );
3471             if ( t3.getNumberOfExternalNodes() != 0 ) {
3472                 return false;
3473             }
3474             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3475             if ( t4.getNumberOfExternalNodes() != 6 ) {
3476                 return false;
3477             }
3478             t4.deleteSubtree( t4.getNode( "B2" ), true );
3479             if ( t4.getNumberOfExternalNodes() != 5 ) {
3480                 return false;
3481             }
3482             String s = w.toNewHampshire( t4, true ).toString();
3483             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3484                 return false;
3485             }
3486             t4.deleteSubtree( t4.getNode( "B11" ), true );
3487             if ( t4.getNumberOfExternalNodes() != 4 ) {
3488                 return false;
3489             }
3490             t4.deleteSubtree( t4.getNode( "C" ), true );
3491             if ( t4.getNumberOfExternalNodes() != 3 ) {
3492                 return false;
3493             }
3494             n = t4.getNode( "A" );
3495             n = n.getNextExternalNode();
3496             if ( !n.getName().equals( "B12" ) ) {
3497                 return false;
3498             }
3499             n = n.getNextExternalNode();
3500             if ( !n.getName().equals( "D" ) ) {
3501                 return false;
3502             }
3503             s = w.toNewHampshire( t4, true ).toString();
3504             if ( !s.equals( "((A,B12),D);" ) ) {
3505                 return false;
3506             }
3507             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3508             t5.deleteSubtree( t5.getNode( "A" ), true );
3509             if ( t5.getNumberOfExternalNodes() != 5 ) {
3510                 return false;
3511             }
3512             s = w.toNewHampshire( t5, true ).toString();
3513             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3514                 return false;
3515             }
3516             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3517             t6.deleteSubtree( t6.getNode( "B11" ), true );
3518             if ( t6.getNumberOfExternalNodes() != 5 ) {
3519                 return false;
3520             }
3521             s = w.toNewHampshire( t6, false ).toString();
3522             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3523                 return false;
3524             }
3525             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3526             t7.deleteSubtree( t7.getNode( "B12" ), true );
3527             if ( t7.getNumberOfExternalNodes() != 5 ) {
3528                 return false;
3529             }
3530             s = w.toNewHampshire( t7, true ).toString();
3531             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3532                 return false;
3533             }
3534             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3535             t8.deleteSubtree( t8.getNode( "B2" ), true );
3536             if ( t8.getNumberOfExternalNodes() != 5 ) {
3537                 return false;
3538             }
3539             s = w.toNewHampshire( t8, false ).toString();
3540             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3541                 return false;
3542             }
3543             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3544             t9.deleteSubtree( t9.getNode( "C" ), true );
3545             if ( t9.getNumberOfExternalNodes() != 5 ) {
3546                 return false;
3547             }
3548             s = w.toNewHampshire( t9, true ).toString();
3549             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3550                 return false;
3551             }
3552             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3553             t10.deleteSubtree( t10.getNode( "D" ), true );
3554             if ( t10.getNumberOfExternalNodes() != 5 ) {
3555                 return false;
3556             }
3557             s = w.toNewHampshire( t10, true ).toString();
3558             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3559                 return false;
3560             }
3561             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3562             t11.deleteSubtree( t11.getNode( "A" ), true );
3563             if ( t11.getNumberOfExternalNodes() != 2 ) {
3564                 return false;
3565             }
3566             s = w.toNewHampshire( t11, true ).toString();
3567             if ( !s.equals( "(B,C);" ) ) {
3568                 return false;
3569             }
3570             t11.deleteSubtree( t11.getNode( "C" ), true );
3571             if ( t11.getNumberOfExternalNodes() != 1 ) {
3572                 return false;
3573             }
3574             s = w.toNewHampshire( t11, false ).toString();
3575             if ( !s.equals( "B;" ) ) {
3576                 return false;
3577             }
3578             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3579             t12.deleteSubtree( t12.getNode( "B2" ), true );
3580             if ( t12.getNumberOfExternalNodes() != 8 ) {
3581                 return false;
3582             }
3583             s = w.toNewHampshire( t12, true ).toString();
3584             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3585                 return false;
3586             }
3587             t12.deleteSubtree( t12.getNode( "B3" ), true );
3588             if ( t12.getNumberOfExternalNodes() != 7 ) {
3589                 return false;
3590             }
3591             s = w.toNewHampshire( t12, true ).toString();
3592             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3593                 return false;
3594             }
3595             t12.deleteSubtree( t12.getNode( "C3" ), true );
3596             if ( t12.getNumberOfExternalNodes() != 6 ) {
3597                 return false;
3598             }
3599             s = w.toNewHampshire( t12, true ).toString();
3600             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3601                 return false;
3602             }
3603             t12.deleteSubtree( t12.getNode( "A1" ), true );
3604             if ( t12.getNumberOfExternalNodes() != 5 ) {
3605                 return false;
3606             }
3607             s = w.toNewHampshire( t12, true ).toString();
3608             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3609                 return false;
3610             }
3611             t12.deleteSubtree( t12.getNode( "B1" ), true );
3612             if ( t12.getNumberOfExternalNodes() != 4 ) {
3613                 return false;
3614             }
3615             s = w.toNewHampshire( t12, true ).toString();
3616             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3617                 return false;
3618             }
3619             t12.deleteSubtree( t12.getNode( "A3" ), true );
3620             if ( t12.getNumberOfExternalNodes() != 3 ) {
3621                 return false;
3622             }
3623             s = w.toNewHampshire( t12, true ).toString();
3624             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3625                 return false;
3626             }
3627             t12.deleteSubtree( t12.getNode( "A2" ), true );
3628             if ( t12.getNumberOfExternalNodes() != 2 ) {
3629                 return false;
3630             }
3631             s = w.toNewHampshire( t12, true ).toString();
3632             if ( !s.equals( "(C1,C2);" ) ) {
3633                 return false;
3634             }
3635             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3636             t13.deleteSubtree( t13.getNode( "D" ), true );
3637             if ( t13.getNumberOfExternalNodes() != 4 ) {
3638                 return false;
3639             }
3640             s = w.toNewHampshire( t13, true ).toString();
3641             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3642                 return false;
3643             }
3644             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3645             t14.deleteSubtree( t14.getNode( "E" ), true );
3646             if ( t14.getNumberOfExternalNodes() != 5 ) {
3647                 return false;
3648             }
3649             s = w.toNewHampshire( t14, true ).toString();
3650             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3651                 return false;
3652             }
3653             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3654             t15.deleteSubtree( t15.getNode( "B2" ), true );
3655             if ( t15.getNumberOfExternalNodes() != 11 ) {
3656                 return false;
3657             }
3658             t15.deleteSubtree( t15.getNode( "B1" ), true );
3659             if ( t15.getNumberOfExternalNodes() != 10 ) {
3660                 return false;
3661             }
3662             t15.deleteSubtree( t15.getNode( "B3" ), true );
3663             if ( t15.getNumberOfExternalNodes() != 9 ) {
3664                 return false;
3665             }
3666             t15.deleteSubtree( t15.getNode( "B4" ), true );
3667             if ( t15.getNumberOfExternalNodes() != 8 ) {
3668                 return false;
3669             }
3670             t15.deleteSubtree( t15.getNode( "A1" ), true );
3671             if ( t15.getNumberOfExternalNodes() != 7 ) {
3672                 return false;
3673             }
3674             t15.deleteSubtree( t15.getNode( "C4" ), true );
3675             if ( t15.getNumberOfExternalNodes() != 6 ) {
3676                 return false;
3677             }
3678         }
3679         catch ( final Exception e ) {
3680             e.printStackTrace( System.out );
3681             return false;
3682         }
3683         return true;
3684     }
3685
3686     private static boolean testDescriptiveStatistics() {
3687         try {
3688             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3689             dss1.addValue( 82 );
3690             dss1.addValue( 78 );
3691             dss1.addValue( 70 );
3692             dss1.addValue( 58 );
3693             dss1.addValue( 42 );
3694             if ( dss1.getN() != 5 ) {
3695                 return false;
3696             }
3697             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3698                 return false;
3699             }
3700             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3701                 return false;
3702             }
3703             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3704                 return false;
3705             }
3706             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3707                 return false;
3708             }
3709             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3710                 return false;
3711             }
3712             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3713                 return false;
3714             }
3715             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3716                 return false;
3717             }
3718             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3719                 return false;
3720             }
3721             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3722                 return false;
3723             }
3724             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3725                 return false;
3726             }
3727             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3728                 return false;
3729             }
3730             dss1.addValue( 123 );
3731             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3732                 return false;
3733             }
3734             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3735                 return false;
3736             }
3737             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3738                 return false;
3739             }
3740             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3741             dss2.addValue( -1.85 );
3742             dss2.addValue( 57.5 );
3743             dss2.addValue( 92.78 );
3744             dss2.addValue( 57.78 );
3745             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3746                 return false;
3747             }
3748             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3749                 return false;
3750             }
3751             final double[] a = dss2.getDataAsDoubleArray();
3752             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3753                 return false;
3754             }
3755             dss2.addValue( -100 );
3756             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3757                 return false;
3758             }
3759             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3760                 return false;
3761             }
3762             final double[] ds = new double[ 14 ];
3763             ds[ 0 ] = 34;
3764             ds[ 1 ] = 23;
3765             ds[ 2 ] = 1;
3766             ds[ 3 ] = 32;
3767             ds[ 4 ] = 11;
3768             ds[ 5 ] = 2;
3769             ds[ 6 ] = 12;
3770             ds[ 7 ] = 33;
3771             ds[ 8 ] = 13;
3772             ds[ 9 ] = 22;
3773             ds[ 10 ] = 21;
3774             ds[ 11 ] = 35;
3775             ds[ 12 ] = 24;
3776             ds[ 13 ] = 31;
3777             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3778             if ( bins.length != 4 ) {
3779                 return false;
3780             }
3781             if ( bins[ 0 ] != 2 ) {
3782                 return false;
3783             }
3784             if ( bins[ 1 ] != 3 ) {
3785                 return false;
3786             }
3787             if ( bins[ 2 ] != 4 ) {
3788                 return false;
3789             }
3790             if ( bins[ 3 ] != 5 ) {
3791                 return false;
3792             }
3793             final double[] ds1 = new double[ 9 ];
3794             ds1[ 0 ] = 10.0;
3795             ds1[ 1 ] = 19.0;
3796             ds1[ 2 ] = 9.999;
3797             ds1[ 3 ] = 0.0;
3798             ds1[ 4 ] = 39.9;
3799             ds1[ 5 ] = 39.999;
3800             ds1[ 6 ] = 30.0;
3801             ds1[ 7 ] = 19.999;
3802             ds1[ 8 ] = 30.1;
3803             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3804             if ( bins1.length != 4 ) {
3805                 return false;
3806             }
3807             if ( bins1[ 0 ] != 2 ) {
3808                 return false;
3809             }
3810             if ( bins1[ 1 ] != 3 ) {
3811                 return false;
3812             }
3813             if ( bins1[ 2 ] != 0 ) {
3814                 return false;
3815             }
3816             if ( bins1[ 3 ] != 4 ) {
3817                 return false;
3818             }
3819             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3820             if ( bins1_1.length != 3 ) {
3821                 return false;
3822             }
3823             if ( bins1_1[ 0 ] != 3 ) {
3824                 return false;
3825             }
3826             if ( bins1_1[ 1 ] != 2 ) {
3827                 return false;
3828             }
3829             if ( bins1_1[ 2 ] != 4 ) {
3830                 return false;
3831             }
3832             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3833             if ( bins1_2.length != 3 ) {
3834                 return false;
3835             }
3836             if ( bins1_2[ 0 ] != 2 ) {
3837                 return false;
3838             }
3839             if ( bins1_2[ 1 ] != 2 ) {
3840                 return false;
3841             }
3842             if ( bins1_2[ 2 ] != 2 ) {
3843                 return false;
3844             }
3845             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3846             dss3.addValue( 1 );
3847             dss3.addValue( 1 );
3848             dss3.addValue( 1 );
3849             dss3.addValue( 2 );
3850             dss3.addValue( 3 );
3851             dss3.addValue( 4 );
3852             dss3.addValue( 5 );
3853             dss3.addValue( 5 );
3854             dss3.addValue( 5 );
3855             dss3.addValue( 6 );
3856             dss3.addValue( 7 );
3857             dss3.addValue( 8 );
3858             dss3.addValue( 9 );
3859             dss3.addValue( 10 );
3860             dss3.addValue( 10 );
3861             dss3.addValue( 10 );
3862             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3863             histo.toStringBuffer( 10, '=', 40, 5 );
3864             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3865         }
3866         catch ( final Exception e ) {
3867             e.printStackTrace( System.out );
3868             return false;
3869         }
3870         return true;
3871     }
3872
3873     private static boolean testDir( final String file ) {
3874         try {
3875             final File f = new File( file );
3876             if ( !f.exists() ) {
3877                 return false;
3878             }
3879             if ( !f.isDirectory() ) {
3880                 return false;
3881             }
3882             if ( !f.canRead() ) {
3883                 return false;
3884             }
3885         }
3886         catch ( final Exception e ) {
3887             return false;
3888         }
3889         return true;
3890     }
3891
3892     private static boolean testEbiEntryRetrieval() {
3893         try {
3894             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
3895             if ( !entry.getAccession().equals( "AAK41263" ) ) {
3896                 System.out.println( entry.getAccession() );
3897                 return false;
3898             }
3899             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
3900                 System.out.println( entry.getTaxonomyScientificName() );
3901                 return false;
3902             }
3903             if ( !entry.getSequenceName()
3904                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
3905                 System.out.println( entry.getSequenceName() );
3906                 return false;
3907             }
3908             // if ( !entry.getSequenceSymbol().equals( "" ) ) {
3909             //     System.out.println( entry.getSequenceSymbol() );
3910             //     return false;
3911             // }
3912             if ( !entry.getGeneName().equals( "treX-like" ) ) {
3913                 System.out.println( entry.getGeneName() );
3914                 return false;
3915             }
3916             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
3917                 System.out.println( entry.getTaxonomyIdentifier() );
3918                 return false;
3919             }
3920             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
3921                 System.out.println( entry.getAnnotations().first().getRefValue() );
3922                 return false;
3923             }
3924             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
3925                 System.out.println( entry.getAnnotations().first().getRefSource() );
3926                 return false;
3927             }
3928             if ( entry.getCrossReferences().size() != 5 ) {
3929                 return false;
3930             }
3931             //
3932             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
3933             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
3934                 return false;
3935             }
3936             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
3937                 System.out.println( entry1.getTaxonomyScientificName() );
3938                 return false;
3939             }
3940             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
3941                 System.out.println( entry1.getSequenceName() );
3942                 return false;
3943             }
3944             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
3945                 System.out.println( entry1.getTaxonomyIdentifier() );
3946                 return false;
3947             }
3948             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
3949                 System.out.println( entry1.getGeneName() );
3950                 return false;
3951             }
3952             if ( entry1.getCrossReferences().size() != 6 ) {
3953                 return false;
3954             }
3955             //
3956             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
3957             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
3958                 return false;
3959             }
3960             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
3961                 System.out.println( entry2.getTaxonomyScientificName() );
3962                 return false;
3963             }
3964             if ( !entry2.getSequenceName()
3965                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
3966                 System.out.println( entry2.getSequenceName() );
3967                 return false;
3968             }
3969             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
3970                 System.out.println( entry2.getTaxonomyIdentifier() );
3971                 return false;
3972             }
3973             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
3974                 System.out.println( entry2.getGeneName() );
3975                 return false;
3976             }
3977             if ( entry2.getCrossReferences().size() != 3 ) {
3978                 return false;
3979             }
3980             //
3981             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
3982             if ( !entry3.getAccession().equals( "HM043801" ) ) {
3983                 return false;
3984             }
3985             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
3986                 System.out.println( entry3.getTaxonomyScientificName() );
3987                 return false;
3988             }
3989             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
3990                 System.out.println( entry3.getSequenceName() );
3991                 return false;
3992             }
3993             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
3994                 System.out.println( entry3.getTaxonomyIdentifier() );
3995                 return false;
3996             }
3997             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
3998                 System.out.println( entry3.getSequenceSymbol() );
3999                 return false;
4000             }
4001             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
4002                 return false;
4003             }
4004             if ( entry3.getCrossReferences().size() != 8 ) {
4005                 return false;
4006             }
4007             //
4008             //
4009             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
4010             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
4011                 return false;
4012             }
4013             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4014                 System.out.println( entry4.getTaxonomyScientificName() );
4015                 return false;
4016             }
4017             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4018                 System.out.println( entry4.getSequenceName() );
4019                 return false;
4020             }
4021             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4022                 System.out.println( entry4.getTaxonomyIdentifier() );
4023                 return false;
4024             }
4025             if ( !entry4.getGeneName().equals( "ras" ) ) {
4026                 System.out.println( entry4.getGeneName() );
4027                 return false;
4028             }
4029             //   if ( !entry4.getChromosome().equals( "ras" ) ) {
4030             //     System.out.println( entry4.getChromosome() );
4031             //     return false;
4032             // }
4033             // if ( !entry4.getMap().equals( "ras" ) ) {
4034             //     System.out.println( entry4.getMap() );
4035             //     return false;
4036             // }
4037             //TODO FIXME gi...
4038             //
4039             //TODO fails:
4040             //            final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "M30539" );
4041             //            if ( !entry5.getAccession().equals( "HM043801" ) ) {
4042             //                return false;
4043             //            }
4044             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4045             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4046                 return false;
4047             }
4048             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4049                 System.out.println( entry5.getTaxonomyScientificName() );
4050                 return false;
4051             }
4052             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4053                 System.out.println( entry5.getSequenceName() );
4054                 return false;
4055             }
4056             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4057                 System.out.println( entry5.getTaxonomyIdentifier() );
4058                 return false;
4059             }
4060         }
4061         catch ( final IOException e ) {
4062             System.out.println();
4063             System.out.println( "the following might be due to absence internet connection:" );
4064             e.printStackTrace( System.out );
4065             return true;
4066         }
4067         catch ( final Exception e ) {
4068             e.printStackTrace();
4069             return false;
4070         }
4071         return true;
4072     }
4073
4074     private static boolean testExternalNodeRelatedMethods() {
4075         try {
4076             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4077             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4078             PhylogenyNode n = t1.getNode( "A" );
4079             n = n.getNextExternalNode();
4080             if ( !n.getName().equals( "B" ) ) {
4081                 return false;
4082             }
4083             n = n.getNextExternalNode();
4084             if ( !n.getName().equals( "C" ) ) {
4085                 return false;
4086             }
4087             n = n.getNextExternalNode();
4088             if ( !n.getName().equals( "D" ) ) {
4089                 return false;
4090             }
4091             n = t1.getNode( "B" );
4092             while ( !n.isLastExternalNode() ) {
4093                 n = n.getNextExternalNode();
4094             }
4095             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4096             n = t2.getNode( "A" );
4097             n = n.getNextExternalNode();
4098             if ( !n.getName().equals( "B" ) ) {
4099                 return false;
4100             }
4101             n = n.getNextExternalNode();
4102             if ( !n.getName().equals( "C" ) ) {
4103                 return false;
4104             }
4105             n = n.getNextExternalNode();
4106             if ( !n.getName().equals( "D" ) ) {
4107                 return false;
4108             }
4109             n = t2.getNode( "B" );
4110             while ( !n.isLastExternalNode() ) {
4111                 n = n.getNextExternalNode();
4112             }
4113             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4114             n = t3.getNode( "A" );
4115             n = n.getNextExternalNode();
4116             if ( !n.getName().equals( "B" ) ) {
4117                 return false;
4118             }
4119             n = n.getNextExternalNode();
4120             if ( !n.getName().equals( "C" ) ) {
4121                 return false;
4122             }
4123             n = n.getNextExternalNode();
4124             if ( !n.getName().equals( "D" ) ) {
4125                 return false;
4126             }
4127             n = n.getNextExternalNode();
4128             if ( !n.getName().equals( "E" ) ) {
4129                 return false;
4130             }
4131             n = n.getNextExternalNode();
4132             if ( !n.getName().equals( "F" ) ) {
4133                 return false;
4134             }
4135             n = n.getNextExternalNode();
4136             if ( !n.getName().equals( "G" ) ) {
4137                 return false;
4138             }
4139             n = n.getNextExternalNode();
4140             if ( !n.getName().equals( "H" ) ) {
4141                 return false;
4142             }
4143             n = t3.getNode( "B" );
4144             while ( !n.isLastExternalNode() ) {
4145                 n = n.getNextExternalNode();
4146             }
4147             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4148             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4149                 final PhylogenyNode node = iter.next();
4150             }
4151             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4152             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4153                 final PhylogenyNode node = iter.next();
4154             }
4155             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4156             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4157             if ( !iter.next().getName().equals( "A" ) ) {
4158                 return false;
4159             }
4160             if ( !iter.next().getName().equals( "B" ) ) {
4161                 return false;
4162             }
4163             if ( !iter.next().getName().equals( "C" ) ) {
4164                 return false;
4165             }
4166             if ( !iter.next().getName().equals( "D" ) ) {
4167                 return false;
4168             }
4169             if ( !iter.next().getName().equals( "E" ) ) {
4170                 return false;
4171             }
4172             if ( !iter.next().getName().equals( "F" ) ) {
4173                 return false;
4174             }
4175             if ( iter.hasNext() ) {
4176                 return false;
4177             }
4178         }
4179         catch ( final Exception e ) {
4180             e.printStackTrace( System.out );
4181             return false;
4182         }
4183         return true;
4184     }
4185
4186     private static boolean testExtractSNFromNodeName() {
4187         try {
4188             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4189                 return false;
4190             }
4191             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4192                 return false;
4193             }
4194             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4195                 return false;
4196             }
4197             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4198                     .equals( "Mus musculus musculus" ) ) {
4199                 return false;
4200             }
4201             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4202                     .equals( "Mus musculus musculus" ) ) {
4203                 return false;
4204             }
4205             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4206                     .equals( "Mus musculus musculus" ) ) {
4207                 return false;
4208             }
4209             if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4210                     .equals( "Mus musculus musculus" ) ) {
4211                 return false;
4212             }
4213             if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4214                 return false;
4215             }
4216             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4217                     .equals( "Mus musculus musculus" ) ) {
4218                 return false;
4219             }
4220             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4221                     .equals( "Mus musculus musculus" ) ) {
4222                 return false;
4223             }
4224             if ( ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
4225                 return false;
4226             }
4227             if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
4228                 return false;
4229             }
4230             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
4231                 return false;
4232             }
4233             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
4234                 return false;
4235             }
4236             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
4237                     .equals( "Mus musculus musculus" ) ) {
4238                 return false;
4239             }
4240             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
4241                 return false;
4242             }
4243             if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
4244                 return false;
4245             }
4246             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
4247                 return false;
4248             }
4249             if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
4250                 return false;
4251             }
4252             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
4253                 return false;
4254             }
4255             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
4256                 return false;
4257             }
4258             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
4259                 return false;
4260             }
4261             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
4262                 return false;
4263             }
4264             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
4265                     .equals( "Mus musculus" ) ) {
4266                 return false;
4267             }
4268             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
4269                     .equals( "Mus musculus" ) ) {
4270                 return false;
4271             }
4272             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4273                 return false;
4274             }
4275             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4276                     .equals( "Mus musculus musculus" ) ) {
4277                 return false;
4278             }
4279             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4280                     .equals( "Mus musculus musculus" ) ) {
4281                 return false;
4282             }
4283             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
4284                     .equals( "Mus musculus musculus" ) ) {
4285                 return false;
4286             }
4287             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4288                 return false;
4289             }
4290             if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
4291                     .equals( "Pilostyles mexicana" ) ) {
4292                 return false;
4293             }
4294             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
4295                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
4296                 return false;
4297             }
4298             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
4299                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4300                 return false;
4301             }
4302             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
4303                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4304                 return false;
4305             }
4306             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
4307                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4308                 return false;
4309             }
4310             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
4311                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4312                 return false;
4313             }
4314             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
4315                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4316                 return false;
4317             }
4318             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
4319                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4320                 return false;
4321             }
4322             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
4323                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4324                 return false;
4325             }
4326             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
4327                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
4328                 return false;
4329             }
4330             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
4331                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
4332                 return false;
4333             }
4334             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
4335                     .equals( "Escherichia coli (strain K12)" ) ) {
4336                 return false;
4337             }
4338             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
4339                     .equals( "Escherichia coli (strain K12)" ) ) {
4340                 return false;
4341             }
4342             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
4343                     .equals( "Escherichia coli (str. K12)" ) ) {
4344                 return false;
4345             }
4346             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
4347                     .equals( "Escherichia coli (str. K12)" ) ) {
4348                 return false;
4349             }
4350             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
4351                     .equals( "Escherichia coli (str. K12)" ) ) {
4352                 return false;
4353             }
4354             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
4355                     .equals( "Escherichia coli (var. K12)" ) ) {
4356                 return false;
4357             }
4358             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K-12 substr. MG1655star" )
4359                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4360                 return false;
4361             }
4362             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star" )
4363                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4364                 return false;
4365             }
4366             if ( !ParserUtils
4367                     .extractScientificNameFromNodeName( "could be anything 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 gene1" )
4372                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4373                 return false;
4374             }
4375             if ( !ParserUtils
4376                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
4377                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4378                 return false;
4379             }
4380             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4381                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4382                 return false;
4383             }
4384             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4385                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4386                 return false;
4387             }
4388             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
4389                 return false;
4390             }
4391             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
4392                 return false;
4393             }
4394             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
4395                 return false;
4396             }
4397             if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
4398                     .equals( "Macrocera sp." ) ) {
4399                 return false;
4400             }
4401             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
4402                 return false;
4403             }
4404             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
4405                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4406                 return false;
4407             }
4408             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
4409                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4410                 return false;
4411             }
4412             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
4413                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4414                 return false;
4415             }
4416             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
4417                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4418                 return false;
4419             }
4420         }
4421         catch ( final Exception e ) {
4422             e.printStackTrace( System.out );
4423             return false;
4424         }
4425         return true;
4426     }
4427
4428     private static boolean testExtractTaxonomyCodeFromNodeName() {
4429         try {
4430             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4431                 return false;
4432             }
4433             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4434                     .equals( "SOYBN" ) ) {
4435                 return false;
4436             }
4437             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4438                     .equals( "ARATH" ) ) {
4439                 return false;
4440             }
4441             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4442                     .equals( "ARATH" ) ) {
4443                 return false;
4444             }
4445             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4446                 return false;
4447             }
4448             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4449                 return false;
4450             }
4451             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4452                 return false;
4453             }
4454             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4455                     .equals( "SOYBN" ) ) {
4456                 return false;
4457             }
4458             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4459                     .equals( "SOYBN" ) ) {
4460                 return false;
4461             }
4462             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4463                     .equals( "SOYBN" ) ) {
4464                 return false;
4465             }
4466             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4467                     .equals( "SOYBN" ) ) {
4468                 return false;
4469             }
4470             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4471                     .equals( "SOYBN" ) ) {
4472                 return false;
4473             }
4474             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4475                     .equals( "SOYBN" ) ) {
4476                 return false;
4477             }
4478             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4479                     .equals( "SOYBN" ) ) {
4480                 return false;
4481             }
4482             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
4483                     .equals( "SOYBN" ) ) {
4484                 return false;
4485             }
4486             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
4487                 return false;
4488             }
4489             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
4490                     .equals( "SOYBN" ) ) {
4491                 return false;
4492             }
4493             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
4494                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
4495                 return false;
4496             }
4497             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
4498                     .equals( "9YX45" ) ) {
4499                 return false;
4500             }
4501             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
4502                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4503                     .equals( "MOUSE" ) ) {
4504                 return false;
4505             }
4506             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
4507                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4508                     .equals( "MOUSE" ) ) {
4509                 return false;
4510             }
4511             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
4512                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4513                     .equals( "MOUSE" ) ) {
4514                 return false;
4515             }
4516             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
4517                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4518                 return false;
4519             }
4520             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
4521                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4522                 return false;
4523             }
4524             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4525                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4526                 return false;
4527             }
4528             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4529                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4530                 return false;
4531             }
4532             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
4533                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4534                 return false;
4535             }
4536             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
4537                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4538                 return false;
4539             }
4540             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
4541                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4542                 return false;
4543             }
4544             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4545                     .equals( "RAT" ) ) {
4546                 return false;
4547             }
4548             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4549                     .equals( "PIG" ) ) {
4550                 return false;
4551             }
4552             if ( !ParserUtils
4553                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4554                     .equals( "MOUSE" ) ) {
4555                 return false;
4556             }
4557             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4558                     .equals( "MOUSE" ) ) {
4559                 return false;
4560             }
4561             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4562                 return false;
4563             }
4564         }
4565         catch ( final Exception e ) {
4566             e.printStackTrace( System.out );
4567             return false;
4568         }
4569         return true;
4570     }
4571
4572     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
4573         try {
4574             PhylogenyNode n = new PhylogenyNode();
4575             n.setName( "tr|B3RJ64" );
4576             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4577                 return false;
4578             }
4579             n.setName( "tr.B3RJ64" );
4580             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4581                 return false;
4582             }
4583             n.setName( "tr=B3RJ64" );
4584             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4585                 return false;
4586             }
4587             n.setName( "tr-B3RJ64" );
4588             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4589                 return false;
4590             }
4591             n.setName( "tr/B3RJ64" );
4592             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4593                 return false;
4594             }
4595             n.setName( "tr\\B3RJ64" );
4596             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4597                 return false;
4598             }
4599             n.setName( "tr_B3RJ64" );
4600             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4601                 return false;
4602             }
4603             n.setName( " tr|B3RJ64 " );
4604             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4605                 return false;
4606             }
4607             n.setName( "-tr|B3RJ64-" );
4608             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4609                 return false;
4610             }
4611             n.setName( "-tr=B3RJ64-" );
4612             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4613                 return false;
4614             }
4615             n.setName( "_tr=B3RJ64_" );
4616             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4617                 return false;
4618             }
4619             n.setName( " tr_tr|B3RJ64_sp|123 " );
4620             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4621                 return false;
4622             }
4623             n.setName( "B3RJ64" );
4624             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4625                 return false;
4626             }
4627             n.setName( "sp|B3RJ64" );
4628             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4629                 return false;
4630             }
4631             n.setName( "sp|B3RJ64C" );
4632             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4633                 return false;
4634             }
4635             n.setName( "sp B3RJ64" );
4636             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4637                 return false;
4638             }
4639             n.setName( "sp|B3RJ6X" );
4640             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4641                 return false;
4642             }
4643             n.setName( "sp|B3RJ6" );
4644             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4645                 return false;
4646             }
4647             n.setName( "K1PYK7_CRAGI" );
4648             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4649                 return false;
4650             }
4651             n.setName( "K1PYK7_PEA" );
4652             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
4653                 return false;
4654             }
4655             n.setName( "K1PYK7_RAT" );
4656             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
4657                 return false;
4658             }
4659             n.setName( "K1PYK7_PIG" );
4660             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4661                 return false;
4662             }
4663             n.setName( "~K1PYK7_PIG~" );
4664             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4665                 return false;
4666             }
4667             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
4668             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4669                 return false;
4670             }
4671             n.setName( "K1PYKX_CRAGI" );
4672             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4673                 return false;
4674             }
4675             n.setName( "XXXXX_CRAGI" );
4676             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
4677                 return false;
4678             }
4679             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
4680             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
4681                 return false;
4682             }
4683             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
4684             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4685                 return false;
4686             }
4687             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
4688             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
4689                 return false;
4690             }
4691             n = new PhylogenyNode();
4692             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
4693             seq.setSymbol( "K1PYK7_CRAGI" );
4694             n.getNodeData().addSequence( seq );
4695             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4696                 return false;
4697             }
4698             seq.setSymbol( "tr|B3RJ64" );
4699             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4700                 return false;
4701             }
4702             n = new PhylogenyNode();
4703             seq = new org.forester.phylogeny.data.Sequence();
4704             seq.setName( "K1PYK7_CRAGI" );
4705             n.getNodeData().addSequence( seq );
4706             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4707                 return false;
4708             }
4709             seq.setName( "tr|B3RJ64" );
4710             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4711                 return false;
4712             }
4713             n = new PhylogenyNode();
4714             seq = new org.forester.phylogeny.data.Sequence();
4715             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4716             n.getNodeData().addSequence( seq );
4717             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
4718                 return false;
4719             }
4720             n = new PhylogenyNode();
4721             seq = new org.forester.phylogeny.data.Sequence();
4722             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4723             n.getNodeData().addSequence( seq );
4724             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4725                 return false;
4726             }
4727             //
4728             n = new PhylogenyNode();
4729             n.setName( "ACP19736" );
4730             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4731                 return false;
4732             }
4733             n = new PhylogenyNode();
4734             n.setName( "|ACP19736|" );
4735             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4736                 return false;
4737             }
4738         }
4739         catch ( final Exception e ) {
4740             e.printStackTrace( System.out );
4741             return false;
4742         }
4743         return true;
4744     }
4745
4746     private static boolean testFastaParser() {
4747         try {
4748             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
4749                 return false;
4750             }
4751             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
4752                 return false;
4753             }
4754             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
4755             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
4756                 return false;
4757             }
4758             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
4759                 return false;
4760             }
4761             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
4762                 return false;
4763             }
4764             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
4765                 return false;
4766             }
4767             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
4768                 return false;
4769             }
4770             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
4771                 return false;
4772             }
4773         }
4774         catch ( final Exception e ) {
4775             e.printStackTrace();
4776             return false;
4777         }
4778         return true;
4779     }
4780
4781     private static boolean testGenbankAccessorParsing() {
4782         //The format for GenBank Accession numbers are:
4783         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
4784         //Protein:    3 letters + 5 numerals
4785         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
4786         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
4787             return false;
4788         }
4789         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
4790             return false;
4791         }
4792         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
4793             return false;
4794         }
4795         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
4796             return false;
4797         }
4798         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
4799             return false;
4800         }
4801         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
4802             return false;
4803         }
4804         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
4805             return false;
4806         }
4807         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
4808             return false;
4809         }
4810         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
4811             return false;
4812         }
4813         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
4814             return false;
4815         }
4816         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
4817             return false;
4818         }
4819         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
4820             return false;
4821         }
4822         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
4823             return false;
4824         }
4825         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
4826             return false;
4827         }
4828         return true;
4829     }
4830
4831     private static boolean testGeneralMsaParser() {
4832         try {
4833             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
4834             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
4835             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
4836             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
4837             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
4838             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
4839             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
4840             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
4841             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4842                 return false;
4843             }
4844             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4845                 return false;
4846             }
4847             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4848                 return false;
4849             }
4850             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4851                 return false;
4852             }
4853             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4854                 return false;
4855             }
4856             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4857                 return false;
4858             }
4859             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4860                 return false;
4861             }
4862             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4863                 return false;
4864             }
4865             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4866                 return false;
4867             }
4868             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4869                 return false;
4870             }
4871             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4872                 return false;
4873             }
4874             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4875                 return false;
4876             }
4877             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
4878             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4879                 return false;
4880             }
4881             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4882                 return false;
4883             }
4884             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4885                 return false;
4886             }
4887             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
4888             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
4889                 return false;
4890             }
4891             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
4892                 return false;
4893             }
4894             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
4895                 return false;
4896             }
4897             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
4898             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4899                 return false;
4900             }
4901             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4902                 return false;
4903             }
4904             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4905                 return false;
4906             }
4907         }
4908         catch ( final Exception e ) {
4909             e.printStackTrace();
4910             return false;
4911         }
4912         return true;
4913     }
4914
4915     private static boolean testGeneralTable() {
4916         try {
4917             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
4918             t0.setValue( 3, 2, "23" );
4919             t0.setValue( 10, 1, "error" );
4920             t0.setValue( 10, 1, "110" );
4921             t0.setValue( 9, 1, "19" );
4922             t0.setValue( 1, 10, "101" );
4923             t0.setValue( 10, 10, "1010" );
4924             t0.setValue( 100, 10, "10100" );
4925             t0.setValue( 0, 0, "00" );
4926             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
4927                 return false;
4928             }
4929             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
4930                 return false;
4931             }
4932             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
4933                 return false;
4934             }
4935             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
4936                 return false;
4937             }
4938             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
4939                 return false;
4940             }
4941             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
4942                 return false;
4943             }
4944             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
4945                 return false;
4946             }
4947             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
4948                 return false;
4949             }
4950             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
4951                 return false;
4952             }
4953             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
4954             t1.setValue( "3", "2", "23" );
4955             t1.setValue( "10", "1", "error" );
4956             t1.setValue( "10", "1", "110" );
4957             t1.setValue( "9", "1", "19" );
4958             t1.setValue( "1", "10", "101" );
4959             t1.setValue( "10", "10", "1010" );
4960             t1.setValue( "100", "10", "10100" );
4961             t1.setValue( "0", "0", "00" );
4962             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
4963             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
4964                 return false;
4965             }
4966             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
4967                 return false;
4968             }
4969             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
4970                 return false;
4971             }
4972             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
4973                 return false;
4974             }
4975             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
4976                 return false;
4977             }
4978             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
4979                 return false;
4980             }
4981             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
4982                 return false;
4983             }
4984             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
4985                 return false;
4986             }
4987             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
4988                 return false;
4989             }
4990             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
4991                 return false;
4992             }
4993         }
4994         catch ( final Exception e ) {
4995             e.printStackTrace( System.out );
4996             return false;
4997         }
4998         return true;
4999     }
5000
5001     private static boolean testGetDistance() {
5002         try {
5003             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5004             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",
5005                                                  new NHXParser() )[ 0 ];
5006             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
5007                 return false;
5008             }
5009             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
5010                 return false;
5011             }
5012             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5013                 return false;
5014             }
5015             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5016                 return false;
5017             }
5018             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5019                 return false;
5020             }
5021             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5022                 return false;
5023             }
5024             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5025                 return false;
5026             }
5027             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5028                 return false;
5029             }
5030             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5031                 return false;
5032             }
5033             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5034                 return false;
5035             }
5036             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5037                 return false;
5038             }
5039             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5040                 return false;
5041             }
5042             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5043                 return false;
5044             }
5045             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5046                 return false;
5047             }
5048             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5049                 return false;
5050             }
5051             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5052                 return false;
5053             }
5054             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5055                 return false;
5056             }
5057             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5058                 return false;
5059             }
5060             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5061                 return false;
5062             }
5063             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5064                 return false;
5065             }
5066             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5067                 return false;
5068             }
5069             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5070                 return false;
5071             }
5072             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5073                 return false;
5074             }
5075             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5076                 return false;
5077             }
5078             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5079                 return false;
5080             }
5081             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5082                 return false;
5083             }
5084             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5085                 return false;
5086             }
5087             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5088                 return false;
5089             }
5090             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5091                 return false;
5092             }
5093             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5094                 return false;
5095             }
5096             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5097                 return false;
5098             }
5099             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",
5100                                                  new NHXParser() )[ 0 ];
5101             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5102                 return false;
5103             }
5104             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5105                 return false;
5106             }
5107             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5108                 return false;
5109             }
5110             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5111                 return false;
5112             }
5113             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5114                 return false;
5115             }
5116             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5117                 return false;
5118             }
5119             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5120                 return false;
5121             }
5122             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5123                 return false;
5124             }
5125             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5126                 return false;
5127             }
5128             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5129                 return false;
5130             }
5131             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5132                 return false;
5133             }
5134         }
5135         catch ( final Exception e ) {
5136             e.printStackTrace( System.out );
5137             return false;
5138         }
5139         return true;
5140     }
5141
5142     private static boolean testGetLCA() {
5143         try {
5144             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5145             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5146                                                  new NHXParser() )[ 0 ];
5147             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5148             if ( !A.getName().equals( "A" ) ) {
5149                 return false;
5150             }
5151             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5152             if ( !gh.getName().equals( "gh" ) ) {
5153                 return false;
5154             }
5155             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5156             if ( !ab.getName().equals( "ab" ) ) {
5157                 return false;
5158             }
5159             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5160             if ( !ab2.getName().equals( "ab" ) ) {
5161                 return false;
5162             }
5163             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5164             if ( !gh2.getName().equals( "gh" ) ) {
5165                 return false;
5166             }
5167             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5168             if ( !gh3.getName().equals( "gh" ) ) {
5169                 return false;
5170             }
5171             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5172             if ( !abc.getName().equals( "abc" ) ) {
5173                 return false;
5174             }
5175             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5176             if ( !abc2.getName().equals( "abc" ) ) {
5177                 return false;
5178             }
5179             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5180             if ( !abcd.getName().equals( "abcd" ) ) {
5181                 return false;
5182             }
5183             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5184             if ( !abcd2.getName().equals( "abcd" ) ) {
5185                 return false;
5186             }
5187             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5188             if ( !abcdef.getName().equals( "abcdef" ) ) {
5189                 return false;
5190             }
5191             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5192             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5193                 return false;
5194             }
5195             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5196             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5197                 return false;
5198             }
5199             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5200             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5201                 return false;
5202             }
5203             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
5204             if ( !abcde.getName().equals( "abcde" ) ) {
5205                 return false;
5206             }
5207             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
5208             if ( !abcde2.getName().equals( "abcde" ) ) {
5209                 return false;
5210             }
5211             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
5212             if ( !r.getName().equals( "abcdefgh" ) ) {
5213                 return false;
5214             }
5215             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5216             if ( !r2.getName().equals( "abcdefgh" ) ) {
5217                 return false;
5218             }
5219             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5220             if ( !r3.getName().equals( "abcdefgh" ) ) {
5221                 return false;
5222             }
5223             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5224             if ( !abcde3.getName().equals( "abcde" ) ) {
5225                 return false;
5226             }
5227             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5228             if ( !abcde4.getName().equals( "abcde" ) ) {
5229                 return false;
5230             }
5231             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5232             if ( !ab3.getName().equals( "ab" ) ) {
5233                 return false;
5234             }
5235             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5236             if ( !ab4.getName().equals( "ab" ) ) {
5237                 return false;
5238             }
5239             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5240             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5241             if ( !cd.getName().equals( "cd" ) ) {
5242                 return false;
5243             }
5244             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5245             if ( !cd2.getName().equals( "cd" ) ) {
5246                 return false;
5247             }
5248             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5249             if ( !cde.getName().equals( "cde" ) ) {
5250                 return false;
5251             }
5252             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5253             if ( !cde2.getName().equals( "cde" ) ) {
5254                 return false;
5255             }
5256             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5257             if ( !cdef.getName().equals( "cdef" ) ) {
5258                 return false;
5259             }
5260             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5261             if ( !cdef2.getName().equals( "cdef" ) ) {
5262                 return false;
5263             }
5264             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5265             if ( !cdef3.getName().equals( "cdef" ) ) {
5266                 return false;
5267             }
5268             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5269             if ( !rt.getName().equals( "r" ) ) {
5270                 return false;
5271             }
5272             final Phylogeny p3 = factory
5273                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5274                              new NHXParser() )[ 0 ];
5275             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5276             if ( !bc_3.getName().equals( "bc" ) ) {
5277                 return false;
5278             }
5279             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5280             if ( !ac_3.getName().equals( "abc" ) ) {
5281                 return false;
5282             }
5283             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5284             if ( !ad_3.getName().equals( "abcde" ) ) {
5285                 return false;
5286             }
5287             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5288             if ( !af_3.getName().equals( "abcdef" ) ) {
5289                 return false;
5290             }
5291             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5292             if ( !ag_3.getName().equals( "" ) ) {
5293                 return false;
5294             }
5295             if ( !ag_3.isRoot() ) {
5296                 return false;
5297             }
5298             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5299             if ( !al_3.getName().equals( "" ) ) {
5300                 return false;
5301             }
5302             if ( !al_3.isRoot() ) {
5303                 return false;
5304             }
5305             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5306             if ( !kl_3.getName().equals( "" ) ) {
5307                 return false;
5308             }
5309             if ( !kl_3.isRoot() ) {
5310                 return false;
5311             }
5312             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5313             if ( !fl_3.getName().equals( "" ) ) {
5314                 return false;
5315             }
5316             if ( !fl_3.isRoot() ) {
5317                 return false;
5318             }
5319             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5320             if ( !gk_3.getName().equals( "ghijk" ) ) {
5321                 return false;
5322             }
5323             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5324             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5325             if ( !r_4.getName().equals( "r" ) ) {
5326                 return false;
5327             }
5328             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5329             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5330             if ( !r_5.getName().equals( "root" ) ) {
5331                 return false;
5332             }
5333             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5334             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5335             if ( !r_6.getName().equals( "rot" ) ) {
5336                 return false;
5337             }
5338             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5339             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5340             if ( !r_7.getName().equals( "rott" ) ) {
5341                 return false;
5342             }
5343         }
5344         catch ( final Exception e ) {
5345             e.printStackTrace( System.out );
5346             return false;
5347         }
5348         return true;
5349     }
5350
5351     private static boolean testGetLCA2() {
5352         try {
5353             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5354             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5355             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5356             PhylogenyMethods.preOrderReId( p_a );
5357             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5358                                                                                               p_a.getNode( "a" ) );
5359             if ( !p_a_1.getName().equals( "a" ) ) {
5360                 return false;
5361             }
5362             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5363             PhylogenyMethods.preOrderReId( p_b );
5364             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5365                                                                                               p_b.getNode( "a" ) );
5366             if ( !p_b_1.getName().equals( "b" ) ) {
5367                 return false;
5368             }
5369             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5370                                                                                               p_b.getNode( "b" ) );
5371             if ( !p_b_2.getName().equals( "b" ) ) {
5372                 return false;
5373             }
5374             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5375             PhylogenyMethods.preOrderReId( p_c );
5376             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5377                                                                                               p_c.getNode( "a" ) );
5378             if ( !p_c_1.getName().equals( "b" ) ) {
5379                 return false;
5380             }
5381             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5382                                                                                               p_c.getNode( "c" ) );
5383             if ( !p_c_2.getName().equals( "c" ) ) {
5384                 System.out.println( p_c_2.getName() );
5385                 System.exit( -1 );
5386                 return false;
5387             }
5388             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5389                                                                                               p_c.getNode( "b" ) );
5390             if ( !p_c_3.getName().equals( "b" ) ) {
5391                 return false;
5392             }
5393             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5394                                                                                               p_c.getNode( "a" ) );
5395             if ( !p_c_4.getName().equals( "c" ) ) {
5396                 return false;
5397             }
5398             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5399                                                  new NHXParser() )[ 0 ];
5400             PhylogenyMethods.preOrderReId( p1 );
5401             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5402                                                                                           p1.getNode( "A" ) );
5403             if ( !A.getName().equals( "A" ) ) {
5404                 return false;
5405             }
5406             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5407                                                                                            p1.getNode( "gh" ) );
5408             if ( !gh.getName().equals( "gh" ) ) {
5409                 return false;
5410             }
5411             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5412                                                                                            p1.getNode( "B" ) );
5413             if ( !ab.getName().equals( "ab" ) ) {
5414                 return false;
5415             }
5416             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5417                                                                                             p1.getNode( "A" ) );
5418             if ( !ab2.getName().equals( "ab" ) ) {
5419                 return false;
5420             }
5421             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5422                                                                                             p1.getNode( "G" ) );
5423             if ( !gh2.getName().equals( "gh" ) ) {
5424                 return false;
5425             }
5426             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5427                                                                                             p1.getNode( "H" ) );
5428             if ( !gh3.getName().equals( "gh" ) ) {
5429                 return false;
5430             }
5431             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5432                                                                                             p1.getNode( "A" ) );
5433             if ( !abc.getName().equals( "abc" ) ) {
5434                 return false;
5435             }
5436             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5437                                                                                              p1.getNode( "C" ) );
5438             if ( !abc2.getName().equals( "abc" ) ) {
5439                 return false;
5440             }
5441             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5442                                                                                              p1.getNode( "D" ) );
5443             if ( !abcd.getName().equals( "abcd" ) ) {
5444                 return false;
5445             }
5446             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5447                                                                                               p1.getNode( "A" ) );
5448             if ( !abcd2.getName().equals( "abcd" ) ) {
5449                 return false;
5450             }
5451             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5452                                                                                                p1.getNode( "F" ) );
5453             if ( !abcdef.getName().equals( "abcdef" ) ) {
5454                 return false;
5455             }
5456             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5457                                                                                                 p1.getNode( "A" ) );
5458             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5459                 return false;
5460             }
5461             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5462                                                                                                 p1.getNode( "F" ) );
5463             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5464                 return false;
5465             }
5466             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5467                                                                                                 p1.getNode( "ab" ) );
5468             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5469                 return false;
5470             }
5471             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5472                                                                                               p1.getNode( "E" ) );
5473             if ( !abcde.getName().equals( "abcde" ) ) {
5474                 return false;
5475             }
5476             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5477                                                                                                p1.getNode( "A" ) );
5478             if ( !abcde2.getName().equals( "abcde" ) ) {
5479                 return false;
5480             }
5481             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
5482                                                                                           p1.getNode( "abcdefgh" ) );
5483             if ( !r.getName().equals( "abcdefgh" ) ) {
5484                 return false;
5485             }
5486             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5487                                                                                            p1.getNode( "H" ) );
5488             if ( !r2.getName().equals( "abcdefgh" ) ) {
5489                 return false;
5490             }
5491             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5492                                                                                            p1.getNode( "A" ) );
5493             if ( !r3.getName().equals( "abcdefgh" ) ) {
5494                 return false;
5495             }
5496             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5497                                                                                                p1.getNode( "abcde" ) );
5498             if ( !abcde3.getName().equals( "abcde" ) ) {
5499                 return false;
5500             }
5501             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
5502                                                                                                p1.getNode( "E" ) );
5503             if ( !abcde4.getName().equals( "abcde" ) ) {
5504                 return false;
5505             }
5506             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5507                                                                                             p1.getNode( "B" ) );
5508             if ( !ab3.getName().equals( "ab" ) ) {
5509                 return false;
5510             }
5511             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5512                                                                                             p1.getNode( "ab" ) );
5513             if ( !ab4.getName().equals( "ab" ) ) {
5514                 return false;
5515             }
5516             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5517             PhylogenyMethods.preOrderReId( p2 );
5518             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5519                                                                                            p2.getNode( "d" ) );
5520             if ( !cd.getName().equals( "cd" ) ) {
5521                 return false;
5522             }
5523             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5524                                                                                             p2.getNode( "c" ) );
5525             if ( !cd2.getName().equals( "cd" ) ) {
5526                 return false;
5527             }
5528             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5529                                                                                             p2.getNode( "e" ) );
5530             if ( !cde.getName().equals( "cde" ) ) {
5531                 return false;
5532             }
5533             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
5534                                                                                              p2.getNode( "c" ) );
5535             if ( !cde2.getName().equals( "cde" ) ) {
5536                 return false;
5537             }
5538             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5539                                                                                              p2.getNode( "f" ) );
5540             if ( !cdef.getName().equals( "cdef" ) ) {
5541                 return false;
5542             }
5543             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5544                                                                                               p2.getNode( "f" ) );
5545             if ( !cdef2.getName().equals( "cdef" ) ) {
5546                 return false;
5547             }
5548             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
5549                                                                                               p2.getNode( "d" ) );
5550             if ( !cdef3.getName().equals( "cdef" ) ) {
5551                 return false;
5552             }
5553             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5554                                                                                            p2.getNode( "a" ) );
5555             if ( !rt.getName().equals( "r" ) ) {
5556                 return false;
5557             }
5558             final Phylogeny p3 = factory
5559                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5560                              new NHXParser() )[ 0 ];
5561             PhylogenyMethods.preOrderReId( p3 );
5562             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
5563                                                                                              p3.getNode( "c" ) );
5564             if ( !bc_3.getName().equals( "bc" ) ) {
5565                 return false;
5566             }
5567             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5568                                                                                              p3.getNode( "c" ) );
5569             if ( !ac_3.getName().equals( "abc" ) ) {
5570                 return false;
5571             }
5572             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5573                                                                                              p3.getNode( "d" ) );
5574             if ( !ad_3.getName().equals( "abcde" ) ) {
5575                 return false;
5576             }
5577             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5578                                                                                              p3.getNode( "f" ) );
5579             if ( !af_3.getName().equals( "abcdef" ) ) {
5580                 return false;
5581             }
5582             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5583                                                                                              p3.getNode( "g" ) );
5584             if ( !ag_3.getName().equals( "" ) ) {
5585                 return false;
5586             }
5587             if ( !ag_3.isRoot() ) {
5588                 return false;
5589             }
5590             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5591                                                                                              p3.getNode( "l" ) );
5592             if ( !al_3.getName().equals( "" ) ) {
5593                 return false;
5594             }
5595             if ( !al_3.isRoot() ) {
5596                 return false;
5597             }
5598             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
5599                                                                                              p3.getNode( "l" ) );
5600             if ( !kl_3.getName().equals( "" ) ) {
5601                 return false;
5602             }
5603             if ( !kl_3.isRoot() ) {
5604                 return false;
5605             }
5606             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
5607                                                                                              p3.getNode( "l" ) );
5608             if ( !fl_3.getName().equals( "" ) ) {
5609                 return false;
5610             }
5611             if ( !fl_3.isRoot() ) {
5612                 return false;
5613             }
5614             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
5615                                                                                              p3.getNode( "k" ) );
5616             if ( !gk_3.getName().equals( "ghijk" ) ) {
5617                 return false;
5618             }
5619             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5620             PhylogenyMethods.preOrderReId( p4 );
5621             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
5622                                                                                             p4.getNode( "c" ) );
5623             if ( !r_4.getName().equals( "r" ) ) {
5624                 return false;
5625             }
5626             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5627             PhylogenyMethods.preOrderReId( p5 );
5628             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
5629                                                                                             p5.getNode( "c" ) );
5630             if ( !r_5.getName().equals( "root" ) ) {
5631                 return false;
5632             }
5633             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5634             PhylogenyMethods.preOrderReId( p6 );
5635             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
5636                                                                                             p6.getNode( "a" ) );
5637             if ( !r_6.getName().equals( "rot" ) ) {
5638                 return false;
5639             }
5640             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5641             PhylogenyMethods.preOrderReId( p7 );
5642             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
5643                                                                                             p7.getNode( "e" ) );
5644             if ( !r_7.getName().equals( "rott" ) ) {
5645                 return false;
5646             }
5647             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5648                                                                                              p7.getNode( "a" ) );
5649             if ( !r_71.getName().equals( "rott" ) ) {
5650                 return false;
5651             }
5652             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5653                                                                                              p7.getNode( "rott" ) );
5654             if ( !r_72.getName().equals( "rott" ) ) {
5655                 return false;
5656             }
5657             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5658                                                                                              p7.getNode( "a" ) );
5659             if ( !r_73.getName().equals( "rott" ) ) {
5660                 return false;
5661             }
5662             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5663                                                                                              p7.getNode( "rott" ) );
5664             if ( !r_74.getName().equals( "rott" ) ) {
5665                 return false;
5666             }
5667             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5668                                                                                              p7.getNode( "e" ) );
5669             if ( !r_75.getName().equals( "e" ) ) {
5670                 return false;
5671             }
5672         }
5673         catch ( final Exception e ) {
5674             e.printStackTrace( System.out );
5675             return false;
5676         }
5677         return true;
5678     }
5679
5680     private static boolean testHmmscanOutputParser() {
5681         final String test_dir = Test.PATH_TO_TEST_DATA;
5682         try {
5683             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
5684                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5685             parser1.parse();
5686             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
5687                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5688             final List<Protein> proteins = parser2.parse();
5689             if ( parser2.getProteinsEncountered() != 4 ) {
5690                 return false;
5691             }
5692             if ( proteins.size() != 4 ) {
5693                 return false;
5694             }
5695             if ( parser2.getDomainsEncountered() != 69 ) {
5696                 return false;
5697             }
5698             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
5699                 return false;
5700             }
5701             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
5702                 return false;
5703             }
5704             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
5705                 return false;
5706             }
5707             final Protein p1 = proteins.get( 0 );
5708             if ( p1.getNumberOfProteinDomains() != 15 ) {
5709                 return false;
5710             }
5711             if ( p1.getLength() != 850 ) {
5712                 return false;
5713             }
5714             final Protein p2 = proteins.get( 1 );
5715             if ( p2.getNumberOfProteinDomains() != 51 ) {
5716                 return false;
5717             }
5718             if ( p2.getLength() != 1291 ) {
5719                 return false;
5720             }
5721             final Protein p3 = proteins.get( 2 );
5722             if ( p3.getNumberOfProteinDomains() != 2 ) {
5723                 return false;
5724             }
5725             final Protein p4 = proteins.get( 3 );
5726             if ( p4.getNumberOfProteinDomains() != 1 ) {
5727                 return false;
5728             }
5729             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
5730                 return false;
5731             }
5732             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
5733                 return false;
5734             }
5735             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
5736                 return false;
5737             }
5738             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
5739                 return false;
5740             }
5741             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
5742                 return false;
5743             }
5744             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
5745                 return false;
5746             }
5747             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
5748                 return false;
5749             }
5750         }
5751         catch ( final Exception e ) {
5752             e.printStackTrace( System.out );
5753             return false;
5754         }
5755         return true;
5756     }
5757
5758     private static boolean testLastExternalNodeMethods() {
5759         try {
5760             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5761             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
5762             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
5763             final PhylogenyNode n1 = t0.getNode( "A" );
5764             if ( n1.isLastExternalNode() ) {
5765                 return false;
5766             }
5767             final PhylogenyNode n2 = t0.getNode( "B" );
5768             if ( n2.isLastExternalNode() ) {
5769                 return false;
5770             }
5771             final PhylogenyNode n3 = t0.getNode( "C" );
5772             if ( n3.isLastExternalNode() ) {
5773                 return false;
5774             }
5775             final PhylogenyNode n4 = t0.getNode( "D" );
5776             if ( !n4.isLastExternalNode() ) {
5777                 return false;
5778             }
5779         }
5780         catch ( final Exception e ) {
5781             e.printStackTrace( System.out );
5782             return false;
5783         }
5784         return true;
5785     }
5786
5787     private static boolean testLevelOrderIterator() {
5788         try {
5789             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5790             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5791             PhylogenyNodeIterator it0;
5792             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
5793                 it0.next();
5794             }
5795             for( it0.reset(); it0.hasNext(); ) {
5796                 it0.next();
5797             }
5798             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
5799             if ( !it.next().getName().equals( "r" ) ) {
5800                 return false;
5801             }
5802             if ( !it.next().getName().equals( "ab" ) ) {
5803                 return false;
5804             }
5805             if ( !it.next().getName().equals( "cd" ) ) {
5806                 return false;
5807             }
5808             if ( !it.next().getName().equals( "A" ) ) {
5809                 return false;
5810             }
5811             if ( !it.next().getName().equals( "B" ) ) {
5812                 return false;
5813             }
5814             if ( !it.next().getName().equals( "C" ) ) {
5815                 return false;
5816             }
5817             if ( !it.next().getName().equals( "D" ) ) {
5818                 return false;
5819             }
5820             if ( it.hasNext() ) {
5821                 return false;
5822             }
5823             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",
5824                                                  new NHXParser() )[ 0 ];
5825             PhylogenyNodeIterator it2;
5826             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
5827                 it2.next();
5828             }
5829             for( it2.reset(); it2.hasNext(); ) {
5830                 it2.next();
5831             }
5832             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
5833             if ( !it3.next().getName().equals( "r" ) ) {
5834                 return false;
5835             }
5836             if ( !it3.next().getName().equals( "abc" ) ) {
5837                 return false;
5838             }
5839             if ( !it3.next().getName().equals( "defg" ) ) {
5840                 return false;
5841             }
5842             if ( !it3.next().getName().equals( "A" ) ) {
5843                 return false;
5844             }
5845             if ( !it3.next().getName().equals( "B" ) ) {
5846                 return false;
5847             }
5848             if ( !it3.next().getName().equals( "C" ) ) {
5849                 return false;
5850             }
5851             if ( !it3.next().getName().equals( "D" ) ) {
5852                 return false;
5853             }
5854             if ( !it3.next().getName().equals( "E" ) ) {
5855                 return false;
5856             }
5857             if ( !it3.next().getName().equals( "F" ) ) {
5858                 return false;
5859             }
5860             if ( !it3.next().getName().equals( "G" ) ) {
5861                 return false;
5862             }
5863             if ( !it3.next().getName().equals( "1" ) ) {
5864                 return false;
5865             }
5866             if ( !it3.next().getName().equals( "2" ) ) {
5867                 return false;
5868             }
5869             if ( !it3.next().getName().equals( "3" ) ) {
5870                 return false;
5871             }
5872             if ( !it3.next().getName().equals( "4" ) ) {
5873                 return false;
5874             }
5875             if ( !it3.next().getName().equals( "5" ) ) {
5876                 return false;
5877             }
5878             if ( !it3.next().getName().equals( "6" ) ) {
5879                 return false;
5880             }
5881             if ( !it3.next().getName().equals( "f1" ) ) {
5882                 return false;
5883             }
5884             if ( !it3.next().getName().equals( "f2" ) ) {
5885                 return false;
5886             }
5887             if ( !it3.next().getName().equals( "f3" ) ) {
5888                 return false;
5889             }
5890             if ( !it3.next().getName().equals( "a" ) ) {
5891                 return false;
5892             }
5893             if ( !it3.next().getName().equals( "b" ) ) {
5894                 return false;
5895             }
5896             if ( !it3.next().getName().equals( "f21" ) ) {
5897                 return false;
5898             }
5899             if ( !it3.next().getName().equals( "X" ) ) {
5900                 return false;
5901             }
5902             if ( !it3.next().getName().equals( "Y" ) ) {
5903                 return false;
5904             }
5905             if ( !it3.next().getName().equals( "Z" ) ) {
5906                 return false;
5907             }
5908             if ( it3.hasNext() ) {
5909                 return false;
5910             }
5911             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
5912             PhylogenyNodeIterator it4;
5913             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
5914                 it4.next();
5915             }
5916             for( it4.reset(); it4.hasNext(); ) {
5917                 it4.next();
5918             }
5919             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
5920             if ( !it5.next().getName().equals( "r" ) ) {
5921                 return false;
5922             }
5923             if ( !it5.next().getName().equals( "A" ) ) {
5924                 return false;
5925             }
5926             if ( !it5.next().getName().equals( "B" ) ) {
5927                 return false;
5928             }
5929             if ( !it5.next().getName().equals( "C" ) ) {
5930                 return false;
5931             }
5932             if ( !it5.next().getName().equals( "D" ) ) {
5933                 return false;
5934             }
5935             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
5936             PhylogenyNodeIterator it6;
5937             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
5938                 it6.next();
5939             }
5940             for( it6.reset(); it6.hasNext(); ) {
5941                 it6.next();
5942             }
5943             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
5944             if ( !it7.next().getName().equals( "A" ) ) {
5945                 return false;
5946             }
5947             if ( it.hasNext() ) {
5948                 return false;
5949             }
5950         }
5951         catch ( final Exception e ) {
5952             e.printStackTrace( System.out );
5953             return false;
5954         }
5955         return true;
5956     }
5957
5958     private static boolean testMafft( final String path ) {
5959         try {
5960             final List<String> opts = new ArrayList<String>();
5961             opts.add( "--maxiterate" );
5962             opts.add( "1000" );
5963             opts.add( "--localpair" );
5964             opts.add( "--quiet" );
5965             Msa msa = null;
5966             final MsaInferrer mafft = Mafft.createInstance( path );
5967             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
5968             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
5969                 return false;
5970             }
5971             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
5972                 return false;
5973             }
5974         }
5975         catch ( final Exception e ) {
5976             e.printStackTrace( System.out );
5977             return false;
5978         }
5979         return true;
5980     }
5981
5982     private static boolean testMidpointrooting() {
5983         try {
5984             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5985             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
5986             PhylogenyMethods.midpointRoot( t0 );
5987             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
5988                 return false;
5989             }
5990             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
5991                 return false;
5992             }
5993             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
5994                            1 ) ) {
5995                 return false;
5996             }
5997             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",
5998                                                  new NHXParser() )[ 0 ];
5999             if ( !t1.isRooted() ) {
6000                 return false;
6001             }
6002             PhylogenyMethods.midpointRoot( t1 );
6003             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6004                 return false;
6005             }
6006             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6007                 return false;
6008             }
6009             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6010                 return false;
6011             }
6012             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6013                 return false;
6014             }
6015             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6016                 return false;
6017             }
6018             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6019                 return false;
6020             }
6021             t1.reRoot( t1.getNode( "A" ) );
6022             PhylogenyMethods.midpointRoot( t1 );
6023             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6024                 return false;
6025             }
6026             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6027                 return false;
6028             }
6029             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6030                 return false;
6031             }
6032             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6033                 return false;
6034             }
6035             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6036                 System.exit( -1 );
6037                 return false;
6038             }
6039             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6040                 return false;
6041             }
6042         }
6043         catch ( final Exception e ) {
6044             e.printStackTrace( System.out );
6045             return false;
6046         }
6047         return true;
6048     }
6049
6050     private static boolean testMsaQualityMethod() {
6051         try {
6052             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6053             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6054             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6055             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6056             final List<Sequence> l = new ArrayList<Sequence>();
6057             l.add( s0 );
6058             l.add( s1 );
6059             l.add( s2 );
6060             l.add( s3 );
6061             final Msa msa = BasicMsa.createInstance( l );
6062             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6063                 return false;
6064             }
6065             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6066                 return false;
6067             }
6068             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6069                 return false;
6070             }
6071             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6072                 return false;
6073             }
6074             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6075                 return false;
6076             }
6077             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6078                 return false;
6079             }
6080             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6081                 return false;
6082             }
6083         }
6084         catch ( final Exception e ) {
6085             e.printStackTrace( System.out );
6086             return false;
6087         }
6088         return true;
6089     }
6090
6091     private static boolean testDeleteableMsa() {
6092         try {
6093             final Sequence s0 = BasicSequence.createAaSequence( "a", "AAAA" );
6094             final Sequence s1 = BasicSequence.createAaSequence( "b", "BAAA" );
6095             final Sequence s2 = BasicSequence.createAaSequence( "c", "CAAA" );
6096             final Sequence s3 = BasicSequence.createAaSequence( "d", "DAAA" );
6097             final Sequence s4 = BasicSequence.createAaSequence( "e", "EAAA" );
6098             final Sequence s5 = BasicSequence.createAaSequence( "f", "FAAA" );
6099             final List<Sequence> l0 = new ArrayList<Sequence>();
6100             l0.add( s0 );
6101             l0.add( s1 );
6102             l0.add( s2 );
6103             l0.add( s3 );
6104             l0.add( s4 );
6105             l0.add( s5 );
6106             final DeleteableMsa dmsa0 = DeleteableMsa.createInstance( l0 );
6107             dmsa0.deleteRow( "b" );
6108             if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) {
6109                 return false;
6110             }
6111             dmsa0.deleteRow( "e" );
6112             dmsa0.deleteRow( "a" );
6113             dmsa0.deleteRow( "f" );
6114             if ( dmsa0.getLength() != 4 ) {
6115                 return false;
6116             }
6117             if ( dmsa0.getNumberOfSequences() != 2 ) {
6118                 return false;
6119             }
6120             if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) {
6121                 return false;
6122             }
6123             if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) {
6124                 return false;
6125             }
6126             if ( dmsa0.getResidueAt( 0, 0 ) != 'C' ) {
6127                 return false;
6128             }
6129             if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" ) ) {
6130                 return false;
6131             }
6132             if ( dmsa0.getColumnAt( 0 ).size() != 2 ) {
6133                 return false;
6134             }
6135             dmsa0.deleteRow( "c" );
6136             dmsa0.deleteRow( "d" );
6137             if ( dmsa0.getNumberOfSequences() != 0 ) {
6138                 return false;
6139             }
6140             //
6141             final Sequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C--X----" );
6142             final Sequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C-------" );
6143             final Sequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C------Z" );
6144             final Sequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C-------" );
6145             final Sequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C-------" );
6146             final Sequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--Y---" );
6147             final List<Sequence> l1 = new ArrayList<Sequence>();
6148             l1.add( s_0 );
6149             l1.add( s_1 );
6150             l1.add( s_2 );
6151             l1.add( s_3 );
6152             l1.add( s_4 );
6153             l1.add( s_5 );
6154             final DeleteableMsa dmsa1 = DeleteableMsa.createInstance( l1 );
6155             dmsa1.deleteGapOnlyColumns();
6156             dmsa1.deleteRow( "a" );
6157             dmsa1.deleteRow( "f" );
6158             dmsa1.deleteRow( "d" );
6159             dmsa1.deleteGapOnlyColumns();
6160             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C-" ) ) {
6161                 return false;
6162             }
6163             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "CABCZ" ) ) {
6164                 return false;
6165             }
6166             if ( !dmsa1.getSequenceAsString( 2 ).toString().equals( "EAAC-" ) ) {
6167                 return false;
6168             }
6169             dmsa1.deleteRow( "c" );
6170             dmsa1.deleteGapOnlyColumns();
6171             final Writer w0 = new StringWriter();
6172             dmsa1.write( w0, MSA_FORMAT.FASTA );
6173             final Writer w1 = new StringWriter();
6174             dmsa1.write( w1, MSA_FORMAT.PHYLIP );
6175             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C" ) ) {
6176                 return false;
6177             }
6178             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "EAAC" ) ) {
6179                 return false;
6180             }
6181             //
6182             final Sequence s__0 = BasicSequence.createAaSequence( "a", "A------" );
6183             final Sequence s__1 = BasicSequence.createAaSequence( "b", "BB-----" );
6184             final Sequence s__2 = BasicSequence.createAaSequence( "c", "CCC----" );
6185             final Sequence s__3 = BasicSequence.createAaSequence( "d", "DDDD---" );
6186             final Sequence s__4 = BasicSequence.createAaSequence( "e", "EEEEE--" );
6187             final Sequence s__5 = BasicSequence.createAaSequence( "f", "FFFFFF-" );
6188             final List<Sequence> l2 = new ArrayList<Sequence>();
6189             l2.add( s__0 );
6190             l2.add( s__1 );
6191             l2.add( s__2 );
6192             l2.add( s__3 );
6193             l2.add( s__4 );
6194             l2.add( s__5 );
6195             final DeleteableMsa dmsa2 = DeleteableMsa.createInstance( l2 );
6196             dmsa2.deleteGapColumns( 0.5 );
6197             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A---" ) ) {
6198                 return false;
6199             }
6200             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB--" ) ) {
6201                 return false;
6202             }
6203             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CCC-" ) ) {
6204                 return false;
6205             }
6206             dmsa2.deleteGapColumns( 0.2 );
6207             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A-" ) ) {
6208                 return false;
6209             }
6210             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB" ) ) {
6211                 return false;
6212             }
6213             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CC" ) ) {
6214                 return false;
6215             }
6216             dmsa2.deleteGapColumns( 0 );
6217             dmsa2.deleteRow( "a" );
6218             dmsa2.deleteRow( "b" );
6219             dmsa2.deleteRow( "f" );
6220             dmsa2.deleteRow( "e" );
6221             dmsa2.setIdentifier( 0, "new_c" );
6222             dmsa2.setIdentifier( 1, "new_d" );
6223             dmsa2.setResidueAt( 0, 0, 'x' );
6224             dmsa2.deleteRow( "new_d" );
6225             final Writer w = new StringWriter();
6226             dmsa2.write( w, MSA_FORMAT.PHYLIP );
6227             final String phylip = w.toString();
6228             if ( !phylip.equals( "new_c x" + ForesterUtil.LINE_SEPARATOR ) ) {
6229                 return false;
6230             }
6231             final Writer w2 = new StringWriter();
6232             dmsa2.write( w2, MSA_FORMAT.FASTA );
6233             final String fasta = w2.toString();
6234             if ( !fasta.equals( ">new_c" + ForesterUtil.LINE_SEPARATOR + "x" + ForesterUtil.LINE_SEPARATOR ) ) {
6235                 return false;
6236             }
6237         }
6238         catch ( final Exception e ) {
6239             e.printStackTrace( System.out );
6240             return false;
6241         }
6242         return true;
6243     }
6244
6245     private static boolean testNextNodeWithCollapsing() {
6246         try {
6247             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6248             PhylogenyNode n;
6249             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
6250             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6251             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
6252             t0.getNode( "cd" ).setCollapse( true );
6253             t0.getNode( "cde" ).setCollapse( true );
6254             n = t0.getFirstExternalNode();
6255             while ( n != null ) {
6256                 ext.add( n );
6257                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6258             }
6259             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6260                 return false;
6261             }
6262             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6263                 return false;
6264             }
6265             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
6266                 return false;
6267             }
6268             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
6269                 return false;
6270             }
6271             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
6272                 return false;
6273             }
6274             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
6275                 return false;
6276             }
6277             ext.clear();
6278             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6279             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
6280             t1.getNode( "ab" ).setCollapse( true );
6281             t1.getNode( "cd" ).setCollapse( true );
6282             t1.getNode( "cde" ).setCollapse( true );
6283             n = t1.getNode( "ab" );
6284             ext = new ArrayList<PhylogenyNode>();
6285             while ( n != null ) {
6286                 ext.add( n );
6287                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6288             }
6289             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6290                 return false;
6291             }
6292             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6293                 return false;
6294             }
6295             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6296                 return false;
6297             }
6298             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
6299                 return false;
6300             }
6301             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
6302                 return false;
6303             }
6304             //
6305             //
6306             ext.clear();
6307             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6308             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
6309             t2.getNode( "ab" ).setCollapse( true );
6310             t2.getNode( "cd" ).setCollapse( true );
6311             t2.getNode( "cde" ).setCollapse( true );
6312             t2.getNode( "c" ).setCollapse( true );
6313             t2.getNode( "d" ).setCollapse( true );
6314             t2.getNode( "e" ).setCollapse( true );
6315             t2.getNode( "gh" ).setCollapse( true );
6316             n = t2.getNode( "ab" );
6317             ext = new ArrayList<PhylogenyNode>();
6318             while ( n != null ) {
6319                 ext.add( n );
6320                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6321             }
6322             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6323                 return false;
6324             }
6325             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6326                 return false;
6327             }
6328             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6329                 return false;
6330             }
6331             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
6332                 return false;
6333             }
6334             //
6335             //
6336             ext.clear();
6337             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6338             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
6339             t3.getNode( "ab" ).setCollapse( true );
6340             t3.getNode( "cd" ).setCollapse( true );
6341             t3.getNode( "cde" ).setCollapse( true );
6342             t3.getNode( "c" ).setCollapse( true );
6343             t3.getNode( "d" ).setCollapse( true );
6344             t3.getNode( "e" ).setCollapse( true );
6345             t3.getNode( "gh" ).setCollapse( true );
6346             t3.getNode( "fgh" ).setCollapse( true );
6347             n = t3.getNode( "ab" );
6348             ext = new ArrayList<PhylogenyNode>();
6349             while ( n != null ) {
6350                 ext.add( n );
6351                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6352             }
6353             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6354                 return false;
6355             }
6356             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6357                 return false;
6358             }
6359             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
6360                 return false;
6361             }
6362             //
6363             //
6364             ext.clear();
6365             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6366             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
6367             t4.getNode( "ab" ).setCollapse( true );
6368             t4.getNode( "cd" ).setCollapse( true );
6369             t4.getNode( "cde" ).setCollapse( true );
6370             t4.getNode( "c" ).setCollapse( true );
6371             t4.getNode( "d" ).setCollapse( true );
6372             t4.getNode( "e" ).setCollapse( true );
6373             t4.getNode( "gh" ).setCollapse( true );
6374             t4.getNode( "fgh" ).setCollapse( true );
6375             t4.getNode( "abcdefgh" ).setCollapse( true );
6376             n = t4.getNode( "abcdefgh" );
6377             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
6378                 return false;
6379             }
6380             //
6381             //
6382             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6383             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
6384             ext.clear();
6385             n = t5.getFirstExternalNode();
6386             while ( n != null ) {
6387                 ext.add( n );
6388                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6389             }
6390             if ( ext.size() != 8 ) {
6391                 return false;
6392             }
6393             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6394                 return false;
6395             }
6396             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6397                 return false;
6398             }
6399             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6400                 return false;
6401             }
6402             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6403                 return false;
6404             }
6405             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6406                 return false;
6407             }
6408             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6409                 return false;
6410             }
6411             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
6412                 return false;
6413             }
6414             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
6415                 return false;
6416             }
6417             //
6418             //
6419             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6420             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
6421             ext.clear();
6422             t6.getNode( "ab" ).setCollapse( true );
6423             n = t6.getNode( "ab" );
6424             while ( n != null ) {
6425                 ext.add( n );
6426                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6427             }
6428             if ( ext.size() != 7 ) {
6429                 return false;
6430             }
6431             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6432                 return false;
6433             }
6434             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6435                 return false;
6436             }
6437             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6438                 return false;
6439             }
6440             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6441                 return false;
6442             }
6443             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6444                 return false;
6445             }
6446             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6447                 return false;
6448             }
6449             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6450                 return false;
6451             }
6452             //
6453             //
6454             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6455             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
6456             ext.clear();
6457             t7.getNode( "cd" ).setCollapse( true );
6458             n = t7.getNode( "a" );
6459             while ( n != null ) {
6460                 ext.add( n );
6461                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6462             }
6463             if ( ext.size() != 7 ) {
6464                 return false;
6465             }
6466             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6467                 return false;
6468             }
6469             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6470                 return false;
6471             }
6472             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6473                 return false;
6474             }
6475             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6476                 return false;
6477             }
6478             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6479                 return false;
6480             }
6481             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6482                 return false;
6483             }
6484             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6485                 return false;
6486             }
6487             //
6488             //
6489             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6490             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
6491             ext.clear();
6492             t8.getNode( "cd" ).setCollapse( true );
6493             t8.getNode( "c" ).setCollapse( true );
6494             t8.getNode( "d" ).setCollapse( true );
6495             n = t8.getNode( "a" );
6496             while ( n != null ) {
6497                 ext.add( n );
6498                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6499             }
6500             if ( ext.size() != 7 ) {
6501                 return false;
6502             }
6503             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6504                 return false;
6505             }
6506             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6507                 return false;
6508             }
6509             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6510                 System.out.println( "2 fail" );
6511                 return false;
6512             }
6513             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6514                 return false;
6515             }
6516             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6517                 return false;
6518             }
6519             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6520                 return false;
6521             }
6522             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6523                 return false;
6524             }
6525             //
6526             //
6527             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6528             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
6529             ext.clear();
6530             t9.getNode( "gh" ).setCollapse( true );
6531             n = t9.getNode( "a" );
6532             while ( n != null ) {
6533                 ext.add( n );
6534                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6535             }
6536             if ( ext.size() != 7 ) {
6537                 return false;
6538             }
6539             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6540                 return false;
6541             }
6542             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6543                 return false;
6544             }
6545             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6546                 return false;
6547             }
6548             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6549                 return false;
6550             }
6551             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6552                 return false;
6553             }
6554             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6555                 return false;
6556             }
6557             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6558                 return false;
6559             }
6560             //
6561             //
6562             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6563             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
6564             ext.clear();
6565             t10.getNode( "gh" ).setCollapse( true );
6566             t10.getNode( "g" ).setCollapse( true );
6567             t10.getNode( "h" ).setCollapse( true );
6568             n = t10.getNode( "a" );
6569             while ( n != null ) {
6570                 ext.add( n );
6571                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6572             }
6573             if ( ext.size() != 7 ) {
6574                 return false;
6575             }
6576             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6577                 return false;
6578             }
6579             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6580                 return false;
6581             }
6582             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6583                 return false;
6584             }
6585             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6586                 return false;
6587             }
6588             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6589                 return false;
6590             }
6591             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6592                 return false;
6593             }
6594             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6595                 return false;
6596             }
6597             //
6598             //
6599             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6600             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
6601             ext.clear();
6602             t11.getNode( "gh" ).setCollapse( true );
6603             t11.getNode( "fgh" ).setCollapse( true );
6604             n = t11.getNode( "a" );
6605             while ( n != null ) {
6606                 ext.add( n );
6607                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6608             }
6609             if ( ext.size() != 6 ) {
6610                 return false;
6611             }
6612             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6613                 return false;
6614             }
6615             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6616                 return false;
6617             }
6618             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6619                 return false;
6620             }
6621             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6622                 return false;
6623             }
6624             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6625                 return false;
6626             }
6627             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6628                 return false;
6629             }
6630             //
6631             //
6632             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6633             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
6634             ext.clear();
6635             t12.getNode( "gh" ).setCollapse( true );
6636             t12.getNode( "fgh" ).setCollapse( true );
6637             t12.getNode( "g" ).setCollapse( true );
6638             t12.getNode( "h" ).setCollapse( true );
6639             t12.getNode( "f" ).setCollapse( true );
6640             n = t12.getNode( "a" );
6641             while ( n != null ) {
6642                 ext.add( n );
6643                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6644             }
6645             if ( ext.size() != 6 ) {
6646                 return false;
6647             }
6648             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6649                 return false;
6650             }
6651             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6652                 return false;
6653             }
6654             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6655                 return false;
6656             }
6657             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6658                 return false;
6659             }
6660             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6661                 return false;
6662             }
6663             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6664                 return false;
6665             }
6666             //
6667             //
6668             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6669             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
6670             ext.clear();
6671             t13.getNode( "ab" ).setCollapse( true );
6672             t13.getNode( "b" ).setCollapse( true );
6673             t13.getNode( "fgh" ).setCollapse( true );
6674             t13.getNode( "gh" ).setCollapse( true );
6675             n = t13.getNode( "ab" );
6676             while ( n != null ) {
6677                 ext.add( n );
6678                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6679             }
6680             if ( ext.size() != 5 ) {
6681                 return false;
6682             }
6683             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6684                 return false;
6685             }
6686             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6687                 return false;
6688             }
6689             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6690                 return false;
6691             }
6692             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6693                 return false;
6694             }
6695             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6696                 return false;
6697             }
6698             //
6699             //
6700             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
6701             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
6702             ext.clear();
6703             t14.getNode( "ab" ).setCollapse( true );
6704             t14.getNode( "a" ).setCollapse( true );
6705             t14.getNode( "fgh" ).setCollapse( true );
6706             t14.getNode( "gh" ).setCollapse( true );
6707             n = t14.getNode( "ab" );
6708             while ( n != null ) {
6709                 ext.add( n );
6710                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6711             }
6712             if ( ext.size() != 5 ) {
6713                 return false;
6714             }
6715             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6716                 return false;
6717             }
6718             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6719                 return false;
6720             }
6721             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6722                 return false;
6723             }
6724             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6725                 return false;
6726             }
6727             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6728                 return false;
6729             }
6730             //
6731             //
6732             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" );
6733             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
6734             ext.clear();
6735             t15.getNode( "ab" ).setCollapse( true );
6736             t15.getNode( "a" ).setCollapse( true );
6737             t15.getNode( "fgh" ).setCollapse( true );
6738             t15.getNode( "gh" ).setCollapse( true );
6739             n = t15.getNode( "ab" );
6740             while ( n != null ) {
6741                 ext.add( n );
6742                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6743             }
6744             if ( ext.size() != 6 ) {
6745                 return false;
6746             }
6747             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6748                 return false;
6749             }
6750             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6751                 return false;
6752             }
6753             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6754                 return false;
6755             }
6756             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6757                 return false;
6758             }
6759             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
6760                 return false;
6761             }
6762             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6763                 return false;
6764             }
6765             //
6766             //
6767             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" );
6768             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
6769             ext.clear();
6770             t16.getNode( "ab" ).setCollapse( true );
6771             t16.getNode( "a" ).setCollapse( true );
6772             t16.getNode( "fgh" ).setCollapse( true );
6773             t16.getNode( "gh" ).setCollapse( true );
6774             t16.getNode( "cd" ).setCollapse( true );
6775             t16.getNode( "cde" ).setCollapse( true );
6776             t16.getNode( "d" ).setCollapse( true );
6777             t16.getNode( "x" ).setCollapse( true );
6778             n = t16.getNode( "ab" );
6779             while ( n != null ) {
6780                 ext.add( n );
6781                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6782             }
6783             if ( ext.size() != 4 ) {
6784                 return false;
6785             }
6786             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6787                 return false;
6788             }
6789             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6790                 return false;
6791             }
6792             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
6793                 return false;
6794             }
6795             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
6796                 return false;
6797             }
6798         }
6799         catch ( final Exception e ) {
6800             e.printStackTrace( System.out );
6801             return false;
6802         }
6803         return true;
6804     }
6805
6806     private static boolean testNexusCharactersParsing() {
6807         try {
6808             final NexusCharactersParser parser = new NexusCharactersParser();
6809             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
6810             parser.parse();
6811             String[] labels = parser.getCharStateLabels();
6812             if ( labels.length != 7 ) {
6813                 return false;
6814             }
6815             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6816                 return false;
6817             }
6818             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6819                 return false;
6820             }
6821             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6822                 return false;
6823             }
6824             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6825                 return false;
6826             }
6827             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6828                 return false;
6829             }
6830             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6831                 return false;
6832             }
6833             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6834                 return false;
6835             }
6836             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6837             parser.parse();
6838             labels = parser.getCharStateLabels();
6839             if ( labels.length != 7 ) {
6840                 return false;
6841             }
6842             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6843                 return false;
6844             }
6845             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6846                 return false;
6847             }
6848             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6849                 return false;
6850             }
6851             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6852                 return false;
6853             }
6854             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6855                 return false;
6856             }
6857             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6858                 return false;
6859             }
6860             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6861                 return false;
6862             }
6863         }
6864         catch ( final Exception e ) {
6865             e.printStackTrace( System.out );
6866             return false;
6867         }
6868         return true;
6869     }
6870
6871     private static boolean testNexusMatrixParsing() {
6872         try {
6873             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
6874             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
6875             parser.parse();
6876             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
6877             if ( m.getNumberOfCharacters() != 9 ) {
6878                 return false;
6879             }
6880             if ( m.getNumberOfIdentifiers() != 5 ) {
6881                 return false;
6882             }
6883             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
6884                 return false;
6885             }
6886             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
6887                 return false;
6888             }
6889             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
6890                 return false;
6891             }
6892             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
6893                 return false;
6894             }
6895             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
6896                 return false;
6897             }
6898             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
6899                 return false;
6900             }
6901             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
6902                 return false;
6903             }
6904             //            if ( labels.length != 7 ) {
6905             //                return false;
6906             //            }
6907             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6908             //                return false;
6909             //            }
6910             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6911             //                return false;
6912             //            }
6913             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6914             //                return false;
6915             //            }
6916             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6917             //                return false;
6918             //            }
6919             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6920             //                return false;
6921             //            }
6922             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6923             //                return false;
6924             //            }
6925             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6926             //                return false;
6927             //            }
6928             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6929             //            parser.parse();
6930             //            labels = parser.getCharStateLabels();
6931             //            if ( labels.length != 7 ) {
6932             //                return false;
6933             //            }
6934             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6935             //                return false;
6936             //            }
6937             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6938             //                return false;
6939             //            }
6940             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6941             //                return false;
6942             //            }
6943             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6944             //                return false;
6945             //            }
6946             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6947             //                return false;
6948             //            }
6949             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6950             //                return false;
6951             //            }
6952             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6953             //                return false;
6954             //            }
6955         }
6956         catch ( final Exception e ) {
6957             e.printStackTrace( System.out );
6958             return false;
6959         }
6960         return true;
6961     }
6962
6963     private static boolean testNexusTreeParsing() {
6964         try {
6965             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6966             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
6967             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
6968             if ( phylogenies.length != 1 ) {
6969                 return false;
6970             }
6971             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
6972                 return false;
6973             }
6974             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6975                 return false;
6976             }
6977             phylogenies = null;
6978             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
6979             if ( phylogenies.length != 1 ) {
6980                 return false;
6981             }
6982             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6983                 return false;
6984             }
6985             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
6986                 return false;
6987             }
6988             phylogenies = null;
6989             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
6990             if ( phylogenies.length != 1 ) {
6991                 return false;
6992             }
6993             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6994                 return false;
6995             }
6996             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6997                 return false;
6998             }
6999             if ( phylogenies[ 0 ].isRooted() ) {
7000                 return false;
7001             }
7002             phylogenies = null;
7003             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
7004             if ( phylogenies.length != 18 ) {
7005                 return false;
7006             }
7007             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7008                 return false;
7009             }
7010             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
7011                 return false;
7012             }
7013             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
7014                 return false;
7015             }
7016             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
7017                 return false;
7018             }
7019             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7020                 return false;
7021             }
7022             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
7023                 return false;
7024             }
7025             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
7026                 return false;
7027             }
7028             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
7029                 return false;
7030             }
7031             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
7032                 return false;
7033             }
7034             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
7035                 return false;
7036             }
7037             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
7038                 return false;
7039             }
7040             if ( phylogenies[ 8 ].isRooted() ) {
7041                 return false;
7042             }
7043             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
7044                 return false;
7045             }
7046             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
7047                 return false;
7048             }
7049             if ( !phylogenies[ 9 ].isRooted() ) {
7050                 return false;
7051             }
7052             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
7053                 return false;
7054             }
7055             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
7056                 return false;
7057             }
7058             if ( !phylogenies[ 10 ].isRooted() ) {
7059                 return false;
7060             }
7061             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
7062                 return false;
7063             }
7064             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
7065                 return false;
7066             }
7067             if ( phylogenies[ 11 ].isRooted() ) {
7068                 return false;
7069             }
7070             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
7071                 return false;
7072             }
7073             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
7074                 return false;
7075             }
7076             if ( !phylogenies[ 12 ].isRooted() ) {
7077                 return false;
7078             }
7079             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
7080                 return false;
7081             }
7082             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
7083                 return false;
7084             }
7085             if ( !phylogenies[ 13 ].isRooted() ) {
7086                 return false;
7087             }
7088             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
7089                 return false;
7090             }
7091             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
7092                 return false;
7093             }
7094             if ( !phylogenies[ 14 ].isRooted() ) {
7095                 return false;
7096             }
7097             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
7098                 return false;
7099             }
7100             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
7101                 return false;
7102             }
7103             if ( phylogenies[ 15 ].isRooted() ) {
7104                 return false;
7105             }
7106             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
7107                 return false;
7108             }
7109             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
7110                 return false;
7111             }
7112             if ( !phylogenies[ 16 ].isRooted() ) {
7113                 return false;
7114             }
7115             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
7116                 return false;
7117             }
7118             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
7119                 return false;
7120             }
7121             if ( phylogenies[ 17 ].isRooted() ) {
7122                 return false;
7123             }
7124             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
7125                 return false;
7126             }
7127             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7128             phylogenies = null;
7129             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
7130             if ( phylogenies.length != 9 ) {
7131                 return false;
7132             }
7133             if ( !isEqual( 0.48039661496919533, phylogenies[ 0 ].getNode( "Diadocidia_spinosula" )
7134                     .getDistanceToParent() ) ) {
7135                 return false;
7136             }
7137             if ( !isEqual( 0.3959796191512233, phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" )
7138                     .getDistanceToParent() ) ) {
7139                 return false;
7140             }
7141             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
7142                 return false;
7143             }
7144             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7145                 return false;
7146             }
7147             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7148                 return false;
7149             }
7150             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7151                 return false;
7152             }
7153             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7154                 return false;
7155             }
7156         }
7157         catch ( final Exception e ) {
7158             e.printStackTrace( System.out );
7159             return false;
7160         }
7161         return true;
7162     }
7163
7164     private static boolean testNexusTreeParsingIterating() {
7165         try {
7166             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
7167             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
7168             if ( !p.hasNext() ) {
7169                 return false;
7170             }
7171             Phylogeny phy = p.next();
7172             if ( phy == null ) {
7173                 return false;
7174             }
7175             if ( phy.getNumberOfExternalNodes() != 25 ) {
7176                 return false;
7177             }
7178             if ( !phy.getName().equals( "" ) ) {
7179                 return false;
7180             }
7181             if ( p.hasNext() ) {
7182                 return false;
7183             }
7184             phy = p.next();
7185             if ( phy != null ) {
7186                 return false;
7187             }
7188             //
7189             p.reset();
7190             if ( !p.hasNext() ) {
7191                 return false;
7192             }
7193             phy = p.next();
7194             if ( phy == null ) {
7195                 return false;
7196             }
7197             if ( phy.getNumberOfExternalNodes() != 25 ) {
7198                 return false;
7199             }
7200             if ( !phy.getName().equals( "" ) ) {
7201                 return false;
7202             }
7203             if ( p.hasNext() ) {
7204                 return false;
7205             }
7206             phy = p.next();
7207             if ( phy != null ) {
7208                 return false;
7209             }
7210             ////
7211             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
7212             if ( !p.hasNext() ) {
7213                 return false;
7214             }
7215             phy = p.next();
7216             if ( phy == null ) {
7217                 return false;
7218             }
7219             if ( phy.getNumberOfExternalNodes() != 10 ) {
7220                 return false;
7221             }
7222             if ( !phy.getName().equals( "name" ) ) {
7223                 return false;
7224             }
7225             if ( p.hasNext() ) {
7226                 return false;
7227             }
7228             phy = p.next();
7229             if ( phy != null ) {
7230                 return false;
7231             }
7232             //
7233             p.reset();
7234             if ( !p.hasNext() ) {
7235                 return false;
7236             }
7237             phy = p.next();
7238             if ( phy == null ) {
7239                 return false;
7240             }
7241             if ( phy.getNumberOfExternalNodes() != 10 ) {
7242                 return false;
7243             }
7244             if ( !phy.getName().equals( "name" ) ) {
7245                 return false;
7246             }
7247             if ( p.hasNext() ) {
7248                 return false;
7249             }
7250             phy = p.next();
7251             if ( phy != null ) {
7252                 return false;
7253             }
7254             //
7255             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
7256             if ( !p.hasNext() ) {
7257                 return false;
7258             }
7259             phy = p.next();
7260             if ( phy == null ) {
7261                 return false;
7262             }
7263             if ( phy.getNumberOfExternalNodes() != 3 ) {
7264                 return false;
7265             }
7266             if ( !phy.getName().equals( "" ) ) {
7267                 return false;
7268             }
7269             if ( phy.isRooted() ) {
7270                 return false;
7271             }
7272             if ( p.hasNext() ) {
7273                 return false;
7274             }
7275             phy = p.next();
7276             if ( phy != null ) {
7277                 return false;
7278             }
7279             //
7280             p.reset();
7281             if ( !p.hasNext() ) {
7282                 return false;
7283             }
7284             phy = p.next();
7285             if ( phy == null ) {
7286                 return false;
7287             }
7288             if ( phy.getNumberOfExternalNodes() != 3 ) {
7289                 return false;
7290             }
7291             if ( !phy.getName().equals( "" ) ) {
7292                 return false;
7293             }
7294             if ( p.hasNext() ) {
7295                 return false;
7296             }
7297             phy = p.next();
7298             if ( phy != null ) {
7299                 return false;
7300             }
7301             //
7302             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
7303             if ( !p.hasNext() ) {
7304                 return false;
7305             }
7306             //0
7307             phy = p.next();
7308             if ( phy == null ) {
7309                 return false;
7310             }
7311             if ( phy.getNumberOfExternalNodes() != 10 ) {
7312                 return false;
7313             }
7314             if ( !phy.getName().equals( "tree 0" ) ) {
7315                 return false;
7316             }
7317             //1
7318             if ( !p.hasNext() ) {
7319                 return false;
7320             }
7321             phy = p.next();
7322             if ( phy == null ) {
7323                 return false;
7324             }
7325             if ( phy.getNumberOfExternalNodes() != 10 ) {
7326                 return false;
7327             }
7328             if ( !phy.getName().equals( "tree 1" ) ) {
7329                 return false;
7330             }
7331             //2
7332             if ( !p.hasNext() ) {
7333                 return false;
7334             }
7335             phy = p.next();
7336             if ( phy == null ) {
7337                 return false;
7338             }
7339             if ( phy.getNumberOfExternalNodes() != 3 ) {
7340                 System.out.println( phy.toString() );
7341                 return false;
7342             }
7343             if ( !phy.getName().equals( "" ) ) {
7344                 return false;
7345             }
7346             if ( phy.isRooted() ) {
7347                 return false;
7348             }
7349             //3
7350             if ( !p.hasNext() ) {
7351                 return false;
7352             }
7353             phy = p.next();
7354             if ( phy == null ) {
7355                 return false;
7356             }
7357             if ( phy.getNumberOfExternalNodes() != 4 ) {
7358                 return false;
7359             }
7360             if ( !phy.getName().equals( "" ) ) {
7361                 return false;
7362             }
7363             if ( !phy.isRooted() ) {
7364                 return false;
7365             }
7366             //4
7367             if ( !p.hasNext() ) {
7368                 return false;
7369             }
7370             phy = p.next();
7371             if ( phy == null ) {
7372                 return false;
7373             }
7374             if ( phy.getNumberOfExternalNodes() != 5 ) {
7375                 System.out.println( phy.getNumberOfExternalNodes() );
7376                 return false;
7377             }
7378             if ( !phy.getName().equals( "" ) ) {
7379                 return false;
7380             }
7381             if ( !phy.isRooted() ) {
7382                 return false;
7383             }
7384             //5
7385             if ( !p.hasNext() ) {
7386                 return false;
7387             }
7388             phy = p.next();
7389             if ( phy == null ) {
7390                 return false;
7391             }
7392             if ( phy.getNumberOfExternalNodes() != 3 ) {
7393                 return false;
7394             }
7395             if ( !phy.getName().equals( "" ) ) {
7396                 return false;
7397             }
7398             if ( phy.isRooted() ) {
7399                 return false;
7400             }
7401             //6
7402             if ( !p.hasNext() ) {
7403                 return false;
7404             }
7405             phy = p.next();
7406             if ( phy == null ) {
7407                 return false;
7408             }
7409             if ( phy.getNumberOfExternalNodes() != 2 ) {
7410                 return false;
7411             }
7412             if ( !phy.getName().equals( "" ) ) {
7413                 return false;
7414             }
7415             if ( !phy.isRooted() ) {
7416                 return false;
7417             }
7418             //7
7419             if ( !p.hasNext() ) {
7420                 return false;
7421             }
7422             phy = p.next();
7423             if ( phy.getNumberOfExternalNodes() != 3 ) {
7424                 return false;
7425             }
7426             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7427                 return false;
7428             }
7429             if ( !phy.isRooted() ) {
7430                 return false;
7431             }
7432             //8
7433             if ( !p.hasNext() ) {
7434                 return false;
7435             }
7436             phy = p.next();
7437             if ( phy.getNumberOfExternalNodes() != 3 ) {
7438                 return false;
7439             }
7440             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
7441                 return false;
7442             }
7443             if ( !phy.getName().equals( "tree 8" ) ) {
7444                 return false;
7445             }
7446             //9
7447             if ( !p.hasNext() ) {
7448                 return false;
7449             }
7450             phy = p.next();
7451             if ( phy.getNumberOfExternalNodes() != 3 ) {
7452                 return false;
7453             }
7454             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
7455                 return false;
7456             }
7457             if ( !phy.getName().equals( "tree 9" ) ) {
7458                 return false;
7459             }
7460             //10
7461             if ( !p.hasNext() ) {
7462                 return false;
7463             }
7464             phy = p.next();
7465             if ( phy.getNumberOfExternalNodes() != 3 ) {
7466                 return false;
7467             }
7468             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7469                 return false;
7470             }
7471             if ( !phy.getName().equals( "tree 10" ) ) {
7472                 return false;
7473             }
7474             if ( !phy.isRooted() ) {
7475                 return false;
7476             }
7477             //11
7478             if ( !p.hasNext() ) {
7479                 return false;
7480             }
7481             phy = p.next();
7482             if ( phy.getNumberOfExternalNodes() != 3 ) {
7483                 return false;
7484             }
7485             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
7486                 return false;
7487             }
7488             if ( !phy.getName().equals( "tree 11" ) ) {
7489                 return false;
7490             }
7491             if ( phy.isRooted() ) {
7492                 return false;
7493             }
7494             //12
7495             if ( !p.hasNext() ) {
7496                 return false;
7497             }
7498             phy = p.next();
7499             if ( phy.getNumberOfExternalNodes() != 3 ) {
7500                 return false;
7501             }
7502             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
7503                 return false;
7504             }
7505             if ( !phy.getName().equals( "tree 12" ) ) {
7506                 return false;
7507             }
7508             if ( !phy.isRooted() ) {
7509                 return false;
7510             }
7511             //13
7512             if ( !p.hasNext() ) {
7513                 return false;
7514             }
7515             phy = p.next();
7516             if ( phy.getNumberOfExternalNodes() != 3 ) {
7517                 return false;
7518             }
7519             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7520                 return false;
7521             }
7522             if ( !phy.getName().equals( "tree 13" ) ) {
7523                 return false;
7524             }
7525             if ( !phy.isRooted() ) {
7526                 return false;
7527             }
7528             //14
7529             if ( !p.hasNext() ) {
7530                 return false;
7531             }
7532             phy = p.next();
7533             if ( phy.getNumberOfExternalNodes() != 10 ) {
7534                 System.out.println( phy.getNumberOfExternalNodes() );
7535                 return false;
7536             }
7537             if ( !phy
7538                     .toNewHampshire()
7539                     .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;" ) ) {
7540                 System.out.println( phy.toNewHampshire() );
7541                 return false;
7542             }
7543             if ( !phy.getName().equals( "tree 14" ) ) {
7544                 return false;
7545             }
7546             if ( !phy.isRooted() ) {
7547                 return false;
7548             }
7549             //15
7550             if ( !p.hasNext() ) {
7551                 return false;
7552             }
7553             phy = p.next();
7554             if ( phy.getNumberOfExternalNodes() != 10 ) {
7555                 System.out.println( phy.getNumberOfExternalNodes() );
7556                 return false;
7557             }
7558             if ( !phy
7559                     .toNewHampshire()
7560                     .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;" ) ) {
7561                 System.out.println( phy.toNewHampshire() );
7562                 return false;
7563             }
7564             if ( !phy.getName().equals( "tree 15" ) ) {
7565                 return false;
7566             }
7567             if ( phy.isRooted() ) {
7568                 return false;
7569             }
7570             //16
7571             if ( !p.hasNext() ) {
7572                 return false;
7573             }
7574             phy = p.next();
7575             if ( phy.getNumberOfExternalNodes() != 10 ) {
7576                 System.out.println( phy.getNumberOfExternalNodes() );
7577                 return false;
7578             }
7579             if ( !phy
7580                     .toNewHampshire()
7581                     .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;" ) ) {
7582                 System.out.println( phy.toNewHampshire() );
7583                 return false;
7584             }
7585             if ( !phy.getName().equals( "tree 16" ) ) {
7586                 return false;
7587             }
7588             if ( !phy.isRooted() ) {
7589                 return false;
7590             }
7591             //17
7592             if ( !p.hasNext() ) {
7593                 return false;
7594             }
7595             phy = p.next();
7596             if ( phy.getNumberOfExternalNodes() != 10 ) {
7597                 System.out.println( phy.getNumberOfExternalNodes() );
7598                 return false;
7599             }
7600             if ( !phy
7601                     .toNewHampshire()
7602                     .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;" ) ) {
7603                 System.out.println( phy.toNewHampshire() );
7604                 return false;
7605             }
7606             if ( !phy.getName().equals( "tree 17" ) ) {
7607                 return false;
7608             }
7609             if ( phy.isRooted() ) {
7610                 return false;
7611             }
7612             //
7613             if ( p.hasNext() ) {
7614                 return false;
7615             }
7616             phy = p.next();
7617             if ( phy != null ) {
7618                 return false;
7619             }
7620             p.reset();
7621             //0
7622             if ( !p.hasNext() ) {
7623                 return false;
7624             }
7625             phy = p.next();
7626             if ( phy == null ) {
7627                 return false;
7628             }
7629             if ( phy.getNumberOfExternalNodes() != 10 ) {
7630                 return false;
7631             }
7632             if ( !phy.getName().equals( "tree 0" ) ) {
7633                 return false;
7634             }
7635             //1
7636             if ( !p.hasNext() ) {
7637                 return false;
7638             }
7639             phy = p.next();
7640             if ( phy == null ) {
7641                 return false;
7642             }
7643             if ( phy.getNumberOfExternalNodes() != 10 ) {
7644                 return false;
7645             }
7646             if ( !phy.getName().equals( "tree 1" ) ) {
7647                 return false;
7648             }
7649             //2
7650             if ( !p.hasNext() ) {
7651                 return false;
7652             }
7653             phy = p.next();
7654             if ( phy == null ) {
7655                 return false;
7656             }
7657             if ( phy.getNumberOfExternalNodes() != 3 ) {
7658                 return false;
7659             }
7660             if ( !phy.getName().equals( "" ) ) {
7661                 return false;
7662             }
7663             if ( phy.isRooted() ) {
7664                 return false;
7665             }
7666             //3
7667             if ( !p.hasNext() ) {
7668                 return false;
7669             }
7670             phy = p.next();
7671             if ( phy == null ) {
7672                 return false;
7673             }
7674             if ( phy.getNumberOfExternalNodes() != 4 ) {
7675                 return false;
7676             }
7677             if ( !phy.getName().equals( "" ) ) {
7678                 return false;
7679             }
7680             if ( !phy.isRooted() ) {
7681                 return false;
7682             }
7683             //4
7684             if ( !p.hasNext() ) {
7685                 return false;
7686             }
7687             phy = p.next();
7688             if ( phy == null ) {
7689                 return false;
7690             }
7691             if ( phy.getNumberOfExternalNodes() != 5 ) {
7692                 System.out.println( phy.getNumberOfExternalNodes() );
7693                 return false;
7694             }
7695             if ( !phy.getName().equals( "" ) ) {
7696                 return false;
7697             }
7698             if ( !phy.isRooted() ) {
7699                 return false;
7700             }
7701             //5
7702             if ( !p.hasNext() ) {
7703                 return false;
7704             }
7705             phy = p.next();
7706             if ( phy == null ) {
7707                 return false;
7708             }
7709             if ( phy.getNumberOfExternalNodes() != 3 ) {
7710                 return false;
7711             }
7712             if ( !phy.getName().equals( "" ) ) {
7713                 return false;
7714             }
7715             if ( phy.isRooted() ) {
7716                 return false;
7717             }
7718             //
7719             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7720             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
7721             // 0
7722             if ( !p2.hasNext() ) {
7723                 return false;
7724             }
7725             phy = p2.next();
7726             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7727                 return false;
7728             }
7729             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7730                 return false;
7731             }
7732             // 1
7733             if ( !p2.hasNext() ) {
7734                 return false;
7735             }
7736             phy = p2.next();
7737             // 2
7738             if ( !p2.hasNext() ) {
7739                 return false;
7740             }
7741             phy = p2.next();
7742             // 3
7743             if ( !p2.hasNext() ) {
7744                 return false;
7745             }
7746             phy = p2.next();
7747             // 4
7748             if ( !p2.hasNext() ) {
7749                 return false;
7750             }
7751             phy = p2.next();
7752             // 5
7753             if ( !p2.hasNext() ) {
7754                 return false;
7755             }
7756             phy = p2.next();
7757             // 6
7758             if ( !p2.hasNext() ) {
7759                 return false;
7760             }
7761             phy = p2.next();
7762             // 7
7763             if ( !p2.hasNext() ) {
7764                 return false;
7765             }
7766             phy = p2.next();
7767             // 8
7768             if ( !p2.hasNext() ) {
7769                 return false;
7770             }
7771             phy = p2.next();
7772             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7773                 return false;
7774             }
7775             if ( p2.hasNext() ) {
7776                 return false;
7777             }
7778             phy = p2.next();
7779             if ( phy != null ) {
7780                 return false;
7781             }
7782             // 0
7783             p2.reset();
7784             if ( !p2.hasNext() ) {
7785                 return false;
7786             }
7787             phy = p2.next();
7788             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7789                 return false;
7790             }
7791             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7792                 return false;
7793             }
7794         }
7795         catch ( final Exception e ) {
7796             e.printStackTrace( System.out );
7797             return false;
7798         }
7799         return true;
7800     }
7801
7802     private static boolean testNexusTreeParsingTranslating() {
7803         try {
7804             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7805             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7806             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
7807             if ( phylogenies.length != 1 ) {
7808                 return false;
7809             }
7810             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7811                 return false;
7812             }
7813             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7814                 return false;
7815             }
7816             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7817                 return false;
7818             }
7819             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7820                 return false;
7821             }
7822             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7823                     .equals( "Aranaeus" ) ) {
7824                 return false;
7825             }
7826             phylogenies = null;
7827             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
7828             if ( phylogenies.length != 3 ) {
7829                 return false;
7830             }
7831             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7832                 return false;
7833             }
7834             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7835                 return false;
7836             }
7837             if ( phylogenies[ 0 ].isRooted() ) {
7838                 return false;
7839             }
7840             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7841                 return false;
7842             }
7843             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7844                 return false;
7845             }
7846             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7847                     .equals( "Aranaeus" ) ) {
7848                 return false;
7849             }
7850             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7851                 return false;
7852             }
7853             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7854                 return false;
7855             }
7856             if ( phylogenies[ 1 ].isRooted() ) {
7857                 return false;
7858             }
7859             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7860                 return false;
7861             }
7862             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7863                 return false;
7864             }
7865             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7866                     .equals( "Aranaeus" ) ) {
7867                 return false;
7868             }
7869             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7870                 return false;
7871             }
7872             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7873                 return false;
7874             }
7875             if ( !phylogenies[ 2 ].isRooted() ) {
7876                 return false;
7877             }
7878             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7879                 return false;
7880             }
7881             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7882                 return false;
7883             }
7884             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7885                     .equals( "Aranaeus" ) ) {
7886                 return false;
7887             }
7888             phylogenies = null;
7889             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
7890             if ( phylogenies.length != 3 ) {
7891                 return false;
7892             }
7893             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7894                 return false;
7895             }
7896             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7897                 return false;
7898             }
7899             if ( phylogenies[ 0 ].isRooted() ) {
7900                 return false;
7901             }
7902             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7903                 return false;
7904             }
7905             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7906                 return false;
7907             }
7908             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7909                     .equals( "Aranaeus" ) ) {
7910                 return false;
7911             }
7912             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7913                 return false;
7914             }
7915             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7916                 return false;
7917             }
7918             if ( phylogenies[ 1 ].isRooted() ) {
7919                 return false;
7920             }
7921             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7922                 return false;
7923             }
7924             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7925                 return false;
7926             }
7927             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7928                     .equals( "Aranaeus" ) ) {
7929                 return false;
7930             }
7931             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7932                 return false;
7933             }
7934             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7935                 return false;
7936             }
7937             if ( !phylogenies[ 2 ].isRooted() ) {
7938                 return false;
7939             }
7940             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7941                 return false;
7942             }
7943             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7944                 return false;
7945             }
7946             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7947                     .equals( "Aranaeus" ) ) {
7948                 return false;
7949             }
7950             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
7951             if ( phylogenies.length != 3 ) {
7952                 return false;
7953             }
7954             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
7955                            0.00100049 ) ) {
7956                 return false;
7957             }
7958         }
7959         catch ( final Exception e ) {
7960             e.printStackTrace( System.out );
7961             return false;
7962         }
7963         return true;
7964     }
7965
7966     private static boolean testNHParsing() {
7967         try {
7968             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7969             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
7970             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
7971                 return false;
7972             }
7973             final NHXParser nhxp = new NHXParser();
7974             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
7975             nhxp.setReplaceUnderscores( true );
7976             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
7977             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
7978                 return false;
7979             }
7980             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
7981                 return false;
7982             }
7983             final Phylogeny p1b = factory
7984                     .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 ",
7985                              new NHXParser() )[ 0 ];
7986             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
7987                 return false;
7988             }
7989             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
7990                 return false;
7991             }
7992             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
7993             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
7994             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
7995             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
7996             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
7997             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
7998             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
7999             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
8000             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
8001             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
8002             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
8003                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
8004                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
8005                                                     new NHXParser() );
8006             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
8007                 return false;
8008             }
8009             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
8010                 return false;
8011             }
8012             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
8013                 return false;
8014             }
8015             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
8016                 return false;
8017             }
8018             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
8019             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
8020             final String p16_S = "((A,B),C)";
8021             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
8022             if ( p16.length != 1 ) {
8023                 return false;
8024             }
8025             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
8026                 return false;
8027             }
8028             final String p17_S = "(C,(A,B))";
8029             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
8030             if ( p17.length != 1 ) {
8031                 return false;
8032             }
8033             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
8034                 return false;
8035             }
8036             final String p18_S = "((A,B),(C,D))";
8037             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
8038             if ( p18.length != 1 ) {
8039                 return false;
8040             }
8041             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
8042                 return false;
8043             }
8044             final String p19_S = "(((A,B),C),D)";
8045             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
8046             if ( p19.length != 1 ) {
8047                 return false;
8048             }
8049             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
8050                 return false;
8051             }
8052             final String p20_S = "(A,(B,(C,D)))";
8053             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
8054             if ( p20.length != 1 ) {
8055                 return false;
8056             }
8057             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
8058                 return false;
8059             }
8060             final String p21_S = "(A,(B,(C,(D,E))))";
8061             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
8062             if ( p21.length != 1 ) {
8063                 return false;
8064             }
8065             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
8066                 return false;
8067             }
8068             final String p22_S = "((((A,B),C),D),E)";
8069             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
8070             if ( p22.length != 1 ) {
8071                 return false;
8072             }
8073             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
8074                 return false;
8075             }
8076             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8077             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
8078             if ( p23.length != 1 ) {
8079                 System.out.println( "xl=" + p23.length );
8080                 System.exit( -1 );
8081                 return false;
8082             }
8083             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
8084                 return false;
8085             }
8086             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8087             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
8088             if ( p24.length != 1 ) {
8089                 return false;
8090             }
8091             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
8092                 return false;
8093             }
8094             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8095             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8096             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
8097             if ( p241.length != 2 ) {
8098                 return false;
8099             }
8100             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
8101                 return false;
8102             }
8103             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
8104                 return false;
8105             }
8106             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
8107                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
8108                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
8109                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
8110                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
8111                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
8112                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
8113                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
8114             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
8115             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
8116                 return false;
8117             }
8118             final String p26_S = "(A,B)ab";
8119             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
8120             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
8121                 return false;
8122             }
8123             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8124             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
8125             if ( p27s.length != 1 ) {
8126                 System.out.println( "xxl=" + p27s.length );
8127                 System.exit( -1 );
8128                 return false;
8129             }
8130             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8131                 System.out.println( p27s[ 0 ].toNewHampshireX() );
8132                 System.exit( -1 );
8133                 return false;
8134             }
8135             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
8136                                                     new NHXParser() );
8137             if ( p27.length != 1 ) {
8138                 System.out.println( "yl=" + p27.length );
8139                 System.exit( -1 );
8140                 return false;
8141             }
8142             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8143                 System.out.println( p27[ 0 ].toNewHampshireX() );
8144                 System.exit( -1 );
8145                 return false;
8146             }
8147             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8148             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8149             final String p28_S3 = "(A,B)ab";
8150             final String p28_S4 = "((((A,B),C),D),;E;)";
8151             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
8152                                                     new NHXParser() );
8153             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
8154                 return false;
8155             }
8156             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
8157                 return false;
8158             }
8159             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
8160                 return false;
8161             }
8162             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
8163                 return false;
8164             }
8165             if ( p28.length != 4 ) {
8166                 return false;
8167             }
8168             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";
8169             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
8170             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
8171                 return false;
8172             }
8173             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";
8174             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
8175             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
8176                 return false;
8177             }
8178             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
8179             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
8180             if ( ( p32.length != 0 ) ) {
8181                 return false;
8182             }
8183             final String p33_S = "A";
8184             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
8185             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
8186                 return false;
8187             }
8188             final String p34_S = "B;";
8189             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
8190             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
8191                 return false;
8192             }
8193             final String p35_S = "B:0.2";
8194             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
8195             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
8196                 return false;
8197             }
8198             final String p36_S = "(A)";
8199             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
8200             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
8201                 return false;
8202             }
8203             final String p37_S = "((A))";
8204             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
8205             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
8206                 return false;
8207             }
8208             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8209             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
8210             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
8211                 return false;
8212             }
8213             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8214             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
8215             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
8216                 return false;
8217             }
8218             final String p40_S = "(A,B,C)";
8219             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
8220             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
8221                 return false;
8222             }
8223             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
8224             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
8225             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
8226                 return false;
8227             }
8228             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
8229             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
8230             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
8231                 return false;
8232             }
8233             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)";
8234             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
8235             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
8236                 return false;
8237             }
8238             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)))";
8239             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
8240             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
8241                 return false;
8242             }
8243             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
8244             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
8245             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
8246                 return false;
8247             }
8248             final String p46_S = "";
8249             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
8250             if ( p46.length != 0 ) {
8251                 return false;
8252             }
8253             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
8254             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8255                 return false;
8256             }
8257             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8258             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8259                 return false;
8260             }
8261             final Phylogeny p49 = factory
8262                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
8263                              new NHXParser() )[ 0 ];
8264             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8265                 return false;
8266             }
8267             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8268             if ( p50.getNode( "A" ) == null ) {
8269                 return false;
8270             }
8271             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8272                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
8273                 return false;
8274             }
8275             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
8276                 return false;
8277             }
8278             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
8279                     .equals( "((A,B)88:2.0,C);" ) ) {
8280                 return false;
8281             }
8282             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8283             if ( p51.getNode( "A(A" ) == null ) {
8284                 return false;
8285             }
8286             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8287             if ( p52.getNode( "A(A" ) == null ) {
8288                 return false;
8289             }
8290             final Phylogeny p53 = factory
8291                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
8292                              new NHXParser() )[ 0 ];
8293             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
8294                 return false;
8295             }
8296             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
8297             if ( p54.getNode( "A" ) == null ) {
8298                 return false;
8299             }
8300             if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ).equals( "((A,B)[88],C);" ) ) {
8301                 return false;
8302             }
8303             final Phylogeny p55 = factory
8304                     .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);" ),
8305                              new NHXParser() )[ 0 ];
8306             if ( !p55
8307                     .toNewHampshire()
8308                     .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);" ) ) {
8309                 System.out.println( p55.toNewHampshire() );
8310                 return false;
8311             }
8312             final Phylogeny p56 = factory
8313                     .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);" ),
8314                              new NHXParser() )[ 0 ];
8315             if ( !p56
8316                     .toNewHampshire()
8317                     .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);" ) ) {
8318                 System.out.println( p56.toNewHampshire() );
8319                 return false;
8320             }
8321             final Phylogeny p57 = factory
8322                     .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);" ),
8323                              new NHXParser() )[ 0 ];
8324             if ( !p57
8325                     .toNewHampshire()
8326                     .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);" ) ) {
8327                 System.out.println( p56.toNewHampshire() );
8328                 return false;
8329             }
8330             final String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
8331             final Phylogeny p58 = factory.create( new StringBuffer( s58 ), new NHXParser() )[ 0 ];
8332             if ( !p58.toNewHampshire().equals( s58 ) ) {
8333                 System.out.println( p58.toNewHampshire() );
8334                 return false;
8335             }
8336             final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
8337             final Phylogeny p59 = factory.create( new StringBuffer( s59 ), new NHXParser() )[ 0 ];
8338             if ( !p59.toNewHampshire().equals( s59 ) ) {
8339                 System.out.println( p59.toNewHampshire() );
8340                 return false;
8341             }
8342             final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
8343             final Phylogeny p60 = factory.create( new StringBuffer( s60 ), new NHXParser() )[ 0 ];
8344             if ( !p60.toNewHampshire().equals( s60 ) ) {
8345                 System.out.println( p60.toNewHampshire() );
8346                 return false;
8347             }
8348             final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
8349             final Phylogeny p61 = factory.create( new StringBuffer( s61 ), new NHXParser() )[ 0 ];
8350             if ( !p61.toNewHampshire()
8351                     .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
8352                 System.out.println( p61.toNewHampshire() );
8353                 return false;
8354             }
8355         }
8356         catch ( final Exception e ) {
8357             e.printStackTrace( System.out );
8358             return false;
8359         }
8360         return true;
8361     }
8362
8363     private static boolean testNHParsingIter() {
8364         try {
8365             final String p0_str = "(A,B);";
8366             final NHXParser p = new NHXParser();
8367             p.setSource( p0_str );
8368             if ( !p.hasNext() ) {
8369                 return false;
8370             }
8371             final Phylogeny p0 = p.next();
8372             if ( !p0.toNewHampshire().equals( p0_str ) ) {
8373                 System.out.println( p0.toNewHampshire() );
8374                 return false;
8375             }
8376             if ( p.hasNext() ) {
8377                 return false;
8378             }
8379             if ( p.next() != null ) {
8380                 return false;
8381             }
8382             //
8383             final String p00_str = "(A,B)root;";
8384             p.setSource( p00_str );
8385             final Phylogeny p00 = p.next();
8386             if ( !p00.toNewHampshire().equals( p00_str ) ) {
8387                 System.out.println( p00.toNewHampshire() );
8388                 return false;
8389             }
8390             //
8391             final String p000_str = "A;";
8392             p.setSource( p000_str );
8393             final Phylogeny p000 = p.next();
8394             if ( !p000.toNewHampshire().equals( p000_str ) ) {
8395                 System.out.println( p000.toNewHampshire() );
8396                 return false;
8397             }
8398             //
8399             final String p0000_str = "A";
8400             p.setSource( p0000_str );
8401             final Phylogeny p0000 = p.next();
8402             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
8403                 System.out.println( p0000.toNewHampshire() );
8404                 return false;
8405             }
8406             //
8407             p.setSource( "(A)" );
8408             final Phylogeny p00000 = p.next();
8409             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
8410                 System.out.println( p00000.toNewHampshire() );
8411                 return false;
8412             }
8413             //
8414             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
8415             p.setSource( p1_str );
8416             if ( !p.hasNext() ) {
8417                 return false;
8418             }
8419             final Phylogeny p1_0 = p.next();
8420             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
8421                 System.out.println( p1_0.toNewHampshire() );
8422                 return false;
8423             }
8424             if ( !p.hasNext() ) {
8425                 return false;
8426             }
8427             final Phylogeny p1_1 = p.next();
8428             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
8429                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
8430                 return false;
8431             }
8432             if ( !p.hasNext() ) {
8433                 return false;
8434             }
8435             final Phylogeny p1_2 = p.next();
8436             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
8437                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
8438                 return false;
8439             }
8440             if ( !p.hasNext() ) {
8441                 return false;
8442             }
8443             final Phylogeny p1_3 = p.next();
8444             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
8445                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
8446                 return false;
8447             }
8448             if ( p.hasNext() ) {
8449                 return false;
8450             }
8451             if ( p.next() != null ) {
8452                 return false;
8453             }
8454             //
8455             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
8456             p.setSource( p2_str );
8457             if ( !p.hasNext() ) {
8458                 return false;
8459             }
8460             Phylogeny p2_0 = p.next();
8461             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8462                 System.out.println( p2_0.toNewHampshire() );
8463                 return false;
8464             }
8465             if ( !p.hasNext() ) {
8466                 return false;
8467             }
8468             Phylogeny p2_1 = p.next();
8469             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8470                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8471                 return false;
8472             }
8473             if ( !p.hasNext() ) {
8474                 return false;
8475             }
8476             Phylogeny p2_2 = p.next();
8477             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8478                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8479                 return false;
8480             }
8481             if ( !p.hasNext() ) {
8482                 return false;
8483             }
8484             Phylogeny p2_3 = p.next();
8485             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8486                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8487                 return false;
8488             }
8489             if ( !p.hasNext() ) {
8490                 return false;
8491             }
8492             Phylogeny p2_4 = p.next();
8493             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8494                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8495                 return false;
8496             }
8497             if ( p.hasNext() ) {
8498                 return false;
8499             }
8500             if ( p.next() != null ) {
8501                 return false;
8502             }
8503             ////
8504             p.reset();
8505             if ( !p.hasNext() ) {
8506                 return false;
8507             }
8508             p2_0 = p.next();
8509             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8510                 System.out.println( p2_0.toNewHampshire() );
8511                 return false;
8512             }
8513             if ( !p.hasNext() ) {
8514                 return false;
8515             }
8516             p2_1 = p.next();
8517             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8518                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8519                 return false;
8520             }
8521             if ( !p.hasNext() ) {
8522                 return false;
8523             }
8524             p2_2 = p.next();
8525             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8526                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8527                 return false;
8528             }
8529             if ( !p.hasNext() ) {
8530                 return false;
8531             }
8532             p2_3 = p.next();
8533             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8534                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8535                 return false;
8536             }
8537             if ( !p.hasNext() ) {
8538                 return false;
8539             }
8540             p2_4 = p.next();
8541             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8542                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8543                 return false;
8544             }
8545             if ( p.hasNext() ) {
8546                 return false;
8547             }
8548             if ( p.next() != null ) {
8549                 return false;
8550             }
8551             //
8552             final String p3_str = "((A,B),C)abc";
8553             p.setSource( p3_str );
8554             if ( !p.hasNext() ) {
8555                 return false;
8556             }
8557             final Phylogeny p3_0 = p.next();
8558             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
8559                 return false;
8560             }
8561             if ( p.hasNext() ) {
8562                 return false;
8563             }
8564             if ( p.next() != null ) {
8565                 return false;
8566             }
8567             //
8568             final String p4_str = "((A,B)ab,C)abc";
8569             p.setSource( p4_str );
8570             if ( !p.hasNext() ) {
8571                 return false;
8572             }
8573             final Phylogeny p4_0 = p.next();
8574             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
8575                 return false;
8576             }
8577             if ( p.hasNext() ) {
8578                 return false;
8579             }
8580             if ( p.next() != null ) {
8581                 return false;
8582             }
8583             //
8584             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
8585             p.setSource( p5_str );
8586             if ( !p.hasNext() ) {
8587                 return false;
8588             }
8589             final Phylogeny p5_0 = p.next();
8590             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
8591                 return false;
8592             }
8593             if ( p.hasNext() ) {
8594                 return false;
8595             }
8596             if ( p.next() != null ) {
8597                 return false;
8598             }
8599             //
8600             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8601             p.setSource( p6_str );
8602             if ( !p.hasNext() ) {
8603                 return false;
8604             }
8605             Phylogeny p6_0 = p.next();
8606             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8607                 return false;
8608             }
8609             if ( p.hasNext() ) {
8610                 return false;
8611             }
8612             if ( p.next() != null ) {
8613                 return false;
8614             }
8615             p.reset();
8616             if ( !p.hasNext() ) {
8617                 return false;
8618             }
8619             p6_0 = p.next();
8620             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8621                 return false;
8622             }
8623             if ( p.hasNext() ) {
8624                 return false;
8625             }
8626             if ( p.next() != null ) {
8627                 return false;
8628             }
8629             //
8630             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8631             p.setSource( p7_str );
8632             if ( !p.hasNext() ) {
8633                 return false;
8634             }
8635             Phylogeny p7_0 = p.next();
8636             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8637                 return false;
8638             }
8639             if ( p.hasNext() ) {
8640                 return false;
8641             }
8642             if ( p.next() != null ) {
8643                 return false;
8644             }
8645             p.reset();
8646             if ( !p.hasNext() ) {
8647                 return false;
8648             }
8649             p7_0 = p.next();
8650             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8651                 return false;
8652             }
8653             if ( p.hasNext() ) {
8654                 return false;
8655             }
8656             if ( p.next() != null ) {
8657                 return false;
8658             }
8659             //
8660             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
8661             p.setSource( p8_str );
8662             if ( !p.hasNext() ) {
8663                 return false;
8664             }
8665             Phylogeny p8_0 = p.next();
8666             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8667                 return false;
8668             }
8669             if ( !p.hasNext() ) {
8670                 return false;
8671             }
8672             if ( !p.hasNext() ) {
8673                 return false;
8674             }
8675             Phylogeny p8_1 = p.next();
8676             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8677                 return false;
8678             }
8679             if ( p.hasNext() ) {
8680                 return false;
8681             }
8682             if ( p.next() != null ) {
8683                 return false;
8684             }
8685             p.reset();
8686             if ( !p.hasNext() ) {
8687                 return false;
8688             }
8689             p8_0 = p.next();
8690             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8691                 return false;
8692             }
8693             if ( !p.hasNext() ) {
8694                 return false;
8695             }
8696             p8_1 = p.next();
8697             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8698                 return false;
8699             }
8700             if ( p.hasNext() ) {
8701                 return false;
8702             }
8703             if ( p.next() != null ) {
8704                 return false;
8705             }
8706             p.reset();
8707             //
8708             p.setSource( "" );
8709             if ( p.hasNext() ) {
8710                 return false;
8711             }
8712             //
8713             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
8714             if ( !p.hasNext() ) {
8715                 return false;
8716             }
8717             Phylogeny p_27 = p.next();
8718             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8719                 System.out.println( p_27.toNewHampshireX() );
8720                 System.exit( -1 );
8721                 return false;
8722             }
8723             if ( p.hasNext() ) {
8724                 return false;
8725             }
8726             if ( p.next() != null ) {
8727                 return false;
8728             }
8729             p.reset();
8730             if ( !p.hasNext() ) {
8731                 return false;
8732             }
8733             p_27 = p.next();
8734             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8735                 System.out.println( p_27.toNewHampshireX() );
8736                 System.exit( -1 );
8737                 return false;
8738             }
8739             if ( p.hasNext() ) {
8740                 return false;
8741             }
8742             if ( p.next() != null ) {
8743                 return false;
8744             }
8745             //
8746             final String p30_str = "(A,B);(C,D)";
8747             final NHXParser p30 = new NHXParser();
8748             p30.setSource( p30_str );
8749             if ( !p30.hasNext() ) {
8750                 return false;
8751             }
8752             Phylogeny phy30 = p30.next();
8753             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8754                 System.out.println( phy30.toNewHampshire() );
8755                 return false;
8756             }
8757             if ( !p30.hasNext() ) {
8758                 return false;
8759             }
8760             Phylogeny phy301 = p30.next();
8761             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8762                 System.out.println( phy301.toNewHampshire() );
8763                 return false;
8764             }
8765             if ( p30.hasNext() ) {
8766                 return false;
8767             }
8768             if ( p30.hasNext() ) {
8769                 return false;
8770             }
8771             if ( p30.next() != null ) {
8772                 return false;
8773             }
8774             if ( p30.next() != null ) {
8775                 return false;
8776             }
8777             p30.reset();
8778             if ( !p30.hasNext() ) {
8779                 return false;
8780             }
8781             phy30 = p30.next();
8782             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8783                 System.out.println( phy30.toNewHampshire() );
8784                 return false;
8785             }
8786             if ( !p30.hasNext() ) {
8787                 return false;
8788             }
8789             phy301 = p30.next();
8790             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8791                 System.out.println( phy301.toNewHampshire() );
8792                 return false;
8793             }
8794             if ( p30.hasNext() ) {
8795                 return false;
8796             }
8797             if ( p30.hasNext() ) {
8798                 return false;
8799             }
8800             if ( p30.next() != null ) {
8801                 return false;
8802             }
8803             if ( p30.next() != null ) {
8804                 return false;
8805             }
8806         }
8807         catch ( final Exception e ) {
8808             e.printStackTrace( System.out );
8809             return false;
8810         }
8811         return true;
8812     }
8813
8814     private static boolean testNHXconversion() {
8815         try {
8816             final PhylogenyNode n1 = new PhylogenyNode();
8817             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8818             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8819             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8820             final PhylogenyNode n5 = PhylogenyNode
8821                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
8822             final PhylogenyNode n6 = PhylogenyNode
8823                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
8824             if ( !n1.toNewHampshireX().equals( "" ) ) {
8825                 return false;
8826             }
8827             if ( !n2.toNewHampshireX().equals( "" ) ) {
8828                 return false;
8829             }
8830             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
8831                 return false;
8832             }
8833             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
8834                 return false;
8835             }
8836             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
8837                 return false;
8838             }
8839             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
8840                 System.out.println( n6.toNewHampshireX() );
8841                 return false;
8842             }
8843             final PhylogenyNode n7 = new PhylogenyNode();
8844             n7.setName( "   gks:dr-m4 \"    '    `@:[]sadq04 " );
8845             if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8846                     .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
8847                 System.out.println( n7
8848                         .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
8849                 return false;
8850             }
8851         }
8852         catch ( final Exception e ) {
8853             e.printStackTrace( System.out );
8854             return false;
8855         }
8856         return true;
8857     }
8858
8859     private static boolean testNHXNodeParsing() {
8860         try {
8861             final PhylogenyNode n1 = new PhylogenyNode();
8862             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8863             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8864             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8865             final PhylogenyNode n5 = PhylogenyNode
8866                     .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]" );
8867             if ( !n3.getName().equals( "n3" ) ) {
8868                 return false;
8869             }
8870             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8871                 return false;
8872             }
8873             if ( n3.isDuplication() ) {
8874                 return false;
8875             }
8876             if ( n3.isHasAssignedEvent() ) {
8877                 return false;
8878             }
8879             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
8880                 return false;
8881             }
8882             if ( !n4.getName().equals( "n4" ) ) {
8883                 return false;
8884             }
8885             if ( n4.getDistanceToParent() != 0.01 ) {
8886                 return false;
8887             }
8888             if ( !n5.getName().equals( "n5" ) ) {
8889                 return false;
8890             }
8891             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
8892                 return false;
8893             }
8894             if ( n5.getDistanceToParent() != 0.1 ) {
8895                 return false;
8896             }
8897             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
8898                 return false;
8899             }
8900             if ( !n5.isDuplication() ) {
8901                 return false;
8902             }
8903             if ( !n5.isHasAssignedEvent() ) {
8904                 return false;
8905             }
8906             final PhylogenyNode n8 = PhylogenyNode
8907                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
8908                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8909             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8910                 return false;
8911             }
8912             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
8913                 return false;
8914             }
8915             final PhylogenyNode n9 = PhylogenyNode
8916                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
8917                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8918             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
8919                 return false;
8920             }
8921             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
8922                 return false;
8923             }
8924             final PhylogenyNode n10 = PhylogenyNode
8925                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8926             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
8927                 return false;
8928             }
8929             final PhylogenyNode n20 = PhylogenyNode
8930                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8931             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8932                 return false;
8933             }
8934             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
8935                 return false;
8936             }
8937             final PhylogenyNode n20x = PhylogenyNode
8938                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8939             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
8940                 return false;
8941             }
8942             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
8943                 return false;
8944             }
8945             final PhylogenyNode n20xx = PhylogenyNode
8946                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8947             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
8948                 return false;
8949             }
8950             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
8951                 return false;
8952             }
8953             final PhylogenyNode n20xxx = PhylogenyNode
8954                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8955             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
8956                 return false;
8957             }
8958             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
8959                 return false;
8960             }
8961             final PhylogenyNode n20xxxx = PhylogenyNode
8962                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8963             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
8964                 return false;
8965             }
8966             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
8967                 return false;
8968             }
8969             final PhylogenyNode n21 = PhylogenyNode
8970                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8971             if ( !n21.getName().equals( "N21_PIG" ) ) {
8972                 return false;
8973             }
8974             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
8975                 return false;
8976             }
8977             final PhylogenyNode n21x = PhylogenyNode
8978                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8979             if ( !n21x.getName().equals( "n21_PIG" ) ) {
8980                 return false;
8981             }
8982             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
8983                 return false;
8984             }
8985             final PhylogenyNode n22 = PhylogenyNode
8986                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8987             if ( !n22.getName().equals( "n22/PIG" ) ) {
8988                 return false;
8989             }
8990             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
8991                 return false;
8992             }
8993             final PhylogenyNode n23 = PhylogenyNode
8994                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8995             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
8996                 return false;
8997             }
8998             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
8999                 return false;
9000             }
9001             final PhylogenyNode a = PhylogenyNode
9002                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9003             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9004                 return false;
9005             }
9006             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
9007                 return false;
9008             }
9009             final PhylogenyNode c1 = PhylogenyNode
9010                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
9011                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9012             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
9013                 return false;
9014             }
9015             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
9016                 return false;
9017             }
9018             final PhylogenyNode c2 = PhylogenyNode
9019                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
9020                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9021             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
9022                 return false;
9023             }
9024             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
9025                 return false;
9026             }
9027             final PhylogenyNode e3 = PhylogenyNode
9028                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9029             if ( !e3.getName().equals( "n10_RAT~" ) ) {
9030                 return false;
9031             }
9032             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
9033                 return false;
9034             }
9035             final PhylogenyNode n11 = PhylogenyNode
9036                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
9037                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9038             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
9039                 return false;
9040             }
9041             if ( n11.getDistanceToParent() != 0.4 ) {
9042                 return false;
9043             }
9044             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
9045                 return false;
9046             }
9047             final PhylogenyNode n12 = PhylogenyNode
9048                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
9049                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9050             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
9051                 return false;
9052             }
9053             if ( n12.getDistanceToParent() != 0.4 ) {
9054                 return false;
9055             }
9056             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
9057                 return false;
9058             }
9059             final PhylogenyNode o = PhylogenyNode
9060                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9061             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
9062                 return false;
9063             }
9064             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
9065                 return false;
9066             }
9067             if ( n1.getName().compareTo( "" ) != 0 ) {
9068                 return false;
9069             }
9070             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9071                 return false;
9072             }
9073             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9074                 return false;
9075             }
9076             if ( n2.getName().compareTo( "" ) != 0 ) {
9077                 return false;
9078             }
9079             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9080                 return false;
9081             }
9082             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9083                 return false;
9084             }
9085             final PhylogenyNode n00 = PhylogenyNode
9086                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
9087             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
9088                 return false;
9089             }
9090             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
9091                 return false;
9092             }
9093             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
9094             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
9095                 return false;
9096             }
9097             final PhylogenyNode n13 = PhylogenyNode
9098                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9099             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
9100                 return false;
9101             }
9102             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
9103                 return false;
9104             }
9105             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9106                 return false;
9107             }
9108             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9109                 return false;
9110             }
9111             final PhylogenyNode n14 = PhylogenyNode
9112                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9113             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
9114                 return false;
9115             }
9116             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
9117                 return false;
9118             }
9119             final PhylogenyNode n15 = PhylogenyNode
9120                     .createInstanceFromNhxString( "something_wicked[123]",
9121                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9122             if ( !n15.getName().equals( "something_wicked" ) ) {
9123                 return false;
9124             }
9125             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
9126                 return false;
9127             }
9128             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
9129                 return false;
9130             }
9131             final PhylogenyNode n16 = PhylogenyNode
9132                     .createInstanceFromNhxString( "something_wicked2[9]",
9133                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9134             if ( !n16.getName().equals( "something_wicked2" ) ) {
9135                 return false;
9136             }
9137             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
9138                 return false;
9139             }
9140             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
9141                 return false;
9142             }
9143             final PhylogenyNode n17 = PhylogenyNode
9144                     .createInstanceFromNhxString( "something_wicked3[a]",
9145                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9146             if ( !n17.getName().equals( "something_wicked3" ) ) {
9147                 return false;
9148             }
9149             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
9150                 return false;
9151             }
9152             final PhylogenyNode n18 = PhylogenyNode
9153                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9154             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
9155                 return false;
9156             }
9157             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
9158                 return false;
9159             }
9160             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
9161                 return false;
9162             }
9163             final PhylogenyNode n19 = PhylogenyNode
9164                     .createInstanceFromNhxString( "BLAH_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9165             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
9166                 return false;
9167             }
9168             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9169                 return false;
9170             }
9171             final PhylogenyNode n30 = PhylogenyNode
9172                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
9173                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9174             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
9175                 return false;
9176             }
9177             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9178                 return false;
9179             }
9180             final PhylogenyNode n31 = PhylogenyNode
9181                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
9182                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9183             if ( n31.getNodeData().isHasTaxonomy() ) {
9184                 return false;
9185             }
9186             final PhylogenyNode n32 = PhylogenyNode
9187                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9188             if ( n32.getNodeData().isHasTaxonomy() ) {
9189                 return false;
9190             }
9191             final PhylogenyNode n40 = PhylogenyNode
9192                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9193             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9194                 return false;
9195             }
9196             final PhylogenyNode n41 = PhylogenyNode
9197                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9198             if ( n41.getNodeData().isHasTaxonomy() ) {
9199                 return false;
9200             }
9201             final PhylogenyNode n42 = PhylogenyNode
9202                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9203             if ( n42.getNodeData().isHasTaxonomy() ) {
9204                 return false;
9205             }
9206             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
9207                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
9208             if ( n43.getNodeData().isHasTaxonomy() ) {
9209                 return false;
9210             }
9211             final PhylogenyNode n44 = PhylogenyNode
9212                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9213             if ( n44.getNodeData().isHasTaxonomy() ) {
9214                 return false;
9215             }
9216         }
9217         catch ( final Exception e ) {
9218             e.printStackTrace( System.out );
9219             return false;
9220         }
9221         return true;
9222     }
9223
9224     private static boolean testNHXParsing() {
9225         try {
9226             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9227             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
9228             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
9229                 return false;
9230             }
9231             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]";
9232             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
9233             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9234                 return false;
9235             }
9236             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]";
9237             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
9238             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
9239                 return false;
9240             }
9241             final Phylogeny[] p3 = factory
9242                     .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]",
9243                              new NHXParser() );
9244             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9245                 return false;
9246             }
9247             final Phylogeny[] p4 = factory
9248                     .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(]",
9249                              new NHXParser() );
9250             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9251                 return false;
9252             }
9253             final Phylogeny[] p5 = factory
9254                     .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(((]",
9255                              new NHXParser() );
9256             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9257                 return false;
9258             }
9259             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)";
9260             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)";
9261             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
9262             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
9263                 return false;
9264             }
9265             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)))";
9266             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)))";
9267             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
9268             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
9269                 return false;
9270             }
9271             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])   ))[,,, ])))))))";
9272             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
9273             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
9274             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
9275                 return false;
9276             }
9277             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
9278             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9279                 return false;
9280             }
9281             final Phylogeny p10 = factory
9282                     .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]",
9283                              new NHXParser() )[ 0 ];
9284             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9285                 return false;
9286             }
9287             final Phylogeny p11 = factory
9288                     .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]",
9289                              new NHXParser() )[ 0 ];
9290             if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9291                 return false;
9292             }
9293         }
9294         catch ( final Exception e ) {
9295             e.printStackTrace( System.out );
9296             return false;
9297         }
9298         return true;
9299     }
9300
9301     private static boolean testNHXParsingMB() {
9302         try {
9303             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9304             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
9305                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9306                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9307                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9308                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9309                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9310                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9311                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9312                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
9313             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
9314                 return false;
9315             }
9316             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
9317                 return false;
9318             }
9319             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
9320                            0.1100000000000000e+00 ) ) {
9321                 return false;
9322             }
9323             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
9324                 return false;
9325             }
9326             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
9327                 return false;
9328             }
9329             final Phylogeny p2 = factory
9330                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
9331                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9332                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9333                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9334                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9335                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9336                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9337                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9338                                      + "7.369400000000000e-02}])",
9339                              new NHXParser() )[ 0 ];
9340             if ( p2.getNode( "1" ) == null ) {
9341                 return false;
9342             }
9343             if ( p2.getNode( "2" ) == null ) {
9344                 return false;
9345             }
9346         }
9347         catch ( final Exception e ) {
9348             e.printStackTrace( System.out );
9349             System.exit( -1 );
9350             return false;
9351         }
9352         return true;
9353     }
9354
9355     private static boolean testNHXParsingQuotes() {
9356         try {
9357             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9358             final NHXParser p = new NHXParser();
9359             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
9360             if ( phylogenies_0.length != 5 ) {
9361                 return false;
9362             }
9363             final Phylogeny phy = phylogenies_0[ 4 ];
9364             if ( phy.getNumberOfExternalNodes() != 7 ) {
9365                 return false;
9366             }
9367             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
9368                 return false;
9369             }
9370             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
9371                 return false;
9372             }
9373             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
9374                     .getScientificName().equals( "hsapiens" ) ) {
9375                 return false;
9376             }
9377             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
9378                 return false;
9379             }
9380             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
9381                 return false;
9382             }
9383             if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
9384                 return false;
9385             }
9386             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
9387                 return false;
9388             }
9389             if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
9390                 return false;
9391             }
9392             final NHXParser p1p = new NHXParser();
9393             p1p.setIgnoreQuotes( true );
9394             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
9395             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
9396                 return false;
9397             }
9398             final NHXParser p2p = new NHXParser();
9399             p1p.setIgnoreQuotes( false );
9400             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
9401             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
9402                 return false;
9403             }
9404             final NHXParser p3p = new NHXParser();
9405             p3p.setIgnoreQuotes( false );
9406             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
9407             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
9408                 return false;
9409             }
9410             final NHXParser p4p = new NHXParser();
9411             p4p.setIgnoreQuotes( false );
9412             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
9413             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
9414                 return false;
9415             }
9416             final Phylogeny p10 = factory
9417                     .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]",
9418                              new NHXParser() )[ 0 ];
9419             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]";
9420             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
9421                 return false;
9422             }
9423             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
9424             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
9425                 return false;
9426             }
9427             final Phylogeny p12 = factory
9428                     .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]",
9429                              new NHXParser() )[ 0 ];
9430             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]";
9431             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
9432                 return false;
9433             }
9434             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
9435             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
9436                 return false;
9437             }
9438             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;";
9439             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
9440                 return false;
9441             }
9442             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
9443             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
9444                 return false;
9445             }
9446         }
9447         catch ( final Exception e ) {
9448             e.printStackTrace( System.out );
9449             return false;
9450         }
9451         return true;
9452     }
9453
9454     private static boolean testNodeRemoval() {
9455         try {
9456             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9457             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
9458             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
9459             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
9460                 return false;
9461             }
9462             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
9463             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
9464             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
9465                 return false;
9466             }
9467             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
9468             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
9469             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
9470                 return false;
9471             }
9472         }
9473         catch ( final Exception e ) {
9474             e.printStackTrace( System.out );
9475             return false;
9476         }
9477         return true;
9478     }
9479
9480     private static boolean testPhylogenyBranch() {
9481         try {
9482             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
9483             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
9484             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
9485             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
9486             if ( !a1b1.equals( a1b1 ) ) {
9487                 return false;
9488             }
9489             if ( !a1b1.equals( b1a1 ) ) {
9490                 return false;
9491             }
9492             if ( !b1a1.equals( a1b1 ) ) {
9493                 return false;
9494             }
9495             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
9496             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
9497             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
9498             if ( a1_b1.equals( b1_a1 ) ) {
9499                 return false;
9500             }
9501             if ( a1_b1.equals( a1_b1_ ) ) {
9502                 return false;
9503             }
9504             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
9505             if ( !a1_b1.equals( b1_a1_ ) ) {
9506                 return false;
9507             }
9508             if ( a1_b1_.equals( b1_a1_ ) ) {
9509                 return false;
9510             }
9511             if ( !a1_b1_.equals( b1_a1 ) ) {
9512                 return false;
9513             }
9514         }
9515         catch ( final Exception e ) {
9516             e.printStackTrace( System.out );
9517             return false;
9518         }
9519         return true;
9520     }
9521
9522     private static boolean testPhyloXMLparsingOfDistributionElement() {
9523         try {
9524             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9525             PhyloXmlParser xml_parser = null;
9526             try {
9527                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
9528             }
9529             catch ( final Exception e ) {
9530                 // Do nothing -- means were not running from jar.
9531             }
9532             if ( xml_parser == null ) {
9533                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
9534                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
9535                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
9536                 }
9537                 else {
9538                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
9539                 }
9540             }
9541             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
9542                                                               xml_parser );
9543             if ( xml_parser.getErrorCount() > 0 ) {
9544                 System.out.println( xml_parser.getErrorMessages().toString() );
9545                 return false;
9546             }
9547             if ( phylogenies_0.length != 1 ) {
9548                 return false;
9549             }
9550             final Phylogeny t1 = phylogenies_0[ 0 ];
9551             PhylogenyNode n = null;
9552             Distribution d = null;
9553             n = t1.getNode( "root node" );
9554             if ( !n.getNodeData().isHasDistribution() ) {
9555                 return false;
9556             }
9557             if ( n.getNodeData().getDistributions().size() != 1 ) {
9558                 return false;
9559             }
9560             d = n.getNodeData().getDistribution();
9561             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9562                 return false;
9563             }
9564             if ( d.getPoints().size() != 1 ) {
9565                 return false;
9566             }
9567             if ( d.getPolygons() != null ) {
9568                 return false;
9569             }
9570             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9571                 return false;
9572             }
9573             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9574                 return false;
9575             }
9576             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9577                 return false;
9578             }
9579             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9580                 return false;
9581             }
9582             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9583                 return false;
9584             }
9585             n = t1.getNode( "node a" );
9586             if ( !n.getNodeData().isHasDistribution() ) {
9587                 return false;
9588             }
9589             if ( n.getNodeData().getDistributions().size() != 2 ) {
9590                 return false;
9591             }
9592             d = n.getNodeData().getDistribution( 1 );
9593             if ( !d.getDesc().equals( "San Diego" ) ) {
9594                 return false;
9595             }
9596             if ( d.getPoints().size() != 1 ) {
9597                 return false;
9598             }
9599             if ( d.getPolygons() != null ) {
9600                 return false;
9601             }
9602             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9603                 return false;
9604             }
9605             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9606                 return false;
9607             }
9608             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9609                 return false;
9610             }
9611             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9612                 return false;
9613             }
9614             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9615                 return false;
9616             }
9617             n = t1.getNode( "node bb" );
9618             if ( !n.getNodeData().isHasDistribution() ) {
9619                 return false;
9620             }
9621             if ( n.getNodeData().getDistributions().size() != 1 ) {
9622                 return false;
9623             }
9624             d = n.getNodeData().getDistribution( 0 );
9625             if ( d.getPoints().size() != 3 ) {
9626                 return false;
9627             }
9628             if ( d.getPolygons().size() != 2 ) {
9629                 return false;
9630             }
9631             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9632                 return false;
9633             }
9634             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9635                 return false;
9636             }
9637             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9638                 return false;
9639             }
9640             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9641                 return false;
9642             }
9643             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9644                 return false;
9645             }
9646             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9647                 return false;
9648             }
9649             Polygon p = d.getPolygons().get( 0 );
9650             if ( p.getPoints().size() != 3 ) {
9651                 return false;
9652             }
9653             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9654                 return false;
9655             }
9656             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9657                 return false;
9658             }
9659             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9660                 return false;
9661             }
9662             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9663                 return false;
9664             }
9665             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9666                 return false;
9667             }
9668             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9669                 return false;
9670             }
9671             p = d.getPolygons().get( 1 );
9672             if ( p.getPoints().size() != 3 ) {
9673                 return false;
9674             }
9675             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9676                 return false;
9677             }
9678             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9679                 return false;
9680             }
9681             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9682                 return false;
9683             }
9684             // Roundtrip:
9685             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
9686             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
9687             if ( rt.length != 1 ) {
9688                 return false;
9689             }
9690             final Phylogeny t1_rt = rt[ 0 ];
9691             n = t1_rt.getNode( "root node" );
9692             if ( !n.getNodeData().isHasDistribution() ) {
9693                 return false;
9694             }
9695             if ( n.getNodeData().getDistributions().size() != 1 ) {
9696                 return false;
9697             }
9698             d = n.getNodeData().getDistribution();
9699             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9700                 return false;
9701             }
9702             if ( d.getPoints().size() != 1 ) {
9703                 return false;
9704             }
9705             if ( d.getPolygons() != null ) {
9706                 return false;
9707             }
9708             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9709                 return false;
9710             }
9711             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9712                 return false;
9713             }
9714             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9715                 return false;
9716             }
9717             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9718                 return false;
9719             }
9720             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9721                 return false;
9722             }
9723             n = t1_rt.getNode( "node a" );
9724             if ( !n.getNodeData().isHasDistribution() ) {
9725                 return false;
9726             }
9727             if ( n.getNodeData().getDistributions().size() != 2 ) {
9728                 return false;
9729             }
9730             d = n.getNodeData().getDistribution( 1 );
9731             if ( !d.getDesc().equals( "San Diego" ) ) {
9732                 return false;
9733             }
9734             if ( d.getPoints().size() != 1 ) {
9735                 return false;
9736             }
9737             if ( d.getPolygons() != null ) {
9738                 return false;
9739             }
9740             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9741                 return false;
9742             }
9743             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9744                 return false;
9745             }
9746             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9747                 return false;
9748             }
9749             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9750                 return false;
9751             }
9752             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9753                 return false;
9754             }
9755             n = t1_rt.getNode( "node bb" );
9756             if ( !n.getNodeData().isHasDistribution() ) {
9757                 return false;
9758             }
9759             if ( n.getNodeData().getDistributions().size() != 1 ) {
9760                 return false;
9761             }
9762             d = n.getNodeData().getDistribution( 0 );
9763             if ( d.getPoints().size() != 3 ) {
9764                 return false;
9765             }
9766             if ( d.getPolygons().size() != 2 ) {
9767                 return false;
9768             }
9769             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9770                 return false;
9771             }
9772             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9773                 return false;
9774             }
9775             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9776                 return false;
9777             }
9778             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9779                 return false;
9780             }
9781             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9782                 return false;
9783             }
9784             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9785                 return false;
9786             }
9787             p = d.getPolygons().get( 0 );
9788             if ( p.getPoints().size() != 3 ) {
9789                 return false;
9790             }
9791             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9792                 return false;
9793             }
9794             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9795                 return false;
9796             }
9797             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9798                 return false;
9799             }
9800             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9801                 return false;
9802             }
9803             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9804                 return false;
9805             }
9806             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9807                 return false;
9808             }
9809             p = d.getPolygons().get( 1 );
9810             if ( p.getPoints().size() != 3 ) {
9811                 return false;
9812             }
9813             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9814                 return false;
9815             }
9816             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9817                 return false;
9818             }
9819             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9820                 return false;
9821             }
9822         }
9823         catch ( final Exception e ) {
9824             e.printStackTrace( System.out );
9825             return false;
9826         }
9827         return true;
9828     }
9829
9830     private static boolean testPostOrderIterator() {
9831         try {
9832             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9833             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9834             PhylogenyNodeIterator it0;
9835             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
9836                 it0.next();
9837             }
9838             for( it0.reset(); it0.hasNext(); ) {
9839                 it0.next();
9840             }
9841             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9842             final PhylogenyNodeIterator it = t1.iteratorPostorder();
9843             if ( !it.next().getName().equals( "A" ) ) {
9844                 return false;
9845             }
9846             if ( !it.next().getName().equals( "B" ) ) {
9847                 return false;
9848             }
9849             if ( !it.next().getName().equals( "ab" ) ) {
9850                 return false;
9851             }
9852             if ( !it.next().getName().equals( "C" ) ) {
9853                 return false;
9854             }
9855             if ( !it.next().getName().equals( "D" ) ) {
9856                 return false;
9857             }
9858             if ( !it.next().getName().equals( "cd" ) ) {
9859                 return false;
9860             }
9861             if ( !it.next().getName().equals( "abcd" ) ) {
9862                 return false;
9863             }
9864             if ( !it.next().getName().equals( "E" ) ) {
9865                 return false;
9866             }
9867             if ( !it.next().getName().equals( "F" ) ) {
9868                 return false;
9869             }
9870             if ( !it.next().getName().equals( "ef" ) ) {
9871                 return false;
9872             }
9873             if ( !it.next().getName().equals( "G" ) ) {
9874                 return false;
9875             }
9876             if ( !it.next().getName().equals( "H" ) ) {
9877                 return false;
9878             }
9879             if ( !it.next().getName().equals( "gh" ) ) {
9880                 return false;
9881             }
9882             if ( !it.next().getName().equals( "efgh" ) ) {
9883                 return false;
9884             }
9885             if ( !it.next().getName().equals( "r" ) ) {
9886                 return false;
9887             }
9888             if ( it.hasNext() ) {
9889                 return false;
9890             }
9891         }
9892         catch ( final Exception e ) {
9893             e.printStackTrace( System.out );
9894             return false;
9895         }
9896         return true;
9897     }
9898
9899     private static boolean testPreOrderIterator() {
9900         try {
9901             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9902             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9903             PhylogenyNodeIterator it0;
9904             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
9905                 it0.next();
9906             }
9907             for( it0.reset(); it0.hasNext(); ) {
9908                 it0.next();
9909             }
9910             PhylogenyNodeIterator it = t0.iteratorPreorder();
9911             if ( !it.next().getName().equals( "r" ) ) {
9912                 return false;
9913             }
9914             if ( !it.next().getName().equals( "ab" ) ) {
9915                 return false;
9916             }
9917             if ( !it.next().getName().equals( "A" ) ) {
9918                 return false;
9919             }
9920             if ( !it.next().getName().equals( "B" ) ) {
9921                 return false;
9922             }
9923             if ( !it.next().getName().equals( "cd" ) ) {
9924                 return false;
9925             }
9926             if ( !it.next().getName().equals( "C" ) ) {
9927                 return false;
9928             }
9929             if ( !it.next().getName().equals( "D" ) ) {
9930                 return false;
9931             }
9932             if ( it.hasNext() ) {
9933                 return false;
9934             }
9935             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9936             it = t1.iteratorPreorder();
9937             if ( !it.next().getName().equals( "r" ) ) {
9938                 return false;
9939             }
9940             if ( !it.next().getName().equals( "abcd" ) ) {
9941                 return false;
9942             }
9943             if ( !it.next().getName().equals( "ab" ) ) {
9944                 return false;
9945             }
9946             if ( !it.next().getName().equals( "A" ) ) {
9947                 return false;
9948             }
9949             if ( !it.next().getName().equals( "B" ) ) {
9950                 return false;
9951             }
9952             if ( !it.next().getName().equals( "cd" ) ) {
9953                 return false;
9954             }
9955             if ( !it.next().getName().equals( "C" ) ) {
9956                 return false;
9957             }
9958             if ( !it.next().getName().equals( "D" ) ) {
9959                 return false;
9960             }
9961             if ( !it.next().getName().equals( "efgh" ) ) {
9962                 return false;
9963             }
9964             if ( !it.next().getName().equals( "ef" ) ) {
9965                 return false;
9966             }
9967             if ( !it.next().getName().equals( "E" ) ) {
9968                 return false;
9969             }
9970             if ( !it.next().getName().equals( "F" ) ) {
9971                 return false;
9972             }
9973             if ( !it.next().getName().equals( "gh" ) ) {
9974                 return false;
9975             }
9976             if ( !it.next().getName().equals( "G" ) ) {
9977                 return false;
9978             }
9979             if ( !it.next().getName().equals( "H" ) ) {
9980                 return false;
9981             }
9982             if ( it.hasNext() ) {
9983                 return false;
9984             }
9985         }
9986         catch ( final Exception e ) {
9987             e.printStackTrace( System.out );
9988             return false;
9989         }
9990         return true;
9991     }
9992
9993     private static boolean testPropertiesMap() {
9994         try {
9995             final PropertiesMap pm = new PropertiesMap();
9996             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
9997             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
9998             final Property p2 = new Property( "something:else",
9999                                               "?",
10000                                               "improbable:research",
10001                                               "xsd:decimal",
10002                                               AppliesTo.NODE );
10003             pm.addProperty( p0 );
10004             pm.addProperty( p1 );
10005             pm.addProperty( p2 );
10006             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
10007                 return false;
10008             }
10009             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
10010                 return false;
10011             }
10012             if ( pm.getProperties().size() != 3 ) {
10013                 return false;
10014             }
10015             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
10016                 return false;
10017             }
10018             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10019                 return false;
10020             }
10021             if ( pm.getProperties().size() != 3 ) {
10022                 return false;
10023             }
10024             pm.removeProperty( "dimensions:diameter" );
10025             if ( pm.getProperties().size() != 2 ) {
10026                 return false;
10027             }
10028             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
10029                 return false;
10030             }
10031             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10032                 return false;
10033             }
10034         }
10035         catch ( final Exception e ) {
10036             e.printStackTrace( System.out );
10037             return false;
10038         }
10039         return true;
10040     }
10041
10042     private static boolean testProteinId() {
10043         try {
10044             final ProteinId id1 = new ProteinId( "a" );
10045             final ProteinId id2 = new ProteinId( "a" );
10046             final ProteinId id3 = new ProteinId( "A" );
10047             final ProteinId id4 = new ProteinId( "b" );
10048             if ( !id1.equals( id1 ) ) {
10049                 return false;
10050             }
10051             if ( id1.getId().equals( "x" ) ) {
10052                 return false;
10053             }
10054             if ( id1.getId().equals( null ) ) {
10055                 return false;
10056             }
10057             if ( !id1.equals( id2 ) ) {
10058                 return false;
10059             }
10060             if ( id1.equals( id3 ) ) {
10061                 return false;
10062             }
10063             if ( id1.hashCode() != id1.hashCode() ) {
10064                 return false;
10065             }
10066             if ( id1.hashCode() != id2.hashCode() ) {
10067                 return false;
10068             }
10069             if ( id1.hashCode() == id3.hashCode() ) {
10070                 return false;
10071             }
10072             if ( id1.compareTo( id1 ) != 0 ) {
10073                 return false;
10074             }
10075             if ( id1.compareTo( id2 ) != 0 ) {
10076                 return false;
10077             }
10078             if ( id1.compareTo( id3 ) != 0 ) {
10079                 return false;
10080             }
10081             if ( id1.compareTo( id4 ) >= 0 ) {
10082                 return false;
10083             }
10084             if ( id4.compareTo( id1 ) <= 0 ) {
10085                 return false;
10086             }
10087             if ( !id4.getId().equals( "b" ) ) {
10088                 return false;
10089             }
10090             final ProteinId id5 = new ProteinId( " C " );
10091             if ( !id5.getId().equals( "C" ) ) {
10092                 return false;
10093             }
10094             if ( id5.equals( id1 ) ) {
10095                 return false;
10096             }
10097         }
10098         catch ( final Exception e ) {
10099             e.printStackTrace( System.out );
10100             return false;
10101         }
10102         return true;
10103     }
10104
10105     private static boolean testReIdMethods() {
10106         try {
10107             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10108             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
10109             final long count = PhylogenyNode.getNodeCount();
10110             p.levelOrderReID();
10111             if ( p.getNode( "r" ).getId() != count ) {
10112                 return false;
10113             }
10114             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
10115                 return false;
10116             }
10117             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
10118                 return false;
10119             }
10120             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
10121                 return false;
10122             }
10123             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
10124                 return false;
10125             }
10126             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
10127                 return false;
10128             }
10129             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
10130                 return false;
10131             }
10132             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
10133                 return false;
10134             }
10135             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
10136                 return false;
10137             }
10138             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
10139                 return false;
10140             }
10141             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
10142                 return false;
10143             }
10144             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
10145                 return false;
10146             }
10147             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
10148                 return false;
10149             }
10150             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
10151                 return false;
10152             }
10153             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
10154                 return false;
10155             }
10156         }
10157         catch ( final Exception e ) {
10158             e.printStackTrace( System.out );
10159             return false;
10160         }
10161         return true;
10162     }
10163
10164     private static boolean testRerooting() {
10165         try {
10166             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10167             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",
10168                                                  new NHXParser() )[ 0 ];
10169             if ( !t1.isRooted() ) {
10170                 return false;
10171             }
10172             t1.reRoot( t1.getNode( "D" ) );
10173             t1.reRoot( t1.getNode( "CD" ) );
10174             t1.reRoot( t1.getNode( "A" ) );
10175             t1.reRoot( t1.getNode( "B" ) );
10176             t1.reRoot( t1.getNode( "AB" ) );
10177             t1.reRoot( t1.getNode( "D" ) );
10178             t1.reRoot( t1.getNode( "C" ) );
10179             t1.reRoot( t1.getNode( "CD" ) );
10180             t1.reRoot( t1.getNode( "A" ) );
10181             t1.reRoot( t1.getNode( "B" ) );
10182             t1.reRoot( t1.getNode( "AB" ) );
10183             t1.reRoot( t1.getNode( "D" ) );
10184             t1.reRoot( t1.getNode( "D" ) );
10185             t1.reRoot( t1.getNode( "C" ) );
10186             t1.reRoot( t1.getNode( "A" ) );
10187             t1.reRoot( t1.getNode( "B" ) );
10188             t1.reRoot( t1.getNode( "AB" ) );
10189             t1.reRoot( t1.getNode( "C" ) );
10190             t1.reRoot( t1.getNode( "D" ) );
10191             t1.reRoot( t1.getNode( "CD" ) );
10192             t1.reRoot( t1.getNode( "D" ) );
10193             t1.reRoot( t1.getNode( "A" ) );
10194             t1.reRoot( t1.getNode( "B" ) );
10195             t1.reRoot( t1.getNode( "AB" ) );
10196             t1.reRoot( t1.getNode( "C" ) );
10197             t1.reRoot( t1.getNode( "D" ) );
10198             t1.reRoot( t1.getNode( "CD" ) );
10199             t1.reRoot( t1.getNode( "D" ) );
10200             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
10201                 return false;
10202             }
10203             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
10204                 return false;
10205             }
10206             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
10207                 return false;
10208             }
10209             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
10210                 return false;
10211             }
10212             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
10213                 return false;
10214             }
10215             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
10216                 return false;
10217             }
10218             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",
10219                                                  new NHXParser() )[ 0 ];
10220             t2.reRoot( t2.getNode( "A" ) );
10221             t2.reRoot( t2.getNode( "D" ) );
10222             t2.reRoot( t2.getNode( "ABC" ) );
10223             t2.reRoot( t2.getNode( "A" ) );
10224             t2.reRoot( t2.getNode( "B" ) );
10225             t2.reRoot( t2.getNode( "D" ) );
10226             t2.reRoot( t2.getNode( "C" ) );
10227             t2.reRoot( t2.getNode( "ABC" ) );
10228             t2.reRoot( t2.getNode( "A" ) );
10229             t2.reRoot( t2.getNode( "B" ) );
10230             t2.reRoot( t2.getNode( "AB" ) );
10231             t2.reRoot( t2.getNode( "AB" ) );
10232             t2.reRoot( t2.getNode( "D" ) );
10233             t2.reRoot( t2.getNode( "C" ) );
10234             t2.reRoot( t2.getNode( "B" ) );
10235             t2.reRoot( t2.getNode( "AB" ) );
10236             t2.reRoot( t2.getNode( "D" ) );
10237             t2.reRoot( t2.getNode( "D" ) );
10238             t2.reRoot( t2.getNode( "ABC" ) );
10239             t2.reRoot( t2.getNode( "A" ) );
10240             t2.reRoot( t2.getNode( "B" ) );
10241             t2.reRoot( t2.getNode( "AB" ) );
10242             t2.reRoot( t2.getNode( "D" ) );
10243             t2.reRoot( t2.getNode( "C" ) );
10244             t2.reRoot( t2.getNode( "ABC" ) );
10245             t2.reRoot( t2.getNode( "A" ) );
10246             t2.reRoot( t2.getNode( "B" ) );
10247             t2.reRoot( t2.getNode( "AB" ) );
10248             t2.reRoot( t2.getNode( "D" ) );
10249             t2.reRoot( t2.getNode( "D" ) );
10250             t2.reRoot( t2.getNode( "C" ) );
10251             t2.reRoot( t2.getNode( "A" ) );
10252             t2.reRoot( t2.getNode( "B" ) );
10253             t2.reRoot( t2.getNode( "AB" ) );
10254             t2.reRoot( t2.getNode( "C" ) );
10255             t2.reRoot( t2.getNode( "D" ) );
10256             t2.reRoot( t2.getNode( "ABC" ) );
10257             t2.reRoot( t2.getNode( "D" ) );
10258             t2.reRoot( t2.getNode( "A" ) );
10259             t2.reRoot( t2.getNode( "B" ) );
10260             t2.reRoot( t2.getNode( "AB" ) );
10261             t2.reRoot( t2.getNode( "C" ) );
10262             t2.reRoot( t2.getNode( "D" ) );
10263             t2.reRoot( t2.getNode( "ABC" ) );
10264             t2.reRoot( t2.getNode( "D" ) );
10265             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10266                 return false;
10267             }
10268             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10269                 return false;
10270             }
10271             t2.reRoot( t2.getNode( "ABC" ) );
10272             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10273                 return false;
10274             }
10275             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10276                 return false;
10277             }
10278             t2.reRoot( t2.getNode( "AB" ) );
10279             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10280                 return false;
10281             }
10282             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10283                 return false;
10284             }
10285             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10286                 return false;
10287             }
10288             t2.reRoot( t2.getNode( "AB" ) );
10289             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10290                 return false;
10291             }
10292             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10293                 return false;
10294             }
10295             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10296                 return false;
10297             }
10298             t2.reRoot( t2.getNode( "D" ) );
10299             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10300                 return false;
10301             }
10302             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10303                 return false;
10304             }
10305             t2.reRoot( t2.getNode( "ABC" ) );
10306             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10307                 return false;
10308             }
10309             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10310                 return false;
10311             }
10312             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
10313                                                  new NHXParser() )[ 0 ];
10314             t3.reRoot( t3.getNode( "B" ) );
10315             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10316                 return false;
10317             }
10318             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10319                 return false;
10320             }
10321             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10322                 return false;
10323             }
10324             t3.reRoot( t3.getNode( "B" ) );
10325             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10326                 return false;
10327             }
10328             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10329                 return false;
10330             }
10331             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10332                 return false;
10333             }
10334             t3.reRoot( t3.getRoot() );
10335             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10336                 return false;
10337             }
10338             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10339                 return false;
10340             }
10341             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10342                 return false;
10343             }
10344         }
10345         catch ( final Exception e ) {
10346             e.printStackTrace( System.out );
10347             return false;
10348         }
10349         return true;
10350     }
10351
10352     private static boolean testSDIse() {
10353         try {
10354             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10355             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
10356             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
10357             gene1.setRooted( true );
10358             species1.setRooted( true );
10359             final SDI sdi = new SDI( gene1, species1 );
10360             if ( !gene1.getRoot().isDuplication() ) {
10361                 return false;
10362             }
10363             final Phylogeny species2 = factory
10364                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10365                              new NHXParser() )[ 0 ];
10366             final Phylogeny gene2 = factory
10367                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10368                              new NHXParser() )[ 0 ];
10369             species2.setRooted( true );
10370             gene2.setRooted( true );
10371             final SDI sdi2 = new SDI( gene2, species2 );
10372             if ( sdi2.getDuplicationsSum() != 0 ) {
10373                 return false;
10374             }
10375             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
10376                 return false;
10377             }
10378             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
10379                 return false;
10380             }
10381             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
10382                 return false;
10383             }
10384             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
10385                 return false;
10386             }
10387             if ( !gene2.getNode( "r" ).isSpeciation() ) {
10388                 return false;
10389             }
10390             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
10391                 return false;
10392             }
10393             final Phylogeny species3 = factory
10394                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10395                              new NHXParser() )[ 0 ];
10396             final Phylogeny gene3 = factory
10397                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10398                              new NHXParser() )[ 0 ];
10399             species3.setRooted( true );
10400             gene3.setRooted( true );
10401             final SDI sdi3 = new SDI( gene3, species3 );
10402             if ( sdi3.getDuplicationsSum() != 1 ) {
10403                 return false;
10404             }
10405             if ( !gene3.getNode( "aa" ).isDuplication() ) {
10406                 return false;
10407             }
10408             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
10409                 return false;
10410             }
10411             final Phylogeny species4 = factory
10412                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10413                              new NHXParser() )[ 0 ];
10414             final Phylogeny gene4 = factory
10415                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10416                              new NHXParser() )[ 0 ];
10417             species4.setRooted( true );
10418             gene4.setRooted( true );
10419             final SDI sdi4 = new SDI( gene4, species4 );
10420             if ( sdi4.getDuplicationsSum() != 1 ) {
10421                 return false;
10422             }
10423             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
10424                 return false;
10425             }
10426             if ( !gene4.getNode( "abc" ).isDuplication() ) {
10427                 return false;
10428             }
10429             if ( gene4.getNode( "abcd" ).isDuplication() ) {
10430                 return false;
10431             }
10432             if ( species4.getNumberOfExternalNodes() != 6 ) {
10433                 return false;
10434             }
10435             if ( gene4.getNumberOfExternalNodes() != 6 ) {
10436                 return false;
10437             }
10438             final Phylogeny species5 = factory
10439                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10440                              new NHXParser() )[ 0 ];
10441             final Phylogeny gene5 = factory
10442                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10443                              new NHXParser() )[ 0 ];
10444             species5.setRooted( true );
10445             gene5.setRooted( true );
10446             final SDI sdi5 = new SDI( gene5, species5 );
10447             if ( sdi5.getDuplicationsSum() != 2 ) {
10448                 return false;
10449             }
10450             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
10451                 return false;
10452             }
10453             if ( !gene5.getNode( "adc" ).isDuplication() ) {
10454                 return false;
10455             }
10456             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
10457                 return false;
10458             }
10459             if ( species5.getNumberOfExternalNodes() != 6 ) {
10460                 return false;
10461             }
10462             if ( gene5.getNumberOfExternalNodes() != 6 ) {
10463                 return false;
10464             }
10465             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
10466             // Conjecture for Comparing Molecular Phylogenies"
10467             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
10468             final Phylogeny species6 = factory
10469                     .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,"
10470                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10471                              new NHXParser() )[ 0 ];
10472             final Phylogeny gene6 = factory
10473                     .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,"
10474                                      + "((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,"
10475                                      + "(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;",
10476                              new NHXParser() )[ 0 ];
10477             species6.setRooted( true );
10478             gene6.setRooted( true );
10479             final SDI sdi6 = new SDI( gene6, species6 );
10480             if ( sdi6.getDuplicationsSum() != 3 ) {
10481                 return false;
10482             }
10483             if ( !gene6.getNode( "r" ).isDuplication() ) {
10484                 return false;
10485             }
10486             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
10487                 return false;
10488             }
10489             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
10490                 return false;
10491             }
10492             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
10493                 return false;
10494             }
10495             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
10496                 return false;
10497             }
10498             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
10499                 return false;
10500             }
10501             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
10502                 return false;
10503             }
10504             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
10505                 return false;
10506             }
10507             sdi6.computeMappingCostL();
10508             if ( sdi6.computeMappingCostL() != 17 ) {
10509                 return false;
10510             }
10511             if ( species6.getNumberOfExternalNodes() != 9 ) {
10512                 return false;
10513             }
10514             if ( gene6.getNumberOfExternalNodes() != 9 ) {
10515                 return false;
10516             }
10517             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
10518                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
10519                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
10520                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
10521                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
10522             species7.setRooted( true );
10523             final Phylogeny gene7_1 = Test
10524                     .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])" );
10525             gene7_1.setRooted( true );
10526             final SDI sdi7 = new SDI( gene7_1, species7 );
10527             if ( sdi7.getDuplicationsSum() != 0 ) {
10528                 return false;
10529             }
10530             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
10531                 return false;
10532             }
10533             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
10534                 return false;
10535             }
10536             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
10537                 return false;
10538             }
10539             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
10540                 return false;
10541             }
10542             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
10543                 return false;
10544             }
10545             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
10546                 return false;
10547             }
10548             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
10549                 return false;
10550             }
10551             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
10552                 return false;
10553             }
10554             final Phylogeny gene7_2 = Test
10555                     .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])" );
10556             gene7_2.setRooted( true );
10557             final SDI sdi7_2 = new SDI( gene7_2, species7 );
10558             if ( sdi7_2.getDuplicationsSum() != 1 ) {
10559                 return false;
10560             }
10561             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
10562                 return false;
10563             }
10564             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
10565                 return false;
10566             }
10567             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
10568                 return false;
10569             }
10570             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
10571                 return false;
10572             }
10573             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
10574                 return false;
10575             }
10576             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
10577                 return false;
10578             }
10579             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
10580                 return false;
10581             }
10582             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
10583                 return false;
10584             }
10585             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
10586                 return false;
10587             }
10588         }
10589         catch ( final Exception e ) {
10590             return false;
10591         }
10592         return true;
10593     }
10594
10595     private static boolean testSDIunrooted() {
10596         try {
10597             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10598             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
10599             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
10600             final Iterator<PhylogenyBranch> iter = l.iterator();
10601             PhylogenyBranch br = iter.next();
10602             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
10603                 return false;
10604             }
10605             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
10606                 return false;
10607             }
10608             br = iter.next();
10609             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10610                 return false;
10611             }
10612             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10613                 return false;
10614             }
10615             br = iter.next();
10616             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
10617                 return false;
10618             }
10619             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
10620                 return false;
10621             }
10622             br = iter.next();
10623             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10624                 return false;
10625             }
10626             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10627                 return false;
10628             }
10629             br = iter.next();
10630             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10631                 return false;
10632             }
10633             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10634                 return false;
10635             }
10636             br = iter.next();
10637             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10638                 return false;
10639             }
10640             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10641                 return false;
10642             }
10643             br = iter.next();
10644             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10645                 return false;
10646             }
10647             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10648                 return false;
10649             }
10650             br = iter.next();
10651             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10652                 return false;
10653             }
10654             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10655                 return false;
10656             }
10657             br = iter.next();
10658             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10659                 return false;
10660             }
10661             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10662                 return false;
10663             }
10664             br = iter.next();
10665             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10666                 return false;
10667             }
10668             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10669                 return false;
10670             }
10671             br = iter.next();
10672             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10673                 return false;
10674             }
10675             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10676                 return false;
10677             }
10678             br = iter.next();
10679             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
10680                 return false;
10681             }
10682             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
10683                 return false;
10684             }
10685             br = iter.next();
10686             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10687                 return false;
10688             }
10689             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10690                 return false;
10691             }
10692             br = iter.next();
10693             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
10694                 return false;
10695             }
10696             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
10697                 return false;
10698             }
10699             br = iter.next();
10700             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
10701                 return false;
10702             }
10703             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
10704                 return false;
10705             }
10706             if ( iter.hasNext() ) {
10707                 return false;
10708             }
10709             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
10710             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
10711             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
10712             br = iter1.next();
10713             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10714                 return false;
10715             }
10716             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10717                 return false;
10718             }
10719             br = iter1.next();
10720             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10721                 return false;
10722             }
10723             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10724                 return false;
10725             }
10726             br = iter1.next();
10727             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10728                 return false;
10729             }
10730             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10731                 return false;
10732             }
10733             if ( iter1.hasNext() ) {
10734                 return false;
10735             }
10736             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
10737             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
10738             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
10739             br = iter2.next();
10740             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10741                 return false;
10742             }
10743             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10744                 return false;
10745             }
10746             br = iter2.next();
10747             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10748                 return false;
10749             }
10750             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10751                 return false;
10752             }
10753             br = iter2.next();
10754             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10755                 return false;
10756             }
10757             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10758                 return false;
10759             }
10760             if ( iter2.hasNext() ) {
10761                 return false;
10762             }
10763             final Phylogeny species0 = factory
10764                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10765                              new NHXParser() )[ 0 ];
10766             final Phylogeny gene1 = factory
10767                     .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])",
10768                              new NHXParser() )[ 0 ];
10769             species0.setRooted( true );
10770             gene1.setRooted( true );
10771             final SDIR sdi_unrooted = new SDIR();
10772             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
10773             if ( sdi_unrooted.getCount() != 1 ) {
10774                 return false;
10775             }
10776             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
10777                 return false;
10778             }
10779             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
10780                 return false;
10781             }
10782             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
10783                 return false;
10784             }
10785             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10786                 return false;
10787             }
10788             final Phylogeny gene2 = factory
10789                     .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])",
10790                              new NHXParser() )[ 0 ];
10791             gene2.setRooted( true );
10792             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
10793             if ( sdi_unrooted.getCount() != 1 ) {
10794                 return false;
10795             }
10796             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10797                 return false;
10798             }
10799             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10800                 return false;
10801             }
10802             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
10803                 return false;
10804             }
10805             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10806                 return false;
10807             }
10808             final Phylogeny species6 = factory
10809                     .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,"
10810                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10811                              new NHXParser() )[ 0 ];
10812             final Phylogeny gene6 = factory
10813                     .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],"
10814                                      + "(((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],"
10815                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10816                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10817                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10818                              new NHXParser() )[ 0 ];
10819             species6.setRooted( true );
10820             gene6.setRooted( true );
10821             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
10822             if ( sdi_unrooted.getCount() != 1 ) {
10823                 return false;
10824             }
10825             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10826                 return false;
10827             }
10828             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10829                 return false;
10830             }
10831             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10832                 return false;
10833             }
10834             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10835                 return false;
10836             }
10837             if ( !p6[ 0 ].getRoot().isDuplication() ) {
10838                 return false;
10839             }
10840             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10841                 return false;
10842             }
10843             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10844                 return false;
10845             }
10846             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
10847                 return false;
10848             }
10849             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10850                 return false;
10851             }
10852             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
10853                 return false;
10854             }
10855             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
10856                 return false;
10857             }
10858             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10859                 return false;
10860             }
10861             p6 = null;
10862             final Phylogeny species7 = factory
10863                     .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,"
10864                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10865                              new NHXParser() )[ 0 ];
10866             final Phylogeny gene7 = factory
10867                     .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],"
10868                                      + "(((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],"
10869                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10870                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10871                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10872                              new NHXParser() )[ 0 ];
10873             species7.setRooted( true );
10874             gene7.setRooted( true );
10875             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
10876             if ( sdi_unrooted.getCount() != 1 ) {
10877                 return false;
10878             }
10879             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10880                 return false;
10881             }
10882             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10883                 return false;
10884             }
10885             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10886                 return false;
10887             }
10888             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
10889                 return false;
10890             }
10891             if ( !p7[ 0 ].getRoot().isDuplication() ) {
10892                 return false;
10893             }
10894             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10895                 return false;
10896             }
10897             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10898                 return false;
10899             }
10900             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
10901                 return false;
10902             }
10903             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10904                 return false;
10905             }
10906             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
10907                 return false;
10908             }
10909             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
10910                 return false;
10911             }
10912             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10913                 return false;
10914             }
10915             p7 = null;
10916             final Phylogeny species8 = factory
10917                     .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,"
10918                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10919                              new NHXParser() )[ 0 ];
10920             final Phylogeny gene8 = factory
10921                     .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],"
10922                                      + "(((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],"
10923                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10924                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10925                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10926                              new NHXParser() )[ 0 ];
10927             species8.setRooted( true );
10928             gene8.setRooted( true );
10929             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
10930             if ( sdi_unrooted.getCount() != 1 ) {
10931                 return false;
10932             }
10933             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10934                 return false;
10935             }
10936             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10937                 return false;
10938             }
10939             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10940                 return false;
10941             }
10942             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10943                 return false;
10944             }
10945             if ( !p8[ 0 ].getRoot().isDuplication() ) {
10946                 return false;
10947             }
10948             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10949                 return false;
10950             }
10951             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10952                 return false;
10953             }
10954             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
10955                 return false;
10956             }
10957             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10958                 return false;
10959             }
10960             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
10961                 return false;
10962             }
10963             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
10964                 return false;
10965             }
10966             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10967                 return false;
10968             }
10969             p8 = null;
10970         }
10971         catch ( final Exception e ) {
10972             e.printStackTrace( System.out );
10973             return false;
10974         }
10975         return true;
10976     }
10977
10978     private static boolean testSequenceDbWsTools1() {
10979         try {
10980             final PhylogenyNode n = new PhylogenyNode();
10981             n.setName( "NP_001025424" );
10982             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
10983             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10984                     || !acc.getValue().equals( "NP_001025424" ) ) {
10985                 return false;
10986             }
10987             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
10988             acc = SequenceDbWsTools.obtainSeqAccession( n );
10989             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10990                     || !acc.getValue().equals( "NP_001025424" ) ) {
10991                 return false;
10992             }
10993             n.setName( "NP_001025424.1" );
10994             acc = SequenceDbWsTools.obtainSeqAccession( n );
10995             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10996                     || !acc.getValue().equals( "NP_001025424" ) ) {
10997                 return false;
10998             }
10999             n.setName( "NM_001030253" );
11000             acc = SequenceDbWsTools.obtainSeqAccession( n );
11001             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11002                     || !acc.getValue().equals( "NM_001030253" ) ) {
11003                 return false;
11004             }
11005             n.setName( "BCL2_HUMAN" );
11006             acc = SequenceDbWsTools.obtainSeqAccession( n );
11007             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11008                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
11009                 System.out.println( acc.toString() );
11010                 return false;
11011             }
11012             n.setName( "P10415" );
11013             acc = SequenceDbWsTools.obtainSeqAccession( n );
11014             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11015                     || !acc.getValue().equals( "P10415" ) ) {
11016                 System.out.println( acc.toString() );
11017                 return false;
11018             }
11019             n.setName( " P10415 " );
11020             acc = SequenceDbWsTools.obtainSeqAccession( n );
11021             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11022                     || !acc.getValue().equals( "P10415" ) ) {
11023                 System.out.println( acc.toString() );
11024                 return false;
11025             }
11026             n.setName( "_P10415|" );
11027             acc = SequenceDbWsTools.obtainSeqAccession( n );
11028             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11029                     || !acc.getValue().equals( "P10415" ) ) {
11030                 System.out.println( acc.toString() );
11031                 return false;
11032             }
11033             n.setName( "AY695820" );
11034             acc = SequenceDbWsTools.obtainSeqAccession( n );
11035             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11036                     || !acc.getValue().equals( "AY695820" ) ) {
11037                 System.out.println( acc.toString() );
11038                 return false;
11039             }
11040             n.setName( "_AY695820_" );
11041             acc = SequenceDbWsTools.obtainSeqAccession( n );
11042             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11043                     || !acc.getValue().equals( "AY695820" ) ) {
11044                 System.out.println( acc.toString() );
11045                 return false;
11046             }
11047             n.setName( "AAA59452" );
11048             acc = SequenceDbWsTools.obtainSeqAccession( n );
11049             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11050                     || !acc.getValue().equals( "AAA59452" ) ) {
11051                 System.out.println( acc.toString() );
11052                 return false;
11053             }
11054             n.setName( "_AAA59452_" );
11055             acc = SequenceDbWsTools.obtainSeqAccession( n );
11056             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11057                     || !acc.getValue().equals( "AAA59452" ) ) {
11058                 System.out.println( acc.toString() );
11059                 return false;
11060             }
11061             n.setName( "AAA59452.1" );
11062             acc = SequenceDbWsTools.obtainSeqAccession( n );
11063             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11064                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11065                 System.out.println( acc.toString() );
11066                 return false;
11067             }
11068             n.setName( "_AAA59452.1_" );
11069             acc = SequenceDbWsTools.obtainSeqAccession( n );
11070             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11071                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11072                 System.out.println( acc.toString() );
11073                 return false;
11074             }
11075             n.setName( "GI:94894583" );
11076             acc = SequenceDbWsTools.obtainSeqAccession( n );
11077             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11078                     || !acc.getValue().equals( "94894583" ) ) {
11079                 System.out.println( acc.toString() );
11080                 return false;
11081             }
11082             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11083             acc = SequenceDbWsTools.obtainSeqAccession( n );
11084             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11085                     || !acc.getValue().equals( "71845847" ) ) {
11086                 System.out.println( acc.toString() );
11087                 return false;
11088             }
11089             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11090             acc = SequenceDbWsTools.obtainSeqAccession( n );
11091             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11092                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
11093                 System.out.println( acc.toString() );
11094                 return false;
11095             }
11096         }
11097         catch ( final Exception e ) {
11098             return false;
11099         }
11100         return true;
11101     }
11102
11103     private static boolean testSequenceDbWsTools2() {
11104         try {
11105             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
11106             SequenceDbWsTools.obtainSeqInformation( n1 );
11107             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
11108                 return false;
11109             }
11110             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11111                 return false;
11112             }
11113             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11114                 return false;
11115             }
11116             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
11117                 return false;
11118             }
11119             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
11120             SequenceDbWsTools.obtainSeqInformation( n2 );
11121             if ( !n2.getNodeData().getSequence().getName()
11122                     .equals( "Danio rerio B-cell leukemia/lymphoma 2 (bcl2), mRNA" ) ) {
11123                 return false;
11124             }
11125             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11126                 return false;
11127             }
11128             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11129                 return false;
11130             }
11131             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
11132                 return false;
11133             }
11134             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
11135             SequenceDbWsTools.obtainSeqInformation( n3 );
11136             if ( !n3.getNodeData().getSequence().getName()
11137                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
11138                 return false;
11139             }
11140             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
11141                 return false;
11142             }
11143             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11144                 return false;
11145             }
11146             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
11147                 return false;
11148             }
11149         }
11150         catch ( final IOException e ) {
11151             System.out.println();
11152             System.out.println( "the following might be due to absence internet connection:" );
11153             e.printStackTrace( System.out );
11154             return true;
11155         }
11156         catch ( final Exception e ) {
11157             e.printStackTrace();
11158             return false;
11159         }
11160         return true;
11161     }
11162
11163     private static boolean testSequenceIdParsing() {
11164         try {
11165             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
11166             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11167                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11168                 if ( id != null ) {
11169                     System.out.println( "value   =" + id.getValue() );
11170                     System.out.println( "provider=" + id.getSource() );
11171                 }
11172                 return false;
11173             }
11174             //
11175             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
11176             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11177                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11178                 if ( id != null ) {
11179                     System.out.println( "value   =" + id.getValue() );
11180                     System.out.println( "provider=" + id.getSource() );
11181                 }
11182                 return false;
11183             }
11184             //
11185             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
11186             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11187                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11188                 if ( id != null ) {
11189                     System.out.println( "value   =" + id.getValue() );
11190                     System.out.println( "provider=" + id.getSource() );
11191                 }
11192                 return false;
11193             }
11194             // 
11195             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
11196             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11197                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
11198                 if ( id != null ) {
11199                     System.out.println( "value   =" + id.getValue() );
11200                     System.out.println( "provider=" + id.getSource() );
11201                 }
11202                 return false;
11203             }
11204             // 
11205             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
11206             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11207                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
11208                 if ( id != null ) {
11209                     System.out.println( "value   =" + id.getValue() );
11210                     System.out.println( "provider=" + id.getSource() );
11211                 }
11212                 return false;
11213             }
11214             // 
11215             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
11216             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11217                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
11218                 if ( id != null ) {
11219                     System.out.println( "value   =" + id.getValue() );
11220                     System.out.println( "provider=" + id.getSource() );
11221                 }
11222                 return false;
11223             }
11224             // 
11225             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
11226             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11227                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
11228                 if ( id != null ) {
11229                     System.out.println( "value   =" + id.getValue() );
11230                     System.out.println( "provider=" + id.getSource() );
11231                 }
11232                 return false;
11233             }
11234             // 
11235             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
11236             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11237                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11238                 if ( id != null ) {
11239                     System.out.println( "value   =" + id.getValue() );
11240                     System.out.println( "provider=" + id.getSource() );
11241                 }
11242                 return false;
11243             }
11244             // 
11245             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
11246             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11247                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11248                 if ( id != null ) {
11249                     System.out.println( "value   =" + id.getValue() );
11250                     System.out.println( "provider=" + id.getSource() );
11251                 }
11252                 return false;
11253             }
11254             // 
11255             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
11256             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11257                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
11258                 if ( id != null ) {
11259                     System.out.println( "value   =" + id.getValue() );
11260                     System.out.println( "provider=" + id.getSource() );
11261                 }
11262                 return false;
11263             }
11264             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
11265             if ( id != null ) {
11266                 System.out.println( "value   =" + id.getValue() );
11267                 System.out.println( "provider=" + id.getSource() );
11268                 return false;
11269             }
11270         }
11271         catch ( final Exception e ) {
11272             e.printStackTrace( System.out );
11273             return false;
11274         }
11275         return true;
11276     }
11277
11278     private static boolean testSequenceWriter() {
11279         try {
11280             final String n = ForesterUtil.LINE_SEPARATOR;
11281             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
11282                 return false;
11283             }
11284             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
11285                 return false;
11286             }
11287             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
11288                 return false;
11289             }
11290             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
11291                 return false;
11292             }
11293             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
11294                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
11295                 return false;
11296             }
11297             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
11298                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
11299                 return false;
11300             }
11301         }
11302         catch ( final Exception e ) {
11303             e.printStackTrace();
11304             return false;
11305         }
11306         return true;
11307     }
11308
11309     private static boolean testSpecies() {
11310         try {
11311             final Species s1 = new BasicSpecies( "a" );
11312             final Species s2 = new BasicSpecies( "a" );
11313             final Species s3 = new BasicSpecies( "A" );
11314             final Species s4 = new BasicSpecies( "b" );
11315             if ( !s1.equals( s1 ) ) {
11316                 return false;
11317             }
11318             if ( s1.getSpeciesId().equals( "x" ) ) {
11319                 return false;
11320             }
11321             if ( s1.getSpeciesId().equals( null ) ) {
11322                 return false;
11323             }
11324             if ( !s1.equals( s2 ) ) {
11325                 return false;
11326             }
11327             if ( s1.equals( s3 ) ) {
11328                 return false;
11329             }
11330             if ( s1.hashCode() != s1.hashCode() ) {
11331                 return false;
11332             }
11333             if ( s1.hashCode() != s2.hashCode() ) {
11334                 return false;
11335             }
11336             if ( s1.hashCode() == s3.hashCode() ) {
11337                 return false;
11338             }
11339             if ( s1.compareTo( s1 ) != 0 ) {
11340                 return false;
11341             }
11342             if ( s1.compareTo( s2 ) != 0 ) {
11343                 return false;
11344             }
11345             if ( s1.compareTo( s3 ) != 0 ) {
11346                 return false;
11347             }
11348             if ( s1.compareTo( s4 ) >= 0 ) {
11349                 return false;
11350             }
11351             if ( s4.compareTo( s1 ) <= 0 ) {
11352                 return false;
11353             }
11354             if ( !s4.getSpeciesId().equals( "b" ) ) {
11355                 return false;
11356             }
11357             final Species s5 = new BasicSpecies( " C " );
11358             if ( !s5.getSpeciesId().equals( "C" ) ) {
11359                 return false;
11360             }
11361             if ( s5.equals( s1 ) ) {
11362                 return false;
11363             }
11364         }
11365         catch ( final Exception e ) {
11366             e.printStackTrace( System.out );
11367             return false;
11368         }
11369         return true;
11370     }
11371
11372     private static boolean testSplit() {
11373         try {
11374             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11375             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11376             //Archaeopteryx.createApplication( p0 );
11377             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11378             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11379             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11380             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11381             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11382             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11383             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11384             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11385             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11386             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11387             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
11388             // System.out.println( s0.toString() );
11389             //
11390             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11391             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11392             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11393             if ( s0.match( query_nodes ) ) {
11394                 return false;
11395             }
11396             query_nodes = new HashSet<PhylogenyNode>();
11397             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11398             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11399             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11400             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11401             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11402             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11403             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11404             if ( !s0.match( query_nodes ) ) {
11405                 return false;
11406             }
11407             //
11408             query_nodes = new HashSet<PhylogenyNode>();
11409             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11410             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11411             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11412             if ( !s0.match( query_nodes ) ) {
11413                 return false;
11414             }
11415             //
11416             query_nodes = new HashSet<PhylogenyNode>();
11417             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11418             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11419             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11420             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11421             if ( !s0.match( query_nodes ) ) {
11422                 return false;
11423             }
11424             //
11425             query_nodes = new HashSet<PhylogenyNode>();
11426             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11427             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11428             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11429             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11430             if ( !s0.match( query_nodes ) ) {
11431                 return false;
11432             }
11433             //
11434             query_nodes = new HashSet<PhylogenyNode>();
11435             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11436             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11437             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11438             if ( !s0.match( query_nodes ) ) {
11439                 return false;
11440             }
11441             //
11442             query_nodes = new HashSet<PhylogenyNode>();
11443             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11444             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11445             if ( !s0.match( query_nodes ) ) {
11446                 return false;
11447             }
11448             //
11449             query_nodes = new HashSet<PhylogenyNode>();
11450             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11451             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11452             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11453             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11454             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11455             if ( !s0.match( query_nodes ) ) {
11456                 return false;
11457             }
11458             //
11459             query_nodes = new HashSet<PhylogenyNode>();
11460             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11461             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11462             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11463             if ( !s0.match( query_nodes ) ) {
11464                 return false;
11465             }
11466             //
11467             query_nodes = new HashSet<PhylogenyNode>();
11468             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11469             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11470             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11471             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11472             if ( !s0.match( query_nodes ) ) {
11473                 return false;
11474             }
11475             //
11476             query_nodes = new HashSet<PhylogenyNode>();
11477             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11478             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11479             if ( s0.match( query_nodes ) ) {
11480                 return false;
11481             }
11482             //
11483             query_nodes = new HashSet<PhylogenyNode>();
11484             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11485             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11486             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11487             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11488             if ( s0.match( query_nodes ) ) {
11489                 return false;
11490             }
11491             //
11492             query_nodes = new HashSet<PhylogenyNode>();
11493             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11494             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11495             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11496             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11497             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11498             if ( s0.match( query_nodes ) ) {
11499                 return false;
11500             }
11501             //
11502             query_nodes = new HashSet<PhylogenyNode>();
11503             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11504             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
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( "A" ) );
11512             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11513             if ( s0.match( query_nodes ) ) {
11514                 return false;
11515             }
11516             //
11517             query_nodes = new HashSet<PhylogenyNode>();
11518             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11519             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11520             if ( s0.match( query_nodes ) ) {
11521                 return false;
11522             }
11523             //
11524             query_nodes = new HashSet<PhylogenyNode>();
11525             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11526             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11527             if ( s0.match( query_nodes ) ) {
11528                 return false;
11529             }
11530             //
11531             query_nodes = new HashSet<PhylogenyNode>();
11532             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11533             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11534             if ( s0.match( query_nodes ) ) {
11535                 return false;
11536             }
11537             //
11538             query_nodes = new HashSet<PhylogenyNode>();
11539             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11540             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11541             if ( s0.match( query_nodes ) ) {
11542                 return false;
11543             }
11544             //
11545             query_nodes = new HashSet<PhylogenyNode>();
11546             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11547             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11548             if ( s0.match( query_nodes ) ) {
11549                 return false;
11550             }
11551             //
11552             query_nodes = new HashSet<PhylogenyNode>();
11553             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11554             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11555             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11556             if ( s0.match( query_nodes ) ) {
11557                 return false;
11558             }
11559             //
11560             query_nodes = new HashSet<PhylogenyNode>();
11561             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11562             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11563             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11564             if ( s0.match( query_nodes ) ) {
11565                 return false;
11566             }
11567             //
11568             query_nodes = new HashSet<PhylogenyNode>();
11569             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11570             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11571             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11572             if ( s0.match( query_nodes ) ) {
11573                 return false;
11574             }
11575             //
11576             query_nodes = new HashSet<PhylogenyNode>();
11577             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11578             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11579             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11580             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11581             if ( s0.match( query_nodes ) ) {
11582                 return false;
11583             }
11584             /////////
11585             //            query_nodes = new HashSet<PhylogenyNode>();
11586             //            query_nodes.add( new PhylogenyNode( "X" ) );
11587             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11588             //            query_nodes.add( new PhylogenyNode( "A" ) );
11589             //            query_nodes.add( new PhylogenyNode( "B" ) );
11590             //            query_nodes.add( new PhylogenyNode( "C" ) );
11591             //            query_nodes.add( new PhylogenyNode( "D" ) );
11592             //            query_nodes.add( new PhylogenyNode( "E" ) );
11593             //            query_nodes.add( new PhylogenyNode( "F" ) );
11594             //            query_nodes.add( new PhylogenyNode( "G" ) );
11595             //            if ( !s0.match( query_nodes ) ) {
11596             //                return false;
11597             //            }
11598             //            query_nodes = new HashSet<PhylogenyNode>();
11599             //            query_nodes.add( new PhylogenyNode( "X" ) );
11600             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11601             //            query_nodes.add( new PhylogenyNode( "A" ) );
11602             //            query_nodes.add( new PhylogenyNode( "B" ) );
11603             //            query_nodes.add( new PhylogenyNode( "C" ) );
11604             //            if ( !s0.match( query_nodes ) ) {
11605             //                return false;
11606             //            }
11607             //            //
11608             //            query_nodes = new HashSet<PhylogenyNode>();
11609             //            query_nodes.add( new PhylogenyNode( "X" ) );
11610             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11611             //            query_nodes.add( new PhylogenyNode( "D" ) );
11612             //            query_nodes.add( new PhylogenyNode( "E" ) );
11613             //            query_nodes.add( new PhylogenyNode( "F" ) );
11614             //            query_nodes.add( new PhylogenyNode( "G" ) );
11615             //            if ( !s0.match( query_nodes ) ) {
11616             //                return false;
11617             //            }
11618             //            //
11619             //            query_nodes = new HashSet<PhylogenyNode>();
11620             //            query_nodes.add( new PhylogenyNode( "X" ) );
11621             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11622             //            query_nodes.add( new PhylogenyNode( "A" ) );
11623             //            query_nodes.add( new PhylogenyNode( "B" ) );
11624             //            query_nodes.add( new PhylogenyNode( "C" ) );
11625             //            query_nodes.add( new PhylogenyNode( "D" ) );
11626             //            if ( !s0.match( query_nodes ) ) {
11627             //                return false;
11628             //            }
11629             //            //
11630             //            query_nodes = new HashSet<PhylogenyNode>();
11631             //            query_nodes.add( new PhylogenyNode( "X" ) );
11632             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11633             //            query_nodes.add( new PhylogenyNode( "E" ) );
11634             //            query_nodes.add( new PhylogenyNode( "F" ) );
11635             //            query_nodes.add( new PhylogenyNode( "G" ) );
11636             //            if ( !s0.match( query_nodes ) ) {
11637             //                return false;
11638             //            }
11639             //            //
11640             //            query_nodes = new HashSet<PhylogenyNode>();
11641             //            query_nodes.add( new PhylogenyNode( "X" ) );
11642             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11643             //            query_nodes.add( new PhylogenyNode( "F" ) );
11644             //            query_nodes.add( new PhylogenyNode( "G" ) );
11645             //            if ( !s0.match( query_nodes ) ) {
11646             //                return false;
11647             //            }
11648             //
11649             query_nodes = new HashSet<PhylogenyNode>();
11650             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11651             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11652             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11653             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11654             if ( s0.match( query_nodes ) ) {
11655                 return false;
11656             }
11657             //
11658             query_nodes = new HashSet<PhylogenyNode>();
11659             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11660             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11661             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11662             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11663             if ( s0.match( query_nodes ) ) {
11664                 return false;
11665             }
11666             ///////////////////////////
11667             //
11668             query_nodes = new HashSet<PhylogenyNode>();
11669             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11670             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11671             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11672             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11673             if ( s0.match( query_nodes ) ) {
11674                 return false;
11675             }
11676             //
11677             query_nodes = new HashSet<PhylogenyNode>();
11678             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11679             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11680             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11681             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11682             if ( s0.match( query_nodes ) ) {
11683                 return false;
11684             }
11685             //
11686             query_nodes = new HashSet<PhylogenyNode>();
11687             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11688             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11689             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11690             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11691             if ( s0.match( query_nodes ) ) {
11692                 return false;
11693             }
11694             //
11695             query_nodes = new HashSet<PhylogenyNode>();
11696             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11697             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11698             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11699             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11700             if ( s0.match( query_nodes ) ) {
11701                 return false;
11702             }
11703             //
11704             query_nodes = new HashSet<PhylogenyNode>();
11705             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11706             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11707             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11708             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11709             if ( s0.match( query_nodes ) ) {
11710                 return false;
11711             }
11712             //
11713             query_nodes = new HashSet<PhylogenyNode>();
11714             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11715             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11716             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11717             if ( s0.match( query_nodes ) ) {
11718                 return false;
11719             }
11720             //
11721             query_nodes = new HashSet<PhylogenyNode>();
11722             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11723             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11724             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11725             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11726             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11727             if ( s0.match( query_nodes ) ) {
11728                 return false;
11729             }
11730             //
11731             query_nodes = new HashSet<PhylogenyNode>();
11732             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11733             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11734             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11735             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11736             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11737             if ( s0.match( query_nodes ) ) {
11738                 return false;
11739             }
11740             //
11741             query_nodes = new HashSet<PhylogenyNode>();
11742             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11743             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11744             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11745             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11746             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11747             if ( s0.match( query_nodes ) ) {
11748                 return false;
11749             }
11750             //
11751             query_nodes = new HashSet<PhylogenyNode>();
11752             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11753             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11754             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11755             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11756             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11757             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11758             if ( s0.match( query_nodes ) ) {
11759                 return false;
11760             }
11761         }
11762         catch ( final Exception e ) {
11763             e.printStackTrace();
11764             return false;
11765         }
11766         return true;
11767     }
11768
11769     private static boolean testSplitStrict() {
11770         try {
11771             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11772             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11773             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11774             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11775             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11776             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11777             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11778             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11779             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11780             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11781             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
11782             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11783             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11784             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11785             if ( s0.match( query_nodes ) ) {
11786                 return false;
11787             }
11788             query_nodes = new HashSet<PhylogenyNode>();
11789             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11790             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11791             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11792             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11793             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11794             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11795             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11796             if ( !s0.match( query_nodes ) ) {
11797                 return false;
11798             }
11799             //
11800             query_nodes = new HashSet<PhylogenyNode>();
11801             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11802             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11803             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11804             if ( !s0.match( query_nodes ) ) {
11805                 return false;
11806             }
11807             //
11808             query_nodes = new HashSet<PhylogenyNode>();
11809             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11810             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11811             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11812             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11813             if ( !s0.match( query_nodes ) ) {
11814                 return false;
11815             }
11816             //
11817             query_nodes = new HashSet<PhylogenyNode>();
11818             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11819             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11820             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11821             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11822             if ( !s0.match( query_nodes ) ) {
11823                 return false;
11824             }
11825             //
11826             query_nodes = new HashSet<PhylogenyNode>();
11827             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11828             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11829             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11830             if ( !s0.match( query_nodes ) ) {
11831                 return false;
11832             }
11833             //
11834             query_nodes = new HashSet<PhylogenyNode>();
11835             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11836             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11837             if ( !s0.match( query_nodes ) ) {
11838                 return false;
11839             }
11840             //
11841             query_nodes = new HashSet<PhylogenyNode>();
11842             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11843             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11844             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11845             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11846             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11847             if ( !s0.match( query_nodes ) ) {
11848                 return false;
11849             }
11850             //
11851             query_nodes = new HashSet<PhylogenyNode>();
11852             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11853             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11854             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11855             if ( !s0.match( query_nodes ) ) {
11856                 return false;
11857             }
11858             //
11859             query_nodes = new HashSet<PhylogenyNode>();
11860             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11861             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11862             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11863             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11864             if ( !s0.match( query_nodes ) ) {
11865                 return false;
11866             }
11867             //
11868             query_nodes = new HashSet<PhylogenyNode>();
11869             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11870             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11871             if ( s0.match( query_nodes ) ) {
11872                 return false;
11873             }
11874             //
11875             query_nodes = new HashSet<PhylogenyNode>();
11876             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11877             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11878             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11879             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11880             if ( s0.match( query_nodes ) ) {
11881                 return false;
11882             }
11883             //
11884             query_nodes = new HashSet<PhylogenyNode>();
11885             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11886             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11887             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11888             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11889             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11890             if ( s0.match( query_nodes ) ) {
11891                 return false;
11892             }
11893             //
11894             query_nodes = new HashSet<PhylogenyNode>();
11895             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11896             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11897             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11898             if ( s0.match( query_nodes ) ) {
11899                 return false;
11900             }
11901             //
11902             query_nodes = new HashSet<PhylogenyNode>();
11903             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11904             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11905             if ( s0.match( query_nodes ) ) {
11906                 return false;
11907             }
11908             //
11909             query_nodes = new HashSet<PhylogenyNode>();
11910             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11911             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11912             if ( s0.match( query_nodes ) ) {
11913                 return false;
11914             }
11915             //
11916             query_nodes = new HashSet<PhylogenyNode>();
11917             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11918             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11919             if ( s0.match( query_nodes ) ) {
11920                 return false;
11921             }
11922             //
11923             query_nodes = new HashSet<PhylogenyNode>();
11924             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11925             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11926             if ( s0.match( query_nodes ) ) {
11927                 return false;
11928             }
11929             //
11930             query_nodes = new HashSet<PhylogenyNode>();
11931             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11932             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11933             if ( s0.match( query_nodes ) ) {
11934                 return false;
11935             }
11936             //
11937             query_nodes = new HashSet<PhylogenyNode>();
11938             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11939             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11940             if ( s0.match( query_nodes ) ) {
11941                 return false;
11942             }
11943             //
11944             query_nodes = new HashSet<PhylogenyNode>();
11945             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11946             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11947             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11948             if ( s0.match( query_nodes ) ) {
11949                 return false;
11950             }
11951             //
11952             query_nodes = new HashSet<PhylogenyNode>();
11953             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11954             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11955             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11956             if ( s0.match( query_nodes ) ) {
11957                 return false;
11958             }
11959             //
11960             query_nodes = new HashSet<PhylogenyNode>();
11961             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11962             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11963             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11964             if ( s0.match( query_nodes ) ) {
11965                 return false;
11966             }
11967             //
11968             query_nodes = new HashSet<PhylogenyNode>();
11969             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11970             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11971             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11972             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11973             if ( s0.match( query_nodes ) ) {
11974                 return false;
11975             }
11976         }
11977         catch ( final Exception e ) {
11978             e.printStackTrace();
11979             return false;
11980         }
11981         return true;
11982     }
11983
11984     private static boolean testSubtreeDeletion() {
11985         try {
11986             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11987             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
11988             t1.deleteSubtree( t1.getNode( "A" ), false );
11989             if ( t1.getNumberOfExternalNodes() != 5 ) {
11990                 return false;
11991             }
11992             t1.toNewHampshireX();
11993             t1.deleteSubtree( t1.getNode( "E" ), false );
11994             if ( t1.getNumberOfExternalNodes() != 4 ) {
11995                 return false;
11996             }
11997             t1.toNewHampshireX();
11998             t1.deleteSubtree( t1.getNode( "F" ), false );
11999             if ( t1.getNumberOfExternalNodes() != 3 ) {
12000                 return false;
12001             }
12002             t1.toNewHampshireX();
12003             t1.deleteSubtree( t1.getNode( "D" ), false );
12004             t1.toNewHampshireX();
12005             if ( t1.getNumberOfExternalNodes() != 3 ) {
12006                 return false;
12007             }
12008             t1.deleteSubtree( t1.getNode( "def" ), false );
12009             t1.toNewHampshireX();
12010             if ( t1.getNumberOfExternalNodes() != 2 ) {
12011                 return false;
12012             }
12013             t1.deleteSubtree( t1.getNode( "B" ), false );
12014             t1.toNewHampshireX();
12015             if ( t1.getNumberOfExternalNodes() != 1 ) {
12016                 return false;
12017             }
12018             t1.deleteSubtree( t1.getNode( "C" ), false );
12019             t1.toNewHampshireX();
12020             if ( t1.getNumberOfExternalNodes() != 1 ) {
12021                 return false;
12022             }
12023             t1.deleteSubtree( t1.getNode( "abc" ), false );
12024             t1.toNewHampshireX();
12025             if ( t1.getNumberOfExternalNodes() != 1 ) {
12026                 return false;
12027             }
12028             t1.deleteSubtree( t1.getNode( "r" ), false );
12029             if ( t1.getNumberOfExternalNodes() != 0 ) {
12030                 return false;
12031             }
12032             if ( !t1.isEmpty() ) {
12033                 return false;
12034             }
12035             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12036             t2.deleteSubtree( t2.getNode( "A" ), false );
12037             t2.toNewHampshireX();
12038             if ( t2.getNumberOfExternalNodes() != 5 ) {
12039                 return false;
12040             }
12041             t2.deleteSubtree( t2.getNode( "abc" ), false );
12042             t2.toNewHampshireX();
12043             if ( t2.getNumberOfExternalNodes() != 3 ) {
12044                 return false;
12045             }
12046             t2.deleteSubtree( t2.getNode( "def" ), false );
12047             t2.toNewHampshireX();
12048             if ( t2.getNumberOfExternalNodes() != 1 ) {
12049                 return false;
12050             }
12051         }
12052         catch ( final Exception e ) {
12053             e.printStackTrace( System.out );
12054             return false;
12055         }
12056         return true;
12057     }
12058
12059     private static boolean testSupportCount() {
12060         try {
12061             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12062             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
12063             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
12064                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
12065                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
12066                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
12067                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
12068                                                               new NHXParser() );
12069             SupportCount.count( t0_1, phylogenies_1, true, false );
12070             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
12071             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
12072                                                                       + "(((((A,B),C),D),E),((F,G),X))"
12073                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
12074                                                                       + "(((((A,B),C),D),E),(F,G))"
12075                                                                       + "(((((A,B),C),D),E),(F,G))"
12076                                                                       + "(((((A,B),C),D),E),(F,G))"
12077                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
12078                                                                       + "(((((A,B),C),D),E),(F,G))"
12079                                                                       + "((((((A,B),C),D),E),F),G)"
12080                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
12081                                                               new NHXParser() );
12082             SupportCount.count( t0_2, phylogenies_2, true, false );
12083             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
12084             while ( it.hasNext() ) {
12085                 final PhylogenyNode n = it.next();
12086                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
12087                     return false;
12088                 }
12089             }
12090             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
12091             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
12092                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
12093             SupportCount.count( t0_3, phylogenies_3, true, false );
12094             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
12095             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
12096                 return false;
12097             }
12098             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
12099                 return false;
12100             }
12101             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
12102                 return false;
12103             }
12104             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
12105                 return false;
12106             }
12107             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
12108                 return false;
12109             }
12110             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
12111                 return false;
12112             }
12113             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
12114                 return false;
12115             }
12116             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
12117                 return false;
12118             }
12119             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
12120                 return false;
12121             }
12122             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
12123                 return false;
12124             }
12125             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12126             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
12127                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
12128             SupportCount.count( t0_4, phylogenies_4, true, false );
12129             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
12130             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
12131                 return false;
12132             }
12133             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
12134                 return false;
12135             }
12136             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
12137                 return false;
12138             }
12139             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
12140                 return false;
12141             }
12142             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
12143                 return false;
12144             }
12145             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
12146                 return false;
12147             }
12148             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
12149                 return false;
12150             }
12151             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
12152                 return false;
12153             }
12154             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
12155                 return false;
12156             }
12157             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
12158                 return false;
12159             }
12160             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12161             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12162             double d = SupportCount.compare( b1, a, true, true, true );
12163             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
12164                 return false;
12165             }
12166             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12167             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12168             d = SupportCount.compare( b2, a, true, true, true );
12169             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
12170                 return false;
12171             }
12172             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12173             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
12174             d = SupportCount.compare( b3, a, true, true, true );
12175             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
12176                 return false;
12177             }
12178             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
12179             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
12180             d = SupportCount.compare( b4, a, true, true, false );
12181             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
12182                 return false;
12183             }
12184         }
12185         catch ( final Exception e ) {
12186             e.printStackTrace( System.out );
12187             return false;
12188         }
12189         return true;
12190     }
12191
12192     private static boolean testSupportTransfer() {
12193         try {
12194             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12195             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)",
12196                                                  new NHXParser() )[ 0 ];
12197             final Phylogeny p2 = factory
12198                     .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 ];
12199             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
12200                 return false;
12201             }
12202             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
12203                 return false;
12204             }
12205             support_transfer.moveBranchLengthsToBootstrap( p1 );
12206             support_transfer.transferSupportValues( p1, p2 );
12207             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
12208                 return false;
12209             }
12210             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
12211                 return false;
12212             }
12213             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
12214                 return false;
12215             }
12216             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
12217                 return false;
12218             }
12219             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
12220                 return false;
12221             }
12222             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
12223                 return false;
12224             }
12225             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
12226                 return false;
12227             }
12228             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
12229                 return false;
12230             }
12231         }
12232         catch ( final Exception e ) {
12233             e.printStackTrace( System.out );
12234             return false;
12235         }
12236         return true;
12237     }
12238
12239     private static boolean testTaxonomyExtraction() {
12240         try {
12241             final PhylogenyNode n0 = PhylogenyNode
12242                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12243             if ( n0.getNodeData().isHasTaxonomy() ) {
12244                 return false;
12245             }
12246             final PhylogenyNode n1 = PhylogenyNode
12247                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12248             if ( n1.getNodeData().isHasTaxonomy() ) {
12249                 System.out.println( n1.toString() );
12250                 return false;
12251             }
12252             final PhylogenyNode n2x = PhylogenyNode
12253                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12254             if ( n2x.getNodeData().isHasTaxonomy() ) {
12255                 return false;
12256             }
12257             final PhylogenyNode n3 = PhylogenyNode
12258                     .createInstanceFromNhxString( "BLAG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12259             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12260                 System.out.println( n3.toString() );
12261                 return false;
12262             }
12263             final PhylogenyNode n4 = PhylogenyNode
12264                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12265             if ( n4.getNodeData().isHasTaxonomy() ) {
12266                 System.out.println( n4.toString() );
12267                 return false;
12268             }
12269             final PhylogenyNode n5 = PhylogenyNode
12270                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12271             if ( n5.getNodeData().isHasTaxonomy() ) {
12272                 System.out.println( n5.toString() );
12273                 return false;
12274             }
12275             final PhylogenyNode n6 = PhylogenyNode
12276                     .createInstanceFromNhxString( "BLAG-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12277             if ( n6.getNodeData().isHasTaxonomy() ) {
12278                 System.out.println( n6.toString() );
12279                 return false;
12280             }
12281             final PhylogenyNode n7 = PhylogenyNode
12282                     .createInstanceFromNhxString( "BLAG-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12283             if ( n7.getNodeData().isHasTaxonomy() ) {
12284                 System.out.println( n7.toString() );
12285                 return false;
12286             }
12287             final PhylogenyNode n8 = PhylogenyNode
12288                     .createInstanceFromNhxString( "BLAG_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12289             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12290                 System.out.println( n8.toString() );
12291                 return false;
12292             }
12293             final PhylogenyNode n9 = PhylogenyNode
12294                     .createInstanceFromNhxString( "BLAG_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12295             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12296                 System.out.println( n9.toString() );
12297                 return false;
12298             }
12299             final PhylogenyNode n10x = PhylogenyNode
12300                     .createInstanceFromNhxString( "BLAG_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12301             if ( n10x.getNodeData().isHasTaxonomy() ) {
12302                 System.out.println( n10x.toString() );
12303                 return false;
12304             }
12305             final PhylogenyNode n10xx = PhylogenyNode
12306                     .createInstanceFromNhxString( "BLAG_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12307             if ( n10xx.getNodeData().isHasTaxonomy() ) {
12308                 System.out.println( n10xx.toString() );
12309                 return false;
12310             }
12311             final PhylogenyNode n10 = PhylogenyNode
12312                     .createInstanceFromNhxString( "BLAG_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12313             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
12314                 System.out.println( n10.toString() );
12315                 return false;
12316             }
12317             final PhylogenyNode n11 = PhylogenyNode
12318                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12319             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12320                 System.out.println( n11.toString() );
12321                 return false;
12322             }
12323             final PhylogenyNode n12 = PhylogenyNode
12324                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
12325                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12326             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12327                 System.out.println( n12.toString() );
12328                 return false;
12329             }
12330             final PhylogenyNode n13 = PhylogenyNode
12331                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12332             if ( n13.getNodeData().isHasTaxonomy() ) {
12333                 System.out.println( n13.toString() );
12334                 return false;
12335             }
12336             final PhylogenyNode n14 = PhylogenyNode
12337                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12338             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12339                 System.out.println( n14.toString() );
12340                 return false;
12341             }
12342             final PhylogenyNode n15 = PhylogenyNode
12343                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12344             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12345                 System.out.println( n15.toString() );
12346                 return false;
12347             }
12348             final PhylogenyNode n16 = PhylogenyNode
12349                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12350             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12351                 System.out.println( n16.toString() );
12352                 return false;
12353             }
12354             final PhylogenyNode n17 = PhylogenyNode
12355                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12356             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12357                 System.out.println( n17.toString() );
12358                 return false;
12359             }
12360             //
12361             final PhylogenyNode n18 = PhylogenyNode
12362                     .createInstanceFromNhxString( "Mus_musculus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12363             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12364                 System.out.println( n18.toString() );
12365                 return false;
12366             }
12367             final PhylogenyNode n19 = PhylogenyNode
12368                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
12369                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12370             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12371                 System.out.println( n19.toString() );
12372                 return false;
12373             }
12374             final PhylogenyNode n20 = PhylogenyNode
12375                     .createInstanceFromNhxString( "Mus musculus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12376             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12377                 System.out.println( n20.toString() );
12378                 return false;
12379             }
12380             final PhylogenyNode n21 = PhylogenyNode
12381                     .createInstanceFromNhxString( "Mus musculus musculus K392",
12382                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12383             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12384                 System.out.println( n21.toString() );
12385                 return false;
12386             }
12387             final PhylogenyNode n22 = PhylogenyNode
12388                     .createInstanceFromNhxString( "NEMVE_Nematostella_vectensis",
12389                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12390             if ( !n22.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12391                 System.out.println( n22.toString() );
12392                 return false;
12393             }
12394             final PhylogenyNode n23 = PhylogenyNode
12395                     .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
12396                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12397             if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12398                 System.out.println( n23.toString() );
12399                 return false;
12400             }
12401             final PhylogenyNode n24 = PhylogenyNode
12402                     .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12403             if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12404                 System.out.println( n24.toString() );
12405                 return false;
12406             }
12407             //
12408             final PhylogenyNode n25 = PhylogenyNode
12409                     .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
12410                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12411             if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12412                 System.out.println( n25.toString() );
12413                 return false;
12414             }
12415             final PhylogenyNode n26 = PhylogenyNode
12416                     .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
12417                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12418             if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12419                 System.out.println( n26.toString() );
12420                 return false;
12421             }
12422             final PhylogenyNode n27 = PhylogenyNode
12423                     .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12424             if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12425                 System.out.println( n27.toString() );
12426                 return false;
12427             }
12428         }
12429         catch ( final Exception e ) {
12430             e.printStackTrace( System.out );
12431             return false;
12432         }
12433         return true;
12434     }
12435
12436     private static boolean testTreeCopy() {
12437         try {
12438             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
12439             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
12440             final Phylogeny t1 = t0.copy();
12441             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
12442                 return false;
12443             }
12444             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12445                 return false;
12446             }
12447             t0.deleteSubtree( t0.getNode( "c" ), true );
12448             t0.deleteSubtree( t0.getNode( "a" ), true );
12449             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
12450             t0.getNode( "b" ).setName( "Bee" );
12451             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
12452                 return false;
12453             }
12454             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12455                 return false;
12456             }
12457             t0.deleteSubtree( t0.getNode( "e" ), true );
12458             t0.deleteSubtree( t0.getNode( "Bee" ), true );
12459             t0.deleteSubtree( t0.getNode( "d" ), true );
12460             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12461                 return false;
12462             }
12463         }
12464         catch ( final Exception e ) {
12465             e.printStackTrace();
12466             return false;
12467         }
12468         return true;
12469     }
12470
12471     private static boolean testTreeMethods() {
12472         try {
12473             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12474             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
12475             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
12476             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
12477                 System.out.println( t0.toNewHampshireX() );
12478                 return false;
12479             }
12480             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
12481             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
12482             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
12483                 return false;
12484             }
12485             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
12486                 return false;
12487             }
12488             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
12489                 return false;
12490             }
12491         }
12492         catch ( final Exception e ) {
12493             e.printStackTrace( System.out );
12494             return false;
12495         }
12496         return true;
12497     }
12498
12499     private static boolean testUniprotEntryRetrieval() {
12500         try {
12501             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
12502             if ( !entry.getAccession().equals( "P12345" ) ) {
12503                 return false;
12504             }
12505             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
12506                 return false;
12507             }
12508             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
12509                 return false;
12510             }
12511             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
12512                 return false;
12513             }
12514             if ( !entry.getGeneName().equals( "GOT2" ) ) {
12515                 return false;
12516             }
12517             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
12518                 return false;
12519             }
12520         }
12521         catch ( final IOException e ) {
12522             System.out.println();
12523             System.out.println( "the following might be due to absence internet connection:" );
12524             e.printStackTrace( System.out );
12525             return true;
12526         }
12527         catch ( final Exception e ) {
12528             return false;
12529         }
12530         return true;
12531     }
12532
12533     private static boolean testUniprotTaxonomySearch() {
12534         try {
12535             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
12536                                                                                                  10 );
12537             if ( results.size() != 1 ) {
12538                 return false;
12539             }
12540             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12541                 return false;
12542             }
12543             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12544                 return false;
12545             }
12546             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12547                 return false;
12548             }
12549             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12550                 return false;
12551             }
12552             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12553                 return false;
12554             }
12555             results = null;
12556             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
12557             if ( results.size() != 1 ) {
12558                 return false;
12559             }
12560             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12561                 return false;
12562             }
12563             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12564                 return false;
12565             }
12566             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12567                 return false;
12568             }
12569             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12570                 return false;
12571             }
12572             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12573                 return false;
12574             }
12575             results = null;
12576             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
12577             if ( results.size() != 1 ) {
12578                 return false;
12579             }
12580             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12581                 return false;
12582             }
12583             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12584                 return false;
12585             }
12586             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12587                 return false;
12588             }
12589             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12590                 return false;
12591             }
12592             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12593                 return false;
12594             }
12595             results = null;
12596             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
12597             if ( results.size() != 1 ) {
12598                 return false;
12599             }
12600             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12601                 return false;
12602             }
12603             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12604                 return false;
12605             }
12606             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12607                 return false;
12608             }
12609             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12610                 return false;
12611             }
12612             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12613                 return false;
12614             }
12615             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
12616                 return false;
12617             }
12618             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
12619                 return false;
12620             }
12621             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12622                     .equals( "Nematostella vectensis" ) ) {
12623                 System.out.println( results.get( 0 ).getLineage() );
12624                 return false;
12625             }
12626             //
12627             results = null;
12628             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
12629             if ( results.size() != 1 ) {
12630                 return false;
12631             }
12632             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12633                 return false;
12634             }
12635             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12636                 return false;
12637             }
12638             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12639                 return false;
12640             }
12641             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12642                 return false;
12643             }
12644             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12645                 return false;
12646             }
12647             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12648                     .equals( "Xenopus tropicalis" ) ) {
12649                 System.out.println( results.get( 0 ).getLineage() );
12650                 return false;
12651             }
12652             //
12653             results = null;
12654             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
12655             if ( results.size() != 1 ) {
12656                 return false;
12657             }
12658             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12659                 return false;
12660             }
12661             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12662                 return false;
12663             }
12664             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12665                 return false;
12666             }
12667             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12668                 return false;
12669             }
12670             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12671                 return false;
12672             }
12673             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12674                     .equals( "Xenopus tropicalis" ) ) {
12675                 System.out.println( results.get( 0 ).getLineage() );
12676                 return false;
12677             }
12678             //
12679             results = null;
12680             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
12681             if ( results.size() != 1 ) {
12682                 return false;
12683             }
12684             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12685                 return false;
12686             }
12687             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12688                 return false;
12689             }
12690             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12691                 return false;
12692             }
12693             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12694                 return false;
12695             }
12696             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12697                 return false;
12698             }
12699             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12700                     .equals( "Xenopus tropicalis" ) ) {
12701                 System.out.println( results.get( 0 ).getLineage() );
12702                 return false;
12703             }
12704         }
12705         catch ( final IOException e ) {
12706             System.out.println();
12707             System.out.println( "the following might be due to absence internet connection:" );
12708             e.printStackTrace( System.out );
12709             return true;
12710         }
12711         catch ( final Exception e ) {
12712             return false;
12713         }
12714         return true;
12715     }
12716
12717     private static boolean testWabiTxSearch() {
12718         try {
12719             String result = "";
12720             result = TxSearch.searchSimple( "nematostella" );
12721             result = TxSearch.getTxId( "nematostella" );
12722             if ( !result.equals( "45350" ) ) {
12723                 return false;
12724             }
12725             result = TxSearch.getTxName( "45350" );
12726             if ( !result.equals( "Nematostella" ) ) {
12727                 return false;
12728             }
12729             result = TxSearch.getTxId( "nematostella vectensis" );
12730             if ( !result.equals( "45351" ) ) {
12731                 return false;
12732             }
12733             result = TxSearch.getTxName( "45351" );
12734             if ( !result.equals( "Nematostella vectensis" ) ) {
12735                 return false;
12736             }
12737             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
12738             if ( !result.equals( "536089" ) ) {
12739                 return false;
12740             }
12741             result = TxSearch.getTxName( "536089" );
12742             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
12743                 return false;
12744             }
12745             final List<String> queries = new ArrayList<String>();
12746             queries.add( "Campylobacter coli" );
12747             queries.add( "Escherichia coli" );
12748             queries.add( "Arabidopsis" );
12749             queries.add( "Trichoplax" );
12750             queries.add( "Samanea saman" );
12751             queries.add( "Kluyveromyces marxianus" );
12752             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
12753             queries.add( "Bornavirus parrot/PDD/2008" );
12754             final List<RANKS> ranks = new ArrayList<RANKS>();
12755             ranks.add( RANKS.SUPERKINGDOM );
12756             ranks.add( RANKS.KINGDOM );
12757             ranks.add( RANKS.FAMILY );
12758             ranks.add( RANKS.GENUS );
12759             ranks.add( RANKS.TRIBE );
12760             result = TxSearch.searchLineage( queries, ranks );
12761             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
12762             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
12763         }
12764         catch ( final Exception e ) {
12765             System.out.println();
12766             System.out.println( "the following might be due to absence internet connection:" );
12767             e.printStackTrace( System.out );
12768             return false;
12769         }
12770         return true;
12771     }
12772 }