inprogress
[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( "MSA entropy: " );
184         if ( Test.testMsaEntropy() ) {
185             System.out.println( "OK." );
186             succeeded++;
187         }
188         else {
189             System.out.println( "failed." );
190             failed++;
191         }
192         System.exit( 0 );
193         System.out.print( "Basic node methods: " );
194         if ( Test.testBasicNodeMethods() ) {
195             System.out.println( "OK." );
196             succeeded++;
197         }
198         else {
199             System.out.println( "failed." );
200             failed++;
201         }
202         System.out.print( "Protein id: " );
203         if ( !testProteinId() ) {
204             System.out.println( "failed." );
205             failed++;
206         }
207         else {
208             succeeded++;
209         }
210         System.out.println( "OK." );
211         System.out.print( "Species: " );
212         if ( !testSpecies() ) {
213             System.out.println( "failed." );
214             failed++;
215         }
216         else {
217             succeeded++;
218         }
219         System.out.println( "OK." );
220         System.out.print( "Basic domain: " );
221         if ( !testBasicDomain() ) {
222             System.out.println( "failed." );
223             failed++;
224         }
225         else {
226             succeeded++;
227         }
228         System.out.println( "OK." );
229         System.out.print( "Basic protein: " );
230         if ( !testBasicProtein() ) {
231             System.out.println( "failed." );
232             failed++;
233         }
234         else {
235             succeeded++;
236         }
237         System.out.println( "OK." );
238         System.out.print( "Sequence writer: " );
239         if ( testSequenceWriter() ) {
240             System.out.println( "OK." );
241             succeeded++;
242         }
243         else {
244             System.out.println( "failed." );
245             failed++;
246         }
247         System.out.print( "Sequence id parsing: " );
248         if ( testSequenceIdParsing() ) {
249             System.out.println( "OK." );
250             succeeded++;
251         }
252         else {
253             System.out.println( "failed." );
254             failed++;
255         }
256         System.out.print( "UniProtKB id extraction: " );
257         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
258             System.out.println( "OK." );
259             succeeded++;
260         }
261         else {
262             System.out.println( "failed." );
263             failed++;
264         }
265         System.out.print( "Sequence DB tools 1: " );
266         if ( testSequenceDbWsTools1() ) {
267             System.out.println( "OK." );
268             succeeded++;
269         }
270         else {
271             System.out.println( "failed." );
272             failed++;
273         }
274         System.out.print( "Hmmscan output parser: " );
275         if ( testHmmscanOutputParser() ) {
276             System.out.println( "OK." );
277             succeeded++;
278         }
279         else {
280             System.out.println( "failed." );
281             failed++;
282         }
283         System.out.print( "Overlap removal: " );
284         if ( !org.forester.test.Test.testOverlapRemoval() ) {
285             System.out.println( "failed." );
286             failed++;
287         }
288         else {
289             succeeded++;
290         }
291         System.out.println( "OK." );
292         System.out.print( "Engulfing overlap removal: " );
293         if ( !Test.testEngulfingOverlapRemoval() ) {
294             System.out.println( "failed." );
295             failed++;
296         }
297         else {
298             succeeded++;
299         }
300         System.out.println( "OK." );
301         System.out.print( "Taxonomy code extraction: " );
302         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
303             System.out.println( "OK." );
304             succeeded++;
305         }
306         else {
307             System.out.println( "failed." );
308             failed++;
309         }
310         System.out.print( "SN extraction: " );
311         if ( Test.testExtractSNFromNodeName() ) {
312             System.out.println( "OK." );
313             succeeded++;
314         }
315         else {
316             System.out.println( "failed." );
317             failed++;
318         }
319         System.out.print( "Taxonomy extraction (general): " );
320         if ( Test.testTaxonomyExtraction() ) {
321             System.out.println( "OK." );
322             succeeded++;
323         }
324         else {
325             System.out.println( "failed." );
326             failed++;
327         }
328         System.out.print( "Uri for Aptx web sequence accession: " );
329         if ( Test.testCreateUriForSeqWeb() ) {
330             System.out.println( "OK." );
331             succeeded++;
332         }
333         else {
334             System.out.println( "failed." );
335             failed++;
336         }
337         System.out.print( "Basic node construction and parsing of NHX (node level): " );
338         if ( Test.testNHXNodeParsing() ) {
339             System.out.println( "OK." );
340             succeeded++;
341         }
342         else {
343             System.out.println( "failed." );
344             failed++;
345         }
346         System.out.print( "NHX parsing iterating: " );
347         if ( Test.testNHParsingIter() ) {
348             System.out.println( "OK." );
349             succeeded++;
350         }
351         else {
352             System.out.println( "failed." );
353             failed++;
354         }
355         System.out.print( "NH parsing: " );
356         if ( Test.testNHParsing() ) {
357             System.out.println( "OK." );
358             succeeded++;
359         }
360         else {
361             System.out.println( "failed." );
362             failed++;
363         }
364         System.out.print( "Conversion to NHX (node level): " );
365         if ( Test.testNHXconversion() ) {
366             System.out.println( "OK." );
367             succeeded++;
368         }
369         else {
370             System.out.println( "failed." );
371             failed++;
372         }
373         System.out.print( "NHX parsing: " );
374         if ( Test.testNHXParsing() ) {
375             System.out.println( "OK." );
376             succeeded++;
377         }
378         else {
379             System.out.println( "failed." );
380             failed++;
381         }
382         System.out.print( "NHX parsing with quotes: " );
383         if ( Test.testNHXParsingQuotes() ) {
384             System.out.println( "OK." );
385             succeeded++;
386         }
387         else {
388             System.out.println( "failed." );
389             failed++;
390         }
391         System.out.print( "NHX parsing (MrBayes): " );
392         if ( Test.testNHXParsingMB() ) {
393             System.out.println( "OK." );
394             succeeded++;
395         }
396         else {
397             System.out.println( "failed." );
398             failed++;
399         }
400         System.out.print( "Nexus characters parsing: " );
401         if ( Test.testNexusCharactersParsing() ) {
402             System.out.println( "OK." );
403             succeeded++;
404         }
405         else {
406             System.out.println( "failed." );
407             failed++;
408         }
409         System.out.print( "Nexus tree parsing iterating: " );
410         if ( Test.testNexusTreeParsingIterating() ) {
411             System.out.println( "OK." );
412             succeeded++;
413         }
414         else {
415             System.out.println( "failed." );
416             failed++;
417         }
418         System.out.print( "Nexus tree parsing: " );
419         if ( Test.testNexusTreeParsing() ) {
420             System.out.println( "OK." );
421             succeeded++;
422         }
423         else {
424             System.out.println( "failed." );
425             failed++;
426         }
427         System.out.print( "Nexus tree parsing (translating): " );
428         if ( Test.testNexusTreeParsingTranslating() ) {
429             System.out.println( "OK." );
430             succeeded++;
431         }
432         else {
433             System.out.println( "failed." );
434             failed++;
435         }
436         System.out.print( "Nexus matrix parsing: " );
437         if ( Test.testNexusMatrixParsing() ) {
438             System.out.println( "OK." );
439             succeeded++;
440         }
441         else {
442             System.out.println( "failed." );
443             failed++;
444         }
445         System.out.print( "Basic phyloXML parsing: " );
446         if ( Test.testBasicPhyloXMLparsing() ) {
447             System.out.println( "OK." );
448             succeeded++;
449         }
450         else {
451             System.out.println( "failed." );
452             failed++;
453         }
454         System.out.print( "Basic phyloXML parsing (validating against schema): " );
455         if ( testBasicPhyloXMLparsingValidating() ) {
456             System.out.println( "OK." );
457             succeeded++;
458         }
459         else {
460             System.out.println( "failed." );
461             failed++;
462         }
463         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
464         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
465             System.out.println( "OK." );
466             succeeded++;
467         }
468         else {
469             System.out.println( "failed." );
470             failed++;
471         }
472         System.out.print( "phyloXML Distribution Element: " );
473         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
474             System.out.println( "OK." );
475             succeeded++;
476         }
477         else {
478             System.out.println( "failed." );
479             failed++;
480         }
481         System.out.print( "Tol XML parsing: " );
482         if ( Test.testBasicTolXMLparsing() ) {
483             System.out.println( "OK." );
484             succeeded++;
485         }
486         else {
487             System.out.println( "failed." );
488             failed++;
489         }
490         System.out.print( "Copying of node data: " );
491         if ( Test.testCopyOfNodeData() ) {
492             System.out.println( "OK." );
493             succeeded++;
494         }
495         else {
496             System.out.println( "failed." );
497             failed++;
498         }
499         System.out.print( "Tree copy: " );
500         if ( Test.testTreeCopy() ) {
501             System.out.println( "OK." );
502             succeeded++;
503         }
504         else {
505             System.out.println( "failed." );
506             failed++;
507         }
508         System.out.print( "Basic tree methods: " );
509         if ( Test.testBasicTreeMethods() ) {
510             System.out.println( "OK." );
511             succeeded++;
512         }
513         else {
514             System.out.println( "failed." );
515             failed++;
516         }
517         System.out.print( "Tree methods: " );
518         if ( Test.testTreeMethods() ) {
519             System.out.println( "OK." );
520             succeeded++;
521         }
522         else {
523             System.out.println( "failed." );
524             failed++;
525         }
526         System.out.print( "Postorder Iterator: " );
527         if ( Test.testPostOrderIterator() ) {
528             System.out.println( "OK." );
529             succeeded++;
530         }
531         else {
532             System.out.println( "failed." );
533             failed++;
534         }
535         System.out.print( "Preorder Iterator: " );
536         if ( Test.testPreOrderIterator() ) {
537             System.out.println( "OK." );
538             succeeded++;
539         }
540         else {
541             System.out.println( "failed." );
542             failed++;
543         }
544         System.out.print( "Levelorder Iterator: " );
545         if ( Test.testLevelOrderIterator() ) {
546             System.out.println( "OK." );
547             succeeded++;
548         }
549         else {
550             System.out.println( "failed." );
551             failed++;
552         }
553         System.out.print( "Re-id methods: " );
554         if ( Test.testReIdMethods() ) {
555             System.out.println( "OK." );
556             succeeded++;
557         }
558         else {
559             System.out.println( "failed." );
560             failed++;
561         }
562         System.out.print( "Methods on last external nodes: " );
563         if ( Test.testLastExternalNodeMethods() ) {
564             System.out.println( "OK." );
565             succeeded++;
566         }
567         else {
568             System.out.println( "failed." );
569             failed++;
570         }
571         System.out.print( "Methods on external nodes: " );
572         if ( Test.testExternalNodeRelatedMethods() ) {
573             System.out.println( "OK." );
574             succeeded++;
575         }
576         else {
577             System.out.println( "failed." );
578             failed++;
579         }
580         System.out.print( "Deletion of external nodes: " );
581         if ( Test.testDeletionOfExternalNodes() ) {
582             System.out.println( "OK." );
583             succeeded++;
584         }
585         else {
586             System.out.println( "failed." );
587             failed++;
588         }
589         System.out.print( "Subtree deletion: " );
590         if ( Test.testSubtreeDeletion() ) {
591             System.out.println( "OK." );
592             succeeded++;
593         }
594         else {
595             System.out.println( "failed." );
596             failed++;
597         }
598         System.out.print( "Phylogeny branch: " );
599         if ( Test.testPhylogenyBranch() ) {
600             System.out.println( "OK." );
601             succeeded++;
602         }
603         else {
604             System.out.println( "failed." );
605             failed++;
606         }
607         System.out.print( "Rerooting: " );
608         if ( Test.testRerooting() ) {
609             System.out.println( "OK." );
610             succeeded++;
611         }
612         else {
613             System.out.println( "failed." );
614             failed++;
615         }
616         System.out.print( "Mipoint rooting: " );
617         if ( Test.testMidpointrooting() ) {
618             System.out.println( "OK." );
619             succeeded++;
620         }
621         else {
622             System.out.println( "failed." );
623             failed++;
624         }
625         System.out.print( "Node removal: " );
626         if ( Test.testNodeRemoval() ) {
627             System.out.println( "OK." );
628             succeeded++;
629         }
630         else {
631             System.out.println( "failed." );
632             failed++;
633         }
634         System.out.print( "Support count: " );
635         if ( Test.testSupportCount() ) {
636             System.out.println( "OK." );
637             succeeded++;
638         }
639         else {
640             System.out.println( "failed." );
641             failed++;
642         }
643         System.out.print( "Support transfer: " );
644         if ( Test.testSupportTransfer() ) {
645             System.out.println( "OK." );
646             succeeded++;
647         }
648         else {
649             System.out.println( "failed." );
650             failed++;
651         }
652         System.out.print( "Finding of LCA: " );
653         if ( Test.testGetLCA() ) {
654             System.out.println( "OK." );
655             succeeded++;
656         }
657         else {
658             System.out.println( "failed." );
659             failed++;
660         }
661         System.out.print( "Finding of LCA 2: " );
662         if ( Test.testGetLCA2() ) {
663             System.out.println( "OK." );
664             succeeded++;
665         }
666         else {
667             System.out.println( "failed." );
668             failed++;
669         }
670         System.out.print( "Calculation of distance between nodes: " );
671         if ( Test.testGetDistance() ) {
672             System.out.println( "OK." );
673             succeeded++;
674         }
675         else {
676             System.out.println( "failed." );
677             failed++;
678         }
679         System.out.print( "Descriptive statistics: " );
680         if ( Test.testDescriptiveStatistics() ) {
681             System.out.println( "OK." );
682             succeeded++;
683         }
684         else {
685             System.out.println( "failed." );
686             failed++;
687         }
688         System.out.print( "Data objects and methods: " );
689         if ( Test.testDataObjects() ) {
690             System.out.println( "OK." );
691             succeeded++;
692         }
693         else {
694             System.out.println( "failed." );
695             failed++;
696         }
697         System.out.print( "Properties map: " );
698         if ( Test.testPropertiesMap() ) {
699             System.out.println( "OK." );
700             succeeded++;
701         }
702         else {
703             System.out.println( "failed." );
704             failed++;
705         }
706         System.out.print( "SDIse: " );
707         if ( Test.testSDIse() ) {
708             System.out.println( "OK." );
709             succeeded++;
710         }
711         else {
712             System.out.println( "failed." );
713             failed++;
714         }
715         System.out.print( "SDIunrooted: " );
716         if ( Test.testSDIunrooted() ) {
717             System.out.println( "OK." );
718             succeeded++;
719         }
720         else {
721             System.out.println( "failed." );
722             failed++;
723         }
724         System.out.print( "GSDI: " );
725         if ( TestGSDI.test() ) {
726             System.out.println( "OK." );
727             succeeded++;
728         }
729         else {
730             System.out.println( "failed." );
731             failed++;
732         }
733         System.out.print( "RIO: " );
734         if ( TestRIO.test() ) {
735             System.out.println( "OK." );
736             succeeded++;
737         }
738         else {
739             System.out.println( "failed." );
740             failed++;
741         }
742         System.out.print( "Phylogeny reconstruction:" );
743         System.out.println();
744         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
745             System.out.println( "OK." );
746             succeeded++;
747         }
748         else {
749             System.out.println( "failed." );
750             failed++;
751         }
752         System.out.print( "Analysis of domain architectures: " );
753         System.out.println();
754         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
755             System.out.println( "OK." );
756             succeeded++;
757         }
758         else {
759             System.out.println( "failed." );
760             failed++;
761         }
762         System.out.print( "GO: " );
763         System.out.println();
764         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
765             System.out.println( "OK." );
766             succeeded++;
767         }
768         else {
769             System.out.println( "failed." );
770             failed++;
771         }
772         System.out.print( "Modeling tools: " );
773         if ( TestPccx.test() ) {
774             System.out.println( "OK." );
775             succeeded++;
776         }
777         else {
778             System.out.println( "failed." );
779             failed++;
780         }
781         System.out.print( "Split Matrix strict: " );
782         if ( Test.testSplitStrict() ) {
783             System.out.println( "OK." );
784             succeeded++;
785         }
786         else {
787             System.out.println( "failed." );
788             failed++;
789         }
790         System.out.print( "Split Matrix: " );
791         if ( Test.testSplit() ) {
792             System.out.println( "OK." );
793             succeeded++;
794         }
795         else {
796             System.out.println( "failed." );
797             failed++;
798         }
799         System.out.print( "Confidence Assessor: " );
800         if ( Test.testConfidenceAssessor() ) {
801             System.out.println( "OK." );
802             succeeded++;
803         }
804         else {
805             System.out.println( "failed." );
806             failed++;
807         }
808         System.out.print( "Basic table: " );
809         if ( Test.testBasicTable() ) {
810             System.out.println( "OK." );
811             succeeded++;
812         }
813         else {
814             System.out.println( "failed." );
815             failed++;
816         }
817         System.out.print( "General table: " );
818         if ( Test.testGeneralTable() ) {
819             System.out.println( "OK." );
820             succeeded++;
821         }
822         else {
823             System.out.println( "failed." );
824             failed++;
825         }
826         System.out.print( "Amino acid sequence: " );
827         if ( Test.testAminoAcidSequence() ) {
828             System.out.println( "OK." );
829             succeeded++;
830         }
831         else {
832             System.out.println( "failed." );
833             failed++;
834         }
835         System.out.print( "General MSA parser: " );
836         if ( Test.testGeneralMsaParser() ) {
837             System.out.println( "OK." );
838             succeeded++;
839         }
840         else {
841             System.out.println( "failed." );
842             failed++;
843         }
844         System.out.print( "Fasta parser for msa: " );
845         if ( Test.testFastaParser() ) {
846             System.out.println( "OK." );
847             succeeded++;
848         }
849         else {
850             System.out.println( "failed." );
851             failed++;
852         }
853         System.out.print( "Creation of balanced phylogeny: " );
854         if ( Test.testCreateBalancedPhylogeny() ) {
855             System.out.println( "OK." );
856             succeeded++;
857         }
858         else {
859             System.out.println( "failed." );
860             failed++;
861         }
862         System.out.print( "Genbank accessor parsing: " );
863         if ( Test.testGenbankAccessorParsing() ) {
864             System.out.println( "OK." );
865             succeeded++;
866         }
867         else {
868             System.out.println( "failed." );
869             failed++;
870         }
871         String path = "";
872         final String os = ForesterUtil.OS_NAME.toLowerCase();
873         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
874             path = "/usr/local/bin/mafft";
875         }
876         else if ( os.indexOf( "win" ) >= 0 ) {
877             path = "C:\\Program Files\\mafft-win\\mafft.bat";
878         }
879         else {
880             path = "mafft";
881             if ( !MsaInferrer.isInstalled( path ) ) {
882                 path = "/usr/bin/mafft";
883             }
884             if ( !MsaInferrer.isInstalled( path ) ) {
885                 path = "/usr/local/bin/mafft";
886             }
887         }
888         if ( MsaInferrer.isInstalled( path ) ) {
889             System.out.print( "MAFFT (external program): " );
890             if ( Test.testMafft( path ) ) {
891                 System.out.println( "OK." );
892                 succeeded++;
893             }
894             else {
895                 System.out.println( "failed [will not count towards failed tests]" );
896             }
897         }
898         System.out.print( "Next nodes with collapsed: " );
899         if ( Test.testNextNodeWithCollapsing() ) {
900             System.out.println( "OK." );
901             succeeded++;
902         }
903         else {
904             System.out.println( "failed." );
905             failed++;
906         }
907         System.out.print( "Simple MSA quality: " );
908         if ( Test.testMsaQualityMethod() ) {
909             System.out.println( "OK." );
910             succeeded++;
911         }
912         else {
913             System.out.println( "failed." );
914             failed++;
915         }
916         System.out.print( "Deleteable MSA: " );
917         if ( Test.testDeleteableMsa() ) {
918             System.out.println( "OK." );
919             succeeded++;
920         }
921         else {
922             System.out.println( "failed." );
923             failed++;
924         }
925         if ( PERFORM_DB_TESTS ) {
926             System.out.print( "Uniprot Entry Retrieval: " );
927             if ( Test.testUniprotEntryRetrieval() ) {
928                 System.out.println( "OK." );
929                 succeeded++;
930             }
931             else {
932                 System.out.println( "failed." );
933                 failed++;
934             }
935             System.out.print( "Ebi Entry Retrieval: " );
936             if ( Test.testEbiEntryRetrieval() ) {
937                 System.out.println( "OK." );
938                 succeeded++;
939             }
940             else {
941                 System.out.println( "failed." );
942                 failed++;
943             }
944             System.out.print( "Sequence DB tools 2: " );
945             if ( testSequenceDbWsTools2() ) {
946                 System.out.println( "OK." );
947                 succeeded++;
948             }
949             else {
950                 System.out.println( "failed." );
951                 failed++;
952                 System.exit( -1 );
953             }
954             System.out.print( "Uniprot Taxonomy Search: " );
955             if ( Test.testUniprotTaxonomySearch() ) {
956                 System.out.println( "OK." );
957                 succeeded++;
958             }
959             else {
960                 System.out.println( "failed." );
961                 failed++;
962             }
963         }
964         if ( PERFORM_WEB_TREE_ACCESS ) {
965             System.out.print( "NHX parsing from URL: " );
966             if ( Test.testNHXparsingFromURL() ) {
967                 System.out.println( "OK." );
968                 succeeded++;
969             }
970             else {
971                 System.out.println( "failed." );
972                 failed++;
973             }
974             System.out.print( "phyloXML parsing from URL: " );
975             if ( Test.testPhyloXMLparsingFromURL() ) {
976                 System.out.println( "OK." );
977                 succeeded++;
978             }
979             else {
980                 System.out.println( "failed." );
981                 failed++;
982             }
983             System.out.print( "TreeBase acccess: " );
984             if ( Test.testTreeBaseReading() ) {
985                 System.out.println( "OK." );
986                 succeeded++;
987             }
988             else {
989                 System.out.println( "failed." );
990                 failed++;
991             }
992             //
993             System.out.print( "ToL access: " );
994             if ( Test.testToLReading() ) {
995                 System.out.println( "OK." );
996                 succeeded++;
997             }
998             else {
999                 System.out.println( "failed." );
1000                 failed++;
1001             }
1002             //
1003             System.out.print( "TreeFam access: " );
1004             if ( Test.testTreeFamReading() ) {
1005                 System.out.println( "OK." );
1006                 succeeded++;
1007             }
1008             else {
1009                 System.out.println( "failed." );
1010                 failed++;
1011             }
1012             //
1013             //
1014             System.out.print( "Pfam tree access: " );
1015             if ( Test.testPfamTreeReading() ) {
1016                 System.out.println( "OK." );
1017                 succeeded++;
1018             }
1019             else {
1020                 System.out.println( "failed." );
1021                 failed++;
1022             }
1023         }
1024         System.out.println();
1025         final Runtime rt = java.lang.Runtime.getRuntime();
1026         final long free_memory = rt.freeMemory() / 1000000;
1027         final long total_memory = rt.totalMemory() / 1000000;
1028         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1029                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1030         System.out.println();
1031         System.out.println( "Successful tests: " + succeeded );
1032         System.out.println( "Failed     tests: " + failed );
1033         System.out.println();
1034         if ( failed < 1 ) {
1035             System.out.println( "OK." );
1036         }
1037         else {
1038             System.out.println( "Not OK." );
1039         }
1040     }
1041
1042     public static boolean testEngulfingOverlapRemoval() {
1043         try {
1044             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1045             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1046             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1047             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1048             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1049             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1050             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1051             final List<Boolean> covered = new ArrayList<Boolean>();
1052             covered.add( true ); // 0
1053             covered.add( false ); // 1
1054             covered.add( true ); // 2
1055             covered.add( false ); // 3
1056             covered.add( true ); // 4
1057             covered.add( true ); // 5
1058             covered.add( false ); // 6
1059             covered.add( true ); // 7
1060             covered.add( true ); // 8
1061             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1062                 return false;
1063             }
1064             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1065                 return false;
1066             }
1067             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1068                 return false;
1069             }
1070             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1071                 return false;
1072             }
1073             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1074                 return false;
1075             }
1076             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1077                 return false;
1078             }
1079             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1080                 return false;
1081             }
1082             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1083             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1084             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1085             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1086             abc.addProteinDomain( a );
1087             abc.addProteinDomain( b );
1088             abc.addProteinDomain( c );
1089             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1090             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1091             if ( abc.getNumberOfProteinDomains() != 3 ) {
1092                 return false;
1093             }
1094             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1095                 return false;
1096             }
1097             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1098                 return false;
1099             }
1100             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1101                 return false;
1102             }
1103             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1104                 return false;
1105             }
1106             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1107             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1108             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1109             final Protein def = new BasicProtein( "def", "nemve", 0 );
1110             def.addProteinDomain( d );
1111             def.addProteinDomain( e );
1112             def.addProteinDomain( f );
1113             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1114             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1115             if ( def.getNumberOfProteinDomains() != 3 ) {
1116                 return false;
1117             }
1118             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1119                 return false;
1120             }
1121             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1122                 return false;
1123             }
1124             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1125                 return false;
1126             }
1127             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1128                 return false;
1129             }
1130             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1131                 return false;
1132             }
1133         }
1134         catch ( final Exception e ) {
1135             e.printStackTrace( System.out );
1136             return false;
1137         }
1138         return true;
1139     }
1140
1141     public static final boolean testNHXparsingFromURL() {
1142         try {
1143             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1144             final URL u = new URL( s );
1145             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1146             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1147             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1148                 return false;
1149             }
1150             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1151                 System.out.println( phys[ 0 ].toNewHampshire() );
1152                 return false;
1153             }
1154             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1155                 System.out.println( phys[ 1 ].toNewHampshire() );
1156                 return false;
1157             }
1158             final Phylogeny[] phys2 = factory.create( u.openStream(), new NHXParser() );
1159             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1160                 return false;
1161             }
1162             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1163                 System.out.println( phys2[ 0 ].toNewHampshire() );
1164                 return false;
1165             }
1166             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1167             final NHXParser p = new NHXParser();
1168             final URL u2 = new URL( s );
1169             p.setSource( u2 );
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.hasNext() ) {
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             p.reset();
1190             if ( !p.hasNext() ) {
1191                 return false;
1192             }
1193             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1194                 return false;
1195             }
1196             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1197                 return false;
1198             }
1199         }
1200         catch ( final Exception e ) {
1201             e.printStackTrace();
1202         }
1203         return true;
1204     }
1205
1206     public static boolean testOverlapRemoval() {
1207         try {
1208             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1209             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1210             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1211             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1212             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1213             final List<Boolean> covered = new ArrayList<Boolean>();
1214             covered.add( true ); // 0
1215             covered.add( false ); // 1
1216             covered.add( true ); // 2
1217             covered.add( false ); // 3
1218             covered.add( true ); // 4
1219             covered.add( true ); // 5
1220             covered.add( false ); // 6
1221             covered.add( true ); // 7
1222             covered.add( true ); // 8
1223             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1224                 return false;
1225             }
1226             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1227                 return false;
1228             }
1229             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1230                 return false;
1231             }
1232             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1233                 return false;
1234             }
1235             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1236                 return false;
1237             }
1238             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1239             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1240             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1241             ab.addProteinDomain( a );
1242             ab.addProteinDomain( b );
1243             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1244             if ( ab.getNumberOfProteinDomains() != 2 ) {
1245                 return false;
1246             }
1247             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1248                 return false;
1249             }
1250             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1251                 return false;
1252             }
1253             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1254             if ( ab.getNumberOfProteinDomains() != 2 ) {
1255                 return false;
1256             }
1257             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1258                 return false;
1259             }
1260             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1261             final Domain d = new BasicDomain( "d",
1262                                               ( short ) 10000,
1263                                               ( short ) 10500,
1264                                               ( short ) 1,
1265                                               ( short ) 1,
1266                                               0.0000001,
1267                                               1 );
1268             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1269             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1270             cde.addProteinDomain( c );
1271             cde.addProteinDomain( d );
1272             cde.addProteinDomain( e );
1273             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1274             if ( cde.getNumberOfProteinDomains() != 3 ) {
1275                 return false;
1276             }
1277             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1278                 return false;
1279             }
1280             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1281             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1282             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1283             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1284             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1285             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1286             fghi.addProteinDomain( f );
1287             fghi.addProteinDomain( g );
1288             fghi.addProteinDomain( h );
1289             fghi.addProteinDomain( i );
1290             fghi.addProteinDomain( i );
1291             fghi.addProteinDomain( i );
1292             fghi.addProteinDomain( i2 );
1293             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1294             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1295                 return false;
1296             }
1297             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1298                 return false;
1299             }
1300             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1301                 return false;
1302             }
1303             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1304             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1305                 return false;
1306             }
1307             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1308                 return false;
1309             }
1310             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1311             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1312             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1313             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1314             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1315             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1316             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1317             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1318             jklm.addProteinDomain( j );
1319             jklm.addProteinDomain( k );
1320             jklm.addProteinDomain( l );
1321             jklm.addProteinDomain( m );
1322             jklm.addProteinDomain( m0 );
1323             jklm.addProteinDomain( m1 );
1324             jklm.addProteinDomain( m2 );
1325             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1326             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1327                 return false;
1328             }
1329             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1330                 return false;
1331             }
1332             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1333                 return false;
1334             }
1335             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1336             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1337                 return false;
1338             }
1339             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1340                 return false;
1341             }
1342             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1343             final Protein od = new BasicProtein( "od", "varanus", 0 );
1344             od.addProteinDomain( only );
1345             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1346             if ( od.getNumberOfProteinDomains() != 1 ) {
1347                 return false;
1348             }
1349             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1350                 return false;
1351             }
1352         }
1353         catch ( final Exception e ) {
1354             e.printStackTrace( System.out );
1355             return false;
1356         }
1357         return true;
1358     }
1359
1360     public static final boolean testPfamTreeReading() {
1361         try {
1362             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1363             final NHXParser parser = new NHXParser();
1364             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1365             parser.setReplaceUnderscores( false );
1366             parser.setGuessRootedness( true );
1367             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1368             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1369             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1370                 return false;
1371             }
1372             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1373                 return false;
1374             }
1375         }
1376         catch ( final Exception e ) {
1377             e.printStackTrace();
1378         }
1379         return true;
1380     }
1381
1382     public static final boolean testPhyloXMLparsingFromURL() {
1383         try {
1384             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1385             final URL u = new URL( s );
1386             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1387             final Phylogeny[] phys = factory.create( u.openStream(), PhyloXmlParser.createPhyloXmlParser() );
1388             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1389                 return false;
1390             }
1391         }
1392         catch ( final Exception e ) {
1393             e.printStackTrace();
1394         }
1395         return true;
1396     }
1397
1398     public static final boolean testToLReading() {
1399         try {
1400             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1401             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1402             final Phylogeny[] phys = factory.create( u.openStream(), new TolParser() );
1403             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1404                 return false;
1405             }
1406             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1407                 return false;
1408             }
1409             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Protacanthopterygii" ) ) {
1410                 return false;
1411             }
1412             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1413                 return false;
1414             }
1415         }
1416         catch ( final Exception e ) {
1417             e.printStackTrace();
1418         }
1419         return true;
1420     }
1421
1422     public static final boolean testTreeBaseReading() {
1423         try {
1424             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );
1425             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1426             parser.setReplaceUnderscores( true );
1427             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1428             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1429             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1430                 return false;
1431             }
1432             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1433             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1434             parser2.setReplaceUnderscores( true );
1435             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1436             final Phylogeny[] phys2 = factory2.create( u2.openStream(), parser2 );
1437             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1438                 return false;
1439             }
1440         }
1441         catch ( final Exception e ) {
1442             e.printStackTrace();
1443         }
1444         return true;
1445     }
1446
1447     public static final boolean testTreeFamReading() {
1448         try {
1449             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1450             final NHXParser parser = new NHXParser();
1451             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1452             parser.setReplaceUnderscores( false );
1453             parser.setGuessRootedness( true );
1454             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1455             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1456             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1457                 return false;
1458             }
1459             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1460                 return false;
1461             }
1462         }
1463         catch ( final Exception e ) {
1464             e.printStackTrace();
1465         }
1466         return true;
1467     }
1468
1469     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1470         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1471         return p;
1472     }
1473
1474     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1475         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1476     }
1477
1478     private static boolean testAminoAcidSequence() {
1479         try {
1480             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1481             if ( aa1.getLength() != 13 ) {
1482                 return false;
1483             }
1484             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1485                 return false;
1486             }
1487             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1488                 return false;
1489             }
1490             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1491                 return false;
1492             }
1493             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1494             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
1495                 return false;
1496             }
1497             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1498             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1499                 return false;
1500             }
1501             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1502             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1503                 return false;
1504             }
1505         }
1506         catch ( final Exception e ) {
1507             e.printStackTrace();
1508             return false;
1509         }
1510         return true;
1511     }
1512
1513     private static boolean testBasicDomain() {
1514         try {
1515             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1516             if ( !pd.getDomainId().equals( "id" ) ) {
1517                 return false;
1518             }
1519             if ( pd.getNumber() != 1 ) {
1520                 return false;
1521             }
1522             if ( pd.getTotalCount() != 4 ) {
1523                 return false;
1524             }
1525             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1526                 return false;
1527             }
1528             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1529             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1530             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1531             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1532             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1533             if ( !a1.equals( a1 ) ) {
1534                 return false;
1535             }
1536             if ( !a1.equals( a1_copy ) ) {
1537                 return false;
1538             }
1539             if ( !a1.equals( a1_equal ) ) {
1540                 return false;
1541             }
1542             if ( !a1.equals( a2 ) ) {
1543                 return false;
1544             }
1545             if ( a1.equals( a3 ) ) {
1546                 return false;
1547             }
1548             if ( a1.compareTo( a1 ) != 0 ) {
1549                 return false;
1550             }
1551             if ( a1.compareTo( a1_copy ) != 0 ) {
1552                 return false;
1553             }
1554             if ( a1.compareTo( a1_equal ) != 0 ) {
1555                 return false;
1556             }
1557             if ( a1.compareTo( a2 ) != 0 ) {
1558                 return false;
1559             }
1560             if ( a1.compareTo( a3 ) == 0 ) {
1561                 return false;
1562             }
1563         }
1564         catch ( final Exception e ) {
1565             e.printStackTrace( System.out );
1566             return false;
1567         }
1568         return true;
1569     }
1570
1571     private static boolean testBasicNodeMethods() {
1572         try {
1573             if ( PhylogenyNode.getNodeCount() != 0 ) {
1574                 return false;
1575             }
1576             final PhylogenyNode n1 = new PhylogenyNode();
1577             final PhylogenyNode n2 = PhylogenyNode
1578                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1579             final PhylogenyNode n3 = PhylogenyNode
1580                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1581             final PhylogenyNode n4 = PhylogenyNode
1582                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1583             if ( n1.isHasAssignedEvent() ) {
1584                 return false;
1585             }
1586             if ( PhylogenyNode.getNodeCount() != 4 ) {
1587                 return false;
1588             }
1589             if ( n3.getIndicator() != 0 ) {
1590                 return false;
1591             }
1592             if ( n3.getNumberOfExternalNodes() != 1 ) {
1593                 return false;
1594             }
1595             if ( !n3.isExternal() ) {
1596                 return false;
1597             }
1598             if ( !n3.isRoot() ) {
1599                 return false;
1600             }
1601             if ( !n4.getName().equals( "n4" ) ) {
1602                 return false;
1603             }
1604         }
1605         catch ( final Exception e ) {
1606             e.printStackTrace( System.out );
1607             return false;
1608         }
1609         return true;
1610     }
1611
1612     private static boolean testBasicPhyloXMLparsing() {
1613         try {
1614             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1615             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1616             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1617                                                               xml_parser );
1618             if ( xml_parser.getErrorCount() > 0 ) {
1619                 System.out.println( xml_parser.getErrorMessages().toString() );
1620                 return false;
1621             }
1622             if ( phylogenies_0.length != 4 ) {
1623                 return false;
1624             }
1625             final Phylogeny t1 = phylogenies_0[ 0 ];
1626             final Phylogeny t2 = phylogenies_0[ 1 ];
1627             final Phylogeny t3 = phylogenies_0[ 2 ];
1628             final Phylogeny t4 = phylogenies_0[ 3 ];
1629             if ( t1.getNumberOfExternalNodes() != 1 ) {
1630                 return false;
1631             }
1632             if ( !t1.isRooted() ) {
1633                 return false;
1634             }
1635             if ( t1.isRerootable() ) {
1636                 return false;
1637             }
1638             if ( !t1.getType().equals( "gene_tree" ) ) {
1639                 return false;
1640             }
1641             if ( t2.getNumberOfExternalNodes() != 2 ) {
1642                 return false;
1643             }
1644             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1645                 return false;
1646             }
1647             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1648                 return false;
1649             }
1650             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1651                 return false;
1652             }
1653             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1654                 return false;
1655             }
1656             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1657                 return false;
1658             }
1659             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1660                 return false;
1661             }
1662             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1663                     .startsWith( "actgtgggggt" ) ) {
1664                 return false;
1665             }
1666             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1667                     .startsWith( "ctgtgatgcat" ) ) {
1668                 return false;
1669             }
1670             if ( t3.getNumberOfExternalNodes() != 4 ) {
1671                 return false;
1672             }
1673             if ( !t1.getName().equals( "t1" ) ) {
1674                 return false;
1675             }
1676             if ( !t2.getName().equals( "t2" ) ) {
1677                 return false;
1678             }
1679             if ( !t3.getName().equals( "t3" ) ) {
1680                 return false;
1681             }
1682             if ( !t4.getName().equals( "t4" ) ) {
1683                 return false;
1684             }
1685             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1686                 return false;
1687             }
1688             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1689                 return false;
1690             }
1691             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1692                 return false;
1693             }
1694             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1695                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1696                 return false;
1697             }
1698             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1699                 return false;
1700             }
1701             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1702                 return false;
1703             }
1704             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1705                 return false;
1706             }
1707             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1708                     .equals( "apoptosis" ) ) {
1709                 return false;
1710             }
1711             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1712                     .equals( "GO:0006915" ) ) {
1713                 return false;
1714             }
1715             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1716                     .equals( "UniProtKB" ) ) {
1717                 return false;
1718             }
1719             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1720                     .equals( "experimental" ) ) {
1721                 return false;
1722             }
1723             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1724                     .equals( "function" ) ) {
1725                 return false;
1726             }
1727             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1728                     .getValue() != 1 ) {
1729                 return false;
1730             }
1731             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1732                     .getType().equals( "ml" ) ) {
1733                 return false;
1734             }
1735             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1736                     .equals( "apoptosis" ) ) {
1737                 return false;
1738             }
1739             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1740                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1741                 return false;
1742             }
1743             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1744                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1745                 return false;
1746             }
1747             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1748                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1749                 return false;
1750             }
1751             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1752                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1753                 return false;
1754             }
1755             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1756                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1757                 return false;
1758             }
1759             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1760                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1761                 return false;
1762             }
1763             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1764                     .equals( "GO:0005829" ) ) {
1765                 return false;
1766             }
1767             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1768                     .equals( "intracellular organelle" ) ) {
1769                 return false;
1770             }
1771             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1772                 return false;
1773             }
1774             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1775                     .equals( "UniProt link" ) ) ) {
1776                 return false;
1777             }
1778             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1779                 return false;
1780             }
1781             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1782             if ( x.size() != 4 ) {
1783                 return false;
1784             }
1785             int c = 0;
1786             for( final Accession acc : x ) {
1787                 if ( c == 0 ) {
1788                     if ( !acc.getSource().equals( "KEGG" ) ) {
1789                         return false;
1790                     }
1791                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1792                         return false;
1793                     }
1794                 }
1795                 c++;
1796             }
1797         }
1798         catch ( final Exception e ) {
1799             e.printStackTrace( System.out );
1800             return false;
1801         }
1802         return true;
1803     }
1804
1805     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1806         try {
1807             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1808             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1809             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1810                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1811             }
1812             else {
1813                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1814             }
1815             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1816                                                               xml_parser );
1817             if ( xml_parser.getErrorCount() > 0 ) {
1818                 System.out.println( xml_parser.getErrorMessages().toString() );
1819                 return false;
1820             }
1821             if ( phylogenies_0.length != 4 ) {
1822                 return false;
1823             }
1824             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1825             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1826             if ( phylogenies_t1.length != 1 ) {
1827                 return false;
1828             }
1829             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1830             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1831                 return false;
1832             }
1833             if ( !t1_rt.isRooted() ) {
1834                 return false;
1835             }
1836             if ( t1_rt.isRerootable() ) {
1837                 return false;
1838             }
1839             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1840                 return false;
1841             }
1842             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1843             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1844             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1845             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1846                 return false;
1847             }
1848             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1849                 return false;
1850             }
1851             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1852                 return false;
1853             }
1854             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1855                 return false;
1856             }
1857             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1858                     .startsWith( "actgtgggggt" ) ) {
1859                 return false;
1860             }
1861             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1862                     .startsWith( "ctgtgatgcat" ) ) {
1863                 return false;
1864             }
1865             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1866             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1867             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1868             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1869             if ( phylogenies_1.length != 1 ) {
1870                 return false;
1871             }
1872             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1873             if ( !t3_rt.getName().equals( "t3" ) ) {
1874                 return false;
1875             }
1876             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1877                 return false;
1878             }
1879             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1880                 return false;
1881             }
1882             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1883                 return false;
1884             }
1885             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1886                 return false;
1887             }
1888             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1889                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1890                 return false;
1891             }
1892             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1893                 return false;
1894             }
1895             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1896                 return false;
1897             }
1898             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1899                     .equals( "UniProtKB" ) ) {
1900                 return false;
1901             }
1902             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1903                     .equals( "apoptosis" ) ) {
1904                 return false;
1905             }
1906             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1907                     .equals( "GO:0006915" ) ) {
1908                 return false;
1909             }
1910             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1911                     .equals( "UniProtKB" ) ) {
1912                 return false;
1913             }
1914             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1915                     .equals( "experimental" ) ) {
1916                 return false;
1917             }
1918             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1919                     .equals( "function" ) ) {
1920                 return false;
1921             }
1922             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1923                     .getValue() != 1 ) {
1924                 return false;
1925             }
1926             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1927                     .getType().equals( "ml" ) ) {
1928                 return false;
1929             }
1930             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1931                     .equals( "apoptosis" ) ) {
1932                 return false;
1933             }
1934             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1935                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1936                 return false;
1937             }
1938             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1939                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1940                 return false;
1941             }
1942             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1943                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1944                 return false;
1945             }
1946             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1947                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1948                 return false;
1949             }
1950             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1951                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1952                 return false;
1953             }
1954             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1955                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1956                 return false;
1957             }
1958             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1959                     .equals( "GO:0005829" ) ) {
1960                 return false;
1961             }
1962             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1963                     .equals( "intracellular organelle" ) ) {
1964                 return false;
1965             }
1966             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1967                 return false;
1968             }
1969             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1970                     .equals( "UniProt link" ) ) ) {
1971                 return false;
1972             }
1973             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1974                 return false;
1975             }
1976             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1977                 return false;
1978             }
1979             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1980                     .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." ) ) ) {
1981                 return false;
1982             }
1983             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1984                 return false;
1985             }
1986             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1987                 return false;
1988             }
1989             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1990                 return false;
1991             }
1992             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1993                 return false;
1994             }
1995             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1996                     .equals( "ncbi" ) ) {
1997                 return false;
1998             }
1999             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
2000                 return false;
2001             }
2002             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2003                     .getName().equals( "B" ) ) {
2004                 return false;
2005             }
2006             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2007                     .getFrom() != 21 ) {
2008                 return false;
2009             }
2010             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
2011                 return false;
2012             }
2013             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2014                     .getLength() != 24 ) {
2015                 return false;
2016             }
2017             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2018                     .getConfidence() != 2144 ) {
2019                 return false;
2020             }
2021             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2022                     .equals( "pfam" ) ) {
2023                 return false;
2024             }
2025             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2026                 return false;
2027             }
2028             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2029                 return false;
2030             }
2031             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2032                 return false;
2033             }
2034             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2035                 return false;
2036             }
2037             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2038             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2039                 return false;
2040             }
2041             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2042                 return false;
2043             }
2044             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2045                 return false;
2046             }
2047             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2048                 return false;
2049             }
2050             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2051                 return false;
2052             }
2053             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2054                 return false;
2055             }
2056             if ( taxbb.getSynonyms().size() != 2 ) {
2057                 return false;
2058             }
2059             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2060                 return false;
2061             }
2062             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2063                 return false;
2064             }
2065             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2066                 return false;
2067             }
2068             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2069                 return false;
2070             }
2071             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2072                 return false;
2073             }
2074             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2075                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2076                 return false;
2077             }
2078             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2079                 return false;
2080             }
2081             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2082                 return false;
2083             }
2084             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2085                 return false;
2086             }
2087             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2088                 return false;
2089             }
2090             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2091                 return false;
2092             }
2093             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2094                 return false;
2095             }
2096             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2097                 return false;
2098             }
2099             //
2100             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2101                 return false;
2102             }
2103             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2104                     .equalsIgnoreCase( "435" ) ) {
2105                 return false;
2106             }
2107             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
2108                 return false;
2109             }
2110             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2111                     .equalsIgnoreCase( "443.7" ) ) {
2112                 return false;
2113             }
2114             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2115                 return false;
2116             }
2117             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2118                 return false;
2119             }
2120             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2121                     .equalsIgnoreCase( "433" ) ) {
2122                 return false;
2123             }
2124             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2125                     .getCrossReferences();
2126             if ( x.size() != 4 ) {
2127                 return false;
2128             }
2129             int c = 0;
2130             for( final Accession acc : x ) {
2131                 if ( c == 0 ) {
2132                     if ( !acc.getSource().equals( "KEGG" ) ) {
2133                         return false;
2134                     }
2135                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2136                         return false;
2137                     }
2138                 }
2139                 c++;
2140             }
2141         }
2142         catch ( final Exception e ) {
2143             e.printStackTrace( System.out );
2144             return false;
2145         }
2146         return true;
2147     }
2148
2149     private static boolean testBasicPhyloXMLparsingValidating() {
2150         try {
2151             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2152             PhyloXmlParser xml_parser = null;
2153             try {
2154                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2155             }
2156             catch ( final Exception e ) {
2157                 // Do nothing -- means were not running from jar.
2158             }
2159             if ( xml_parser == null ) {
2160                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2161                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2162                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2163                 }
2164                 else {
2165                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2166                 }
2167             }
2168             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
2169                                                               xml_parser );
2170             if ( xml_parser.getErrorCount() > 0 ) {
2171                 System.out.println( xml_parser.getErrorMessages().toString() );
2172                 return false;
2173             }
2174             if ( phylogenies_0.length != 4 ) {
2175                 return false;
2176             }
2177             final Phylogeny t1 = phylogenies_0[ 0 ];
2178             final Phylogeny t2 = phylogenies_0[ 1 ];
2179             final Phylogeny t3 = phylogenies_0[ 2 ];
2180             final Phylogeny t4 = phylogenies_0[ 3 ];
2181             if ( !t1.getName().equals( "t1" ) ) {
2182                 return false;
2183             }
2184             if ( !t2.getName().equals( "t2" ) ) {
2185                 return false;
2186             }
2187             if ( !t3.getName().equals( "t3" ) ) {
2188                 return false;
2189             }
2190             if ( !t4.getName().equals( "t4" ) ) {
2191                 return false;
2192             }
2193             if ( t1.getNumberOfExternalNodes() != 1 ) {
2194                 return false;
2195             }
2196             if ( t2.getNumberOfExternalNodes() != 2 ) {
2197                 return false;
2198             }
2199             if ( t3.getNumberOfExternalNodes() != 4 ) {
2200                 return false;
2201             }
2202             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2203             final Phylogeny[] phylogenies_1 = factory.create( x2, 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_1.length != 4 ) {
2210                 return false;
2211             }
2212             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
2213                                                               xml_parser );
2214             if ( xml_parser.getErrorCount() > 0 ) {
2215                 System.out.println( "errors:" );
2216                 System.out.println( xml_parser.getErrorMessages().toString() );
2217                 return false;
2218             }
2219             if ( phylogenies_2.length != 1 ) {
2220                 return false;
2221             }
2222             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2223                 return false;
2224             }
2225             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
2226                                                               xml_parser );
2227             if ( xml_parser.getErrorCount() > 0 ) {
2228                 System.out.println( xml_parser.getErrorMessages().toString() );
2229                 return false;
2230             }
2231             if ( phylogenies_3.length != 2 ) {
2232                 return false;
2233             }
2234             final Phylogeny a = phylogenies_3[ 0 ];
2235             if ( !a.getName().equals( "tree 4" ) ) {
2236                 return false;
2237             }
2238             if ( a.getNumberOfExternalNodes() != 3 ) {
2239                 return false;
2240             }
2241             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2242                 return false;
2243             }
2244             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2245                 return false;
2246             }
2247             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
2248                                                               xml_parser );
2249             if ( xml_parser.getErrorCount() > 0 ) {
2250                 System.out.println( xml_parser.getErrorMessages().toString() );
2251                 return false;
2252             }
2253             if ( phylogenies_4.length != 1 ) {
2254                 return false;
2255             }
2256             final Phylogeny s = phylogenies_4[ 0 ];
2257             if ( s.getNumberOfExternalNodes() != 6 ) {
2258                 return false;
2259             }
2260             s.getNode( "first" );
2261             s.getNode( "<>" );
2262             s.getNode( "\"<a'b&c'd\">\"" );
2263             s.getNode( "'''\"" );
2264             s.getNode( "\"\"\"" );
2265             s.getNode( "dick & doof" );
2266         }
2267         catch ( final Exception e ) {
2268             e.printStackTrace( System.out );
2269             return false;
2270         }
2271         return true;
2272     }
2273
2274     private static boolean testBasicProtein() {
2275         try {
2276             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2277             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2278             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2279             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2280             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2281             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2282             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2283             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2284             p0.addProteinDomain( y );
2285             p0.addProteinDomain( e );
2286             p0.addProteinDomain( b );
2287             p0.addProteinDomain( c );
2288             p0.addProteinDomain( d );
2289             p0.addProteinDomain( a );
2290             p0.addProteinDomain( x );
2291             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2292                 return false;
2293             }
2294             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2295                 return false;
2296             }
2297             //
2298             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2299             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2300             aa0.addProteinDomain( a1 );
2301             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2302                 return false;
2303             }
2304             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2305                 return false;
2306             }
2307             //
2308             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2309             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2310             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2311             aa1.addProteinDomain( a11 );
2312             aa1.addProteinDomain( a12 );
2313             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2314                 return false;
2315             }
2316             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2317                 return false;
2318             }
2319             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2320             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2321                 return false;
2322             }
2323             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2324                 return false;
2325             }
2326             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2327                 return false;
2328             }
2329             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2330             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2331                 return false;
2332             }
2333             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2334                 return false;
2335             }
2336             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2337                 return false;
2338             }
2339             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2340                 return false;
2341             }
2342             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2343             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2344                 return false;
2345             }
2346             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2347                 return false;
2348             }
2349             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2350                 return false;
2351             }
2352             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2353                 return false;
2354             }
2355             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2356             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2357                 return false;
2358             }
2359             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2360                 return false;
2361             }
2362             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2363                 return false;
2364             }
2365             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2366                 return false;
2367             }
2368             //
2369             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2370             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2371             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2372             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2373             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2374             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2375             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2376             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2377             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2378             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2379             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2380             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2381             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2382             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2383             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2384             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2385             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2386             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2387             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2388             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2389             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2390             p00.addProteinDomain( y0 );
2391             p00.addProteinDomain( e0 );
2392             p00.addProteinDomain( b0 );
2393             p00.addProteinDomain( c0 );
2394             p00.addProteinDomain( d0 );
2395             p00.addProteinDomain( a0 );
2396             p00.addProteinDomain( x0 );
2397             p00.addProteinDomain( y1 );
2398             p00.addProteinDomain( y2 );
2399             p00.addProteinDomain( y3 );
2400             p00.addProteinDomain( e1 );
2401             p00.addProteinDomain( e2 );
2402             p00.addProteinDomain( e3 );
2403             p00.addProteinDomain( e4 );
2404             p00.addProteinDomain( e5 );
2405             p00.addProteinDomain( z0 );
2406             p00.addProteinDomain( z1 );
2407             p00.addProteinDomain( z2 );
2408             p00.addProteinDomain( zz0 );
2409             p00.addProteinDomain( zz1 );
2410             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2411                 return false;
2412             }
2413             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2414                 return false;
2415             }
2416             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2417                 return false;
2418             }
2419             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2420                 return false;
2421             }
2422             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" ) ) {
2423                 return false;
2424             }
2425             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2426             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2427             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2428             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2429             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2430             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2431             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2432             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2433             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2434             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2435             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2436             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2437             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2438             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2439             p.addProteinDomain( B15 );
2440             p.addProteinDomain( C50 );
2441             p.addProteinDomain( A60 );
2442             p.addProteinDomain( A30 );
2443             p.addProteinDomain( C70 );
2444             p.addProteinDomain( B35 );
2445             p.addProteinDomain( B40 );
2446             p.addProteinDomain( A0 );
2447             p.addProteinDomain( A10 );
2448             p.addProteinDomain( A20 );
2449             p.addProteinDomain( B25 );
2450             p.addProteinDomain( D80 );
2451             List<String> domains_ids = new ArrayList<String>();
2452             domains_ids.add( "A" );
2453             domains_ids.add( "B" );
2454             domains_ids.add( "C" );
2455             if ( !p.contains( domains_ids, false ) ) {
2456                 return false;
2457             }
2458             if ( !p.contains( domains_ids, true ) ) {
2459                 return false;
2460             }
2461             domains_ids.add( "X" );
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( "C" );
2471             domains_ids.add( "D" );
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( "D" );
2481             domains_ids.add( "C" );
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( "B" );
2492             if ( !p.contains( domains_ids, false ) ) {
2493                 return false;
2494             }
2495             if ( !p.contains( domains_ids, true ) ) {
2496                 return false;
2497             }
2498             domains_ids = new ArrayList<String>();
2499             domains_ids.add( "A" );
2500             domains_ids.add( "A" );
2501             domains_ids.add( "A" );
2502             domains_ids.add( "B" );
2503             domains_ids.add( "B" );
2504             if ( !p.contains( domains_ids, false ) ) {
2505                 return false;
2506             }
2507             if ( !p.contains( domains_ids, true ) ) {
2508                 return false;
2509             }
2510             domains_ids = new ArrayList<String>();
2511             domains_ids.add( "A" );
2512             domains_ids.add( "A" );
2513             domains_ids.add( "B" );
2514             domains_ids.add( "A" );
2515             domains_ids.add( "B" );
2516             domains_ids.add( "B" );
2517             domains_ids.add( "A" );
2518             domains_ids.add( "B" );
2519             domains_ids.add( "C" );
2520             domains_ids.add( "A" );
2521             domains_ids.add( "C" );
2522             domains_ids.add( "D" );
2523             if ( !p.contains( domains_ids, false ) ) {
2524                 return false;
2525             }
2526             if ( p.contains( domains_ids, true ) ) {
2527                 return false;
2528             }
2529         }
2530         catch ( final Exception e ) {
2531             e.printStackTrace( System.out );
2532             return false;
2533         }
2534         return true;
2535     }
2536
2537     private static boolean testBasicTable() {
2538         try {
2539             final BasicTable<String> t0 = new BasicTable<String>();
2540             if ( t0.getNumberOfColumns() != 0 ) {
2541                 return false;
2542             }
2543             if ( t0.getNumberOfRows() != 0 ) {
2544                 return false;
2545             }
2546             t0.setValue( 3, 2, "23" );
2547             t0.setValue( 10, 1, "error" );
2548             t0.setValue( 10, 1, "110" );
2549             t0.setValue( 9, 1, "19" );
2550             t0.setValue( 1, 10, "101" );
2551             t0.setValue( 10, 10, "1010" );
2552             t0.setValue( 100, 10, "10100" );
2553             t0.setValue( 0, 0, "00" );
2554             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2555                 return false;
2556             }
2557             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2558                 return false;
2559             }
2560             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2561                 return false;
2562             }
2563             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2564                 return false;
2565             }
2566             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2567                 return false;
2568             }
2569             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2570                 return false;
2571             }
2572             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2573                 return false;
2574             }
2575             if ( t0.getNumberOfColumns() != 101 ) {
2576                 return false;
2577             }
2578             if ( t0.getNumberOfRows() != 11 ) {
2579                 return false;
2580             }
2581             if ( t0.getValueAsString( 49, 4 ) != null ) {
2582                 return false;
2583             }
2584             final String l = ForesterUtil.getLineSeparator();
2585             final StringBuffer source = new StringBuffer();
2586             source.append( "" + l );
2587             source.append( "# 1 1 1 1 1 1 1 1" + l );
2588             source.append( " 00 01 02 03" + l );
2589             source.append( "   10 11 12 13  " + l );
2590             source.append( "20 21 22 23 " + l );
2591             source.append( "    30  31    32 33" + l );
2592             source.append( "40 41 42 43" + l );
2593             source.append( "  # 1 1 1 1 1 " + l );
2594             source.append( "50 51 52 53 54" + l );
2595             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2596             if ( t1.getNumberOfColumns() != 5 ) {
2597                 return false;
2598             }
2599             if ( t1.getNumberOfRows() != 6 ) {
2600                 return false;
2601             }
2602             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2603                 return false;
2604             }
2605             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2606                 return false;
2607             }
2608             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2609                 return false;
2610             }
2611             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2612                 return false;
2613             }
2614             final StringBuffer source1 = new StringBuffer();
2615             source1.append( "" + l );
2616             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2617             source1.append( " 00; 01 ;02;03" + l );
2618             source1.append( "   10; 11; 12; 13  " + l );
2619             source1.append( "20; 21; 22; 23 " + l );
2620             source1.append( "    30;  31;    32; 33" + l );
2621             source1.append( "40;41;42;43" + l );
2622             source1.append( "  # 1 1 1 1 1 " + l );
2623             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2624             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2625             if ( t2.getNumberOfColumns() != 5 ) {
2626                 return false;
2627             }
2628             if ( t2.getNumberOfRows() != 6 ) {
2629                 return false;
2630             }
2631             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2632                 return false;
2633             }
2634             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2635                 return false;
2636             }
2637             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2638                 return false;
2639             }
2640             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2641                 return false;
2642             }
2643             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2644                 return false;
2645             }
2646             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2647                 return false;
2648             }
2649             final StringBuffer source2 = new StringBuffer();
2650             source2.append( "" + l );
2651             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2652             source2.append( " 00; 01 ;02;03" + l );
2653             source2.append( "   10; 11; 12; 13  " + l );
2654             source2.append( "20; 21; 22; 23 " + l );
2655             source2.append( "                     " + l );
2656             source2.append( "    30;  31;    32; 33" + l );
2657             source2.append( "40;41;42;43" + l );
2658             source2.append( "  comment: 1 1 1 1 1 " + l );
2659             source2.append( ";;;50  ;   52; 53;;54   " + l );
2660             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2661                                                                         ';',
2662                                                                         false,
2663                                                                         false,
2664                                                                         "comment:",
2665                                                                         false );
2666             if ( tl.size() != 2 ) {
2667                 return false;
2668             }
2669             final BasicTable<String> t3 = tl.get( 0 );
2670             final BasicTable<String> t4 = tl.get( 1 );
2671             if ( t3.getNumberOfColumns() != 4 ) {
2672                 return false;
2673             }
2674             if ( t3.getNumberOfRows() != 3 ) {
2675                 return false;
2676             }
2677             if ( t4.getNumberOfColumns() != 4 ) {
2678                 return false;
2679             }
2680             if ( t4.getNumberOfRows() != 3 ) {
2681                 return false;
2682             }
2683             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2684                 return false;
2685             }
2686             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2687                 return false;
2688             }
2689         }
2690         catch ( final Exception e ) {
2691             e.printStackTrace( System.out );
2692             return false;
2693         }
2694         return true;
2695     }
2696
2697     private static boolean testBasicTolXMLparsing() {
2698         try {
2699             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2700             final TolParser parser = new TolParser();
2701             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2702             if ( parser.getErrorCount() > 0 ) {
2703                 System.out.println( parser.getErrorMessages().toString() );
2704                 return false;
2705             }
2706             if ( phylogenies_0.length != 1 ) {
2707                 return false;
2708             }
2709             final Phylogeny t1 = phylogenies_0[ 0 ];
2710             if ( t1.getNumberOfExternalNodes() != 5 ) {
2711                 return false;
2712             }
2713             if ( !t1.isRooted() ) {
2714                 return false;
2715             }
2716             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2717                 return false;
2718             }
2719             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2720                 return false;
2721             }
2722             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2723                 return false;
2724             }
2725             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2726                 return false;
2727             }
2728             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2729             if ( parser.getErrorCount() > 0 ) {
2730                 System.out.println( parser.getErrorMessages().toString() );
2731                 return false;
2732             }
2733             if ( phylogenies_1.length != 1 ) {
2734                 return false;
2735             }
2736             final Phylogeny t2 = phylogenies_1[ 0 ];
2737             if ( t2.getNumberOfExternalNodes() != 664 ) {
2738                 return false;
2739             }
2740             if ( !t2.isRooted() ) {
2741                 return false;
2742             }
2743             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2744                 return false;
2745             }
2746             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2747                 return false;
2748             }
2749             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2750                 return false;
2751             }
2752             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2753                 return false;
2754             }
2755             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2756                 return false;
2757             }
2758             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2759                     .equals( "Aquifex" ) ) {
2760                 return false;
2761             }
2762             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2763             if ( parser.getErrorCount() > 0 ) {
2764                 System.out.println( parser.getErrorMessages().toString() );
2765                 return false;
2766             }
2767             if ( phylogenies_2.length != 1 ) {
2768                 return false;
2769             }
2770             final Phylogeny t3 = phylogenies_2[ 0 ];
2771             if ( t3.getNumberOfExternalNodes() != 184 ) {
2772                 return false;
2773             }
2774             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2775                 return false;
2776             }
2777             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2778                 return false;
2779             }
2780             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2781                 return false;
2782             }
2783             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2784             if ( parser.getErrorCount() > 0 ) {
2785                 System.out.println( parser.getErrorMessages().toString() );
2786                 return false;
2787             }
2788             if ( phylogenies_3.length != 1 ) {
2789                 return false;
2790             }
2791             final Phylogeny t4 = phylogenies_3[ 0 ];
2792             if ( t4.getNumberOfExternalNodes() != 1 ) {
2793                 return false;
2794             }
2795             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2796                 return false;
2797             }
2798             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2799                 return false;
2800             }
2801             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2802                 return false;
2803             }
2804             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2805             if ( parser.getErrorCount() > 0 ) {
2806                 System.out.println( parser.getErrorMessages().toString() );
2807                 return false;
2808             }
2809             if ( phylogenies_4.length != 1 ) {
2810                 return false;
2811             }
2812             final Phylogeny t5 = phylogenies_4[ 0 ];
2813             if ( t5.getNumberOfExternalNodes() != 13 ) {
2814                 return false;
2815             }
2816             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2817                 return false;
2818             }
2819             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2820                 return false;
2821             }
2822             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2823                 return false;
2824             }
2825         }
2826         catch ( final Exception e ) {
2827             e.printStackTrace( System.out );
2828             return false;
2829         }
2830         return true;
2831     }
2832
2833     private static boolean testBasicTreeMethods() {
2834         try {
2835             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2836             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2837             if ( t2.getNumberOfExternalNodes() != 4 ) {
2838                 return false;
2839             }
2840             if ( t2.getHeight() != 8.5 ) {
2841                 return false;
2842             }
2843             if ( !t2.isCompletelyBinary() ) {
2844                 return false;
2845             }
2846             if ( t2.isEmpty() ) {
2847                 return false;
2848             }
2849             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2850             if ( t3.getNumberOfExternalNodes() != 5 ) {
2851                 return false;
2852             }
2853             if ( t3.getHeight() != 11 ) {
2854                 return false;
2855             }
2856             if ( t3.isCompletelyBinary() ) {
2857                 return false;
2858             }
2859             final PhylogenyNode n = t3.getNode( "ABC" );
2860             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 ];
2861             if ( t4.getNumberOfExternalNodes() != 9 ) {
2862                 return false;
2863             }
2864             if ( t4.getHeight() != 11 ) {
2865                 return false;
2866             }
2867             if ( t4.isCompletelyBinary() ) {
2868                 return false;
2869             }
2870             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)" );
2871             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2872             if ( t5.getNumberOfExternalNodes() != 8 ) {
2873                 return false;
2874             }
2875             if ( t5.getHeight() != 15 ) {
2876                 return false;
2877             }
2878             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)" );
2879             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2880             if ( t6.getHeight() != 15 ) {
2881                 return false;
2882             }
2883             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)" );
2884             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2885             if ( t7.getHeight() != 15 ) {
2886                 return false;
2887             }
2888             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)" );
2889             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2890             if ( t8.getNumberOfExternalNodes() != 10 ) {
2891                 return false;
2892             }
2893             if ( t8.getHeight() != 15 ) {
2894                 return false;
2895             }
2896             final char[] a9 = new char[] { 'a' };
2897             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2898             if ( t9.getHeight() != 0 ) {
2899                 return false;
2900             }
2901             final char[] a10 = new char[] { 'a', ':', '6' };
2902             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2903             if ( t10.getHeight() != 6 ) {
2904                 return false;
2905             }
2906         }
2907         catch ( final Exception e ) {
2908             e.printStackTrace( System.out );
2909             return false;
2910         }
2911         return true;
2912     }
2913
2914     private static boolean testConfidenceAssessor() {
2915         try {
2916             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2917             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2918             final Phylogeny[] ev0 = factory
2919                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2920                              new NHXParser() );
2921             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2922             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2923                 return false;
2924             }
2925             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2926                 return false;
2927             }
2928             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2929             final Phylogeny[] ev1 = factory
2930                     .create( "((((A,B),C),D),E);((A,B),((E,D),C));(((A,B),C),(E,D));(A,(((E,D),C),B));(B,(A,((E,D),C)));(C,((E,D),(A,B)));(D,(E,((A,B),C)));",
2931                              new NHXParser() );
2932             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2933             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2934                 return false;
2935             }
2936             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2937                 return false;
2938             }
2939             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2940             final Phylogeny[] ev_b = factory
2941                     .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",
2942                              new NHXParser() );
2943             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2944             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2945                 return false;
2946             }
2947             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2948                 return false;
2949             }
2950             //
2951             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2952             final Phylogeny[] ev1x = factory
2953                     .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)));",
2954                              new NHXParser() );
2955             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2956             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2957                 return false;
2958             }
2959             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2960                 return false;
2961             }
2962             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2963             final Phylogeny[] ev_bx = factory
2964                     .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",
2965                              new NHXParser() );
2966             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2967             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2968                 return false;
2969             }
2970             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2971                 return false;
2972             }
2973             //
2974             final Phylogeny[] t2 = factory
2975                     .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);",
2976                              new NHXParser() );
2977             final Phylogeny[] ev2 = factory
2978                     .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);",
2979                              new NHXParser() );
2980             for( final Phylogeny target : t2 ) {
2981                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2982             }
2983             //
2984             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2985                                                  new NHXParser() )[ 0 ];
2986             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2987             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2988             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2989                 return false;
2990             }
2991             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2992                 return false;
2993             }
2994             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2995                 return false;
2996             }
2997         }
2998         catch ( final Exception e ) {
2999             e.printStackTrace();
3000             return false;
3001         }
3002         return true;
3003     }
3004
3005     private static boolean testCopyOfNodeData() {
3006         try {
3007             final PhylogenyNode n1 = PhylogenyNode
3008                     .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]" );
3009             final PhylogenyNode n2 = n1.copyNodeData();
3010             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
3011                 return false;
3012             }
3013         }
3014         catch ( final Exception e ) {
3015             e.printStackTrace();
3016             return false;
3017         }
3018         return true;
3019     }
3020
3021     private static boolean testCreateBalancedPhylogeny() {
3022         try {
3023             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3024             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3025                 return false;
3026             }
3027             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3028                 return false;
3029             }
3030             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3031             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3032                 return false;
3033             }
3034             if ( p1.getNumberOfExternalNodes() != 100 ) {
3035                 return false;
3036             }
3037         }
3038         catch ( final Exception e ) {
3039             e.printStackTrace();
3040             return false;
3041         }
3042         return true;
3043     }
3044
3045     private static boolean testCreateUriForSeqWeb() {
3046         try {
3047             final PhylogenyNode n = new PhylogenyNode();
3048             n.setName( "tr|B3RJ64" );
3049             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3050                 return false;
3051             }
3052             n.setName( "B0LM41_HUMAN" );
3053             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3054                 return false;
3055             }
3056             n.setName( "NP_001025424" );
3057             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3058                 return false;
3059             }
3060             n.setName( "_NM_001030253-" );
3061             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3062                 return false;
3063             }
3064             n.setName( "XM_002122186" );
3065             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3066                 return false;
3067             }
3068             n.setName( "dgh_AAA34956_gdg" );
3069             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3070                 return false;
3071             }
3072             n.setName( "AAA34956" );
3073             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3074                 return false;
3075             }
3076             n.setName( "GI:394892" );
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( "gi_394892" );
3082             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3083                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3084                 return false;
3085             }
3086             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3087             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3088                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3089                 return false;
3090             }
3091             n.setName( "P12345" );
3092             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3093                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3094                 return false;
3095             }
3096             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3097             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3098                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3099                 return false;
3100             }
3101         }
3102         catch ( final Exception e ) {
3103             e.printStackTrace( System.out );
3104             return false;
3105         }
3106         return true;
3107     }
3108
3109     private static boolean testDataObjects() {
3110         try {
3111             final Confidence s0 = new Confidence();
3112             final Confidence s1 = new Confidence();
3113             if ( !s0.isEqual( s1 ) ) {
3114                 return false;
3115             }
3116             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3117             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3118             if ( s2.isEqual( s1 ) ) {
3119                 return false;
3120             }
3121             if ( !s2.isEqual( s3 ) ) {
3122                 return false;
3123             }
3124             final Confidence s4 = ( Confidence ) s3.copy();
3125             if ( !s4.isEqual( s3 ) ) {
3126                 return false;
3127             }
3128             s3.asSimpleText();
3129             s3.asText();
3130             // Taxonomy
3131             // ----------
3132             final Taxonomy t1 = new Taxonomy();
3133             final Taxonomy t2 = new Taxonomy();
3134             final Taxonomy t3 = new Taxonomy();
3135             final Taxonomy t4 = new Taxonomy();
3136             final Taxonomy t5 = new Taxonomy();
3137             t1.setIdentifier( new Identifier( "ecoli" ) );
3138             t1.setTaxonomyCode( "ECOLI" );
3139             t1.setScientificName( "E. coli" );
3140             t1.setCommonName( "coli" );
3141             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3142             if ( !t1.isEqual( t0 ) ) {
3143                 return false;
3144             }
3145             t2.setIdentifier( new Identifier( "ecoli" ) );
3146             t2.setTaxonomyCode( "OTHER" );
3147             t2.setScientificName( "what" );
3148             t2.setCommonName( "something" );
3149             if ( !t1.isEqual( t2 ) ) {
3150                 return false;
3151             }
3152             t2.setIdentifier( new Identifier( "nemve" ) );
3153             if ( t1.isEqual( t2 ) ) {
3154                 return false;
3155             }
3156             t1.setIdentifier( null );
3157             t3.setTaxonomyCode( "ECOLI" );
3158             t3.setScientificName( "what" );
3159             t3.setCommonName( "something" );
3160             if ( !t1.isEqual( t3 ) ) {
3161                 return false;
3162             }
3163             t1.setIdentifier( null );
3164             t1.setTaxonomyCode( "" );
3165             t4.setScientificName( "E. ColI" );
3166             t4.setCommonName( "something" );
3167             if ( !t1.isEqual( t4 ) ) {
3168                 return false;
3169             }
3170             t4.setScientificName( "B. subtilis" );
3171             t4.setCommonName( "something" );
3172             if ( t1.isEqual( t4 ) ) {
3173                 return false;
3174             }
3175             t1.setIdentifier( null );
3176             t1.setTaxonomyCode( "" );
3177             t1.setScientificName( "" );
3178             t5.setCommonName( "COLI" );
3179             if ( !t1.isEqual( t5 ) ) {
3180                 return false;
3181             }
3182             t5.setCommonName( "vibrio" );
3183             if ( t1.isEqual( t5 ) ) {
3184                 return false;
3185             }
3186             // Identifier
3187             // ----------
3188             final Identifier id0 = new Identifier( "123", "pfam" );
3189             final Identifier id1 = ( Identifier ) id0.copy();
3190             if ( !id1.isEqual( id1 ) ) {
3191                 return false;
3192             }
3193             if ( !id1.isEqual( id0 ) ) {
3194                 return false;
3195             }
3196             if ( !id0.isEqual( id1 ) ) {
3197                 return false;
3198             }
3199             id1.asSimpleText();
3200             id1.asText();
3201             // ProteinDomain
3202             // ---------------
3203             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3204             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3205             if ( !pd1.isEqual( pd1 ) ) {
3206                 return false;
3207             }
3208             if ( !pd1.isEqual( pd0 ) ) {
3209                 return false;
3210             }
3211             pd1.asSimpleText();
3212             pd1.asText();
3213             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3214             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3215             if ( !pd3.isEqual( pd3 ) ) {
3216                 return false;
3217             }
3218             if ( !pd2.isEqual( pd3 ) ) {
3219                 return false;
3220             }
3221             if ( !pd0.isEqual( pd3 ) ) {
3222                 return false;
3223             }
3224             pd3.asSimpleText();
3225             pd3.asText();
3226             // DomainArchitecture
3227             // ------------------
3228             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3229             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3230             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3231             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3232             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3233             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3234             domains0.add( d2 );
3235             domains0.add( d0 );
3236             domains0.add( d3 );
3237             domains0.add( d1 );
3238             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3239             if ( ds0.getNumberOfDomains() != 4 ) {
3240                 return false;
3241             }
3242             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3243             if ( !ds0.isEqual( ds0 ) ) {
3244                 return false;
3245             }
3246             if ( !ds0.isEqual( ds1 ) ) {
3247                 return false;
3248             }
3249             if ( ds1.getNumberOfDomains() != 4 ) {
3250                 return false;
3251             }
3252             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3253             domains1.add( d1 );
3254             domains1.add( d2 );
3255             domains1.add( d4 );
3256             domains1.add( d0 );
3257             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3258             if ( ds0.isEqual( ds2 ) ) {
3259                 return false;
3260             }
3261             ds1.asSimpleText();
3262             ds1.asText();
3263             ds1.toNHX();
3264             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3265             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3266                 System.out.println( ds3.toNHX() );
3267                 return false;
3268             }
3269             if ( ds3.getNumberOfDomains() != 3 ) {
3270                 return false;
3271             }
3272             // Event
3273             // -----
3274             final Event e1 = new Event( Event.EventType.fusion );
3275             if ( e1.isDuplication() ) {
3276                 return false;
3277             }
3278             if ( !e1.isFusion() ) {
3279                 return false;
3280             }
3281             if ( !e1.asText().toString().equals( "fusion" ) ) {
3282                 return false;
3283             }
3284             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3285                 return false;
3286             }
3287             final Event e11 = new Event( Event.EventType.fusion );
3288             if ( !e11.isEqual( e1 ) ) {
3289                 return false;
3290             }
3291             if ( !e11.toNHX().toString().equals( "" ) ) {
3292                 return false;
3293             }
3294             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3295             if ( e2.isDuplication() ) {
3296                 return false;
3297             }
3298             if ( !e2.isSpeciationOrDuplication() ) {
3299                 return false;
3300             }
3301             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3302                 return false;
3303             }
3304             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3305                 return false;
3306             }
3307             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3308                 return false;
3309             }
3310             if ( e11.isEqual( e2 ) ) {
3311                 return false;
3312             }
3313             final Event e2c = ( Event ) e2.copy();
3314             if ( !e2c.isEqual( e2 ) ) {
3315                 return false;
3316             }
3317             Event e3 = new Event( 1, 2, 3 );
3318             if ( e3.isDuplication() ) {
3319                 return false;
3320             }
3321             if ( e3.isSpeciation() ) {
3322                 return false;
3323             }
3324             if ( e3.isGeneLoss() ) {
3325                 return false;
3326             }
3327             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3328                 return false;
3329             }
3330             final Event e3c = ( Event ) e3.copy();
3331             final Event e3cc = ( Event ) e3c.copy();
3332             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3333                 return false;
3334             }
3335             e3 = null;
3336             if ( !e3c.isEqual( e3cc ) ) {
3337                 return false;
3338             }
3339             Event e4 = new Event( 1, 2, 3 );
3340             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3341                 return false;
3342             }
3343             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3344                 return false;
3345             }
3346             final Event e4c = ( Event ) e4.copy();
3347             e4 = null;
3348             final Event e4cc = ( Event ) e4c.copy();
3349             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3350                 return false;
3351             }
3352             if ( !e4c.isEqual( e4cc ) ) {
3353                 return false;
3354             }
3355             final Event e5 = new Event();
3356             if ( !e5.isUnassigned() ) {
3357                 return false;
3358             }
3359             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3360                 return false;
3361             }
3362             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3363                 return false;
3364             }
3365             final Event e6 = new Event( 1, 0, 0 );
3366             if ( !e6.asText().toString().equals( "duplication" ) ) {
3367                 return false;
3368             }
3369             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3370                 return false;
3371             }
3372             final Event e7 = new Event( 0, 1, 0 );
3373             if ( !e7.asText().toString().equals( "speciation" ) ) {
3374                 return false;
3375             }
3376             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3377                 return false;
3378             }
3379             final Event e8 = new Event( 0, 0, 1 );
3380             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3381                 return false;
3382             }
3383             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3384                 return false;
3385             }
3386         }
3387         catch ( final Exception e ) {
3388             e.printStackTrace( System.out );
3389             return false;
3390         }
3391         return true;
3392     }
3393
3394     private static boolean testDeletionOfExternalNodes() {
3395         try {
3396             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3397             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3398             final PhylogenyWriter w = new PhylogenyWriter();
3399             if ( t0.isEmpty() ) {
3400                 return false;
3401             }
3402             if ( t0.getNumberOfExternalNodes() != 1 ) {
3403                 return false;
3404             }
3405             t0.deleteSubtree( t0.getNode( "A" ), false );
3406             if ( t0.getNumberOfExternalNodes() != 0 ) {
3407                 return false;
3408             }
3409             if ( !t0.isEmpty() ) {
3410                 return false;
3411             }
3412             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3413             if ( t1.getNumberOfExternalNodes() != 2 ) {
3414                 return false;
3415             }
3416             t1.deleteSubtree( t1.getNode( "A" ), false );
3417             if ( t1.getNumberOfExternalNodes() != 1 ) {
3418                 return false;
3419             }
3420             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3421                 return false;
3422             }
3423             t1.deleteSubtree( t1.getNode( "B" ), false );
3424             if ( t1.getNumberOfExternalNodes() != 1 ) {
3425                 return false;
3426             }
3427             t1.deleteSubtree( t1.getNode( "r" ), false );
3428             if ( !t1.isEmpty() ) {
3429                 return false;
3430             }
3431             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3432             if ( t2.getNumberOfExternalNodes() != 3 ) {
3433                 return false;
3434             }
3435             t2.deleteSubtree( t2.getNode( "B" ), false );
3436             if ( t2.getNumberOfExternalNodes() != 2 ) {
3437                 return false;
3438             }
3439             t2.toNewHampshireX();
3440             PhylogenyNode n = t2.getNode( "A" );
3441             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3442                 return false;
3443             }
3444             t2.deleteSubtree( t2.getNode( "A" ), false );
3445             if ( t2.getNumberOfExternalNodes() != 2 ) {
3446                 return false;
3447             }
3448             t2.deleteSubtree( t2.getNode( "C" ), true );
3449             if ( t2.getNumberOfExternalNodes() != 1 ) {
3450                 return false;
3451             }
3452             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3453             if ( t3.getNumberOfExternalNodes() != 4 ) {
3454                 return false;
3455             }
3456             t3.deleteSubtree( t3.getNode( "B" ), true );
3457             if ( t3.getNumberOfExternalNodes() != 3 ) {
3458                 return false;
3459             }
3460             n = t3.getNode( "A" );
3461             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3462                 return false;
3463             }
3464             n = n.getNextExternalNode();
3465             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3466                 return false;
3467             }
3468             t3.deleteSubtree( t3.getNode( "A" ), true );
3469             if ( t3.getNumberOfExternalNodes() != 2 ) {
3470                 return false;
3471             }
3472             n = t3.getNode( "C" );
3473             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3474                 return false;
3475             }
3476             t3.deleteSubtree( t3.getNode( "C" ), true );
3477             if ( t3.getNumberOfExternalNodes() != 1 ) {
3478                 return false;
3479             }
3480             t3.deleteSubtree( t3.getNode( "D" ), true );
3481             if ( t3.getNumberOfExternalNodes() != 0 ) {
3482                 return false;
3483             }
3484             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3485             if ( t4.getNumberOfExternalNodes() != 6 ) {
3486                 return false;
3487             }
3488             t4.deleteSubtree( t4.getNode( "B2" ), true );
3489             if ( t4.getNumberOfExternalNodes() != 5 ) {
3490                 return false;
3491             }
3492             String s = w.toNewHampshire( t4, true ).toString();
3493             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3494                 return false;
3495             }
3496             t4.deleteSubtree( t4.getNode( "B11" ), true );
3497             if ( t4.getNumberOfExternalNodes() != 4 ) {
3498                 return false;
3499             }
3500             t4.deleteSubtree( t4.getNode( "C" ), true );
3501             if ( t4.getNumberOfExternalNodes() != 3 ) {
3502                 return false;
3503             }
3504             n = t4.getNode( "A" );
3505             n = n.getNextExternalNode();
3506             if ( !n.getName().equals( "B12" ) ) {
3507                 return false;
3508             }
3509             n = n.getNextExternalNode();
3510             if ( !n.getName().equals( "D" ) ) {
3511                 return false;
3512             }
3513             s = w.toNewHampshire( t4, true ).toString();
3514             if ( !s.equals( "((A,B12),D);" ) ) {
3515                 return false;
3516             }
3517             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3518             t5.deleteSubtree( t5.getNode( "A" ), true );
3519             if ( t5.getNumberOfExternalNodes() != 5 ) {
3520                 return false;
3521             }
3522             s = w.toNewHampshire( t5, true ).toString();
3523             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3524                 return false;
3525             }
3526             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3527             t6.deleteSubtree( t6.getNode( "B11" ), true );
3528             if ( t6.getNumberOfExternalNodes() != 5 ) {
3529                 return false;
3530             }
3531             s = w.toNewHampshire( t6, false ).toString();
3532             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3533                 return false;
3534             }
3535             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3536             t7.deleteSubtree( t7.getNode( "B12" ), true );
3537             if ( t7.getNumberOfExternalNodes() != 5 ) {
3538                 return false;
3539             }
3540             s = w.toNewHampshire( t7, true ).toString();
3541             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3542                 return false;
3543             }
3544             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3545             t8.deleteSubtree( t8.getNode( "B2" ), true );
3546             if ( t8.getNumberOfExternalNodes() != 5 ) {
3547                 return false;
3548             }
3549             s = w.toNewHampshire( t8, false ).toString();
3550             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3551                 return false;
3552             }
3553             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3554             t9.deleteSubtree( t9.getNode( "C" ), true );
3555             if ( t9.getNumberOfExternalNodes() != 5 ) {
3556                 return false;
3557             }
3558             s = w.toNewHampshire( t9, true ).toString();
3559             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3560                 return false;
3561             }
3562             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3563             t10.deleteSubtree( t10.getNode( "D" ), true );
3564             if ( t10.getNumberOfExternalNodes() != 5 ) {
3565                 return false;
3566             }
3567             s = w.toNewHampshire( t10, true ).toString();
3568             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3569                 return false;
3570             }
3571             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3572             t11.deleteSubtree( t11.getNode( "A" ), true );
3573             if ( t11.getNumberOfExternalNodes() != 2 ) {
3574                 return false;
3575             }
3576             s = w.toNewHampshire( t11, true ).toString();
3577             if ( !s.equals( "(B,C);" ) ) {
3578                 return false;
3579             }
3580             t11.deleteSubtree( t11.getNode( "C" ), true );
3581             if ( t11.getNumberOfExternalNodes() != 1 ) {
3582                 return false;
3583             }
3584             s = w.toNewHampshire( t11, false ).toString();
3585             if ( !s.equals( "B;" ) ) {
3586                 return false;
3587             }
3588             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3589             t12.deleteSubtree( t12.getNode( "B2" ), true );
3590             if ( t12.getNumberOfExternalNodes() != 8 ) {
3591                 return false;
3592             }
3593             s = w.toNewHampshire( t12, true ).toString();
3594             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3595                 return false;
3596             }
3597             t12.deleteSubtree( t12.getNode( "B3" ), true );
3598             if ( t12.getNumberOfExternalNodes() != 7 ) {
3599                 return false;
3600             }
3601             s = w.toNewHampshire( t12, true ).toString();
3602             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3603                 return false;
3604             }
3605             t12.deleteSubtree( t12.getNode( "C3" ), true );
3606             if ( t12.getNumberOfExternalNodes() != 6 ) {
3607                 return false;
3608             }
3609             s = w.toNewHampshire( t12, true ).toString();
3610             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3611                 return false;
3612             }
3613             t12.deleteSubtree( t12.getNode( "A1" ), true );
3614             if ( t12.getNumberOfExternalNodes() != 5 ) {
3615                 return false;
3616             }
3617             s = w.toNewHampshire( t12, true ).toString();
3618             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3619                 return false;
3620             }
3621             t12.deleteSubtree( t12.getNode( "B1" ), true );
3622             if ( t12.getNumberOfExternalNodes() != 4 ) {
3623                 return false;
3624             }
3625             s = w.toNewHampshire( t12, true ).toString();
3626             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3627                 return false;
3628             }
3629             t12.deleteSubtree( t12.getNode( "A3" ), true );
3630             if ( t12.getNumberOfExternalNodes() != 3 ) {
3631                 return false;
3632             }
3633             s = w.toNewHampshire( t12, true ).toString();
3634             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3635                 return false;
3636             }
3637             t12.deleteSubtree( t12.getNode( "A2" ), true );
3638             if ( t12.getNumberOfExternalNodes() != 2 ) {
3639                 return false;
3640             }
3641             s = w.toNewHampshire( t12, true ).toString();
3642             if ( !s.equals( "(C1,C2);" ) ) {
3643                 return false;
3644             }
3645             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3646             t13.deleteSubtree( t13.getNode( "D" ), true );
3647             if ( t13.getNumberOfExternalNodes() != 4 ) {
3648                 return false;
3649             }
3650             s = w.toNewHampshire( t13, true ).toString();
3651             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3652                 return false;
3653             }
3654             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3655             t14.deleteSubtree( t14.getNode( "E" ), true );
3656             if ( t14.getNumberOfExternalNodes() != 5 ) {
3657                 return false;
3658             }
3659             s = w.toNewHampshire( t14, true ).toString();
3660             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3661                 return false;
3662             }
3663             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3664             t15.deleteSubtree( t15.getNode( "B2" ), true );
3665             if ( t15.getNumberOfExternalNodes() != 11 ) {
3666                 return false;
3667             }
3668             t15.deleteSubtree( t15.getNode( "B1" ), true );
3669             if ( t15.getNumberOfExternalNodes() != 10 ) {
3670                 return false;
3671             }
3672             t15.deleteSubtree( t15.getNode( "B3" ), true );
3673             if ( t15.getNumberOfExternalNodes() != 9 ) {
3674                 return false;
3675             }
3676             t15.deleteSubtree( t15.getNode( "B4" ), true );
3677             if ( t15.getNumberOfExternalNodes() != 8 ) {
3678                 return false;
3679             }
3680             t15.deleteSubtree( t15.getNode( "A1" ), true );
3681             if ( t15.getNumberOfExternalNodes() != 7 ) {
3682                 return false;
3683             }
3684             t15.deleteSubtree( t15.getNode( "C4" ), true );
3685             if ( t15.getNumberOfExternalNodes() != 6 ) {
3686                 return false;
3687             }
3688         }
3689         catch ( final Exception e ) {
3690             e.printStackTrace( System.out );
3691             return false;
3692         }
3693         return true;
3694     }
3695
3696     private static boolean testDescriptiveStatistics() {
3697         try {
3698             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3699             dss1.addValue( 82 );
3700             dss1.addValue( 78 );
3701             dss1.addValue( 70 );
3702             dss1.addValue( 58 );
3703             dss1.addValue( 42 );
3704             if ( dss1.getN() != 5 ) {
3705                 return false;
3706             }
3707             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3708                 return false;
3709             }
3710             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3711                 return false;
3712             }
3713             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3714                 return false;
3715             }
3716             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3717                 return false;
3718             }
3719             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3720                 return false;
3721             }
3722             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3723                 return false;
3724             }
3725             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3726                 return false;
3727             }
3728             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3729                 return false;
3730             }
3731             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3732                 return false;
3733             }
3734             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3735                 return false;
3736             }
3737             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3738                 return false;
3739             }
3740             dss1.addValue( 123 );
3741             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3742                 return false;
3743             }
3744             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3745                 return false;
3746             }
3747             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3748                 return false;
3749             }
3750             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3751             dss2.addValue( -1.85 );
3752             dss2.addValue( 57.5 );
3753             dss2.addValue( 92.78 );
3754             dss2.addValue( 57.78 );
3755             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3756                 return false;
3757             }
3758             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3759                 return false;
3760             }
3761             final double[] a = dss2.getDataAsDoubleArray();
3762             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3763                 return false;
3764             }
3765             dss2.addValue( -100 );
3766             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3767                 return false;
3768             }
3769             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3770                 return false;
3771             }
3772             final double[] ds = new double[ 14 ];
3773             ds[ 0 ] = 34;
3774             ds[ 1 ] = 23;
3775             ds[ 2 ] = 1;
3776             ds[ 3 ] = 32;
3777             ds[ 4 ] = 11;
3778             ds[ 5 ] = 2;
3779             ds[ 6 ] = 12;
3780             ds[ 7 ] = 33;
3781             ds[ 8 ] = 13;
3782             ds[ 9 ] = 22;
3783             ds[ 10 ] = 21;
3784             ds[ 11 ] = 35;
3785             ds[ 12 ] = 24;
3786             ds[ 13 ] = 31;
3787             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3788             if ( bins.length != 4 ) {
3789                 return false;
3790             }
3791             if ( bins[ 0 ] != 2 ) {
3792                 return false;
3793             }
3794             if ( bins[ 1 ] != 3 ) {
3795                 return false;
3796             }
3797             if ( bins[ 2 ] != 4 ) {
3798                 return false;
3799             }
3800             if ( bins[ 3 ] != 5 ) {
3801                 return false;
3802             }
3803             final double[] ds1 = new double[ 9 ];
3804             ds1[ 0 ] = 10.0;
3805             ds1[ 1 ] = 19.0;
3806             ds1[ 2 ] = 9.999;
3807             ds1[ 3 ] = 0.0;
3808             ds1[ 4 ] = 39.9;
3809             ds1[ 5 ] = 39.999;
3810             ds1[ 6 ] = 30.0;
3811             ds1[ 7 ] = 19.999;
3812             ds1[ 8 ] = 30.1;
3813             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3814             if ( bins1.length != 4 ) {
3815                 return false;
3816             }
3817             if ( bins1[ 0 ] != 2 ) {
3818                 return false;
3819             }
3820             if ( bins1[ 1 ] != 3 ) {
3821                 return false;
3822             }
3823             if ( bins1[ 2 ] != 0 ) {
3824                 return false;
3825             }
3826             if ( bins1[ 3 ] != 4 ) {
3827                 return false;
3828             }
3829             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3830             if ( bins1_1.length != 3 ) {
3831                 return false;
3832             }
3833             if ( bins1_1[ 0 ] != 3 ) {
3834                 return false;
3835             }
3836             if ( bins1_1[ 1 ] != 2 ) {
3837                 return false;
3838             }
3839             if ( bins1_1[ 2 ] != 4 ) {
3840                 return false;
3841             }
3842             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3843             if ( bins1_2.length != 3 ) {
3844                 return false;
3845             }
3846             if ( bins1_2[ 0 ] != 2 ) {
3847                 return false;
3848             }
3849             if ( bins1_2[ 1 ] != 2 ) {
3850                 return false;
3851             }
3852             if ( bins1_2[ 2 ] != 2 ) {
3853                 return false;
3854             }
3855             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3856             dss3.addValue( 1 );
3857             dss3.addValue( 1 );
3858             dss3.addValue( 1 );
3859             dss3.addValue( 2 );
3860             dss3.addValue( 3 );
3861             dss3.addValue( 4 );
3862             dss3.addValue( 5 );
3863             dss3.addValue( 5 );
3864             dss3.addValue( 5 );
3865             dss3.addValue( 6 );
3866             dss3.addValue( 7 );
3867             dss3.addValue( 8 );
3868             dss3.addValue( 9 );
3869             dss3.addValue( 10 );
3870             dss3.addValue( 10 );
3871             dss3.addValue( 10 );
3872             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3873             histo.toStringBuffer( 10, '=', 40, 5 );
3874             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3875         }
3876         catch ( final Exception e ) {
3877             e.printStackTrace( System.out );
3878             return false;
3879         }
3880         return true;
3881     }
3882
3883     private static boolean testDir( final String file ) {
3884         try {
3885             final File f = new File( file );
3886             if ( !f.exists() ) {
3887                 return false;
3888             }
3889             if ( !f.isDirectory() ) {
3890                 return false;
3891             }
3892             if ( !f.canRead() ) {
3893                 return false;
3894             }
3895         }
3896         catch ( final Exception e ) {
3897             return false;
3898         }
3899         return true;
3900     }
3901
3902     private static boolean testEbiEntryRetrieval() {
3903         try {
3904             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
3905             if ( !entry.getAccession().equals( "AAK41263" ) ) {
3906                 System.out.println( entry.getAccession() );
3907                 return false;
3908             }
3909             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
3910                 System.out.println( entry.getTaxonomyScientificName() );
3911                 return false;
3912             }
3913             if ( !entry.getSequenceName()
3914                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
3915                 System.out.println( entry.getSequenceName() );
3916                 return false;
3917             }
3918             // if ( !entry.getSequenceSymbol().equals( "" ) ) {
3919             //     System.out.println( entry.getSequenceSymbol() );
3920             //     return false;
3921             // }
3922             if ( !entry.getGeneName().equals( "treX-like" ) ) {
3923                 System.out.println( entry.getGeneName() );
3924                 return false;
3925             }
3926             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
3927                 System.out.println( entry.getTaxonomyIdentifier() );
3928                 return false;
3929             }
3930             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
3931                 System.out.println( entry.getAnnotations().first().getRefValue() );
3932                 return false;
3933             }
3934             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
3935                 System.out.println( entry.getAnnotations().first().getRefSource() );
3936                 return false;
3937             }
3938             if ( entry.getCrossReferences().size() != 5 ) {
3939                 return false;
3940             }
3941             //
3942             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
3943             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
3944                 return false;
3945             }
3946             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
3947                 System.out.println( entry1.getTaxonomyScientificName() );
3948                 return false;
3949             }
3950             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
3951                 System.out.println( entry1.getSequenceName() );
3952                 return false;
3953             }
3954             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
3955                 System.out.println( entry1.getTaxonomyIdentifier() );
3956                 return false;
3957             }
3958             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
3959                 System.out.println( entry1.getGeneName() );
3960                 return false;
3961             }
3962             if ( entry1.getCrossReferences().size() != 6 ) {
3963                 return false;
3964             }
3965             //
3966             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
3967             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
3968                 return false;
3969             }
3970             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
3971                 System.out.println( entry2.getTaxonomyScientificName() );
3972                 return false;
3973             }
3974             if ( !entry2.getSequenceName()
3975                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
3976                 System.out.println( entry2.getSequenceName() );
3977                 return false;
3978             }
3979             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
3980                 System.out.println( entry2.getTaxonomyIdentifier() );
3981                 return false;
3982             }
3983             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
3984                 System.out.println( entry2.getGeneName() );
3985                 return false;
3986             }
3987             if ( entry2.getCrossReferences().size() != 3 ) {
3988                 return false;
3989             }
3990             //
3991             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
3992             if ( !entry3.getAccession().equals( "HM043801" ) ) {
3993                 return false;
3994             }
3995             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
3996                 System.out.println( entry3.getTaxonomyScientificName() );
3997                 return false;
3998             }
3999             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
4000                 System.out.println( entry3.getSequenceName() );
4001                 return false;
4002             }
4003             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
4004                 System.out.println( entry3.getTaxonomyIdentifier() );
4005                 return false;
4006             }
4007             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
4008                 System.out.println( entry3.getSequenceSymbol() );
4009                 return false;
4010             }
4011             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
4012                 return false;
4013             }
4014             if ( entry3.getCrossReferences().size() != 8 ) {
4015                 return false;
4016             }
4017             //
4018             //
4019             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
4020             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
4021                 return false;
4022             }
4023             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4024                 System.out.println( entry4.getTaxonomyScientificName() );
4025                 return false;
4026             }
4027             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4028                 System.out.println( entry4.getSequenceName() );
4029                 return false;
4030             }
4031             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4032                 System.out.println( entry4.getTaxonomyIdentifier() );
4033                 return false;
4034             }
4035             if ( !entry4.getGeneName().equals( "ras" ) ) {
4036                 System.out.println( entry4.getGeneName() );
4037                 return false;
4038             }
4039             //   if ( !entry4.getChromosome().equals( "ras" ) ) {
4040             //     System.out.println( entry4.getChromosome() );
4041             //     return false;
4042             // }
4043             // if ( !entry4.getMap().equals( "ras" ) ) {
4044             //     System.out.println( entry4.getMap() );
4045             //     return false;
4046             // }
4047             //TODO FIXME gi...
4048             //
4049             //TODO fails:
4050             //            final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "M30539" );
4051             //            if ( !entry5.getAccession().equals( "HM043801" ) ) {
4052             //                return false;
4053             //            }
4054             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4055             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4056                 return false;
4057             }
4058             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4059                 System.out.println( entry5.getTaxonomyScientificName() );
4060                 return false;
4061             }
4062             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4063                 System.out.println( entry5.getSequenceName() );
4064                 return false;
4065             }
4066             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4067                 System.out.println( entry5.getTaxonomyIdentifier() );
4068                 return false;
4069             }
4070         }
4071         catch ( final IOException e ) {
4072             System.out.println();
4073             System.out.println( "the following might be due to absence internet connection:" );
4074             e.printStackTrace( System.out );
4075             return true;
4076         }
4077         catch ( final Exception e ) {
4078             e.printStackTrace();
4079             return false;
4080         }
4081         return true;
4082     }
4083
4084     private static boolean testExternalNodeRelatedMethods() {
4085         try {
4086             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4087             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4088             PhylogenyNode n = t1.getNode( "A" );
4089             n = n.getNextExternalNode();
4090             if ( !n.getName().equals( "B" ) ) {
4091                 return false;
4092             }
4093             n = n.getNextExternalNode();
4094             if ( !n.getName().equals( "C" ) ) {
4095                 return false;
4096             }
4097             n = n.getNextExternalNode();
4098             if ( !n.getName().equals( "D" ) ) {
4099                 return false;
4100             }
4101             n = t1.getNode( "B" );
4102             while ( !n.isLastExternalNode() ) {
4103                 n = n.getNextExternalNode();
4104             }
4105             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4106             n = t2.getNode( "A" );
4107             n = n.getNextExternalNode();
4108             if ( !n.getName().equals( "B" ) ) {
4109                 return false;
4110             }
4111             n = n.getNextExternalNode();
4112             if ( !n.getName().equals( "C" ) ) {
4113                 return false;
4114             }
4115             n = n.getNextExternalNode();
4116             if ( !n.getName().equals( "D" ) ) {
4117                 return false;
4118             }
4119             n = t2.getNode( "B" );
4120             while ( !n.isLastExternalNode() ) {
4121                 n = n.getNextExternalNode();
4122             }
4123             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4124             n = t3.getNode( "A" );
4125             n = n.getNextExternalNode();
4126             if ( !n.getName().equals( "B" ) ) {
4127                 return false;
4128             }
4129             n = n.getNextExternalNode();
4130             if ( !n.getName().equals( "C" ) ) {
4131                 return false;
4132             }
4133             n = n.getNextExternalNode();
4134             if ( !n.getName().equals( "D" ) ) {
4135                 return false;
4136             }
4137             n = n.getNextExternalNode();
4138             if ( !n.getName().equals( "E" ) ) {
4139                 return false;
4140             }
4141             n = n.getNextExternalNode();
4142             if ( !n.getName().equals( "F" ) ) {
4143                 return false;
4144             }
4145             n = n.getNextExternalNode();
4146             if ( !n.getName().equals( "G" ) ) {
4147                 return false;
4148             }
4149             n = n.getNextExternalNode();
4150             if ( !n.getName().equals( "H" ) ) {
4151                 return false;
4152             }
4153             n = t3.getNode( "B" );
4154             while ( !n.isLastExternalNode() ) {
4155                 n = n.getNextExternalNode();
4156             }
4157             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4158             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4159                 final PhylogenyNode node = iter.next();
4160             }
4161             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4162             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4163                 final PhylogenyNode node = iter.next();
4164             }
4165             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4166             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4167             if ( !iter.next().getName().equals( "A" ) ) {
4168                 return false;
4169             }
4170             if ( !iter.next().getName().equals( "B" ) ) {
4171                 return false;
4172             }
4173             if ( !iter.next().getName().equals( "C" ) ) {
4174                 return false;
4175             }
4176             if ( !iter.next().getName().equals( "D" ) ) {
4177                 return false;
4178             }
4179             if ( !iter.next().getName().equals( "E" ) ) {
4180                 return false;
4181             }
4182             if ( !iter.next().getName().equals( "F" ) ) {
4183                 return false;
4184             }
4185             if ( iter.hasNext() ) {
4186                 return false;
4187             }
4188         }
4189         catch ( final Exception e ) {
4190             e.printStackTrace( System.out );
4191             return false;
4192         }
4193         return true;
4194     }
4195
4196     private static boolean testExtractSNFromNodeName() {
4197         try {
4198             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4199                 return false;
4200             }
4201             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4202                 return false;
4203             }
4204             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4205                 return false;
4206             }
4207             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4208                     .equals( "Mus musculus musculus" ) ) {
4209                 return false;
4210             }
4211             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4212                     .equals( "Mus musculus musculus" ) ) {
4213                 return false;
4214             }
4215             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4216                     .equals( "Mus musculus musculus" ) ) {
4217                 return false;
4218             }
4219             if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4220                     .equals( "Mus musculus musculus" ) ) {
4221                 return false;
4222             }
4223             if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4224                 return false;
4225             }
4226             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4227                     .equals( "Mus musculus musculus" ) ) {
4228                 return false;
4229             }
4230             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4231                     .equals( "Mus musculus musculus" ) ) {
4232                 return false;
4233             }
4234             if ( ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
4235                 return false;
4236             }
4237             if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
4238                 return false;
4239             }
4240             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
4241                 return false;
4242             }
4243             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
4244                 return false;
4245             }
4246             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
4247                     .equals( "Mus musculus musculus" ) ) {
4248                 return false;
4249             }
4250             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
4251                 return false;
4252             }
4253             if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
4254                 return false;
4255             }
4256             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
4257                 return false;
4258             }
4259             if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
4260                 return false;
4261             }
4262             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
4263                 return false;
4264             }
4265             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
4266                 return false;
4267             }
4268             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
4269                 return false;
4270             }
4271             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
4272                 return false;
4273             }
4274             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
4275                     .equals( "Mus musculus" ) ) {
4276                 return false;
4277             }
4278             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
4279                     .equals( "Mus musculus" ) ) {
4280                 return false;
4281             }
4282             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4283                 return false;
4284             }
4285             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4286                     .equals( "Mus musculus musculus" ) ) {
4287                 return false;
4288             }
4289             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4290                     .equals( "Mus musculus musculus" ) ) {
4291                 return false;
4292             }
4293             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
4294                     .equals( "Mus musculus musculus" ) ) {
4295                 return false;
4296             }
4297             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4298                 return false;
4299             }
4300             if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
4301                     .equals( "Pilostyles mexicana" ) ) {
4302                 return false;
4303             }
4304             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
4305                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
4306                 return false;
4307             }
4308             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
4309                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4310                 return false;
4311             }
4312             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
4313                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4314                 return false;
4315             }
4316             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
4317                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4318                 return false;
4319             }
4320             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
4321                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4322                 return false;
4323             }
4324             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
4325                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4326                 return false;
4327             }
4328             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
4329                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4330                 return false;
4331             }
4332             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
4333                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4334                 return false;
4335             }
4336             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
4337                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
4338                 return false;
4339             }
4340             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
4341                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
4342                 return false;
4343             }
4344             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
4345                     .equals( "Escherichia coli (strain K12)" ) ) {
4346                 return false;
4347             }
4348             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
4349                     .equals( "Escherichia coli (strain K12)" ) ) {
4350                 return false;
4351             }
4352             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
4353                     .equals( "Escherichia coli (str. K12)" ) ) {
4354                 return false;
4355             }
4356             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
4357                     .equals( "Escherichia coli (str. K12)" ) ) {
4358                 return false;
4359             }
4360             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
4361                     .equals( "Escherichia coli (str. K12)" ) ) {
4362                 return false;
4363             }
4364             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
4365                     .equals( "Escherichia coli (var. K12)" ) ) {
4366                 return false;
4367             }
4368             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K-12 substr. MG1655star" )
4369                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4370                 return false;
4371             }
4372             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star" )
4373                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4374                 return false;
4375             }
4376             if ( !ParserUtils
4377                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star" )
4378                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4379                 return false;
4380             }
4381             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
4382                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4383                 return false;
4384             }
4385             if ( !ParserUtils
4386                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
4387                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4388                 return false;
4389             }
4390             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4391                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4392                 return false;
4393             }
4394             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4395                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4396                 return false;
4397             }
4398             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
4399                 return false;
4400             }
4401             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
4402                 return false;
4403             }
4404             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
4405                 return false;
4406             }
4407             if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
4408                     .equals( "Macrocera sp." ) ) {
4409                 return false;
4410             }
4411             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
4412                 return false;
4413             }
4414             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
4415                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4416                 return false;
4417             }
4418             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
4419                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4420                 return false;
4421             }
4422             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
4423                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4424                 return false;
4425             }
4426             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
4427                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4428                 return false;
4429             }
4430         }
4431         catch ( final Exception e ) {
4432             e.printStackTrace( System.out );
4433             return false;
4434         }
4435         return true;
4436     }
4437
4438     private static boolean testExtractTaxonomyCodeFromNodeName() {
4439         try {
4440             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4441                 return false;
4442             }
4443             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4444                     .equals( "SOYBN" ) ) {
4445                 return false;
4446             }
4447             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4448                     .equals( "ARATH" ) ) {
4449                 return false;
4450             }
4451             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4452                     .equals( "ARATH" ) ) {
4453                 return false;
4454             }
4455             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4456                 return false;
4457             }
4458             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4459                 return false;
4460             }
4461             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4462                 return false;
4463             }
4464             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4465                     .equals( "SOYBN" ) ) {
4466                 return false;
4467             }
4468             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4469                     .equals( "SOYBN" ) ) {
4470                 return false;
4471             }
4472             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4473                     .equals( "SOYBN" ) ) {
4474                 return false;
4475             }
4476             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4477                     .equals( "SOYBN" ) ) {
4478                 return false;
4479             }
4480             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4481                     .equals( "SOYBN" ) ) {
4482                 return false;
4483             }
4484             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4485                     .equals( "SOYBN" ) ) {
4486                 return false;
4487             }
4488             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4489                     .equals( "SOYBN" ) ) {
4490                 return false;
4491             }
4492             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
4493                     .equals( "SOYBN" ) ) {
4494                 return false;
4495             }
4496             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
4497                 return false;
4498             }
4499             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
4500                     .equals( "SOYBN" ) ) {
4501                 return false;
4502             }
4503             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
4504                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
4505                 return false;
4506             }
4507             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
4508                     .equals( "9YX45" ) ) {
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_MOUSE+function = 23445",
4517                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4518                     .equals( "MOUSE" ) ) {
4519                 return false;
4520             }
4521             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
4522                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4523                     .equals( "MOUSE" ) ) {
4524                 return false;
4525             }
4526             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
4527                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4528                 return false;
4529             }
4530             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
4531                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4532                 return false;
4533             }
4534             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4535                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4536                 return false;
4537             }
4538             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4539                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4540                 return false;
4541             }
4542             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
4543                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4544                 return false;
4545             }
4546             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
4547                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4548                 return false;
4549             }
4550             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
4551                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4552                 return false;
4553             }
4554             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4555                     .equals( "RAT" ) ) {
4556                 return false;
4557             }
4558             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4559                     .equals( "PIG" ) ) {
4560                 return false;
4561             }
4562             if ( !ParserUtils
4563                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4564                     .equals( "MOUSE" ) ) {
4565                 return false;
4566             }
4567             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4568                     .equals( "MOUSE" ) ) {
4569                 return false;
4570             }
4571             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4572                 return false;
4573             }
4574         }
4575         catch ( final Exception e ) {
4576             e.printStackTrace( System.out );
4577             return false;
4578         }
4579         return true;
4580     }
4581
4582     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
4583         try {
4584             PhylogenyNode n = new PhylogenyNode();
4585             n.setName( "tr|B3RJ64" );
4586             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4587                 return false;
4588             }
4589             n.setName( "tr.B3RJ64" );
4590             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4591                 return false;
4592             }
4593             n.setName( "tr=B3RJ64" );
4594             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4595                 return false;
4596             }
4597             n.setName( "tr-B3RJ64" );
4598             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4599                 return false;
4600             }
4601             n.setName( "tr/B3RJ64" );
4602             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4603                 return false;
4604             }
4605             n.setName( "tr\\B3RJ64" );
4606             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4607                 return false;
4608             }
4609             n.setName( "tr_B3RJ64" );
4610             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4611                 return false;
4612             }
4613             n.setName( " tr|B3RJ64 " );
4614             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4615                 return false;
4616             }
4617             n.setName( "-tr|B3RJ64-" );
4618             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4619                 return false;
4620             }
4621             n.setName( "-tr=B3RJ64-" );
4622             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4623                 return false;
4624             }
4625             n.setName( "_tr=B3RJ64_" );
4626             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4627                 return false;
4628             }
4629             n.setName( " tr_tr|B3RJ64_sp|123 " );
4630             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4631                 return false;
4632             }
4633             n.setName( "B3RJ64" );
4634             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4635                 return false;
4636             }
4637             n.setName( "sp|B3RJ64" );
4638             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4639                 return false;
4640             }
4641             n.setName( "sp|B3RJ64C" );
4642             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4643                 return false;
4644             }
4645             n.setName( "sp B3RJ64" );
4646             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4647                 return false;
4648             }
4649             n.setName( "sp|B3RJ6X" );
4650             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4651                 return false;
4652             }
4653             n.setName( "sp|B3RJ6" );
4654             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4655                 return false;
4656             }
4657             n.setName( "K1PYK7_CRAGI" );
4658             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4659                 return false;
4660             }
4661             n.setName( "K1PYK7_PEA" );
4662             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
4663                 return false;
4664             }
4665             n.setName( "K1PYK7_RAT" );
4666             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
4667                 return false;
4668             }
4669             n.setName( "K1PYK7_PIG" );
4670             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4671                 return false;
4672             }
4673             n.setName( "~K1PYK7_PIG~" );
4674             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4675                 return false;
4676             }
4677             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
4678             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4679                 return false;
4680             }
4681             n.setName( "K1PYKX_CRAGI" );
4682             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4683                 return false;
4684             }
4685             n.setName( "XXXXX_CRAGI" );
4686             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
4687                 return false;
4688             }
4689             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
4690             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
4691                 return false;
4692             }
4693             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
4694             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4695                 return false;
4696             }
4697             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
4698             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
4699                 return false;
4700             }
4701             n = new PhylogenyNode();
4702             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
4703             seq.setSymbol( "K1PYK7_CRAGI" );
4704             n.getNodeData().addSequence( seq );
4705             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4706                 return false;
4707             }
4708             seq.setSymbol( "tr|B3RJ64" );
4709             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4710                 return false;
4711             }
4712             n = new PhylogenyNode();
4713             seq = new org.forester.phylogeny.data.Sequence();
4714             seq.setName( "K1PYK7_CRAGI" );
4715             n.getNodeData().addSequence( seq );
4716             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4717                 return false;
4718             }
4719             seq.setName( "tr|B3RJ64" );
4720             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4721                 return false;
4722             }
4723             n = new PhylogenyNode();
4724             seq = new org.forester.phylogeny.data.Sequence();
4725             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4726             n.getNodeData().addSequence( seq );
4727             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
4728                 return false;
4729             }
4730             n = new PhylogenyNode();
4731             seq = new org.forester.phylogeny.data.Sequence();
4732             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4733             n.getNodeData().addSequence( seq );
4734             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4735                 return false;
4736             }
4737             //
4738             n = new PhylogenyNode();
4739             n.setName( "ACP19736" );
4740             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4741                 return false;
4742             }
4743             n = new PhylogenyNode();
4744             n.setName( "|ACP19736|" );
4745             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4746                 return false;
4747             }
4748         }
4749         catch ( final Exception e ) {
4750             e.printStackTrace( System.out );
4751             return false;
4752         }
4753         return true;
4754     }
4755
4756     private static boolean testFastaParser() {
4757         try {
4758             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
4759                 return false;
4760             }
4761             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
4762                 return false;
4763             }
4764             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
4765             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
4766                 return false;
4767             }
4768             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
4769                 return false;
4770             }
4771             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
4772                 return false;
4773             }
4774             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
4775                 return false;
4776             }
4777             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
4778                 return false;
4779             }
4780             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
4781                 return false;
4782             }
4783         }
4784         catch ( final Exception e ) {
4785             e.printStackTrace();
4786             return false;
4787         }
4788         return true;
4789     }
4790
4791     private static boolean testGenbankAccessorParsing() {
4792         //The format for GenBank Accession numbers are:
4793         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
4794         //Protein:    3 letters + 5 numerals
4795         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
4796         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
4797             return false;
4798         }
4799         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
4800             return false;
4801         }
4802         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
4803             return false;
4804         }
4805         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
4806             return false;
4807         }
4808         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
4809             return false;
4810         }
4811         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
4812             return false;
4813         }
4814         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
4815             return false;
4816         }
4817         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
4818             return false;
4819         }
4820         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
4821             return false;
4822         }
4823         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
4824             return false;
4825         }
4826         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
4827             return false;
4828         }
4829         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
4830             return false;
4831         }
4832         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
4833             return false;
4834         }
4835         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
4836             return false;
4837         }
4838         return true;
4839     }
4840
4841     private static boolean testGeneralMsaParser() {
4842         try {
4843             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
4844             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
4845             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
4846             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
4847             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
4848             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
4849             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
4850             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
4851             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4852                 return false;
4853             }
4854             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4855                 return false;
4856             }
4857             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4858                 return false;
4859             }
4860             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4861                 return false;
4862             }
4863             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4864                 return false;
4865             }
4866             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4867                 return false;
4868             }
4869             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4870                 return false;
4871             }
4872             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4873                 return false;
4874             }
4875             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4876                 return false;
4877             }
4878             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4879                 return false;
4880             }
4881             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4882                 return false;
4883             }
4884             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4885                 return false;
4886             }
4887             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
4888             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4889                 return false;
4890             }
4891             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4892                 return false;
4893             }
4894             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4895                 return false;
4896             }
4897             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
4898             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
4899                 return false;
4900             }
4901             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
4902                 return false;
4903             }
4904             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
4905                 return false;
4906             }
4907             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
4908             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4909                 return false;
4910             }
4911             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4912                 return false;
4913             }
4914             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4915                 return false;
4916             }
4917         }
4918         catch ( final Exception e ) {
4919             e.printStackTrace();
4920             return false;
4921         }
4922         return true;
4923     }
4924
4925     private static boolean testGeneralTable() {
4926         try {
4927             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
4928             t0.setValue( 3, 2, "23" );
4929             t0.setValue( 10, 1, "error" );
4930             t0.setValue( 10, 1, "110" );
4931             t0.setValue( 9, 1, "19" );
4932             t0.setValue( 1, 10, "101" );
4933             t0.setValue( 10, 10, "1010" );
4934             t0.setValue( 100, 10, "10100" );
4935             t0.setValue( 0, 0, "00" );
4936             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
4937                 return false;
4938             }
4939             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
4940                 return false;
4941             }
4942             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
4943                 return false;
4944             }
4945             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
4946                 return false;
4947             }
4948             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
4949                 return false;
4950             }
4951             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
4952                 return false;
4953             }
4954             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
4955                 return false;
4956             }
4957             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
4958                 return false;
4959             }
4960             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
4961                 return false;
4962             }
4963             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
4964             t1.setValue( "3", "2", "23" );
4965             t1.setValue( "10", "1", "error" );
4966             t1.setValue( "10", "1", "110" );
4967             t1.setValue( "9", "1", "19" );
4968             t1.setValue( "1", "10", "101" );
4969             t1.setValue( "10", "10", "1010" );
4970             t1.setValue( "100", "10", "10100" );
4971             t1.setValue( "0", "0", "00" );
4972             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
4973             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
4974                 return false;
4975             }
4976             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
4977                 return false;
4978             }
4979             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
4980                 return false;
4981             }
4982             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
4983                 return false;
4984             }
4985             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
4986                 return false;
4987             }
4988             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
4989                 return false;
4990             }
4991             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
4992                 return false;
4993             }
4994             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
4995                 return false;
4996             }
4997             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
4998                 return false;
4999             }
5000             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
5001                 return false;
5002             }
5003         }
5004         catch ( final Exception e ) {
5005             e.printStackTrace( System.out );
5006             return false;
5007         }
5008         return true;
5009     }
5010
5011     private static boolean testGetDistance() {
5012         try {
5013             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5014             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",
5015                                                  new NHXParser() )[ 0 ];
5016             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
5017                 return false;
5018             }
5019             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
5020                 return false;
5021             }
5022             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5023                 return false;
5024             }
5025             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5026                 return false;
5027             }
5028             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5029                 return false;
5030             }
5031             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5032                 return false;
5033             }
5034             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5035                 return false;
5036             }
5037             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5038                 return false;
5039             }
5040             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5041                 return false;
5042             }
5043             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5044                 return false;
5045             }
5046             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5047                 return false;
5048             }
5049             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5050                 return false;
5051             }
5052             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5053                 return false;
5054             }
5055             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5056                 return false;
5057             }
5058             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5059                 return false;
5060             }
5061             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5062                 return false;
5063             }
5064             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5065                 return false;
5066             }
5067             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5068                 return false;
5069             }
5070             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5071                 return false;
5072             }
5073             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5074                 return false;
5075             }
5076             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5077                 return false;
5078             }
5079             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5080                 return false;
5081             }
5082             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5083                 return false;
5084             }
5085             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5086                 return false;
5087             }
5088             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5089                 return false;
5090             }
5091             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5092                 return false;
5093             }
5094             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5095                 return false;
5096             }
5097             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5098                 return false;
5099             }
5100             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5101                 return false;
5102             }
5103             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5104                 return false;
5105             }
5106             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5107                 return false;
5108             }
5109             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",
5110                                                  new NHXParser() )[ 0 ];
5111             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5112                 return false;
5113             }
5114             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5115                 return false;
5116             }
5117             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5118                 return false;
5119             }
5120             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5121                 return false;
5122             }
5123             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5124                 return false;
5125             }
5126             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5127                 return false;
5128             }
5129             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5130                 return false;
5131             }
5132             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5133                 return false;
5134             }
5135             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5136                 return false;
5137             }
5138             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5139                 return false;
5140             }
5141             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5142                 return false;
5143             }
5144         }
5145         catch ( final Exception e ) {
5146             e.printStackTrace( System.out );
5147             return false;
5148         }
5149         return true;
5150     }
5151
5152     private static boolean testGetLCA() {
5153         try {
5154             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5155             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5156                                                  new NHXParser() )[ 0 ];
5157             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5158             if ( !A.getName().equals( "A" ) ) {
5159                 return false;
5160             }
5161             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5162             if ( !gh.getName().equals( "gh" ) ) {
5163                 return false;
5164             }
5165             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5166             if ( !ab.getName().equals( "ab" ) ) {
5167                 return false;
5168             }
5169             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5170             if ( !ab2.getName().equals( "ab" ) ) {
5171                 return false;
5172             }
5173             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5174             if ( !gh2.getName().equals( "gh" ) ) {
5175                 return false;
5176             }
5177             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5178             if ( !gh3.getName().equals( "gh" ) ) {
5179                 return false;
5180             }
5181             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5182             if ( !abc.getName().equals( "abc" ) ) {
5183                 return false;
5184             }
5185             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5186             if ( !abc2.getName().equals( "abc" ) ) {
5187                 return false;
5188             }
5189             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5190             if ( !abcd.getName().equals( "abcd" ) ) {
5191                 return false;
5192             }
5193             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5194             if ( !abcd2.getName().equals( "abcd" ) ) {
5195                 return false;
5196             }
5197             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5198             if ( !abcdef.getName().equals( "abcdef" ) ) {
5199                 return false;
5200             }
5201             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5202             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5203                 return false;
5204             }
5205             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5206             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5207                 return false;
5208             }
5209             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5210             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5211                 return false;
5212             }
5213             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
5214             if ( !abcde.getName().equals( "abcde" ) ) {
5215                 return false;
5216             }
5217             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
5218             if ( !abcde2.getName().equals( "abcde" ) ) {
5219                 return false;
5220             }
5221             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
5222             if ( !r.getName().equals( "abcdefgh" ) ) {
5223                 return false;
5224             }
5225             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5226             if ( !r2.getName().equals( "abcdefgh" ) ) {
5227                 return false;
5228             }
5229             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5230             if ( !r3.getName().equals( "abcdefgh" ) ) {
5231                 return false;
5232             }
5233             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5234             if ( !abcde3.getName().equals( "abcde" ) ) {
5235                 return false;
5236             }
5237             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5238             if ( !abcde4.getName().equals( "abcde" ) ) {
5239                 return false;
5240             }
5241             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5242             if ( !ab3.getName().equals( "ab" ) ) {
5243                 return false;
5244             }
5245             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5246             if ( !ab4.getName().equals( "ab" ) ) {
5247                 return false;
5248             }
5249             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5250             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5251             if ( !cd.getName().equals( "cd" ) ) {
5252                 return false;
5253             }
5254             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5255             if ( !cd2.getName().equals( "cd" ) ) {
5256                 return false;
5257             }
5258             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5259             if ( !cde.getName().equals( "cde" ) ) {
5260                 return false;
5261             }
5262             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5263             if ( !cde2.getName().equals( "cde" ) ) {
5264                 return false;
5265             }
5266             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5267             if ( !cdef.getName().equals( "cdef" ) ) {
5268                 return false;
5269             }
5270             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5271             if ( !cdef2.getName().equals( "cdef" ) ) {
5272                 return false;
5273             }
5274             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5275             if ( !cdef3.getName().equals( "cdef" ) ) {
5276                 return false;
5277             }
5278             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5279             if ( !rt.getName().equals( "r" ) ) {
5280                 return false;
5281             }
5282             final Phylogeny p3 = factory
5283                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5284                              new NHXParser() )[ 0 ];
5285             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5286             if ( !bc_3.getName().equals( "bc" ) ) {
5287                 return false;
5288             }
5289             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5290             if ( !ac_3.getName().equals( "abc" ) ) {
5291                 return false;
5292             }
5293             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5294             if ( !ad_3.getName().equals( "abcde" ) ) {
5295                 return false;
5296             }
5297             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5298             if ( !af_3.getName().equals( "abcdef" ) ) {
5299                 return false;
5300             }
5301             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5302             if ( !ag_3.getName().equals( "" ) ) {
5303                 return false;
5304             }
5305             if ( !ag_3.isRoot() ) {
5306                 return false;
5307             }
5308             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5309             if ( !al_3.getName().equals( "" ) ) {
5310                 return false;
5311             }
5312             if ( !al_3.isRoot() ) {
5313                 return false;
5314             }
5315             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5316             if ( !kl_3.getName().equals( "" ) ) {
5317                 return false;
5318             }
5319             if ( !kl_3.isRoot() ) {
5320                 return false;
5321             }
5322             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5323             if ( !fl_3.getName().equals( "" ) ) {
5324                 return false;
5325             }
5326             if ( !fl_3.isRoot() ) {
5327                 return false;
5328             }
5329             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5330             if ( !gk_3.getName().equals( "ghijk" ) ) {
5331                 return false;
5332             }
5333             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5334             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5335             if ( !r_4.getName().equals( "r" ) ) {
5336                 return false;
5337             }
5338             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5339             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5340             if ( !r_5.getName().equals( "root" ) ) {
5341                 return false;
5342             }
5343             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5344             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5345             if ( !r_6.getName().equals( "rot" ) ) {
5346                 return false;
5347             }
5348             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5349             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5350             if ( !r_7.getName().equals( "rott" ) ) {
5351                 return false;
5352             }
5353         }
5354         catch ( final Exception e ) {
5355             e.printStackTrace( System.out );
5356             return false;
5357         }
5358         return true;
5359     }
5360
5361     private static boolean testGetLCA2() {
5362         try {
5363             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5364             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5365             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5366             PhylogenyMethods.preOrderReId( p_a );
5367             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5368                                                                                               p_a.getNode( "a" ) );
5369             if ( !p_a_1.getName().equals( "a" ) ) {
5370                 return false;
5371             }
5372             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5373             PhylogenyMethods.preOrderReId( p_b );
5374             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5375                                                                                               p_b.getNode( "a" ) );
5376             if ( !p_b_1.getName().equals( "b" ) ) {
5377                 return false;
5378             }
5379             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5380                                                                                               p_b.getNode( "b" ) );
5381             if ( !p_b_2.getName().equals( "b" ) ) {
5382                 return false;
5383             }
5384             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5385             PhylogenyMethods.preOrderReId( p_c );
5386             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5387                                                                                               p_c.getNode( "a" ) );
5388             if ( !p_c_1.getName().equals( "b" ) ) {
5389                 return false;
5390             }
5391             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5392                                                                                               p_c.getNode( "c" ) );
5393             if ( !p_c_2.getName().equals( "c" ) ) {
5394                 System.out.println( p_c_2.getName() );
5395                 System.exit( -1 );
5396                 return false;
5397             }
5398             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5399                                                                                               p_c.getNode( "b" ) );
5400             if ( !p_c_3.getName().equals( "b" ) ) {
5401                 return false;
5402             }
5403             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5404                                                                                               p_c.getNode( "a" ) );
5405             if ( !p_c_4.getName().equals( "c" ) ) {
5406                 return false;
5407             }
5408             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5409                                                  new NHXParser() )[ 0 ];
5410             PhylogenyMethods.preOrderReId( p1 );
5411             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5412                                                                                           p1.getNode( "A" ) );
5413             if ( !A.getName().equals( "A" ) ) {
5414                 return false;
5415             }
5416             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5417                                                                                            p1.getNode( "gh" ) );
5418             if ( !gh.getName().equals( "gh" ) ) {
5419                 return false;
5420             }
5421             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5422                                                                                            p1.getNode( "B" ) );
5423             if ( !ab.getName().equals( "ab" ) ) {
5424                 return false;
5425             }
5426             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5427                                                                                             p1.getNode( "A" ) );
5428             if ( !ab2.getName().equals( "ab" ) ) {
5429                 return false;
5430             }
5431             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5432                                                                                             p1.getNode( "G" ) );
5433             if ( !gh2.getName().equals( "gh" ) ) {
5434                 return false;
5435             }
5436             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5437                                                                                             p1.getNode( "H" ) );
5438             if ( !gh3.getName().equals( "gh" ) ) {
5439                 return false;
5440             }
5441             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5442                                                                                             p1.getNode( "A" ) );
5443             if ( !abc.getName().equals( "abc" ) ) {
5444                 return false;
5445             }
5446             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5447                                                                                              p1.getNode( "C" ) );
5448             if ( !abc2.getName().equals( "abc" ) ) {
5449                 return false;
5450             }
5451             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5452                                                                                              p1.getNode( "D" ) );
5453             if ( !abcd.getName().equals( "abcd" ) ) {
5454                 return false;
5455             }
5456             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5457                                                                                               p1.getNode( "A" ) );
5458             if ( !abcd2.getName().equals( "abcd" ) ) {
5459                 return false;
5460             }
5461             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5462                                                                                                p1.getNode( "F" ) );
5463             if ( !abcdef.getName().equals( "abcdef" ) ) {
5464                 return false;
5465             }
5466             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5467                                                                                                 p1.getNode( "A" ) );
5468             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5469                 return false;
5470             }
5471             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5472                                                                                                 p1.getNode( "F" ) );
5473             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5474                 return false;
5475             }
5476             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5477                                                                                                 p1.getNode( "ab" ) );
5478             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5479                 return false;
5480             }
5481             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5482                                                                                               p1.getNode( "E" ) );
5483             if ( !abcde.getName().equals( "abcde" ) ) {
5484                 return false;
5485             }
5486             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5487                                                                                                p1.getNode( "A" ) );
5488             if ( !abcde2.getName().equals( "abcde" ) ) {
5489                 return false;
5490             }
5491             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
5492                                                                                           p1.getNode( "abcdefgh" ) );
5493             if ( !r.getName().equals( "abcdefgh" ) ) {
5494                 return false;
5495             }
5496             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5497                                                                                            p1.getNode( "H" ) );
5498             if ( !r2.getName().equals( "abcdefgh" ) ) {
5499                 return false;
5500             }
5501             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5502                                                                                            p1.getNode( "A" ) );
5503             if ( !r3.getName().equals( "abcdefgh" ) ) {
5504                 return false;
5505             }
5506             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5507                                                                                                p1.getNode( "abcde" ) );
5508             if ( !abcde3.getName().equals( "abcde" ) ) {
5509                 return false;
5510             }
5511             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
5512                                                                                                p1.getNode( "E" ) );
5513             if ( !abcde4.getName().equals( "abcde" ) ) {
5514                 return false;
5515             }
5516             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5517                                                                                             p1.getNode( "B" ) );
5518             if ( !ab3.getName().equals( "ab" ) ) {
5519                 return false;
5520             }
5521             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5522                                                                                             p1.getNode( "ab" ) );
5523             if ( !ab4.getName().equals( "ab" ) ) {
5524                 return false;
5525             }
5526             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5527             PhylogenyMethods.preOrderReId( p2 );
5528             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5529                                                                                            p2.getNode( "d" ) );
5530             if ( !cd.getName().equals( "cd" ) ) {
5531                 return false;
5532             }
5533             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5534                                                                                             p2.getNode( "c" ) );
5535             if ( !cd2.getName().equals( "cd" ) ) {
5536                 return false;
5537             }
5538             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5539                                                                                             p2.getNode( "e" ) );
5540             if ( !cde.getName().equals( "cde" ) ) {
5541                 return false;
5542             }
5543             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
5544                                                                                              p2.getNode( "c" ) );
5545             if ( !cde2.getName().equals( "cde" ) ) {
5546                 return false;
5547             }
5548             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5549                                                                                              p2.getNode( "f" ) );
5550             if ( !cdef.getName().equals( "cdef" ) ) {
5551                 return false;
5552             }
5553             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5554                                                                                               p2.getNode( "f" ) );
5555             if ( !cdef2.getName().equals( "cdef" ) ) {
5556                 return false;
5557             }
5558             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
5559                                                                                               p2.getNode( "d" ) );
5560             if ( !cdef3.getName().equals( "cdef" ) ) {
5561                 return false;
5562             }
5563             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5564                                                                                            p2.getNode( "a" ) );
5565             if ( !rt.getName().equals( "r" ) ) {
5566                 return false;
5567             }
5568             final Phylogeny p3 = factory
5569                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5570                              new NHXParser() )[ 0 ];
5571             PhylogenyMethods.preOrderReId( p3 );
5572             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
5573                                                                                              p3.getNode( "c" ) );
5574             if ( !bc_3.getName().equals( "bc" ) ) {
5575                 return false;
5576             }
5577             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5578                                                                                              p3.getNode( "c" ) );
5579             if ( !ac_3.getName().equals( "abc" ) ) {
5580                 return false;
5581             }
5582             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5583                                                                                              p3.getNode( "d" ) );
5584             if ( !ad_3.getName().equals( "abcde" ) ) {
5585                 return false;
5586             }
5587             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5588                                                                                              p3.getNode( "f" ) );
5589             if ( !af_3.getName().equals( "abcdef" ) ) {
5590                 return false;
5591             }
5592             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5593                                                                                              p3.getNode( "g" ) );
5594             if ( !ag_3.getName().equals( "" ) ) {
5595                 return false;
5596             }
5597             if ( !ag_3.isRoot() ) {
5598                 return false;
5599             }
5600             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5601                                                                                              p3.getNode( "l" ) );
5602             if ( !al_3.getName().equals( "" ) ) {
5603                 return false;
5604             }
5605             if ( !al_3.isRoot() ) {
5606                 return false;
5607             }
5608             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
5609                                                                                              p3.getNode( "l" ) );
5610             if ( !kl_3.getName().equals( "" ) ) {
5611                 return false;
5612             }
5613             if ( !kl_3.isRoot() ) {
5614                 return false;
5615             }
5616             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
5617                                                                                              p3.getNode( "l" ) );
5618             if ( !fl_3.getName().equals( "" ) ) {
5619                 return false;
5620             }
5621             if ( !fl_3.isRoot() ) {
5622                 return false;
5623             }
5624             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
5625                                                                                              p3.getNode( "k" ) );
5626             if ( !gk_3.getName().equals( "ghijk" ) ) {
5627                 return false;
5628             }
5629             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5630             PhylogenyMethods.preOrderReId( p4 );
5631             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
5632                                                                                             p4.getNode( "c" ) );
5633             if ( !r_4.getName().equals( "r" ) ) {
5634                 return false;
5635             }
5636             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5637             PhylogenyMethods.preOrderReId( p5 );
5638             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
5639                                                                                             p5.getNode( "c" ) );
5640             if ( !r_5.getName().equals( "root" ) ) {
5641                 return false;
5642             }
5643             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5644             PhylogenyMethods.preOrderReId( p6 );
5645             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
5646                                                                                             p6.getNode( "a" ) );
5647             if ( !r_6.getName().equals( "rot" ) ) {
5648                 return false;
5649             }
5650             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5651             PhylogenyMethods.preOrderReId( p7 );
5652             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
5653                                                                                             p7.getNode( "e" ) );
5654             if ( !r_7.getName().equals( "rott" ) ) {
5655                 return false;
5656             }
5657             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5658                                                                                              p7.getNode( "a" ) );
5659             if ( !r_71.getName().equals( "rott" ) ) {
5660                 return false;
5661             }
5662             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5663                                                                                              p7.getNode( "rott" ) );
5664             if ( !r_72.getName().equals( "rott" ) ) {
5665                 return false;
5666             }
5667             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5668                                                                                              p7.getNode( "a" ) );
5669             if ( !r_73.getName().equals( "rott" ) ) {
5670                 return false;
5671             }
5672             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5673                                                                                              p7.getNode( "rott" ) );
5674             if ( !r_74.getName().equals( "rott" ) ) {
5675                 return false;
5676             }
5677             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5678                                                                                              p7.getNode( "e" ) );
5679             if ( !r_75.getName().equals( "e" ) ) {
5680                 return false;
5681             }
5682         }
5683         catch ( final Exception e ) {
5684             e.printStackTrace( System.out );
5685             return false;
5686         }
5687         return true;
5688     }
5689
5690     private static boolean testHmmscanOutputParser() {
5691         final String test_dir = Test.PATH_TO_TEST_DATA;
5692         try {
5693             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
5694                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5695             parser1.parse();
5696             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
5697                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5698             final List<Protein> proteins = parser2.parse();
5699             if ( parser2.getProteinsEncountered() != 4 ) {
5700                 return false;
5701             }
5702             if ( proteins.size() != 4 ) {
5703                 return false;
5704             }
5705             if ( parser2.getDomainsEncountered() != 69 ) {
5706                 return false;
5707             }
5708             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
5709                 return false;
5710             }
5711             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
5712                 return false;
5713             }
5714             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
5715                 return false;
5716             }
5717             final Protein p1 = proteins.get( 0 );
5718             if ( p1.getNumberOfProteinDomains() != 15 ) {
5719                 return false;
5720             }
5721             if ( p1.getLength() != 850 ) {
5722                 return false;
5723             }
5724             final Protein p2 = proteins.get( 1 );
5725             if ( p2.getNumberOfProteinDomains() != 51 ) {
5726                 return false;
5727             }
5728             if ( p2.getLength() != 1291 ) {
5729                 return false;
5730             }
5731             final Protein p3 = proteins.get( 2 );
5732             if ( p3.getNumberOfProteinDomains() != 2 ) {
5733                 return false;
5734             }
5735             final Protein p4 = proteins.get( 3 );
5736             if ( p4.getNumberOfProteinDomains() != 1 ) {
5737                 return false;
5738             }
5739             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
5740                 return false;
5741             }
5742             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
5743                 return false;
5744             }
5745             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
5746                 return false;
5747             }
5748             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
5749                 return false;
5750             }
5751             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
5752                 return false;
5753             }
5754             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
5755                 return false;
5756             }
5757             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
5758                 return false;
5759             }
5760         }
5761         catch ( final Exception e ) {
5762             e.printStackTrace( System.out );
5763             return false;
5764         }
5765         return true;
5766     }
5767
5768     private static boolean testLastExternalNodeMethods() {
5769         try {
5770             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5771             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
5772             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
5773             final PhylogenyNode n1 = t0.getNode( "A" );
5774             if ( n1.isLastExternalNode() ) {
5775                 return false;
5776             }
5777             final PhylogenyNode n2 = t0.getNode( "B" );
5778             if ( n2.isLastExternalNode() ) {
5779                 return false;
5780             }
5781             final PhylogenyNode n3 = t0.getNode( "C" );
5782             if ( n3.isLastExternalNode() ) {
5783                 return false;
5784             }
5785             final PhylogenyNode n4 = t0.getNode( "D" );
5786             if ( !n4.isLastExternalNode() ) {
5787                 return false;
5788             }
5789         }
5790         catch ( final Exception e ) {
5791             e.printStackTrace( System.out );
5792             return false;
5793         }
5794         return true;
5795     }
5796
5797     private static boolean testLevelOrderIterator() {
5798         try {
5799             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5800             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5801             PhylogenyNodeIterator it0;
5802             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
5803                 it0.next();
5804             }
5805             for( it0.reset(); it0.hasNext(); ) {
5806                 it0.next();
5807             }
5808             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
5809             if ( !it.next().getName().equals( "r" ) ) {
5810                 return false;
5811             }
5812             if ( !it.next().getName().equals( "ab" ) ) {
5813                 return false;
5814             }
5815             if ( !it.next().getName().equals( "cd" ) ) {
5816                 return false;
5817             }
5818             if ( !it.next().getName().equals( "A" ) ) {
5819                 return false;
5820             }
5821             if ( !it.next().getName().equals( "B" ) ) {
5822                 return false;
5823             }
5824             if ( !it.next().getName().equals( "C" ) ) {
5825                 return false;
5826             }
5827             if ( !it.next().getName().equals( "D" ) ) {
5828                 return false;
5829             }
5830             if ( it.hasNext() ) {
5831                 return false;
5832             }
5833             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",
5834                                                  new NHXParser() )[ 0 ];
5835             PhylogenyNodeIterator it2;
5836             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
5837                 it2.next();
5838             }
5839             for( it2.reset(); it2.hasNext(); ) {
5840                 it2.next();
5841             }
5842             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
5843             if ( !it3.next().getName().equals( "r" ) ) {
5844                 return false;
5845             }
5846             if ( !it3.next().getName().equals( "abc" ) ) {
5847                 return false;
5848             }
5849             if ( !it3.next().getName().equals( "defg" ) ) {
5850                 return false;
5851             }
5852             if ( !it3.next().getName().equals( "A" ) ) {
5853                 return false;
5854             }
5855             if ( !it3.next().getName().equals( "B" ) ) {
5856                 return false;
5857             }
5858             if ( !it3.next().getName().equals( "C" ) ) {
5859                 return false;
5860             }
5861             if ( !it3.next().getName().equals( "D" ) ) {
5862                 return false;
5863             }
5864             if ( !it3.next().getName().equals( "E" ) ) {
5865                 return false;
5866             }
5867             if ( !it3.next().getName().equals( "F" ) ) {
5868                 return false;
5869             }
5870             if ( !it3.next().getName().equals( "G" ) ) {
5871                 return false;
5872             }
5873             if ( !it3.next().getName().equals( "1" ) ) {
5874                 return false;
5875             }
5876             if ( !it3.next().getName().equals( "2" ) ) {
5877                 return false;
5878             }
5879             if ( !it3.next().getName().equals( "3" ) ) {
5880                 return false;
5881             }
5882             if ( !it3.next().getName().equals( "4" ) ) {
5883                 return false;
5884             }
5885             if ( !it3.next().getName().equals( "5" ) ) {
5886                 return false;
5887             }
5888             if ( !it3.next().getName().equals( "6" ) ) {
5889                 return false;
5890             }
5891             if ( !it3.next().getName().equals( "f1" ) ) {
5892                 return false;
5893             }
5894             if ( !it3.next().getName().equals( "f2" ) ) {
5895                 return false;
5896             }
5897             if ( !it3.next().getName().equals( "f3" ) ) {
5898                 return false;
5899             }
5900             if ( !it3.next().getName().equals( "a" ) ) {
5901                 return false;
5902             }
5903             if ( !it3.next().getName().equals( "b" ) ) {
5904                 return false;
5905             }
5906             if ( !it3.next().getName().equals( "f21" ) ) {
5907                 return false;
5908             }
5909             if ( !it3.next().getName().equals( "X" ) ) {
5910                 return false;
5911             }
5912             if ( !it3.next().getName().equals( "Y" ) ) {
5913                 return false;
5914             }
5915             if ( !it3.next().getName().equals( "Z" ) ) {
5916                 return false;
5917             }
5918             if ( it3.hasNext() ) {
5919                 return false;
5920             }
5921             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
5922             PhylogenyNodeIterator it4;
5923             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
5924                 it4.next();
5925             }
5926             for( it4.reset(); it4.hasNext(); ) {
5927                 it4.next();
5928             }
5929             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
5930             if ( !it5.next().getName().equals( "r" ) ) {
5931                 return false;
5932             }
5933             if ( !it5.next().getName().equals( "A" ) ) {
5934                 return false;
5935             }
5936             if ( !it5.next().getName().equals( "B" ) ) {
5937                 return false;
5938             }
5939             if ( !it5.next().getName().equals( "C" ) ) {
5940                 return false;
5941             }
5942             if ( !it5.next().getName().equals( "D" ) ) {
5943                 return false;
5944             }
5945             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
5946             PhylogenyNodeIterator it6;
5947             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
5948                 it6.next();
5949             }
5950             for( it6.reset(); it6.hasNext(); ) {
5951                 it6.next();
5952             }
5953             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
5954             if ( !it7.next().getName().equals( "A" ) ) {
5955                 return false;
5956             }
5957             if ( it.hasNext() ) {
5958                 return false;
5959             }
5960         }
5961         catch ( final Exception e ) {
5962             e.printStackTrace( System.out );
5963             return false;
5964         }
5965         return true;
5966     }
5967
5968     private static boolean testMafft( final String path ) {
5969         try {
5970             final List<String> opts = new ArrayList<String>();
5971             opts.add( "--maxiterate" );
5972             opts.add( "1000" );
5973             opts.add( "--localpair" );
5974             opts.add( "--quiet" );
5975             Msa msa = null;
5976             final MsaInferrer mafft = Mafft.createInstance( path );
5977             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
5978             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
5979                 return false;
5980             }
5981             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
5982                 return false;
5983             }
5984         }
5985         catch ( final Exception e ) {
5986             e.printStackTrace( System.out );
5987             return false;
5988         }
5989         return true;
5990     }
5991
5992     private static boolean testMidpointrooting() {
5993         try {
5994             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5995             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
5996             PhylogenyMethods.midpointRoot( t0 );
5997             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
5998                 return false;
5999             }
6000             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
6001                 return false;
6002             }
6003             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
6004                            1 ) ) {
6005                 return false;
6006             }
6007             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",
6008                                                  new NHXParser() )[ 0 ];
6009             if ( !t1.isRooted() ) {
6010                 return false;
6011             }
6012             PhylogenyMethods.midpointRoot( t1 );
6013             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6014                 return false;
6015             }
6016             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6017                 return false;
6018             }
6019             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6020                 return false;
6021             }
6022             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6023                 return false;
6024             }
6025             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6026                 return false;
6027             }
6028             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6029                 return false;
6030             }
6031             t1.reRoot( t1.getNode( "A" ) );
6032             PhylogenyMethods.midpointRoot( t1 );
6033             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6034                 return false;
6035             }
6036             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6037                 return false;
6038             }
6039             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6040                 return false;
6041             }
6042             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6043                 return false;
6044             }
6045             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6046                 System.exit( -1 );
6047                 return false;
6048             }
6049             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6050                 return false;
6051             }
6052         }
6053         catch ( final Exception e ) {
6054             e.printStackTrace( System.out );
6055             return false;
6056         }
6057         return true;
6058     }
6059
6060     private static boolean testMsaQualityMethod() {
6061         try {
6062             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6063             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6064             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6065             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6066             final List<Sequence> l = new ArrayList<Sequence>();
6067             l.add( s0 );
6068             l.add( s1 );
6069             l.add( s2 );
6070             l.add( s3 );
6071             final Msa msa = BasicMsa.createInstance( l );
6072             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6073                 return false;
6074             }
6075             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6076                 return false;
6077             }
6078             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6079                 return false;
6080             }
6081             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6082                 return false;
6083             }
6084             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6085                 return false;
6086             }
6087             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6088                 return false;
6089             }
6090             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6091                 return false;
6092             }
6093         }
6094         catch ( final Exception e ) {
6095             e.printStackTrace( System.out );
6096             return false;
6097         }
6098         return true;
6099     }
6100
6101     private static boolean testMsaEntropy() {
6102         try {
6103             final Sequence s0 = BasicSequence.createAaSequence( "a", "AAAAAAA" );
6104             final Sequence s1 = BasicSequence.createAaSequence( "b", "AAAIACC" );
6105             final Sequence s2 = BasicSequence.createAaSequence( "c", "AAIIIIF" );
6106             final Sequence s3 = BasicSequence.createAaSequence( "d", "AIIIVVW" );
6107             final List<Sequence> l = new ArrayList<Sequence>();
6108             l.add( s0 );
6109             l.add( s1 );
6110             l.add( s2 );
6111             l.add( s3 );
6112             final Msa msa = BasicMsa.createInstance( l );
6113             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 0 ) );
6114             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 1 ) );
6115             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 2 ) );
6116             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 3 ) );
6117             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 4 ) );
6118             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 5 ) );
6119             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 6 ) );
6120             System.out.println();
6121             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 0 ) );
6122             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 1 ) );
6123             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 2 ) );
6124             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 3 ) );
6125             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 4 ) );
6126             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 5 ) );
6127             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 6 ) );
6128             final List<Sequence> l2 = new ArrayList<Sequence>();
6129             l2.add( BasicSequence.createAaSequence( "1", "AAAAAAA" ) );
6130             l2.add( BasicSequence.createAaSequence( "2", "AAAIACC" ) );
6131             l2.add( BasicSequence.createAaSequence( "3", "AAIIIIF" ) );
6132             l2.add( BasicSequence.createAaSequence( "4", "AIIIVVW" ) );
6133             l2.add( BasicSequence.createAaSequence( "5", "AAAAAAA" ) );
6134             l2.add( BasicSequence.createAaSequence( "6", "AAAIACC" ) );
6135             l2.add( BasicSequence.createAaSequence( "7", "AAIIIIF" ) );
6136             l2.add( BasicSequence.createAaSequence( "8", "AIIIVVW" ) );
6137             l2.add( BasicSequence.createAaSequence( "9", "AAAAAAA" ) );
6138             l2.add( BasicSequence.createAaSequence( "10", "AAAIACC" ) );
6139             l2.add( BasicSequence.createAaSequence( "11", "AAIIIIF" ) );
6140             l2.add( BasicSequence.createAaSequence( "12", "AIIIVVW" ) );
6141             l2.add( BasicSequence.createAaSequence( "13", "AAIIIIF" ) );
6142             l2.add( BasicSequence.createAaSequence( "14", "AIIIVVW" ) );
6143             l2.add( BasicSequence.createAaSequence( "15", "AAAAAAA" ) );
6144             l2.add( BasicSequence.createAaSequence( "16", "AAAIACC" ) );
6145             l2.add( BasicSequence.createAaSequence( "17", "AAIIIIF" ) );
6146             l2.add( BasicSequence.createAaSequence( "18", "AIIIVVW" ) );
6147             l2.add( BasicSequence.createAaSequence( "19", "AAAAAAA" ) );
6148             l2.add( BasicSequence.createAaSequence( "20", "AAAIACC" ) );
6149             l2.add( BasicSequence.createAaSequence( "21", "AAIIIIF" ) );
6150             l2.add( BasicSequence.createAaSequence( "22", "AIIIVVW" ) );
6151             final Msa msa2 = BasicMsa.createInstance( l2 );
6152             System.out.println();
6153             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 0 ) );
6154             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 1 ) );
6155             System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 2 ) );
6156         }
6157         catch ( final Exception e ) {
6158             e.printStackTrace( System.out );
6159             return false;
6160         }
6161         return true;
6162     }
6163
6164     private static boolean testDeleteableMsa() {
6165         try {
6166             final Sequence s0 = BasicSequence.createAaSequence( "a", "AAAA" );
6167             final Sequence s1 = BasicSequence.createAaSequence( "b", "BAAA" );
6168             final Sequence s2 = BasicSequence.createAaSequence( "c", "CAAA" );
6169             final Sequence s3 = BasicSequence.createAaSequence( "d", "DAAA" );
6170             final Sequence s4 = BasicSequence.createAaSequence( "e", "EAAA" );
6171             final Sequence s5 = BasicSequence.createAaSequence( "f", "FAAA" );
6172             final List<Sequence> l0 = new ArrayList<Sequence>();
6173             l0.add( s0 );
6174             l0.add( s1 );
6175             l0.add( s2 );
6176             l0.add( s3 );
6177             l0.add( s4 );
6178             l0.add( s5 );
6179             final DeleteableMsa dmsa0 = DeleteableMsa.createInstance( l0 );
6180             dmsa0.deleteRow( "b", false );
6181             if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) {
6182                 return false;
6183             }
6184             dmsa0.deleteRow( "e", false );
6185             dmsa0.deleteRow( "a", false );
6186             dmsa0.deleteRow( "f", false );
6187             if ( dmsa0.getLength() != 4 ) {
6188                 return false;
6189             }
6190             if ( dmsa0.getNumberOfSequences() != 2 ) {
6191                 return false;
6192             }
6193             if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) {
6194                 return false;
6195             }
6196             if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) {
6197                 return false;
6198             }
6199             if ( dmsa0.getResidueAt( 0, 0 ) != 'C' ) {
6200                 return false;
6201             }
6202             if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" ) ) {
6203                 return false;
6204             }
6205             if ( dmsa0.getColumnAt( 0 ).size() != 2 ) {
6206                 return false;
6207             }
6208             dmsa0.deleteRow( "c", false );
6209             dmsa0.deleteRow( "d", false );
6210             if ( dmsa0.getNumberOfSequences() != 0 ) {
6211                 return false;
6212             }
6213             //
6214             final Sequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C--X----" );
6215             final Sequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C-------" );
6216             final Sequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C------Z" );
6217             final Sequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C-------" );
6218             final Sequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C-------" );
6219             final Sequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--Y---" );
6220             final List<Sequence> l1 = new ArrayList<Sequence>();
6221             l1.add( s_0 );
6222             l1.add( s_1 );
6223             l1.add( s_2 );
6224             l1.add( s_3 );
6225             l1.add( s_4 );
6226             l1.add( s_5 );
6227             final DeleteableMsa dmsa1 = DeleteableMsa.createInstance( l1 );
6228             dmsa1.deleteGapOnlyColumns();
6229             dmsa1.deleteRow( "a", false );
6230             dmsa1.deleteRow( "f", false );
6231             dmsa1.deleteRow( "d", false );
6232             dmsa1.deleteGapOnlyColumns();
6233             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C-" ) ) {
6234                 return false;
6235             }
6236             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "CABCZ" ) ) {
6237                 return false;
6238             }
6239             if ( !dmsa1.getSequenceAsString( 2 ).toString().equals( "EAAC-" ) ) {
6240                 return false;
6241             }
6242             dmsa1.deleteRow( "c", false );
6243             dmsa1.deleteGapOnlyColumns();
6244             final Writer w0 = new StringWriter();
6245             dmsa1.write( w0, MSA_FORMAT.FASTA );
6246             final Writer w1 = new StringWriter();
6247             dmsa1.write( w1, MSA_FORMAT.PHYLIP );
6248             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C" ) ) {
6249                 return false;
6250             }
6251             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "EAAC" ) ) {
6252                 return false;
6253             }
6254             //
6255             final Sequence s__0 = BasicSequence.createAaSequence( "a", "A------" );
6256             final Sequence s__1 = BasicSequence.createAaSequence( "b", "BB-----" );
6257             final Sequence s__2 = BasicSequence.createAaSequence( "c", "CCC----" );
6258             final Sequence s__3 = BasicSequence.createAaSequence( "d", "DDDD---" );
6259             final Sequence s__4 = BasicSequence.createAaSequence( "e", "EEEEE--" );
6260             final Sequence s__5 = BasicSequence.createAaSequence( "f", "FFFFFF-" );
6261             final List<Sequence> l2 = new ArrayList<Sequence>();
6262             l2.add( s__0 );
6263             l2.add( s__1 );
6264             l2.add( s__2 );
6265             l2.add( s__3 );
6266             l2.add( s__4 );
6267             l2.add( s__5 );
6268             final DeleteableMsa dmsa2 = DeleteableMsa.createInstance( l2 );
6269             dmsa2.deleteGapColumns( 0.5 );
6270             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A---" ) ) {
6271                 return false;
6272             }
6273             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB--" ) ) {
6274                 return false;
6275             }
6276             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CCC-" ) ) {
6277                 return false;
6278             }
6279             dmsa2.deleteGapColumns( 0.2 );
6280             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A-" ) ) {
6281                 return false;
6282             }
6283             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB" ) ) {
6284                 return false;
6285             }
6286             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CC" ) ) {
6287                 return false;
6288             }
6289             dmsa2.deleteGapColumns( 0 );
6290             dmsa2.deleteRow( "a", false );
6291             dmsa2.deleteRow( "b", false );
6292             dmsa2.deleteRow( "f", false );
6293             dmsa2.deleteRow( "e", false );
6294             dmsa2.setIdentifier( 0, "new_c" );
6295             dmsa2.setIdentifier( 1, "new_d" );
6296             dmsa2.setResidueAt( 0, 0, 'x' );
6297             final Sequence s = dmsa2.deleteRow( "new_d", true );
6298             if ( !s.getMolecularSequenceAsString().equals( "D" ) ) {
6299                 return false;
6300             }
6301             final Writer w = new StringWriter();
6302             dmsa2.write( w, MSA_FORMAT.PHYLIP );
6303             final String phylip = w.toString();
6304             if ( !phylip.equals( "new_c x" + ForesterUtil.LINE_SEPARATOR ) ) {
6305                 return false;
6306             }
6307             final Writer w2 = new StringWriter();
6308             dmsa2.write( w2, MSA_FORMAT.FASTA );
6309             final String fasta = w2.toString();
6310             if ( !fasta.equals( ">new_c" + ForesterUtil.LINE_SEPARATOR + "x" + ForesterUtil.LINE_SEPARATOR ) ) {
6311                 return false;
6312             }
6313         }
6314         catch ( final Exception e ) {
6315             e.printStackTrace( System.out );
6316             return false;
6317         }
6318         return true;
6319     }
6320
6321     private static boolean testNextNodeWithCollapsing() {
6322         try {
6323             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6324             PhylogenyNode n;
6325             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
6326             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6327             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
6328             t0.getNode( "cd" ).setCollapse( true );
6329             t0.getNode( "cde" ).setCollapse( true );
6330             n = t0.getFirstExternalNode();
6331             while ( n != null ) {
6332                 ext.add( n );
6333                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6334             }
6335             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6336                 return false;
6337             }
6338             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6339                 return false;
6340             }
6341             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
6342                 return false;
6343             }
6344             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
6345                 return false;
6346             }
6347             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
6348                 return false;
6349             }
6350             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
6351                 return false;
6352             }
6353             ext.clear();
6354             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6355             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
6356             t1.getNode( "ab" ).setCollapse( true );
6357             t1.getNode( "cd" ).setCollapse( true );
6358             t1.getNode( "cde" ).setCollapse( true );
6359             n = t1.getNode( "ab" );
6360             ext = new ArrayList<PhylogenyNode>();
6361             while ( n != null ) {
6362                 ext.add( n );
6363                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6364             }
6365             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6366                 return false;
6367             }
6368             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6369                 return false;
6370             }
6371             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6372                 return false;
6373             }
6374             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
6375                 return false;
6376             }
6377             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
6378                 return false;
6379             }
6380             //
6381             //
6382             ext.clear();
6383             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6384             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
6385             t2.getNode( "ab" ).setCollapse( true );
6386             t2.getNode( "cd" ).setCollapse( true );
6387             t2.getNode( "cde" ).setCollapse( true );
6388             t2.getNode( "c" ).setCollapse( true );
6389             t2.getNode( "d" ).setCollapse( true );
6390             t2.getNode( "e" ).setCollapse( true );
6391             t2.getNode( "gh" ).setCollapse( true );
6392             n = t2.getNode( "ab" );
6393             ext = new ArrayList<PhylogenyNode>();
6394             while ( n != null ) {
6395                 ext.add( n );
6396                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6397             }
6398             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6399                 return false;
6400             }
6401             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6402                 return false;
6403             }
6404             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6405                 return false;
6406             }
6407             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
6408                 return false;
6409             }
6410             //
6411             //
6412             ext.clear();
6413             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6414             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
6415             t3.getNode( "ab" ).setCollapse( true );
6416             t3.getNode( "cd" ).setCollapse( true );
6417             t3.getNode( "cde" ).setCollapse( true );
6418             t3.getNode( "c" ).setCollapse( true );
6419             t3.getNode( "d" ).setCollapse( true );
6420             t3.getNode( "e" ).setCollapse( true );
6421             t3.getNode( "gh" ).setCollapse( true );
6422             t3.getNode( "fgh" ).setCollapse( true );
6423             n = t3.getNode( "ab" );
6424             ext = new ArrayList<PhylogenyNode>();
6425             while ( n != null ) {
6426                 ext.add( n );
6427                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6428             }
6429             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6430                 return false;
6431             }
6432             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6433                 return false;
6434             }
6435             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
6436                 return false;
6437             }
6438             //
6439             //
6440             ext.clear();
6441             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6442             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
6443             t4.getNode( "ab" ).setCollapse( true );
6444             t4.getNode( "cd" ).setCollapse( true );
6445             t4.getNode( "cde" ).setCollapse( true );
6446             t4.getNode( "c" ).setCollapse( true );
6447             t4.getNode( "d" ).setCollapse( true );
6448             t4.getNode( "e" ).setCollapse( true );
6449             t4.getNode( "gh" ).setCollapse( true );
6450             t4.getNode( "fgh" ).setCollapse( true );
6451             t4.getNode( "abcdefgh" ).setCollapse( true );
6452             n = t4.getNode( "abcdefgh" );
6453             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
6454                 return false;
6455             }
6456             //
6457             //
6458             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6459             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
6460             ext.clear();
6461             n = t5.getFirstExternalNode();
6462             while ( n != null ) {
6463                 ext.add( n );
6464                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6465             }
6466             if ( ext.size() != 8 ) {
6467                 return false;
6468             }
6469             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6470                 return false;
6471             }
6472             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6473                 return false;
6474             }
6475             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6476                 return false;
6477             }
6478             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6479                 return false;
6480             }
6481             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6482                 return false;
6483             }
6484             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6485                 return false;
6486             }
6487             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
6488                 return false;
6489             }
6490             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
6491                 return false;
6492             }
6493             //
6494             //
6495             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6496             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
6497             ext.clear();
6498             t6.getNode( "ab" ).setCollapse( true );
6499             n = t6.getNode( "ab" );
6500             while ( n != null ) {
6501                 ext.add( n );
6502                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6503             }
6504             if ( ext.size() != 7 ) {
6505                 return false;
6506             }
6507             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6508                 return false;
6509             }
6510             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6511                 return false;
6512             }
6513             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6514                 return false;
6515             }
6516             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6517                 return false;
6518             }
6519             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6520                 return false;
6521             }
6522             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6523                 return false;
6524             }
6525             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6526                 return false;
6527             }
6528             //
6529             //
6530             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6531             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
6532             ext.clear();
6533             t7.getNode( "cd" ).setCollapse( true );
6534             n = t7.getNode( "a" );
6535             while ( n != null ) {
6536                 ext.add( n );
6537                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6538             }
6539             if ( ext.size() != 7 ) {
6540                 return false;
6541             }
6542             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6543                 return false;
6544             }
6545             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6546                 return false;
6547             }
6548             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6549                 return false;
6550             }
6551             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6552                 return false;
6553             }
6554             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6555                 return false;
6556             }
6557             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6558                 return false;
6559             }
6560             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6561                 return false;
6562             }
6563             //
6564             //
6565             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6566             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
6567             ext.clear();
6568             t8.getNode( "cd" ).setCollapse( true );
6569             t8.getNode( "c" ).setCollapse( true );
6570             t8.getNode( "d" ).setCollapse( true );
6571             n = t8.getNode( "a" );
6572             while ( n != null ) {
6573                 ext.add( n );
6574                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6575             }
6576             if ( ext.size() != 7 ) {
6577                 return false;
6578             }
6579             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6580                 return false;
6581             }
6582             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6583                 return false;
6584             }
6585             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6586                 System.out.println( "2 fail" );
6587                 return false;
6588             }
6589             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6590                 return false;
6591             }
6592             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6593                 return false;
6594             }
6595             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6596                 return false;
6597             }
6598             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6599                 return false;
6600             }
6601             //
6602             //
6603             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6604             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
6605             ext.clear();
6606             t9.getNode( "gh" ).setCollapse( true );
6607             n = t9.getNode( "a" );
6608             while ( n != null ) {
6609                 ext.add( n );
6610                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6611             }
6612             if ( ext.size() != 7 ) {
6613                 return false;
6614             }
6615             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6616                 return false;
6617             }
6618             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6619                 return false;
6620             }
6621             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6622                 return false;
6623             }
6624             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6625                 return false;
6626             }
6627             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6628                 return false;
6629             }
6630             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6631                 return false;
6632             }
6633             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6634                 return false;
6635             }
6636             //
6637             //
6638             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6639             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
6640             ext.clear();
6641             t10.getNode( "gh" ).setCollapse( true );
6642             t10.getNode( "g" ).setCollapse( true );
6643             t10.getNode( "h" ).setCollapse( true );
6644             n = t10.getNode( "a" );
6645             while ( n != null ) {
6646                 ext.add( n );
6647                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6648             }
6649             if ( ext.size() != 7 ) {
6650                 return false;
6651             }
6652             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6653                 return false;
6654             }
6655             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6656                 return false;
6657             }
6658             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6659                 return false;
6660             }
6661             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6662                 return false;
6663             }
6664             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6665                 return false;
6666             }
6667             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6668                 return false;
6669             }
6670             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6671                 return false;
6672             }
6673             //
6674             //
6675             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6676             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
6677             ext.clear();
6678             t11.getNode( "gh" ).setCollapse( true );
6679             t11.getNode( "fgh" ).setCollapse( true );
6680             n = t11.getNode( "a" );
6681             while ( n != null ) {
6682                 ext.add( n );
6683                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6684             }
6685             if ( ext.size() != 6 ) {
6686                 return false;
6687             }
6688             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6689                 return false;
6690             }
6691             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6692                 return false;
6693             }
6694             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6695                 return false;
6696             }
6697             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6698                 return false;
6699             }
6700             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6701                 return false;
6702             }
6703             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6704                 return false;
6705             }
6706             //
6707             //
6708             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6709             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
6710             ext.clear();
6711             t12.getNode( "gh" ).setCollapse( true );
6712             t12.getNode( "fgh" ).setCollapse( true );
6713             t12.getNode( "g" ).setCollapse( true );
6714             t12.getNode( "h" ).setCollapse( true );
6715             t12.getNode( "f" ).setCollapse( true );
6716             n = t12.getNode( "a" );
6717             while ( n != null ) {
6718                 ext.add( n );
6719                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6720             }
6721             if ( ext.size() != 6 ) {
6722                 return false;
6723             }
6724             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6725                 return false;
6726             }
6727             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6728                 return false;
6729             }
6730             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6731                 return false;
6732             }
6733             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6734                 return false;
6735             }
6736             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6737                 return false;
6738             }
6739             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6740                 return false;
6741             }
6742             //
6743             //
6744             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6745             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
6746             ext.clear();
6747             t13.getNode( "ab" ).setCollapse( true );
6748             t13.getNode( "b" ).setCollapse( true );
6749             t13.getNode( "fgh" ).setCollapse( true );
6750             t13.getNode( "gh" ).setCollapse( true );
6751             n = t13.getNode( "ab" );
6752             while ( n != null ) {
6753                 ext.add( n );
6754                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6755             }
6756             if ( ext.size() != 5 ) {
6757                 return false;
6758             }
6759             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6760                 return false;
6761             }
6762             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6763                 return false;
6764             }
6765             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6766                 return false;
6767             }
6768             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6769                 return false;
6770             }
6771             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6772                 return false;
6773             }
6774             //
6775             //
6776             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
6777             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
6778             ext.clear();
6779             t14.getNode( "ab" ).setCollapse( true );
6780             t14.getNode( "a" ).setCollapse( true );
6781             t14.getNode( "fgh" ).setCollapse( true );
6782             t14.getNode( "gh" ).setCollapse( true );
6783             n = t14.getNode( "ab" );
6784             while ( n != null ) {
6785                 ext.add( n );
6786                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6787             }
6788             if ( ext.size() != 5 ) {
6789                 return false;
6790             }
6791             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6792                 return false;
6793             }
6794             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6795                 return false;
6796             }
6797             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6798                 return false;
6799             }
6800             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6801                 return false;
6802             }
6803             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6804                 return false;
6805             }
6806             //
6807             //
6808             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" );
6809             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
6810             ext.clear();
6811             t15.getNode( "ab" ).setCollapse( true );
6812             t15.getNode( "a" ).setCollapse( true );
6813             t15.getNode( "fgh" ).setCollapse( true );
6814             t15.getNode( "gh" ).setCollapse( true );
6815             n = t15.getNode( "ab" );
6816             while ( n != null ) {
6817                 ext.add( n );
6818                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6819             }
6820             if ( ext.size() != 6 ) {
6821                 return false;
6822             }
6823             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6824                 return false;
6825             }
6826             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6827                 return false;
6828             }
6829             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6830                 return false;
6831             }
6832             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6833                 return false;
6834             }
6835             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
6836                 return false;
6837             }
6838             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6839                 return false;
6840             }
6841             //
6842             //
6843             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" );
6844             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
6845             ext.clear();
6846             t16.getNode( "ab" ).setCollapse( true );
6847             t16.getNode( "a" ).setCollapse( true );
6848             t16.getNode( "fgh" ).setCollapse( true );
6849             t16.getNode( "gh" ).setCollapse( true );
6850             t16.getNode( "cd" ).setCollapse( true );
6851             t16.getNode( "cde" ).setCollapse( true );
6852             t16.getNode( "d" ).setCollapse( true );
6853             t16.getNode( "x" ).setCollapse( true );
6854             n = t16.getNode( "ab" );
6855             while ( n != null ) {
6856                 ext.add( n );
6857                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6858             }
6859             if ( ext.size() != 4 ) {
6860                 return false;
6861             }
6862             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6863                 return false;
6864             }
6865             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6866                 return false;
6867             }
6868             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
6869                 return false;
6870             }
6871             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
6872                 return false;
6873             }
6874         }
6875         catch ( final Exception e ) {
6876             e.printStackTrace( System.out );
6877             return false;
6878         }
6879         return true;
6880     }
6881
6882     private static boolean testNexusCharactersParsing() {
6883         try {
6884             final NexusCharactersParser parser = new NexusCharactersParser();
6885             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
6886             parser.parse();
6887             String[] labels = parser.getCharStateLabels();
6888             if ( labels.length != 7 ) {
6889                 return false;
6890             }
6891             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6892                 return false;
6893             }
6894             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6895                 return false;
6896             }
6897             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6898                 return false;
6899             }
6900             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6901                 return false;
6902             }
6903             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6904                 return false;
6905             }
6906             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6907                 return false;
6908             }
6909             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6910                 return false;
6911             }
6912             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6913             parser.parse();
6914             labels = parser.getCharStateLabels();
6915             if ( labels.length != 7 ) {
6916                 return false;
6917             }
6918             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6919                 return false;
6920             }
6921             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6922                 return false;
6923             }
6924             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6925                 return false;
6926             }
6927             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6928                 return false;
6929             }
6930             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6931                 return false;
6932             }
6933             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6934                 return false;
6935             }
6936             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6937                 return false;
6938             }
6939         }
6940         catch ( final Exception e ) {
6941             e.printStackTrace( System.out );
6942             return false;
6943         }
6944         return true;
6945     }
6946
6947     private static boolean testNexusMatrixParsing() {
6948         try {
6949             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
6950             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
6951             parser.parse();
6952             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
6953             if ( m.getNumberOfCharacters() != 9 ) {
6954                 return false;
6955             }
6956             if ( m.getNumberOfIdentifiers() != 5 ) {
6957                 return false;
6958             }
6959             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
6960                 return false;
6961             }
6962             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
6963                 return false;
6964             }
6965             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
6966                 return false;
6967             }
6968             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
6969                 return false;
6970             }
6971             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
6972                 return false;
6973             }
6974             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
6975                 return false;
6976             }
6977             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
6978                 return false;
6979             }
6980             //            if ( labels.length != 7 ) {
6981             //                return false;
6982             //            }
6983             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6984             //                return false;
6985             //            }
6986             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6987             //                return false;
6988             //            }
6989             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6990             //                return false;
6991             //            }
6992             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6993             //                return false;
6994             //            }
6995             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6996             //                return false;
6997             //            }
6998             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6999             //                return false;
7000             //            }
7001             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7002             //                return false;
7003             //            }
7004             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7005             //            parser.parse();
7006             //            labels = parser.getCharStateLabels();
7007             //            if ( labels.length != 7 ) {
7008             //                return false;
7009             //            }
7010             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7011             //                return false;
7012             //            }
7013             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7014             //                return false;
7015             //            }
7016             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7017             //                return false;
7018             //            }
7019             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7020             //                return false;
7021             //            }
7022             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7023             //                return false;
7024             //            }
7025             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7026             //                return false;
7027             //            }
7028             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7029             //                return false;
7030             //            }
7031         }
7032         catch ( final Exception e ) {
7033             e.printStackTrace( System.out );
7034             return false;
7035         }
7036         return true;
7037     }
7038
7039     private static boolean testNexusTreeParsing() {
7040         try {
7041             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7042             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7043             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
7044             if ( phylogenies.length != 1 ) {
7045                 return false;
7046             }
7047             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
7048                 return false;
7049             }
7050             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7051                 return false;
7052             }
7053             phylogenies = null;
7054             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
7055             if ( phylogenies.length != 1 ) {
7056                 return false;
7057             }
7058             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7059                 return false;
7060             }
7061             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
7062                 return false;
7063             }
7064             phylogenies = null;
7065             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
7066             if ( phylogenies.length != 1 ) {
7067                 return false;
7068             }
7069             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7070                 return false;
7071             }
7072             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7073                 return false;
7074             }
7075             if ( phylogenies[ 0 ].isRooted() ) {
7076                 return false;
7077             }
7078             phylogenies = null;
7079             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
7080             if ( phylogenies.length != 18 ) {
7081                 return false;
7082             }
7083             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7084                 return false;
7085             }
7086             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
7087                 return false;
7088             }
7089             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
7090                 return false;
7091             }
7092             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
7093                 return false;
7094             }
7095             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7096                 return false;
7097             }
7098             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
7099                 return false;
7100             }
7101             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
7102                 return false;
7103             }
7104             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
7105                 return false;
7106             }
7107             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
7108                 return false;
7109             }
7110             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
7111                 return false;
7112             }
7113             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
7114                 return false;
7115             }
7116             if ( phylogenies[ 8 ].isRooted() ) {
7117                 return false;
7118             }
7119             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
7120                 return false;
7121             }
7122             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
7123                 return false;
7124             }
7125             if ( !phylogenies[ 9 ].isRooted() ) {
7126                 return false;
7127             }
7128             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
7129                 return false;
7130             }
7131             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
7132                 return false;
7133             }
7134             if ( !phylogenies[ 10 ].isRooted() ) {
7135                 return false;
7136             }
7137             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
7138                 return false;
7139             }
7140             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
7141                 return false;
7142             }
7143             if ( phylogenies[ 11 ].isRooted() ) {
7144                 return false;
7145             }
7146             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
7147                 return false;
7148             }
7149             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
7150                 return false;
7151             }
7152             if ( !phylogenies[ 12 ].isRooted() ) {
7153                 return false;
7154             }
7155             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
7156                 return false;
7157             }
7158             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
7159                 return false;
7160             }
7161             if ( !phylogenies[ 13 ].isRooted() ) {
7162                 return false;
7163             }
7164             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
7165                 return false;
7166             }
7167             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
7168                 return false;
7169             }
7170             if ( !phylogenies[ 14 ].isRooted() ) {
7171                 return false;
7172             }
7173             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
7174                 return false;
7175             }
7176             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
7177                 return false;
7178             }
7179             if ( phylogenies[ 15 ].isRooted() ) {
7180                 return false;
7181             }
7182             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
7183                 return false;
7184             }
7185             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
7186                 return false;
7187             }
7188             if ( !phylogenies[ 16 ].isRooted() ) {
7189                 return false;
7190             }
7191             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
7192                 return false;
7193             }
7194             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
7195                 return false;
7196             }
7197             if ( phylogenies[ 17 ].isRooted() ) {
7198                 return false;
7199             }
7200             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
7201                 return false;
7202             }
7203             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7204             phylogenies = null;
7205             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
7206             if ( phylogenies.length != 9 ) {
7207                 return false;
7208             }
7209             if ( !isEqual( 0.48039661496919533, phylogenies[ 0 ].getNode( "Diadocidia_spinosula" )
7210                     .getDistanceToParent() ) ) {
7211                 return false;
7212             }
7213             if ( !isEqual( 0.3959796191512233, phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" )
7214                     .getDistanceToParent() ) ) {
7215                 return false;
7216             }
7217             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
7218                 return false;
7219             }
7220             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7221                 return false;
7222             }
7223             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7224                 return false;
7225             }
7226             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7227                 return false;
7228             }
7229             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7230                 return false;
7231             }
7232         }
7233         catch ( final Exception e ) {
7234             e.printStackTrace( System.out );
7235             return false;
7236         }
7237         return true;
7238     }
7239
7240     private static boolean testNexusTreeParsingIterating() {
7241         try {
7242             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
7243             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
7244             if ( !p.hasNext() ) {
7245                 return false;
7246             }
7247             Phylogeny phy = p.next();
7248             if ( phy == null ) {
7249                 return false;
7250             }
7251             if ( phy.getNumberOfExternalNodes() != 25 ) {
7252                 return false;
7253             }
7254             if ( !phy.getName().equals( "" ) ) {
7255                 return false;
7256             }
7257             if ( p.hasNext() ) {
7258                 return false;
7259             }
7260             phy = p.next();
7261             if ( phy != null ) {
7262                 return false;
7263             }
7264             //
7265             p.reset();
7266             if ( !p.hasNext() ) {
7267                 return false;
7268             }
7269             phy = p.next();
7270             if ( phy == null ) {
7271                 return false;
7272             }
7273             if ( phy.getNumberOfExternalNodes() != 25 ) {
7274                 return false;
7275             }
7276             if ( !phy.getName().equals( "" ) ) {
7277                 return false;
7278             }
7279             if ( p.hasNext() ) {
7280                 return false;
7281             }
7282             phy = p.next();
7283             if ( phy != null ) {
7284                 return false;
7285             }
7286             ////
7287             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
7288             if ( !p.hasNext() ) {
7289                 return false;
7290             }
7291             phy = p.next();
7292             if ( phy == null ) {
7293                 return false;
7294             }
7295             if ( phy.getNumberOfExternalNodes() != 10 ) {
7296                 return false;
7297             }
7298             if ( !phy.getName().equals( "name" ) ) {
7299                 return false;
7300             }
7301             if ( p.hasNext() ) {
7302                 return false;
7303             }
7304             phy = p.next();
7305             if ( phy != null ) {
7306                 return false;
7307             }
7308             //
7309             p.reset();
7310             if ( !p.hasNext() ) {
7311                 return false;
7312             }
7313             phy = p.next();
7314             if ( phy == null ) {
7315                 return false;
7316             }
7317             if ( phy.getNumberOfExternalNodes() != 10 ) {
7318                 return false;
7319             }
7320             if ( !phy.getName().equals( "name" ) ) {
7321                 return false;
7322             }
7323             if ( p.hasNext() ) {
7324                 return false;
7325             }
7326             phy = p.next();
7327             if ( phy != null ) {
7328                 return false;
7329             }
7330             //
7331             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
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                 return false;
7341             }
7342             if ( !phy.getName().equals( "" ) ) {
7343                 return false;
7344             }
7345             if ( phy.isRooted() ) {
7346                 return false;
7347             }
7348             if ( p.hasNext() ) {
7349                 return false;
7350             }
7351             phy = p.next();
7352             if ( phy != null ) {
7353                 return false;
7354             }
7355             //
7356             p.reset();
7357             if ( !p.hasNext() ) {
7358                 return false;
7359             }
7360             phy = p.next();
7361             if ( phy == null ) {
7362                 return false;
7363             }
7364             if ( phy.getNumberOfExternalNodes() != 3 ) {
7365                 return false;
7366             }
7367             if ( !phy.getName().equals( "" ) ) {
7368                 return false;
7369             }
7370             if ( p.hasNext() ) {
7371                 return false;
7372             }
7373             phy = p.next();
7374             if ( phy != null ) {
7375                 return false;
7376             }
7377             //
7378             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
7379             if ( !p.hasNext() ) {
7380                 return false;
7381             }
7382             //0
7383             phy = p.next();
7384             if ( phy == null ) {
7385                 return false;
7386             }
7387             if ( phy.getNumberOfExternalNodes() != 10 ) {
7388                 return false;
7389             }
7390             if ( !phy.getName().equals( "tree 0" ) ) {
7391                 return false;
7392             }
7393             //1
7394             if ( !p.hasNext() ) {
7395                 return false;
7396             }
7397             phy = p.next();
7398             if ( phy == null ) {
7399                 return false;
7400             }
7401             if ( phy.getNumberOfExternalNodes() != 10 ) {
7402                 return false;
7403             }
7404             if ( !phy.getName().equals( "tree 1" ) ) {
7405                 return false;
7406             }
7407             //2
7408             if ( !p.hasNext() ) {
7409                 return false;
7410             }
7411             phy = p.next();
7412             if ( phy == null ) {
7413                 return false;
7414             }
7415             if ( phy.getNumberOfExternalNodes() != 3 ) {
7416                 System.out.println( phy.toString() );
7417                 return false;
7418             }
7419             if ( !phy.getName().equals( "" ) ) {
7420                 return false;
7421             }
7422             if ( phy.isRooted() ) {
7423                 return false;
7424             }
7425             //3
7426             if ( !p.hasNext() ) {
7427                 return false;
7428             }
7429             phy = p.next();
7430             if ( phy == null ) {
7431                 return false;
7432             }
7433             if ( phy.getNumberOfExternalNodes() != 4 ) {
7434                 return false;
7435             }
7436             if ( !phy.getName().equals( "" ) ) {
7437                 return false;
7438             }
7439             if ( !phy.isRooted() ) {
7440                 return false;
7441             }
7442             //4
7443             if ( !p.hasNext() ) {
7444                 return false;
7445             }
7446             phy = p.next();
7447             if ( phy == null ) {
7448                 return false;
7449             }
7450             if ( phy.getNumberOfExternalNodes() != 5 ) {
7451                 System.out.println( phy.getNumberOfExternalNodes() );
7452                 return false;
7453             }
7454             if ( !phy.getName().equals( "" ) ) {
7455                 return false;
7456             }
7457             if ( !phy.isRooted() ) {
7458                 return false;
7459             }
7460             //5
7461             if ( !p.hasNext() ) {
7462                 return false;
7463             }
7464             phy = p.next();
7465             if ( phy == null ) {
7466                 return false;
7467             }
7468             if ( phy.getNumberOfExternalNodes() != 3 ) {
7469                 return false;
7470             }
7471             if ( !phy.getName().equals( "" ) ) {
7472                 return false;
7473             }
7474             if ( phy.isRooted() ) {
7475                 return false;
7476             }
7477             //6
7478             if ( !p.hasNext() ) {
7479                 return false;
7480             }
7481             phy = p.next();
7482             if ( phy == null ) {
7483                 return false;
7484             }
7485             if ( phy.getNumberOfExternalNodes() != 2 ) {
7486                 return false;
7487             }
7488             if ( !phy.getName().equals( "" ) ) {
7489                 return false;
7490             }
7491             if ( !phy.isRooted() ) {
7492                 return false;
7493             }
7494             //7
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( "((a,b),c);" ) ) {
7503                 return false;
7504             }
7505             if ( !phy.isRooted() ) {
7506                 return false;
7507             }
7508             //8
7509             if ( !p.hasNext() ) {
7510                 return false;
7511             }
7512             phy = p.next();
7513             if ( phy.getNumberOfExternalNodes() != 3 ) {
7514                 return false;
7515             }
7516             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
7517                 return false;
7518             }
7519             if ( !phy.getName().equals( "tree 8" ) ) {
7520                 return false;
7521             }
7522             //9
7523             if ( !p.hasNext() ) {
7524                 return false;
7525             }
7526             phy = p.next();
7527             if ( phy.getNumberOfExternalNodes() != 3 ) {
7528                 return false;
7529             }
7530             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
7531                 return false;
7532             }
7533             if ( !phy.getName().equals( "tree 9" ) ) {
7534                 return false;
7535             }
7536             //10
7537             if ( !p.hasNext() ) {
7538                 return false;
7539             }
7540             phy = p.next();
7541             if ( phy.getNumberOfExternalNodes() != 3 ) {
7542                 return false;
7543             }
7544             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7545                 return false;
7546             }
7547             if ( !phy.getName().equals( "tree 10" ) ) {
7548                 return false;
7549             }
7550             if ( !phy.isRooted() ) {
7551                 return false;
7552             }
7553             //11
7554             if ( !p.hasNext() ) {
7555                 return false;
7556             }
7557             phy = p.next();
7558             if ( phy.getNumberOfExternalNodes() != 3 ) {
7559                 return false;
7560             }
7561             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
7562                 return false;
7563             }
7564             if ( !phy.getName().equals( "tree 11" ) ) {
7565                 return false;
7566             }
7567             if ( phy.isRooted() ) {
7568                 return false;
7569             }
7570             //12
7571             if ( !p.hasNext() ) {
7572                 return false;
7573             }
7574             phy = p.next();
7575             if ( phy.getNumberOfExternalNodes() != 3 ) {
7576                 return false;
7577             }
7578             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
7579                 return false;
7580             }
7581             if ( !phy.getName().equals( "tree 12" ) ) {
7582                 return false;
7583             }
7584             if ( !phy.isRooted() ) {
7585                 return false;
7586             }
7587             //13
7588             if ( !p.hasNext() ) {
7589                 return false;
7590             }
7591             phy = p.next();
7592             if ( phy.getNumberOfExternalNodes() != 3 ) {
7593                 return false;
7594             }
7595             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7596                 return false;
7597             }
7598             if ( !phy.getName().equals( "tree 13" ) ) {
7599                 return false;
7600             }
7601             if ( !phy.isRooted() ) {
7602                 return false;
7603             }
7604             //14
7605             if ( !p.hasNext() ) {
7606                 return false;
7607             }
7608             phy = p.next();
7609             if ( phy.getNumberOfExternalNodes() != 10 ) {
7610                 System.out.println( phy.getNumberOfExternalNodes() );
7611                 return false;
7612             }
7613             if ( !phy
7614                     .toNewHampshire()
7615                     .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;" ) ) {
7616                 System.out.println( phy.toNewHampshire() );
7617                 return false;
7618             }
7619             if ( !phy.getName().equals( "tree 14" ) ) {
7620                 return false;
7621             }
7622             if ( !phy.isRooted() ) {
7623                 return false;
7624             }
7625             //15
7626             if ( !p.hasNext() ) {
7627                 return false;
7628             }
7629             phy = p.next();
7630             if ( phy.getNumberOfExternalNodes() != 10 ) {
7631                 System.out.println( phy.getNumberOfExternalNodes() );
7632                 return false;
7633             }
7634             if ( !phy
7635                     .toNewHampshire()
7636                     .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;" ) ) {
7637                 System.out.println( phy.toNewHampshire() );
7638                 return false;
7639             }
7640             if ( !phy.getName().equals( "tree 15" ) ) {
7641                 return false;
7642             }
7643             if ( phy.isRooted() ) {
7644                 return false;
7645             }
7646             //16
7647             if ( !p.hasNext() ) {
7648                 return false;
7649             }
7650             phy = p.next();
7651             if ( phy.getNumberOfExternalNodes() != 10 ) {
7652                 System.out.println( phy.getNumberOfExternalNodes() );
7653                 return false;
7654             }
7655             if ( !phy
7656                     .toNewHampshire()
7657                     .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;" ) ) {
7658                 System.out.println( phy.toNewHampshire() );
7659                 return false;
7660             }
7661             if ( !phy.getName().equals( "tree 16" ) ) {
7662                 return false;
7663             }
7664             if ( !phy.isRooted() ) {
7665                 return false;
7666             }
7667             //17
7668             if ( !p.hasNext() ) {
7669                 return false;
7670             }
7671             phy = p.next();
7672             if ( phy.getNumberOfExternalNodes() != 10 ) {
7673                 System.out.println( phy.getNumberOfExternalNodes() );
7674                 return false;
7675             }
7676             if ( !phy
7677                     .toNewHampshire()
7678                     .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;" ) ) {
7679                 System.out.println( phy.toNewHampshire() );
7680                 return false;
7681             }
7682             if ( !phy.getName().equals( "tree 17" ) ) {
7683                 return false;
7684             }
7685             if ( phy.isRooted() ) {
7686                 return false;
7687             }
7688             //
7689             if ( p.hasNext() ) {
7690                 return false;
7691             }
7692             phy = p.next();
7693             if ( phy != null ) {
7694                 return false;
7695             }
7696             p.reset();
7697             //0
7698             if ( !p.hasNext() ) {
7699                 return false;
7700             }
7701             phy = p.next();
7702             if ( phy == null ) {
7703                 return false;
7704             }
7705             if ( phy.getNumberOfExternalNodes() != 10 ) {
7706                 return false;
7707             }
7708             if ( !phy.getName().equals( "tree 0" ) ) {
7709                 return false;
7710             }
7711             //1
7712             if ( !p.hasNext() ) {
7713                 return false;
7714             }
7715             phy = p.next();
7716             if ( phy == null ) {
7717                 return false;
7718             }
7719             if ( phy.getNumberOfExternalNodes() != 10 ) {
7720                 return false;
7721             }
7722             if ( !phy.getName().equals( "tree 1" ) ) {
7723                 return false;
7724             }
7725             //2
7726             if ( !p.hasNext() ) {
7727                 return false;
7728             }
7729             phy = p.next();
7730             if ( phy == null ) {
7731                 return false;
7732             }
7733             if ( phy.getNumberOfExternalNodes() != 3 ) {
7734                 return false;
7735             }
7736             if ( !phy.getName().equals( "" ) ) {
7737                 return false;
7738             }
7739             if ( phy.isRooted() ) {
7740                 return false;
7741             }
7742             //3
7743             if ( !p.hasNext() ) {
7744                 return false;
7745             }
7746             phy = p.next();
7747             if ( phy == null ) {
7748                 return false;
7749             }
7750             if ( phy.getNumberOfExternalNodes() != 4 ) {
7751                 return false;
7752             }
7753             if ( !phy.getName().equals( "" ) ) {
7754                 return false;
7755             }
7756             if ( !phy.isRooted() ) {
7757                 return false;
7758             }
7759             //4
7760             if ( !p.hasNext() ) {
7761                 return false;
7762             }
7763             phy = p.next();
7764             if ( phy == null ) {
7765                 return false;
7766             }
7767             if ( phy.getNumberOfExternalNodes() != 5 ) {
7768                 System.out.println( phy.getNumberOfExternalNodes() );
7769                 return false;
7770             }
7771             if ( !phy.getName().equals( "" ) ) {
7772                 return false;
7773             }
7774             if ( !phy.isRooted() ) {
7775                 return false;
7776             }
7777             //5
7778             if ( !p.hasNext() ) {
7779                 return false;
7780             }
7781             phy = p.next();
7782             if ( phy == null ) {
7783                 return false;
7784             }
7785             if ( phy.getNumberOfExternalNodes() != 3 ) {
7786                 return false;
7787             }
7788             if ( !phy.getName().equals( "" ) ) {
7789                 return false;
7790             }
7791             if ( phy.isRooted() ) {
7792                 return false;
7793             }
7794             //
7795             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7796             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
7797             // 0
7798             if ( !p2.hasNext() ) {
7799                 return false;
7800             }
7801             phy = p2.next();
7802             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7803                 return false;
7804             }
7805             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7806                 return false;
7807             }
7808             // 1
7809             if ( !p2.hasNext() ) {
7810                 return false;
7811             }
7812             phy = p2.next();
7813             // 2
7814             if ( !p2.hasNext() ) {
7815                 return false;
7816             }
7817             phy = p2.next();
7818             // 3
7819             if ( !p2.hasNext() ) {
7820                 return false;
7821             }
7822             phy = p2.next();
7823             // 4
7824             if ( !p2.hasNext() ) {
7825                 return false;
7826             }
7827             phy = p2.next();
7828             // 5
7829             if ( !p2.hasNext() ) {
7830                 return false;
7831             }
7832             phy = p2.next();
7833             // 6
7834             if ( !p2.hasNext() ) {
7835                 return false;
7836             }
7837             phy = p2.next();
7838             // 7
7839             if ( !p2.hasNext() ) {
7840                 return false;
7841             }
7842             phy = p2.next();
7843             // 8
7844             if ( !p2.hasNext() ) {
7845                 return false;
7846             }
7847             phy = p2.next();
7848             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7849                 return false;
7850             }
7851             if ( p2.hasNext() ) {
7852                 return false;
7853             }
7854             phy = p2.next();
7855             if ( phy != null ) {
7856                 return false;
7857             }
7858             // 0
7859             p2.reset();
7860             if ( !p2.hasNext() ) {
7861                 return false;
7862             }
7863             phy = p2.next();
7864             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7865                 return false;
7866             }
7867             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7868                 return false;
7869             }
7870         }
7871         catch ( final Exception e ) {
7872             e.printStackTrace( System.out );
7873             return false;
7874         }
7875         return true;
7876     }
7877
7878     private static boolean testNexusTreeParsingTranslating() {
7879         try {
7880             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7881             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7882             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
7883             if ( phylogenies.length != 1 ) {
7884                 return false;
7885             }
7886             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7887                 return false;
7888             }
7889             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7890                 return false;
7891             }
7892             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7893                 return false;
7894             }
7895             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7896                 return false;
7897             }
7898             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7899                     .equals( "Aranaeus" ) ) {
7900                 return false;
7901             }
7902             phylogenies = null;
7903             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
7904             if ( phylogenies.length != 3 ) {
7905                 return false;
7906             }
7907             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7908                 return false;
7909             }
7910             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7911                 return false;
7912             }
7913             if ( phylogenies[ 0 ].isRooted() ) {
7914                 return false;
7915             }
7916             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7917                 return false;
7918             }
7919             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7920                 return false;
7921             }
7922             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7923                     .equals( "Aranaeus" ) ) {
7924                 return false;
7925             }
7926             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7927                 return false;
7928             }
7929             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7930                 return false;
7931             }
7932             if ( phylogenies[ 1 ].isRooted() ) {
7933                 return false;
7934             }
7935             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7936                 return false;
7937             }
7938             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7939                 return false;
7940             }
7941             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7942                     .equals( "Aranaeus" ) ) {
7943                 return false;
7944             }
7945             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7946                 return false;
7947             }
7948             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7949                 return false;
7950             }
7951             if ( !phylogenies[ 2 ].isRooted() ) {
7952                 return false;
7953             }
7954             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7955                 return false;
7956             }
7957             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7958                 return false;
7959             }
7960             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7961                     .equals( "Aranaeus" ) ) {
7962                 return false;
7963             }
7964             phylogenies = null;
7965             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
7966             if ( phylogenies.length != 3 ) {
7967                 return false;
7968             }
7969             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7970                 return false;
7971             }
7972             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7973                 return false;
7974             }
7975             if ( phylogenies[ 0 ].isRooted() ) {
7976                 return false;
7977             }
7978             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7979                 return false;
7980             }
7981             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7982                 return false;
7983             }
7984             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7985                     .equals( "Aranaeus" ) ) {
7986                 return false;
7987             }
7988             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7989                 return false;
7990             }
7991             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7992                 return false;
7993             }
7994             if ( phylogenies[ 1 ].isRooted() ) {
7995                 return false;
7996             }
7997             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7998                 return false;
7999             }
8000             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8001                 return false;
8002             }
8003             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8004                     .equals( "Aranaeus" ) ) {
8005                 return false;
8006             }
8007             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8008                 return false;
8009             }
8010             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8011                 return false;
8012             }
8013             if ( !phylogenies[ 2 ].isRooted() ) {
8014                 return false;
8015             }
8016             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8017                 return false;
8018             }
8019             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8020                 return false;
8021             }
8022             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8023                     .equals( "Aranaeus" ) ) {
8024                 return false;
8025             }
8026             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
8027             if ( phylogenies.length != 3 ) {
8028                 return false;
8029             }
8030             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
8031                            0.00100049 ) ) {
8032                 return false;
8033             }
8034         }
8035         catch ( final Exception e ) {
8036             e.printStackTrace( System.out );
8037             return false;
8038         }
8039         return true;
8040     }
8041
8042     private static boolean testNHParsing() {
8043         try {
8044             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8045             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
8046             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
8047                 return false;
8048             }
8049             final NHXParser nhxp = new NHXParser();
8050             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
8051             nhxp.setReplaceUnderscores( true );
8052             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
8053             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
8054                 return false;
8055             }
8056             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
8057                 return false;
8058             }
8059             final Phylogeny p1b = factory
8060                     .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 ",
8061                              new NHXParser() )[ 0 ];
8062             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
8063                 return false;
8064             }
8065             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
8066                 return false;
8067             }
8068             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
8069             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
8070             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
8071             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
8072             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
8073             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
8074             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
8075             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
8076             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
8077             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
8078             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
8079                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
8080                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
8081                                                     new NHXParser() );
8082             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
8083                 return false;
8084             }
8085             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
8086                 return false;
8087             }
8088             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
8089                 return false;
8090             }
8091             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
8092                 return false;
8093             }
8094             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
8095             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
8096             final String p16_S = "((A,B),C)";
8097             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
8098             if ( p16.length != 1 ) {
8099                 return false;
8100             }
8101             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
8102                 return false;
8103             }
8104             final String p17_S = "(C,(A,B))";
8105             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
8106             if ( p17.length != 1 ) {
8107                 return false;
8108             }
8109             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
8110                 return false;
8111             }
8112             final String p18_S = "((A,B),(C,D))";
8113             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
8114             if ( p18.length != 1 ) {
8115                 return false;
8116             }
8117             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
8118                 return false;
8119             }
8120             final String p19_S = "(((A,B),C),D)";
8121             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
8122             if ( p19.length != 1 ) {
8123                 return false;
8124             }
8125             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
8126                 return false;
8127             }
8128             final String p20_S = "(A,(B,(C,D)))";
8129             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
8130             if ( p20.length != 1 ) {
8131                 return false;
8132             }
8133             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
8134                 return false;
8135             }
8136             final String p21_S = "(A,(B,(C,(D,E))))";
8137             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
8138             if ( p21.length != 1 ) {
8139                 return false;
8140             }
8141             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
8142                 return false;
8143             }
8144             final String p22_S = "((((A,B),C),D),E)";
8145             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
8146             if ( p22.length != 1 ) {
8147                 return false;
8148             }
8149             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
8150                 return false;
8151             }
8152             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8153             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
8154             if ( p23.length != 1 ) {
8155                 System.out.println( "xl=" + p23.length );
8156                 System.exit( -1 );
8157                 return false;
8158             }
8159             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
8160                 return false;
8161             }
8162             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8163             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
8164             if ( p24.length != 1 ) {
8165                 return false;
8166             }
8167             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
8168                 return false;
8169             }
8170             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8171             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8172             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
8173             if ( p241.length != 2 ) {
8174                 return false;
8175             }
8176             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
8177                 return false;
8178             }
8179             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
8180                 return false;
8181             }
8182             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
8183                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
8184                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
8185                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
8186                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
8187                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
8188                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
8189                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
8190             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
8191             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
8192                 return false;
8193             }
8194             final String p26_S = "(A,B)ab";
8195             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
8196             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
8197                 return false;
8198             }
8199             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8200             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
8201             if ( p27s.length != 1 ) {
8202                 System.out.println( "xxl=" + p27s.length );
8203                 System.exit( -1 );
8204                 return false;
8205             }
8206             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8207                 System.out.println( p27s[ 0 ].toNewHampshireX() );
8208                 System.exit( -1 );
8209                 return false;
8210             }
8211             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
8212                                                     new NHXParser() );
8213             if ( p27.length != 1 ) {
8214                 System.out.println( "yl=" + p27.length );
8215                 System.exit( -1 );
8216                 return false;
8217             }
8218             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8219                 System.out.println( p27[ 0 ].toNewHampshireX() );
8220                 System.exit( -1 );
8221                 return false;
8222             }
8223             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8224             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8225             final String p28_S3 = "(A,B)ab";
8226             final String p28_S4 = "((((A,B),C),D),;E;)";
8227             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
8228                                                     new NHXParser() );
8229             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
8230                 return false;
8231             }
8232             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
8233                 return false;
8234             }
8235             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
8236                 return false;
8237             }
8238             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
8239                 return false;
8240             }
8241             if ( p28.length != 4 ) {
8242                 return false;
8243             }
8244             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";
8245             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
8246             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
8247                 return false;
8248             }
8249             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";
8250             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
8251             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
8252                 return false;
8253             }
8254             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
8255             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
8256             if ( ( p32.length != 0 ) ) {
8257                 return false;
8258             }
8259             final String p33_S = "A";
8260             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
8261             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
8262                 return false;
8263             }
8264             final String p34_S = "B;";
8265             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
8266             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
8267                 return false;
8268             }
8269             final String p35_S = "B:0.2";
8270             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
8271             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
8272                 return false;
8273             }
8274             final String p36_S = "(A)";
8275             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
8276             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
8277                 return false;
8278             }
8279             final String p37_S = "((A))";
8280             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
8281             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
8282                 return false;
8283             }
8284             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8285             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
8286             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
8287                 return false;
8288             }
8289             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8290             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
8291             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
8292                 return false;
8293             }
8294             final String p40_S = "(A,B,C)";
8295             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
8296             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
8297                 return false;
8298             }
8299             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
8300             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
8301             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
8302                 return false;
8303             }
8304             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
8305             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
8306             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
8307                 return false;
8308             }
8309             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)";
8310             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
8311             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
8312                 return false;
8313             }
8314             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)))";
8315             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
8316             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
8317                 return false;
8318             }
8319             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
8320             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
8321             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
8322                 return false;
8323             }
8324             final String p46_S = "";
8325             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
8326             if ( p46.length != 0 ) {
8327                 return false;
8328             }
8329             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
8330             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8331                 return false;
8332             }
8333             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8334             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8335                 return false;
8336             }
8337             final Phylogeny p49 = factory
8338                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
8339                              new NHXParser() )[ 0 ];
8340             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8341                 return false;
8342             }
8343             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8344             if ( p50.getNode( "A" ) == null ) {
8345                 return false;
8346             }
8347             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8348                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
8349                 return false;
8350             }
8351             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
8352                 return false;
8353             }
8354             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
8355                     .equals( "((A,B)88:2.0,C);" ) ) {
8356                 return false;
8357             }
8358             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8359             if ( p51.getNode( "A(A" ) == null ) {
8360                 return false;
8361             }
8362             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8363             if ( p52.getNode( "A(A" ) == null ) {
8364                 return false;
8365             }
8366             final Phylogeny p53 = factory
8367                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
8368                              new NHXParser() )[ 0 ];
8369             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
8370                 return false;
8371             }
8372             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
8373             if ( p54.getNode( "A" ) == null ) {
8374                 return false;
8375             }
8376             if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ).equals( "((A,B)[88],C);" ) ) {
8377                 return false;
8378             }
8379             final Phylogeny p55 = factory
8380                     .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);" ),
8381                              new NHXParser() )[ 0 ];
8382             if ( !p55
8383                     .toNewHampshire()
8384                     .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);" ) ) {
8385                 System.out.println( p55.toNewHampshire() );
8386                 return false;
8387             }
8388             final Phylogeny p56 = factory
8389                     .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);" ),
8390                              new NHXParser() )[ 0 ];
8391             if ( !p56
8392                     .toNewHampshire()
8393                     .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);" ) ) {
8394                 System.out.println( p56.toNewHampshire() );
8395                 return false;
8396             }
8397             final Phylogeny p57 = factory
8398                     .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);" ),
8399                              new NHXParser() )[ 0 ];
8400             if ( !p57
8401                     .toNewHampshire()
8402                     .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);" ) ) {
8403                 System.out.println( p56.toNewHampshire() );
8404                 return false;
8405             }
8406             final String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
8407             final Phylogeny p58 = factory.create( new StringBuffer( s58 ), new NHXParser() )[ 0 ];
8408             if ( !p58.toNewHampshire().equals( s58 ) ) {
8409                 System.out.println( p58.toNewHampshire() );
8410                 return false;
8411             }
8412             final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
8413             final Phylogeny p59 = factory.create( new StringBuffer( s59 ), new NHXParser() )[ 0 ];
8414             if ( !p59.toNewHampshire().equals( s59 ) ) {
8415                 System.out.println( p59.toNewHampshire() );
8416                 return false;
8417             }
8418             final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
8419             final Phylogeny p60 = factory.create( new StringBuffer( s60 ), new NHXParser() )[ 0 ];
8420             if ( !p60.toNewHampshire().equals( s60 ) ) {
8421                 System.out.println( p60.toNewHampshire() );
8422                 return false;
8423             }
8424             final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
8425             final Phylogeny p61 = factory.create( new StringBuffer( s61 ), new NHXParser() )[ 0 ];
8426             if ( !p61.toNewHampshire()
8427                     .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
8428                 System.out.println( p61.toNewHampshire() );
8429                 return false;
8430             }
8431         }
8432         catch ( final Exception e ) {
8433             e.printStackTrace( System.out );
8434             return false;
8435         }
8436         return true;
8437     }
8438
8439     private static boolean testNHParsingIter() {
8440         try {
8441             final String p0_str = "(A,B);";
8442             final NHXParser p = new NHXParser();
8443             p.setSource( p0_str );
8444             if ( !p.hasNext() ) {
8445                 return false;
8446             }
8447             final Phylogeny p0 = p.next();
8448             if ( !p0.toNewHampshire().equals( p0_str ) ) {
8449                 System.out.println( p0.toNewHampshire() );
8450                 return false;
8451             }
8452             if ( p.hasNext() ) {
8453                 return false;
8454             }
8455             if ( p.next() != null ) {
8456                 return false;
8457             }
8458             //
8459             final String p00_str = "(A,B)root;";
8460             p.setSource( p00_str );
8461             final Phylogeny p00 = p.next();
8462             if ( !p00.toNewHampshire().equals( p00_str ) ) {
8463                 System.out.println( p00.toNewHampshire() );
8464                 return false;
8465             }
8466             //
8467             final String p000_str = "A;";
8468             p.setSource( p000_str );
8469             final Phylogeny p000 = p.next();
8470             if ( !p000.toNewHampshire().equals( p000_str ) ) {
8471                 System.out.println( p000.toNewHampshire() );
8472                 return false;
8473             }
8474             //
8475             final String p0000_str = "A";
8476             p.setSource( p0000_str );
8477             final Phylogeny p0000 = p.next();
8478             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
8479                 System.out.println( p0000.toNewHampshire() );
8480                 return false;
8481             }
8482             //
8483             p.setSource( "(A)" );
8484             final Phylogeny p00000 = p.next();
8485             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
8486                 System.out.println( p00000.toNewHampshire() );
8487                 return false;
8488             }
8489             //
8490             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
8491             p.setSource( p1_str );
8492             if ( !p.hasNext() ) {
8493                 return false;
8494             }
8495             final Phylogeny p1_0 = p.next();
8496             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
8497                 System.out.println( p1_0.toNewHampshire() );
8498                 return false;
8499             }
8500             if ( !p.hasNext() ) {
8501                 return false;
8502             }
8503             final Phylogeny p1_1 = p.next();
8504             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
8505                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
8506                 return false;
8507             }
8508             if ( !p.hasNext() ) {
8509                 return false;
8510             }
8511             final Phylogeny p1_2 = p.next();
8512             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
8513                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
8514                 return false;
8515             }
8516             if ( !p.hasNext() ) {
8517                 return false;
8518             }
8519             final Phylogeny p1_3 = p.next();
8520             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
8521                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
8522                 return false;
8523             }
8524             if ( p.hasNext() ) {
8525                 return false;
8526             }
8527             if ( p.next() != null ) {
8528                 return false;
8529             }
8530             //
8531             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
8532             p.setSource( p2_str );
8533             if ( !p.hasNext() ) {
8534                 return false;
8535             }
8536             Phylogeny p2_0 = p.next();
8537             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8538                 System.out.println( p2_0.toNewHampshire() );
8539                 return false;
8540             }
8541             if ( !p.hasNext() ) {
8542                 return false;
8543             }
8544             Phylogeny p2_1 = p.next();
8545             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8546                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8547                 return false;
8548             }
8549             if ( !p.hasNext() ) {
8550                 return false;
8551             }
8552             Phylogeny p2_2 = p.next();
8553             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8554                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8555                 return false;
8556             }
8557             if ( !p.hasNext() ) {
8558                 return false;
8559             }
8560             Phylogeny p2_3 = p.next();
8561             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8562                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8563                 return false;
8564             }
8565             if ( !p.hasNext() ) {
8566                 return false;
8567             }
8568             Phylogeny p2_4 = p.next();
8569             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8570                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8571                 return false;
8572             }
8573             if ( p.hasNext() ) {
8574                 return false;
8575             }
8576             if ( p.next() != null ) {
8577                 return false;
8578             }
8579             ////
8580             p.reset();
8581             if ( !p.hasNext() ) {
8582                 return false;
8583             }
8584             p2_0 = p.next();
8585             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8586                 System.out.println( p2_0.toNewHampshire() );
8587                 return false;
8588             }
8589             if ( !p.hasNext() ) {
8590                 return false;
8591             }
8592             p2_1 = p.next();
8593             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8594                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8595                 return false;
8596             }
8597             if ( !p.hasNext() ) {
8598                 return false;
8599             }
8600             p2_2 = p.next();
8601             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8602                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8603                 return false;
8604             }
8605             if ( !p.hasNext() ) {
8606                 return false;
8607             }
8608             p2_3 = p.next();
8609             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8610                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8611                 return false;
8612             }
8613             if ( !p.hasNext() ) {
8614                 return false;
8615             }
8616             p2_4 = p.next();
8617             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8618                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8619                 return false;
8620             }
8621             if ( p.hasNext() ) {
8622                 return false;
8623             }
8624             if ( p.next() != null ) {
8625                 return false;
8626             }
8627             //
8628             final String p3_str = "((A,B),C)abc";
8629             p.setSource( p3_str );
8630             if ( !p.hasNext() ) {
8631                 return false;
8632             }
8633             final Phylogeny p3_0 = p.next();
8634             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
8635                 return false;
8636             }
8637             if ( p.hasNext() ) {
8638                 return false;
8639             }
8640             if ( p.next() != null ) {
8641                 return false;
8642             }
8643             //
8644             final String p4_str = "((A,B)ab,C)abc";
8645             p.setSource( p4_str );
8646             if ( !p.hasNext() ) {
8647                 return false;
8648             }
8649             final Phylogeny p4_0 = p.next();
8650             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
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 p5_str = "(((A,B)ab,C)abc,D)abcd";
8661             p.setSource( p5_str );
8662             if ( !p.hasNext() ) {
8663                 return false;
8664             }
8665             final Phylogeny p5_0 = p.next();
8666             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
8667                 return false;
8668             }
8669             if ( p.hasNext() ) {
8670                 return false;
8671             }
8672             if ( p.next() != null ) {
8673                 return false;
8674             }
8675             //
8676             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8677             p.setSource( p6_str );
8678             if ( !p.hasNext() ) {
8679                 return false;
8680             }
8681             Phylogeny p6_0 = p.next();
8682             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8683                 return false;
8684             }
8685             if ( p.hasNext() ) {
8686                 return false;
8687             }
8688             if ( p.next() != null ) {
8689                 return false;
8690             }
8691             p.reset();
8692             if ( !p.hasNext() ) {
8693                 return false;
8694             }
8695             p6_0 = p.next();
8696             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8697                 return false;
8698             }
8699             if ( p.hasNext() ) {
8700                 return false;
8701             }
8702             if ( p.next() != null ) {
8703                 return false;
8704             }
8705             //
8706             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8707             p.setSource( p7_str );
8708             if ( !p.hasNext() ) {
8709                 return false;
8710             }
8711             Phylogeny p7_0 = p.next();
8712             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8713                 return false;
8714             }
8715             if ( p.hasNext() ) {
8716                 return false;
8717             }
8718             if ( p.next() != null ) {
8719                 return false;
8720             }
8721             p.reset();
8722             if ( !p.hasNext() ) {
8723                 return false;
8724             }
8725             p7_0 = p.next();
8726             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8727                 return false;
8728             }
8729             if ( p.hasNext() ) {
8730                 return false;
8731             }
8732             if ( p.next() != null ) {
8733                 return false;
8734             }
8735             //
8736             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
8737             p.setSource( p8_str );
8738             if ( !p.hasNext() ) {
8739                 return false;
8740             }
8741             Phylogeny p8_0 = p.next();
8742             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8743                 return false;
8744             }
8745             if ( !p.hasNext() ) {
8746                 return false;
8747             }
8748             if ( !p.hasNext() ) {
8749                 return false;
8750             }
8751             Phylogeny p8_1 = p.next();
8752             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8753                 return false;
8754             }
8755             if ( p.hasNext() ) {
8756                 return false;
8757             }
8758             if ( p.next() != null ) {
8759                 return false;
8760             }
8761             p.reset();
8762             if ( !p.hasNext() ) {
8763                 return false;
8764             }
8765             p8_0 = p.next();
8766             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8767                 return false;
8768             }
8769             if ( !p.hasNext() ) {
8770                 return false;
8771             }
8772             p8_1 = p.next();
8773             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8774                 return false;
8775             }
8776             if ( p.hasNext() ) {
8777                 return false;
8778             }
8779             if ( p.next() != null ) {
8780                 return false;
8781             }
8782             p.reset();
8783             //
8784             p.setSource( "" );
8785             if ( p.hasNext() ) {
8786                 return false;
8787             }
8788             //
8789             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
8790             if ( !p.hasNext() ) {
8791                 return false;
8792             }
8793             Phylogeny p_27 = p.next();
8794             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8795                 System.out.println( p_27.toNewHampshireX() );
8796                 System.exit( -1 );
8797                 return false;
8798             }
8799             if ( p.hasNext() ) {
8800                 return false;
8801             }
8802             if ( p.next() != null ) {
8803                 return false;
8804             }
8805             p.reset();
8806             if ( !p.hasNext() ) {
8807                 return false;
8808             }
8809             p_27 = p.next();
8810             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8811                 System.out.println( p_27.toNewHampshireX() );
8812                 System.exit( -1 );
8813                 return false;
8814             }
8815             if ( p.hasNext() ) {
8816                 return false;
8817             }
8818             if ( p.next() != null ) {
8819                 return false;
8820             }
8821             //
8822             final String p30_str = "(A,B);(C,D)";
8823             final NHXParser p30 = new NHXParser();
8824             p30.setSource( p30_str );
8825             if ( !p30.hasNext() ) {
8826                 return false;
8827             }
8828             Phylogeny phy30 = p30.next();
8829             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8830                 System.out.println( phy30.toNewHampshire() );
8831                 return false;
8832             }
8833             if ( !p30.hasNext() ) {
8834                 return false;
8835             }
8836             Phylogeny phy301 = p30.next();
8837             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8838                 System.out.println( phy301.toNewHampshire() );
8839                 return false;
8840             }
8841             if ( p30.hasNext() ) {
8842                 return false;
8843             }
8844             if ( p30.hasNext() ) {
8845                 return false;
8846             }
8847             if ( p30.next() != null ) {
8848                 return false;
8849             }
8850             if ( p30.next() != null ) {
8851                 return false;
8852             }
8853             p30.reset();
8854             if ( !p30.hasNext() ) {
8855                 return false;
8856             }
8857             phy30 = p30.next();
8858             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8859                 System.out.println( phy30.toNewHampshire() );
8860                 return false;
8861             }
8862             if ( !p30.hasNext() ) {
8863                 return false;
8864             }
8865             phy301 = p30.next();
8866             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8867                 System.out.println( phy301.toNewHampshire() );
8868                 return false;
8869             }
8870             if ( p30.hasNext() ) {
8871                 return false;
8872             }
8873             if ( p30.hasNext() ) {
8874                 return false;
8875             }
8876             if ( p30.next() != null ) {
8877                 return false;
8878             }
8879             if ( p30.next() != null ) {
8880                 return false;
8881             }
8882         }
8883         catch ( final Exception e ) {
8884             e.printStackTrace( System.out );
8885             return false;
8886         }
8887         return true;
8888     }
8889
8890     private static boolean testNHXconversion() {
8891         try {
8892             final PhylogenyNode n1 = new PhylogenyNode();
8893             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8894             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8895             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8896             final PhylogenyNode n5 = PhylogenyNode
8897                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
8898             final PhylogenyNode n6 = PhylogenyNode
8899                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
8900             if ( !n1.toNewHampshireX().equals( "" ) ) {
8901                 return false;
8902             }
8903             if ( !n2.toNewHampshireX().equals( "" ) ) {
8904                 return false;
8905             }
8906             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
8907                 return false;
8908             }
8909             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
8910                 return false;
8911             }
8912             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
8913                 return false;
8914             }
8915             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
8916                 System.out.println( n6.toNewHampshireX() );
8917                 return false;
8918             }
8919             final PhylogenyNode n7 = new PhylogenyNode();
8920             n7.setName( "   gks:dr-m4 \"    '    `@:[]sadq04 " );
8921             if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8922                     .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
8923                 System.out.println( n7
8924                         .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
8925                 return false;
8926             }
8927         }
8928         catch ( final Exception e ) {
8929             e.printStackTrace( System.out );
8930             return false;
8931         }
8932         return true;
8933     }
8934
8935     private static boolean testNHXNodeParsing() {
8936         try {
8937             final PhylogenyNode n1 = new PhylogenyNode();
8938             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8939             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8940             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8941             final PhylogenyNode n5 = PhylogenyNode
8942                     .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]" );
8943             if ( !n3.getName().equals( "n3" ) ) {
8944                 return false;
8945             }
8946             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8947                 return false;
8948             }
8949             if ( n3.isDuplication() ) {
8950                 return false;
8951             }
8952             if ( n3.isHasAssignedEvent() ) {
8953                 return false;
8954             }
8955             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
8956                 return false;
8957             }
8958             if ( !n4.getName().equals( "n4" ) ) {
8959                 return false;
8960             }
8961             if ( n4.getDistanceToParent() != 0.01 ) {
8962                 return false;
8963             }
8964             if ( !n5.getName().equals( "n5" ) ) {
8965                 return false;
8966             }
8967             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
8968                 return false;
8969             }
8970             if ( n5.getDistanceToParent() != 0.1 ) {
8971                 return false;
8972             }
8973             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
8974                 return false;
8975             }
8976             if ( !n5.isDuplication() ) {
8977                 return false;
8978             }
8979             if ( !n5.isHasAssignedEvent() ) {
8980                 return false;
8981             }
8982             final PhylogenyNode n8 = PhylogenyNode
8983                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
8984                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8985             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8986                 return false;
8987             }
8988             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
8989                 return false;
8990             }
8991             final PhylogenyNode n9 = PhylogenyNode
8992                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
8993                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8994             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
8995                 return false;
8996             }
8997             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
8998                 return false;
8999             }
9000             final PhylogenyNode n10 = PhylogenyNode
9001                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9002             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
9003                 return false;
9004             }
9005             final PhylogenyNode n20 = PhylogenyNode
9006                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9007             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9008                 return false;
9009             }
9010             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
9011                 return false;
9012             }
9013             final PhylogenyNode n20x = PhylogenyNode
9014                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9015             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
9016                 return false;
9017             }
9018             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
9019                 return false;
9020             }
9021             final PhylogenyNode n20xx = PhylogenyNode
9022                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9023             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
9024                 return false;
9025             }
9026             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
9027                 return false;
9028             }
9029             final PhylogenyNode n20xxx = PhylogenyNode
9030                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9031             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
9032                 return false;
9033             }
9034             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
9035                 return false;
9036             }
9037             final PhylogenyNode n20xxxx = PhylogenyNode
9038                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9039             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
9040                 return false;
9041             }
9042             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
9043                 return false;
9044             }
9045             final PhylogenyNode n21 = PhylogenyNode
9046                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9047             if ( !n21.getName().equals( "N21_PIG" ) ) {
9048                 return false;
9049             }
9050             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
9051                 return false;
9052             }
9053             final PhylogenyNode n21x = PhylogenyNode
9054                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9055             if ( !n21x.getName().equals( "n21_PIG" ) ) {
9056                 return false;
9057             }
9058             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
9059                 return false;
9060             }
9061             final PhylogenyNode n22 = PhylogenyNode
9062                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9063             if ( !n22.getName().equals( "n22/PIG" ) ) {
9064                 return false;
9065             }
9066             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
9067                 return false;
9068             }
9069             final PhylogenyNode n23 = PhylogenyNode
9070                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9071             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
9072                 return false;
9073             }
9074             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
9075                 return false;
9076             }
9077             final PhylogenyNode a = PhylogenyNode
9078                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9079             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9080                 return false;
9081             }
9082             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
9083                 return false;
9084             }
9085             final PhylogenyNode c1 = PhylogenyNode
9086                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
9087                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9088             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
9089                 return false;
9090             }
9091             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
9092                 return false;
9093             }
9094             final PhylogenyNode c2 = PhylogenyNode
9095                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
9096                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9097             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
9098                 return false;
9099             }
9100             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
9101                 return false;
9102             }
9103             final PhylogenyNode e3 = PhylogenyNode
9104                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9105             if ( !e3.getName().equals( "n10_RAT~" ) ) {
9106                 return false;
9107             }
9108             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
9109                 return false;
9110             }
9111             final PhylogenyNode n11 = PhylogenyNode
9112                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
9113                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9114             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
9115                 return false;
9116             }
9117             if ( n11.getDistanceToParent() != 0.4 ) {
9118                 return false;
9119             }
9120             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
9121                 return false;
9122             }
9123             final PhylogenyNode n12 = PhylogenyNode
9124                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
9125                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9126             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
9127                 return false;
9128             }
9129             if ( n12.getDistanceToParent() != 0.4 ) {
9130                 return false;
9131             }
9132             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
9133                 return false;
9134             }
9135             final PhylogenyNode o = PhylogenyNode
9136                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9137             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
9138                 return false;
9139             }
9140             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
9141                 return false;
9142             }
9143             if ( n1.getName().compareTo( "" ) != 0 ) {
9144                 return false;
9145             }
9146             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9147                 return false;
9148             }
9149             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9150                 return false;
9151             }
9152             if ( n2.getName().compareTo( "" ) != 0 ) {
9153                 return false;
9154             }
9155             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9156                 return false;
9157             }
9158             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9159                 return false;
9160             }
9161             final PhylogenyNode n00 = PhylogenyNode
9162                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
9163             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
9164                 return false;
9165             }
9166             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
9167                 return false;
9168             }
9169             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
9170             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
9171                 return false;
9172             }
9173             final PhylogenyNode n13 = PhylogenyNode
9174                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9175             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
9176                 return false;
9177             }
9178             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
9179                 return false;
9180             }
9181             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9182                 return false;
9183             }
9184             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9185                 return false;
9186             }
9187             final PhylogenyNode n14 = PhylogenyNode
9188                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9189             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
9190                 return false;
9191             }
9192             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
9193                 return false;
9194             }
9195             final PhylogenyNode n15 = PhylogenyNode
9196                     .createInstanceFromNhxString( "something_wicked[123]",
9197                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9198             if ( !n15.getName().equals( "something_wicked" ) ) {
9199                 return false;
9200             }
9201             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
9202                 return false;
9203             }
9204             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
9205                 return false;
9206             }
9207             final PhylogenyNode n16 = PhylogenyNode
9208                     .createInstanceFromNhxString( "something_wicked2[9]",
9209                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9210             if ( !n16.getName().equals( "something_wicked2" ) ) {
9211                 return false;
9212             }
9213             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
9214                 return false;
9215             }
9216             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
9217                 return false;
9218             }
9219             final PhylogenyNode n17 = PhylogenyNode
9220                     .createInstanceFromNhxString( "something_wicked3[a]",
9221                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9222             if ( !n17.getName().equals( "something_wicked3" ) ) {
9223                 return false;
9224             }
9225             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
9226                 return false;
9227             }
9228             final PhylogenyNode n18 = PhylogenyNode
9229                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9230             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
9231                 return false;
9232             }
9233             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
9234                 return false;
9235             }
9236             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
9237                 return false;
9238             }
9239             final PhylogenyNode n19 = PhylogenyNode
9240                     .createInstanceFromNhxString( "BLAH_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9241             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
9242                 return false;
9243             }
9244             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9245                 return false;
9246             }
9247             final PhylogenyNode n30 = PhylogenyNode
9248                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
9249                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9250             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
9251                 return false;
9252             }
9253             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9254                 return false;
9255             }
9256             final PhylogenyNode n31 = PhylogenyNode
9257                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
9258                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9259             if ( n31.getNodeData().isHasTaxonomy() ) {
9260                 return false;
9261             }
9262             final PhylogenyNode n32 = PhylogenyNode
9263                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9264             if ( n32.getNodeData().isHasTaxonomy() ) {
9265                 return false;
9266             }
9267             final PhylogenyNode n40 = PhylogenyNode
9268                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9269             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9270                 return false;
9271             }
9272             final PhylogenyNode n41 = PhylogenyNode
9273                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9274             if ( n41.getNodeData().isHasTaxonomy() ) {
9275                 return false;
9276             }
9277             final PhylogenyNode n42 = PhylogenyNode
9278                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9279             if ( n42.getNodeData().isHasTaxonomy() ) {
9280                 return false;
9281             }
9282             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
9283                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
9284             if ( n43.getNodeData().isHasTaxonomy() ) {
9285                 return false;
9286             }
9287             final PhylogenyNode n44 = PhylogenyNode
9288                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9289             if ( n44.getNodeData().isHasTaxonomy() ) {
9290                 return false;
9291             }
9292         }
9293         catch ( final Exception e ) {
9294             e.printStackTrace( System.out );
9295             return false;
9296         }
9297         return true;
9298     }
9299
9300     private static boolean testNHXParsing() {
9301         try {
9302             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9303             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
9304             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
9305                 return false;
9306             }
9307             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]";
9308             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
9309             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9310                 return false;
9311             }
9312             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]";
9313             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
9314             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
9315                 return false;
9316             }
9317             final Phylogeny[] p3 = factory
9318                     .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]",
9319                              new NHXParser() );
9320             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9321                 return false;
9322             }
9323             final Phylogeny[] p4 = factory
9324                     .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(]",
9325                              new NHXParser() );
9326             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9327                 return false;
9328             }
9329             final Phylogeny[] p5 = factory
9330                     .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(((]",
9331                              new NHXParser() );
9332             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9333                 return false;
9334             }
9335             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)";
9336             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)";
9337             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
9338             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
9339                 return false;
9340             }
9341             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)))";
9342             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)))";
9343             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
9344             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
9345                 return false;
9346             }
9347             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])   ))[,,, ])))))))";
9348             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
9349             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
9350             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
9351                 return false;
9352             }
9353             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
9354             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9355                 return false;
9356             }
9357             final Phylogeny p10 = factory
9358                     .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]",
9359                              new NHXParser() )[ 0 ];
9360             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9361                 return false;
9362             }
9363             final Phylogeny p11 = factory
9364                     .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]",
9365                              new NHXParser() )[ 0 ];
9366             if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9367                 return false;
9368             }
9369         }
9370         catch ( final Exception e ) {
9371             e.printStackTrace( System.out );
9372             return false;
9373         }
9374         return true;
9375     }
9376
9377     private static boolean testNHXParsingMB() {
9378         try {
9379             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9380             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
9381                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9382                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9383                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9384                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9385                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9386                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9387                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9388                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
9389             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
9390                 return false;
9391             }
9392             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
9393                 return false;
9394             }
9395             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
9396                            0.1100000000000000e+00 ) ) {
9397                 return false;
9398             }
9399             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
9400                 return false;
9401             }
9402             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
9403                 return false;
9404             }
9405             final Phylogeny p2 = factory
9406                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
9407                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9408                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9409                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9410                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9411                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9412                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9413                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9414                                      + "7.369400000000000e-02}])",
9415                              new NHXParser() )[ 0 ];
9416             if ( p2.getNode( "1" ) == null ) {
9417                 return false;
9418             }
9419             if ( p2.getNode( "2" ) == null ) {
9420                 return false;
9421             }
9422         }
9423         catch ( final Exception e ) {
9424             e.printStackTrace( System.out );
9425             System.exit( -1 );
9426             return false;
9427         }
9428         return true;
9429     }
9430
9431     private static boolean testNHXParsingQuotes() {
9432         try {
9433             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9434             final NHXParser p = new NHXParser();
9435             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
9436             if ( phylogenies_0.length != 5 ) {
9437                 return false;
9438             }
9439             final Phylogeny phy = phylogenies_0[ 4 ];
9440             if ( phy.getNumberOfExternalNodes() != 7 ) {
9441                 return false;
9442             }
9443             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
9444                 return false;
9445             }
9446             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
9447                 return false;
9448             }
9449             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
9450                     .getScientificName().equals( "hsapiens" ) ) {
9451                 return false;
9452             }
9453             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
9454                 return false;
9455             }
9456             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
9457                 return false;
9458             }
9459             if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
9460                 return false;
9461             }
9462             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
9463                 return false;
9464             }
9465             if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
9466                 return false;
9467             }
9468             final NHXParser p1p = new NHXParser();
9469             p1p.setIgnoreQuotes( true );
9470             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
9471             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
9472                 return false;
9473             }
9474             final NHXParser p2p = new NHXParser();
9475             p1p.setIgnoreQuotes( false );
9476             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
9477             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
9478                 return false;
9479             }
9480             final NHXParser p3p = new NHXParser();
9481             p3p.setIgnoreQuotes( false );
9482             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
9483             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
9484                 return false;
9485             }
9486             final NHXParser p4p = new NHXParser();
9487             p4p.setIgnoreQuotes( false );
9488             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
9489             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
9490                 return false;
9491             }
9492             final Phylogeny p10 = factory
9493                     .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]",
9494                              new NHXParser() )[ 0 ];
9495             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]";
9496             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
9497                 return false;
9498             }
9499             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
9500             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
9501                 return false;
9502             }
9503             final Phylogeny p12 = factory
9504                     .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]",
9505                              new NHXParser() )[ 0 ];
9506             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]";
9507             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
9508                 return false;
9509             }
9510             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
9511             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
9512                 return false;
9513             }
9514             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;";
9515             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
9516                 return false;
9517             }
9518             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
9519             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
9520                 return false;
9521             }
9522         }
9523         catch ( final Exception e ) {
9524             e.printStackTrace( System.out );
9525             return false;
9526         }
9527         return true;
9528     }
9529
9530     private static boolean testNodeRemoval() {
9531         try {
9532             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9533             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
9534             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
9535             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
9536                 return false;
9537             }
9538             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
9539             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
9540             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
9541                 return false;
9542             }
9543             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
9544             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
9545             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
9546                 return false;
9547             }
9548         }
9549         catch ( final Exception e ) {
9550             e.printStackTrace( System.out );
9551             return false;
9552         }
9553         return true;
9554     }
9555
9556     private static boolean testPhylogenyBranch() {
9557         try {
9558             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
9559             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
9560             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
9561             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
9562             if ( !a1b1.equals( a1b1 ) ) {
9563                 return false;
9564             }
9565             if ( !a1b1.equals( b1a1 ) ) {
9566                 return false;
9567             }
9568             if ( !b1a1.equals( a1b1 ) ) {
9569                 return false;
9570             }
9571             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
9572             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
9573             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
9574             if ( a1_b1.equals( b1_a1 ) ) {
9575                 return false;
9576             }
9577             if ( a1_b1.equals( a1_b1_ ) ) {
9578                 return false;
9579             }
9580             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
9581             if ( !a1_b1.equals( b1_a1_ ) ) {
9582                 return false;
9583             }
9584             if ( a1_b1_.equals( b1_a1_ ) ) {
9585                 return false;
9586             }
9587             if ( !a1_b1_.equals( b1_a1 ) ) {
9588                 return false;
9589             }
9590         }
9591         catch ( final Exception e ) {
9592             e.printStackTrace( System.out );
9593             return false;
9594         }
9595         return true;
9596     }
9597
9598     private static boolean testPhyloXMLparsingOfDistributionElement() {
9599         try {
9600             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9601             PhyloXmlParser xml_parser = null;
9602             try {
9603                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
9604             }
9605             catch ( final Exception e ) {
9606                 // Do nothing -- means were not running from jar.
9607             }
9608             if ( xml_parser == null ) {
9609                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
9610                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
9611                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
9612                 }
9613                 else {
9614                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
9615                 }
9616             }
9617             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
9618                                                               xml_parser );
9619             if ( xml_parser.getErrorCount() > 0 ) {
9620                 System.out.println( xml_parser.getErrorMessages().toString() );
9621                 return false;
9622             }
9623             if ( phylogenies_0.length != 1 ) {
9624                 return false;
9625             }
9626             final Phylogeny t1 = phylogenies_0[ 0 ];
9627             PhylogenyNode n = null;
9628             Distribution d = null;
9629             n = t1.getNode( "root node" );
9630             if ( !n.getNodeData().isHasDistribution() ) {
9631                 return false;
9632             }
9633             if ( n.getNodeData().getDistributions().size() != 1 ) {
9634                 return false;
9635             }
9636             d = n.getNodeData().getDistribution();
9637             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9638                 return false;
9639             }
9640             if ( d.getPoints().size() != 1 ) {
9641                 return false;
9642             }
9643             if ( d.getPolygons() != null ) {
9644                 return false;
9645             }
9646             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9647                 return false;
9648             }
9649             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9650                 return false;
9651             }
9652             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9653                 return false;
9654             }
9655             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9656                 return false;
9657             }
9658             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9659                 return false;
9660             }
9661             n = t1.getNode( "node a" );
9662             if ( !n.getNodeData().isHasDistribution() ) {
9663                 return false;
9664             }
9665             if ( n.getNodeData().getDistributions().size() != 2 ) {
9666                 return false;
9667             }
9668             d = n.getNodeData().getDistribution( 1 );
9669             if ( !d.getDesc().equals( "San Diego" ) ) {
9670                 return false;
9671             }
9672             if ( d.getPoints().size() != 1 ) {
9673                 return false;
9674             }
9675             if ( d.getPolygons() != null ) {
9676                 return false;
9677             }
9678             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9679                 return false;
9680             }
9681             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9682                 return false;
9683             }
9684             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9685                 return false;
9686             }
9687             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9688                 return false;
9689             }
9690             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9691                 return false;
9692             }
9693             n = t1.getNode( "node bb" );
9694             if ( !n.getNodeData().isHasDistribution() ) {
9695                 return false;
9696             }
9697             if ( n.getNodeData().getDistributions().size() != 1 ) {
9698                 return false;
9699             }
9700             d = n.getNodeData().getDistribution( 0 );
9701             if ( d.getPoints().size() != 3 ) {
9702                 return false;
9703             }
9704             if ( d.getPolygons().size() != 2 ) {
9705                 return false;
9706             }
9707             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9708                 return false;
9709             }
9710             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9711                 return false;
9712             }
9713             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9714                 return false;
9715             }
9716             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9717                 return false;
9718             }
9719             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9720                 return false;
9721             }
9722             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9723                 return false;
9724             }
9725             Polygon p = d.getPolygons().get( 0 );
9726             if ( p.getPoints().size() != 3 ) {
9727                 return false;
9728             }
9729             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9730                 return false;
9731             }
9732             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9733                 return false;
9734             }
9735             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9736                 return false;
9737             }
9738             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9739                 return false;
9740             }
9741             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9742                 return false;
9743             }
9744             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9745                 return false;
9746             }
9747             p = d.getPolygons().get( 1 );
9748             if ( p.getPoints().size() != 3 ) {
9749                 return false;
9750             }
9751             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9752                 return false;
9753             }
9754             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9755                 return false;
9756             }
9757             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9758                 return false;
9759             }
9760             // Roundtrip:
9761             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
9762             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
9763             if ( rt.length != 1 ) {
9764                 return false;
9765             }
9766             final Phylogeny t1_rt = rt[ 0 ];
9767             n = t1_rt.getNode( "root node" );
9768             if ( !n.getNodeData().isHasDistribution() ) {
9769                 return false;
9770             }
9771             if ( n.getNodeData().getDistributions().size() != 1 ) {
9772                 return false;
9773             }
9774             d = n.getNodeData().getDistribution();
9775             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9776                 return false;
9777             }
9778             if ( d.getPoints().size() != 1 ) {
9779                 return false;
9780             }
9781             if ( d.getPolygons() != null ) {
9782                 return false;
9783             }
9784             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9785                 return false;
9786             }
9787             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9788                 return false;
9789             }
9790             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9791                 return false;
9792             }
9793             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9794                 return false;
9795             }
9796             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9797                 return false;
9798             }
9799             n = t1_rt.getNode( "node a" );
9800             if ( !n.getNodeData().isHasDistribution() ) {
9801                 return false;
9802             }
9803             if ( n.getNodeData().getDistributions().size() != 2 ) {
9804                 return false;
9805             }
9806             d = n.getNodeData().getDistribution( 1 );
9807             if ( !d.getDesc().equals( "San Diego" ) ) {
9808                 return false;
9809             }
9810             if ( d.getPoints().size() != 1 ) {
9811                 return false;
9812             }
9813             if ( d.getPolygons() != null ) {
9814                 return false;
9815             }
9816             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9817                 return false;
9818             }
9819             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9820                 return false;
9821             }
9822             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9823                 return false;
9824             }
9825             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9826                 return false;
9827             }
9828             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9829                 return false;
9830             }
9831             n = t1_rt.getNode( "node bb" );
9832             if ( !n.getNodeData().isHasDistribution() ) {
9833                 return false;
9834             }
9835             if ( n.getNodeData().getDistributions().size() != 1 ) {
9836                 return false;
9837             }
9838             d = n.getNodeData().getDistribution( 0 );
9839             if ( d.getPoints().size() != 3 ) {
9840                 return false;
9841             }
9842             if ( d.getPolygons().size() != 2 ) {
9843                 return false;
9844             }
9845             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9846                 return false;
9847             }
9848             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9849                 return false;
9850             }
9851             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9852                 return false;
9853             }
9854             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9855                 return false;
9856             }
9857             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9858                 return false;
9859             }
9860             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9861                 return false;
9862             }
9863             p = d.getPolygons().get( 0 );
9864             if ( p.getPoints().size() != 3 ) {
9865                 return false;
9866             }
9867             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9868                 return false;
9869             }
9870             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9871                 return false;
9872             }
9873             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9874                 return false;
9875             }
9876             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9877                 return false;
9878             }
9879             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9880                 return false;
9881             }
9882             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9883                 return false;
9884             }
9885             p = d.getPolygons().get( 1 );
9886             if ( p.getPoints().size() != 3 ) {
9887                 return false;
9888             }
9889             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9890                 return false;
9891             }
9892             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9893                 return false;
9894             }
9895             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9896                 return false;
9897             }
9898         }
9899         catch ( final Exception e ) {
9900             e.printStackTrace( System.out );
9901             return false;
9902         }
9903         return true;
9904     }
9905
9906     private static boolean testPostOrderIterator() {
9907         try {
9908             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9909             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9910             PhylogenyNodeIterator it0;
9911             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
9912                 it0.next();
9913             }
9914             for( it0.reset(); it0.hasNext(); ) {
9915                 it0.next();
9916             }
9917             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9918             final PhylogenyNodeIterator it = t1.iteratorPostorder();
9919             if ( !it.next().getName().equals( "A" ) ) {
9920                 return false;
9921             }
9922             if ( !it.next().getName().equals( "B" ) ) {
9923                 return false;
9924             }
9925             if ( !it.next().getName().equals( "ab" ) ) {
9926                 return false;
9927             }
9928             if ( !it.next().getName().equals( "C" ) ) {
9929                 return false;
9930             }
9931             if ( !it.next().getName().equals( "D" ) ) {
9932                 return false;
9933             }
9934             if ( !it.next().getName().equals( "cd" ) ) {
9935                 return false;
9936             }
9937             if ( !it.next().getName().equals( "abcd" ) ) {
9938                 return false;
9939             }
9940             if ( !it.next().getName().equals( "E" ) ) {
9941                 return false;
9942             }
9943             if ( !it.next().getName().equals( "F" ) ) {
9944                 return false;
9945             }
9946             if ( !it.next().getName().equals( "ef" ) ) {
9947                 return false;
9948             }
9949             if ( !it.next().getName().equals( "G" ) ) {
9950                 return false;
9951             }
9952             if ( !it.next().getName().equals( "H" ) ) {
9953                 return false;
9954             }
9955             if ( !it.next().getName().equals( "gh" ) ) {
9956                 return false;
9957             }
9958             if ( !it.next().getName().equals( "efgh" ) ) {
9959                 return false;
9960             }
9961             if ( !it.next().getName().equals( "r" ) ) {
9962                 return false;
9963             }
9964             if ( it.hasNext() ) {
9965                 return false;
9966             }
9967         }
9968         catch ( final Exception e ) {
9969             e.printStackTrace( System.out );
9970             return false;
9971         }
9972         return true;
9973     }
9974
9975     private static boolean testPreOrderIterator() {
9976         try {
9977             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9978             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9979             PhylogenyNodeIterator it0;
9980             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
9981                 it0.next();
9982             }
9983             for( it0.reset(); it0.hasNext(); ) {
9984                 it0.next();
9985             }
9986             PhylogenyNodeIterator it = t0.iteratorPreorder();
9987             if ( !it.next().getName().equals( "r" ) ) {
9988                 return false;
9989             }
9990             if ( !it.next().getName().equals( "ab" ) ) {
9991                 return false;
9992             }
9993             if ( !it.next().getName().equals( "A" ) ) {
9994                 return false;
9995             }
9996             if ( !it.next().getName().equals( "B" ) ) {
9997                 return false;
9998             }
9999             if ( !it.next().getName().equals( "cd" ) ) {
10000                 return false;
10001             }
10002             if ( !it.next().getName().equals( "C" ) ) {
10003                 return false;
10004             }
10005             if ( !it.next().getName().equals( "D" ) ) {
10006                 return false;
10007             }
10008             if ( it.hasNext() ) {
10009                 return false;
10010             }
10011             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10012             it = t1.iteratorPreorder();
10013             if ( !it.next().getName().equals( "r" ) ) {
10014                 return false;
10015             }
10016             if ( !it.next().getName().equals( "abcd" ) ) {
10017                 return false;
10018             }
10019             if ( !it.next().getName().equals( "ab" ) ) {
10020                 return false;
10021             }
10022             if ( !it.next().getName().equals( "A" ) ) {
10023                 return false;
10024             }
10025             if ( !it.next().getName().equals( "B" ) ) {
10026                 return false;
10027             }
10028             if ( !it.next().getName().equals( "cd" ) ) {
10029                 return false;
10030             }
10031             if ( !it.next().getName().equals( "C" ) ) {
10032                 return false;
10033             }
10034             if ( !it.next().getName().equals( "D" ) ) {
10035                 return false;
10036             }
10037             if ( !it.next().getName().equals( "efgh" ) ) {
10038                 return false;
10039             }
10040             if ( !it.next().getName().equals( "ef" ) ) {
10041                 return false;
10042             }
10043             if ( !it.next().getName().equals( "E" ) ) {
10044                 return false;
10045             }
10046             if ( !it.next().getName().equals( "F" ) ) {
10047                 return false;
10048             }
10049             if ( !it.next().getName().equals( "gh" ) ) {
10050                 return false;
10051             }
10052             if ( !it.next().getName().equals( "G" ) ) {
10053                 return false;
10054             }
10055             if ( !it.next().getName().equals( "H" ) ) {
10056                 return false;
10057             }
10058             if ( it.hasNext() ) {
10059                 return false;
10060             }
10061         }
10062         catch ( final Exception e ) {
10063             e.printStackTrace( System.out );
10064             return false;
10065         }
10066         return true;
10067     }
10068
10069     private static boolean testPropertiesMap() {
10070         try {
10071             final PropertiesMap pm = new PropertiesMap();
10072             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10073             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10074             final Property p2 = new Property( "something:else",
10075                                               "?",
10076                                               "improbable:research",
10077                                               "xsd:decimal",
10078                                               AppliesTo.NODE );
10079             pm.addProperty( p0 );
10080             pm.addProperty( p1 );
10081             pm.addProperty( p2 );
10082             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
10083                 return false;
10084             }
10085             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
10086                 return false;
10087             }
10088             if ( pm.getProperties().size() != 3 ) {
10089                 return false;
10090             }
10091             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
10092                 return false;
10093             }
10094             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10095                 return false;
10096             }
10097             if ( pm.getProperties().size() != 3 ) {
10098                 return false;
10099             }
10100             pm.removeProperty( "dimensions:diameter" );
10101             if ( pm.getProperties().size() != 2 ) {
10102                 return false;
10103             }
10104             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
10105                 return false;
10106             }
10107             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10108                 return false;
10109             }
10110         }
10111         catch ( final Exception e ) {
10112             e.printStackTrace( System.out );
10113             return false;
10114         }
10115         return true;
10116     }
10117
10118     private static boolean testProteinId() {
10119         try {
10120             final ProteinId id1 = new ProteinId( "a" );
10121             final ProteinId id2 = new ProteinId( "a" );
10122             final ProteinId id3 = new ProteinId( "A" );
10123             final ProteinId id4 = new ProteinId( "b" );
10124             if ( !id1.equals( id1 ) ) {
10125                 return false;
10126             }
10127             if ( id1.getId().equals( "x" ) ) {
10128                 return false;
10129             }
10130             if ( id1.getId().equals( null ) ) {
10131                 return false;
10132             }
10133             if ( !id1.equals( id2 ) ) {
10134                 return false;
10135             }
10136             if ( id1.equals( id3 ) ) {
10137                 return false;
10138             }
10139             if ( id1.hashCode() != id1.hashCode() ) {
10140                 return false;
10141             }
10142             if ( id1.hashCode() != id2.hashCode() ) {
10143                 return false;
10144             }
10145             if ( id1.hashCode() == id3.hashCode() ) {
10146                 return false;
10147             }
10148             if ( id1.compareTo( id1 ) != 0 ) {
10149                 return false;
10150             }
10151             if ( id1.compareTo( id2 ) != 0 ) {
10152                 return false;
10153             }
10154             if ( id1.compareTo( id3 ) != 0 ) {
10155                 return false;
10156             }
10157             if ( id1.compareTo( id4 ) >= 0 ) {
10158                 return false;
10159             }
10160             if ( id4.compareTo( id1 ) <= 0 ) {
10161                 return false;
10162             }
10163             if ( !id4.getId().equals( "b" ) ) {
10164                 return false;
10165             }
10166             final ProteinId id5 = new ProteinId( " C " );
10167             if ( !id5.getId().equals( "C" ) ) {
10168                 return false;
10169             }
10170             if ( id5.equals( id1 ) ) {
10171                 return false;
10172             }
10173         }
10174         catch ( final Exception e ) {
10175             e.printStackTrace( System.out );
10176             return false;
10177         }
10178         return true;
10179     }
10180
10181     private static boolean testReIdMethods() {
10182         try {
10183             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10184             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
10185             final long count = PhylogenyNode.getNodeCount();
10186             p.levelOrderReID();
10187             if ( p.getNode( "r" ).getId() != count ) {
10188                 return false;
10189             }
10190             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
10191                 return false;
10192             }
10193             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
10194                 return false;
10195             }
10196             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
10197                 return false;
10198             }
10199             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
10200                 return false;
10201             }
10202             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
10203                 return false;
10204             }
10205             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
10206                 return false;
10207             }
10208             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
10209                 return false;
10210             }
10211             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
10212                 return false;
10213             }
10214             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
10215                 return false;
10216             }
10217             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
10218                 return false;
10219             }
10220             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
10221                 return false;
10222             }
10223             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
10224                 return false;
10225             }
10226             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
10227                 return false;
10228             }
10229             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
10230                 return false;
10231             }
10232         }
10233         catch ( final Exception e ) {
10234             e.printStackTrace( System.out );
10235             return false;
10236         }
10237         return true;
10238     }
10239
10240     private static boolean testRerooting() {
10241         try {
10242             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10243             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",
10244                                                  new NHXParser() )[ 0 ];
10245             if ( !t1.isRooted() ) {
10246                 return false;
10247             }
10248             t1.reRoot( t1.getNode( "D" ) );
10249             t1.reRoot( t1.getNode( "CD" ) );
10250             t1.reRoot( t1.getNode( "A" ) );
10251             t1.reRoot( t1.getNode( "B" ) );
10252             t1.reRoot( t1.getNode( "AB" ) );
10253             t1.reRoot( t1.getNode( "D" ) );
10254             t1.reRoot( t1.getNode( "C" ) );
10255             t1.reRoot( t1.getNode( "CD" ) );
10256             t1.reRoot( t1.getNode( "A" ) );
10257             t1.reRoot( t1.getNode( "B" ) );
10258             t1.reRoot( t1.getNode( "AB" ) );
10259             t1.reRoot( t1.getNode( "D" ) );
10260             t1.reRoot( t1.getNode( "D" ) );
10261             t1.reRoot( t1.getNode( "C" ) );
10262             t1.reRoot( t1.getNode( "A" ) );
10263             t1.reRoot( t1.getNode( "B" ) );
10264             t1.reRoot( t1.getNode( "AB" ) );
10265             t1.reRoot( t1.getNode( "C" ) );
10266             t1.reRoot( t1.getNode( "D" ) );
10267             t1.reRoot( t1.getNode( "CD" ) );
10268             t1.reRoot( t1.getNode( "D" ) );
10269             t1.reRoot( t1.getNode( "A" ) );
10270             t1.reRoot( t1.getNode( "B" ) );
10271             t1.reRoot( t1.getNode( "AB" ) );
10272             t1.reRoot( t1.getNode( "C" ) );
10273             t1.reRoot( t1.getNode( "D" ) );
10274             t1.reRoot( t1.getNode( "CD" ) );
10275             t1.reRoot( t1.getNode( "D" ) );
10276             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
10277                 return false;
10278             }
10279             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
10280                 return false;
10281             }
10282             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
10283                 return false;
10284             }
10285             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
10286                 return false;
10287             }
10288             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
10289                 return false;
10290             }
10291             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
10292                 return false;
10293             }
10294             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",
10295                                                  new NHXParser() )[ 0 ];
10296             t2.reRoot( t2.getNode( "A" ) );
10297             t2.reRoot( t2.getNode( "D" ) );
10298             t2.reRoot( t2.getNode( "ABC" ) );
10299             t2.reRoot( t2.getNode( "A" ) );
10300             t2.reRoot( t2.getNode( "B" ) );
10301             t2.reRoot( t2.getNode( "D" ) );
10302             t2.reRoot( t2.getNode( "C" ) );
10303             t2.reRoot( t2.getNode( "ABC" ) );
10304             t2.reRoot( t2.getNode( "A" ) );
10305             t2.reRoot( t2.getNode( "B" ) );
10306             t2.reRoot( t2.getNode( "AB" ) );
10307             t2.reRoot( t2.getNode( "AB" ) );
10308             t2.reRoot( t2.getNode( "D" ) );
10309             t2.reRoot( t2.getNode( "C" ) );
10310             t2.reRoot( t2.getNode( "B" ) );
10311             t2.reRoot( t2.getNode( "AB" ) );
10312             t2.reRoot( t2.getNode( "D" ) );
10313             t2.reRoot( t2.getNode( "D" ) );
10314             t2.reRoot( t2.getNode( "ABC" ) );
10315             t2.reRoot( t2.getNode( "A" ) );
10316             t2.reRoot( t2.getNode( "B" ) );
10317             t2.reRoot( t2.getNode( "AB" ) );
10318             t2.reRoot( t2.getNode( "D" ) );
10319             t2.reRoot( t2.getNode( "C" ) );
10320             t2.reRoot( t2.getNode( "ABC" ) );
10321             t2.reRoot( t2.getNode( "A" ) );
10322             t2.reRoot( t2.getNode( "B" ) );
10323             t2.reRoot( t2.getNode( "AB" ) );
10324             t2.reRoot( t2.getNode( "D" ) );
10325             t2.reRoot( t2.getNode( "D" ) );
10326             t2.reRoot( t2.getNode( "C" ) );
10327             t2.reRoot( t2.getNode( "A" ) );
10328             t2.reRoot( t2.getNode( "B" ) );
10329             t2.reRoot( t2.getNode( "AB" ) );
10330             t2.reRoot( t2.getNode( "C" ) );
10331             t2.reRoot( t2.getNode( "D" ) );
10332             t2.reRoot( t2.getNode( "ABC" ) );
10333             t2.reRoot( t2.getNode( "D" ) );
10334             t2.reRoot( t2.getNode( "A" ) );
10335             t2.reRoot( t2.getNode( "B" ) );
10336             t2.reRoot( t2.getNode( "AB" ) );
10337             t2.reRoot( t2.getNode( "C" ) );
10338             t2.reRoot( t2.getNode( "D" ) );
10339             t2.reRoot( t2.getNode( "ABC" ) );
10340             t2.reRoot( t2.getNode( "D" ) );
10341             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10342                 return false;
10343             }
10344             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10345                 return false;
10346             }
10347             t2.reRoot( t2.getNode( "ABC" ) );
10348             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10349                 return false;
10350             }
10351             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10352                 return false;
10353             }
10354             t2.reRoot( t2.getNode( "AB" ) );
10355             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10356                 return false;
10357             }
10358             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10359                 return false;
10360             }
10361             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10362                 return false;
10363             }
10364             t2.reRoot( t2.getNode( "AB" ) );
10365             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10366                 return false;
10367             }
10368             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10369                 return false;
10370             }
10371             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10372                 return false;
10373             }
10374             t2.reRoot( t2.getNode( "D" ) );
10375             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10376                 return false;
10377             }
10378             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10379                 return false;
10380             }
10381             t2.reRoot( t2.getNode( "ABC" ) );
10382             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10383                 return false;
10384             }
10385             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10386                 return false;
10387             }
10388             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
10389                                                  new NHXParser() )[ 0 ];
10390             t3.reRoot( t3.getNode( "B" ) );
10391             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10392                 return false;
10393             }
10394             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10395                 return false;
10396             }
10397             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10398                 return false;
10399             }
10400             t3.reRoot( t3.getNode( "B" ) );
10401             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10402                 return false;
10403             }
10404             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10405                 return false;
10406             }
10407             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10408                 return false;
10409             }
10410             t3.reRoot( t3.getRoot() );
10411             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10412                 return false;
10413             }
10414             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10415                 return false;
10416             }
10417             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10418                 return false;
10419             }
10420         }
10421         catch ( final Exception e ) {
10422             e.printStackTrace( System.out );
10423             return false;
10424         }
10425         return true;
10426     }
10427
10428     private static boolean testSDIse() {
10429         try {
10430             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10431             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
10432             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
10433             gene1.setRooted( true );
10434             species1.setRooted( true );
10435             final SDI sdi = new SDI( gene1, species1 );
10436             if ( !gene1.getRoot().isDuplication() ) {
10437                 return false;
10438             }
10439             final Phylogeny species2 = factory
10440                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10441                              new NHXParser() )[ 0 ];
10442             final Phylogeny gene2 = factory
10443                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10444                              new NHXParser() )[ 0 ];
10445             species2.setRooted( true );
10446             gene2.setRooted( true );
10447             final SDI sdi2 = new SDI( gene2, species2 );
10448             if ( sdi2.getDuplicationsSum() != 0 ) {
10449                 return false;
10450             }
10451             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
10452                 return false;
10453             }
10454             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
10455                 return false;
10456             }
10457             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
10458                 return false;
10459             }
10460             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
10461                 return false;
10462             }
10463             if ( !gene2.getNode( "r" ).isSpeciation() ) {
10464                 return false;
10465             }
10466             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
10467                 return false;
10468             }
10469             final Phylogeny species3 = factory
10470                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10471                              new NHXParser() )[ 0 ];
10472             final Phylogeny gene3 = factory
10473                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10474                              new NHXParser() )[ 0 ];
10475             species3.setRooted( true );
10476             gene3.setRooted( true );
10477             final SDI sdi3 = new SDI( gene3, species3 );
10478             if ( sdi3.getDuplicationsSum() != 1 ) {
10479                 return false;
10480             }
10481             if ( !gene3.getNode( "aa" ).isDuplication() ) {
10482                 return false;
10483             }
10484             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
10485                 return false;
10486             }
10487             final Phylogeny species4 = factory
10488                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10489                              new NHXParser() )[ 0 ];
10490             final Phylogeny gene4 = factory
10491                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10492                              new NHXParser() )[ 0 ];
10493             species4.setRooted( true );
10494             gene4.setRooted( true );
10495             final SDI sdi4 = new SDI( gene4, species4 );
10496             if ( sdi4.getDuplicationsSum() != 1 ) {
10497                 return false;
10498             }
10499             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
10500                 return false;
10501             }
10502             if ( !gene4.getNode( "abc" ).isDuplication() ) {
10503                 return false;
10504             }
10505             if ( gene4.getNode( "abcd" ).isDuplication() ) {
10506                 return false;
10507             }
10508             if ( species4.getNumberOfExternalNodes() != 6 ) {
10509                 return false;
10510             }
10511             if ( gene4.getNumberOfExternalNodes() != 6 ) {
10512                 return false;
10513             }
10514             final Phylogeny species5 = factory
10515                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10516                              new NHXParser() )[ 0 ];
10517             final Phylogeny gene5 = factory
10518                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10519                              new NHXParser() )[ 0 ];
10520             species5.setRooted( true );
10521             gene5.setRooted( true );
10522             final SDI sdi5 = new SDI( gene5, species5 );
10523             if ( sdi5.getDuplicationsSum() != 2 ) {
10524                 return false;
10525             }
10526             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
10527                 return false;
10528             }
10529             if ( !gene5.getNode( "adc" ).isDuplication() ) {
10530                 return false;
10531             }
10532             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
10533                 return false;
10534             }
10535             if ( species5.getNumberOfExternalNodes() != 6 ) {
10536                 return false;
10537             }
10538             if ( gene5.getNumberOfExternalNodes() != 6 ) {
10539                 return false;
10540             }
10541             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
10542             // Conjecture for Comparing Molecular Phylogenies"
10543             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
10544             final Phylogeny species6 = factory
10545                     .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,"
10546                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10547                              new NHXParser() )[ 0 ];
10548             final Phylogeny gene6 = factory
10549                     .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,"
10550                                      + "((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,"
10551                                      + "(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;",
10552                              new NHXParser() )[ 0 ];
10553             species6.setRooted( true );
10554             gene6.setRooted( true );
10555             final SDI sdi6 = new SDI( gene6, species6 );
10556             if ( sdi6.getDuplicationsSum() != 3 ) {
10557                 return false;
10558             }
10559             if ( !gene6.getNode( "r" ).isDuplication() ) {
10560                 return false;
10561             }
10562             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
10563                 return false;
10564             }
10565             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
10566                 return false;
10567             }
10568             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
10569                 return false;
10570             }
10571             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
10572                 return false;
10573             }
10574             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
10575                 return false;
10576             }
10577             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
10578                 return false;
10579             }
10580             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
10581                 return false;
10582             }
10583             sdi6.computeMappingCostL();
10584             if ( sdi6.computeMappingCostL() != 17 ) {
10585                 return false;
10586             }
10587             if ( species6.getNumberOfExternalNodes() != 9 ) {
10588                 return false;
10589             }
10590             if ( gene6.getNumberOfExternalNodes() != 9 ) {
10591                 return false;
10592             }
10593             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
10594                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
10595                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
10596                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
10597                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
10598             species7.setRooted( true );
10599             final Phylogeny gene7_1 = Test
10600                     .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])" );
10601             gene7_1.setRooted( true );
10602             final SDI sdi7 = new SDI( gene7_1, species7 );
10603             if ( sdi7.getDuplicationsSum() != 0 ) {
10604                 return false;
10605             }
10606             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
10607                 return false;
10608             }
10609             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
10610                 return false;
10611             }
10612             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
10613                 return false;
10614             }
10615             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
10616                 return false;
10617             }
10618             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
10619                 return false;
10620             }
10621             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
10622                 return false;
10623             }
10624             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
10625                 return false;
10626             }
10627             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
10628                 return false;
10629             }
10630             final Phylogeny gene7_2 = Test
10631                     .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])" );
10632             gene7_2.setRooted( true );
10633             final SDI sdi7_2 = new SDI( gene7_2, species7 );
10634             if ( sdi7_2.getDuplicationsSum() != 1 ) {
10635                 return false;
10636             }
10637             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
10638                 return false;
10639             }
10640             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
10641                 return false;
10642             }
10643             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
10644                 return false;
10645             }
10646             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
10647                 return false;
10648             }
10649             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
10650                 return false;
10651             }
10652             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
10653                 return false;
10654             }
10655             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
10656                 return false;
10657             }
10658             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
10659                 return false;
10660             }
10661             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
10662                 return false;
10663             }
10664         }
10665         catch ( final Exception e ) {
10666             return false;
10667         }
10668         return true;
10669     }
10670
10671     private static boolean testSDIunrooted() {
10672         try {
10673             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10674             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
10675             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
10676             final Iterator<PhylogenyBranch> iter = l.iterator();
10677             PhylogenyBranch br = iter.next();
10678             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
10679                 return false;
10680             }
10681             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
10682                 return false;
10683             }
10684             br = iter.next();
10685             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10686                 return false;
10687             }
10688             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10689                 return false;
10690             }
10691             br = iter.next();
10692             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
10693                 return false;
10694             }
10695             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
10696                 return false;
10697             }
10698             br = iter.next();
10699             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10700                 return false;
10701             }
10702             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10703                 return false;
10704             }
10705             br = iter.next();
10706             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10707                 return false;
10708             }
10709             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10710                 return false;
10711             }
10712             br = iter.next();
10713             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10714                 return false;
10715             }
10716             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10717                 return false;
10718             }
10719             br = iter.next();
10720             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10721                 return false;
10722             }
10723             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10724                 return false;
10725             }
10726             br = iter.next();
10727             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10728                 return false;
10729             }
10730             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10731                 return false;
10732             }
10733             br = iter.next();
10734             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10735                 return false;
10736             }
10737             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10738                 return false;
10739             }
10740             br = iter.next();
10741             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10742                 return false;
10743             }
10744             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10745                 return false;
10746             }
10747             br = iter.next();
10748             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10749                 return false;
10750             }
10751             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10752                 return false;
10753             }
10754             br = iter.next();
10755             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
10756                 return false;
10757             }
10758             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
10759                 return false;
10760             }
10761             br = iter.next();
10762             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10763                 return false;
10764             }
10765             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10766                 return false;
10767             }
10768             br = iter.next();
10769             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
10770                 return false;
10771             }
10772             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
10773                 return false;
10774             }
10775             br = iter.next();
10776             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
10777                 return false;
10778             }
10779             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
10780                 return false;
10781             }
10782             if ( iter.hasNext() ) {
10783                 return false;
10784             }
10785             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
10786             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
10787             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
10788             br = iter1.next();
10789             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10790                 return false;
10791             }
10792             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10793                 return false;
10794             }
10795             br = iter1.next();
10796             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10797                 return false;
10798             }
10799             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10800                 return false;
10801             }
10802             br = iter1.next();
10803             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10804                 return false;
10805             }
10806             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10807                 return false;
10808             }
10809             if ( iter1.hasNext() ) {
10810                 return false;
10811             }
10812             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
10813             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
10814             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
10815             br = iter2.next();
10816             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10817                 return false;
10818             }
10819             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10820                 return false;
10821             }
10822             br = iter2.next();
10823             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10824                 return false;
10825             }
10826             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10827                 return false;
10828             }
10829             br = iter2.next();
10830             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10831                 return false;
10832             }
10833             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10834                 return false;
10835             }
10836             if ( iter2.hasNext() ) {
10837                 return false;
10838             }
10839             final Phylogeny species0 = factory
10840                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10841                              new NHXParser() )[ 0 ];
10842             final Phylogeny gene1 = factory
10843                     .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])",
10844                              new NHXParser() )[ 0 ];
10845             species0.setRooted( true );
10846             gene1.setRooted( true );
10847             final SDIR sdi_unrooted = new SDIR();
10848             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
10849             if ( sdi_unrooted.getCount() != 1 ) {
10850                 return false;
10851             }
10852             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
10853                 return false;
10854             }
10855             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
10856                 return false;
10857             }
10858             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
10859                 return false;
10860             }
10861             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10862                 return false;
10863             }
10864             final Phylogeny gene2 = factory
10865                     .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])",
10866                              new NHXParser() )[ 0 ];
10867             gene2.setRooted( true );
10868             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
10869             if ( sdi_unrooted.getCount() != 1 ) {
10870                 return false;
10871             }
10872             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10873                 return false;
10874             }
10875             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10876                 return false;
10877             }
10878             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
10879                 return false;
10880             }
10881             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10882                 return false;
10883             }
10884             final Phylogeny species6 = factory
10885                     .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,"
10886                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10887                              new NHXParser() )[ 0 ];
10888             final Phylogeny gene6 = factory
10889                     .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],"
10890                                      + "(((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],"
10891                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10892                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10893                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10894                              new NHXParser() )[ 0 ];
10895             species6.setRooted( true );
10896             gene6.setRooted( true );
10897             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
10898             if ( sdi_unrooted.getCount() != 1 ) {
10899                 return false;
10900             }
10901             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10902                 return false;
10903             }
10904             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10905                 return false;
10906             }
10907             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10908                 return false;
10909             }
10910             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10911                 return false;
10912             }
10913             if ( !p6[ 0 ].getRoot().isDuplication() ) {
10914                 return false;
10915             }
10916             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10917                 return false;
10918             }
10919             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10920                 return false;
10921             }
10922             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
10923                 return false;
10924             }
10925             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10926                 return false;
10927             }
10928             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
10929                 return false;
10930             }
10931             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
10932                 return false;
10933             }
10934             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10935                 return false;
10936             }
10937             p6 = null;
10938             final Phylogeny species7 = factory
10939                     .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,"
10940                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10941                              new NHXParser() )[ 0 ];
10942             final Phylogeny gene7 = factory
10943                     .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],"
10944                                      + "(((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],"
10945                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10946                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10947                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10948                              new NHXParser() )[ 0 ];
10949             species7.setRooted( true );
10950             gene7.setRooted( true );
10951             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
10952             if ( sdi_unrooted.getCount() != 1 ) {
10953                 return false;
10954             }
10955             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10956                 return false;
10957             }
10958             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10959                 return false;
10960             }
10961             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10962                 return false;
10963             }
10964             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
10965                 return false;
10966             }
10967             if ( !p7[ 0 ].getRoot().isDuplication() ) {
10968                 return false;
10969             }
10970             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10971                 return false;
10972             }
10973             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10974                 return false;
10975             }
10976             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
10977                 return false;
10978             }
10979             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10980                 return false;
10981             }
10982             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
10983                 return false;
10984             }
10985             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
10986                 return false;
10987             }
10988             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10989                 return false;
10990             }
10991             p7 = null;
10992             final Phylogeny species8 = factory
10993                     .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,"
10994                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10995                              new NHXParser() )[ 0 ];
10996             final Phylogeny gene8 = factory
10997                     .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],"
10998                                      + "(((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],"
10999                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11000                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11001                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11002                              new NHXParser() )[ 0 ];
11003             species8.setRooted( true );
11004             gene8.setRooted( true );
11005             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
11006             if ( sdi_unrooted.getCount() != 1 ) {
11007                 return false;
11008             }
11009             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11010                 return false;
11011             }
11012             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11013                 return false;
11014             }
11015             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11016                 return false;
11017             }
11018             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11019                 return false;
11020             }
11021             if ( !p8[ 0 ].getRoot().isDuplication() ) {
11022                 return false;
11023             }
11024             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11025                 return false;
11026             }
11027             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11028                 return false;
11029             }
11030             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
11031                 return false;
11032             }
11033             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11034                 return false;
11035             }
11036             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
11037                 return false;
11038             }
11039             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
11040                 return false;
11041             }
11042             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11043                 return false;
11044             }
11045             p8 = null;
11046         }
11047         catch ( final Exception e ) {
11048             e.printStackTrace( System.out );
11049             return false;
11050         }
11051         return true;
11052     }
11053
11054     private static boolean testSequenceDbWsTools1() {
11055         try {
11056             final PhylogenyNode n = new PhylogenyNode();
11057             n.setName( "NP_001025424" );
11058             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
11059             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11060                     || !acc.getValue().equals( "NP_001025424" ) ) {
11061                 return false;
11062             }
11063             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
11064             acc = SequenceDbWsTools.obtainSeqAccession( n );
11065             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11066                     || !acc.getValue().equals( "NP_001025424" ) ) {
11067                 return false;
11068             }
11069             n.setName( "NP_001025424.1" );
11070             acc = SequenceDbWsTools.obtainSeqAccession( n );
11071             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11072                     || !acc.getValue().equals( "NP_001025424" ) ) {
11073                 return false;
11074             }
11075             n.setName( "NM_001030253" );
11076             acc = SequenceDbWsTools.obtainSeqAccession( n );
11077             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11078                     || !acc.getValue().equals( "NM_001030253" ) ) {
11079                 return false;
11080             }
11081             n.setName( "BCL2_HUMAN" );
11082             acc = SequenceDbWsTools.obtainSeqAccession( n );
11083             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11084                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
11085                 System.out.println( acc.toString() );
11086                 return false;
11087             }
11088             n.setName( "P10415" );
11089             acc = SequenceDbWsTools.obtainSeqAccession( n );
11090             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11091                     || !acc.getValue().equals( "P10415" ) ) {
11092                 System.out.println( acc.toString() );
11093                 return false;
11094             }
11095             n.setName( " P10415 " );
11096             acc = SequenceDbWsTools.obtainSeqAccession( n );
11097             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11098                     || !acc.getValue().equals( "P10415" ) ) {
11099                 System.out.println( acc.toString() );
11100                 return false;
11101             }
11102             n.setName( "_P10415|" );
11103             acc = SequenceDbWsTools.obtainSeqAccession( n );
11104             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11105                     || !acc.getValue().equals( "P10415" ) ) {
11106                 System.out.println( acc.toString() );
11107                 return false;
11108             }
11109             n.setName( "AY695820" );
11110             acc = SequenceDbWsTools.obtainSeqAccession( n );
11111             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11112                     || !acc.getValue().equals( "AY695820" ) ) {
11113                 System.out.println( acc.toString() );
11114                 return false;
11115             }
11116             n.setName( "_AY695820_" );
11117             acc = SequenceDbWsTools.obtainSeqAccession( n );
11118             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11119                     || !acc.getValue().equals( "AY695820" ) ) {
11120                 System.out.println( acc.toString() );
11121                 return false;
11122             }
11123             n.setName( "AAA59452" );
11124             acc = SequenceDbWsTools.obtainSeqAccession( n );
11125             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11126                     || !acc.getValue().equals( "AAA59452" ) ) {
11127                 System.out.println( acc.toString() );
11128                 return false;
11129             }
11130             n.setName( "_AAA59452_" );
11131             acc = SequenceDbWsTools.obtainSeqAccession( n );
11132             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11133                     || !acc.getValue().equals( "AAA59452" ) ) {
11134                 System.out.println( acc.toString() );
11135                 return false;
11136             }
11137             n.setName( "AAA59452.1" );
11138             acc = SequenceDbWsTools.obtainSeqAccession( n );
11139             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11140                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11141                 System.out.println( acc.toString() );
11142                 return false;
11143             }
11144             n.setName( "_AAA59452.1_" );
11145             acc = SequenceDbWsTools.obtainSeqAccession( n );
11146             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11147                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11148                 System.out.println( acc.toString() );
11149                 return false;
11150             }
11151             n.setName( "GI:94894583" );
11152             acc = SequenceDbWsTools.obtainSeqAccession( n );
11153             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11154                     || !acc.getValue().equals( "94894583" ) ) {
11155                 System.out.println( acc.toString() );
11156                 return false;
11157             }
11158             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11159             acc = SequenceDbWsTools.obtainSeqAccession( n );
11160             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11161                     || !acc.getValue().equals( "71845847" ) ) {
11162                 System.out.println( acc.toString() );
11163                 return false;
11164             }
11165             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11166             acc = SequenceDbWsTools.obtainSeqAccession( n );
11167             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11168                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
11169                 System.out.println( acc.toString() );
11170                 return false;
11171             }
11172         }
11173         catch ( final Exception e ) {
11174             return false;
11175         }
11176         return true;
11177     }
11178
11179     private static boolean testSequenceDbWsTools2() {
11180         try {
11181             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
11182             SequenceDbWsTools.obtainSeqInformation( n1 );
11183             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
11184                 return false;
11185             }
11186             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11187                 return false;
11188             }
11189             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11190                 return false;
11191             }
11192             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
11193                 return false;
11194             }
11195             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
11196             SequenceDbWsTools.obtainSeqInformation( n2 );
11197             if ( !n2.getNodeData().getSequence().getName()
11198                     .equals( "Danio rerio B-cell leukemia/lymphoma 2 (bcl2), mRNA" ) ) {
11199                 return false;
11200             }
11201             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11202                 return false;
11203             }
11204             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11205                 return false;
11206             }
11207             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
11208                 return false;
11209             }
11210             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
11211             SequenceDbWsTools.obtainSeqInformation( n3 );
11212             if ( !n3.getNodeData().getSequence().getName()
11213                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
11214                 return false;
11215             }
11216             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
11217                 return false;
11218             }
11219             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11220                 return false;
11221             }
11222             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
11223                 return false;
11224             }
11225         }
11226         catch ( final IOException e ) {
11227             System.out.println();
11228             System.out.println( "the following might be due to absence internet connection:" );
11229             e.printStackTrace( System.out );
11230             return true;
11231         }
11232         catch ( final Exception e ) {
11233             e.printStackTrace();
11234             return false;
11235         }
11236         return true;
11237     }
11238
11239     private static boolean testSequenceIdParsing() {
11240         try {
11241             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
11242             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11243                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11244                 if ( id != null ) {
11245                     System.out.println( "value   =" + id.getValue() );
11246                     System.out.println( "provider=" + id.getSource() );
11247                 }
11248                 return false;
11249             }
11250             //
11251             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
11252             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11253                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11254                 if ( id != null ) {
11255                     System.out.println( "value   =" + id.getValue() );
11256                     System.out.println( "provider=" + id.getSource() );
11257                 }
11258                 return false;
11259             }
11260             //
11261             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
11262             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11263                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11264                 if ( id != null ) {
11265                     System.out.println( "value   =" + id.getValue() );
11266                     System.out.println( "provider=" + id.getSource() );
11267                 }
11268                 return false;
11269             }
11270             // 
11271             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
11272             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11273                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
11274                 if ( id != null ) {
11275                     System.out.println( "value   =" + id.getValue() );
11276                     System.out.println( "provider=" + id.getSource() );
11277                 }
11278                 return false;
11279             }
11280             // 
11281             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
11282             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11283                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
11284                 if ( id != null ) {
11285                     System.out.println( "value   =" + id.getValue() );
11286                     System.out.println( "provider=" + id.getSource() );
11287                 }
11288                 return false;
11289             }
11290             // 
11291             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
11292             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11293                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
11294                 if ( id != null ) {
11295                     System.out.println( "value   =" + id.getValue() );
11296                     System.out.println( "provider=" + id.getSource() );
11297                 }
11298                 return false;
11299             }
11300             // 
11301             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
11302             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11303                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
11304                 if ( id != null ) {
11305                     System.out.println( "value   =" + id.getValue() );
11306                     System.out.println( "provider=" + id.getSource() );
11307                 }
11308                 return false;
11309             }
11310             // 
11311             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
11312             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11313                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11314                 if ( id != null ) {
11315                     System.out.println( "value   =" + id.getValue() );
11316                     System.out.println( "provider=" + id.getSource() );
11317                 }
11318                 return false;
11319             }
11320             // 
11321             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
11322             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11323                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11324                 if ( id != null ) {
11325                     System.out.println( "value   =" + id.getValue() );
11326                     System.out.println( "provider=" + id.getSource() );
11327                 }
11328                 return false;
11329             }
11330             // 
11331             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
11332             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11333                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
11334                 if ( id != null ) {
11335                     System.out.println( "value   =" + id.getValue() );
11336                     System.out.println( "provider=" + id.getSource() );
11337                 }
11338                 return false;
11339             }
11340             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
11341             if ( id != null ) {
11342                 System.out.println( "value   =" + id.getValue() );
11343                 System.out.println( "provider=" + id.getSource() );
11344                 return false;
11345             }
11346         }
11347         catch ( final Exception e ) {
11348             e.printStackTrace( System.out );
11349             return false;
11350         }
11351         return true;
11352     }
11353
11354     private static boolean testSequenceWriter() {
11355         try {
11356             final String n = ForesterUtil.LINE_SEPARATOR;
11357             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
11358                 return false;
11359             }
11360             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
11361                 return false;
11362             }
11363             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
11364                 return false;
11365             }
11366             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
11367                 return false;
11368             }
11369             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
11370                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
11371                 return false;
11372             }
11373             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
11374                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
11375                 return false;
11376             }
11377         }
11378         catch ( final Exception e ) {
11379             e.printStackTrace();
11380             return false;
11381         }
11382         return true;
11383     }
11384
11385     private static boolean testSpecies() {
11386         try {
11387             final Species s1 = new BasicSpecies( "a" );
11388             final Species s2 = new BasicSpecies( "a" );
11389             final Species s3 = new BasicSpecies( "A" );
11390             final Species s4 = new BasicSpecies( "b" );
11391             if ( !s1.equals( s1 ) ) {
11392                 return false;
11393             }
11394             if ( s1.getSpeciesId().equals( "x" ) ) {
11395                 return false;
11396             }
11397             if ( s1.getSpeciesId().equals( null ) ) {
11398                 return false;
11399             }
11400             if ( !s1.equals( s2 ) ) {
11401                 return false;
11402             }
11403             if ( s1.equals( s3 ) ) {
11404                 return false;
11405             }
11406             if ( s1.hashCode() != s1.hashCode() ) {
11407                 return false;
11408             }
11409             if ( s1.hashCode() != s2.hashCode() ) {
11410                 return false;
11411             }
11412             if ( s1.hashCode() == s3.hashCode() ) {
11413                 return false;
11414             }
11415             if ( s1.compareTo( s1 ) != 0 ) {
11416                 return false;
11417             }
11418             if ( s1.compareTo( s2 ) != 0 ) {
11419                 return false;
11420             }
11421             if ( s1.compareTo( s3 ) != 0 ) {
11422                 return false;
11423             }
11424             if ( s1.compareTo( s4 ) >= 0 ) {
11425                 return false;
11426             }
11427             if ( s4.compareTo( s1 ) <= 0 ) {
11428                 return false;
11429             }
11430             if ( !s4.getSpeciesId().equals( "b" ) ) {
11431                 return false;
11432             }
11433             final Species s5 = new BasicSpecies( " C " );
11434             if ( !s5.getSpeciesId().equals( "C" ) ) {
11435                 return false;
11436             }
11437             if ( s5.equals( s1 ) ) {
11438                 return false;
11439             }
11440         }
11441         catch ( final Exception e ) {
11442             e.printStackTrace( System.out );
11443             return false;
11444         }
11445         return true;
11446     }
11447
11448     private static boolean testSplit() {
11449         try {
11450             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11451             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11452             //Archaeopteryx.createApplication( p0 );
11453             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11454             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11455             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11456             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11457             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11458             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11459             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11460             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11461             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11462             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11463             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
11464             // System.out.println( s0.toString() );
11465             //
11466             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11467             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11468             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11469             if ( s0.match( query_nodes ) ) {
11470                 return false;
11471             }
11472             query_nodes = new HashSet<PhylogenyNode>();
11473             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11474             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11475             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11476             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11477             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11478             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11479             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11480             if ( !s0.match( query_nodes ) ) {
11481                 return false;
11482             }
11483             //
11484             query_nodes = new HashSet<PhylogenyNode>();
11485             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
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( "D" ) );
11494             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11495             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11496             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11497             if ( !s0.match( query_nodes ) ) {
11498                 return false;
11499             }
11500             //
11501             query_nodes = new HashSet<PhylogenyNode>();
11502             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11503             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11504             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
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( "E" ) );
11512             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11513             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11514             if ( !s0.match( query_nodes ) ) {
11515                 return false;
11516             }
11517             //
11518             query_nodes = new HashSet<PhylogenyNode>();
11519             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11520             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11521             if ( !s0.match( query_nodes ) ) {
11522                 return false;
11523             }
11524             //
11525             query_nodes = new HashSet<PhylogenyNode>();
11526             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11527             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11528             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11529             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11530             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11531             if ( !s0.match( query_nodes ) ) {
11532                 return false;
11533             }
11534             //
11535             query_nodes = new HashSet<PhylogenyNode>();
11536             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11537             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11538             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11539             if ( !s0.match( query_nodes ) ) {
11540                 return false;
11541             }
11542             //
11543             query_nodes = new HashSet<PhylogenyNode>();
11544             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11545             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11546             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11547             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11548             if ( !s0.match( query_nodes ) ) {
11549                 return false;
11550             }
11551             //
11552             query_nodes = new HashSet<PhylogenyNode>();
11553             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11554             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11555             if ( s0.match( query_nodes ) ) {
11556                 return false;
11557             }
11558             //
11559             query_nodes = new HashSet<PhylogenyNode>();
11560             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11561             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11562             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11563             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11564             if ( s0.match( query_nodes ) ) {
11565                 return false;
11566             }
11567             //
11568             query_nodes = new HashSet<PhylogenyNode>();
11569             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11570             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11571             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11572             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11573             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11574             if ( s0.match( query_nodes ) ) {
11575                 return false;
11576             }
11577             //
11578             query_nodes = new HashSet<PhylogenyNode>();
11579             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11580             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11581             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11582             if ( s0.match( query_nodes ) ) {
11583                 return false;
11584             }
11585             //
11586             query_nodes = new HashSet<PhylogenyNode>();
11587             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11588             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11589             if ( s0.match( query_nodes ) ) {
11590                 return false;
11591             }
11592             //
11593             query_nodes = new HashSet<PhylogenyNode>();
11594             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11595             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11596             if ( s0.match( query_nodes ) ) {
11597                 return false;
11598             }
11599             //
11600             query_nodes = new HashSet<PhylogenyNode>();
11601             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11602             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11603             if ( s0.match( query_nodes ) ) {
11604                 return false;
11605             }
11606             //
11607             query_nodes = new HashSet<PhylogenyNode>();
11608             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11609             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11610             if ( s0.match( query_nodes ) ) {
11611                 return false;
11612             }
11613             //
11614             query_nodes = new HashSet<PhylogenyNode>();
11615             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11616             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11617             if ( s0.match( query_nodes ) ) {
11618                 return false;
11619             }
11620             //
11621             query_nodes = new HashSet<PhylogenyNode>();
11622             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11623             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11624             if ( s0.match( query_nodes ) ) {
11625                 return false;
11626             }
11627             //
11628             query_nodes = new HashSet<PhylogenyNode>();
11629             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11630             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11631             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11632             if ( s0.match( query_nodes ) ) {
11633                 return false;
11634             }
11635             //
11636             query_nodes = new HashSet<PhylogenyNode>();
11637             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11638             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11639             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11640             if ( s0.match( query_nodes ) ) {
11641                 return false;
11642             }
11643             //
11644             query_nodes = new HashSet<PhylogenyNode>();
11645             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11646             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11647             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11648             if ( s0.match( query_nodes ) ) {
11649                 return false;
11650             }
11651             //
11652             query_nodes = new HashSet<PhylogenyNode>();
11653             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11654             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11655             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11656             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11657             if ( s0.match( query_nodes ) ) {
11658                 return false;
11659             }
11660             /////////
11661             //            query_nodes = new HashSet<PhylogenyNode>();
11662             //            query_nodes.add( new PhylogenyNode( "X" ) );
11663             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11664             //            query_nodes.add( new PhylogenyNode( "A" ) );
11665             //            query_nodes.add( new PhylogenyNode( "B" ) );
11666             //            query_nodes.add( new PhylogenyNode( "C" ) );
11667             //            query_nodes.add( new PhylogenyNode( "D" ) );
11668             //            query_nodes.add( new PhylogenyNode( "E" ) );
11669             //            query_nodes.add( new PhylogenyNode( "F" ) );
11670             //            query_nodes.add( new PhylogenyNode( "G" ) );
11671             //            if ( !s0.match( query_nodes ) ) {
11672             //                return false;
11673             //            }
11674             //            query_nodes = new HashSet<PhylogenyNode>();
11675             //            query_nodes.add( new PhylogenyNode( "X" ) );
11676             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11677             //            query_nodes.add( new PhylogenyNode( "A" ) );
11678             //            query_nodes.add( new PhylogenyNode( "B" ) );
11679             //            query_nodes.add( new PhylogenyNode( "C" ) );
11680             //            if ( !s0.match( query_nodes ) ) {
11681             //                return false;
11682             //            }
11683             //            //
11684             //            query_nodes = new HashSet<PhylogenyNode>();
11685             //            query_nodes.add( new PhylogenyNode( "X" ) );
11686             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11687             //            query_nodes.add( new PhylogenyNode( "D" ) );
11688             //            query_nodes.add( new PhylogenyNode( "E" ) );
11689             //            query_nodes.add( new PhylogenyNode( "F" ) );
11690             //            query_nodes.add( new PhylogenyNode( "G" ) );
11691             //            if ( !s0.match( query_nodes ) ) {
11692             //                return false;
11693             //            }
11694             //            //
11695             //            query_nodes = new HashSet<PhylogenyNode>();
11696             //            query_nodes.add( new PhylogenyNode( "X" ) );
11697             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11698             //            query_nodes.add( new PhylogenyNode( "A" ) );
11699             //            query_nodes.add( new PhylogenyNode( "B" ) );
11700             //            query_nodes.add( new PhylogenyNode( "C" ) );
11701             //            query_nodes.add( new PhylogenyNode( "D" ) );
11702             //            if ( !s0.match( query_nodes ) ) {
11703             //                return false;
11704             //            }
11705             //            //
11706             //            query_nodes = new HashSet<PhylogenyNode>();
11707             //            query_nodes.add( new PhylogenyNode( "X" ) );
11708             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11709             //            query_nodes.add( new PhylogenyNode( "E" ) );
11710             //            query_nodes.add( new PhylogenyNode( "F" ) );
11711             //            query_nodes.add( new PhylogenyNode( "G" ) );
11712             //            if ( !s0.match( query_nodes ) ) {
11713             //                return false;
11714             //            }
11715             //            //
11716             //            query_nodes = new HashSet<PhylogenyNode>();
11717             //            query_nodes.add( new PhylogenyNode( "X" ) );
11718             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11719             //            query_nodes.add( new PhylogenyNode( "F" ) );
11720             //            query_nodes.add( new PhylogenyNode( "G" ) );
11721             //            if ( !s0.match( query_nodes ) ) {
11722             //                return false;
11723             //            }
11724             //
11725             query_nodes = new HashSet<PhylogenyNode>();
11726             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11727             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11728             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11729             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11730             if ( s0.match( query_nodes ) ) {
11731                 return false;
11732             }
11733             //
11734             query_nodes = new HashSet<PhylogenyNode>();
11735             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11736             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11737             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11738             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11739             if ( s0.match( query_nodes ) ) {
11740                 return false;
11741             }
11742             ///////////////////////////
11743             //
11744             query_nodes = new HashSet<PhylogenyNode>();
11745             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11746             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11747             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11748             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11749             if ( s0.match( query_nodes ) ) {
11750                 return false;
11751             }
11752             //
11753             query_nodes = new HashSet<PhylogenyNode>();
11754             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11755             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11756             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11757             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11758             if ( s0.match( query_nodes ) ) {
11759                 return false;
11760             }
11761             //
11762             query_nodes = new HashSet<PhylogenyNode>();
11763             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11764             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11765             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11766             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11767             if ( s0.match( query_nodes ) ) {
11768                 return false;
11769             }
11770             //
11771             query_nodes = new HashSet<PhylogenyNode>();
11772             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11773             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11774             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11775             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11776             if ( s0.match( query_nodes ) ) {
11777                 return false;
11778             }
11779             //
11780             query_nodes = new HashSet<PhylogenyNode>();
11781             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11782             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11783             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11784             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11785             if ( s0.match( query_nodes ) ) {
11786                 return false;
11787             }
11788             //
11789             query_nodes = new HashSet<PhylogenyNode>();
11790             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11791             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11792             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11793             if ( s0.match( query_nodes ) ) {
11794                 return false;
11795             }
11796             //
11797             query_nodes = new HashSet<PhylogenyNode>();
11798             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11799             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11800             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11801             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11802             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11803             if ( s0.match( query_nodes ) ) {
11804                 return false;
11805             }
11806             //
11807             query_nodes = new HashSet<PhylogenyNode>();
11808             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11809             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11810             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11811             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11812             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11813             if ( s0.match( query_nodes ) ) {
11814                 return false;
11815             }
11816             //
11817             query_nodes = new HashSet<PhylogenyNode>();
11818             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11819             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11820             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11821             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11822             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11823             if ( s0.match( query_nodes ) ) {
11824                 return false;
11825             }
11826             //
11827             query_nodes = new HashSet<PhylogenyNode>();
11828             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11829             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11830             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11831             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11832             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11833             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11834             if ( s0.match( query_nodes ) ) {
11835                 return false;
11836             }
11837         }
11838         catch ( final Exception e ) {
11839             e.printStackTrace();
11840             return false;
11841         }
11842         return true;
11843     }
11844
11845     private static boolean testSplitStrict() {
11846         try {
11847             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11848             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11849             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11850             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11851             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11852             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11853             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11854             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11855             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11856             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11857             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
11858             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11859             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11860             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11861             if ( s0.match( query_nodes ) ) {
11862                 return false;
11863             }
11864             query_nodes = new HashSet<PhylogenyNode>();
11865             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11866             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11867             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11868             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11869             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11870             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11871             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11872             if ( !s0.match( query_nodes ) ) {
11873                 return false;
11874             }
11875             //
11876             query_nodes = new HashSet<PhylogenyNode>();
11877             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
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( "D" ) );
11886             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11887             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11888             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11889             if ( !s0.match( query_nodes ) ) {
11890                 return false;
11891             }
11892             //
11893             query_nodes = new HashSet<PhylogenyNode>();
11894             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11895             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11896             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
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( "E" ) );
11904             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11905             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11906             if ( !s0.match( query_nodes ) ) {
11907                 return false;
11908             }
11909             //
11910             query_nodes = new HashSet<PhylogenyNode>();
11911             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11912             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11913             if ( !s0.match( query_nodes ) ) {
11914                 return false;
11915             }
11916             //
11917             query_nodes = new HashSet<PhylogenyNode>();
11918             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11919             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11920             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11921             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11922             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11923             if ( !s0.match( query_nodes ) ) {
11924                 return false;
11925             }
11926             //
11927             query_nodes = new HashSet<PhylogenyNode>();
11928             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11929             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11930             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11931             if ( !s0.match( query_nodes ) ) {
11932                 return false;
11933             }
11934             //
11935             query_nodes = new HashSet<PhylogenyNode>();
11936             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11937             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11938             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11939             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11940             if ( !s0.match( query_nodes ) ) {
11941                 return false;
11942             }
11943             //
11944             query_nodes = new HashSet<PhylogenyNode>();
11945             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11946             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11947             if ( s0.match( query_nodes ) ) {
11948                 return false;
11949             }
11950             //
11951             query_nodes = new HashSet<PhylogenyNode>();
11952             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11953             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11954             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11955             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11956             if ( s0.match( query_nodes ) ) {
11957                 return false;
11958             }
11959             //
11960             query_nodes = new HashSet<PhylogenyNode>();
11961             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11962             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11963             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11964             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11965             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11966             if ( s0.match( query_nodes ) ) {
11967                 return false;
11968             }
11969             //
11970             query_nodes = new HashSet<PhylogenyNode>();
11971             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11972             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11973             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11974             if ( s0.match( query_nodes ) ) {
11975                 return false;
11976             }
11977             //
11978             query_nodes = new HashSet<PhylogenyNode>();
11979             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11980             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11981             if ( s0.match( query_nodes ) ) {
11982                 return false;
11983             }
11984             //
11985             query_nodes = new HashSet<PhylogenyNode>();
11986             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11987             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11988             if ( s0.match( query_nodes ) ) {
11989                 return false;
11990             }
11991             //
11992             query_nodes = new HashSet<PhylogenyNode>();
11993             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11994             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11995             if ( s0.match( query_nodes ) ) {
11996                 return false;
11997             }
11998             //
11999             query_nodes = new HashSet<PhylogenyNode>();
12000             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12001             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12002             if ( s0.match( query_nodes ) ) {
12003                 return false;
12004             }
12005             //
12006             query_nodes = new HashSet<PhylogenyNode>();
12007             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12008             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12009             if ( s0.match( query_nodes ) ) {
12010                 return false;
12011             }
12012             //
12013             query_nodes = new HashSet<PhylogenyNode>();
12014             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12015             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12016             if ( s0.match( query_nodes ) ) {
12017                 return false;
12018             }
12019             //
12020             query_nodes = new HashSet<PhylogenyNode>();
12021             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12022             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12023             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12024             if ( s0.match( query_nodes ) ) {
12025                 return false;
12026             }
12027             //
12028             query_nodes = new HashSet<PhylogenyNode>();
12029             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12030             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12031             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12032             if ( s0.match( query_nodes ) ) {
12033                 return false;
12034             }
12035             //
12036             query_nodes = new HashSet<PhylogenyNode>();
12037             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12038             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12039             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12040             if ( s0.match( query_nodes ) ) {
12041                 return false;
12042             }
12043             //
12044             query_nodes = new HashSet<PhylogenyNode>();
12045             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12046             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12047             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12048             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12049             if ( s0.match( query_nodes ) ) {
12050                 return false;
12051             }
12052         }
12053         catch ( final Exception e ) {
12054             e.printStackTrace();
12055             return false;
12056         }
12057         return true;
12058     }
12059
12060     private static boolean testSubtreeDeletion() {
12061         try {
12062             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12063             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12064             t1.deleteSubtree( t1.getNode( "A" ), false );
12065             if ( t1.getNumberOfExternalNodes() != 5 ) {
12066                 return false;
12067             }
12068             t1.toNewHampshireX();
12069             t1.deleteSubtree( t1.getNode( "E" ), false );
12070             if ( t1.getNumberOfExternalNodes() != 4 ) {
12071                 return false;
12072             }
12073             t1.toNewHampshireX();
12074             t1.deleteSubtree( t1.getNode( "F" ), false );
12075             if ( t1.getNumberOfExternalNodes() != 3 ) {
12076                 return false;
12077             }
12078             t1.toNewHampshireX();
12079             t1.deleteSubtree( t1.getNode( "D" ), false );
12080             t1.toNewHampshireX();
12081             if ( t1.getNumberOfExternalNodes() != 3 ) {
12082                 return false;
12083             }
12084             t1.deleteSubtree( t1.getNode( "def" ), false );
12085             t1.toNewHampshireX();
12086             if ( t1.getNumberOfExternalNodes() != 2 ) {
12087                 return false;
12088             }
12089             t1.deleteSubtree( t1.getNode( "B" ), false );
12090             t1.toNewHampshireX();
12091             if ( t1.getNumberOfExternalNodes() != 1 ) {
12092                 return false;
12093             }
12094             t1.deleteSubtree( t1.getNode( "C" ), false );
12095             t1.toNewHampshireX();
12096             if ( t1.getNumberOfExternalNodes() != 1 ) {
12097                 return false;
12098             }
12099             t1.deleteSubtree( t1.getNode( "abc" ), false );
12100             t1.toNewHampshireX();
12101             if ( t1.getNumberOfExternalNodes() != 1 ) {
12102                 return false;
12103             }
12104             t1.deleteSubtree( t1.getNode( "r" ), false );
12105             if ( t1.getNumberOfExternalNodes() != 0 ) {
12106                 return false;
12107             }
12108             if ( !t1.isEmpty() ) {
12109                 return false;
12110             }
12111             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12112             t2.deleteSubtree( t2.getNode( "A" ), false );
12113             t2.toNewHampshireX();
12114             if ( t2.getNumberOfExternalNodes() != 5 ) {
12115                 return false;
12116             }
12117             t2.deleteSubtree( t2.getNode( "abc" ), false );
12118             t2.toNewHampshireX();
12119             if ( t2.getNumberOfExternalNodes() != 3 ) {
12120                 return false;
12121             }
12122             t2.deleteSubtree( t2.getNode( "def" ), false );
12123             t2.toNewHampshireX();
12124             if ( t2.getNumberOfExternalNodes() != 1 ) {
12125                 return false;
12126             }
12127         }
12128         catch ( final Exception e ) {
12129             e.printStackTrace( System.out );
12130             return false;
12131         }
12132         return true;
12133     }
12134
12135     private static boolean testSupportCount() {
12136         try {
12137             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12138             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
12139             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
12140                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
12141                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
12142                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
12143                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
12144                                                               new NHXParser() );
12145             SupportCount.count( t0_1, phylogenies_1, true, false );
12146             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
12147             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
12148                                                                       + "(((((A,B),C),D),E),((F,G),X))"
12149                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
12150                                                                       + "(((((A,B),C),D),E),(F,G))"
12151                                                                       + "(((((A,B),C),D),E),(F,G))"
12152                                                                       + "(((((A,B),C),D),E),(F,G))"
12153                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
12154                                                                       + "(((((A,B),C),D),E),(F,G))"
12155                                                                       + "((((((A,B),C),D),E),F),G)"
12156                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
12157                                                               new NHXParser() );
12158             SupportCount.count( t0_2, phylogenies_2, true, false );
12159             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
12160             while ( it.hasNext() ) {
12161                 final PhylogenyNode n = it.next();
12162                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
12163                     return false;
12164                 }
12165             }
12166             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
12167             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
12168                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
12169             SupportCount.count( t0_3, phylogenies_3, true, false );
12170             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
12171             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
12172                 return false;
12173             }
12174             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
12175                 return false;
12176             }
12177             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
12178                 return false;
12179             }
12180             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
12181                 return false;
12182             }
12183             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
12184                 return false;
12185             }
12186             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
12187                 return false;
12188             }
12189             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
12190                 return false;
12191             }
12192             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
12193                 return false;
12194             }
12195             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
12196                 return false;
12197             }
12198             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
12199                 return false;
12200             }
12201             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12202             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
12203                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
12204             SupportCount.count( t0_4, phylogenies_4, true, false );
12205             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
12206             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
12207                 return false;
12208             }
12209             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
12210                 return false;
12211             }
12212             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
12213                 return false;
12214             }
12215             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
12216                 return false;
12217             }
12218             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
12219                 return false;
12220             }
12221             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
12222                 return false;
12223             }
12224             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
12225                 return false;
12226             }
12227             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
12228                 return false;
12229             }
12230             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
12231                 return false;
12232             }
12233             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
12234                 return false;
12235             }
12236             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12237             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12238             double d = SupportCount.compare( b1, a, true, true, true );
12239             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
12240                 return false;
12241             }
12242             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12243             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12244             d = SupportCount.compare( b2, a, true, true, true );
12245             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
12246                 return false;
12247             }
12248             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12249             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
12250             d = SupportCount.compare( b3, a, true, true, true );
12251             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
12252                 return false;
12253             }
12254             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
12255             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
12256             d = SupportCount.compare( b4, a, true, true, false );
12257             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
12258                 return false;
12259             }
12260         }
12261         catch ( final Exception e ) {
12262             e.printStackTrace( System.out );
12263             return false;
12264         }
12265         return true;
12266     }
12267
12268     private static boolean testSupportTransfer() {
12269         try {
12270             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12271             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)",
12272                                                  new NHXParser() )[ 0 ];
12273             final Phylogeny p2 = factory
12274                     .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 ];
12275             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
12276                 return false;
12277             }
12278             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
12279                 return false;
12280             }
12281             support_transfer.moveBranchLengthsToBootstrap( p1 );
12282             support_transfer.transferSupportValues( p1, p2 );
12283             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
12284                 return false;
12285             }
12286             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
12287                 return false;
12288             }
12289             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
12290                 return false;
12291             }
12292             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
12293                 return false;
12294             }
12295             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
12296                 return false;
12297             }
12298             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
12299                 return false;
12300             }
12301             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
12302                 return false;
12303             }
12304             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
12305                 return false;
12306             }
12307         }
12308         catch ( final Exception e ) {
12309             e.printStackTrace( System.out );
12310             return false;
12311         }
12312         return true;
12313     }
12314
12315     private static boolean testTaxonomyExtraction() {
12316         try {
12317             final PhylogenyNode n0 = PhylogenyNode
12318                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12319             if ( n0.getNodeData().isHasTaxonomy() ) {
12320                 return false;
12321             }
12322             final PhylogenyNode n1 = PhylogenyNode
12323                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12324             if ( n1.getNodeData().isHasTaxonomy() ) {
12325                 System.out.println( n1.toString() );
12326                 return false;
12327             }
12328             final PhylogenyNode n2x = PhylogenyNode
12329                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12330             if ( n2x.getNodeData().isHasTaxonomy() ) {
12331                 return false;
12332             }
12333             final PhylogenyNode n3 = PhylogenyNode
12334                     .createInstanceFromNhxString( "BLAG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12335             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12336                 System.out.println( n3.toString() );
12337                 return false;
12338             }
12339             final PhylogenyNode n4 = PhylogenyNode
12340                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12341             if ( n4.getNodeData().isHasTaxonomy() ) {
12342                 System.out.println( n4.toString() );
12343                 return false;
12344             }
12345             final PhylogenyNode n5 = PhylogenyNode
12346                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12347             if ( n5.getNodeData().isHasTaxonomy() ) {
12348                 System.out.println( n5.toString() );
12349                 return false;
12350             }
12351             final PhylogenyNode n6 = PhylogenyNode
12352                     .createInstanceFromNhxString( "BLAG-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12353             if ( n6.getNodeData().isHasTaxonomy() ) {
12354                 System.out.println( n6.toString() );
12355                 return false;
12356             }
12357             final PhylogenyNode n7 = PhylogenyNode
12358                     .createInstanceFromNhxString( "BLAG-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12359             if ( n7.getNodeData().isHasTaxonomy() ) {
12360                 System.out.println( n7.toString() );
12361                 return false;
12362             }
12363             final PhylogenyNode n8 = PhylogenyNode
12364                     .createInstanceFromNhxString( "BLAG_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12365             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12366                 System.out.println( n8.toString() );
12367                 return false;
12368             }
12369             final PhylogenyNode n9 = PhylogenyNode
12370                     .createInstanceFromNhxString( "BLAG_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12371             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12372                 System.out.println( n9.toString() );
12373                 return false;
12374             }
12375             final PhylogenyNode n10x = PhylogenyNode
12376                     .createInstanceFromNhxString( "BLAG_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12377             if ( n10x.getNodeData().isHasTaxonomy() ) {
12378                 System.out.println( n10x.toString() );
12379                 return false;
12380             }
12381             final PhylogenyNode n10xx = PhylogenyNode
12382                     .createInstanceFromNhxString( "BLAG_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12383             if ( n10xx.getNodeData().isHasTaxonomy() ) {
12384                 System.out.println( n10xx.toString() );
12385                 return false;
12386             }
12387             final PhylogenyNode n10 = PhylogenyNode
12388                     .createInstanceFromNhxString( "BLAG_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12389             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
12390                 System.out.println( n10.toString() );
12391                 return false;
12392             }
12393             final PhylogenyNode n11 = PhylogenyNode
12394                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12395             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12396                 System.out.println( n11.toString() );
12397                 return false;
12398             }
12399             final PhylogenyNode n12 = PhylogenyNode
12400                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
12401                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12402             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12403                 System.out.println( n12.toString() );
12404                 return false;
12405             }
12406             final PhylogenyNode n13 = PhylogenyNode
12407                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12408             if ( n13.getNodeData().isHasTaxonomy() ) {
12409                 System.out.println( n13.toString() );
12410                 return false;
12411             }
12412             final PhylogenyNode n14 = PhylogenyNode
12413                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12414             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12415                 System.out.println( n14.toString() );
12416                 return false;
12417             }
12418             final PhylogenyNode n15 = PhylogenyNode
12419                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12420             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12421                 System.out.println( n15.toString() );
12422                 return false;
12423             }
12424             final PhylogenyNode n16 = PhylogenyNode
12425                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12426             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12427                 System.out.println( n16.toString() );
12428                 return false;
12429             }
12430             final PhylogenyNode n17 = PhylogenyNode
12431                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12432             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12433                 System.out.println( n17.toString() );
12434                 return false;
12435             }
12436             //
12437             final PhylogenyNode n18 = PhylogenyNode
12438                     .createInstanceFromNhxString( "Mus_musculus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12439             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12440                 System.out.println( n18.toString() );
12441                 return false;
12442             }
12443             final PhylogenyNode n19 = PhylogenyNode
12444                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
12445                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12446             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12447                 System.out.println( n19.toString() );
12448                 return false;
12449             }
12450             final PhylogenyNode n20 = PhylogenyNode
12451                     .createInstanceFromNhxString( "Mus musculus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12452             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12453                 System.out.println( n20.toString() );
12454                 return false;
12455             }
12456             final PhylogenyNode n21 = PhylogenyNode
12457                     .createInstanceFromNhxString( "Mus musculus musculus K392",
12458                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12459             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12460                 System.out.println( n21.toString() );
12461                 return false;
12462             }
12463             final PhylogenyNode n22 = PhylogenyNode
12464                     .createInstanceFromNhxString( "NEMVE_Nematostella_vectensis",
12465                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12466             if ( !n22.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12467                 System.out.println( n22.toString() );
12468                 return false;
12469             }
12470             final PhylogenyNode n23 = PhylogenyNode
12471                     .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
12472                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12473             if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12474                 System.out.println( n23.toString() );
12475                 return false;
12476             }
12477             final PhylogenyNode n24 = PhylogenyNode
12478                     .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12479             if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12480                 System.out.println( n24.toString() );
12481                 return false;
12482             }
12483             //
12484             final PhylogenyNode n25 = PhylogenyNode
12485                     .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
12486                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12487             if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12488                 System.out.println( n25.toString() );
12489                 return false;
12490             }
12491             final PhylogenyNode n26 = PhylogenyNode
12492                     .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
12493                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12494             if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12495                 System.out.println( n26.toString() );
12496                 return false;
12497             }
12498             final PhylogenyNode n27 = PhylogenyNode
12499                     .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12500             if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12501                 System.out.println( n27.toString() );
12502                 return false;
12503             }
12504         }
12505         catch ( final Exception e ) {
12506             e.printStackTrace( System.out );
12507             return false;
12508         }
12509         return true;
12510     }
12511
12512     private static boolean testTreeCopy() {
12513         try {
12514             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
12515             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
12516             final Phylogeny t1 = t0.copy();
12517             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
12518                 return false;
12519             }
12520             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12521                 return false;
12522             }
12523             t0.deleteSubtree( t0.getNode( "c" ), true );
12524             t0.deleteSubtree( t0.getNode( "a" ), true );
12525             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
12526             t0.getNode( "b" ).setName( "Bee" );
12527             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
12528                 return false;
12529             }
12530             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12531                 return false;
12532             }
12533             t0.deleteSubtree( t0.getNode( "e" ), true );
12534             t0.deleteSubtree( t0.getNode( "Bee" ), true );
12535             t0.deleteSubtree( t0.getNode( "d" ), true );
12536             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12537                 return false;
12538             }
12539         }
12540         catch ( final Exception e ) {
12541             e.printStackTrace();
12542             return false;
12543         }
12544         return true;
12545     }
12546
12547     private static boolean testTreeMethods() {
12548         try {
12549             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12550             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
12551             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
12552             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
12553                 System.out.println( t0.toNewHampshireX() );
12554                 return false;
12555             }
12556             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
12557             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
12558             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
12559                 return false;
12560             }
12561             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
12562                 return false;
12563             }
12564             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
12565                 return false;
12566             }
12567         }
12568         catch ( final Exception e ) {
12569             e.printStackTrace( System.out );
12570             return false;
12571         }
12572         return true;
12573     }
12574
12575     private static boolean testUniprotEntryRetrieval() {
12576         try {
12577             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
12578             if ( !entry.getAccession().equals( "P12345" ) ) {
12579                 return false;
12580             }
12581             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
12582                 return false;
12583             }
12584             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
12585                 return false;
12586             }
12587             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
12588                 return false;
12589             }
12590             if ( !entry.getGeneName().equals( "GOT2" ) ) {
12591                 return false;
12592             }
12593             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
12594                 return false;
12595             }
12596         }
12597         catch ( final IOException e ) {
12598             System.out.println();
12599             System.out.println( "the following might be due to absence internet connection:" );
12600             e.printStackTrace( System.out );
12601             return true;
12602         }
12603         catch ( final Exception e ) {
12604             return false;
12605         }
12606         return true;
12607     }
12608
12609     private static boolean testUniprotTaxonomySearch() {
12610         try {
12611             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
12612                                                                                                  10 );
12613             if ( results.size() != 1 ) {
12614                 return false;
12615             }
12616             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12617                 return false;
12618             }
12619             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12620                 return false;
12621             }
12622             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12623                 return false;
12624             }
12625             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12626                 return false;
12627             }
12628             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12629                 return false;
12630             }
12631             results = null;
12632             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
12633             if ( results.size() != 1 ) {
12634                 return false;
12635             }
12636             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12637                 return false;
12638             }
12639             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12640                 return false;
12641             }
12642             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12643                 return false;
12644             }
12645             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12646                 return false;
12647             }
12648             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12649                 return false;
12650             }
12651             results = null;
12652             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
12653             if ( results.size() != 1 ) {
12654                 return false;
12655             }
12656             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12657                 return false;
12658             }
12659             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12660                 return false;
12661             }
12662             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12663                 return false;
12664             }
12665             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12666                 return false;
12667             }
12668             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12669                 return false;
12670             }
12671             results = null;
12672             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
12673             if ( results.size() != 1 ) {
12674                 return false;
12675             }
12676             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12677                 return false;
12678             }
12679             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12680                 return false;
12681             }
12682             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12683                 return false;
12684             }
12685             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12686                 return false;
12687             }
12688             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12689                 return false;
12690             }
12691             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
12692                 return false;
12693             }
12694             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
12695                 return false;
12696             }
12697             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12698                     .equals( "Nematostella vectensis" ) ) {
12699                 System.out.println( results.get( 0 ).getLineage() );
12700                 return false;
12701             }
12702             //
12703             results = null;
12704             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
12705             if ( results.size() != 1 ) {
12706                 return false;
12707             }
12708             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12709                 return false;
12710             }
12711             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12712                 return false;
12713             }
12714             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12715                 return false;
12716             }
12717             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12718                 return false;
12719             }
12720             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12721                 return false;
12722             }
12723             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12724                     .equals( "Xenopus tropicalis" ) ) {
12725                 System.out.println( results.get( 0 ).getLineage() );
12726                 return false;
12727             }
12728             //
12729             results = null;
12730             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
12731             if ( results.size() != 1 ) {
12732                 return false;
12733             }
12734             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12735                 return false;
12736             }
12737             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12738                 return false;
12739             }
12740             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12741                 return false;
12742             }
12743             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12744                 return false;
12745             }
12746             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12747                 return false;
12748             }
12749             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12750                     .equals( "Xenopus tropicalis" ) ) {
12751                 System.out.println( results.get( 0 ).getLineage() );
12752                 return false;
12753             }
12754             //
12755             results = null;
12756             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
12757             if ( results.size() != 1 ) {
12758                 return false;
12759             }
12760             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12761                 return false;
12762             }
12763             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12764                 return false;
12765             }
12766             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12767                 return false;
12768             }
12769             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12770                 return false;
12771             }
12772             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12773                 return false;
12774             }
12775             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12776                     .equals( "Xenopus tropicalis" ) ) {
12777                 System.out.println( results.get( 0 ).getLineage() );
12778                 return false;
12779             }
12780         }
12781         catch ( final IOException e ) {
12782             System.out.println();
12783             System.out.println( "the following might be due to absence internet connection:" );
12784             e.printStackTrace( System.out );
12785             return true;
12786         }
12787         catch ( final Exception e ) {
12788             return false;
12789         }
12790         return true;
12791     }
12792
12793     private static boolean testWabiTxSearch() {
12794         try {
12795             String result = "";
12796             result = TxSearch.searchSimple( "nematostella" );
12797             result = TxSearch.getTxId( "nematostella" );
12798             if ( !result.equals( "45350" ) ) {
12799                 return false;
12800             }
12801             result = TxSearch.getTxName( "45350" );
12802             if ( !result.equals( "Nematostella" ) ) {
12803                 return false;
12804             }
12805             result = TxSearch.getTxId( "nematostella vectensis" );
12806             if ( !result.equals( "45351" ) ) {
12807                 return false;
12808             }
12809             result = TxSearch.getTxName( "45351" );
12810             if ( !result.equals( "Nematostella vectensis" ) ) {
12811                 return false;
12812             }
12813             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
12814             if ( !result.equals( "536089" ) ) {
12815                 return false;
12816             }
12817             result = TxSearch.getTxName( "536089" );
12818             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
12819                 return false;
12820             }
12821             final List<String> queries = new ArrayList<String>();
12822             queries.add( "Campylobacter coli" );
12823             queries.add( "Escherichia coli" );
12824             queries.add( "Arabidopsis" );
12825             queries.add( "Trichoplax" );
12826             queries.add( "Samanea saman" );
12827             queries.add( "Kluyveromyces marxianus" );
12828             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
12829             queries.add( "Bornavirus parrot/PDD/2008" );
12830             final List<RANKS> ranks = new ArrayList<RANKS>();
12831             ranks.add( RANKS.SUPERKINGDOM );
12832             ranks.add( RANKS.KINGDOM );
12833             ranks.add( RANKS.FAMILY );
12834             ranks.add( RANKS.GENUS );
12835             ranks.add( RANKS.TRIBE );
12836             result = TxSearch.searchLineage( queries, ranks );
12837             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
12838             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
12839         }
12840         catch ( final Exception e ) {
12841             System.out.println();
12842             System.out.println( "the following might be due to absence internet connection:" );
12843             e.printStackTrace( System.out );
12844             return false;
12845         }
12846         return true;
12847     }
12848 }