796acd06d035a8f4d9b5dd1caeb0c5af6106bf01
[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) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
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 // Contact: phylosoft @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
25
26 package org.forester.test;
27
28 import java.io.ByteArrayInputStream;
29 import java.io.File;
30 import java.io.FileInputStream;
31 import java.io.IOException;
32 import java.util.ArrayList;
33 import java.util.Date;
34 import java.util.HashSet;
35 import java.util.Iterator;
36 import java.util.List;
37 import java.util.Locale;
38 import java.util.Set;
39
40 import org.forester.application.support_transfer;
41 import org.forester.archaeopteryx.TreePanelUtil;
42 import org.forester.development.DevelopmentTools;
43 import org.forester.evoinference.TestPhylogenyReconstruction;
44 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
45 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
46 import org.forester.go.TestGo;
47 import org.forester.io.parsers.FastaParser;
48 import org.forester.io.parsers.GeneralMsaParser;
49 import org.forester.io.parsers.HmmscanPerDomainTableParser;
50 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
51 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
52 import org.forester.io.parsers.nexus.NexusCharactersParser;
53 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
54 import org.forester.io.parsers.nhx.NHXParser;
55 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
56 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
57 import org.forester.io.parsers.tol.TolParser;
58 import org.forester.io.parsers.util.ParserUtils;
59 import org.forester.io.writers.PhylogenyWriter;
60 import org.forester.io.writers.SequenceWriter;
61 import org.forester.msa.BasicMsa;
62 import org.forester.msa.Mafft;
63 import org.forester.msa.Msa;
64 import org.forester.msa.MsaInferrer;
65 import org.forester.msa.MsaMethods;
66 import org.forester.pccx.TestPccx;
67 import org.forester.phylogeny.Phylogeny;
68 import org.forester.phylogeny.PhylogenyBranch;
69 import org.forester.phylogeny.PhylogenyMethods;
70 import org.forester.phylogeny.PhylogenyNode;
71 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
72 import org.forester.phylogeny.data.Accession;
73 import org.forester.phylogeny.data.BinaryCharacters;
74 import org.forester.phylogeny.data.BranchWidth;
75 import org.forester.phylogeny.data.Confidence;
76 import org.forester.phylogeny.data.Distribution;
77 import org.forester.phylogeny.data.DomainArchitecture;
78 import org.forester.phylogeny.data.Event;
79 import org.forester.phylogeny.data.Identifier;
80 import org.forester.phylogeny.data.PhylogenyData;
81 import org.forester.phylogeny.data.PhylogenyDataUtil;
82 import org.forester.phylogeny.data.Polygon;
83 import org.forester.phylogeny.data.PropertiesMap;
84 import org.forester.phylogeny.data.Property;
85 import org.forester.phylogeny.data.Property.AppliesTo;
86 import org.forester.phylogeny.data.ProteinDomain;
87 import org.forester.phylogeny.data.Taxonomy;
88 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
89 import org.forester.phylogeny.factories.PhylogenyFactory;
90 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
91 import org.forester.protein.BasicDomain;
92 import org.forester.protein.BasicProtein;
93 import org.forester.protein.Domain;
94 import org.forester.protein.Protein;
95 import org.forester.protein.ProteinId;
96 import org.forester.rio.TestRIO;
97 import org.forester.sdi.SDI;
98 import org.forester.sdi.SDIR;
99 import org.forester.sdi.TestGSDI;
100 import org.forester.sequence.BasicSequence;
101 import org.forester.sequence.Sequence;
102 import org.forester.species.BasicSpecies;
103 import org.forester.species.Species;
104 import org.forester.surfacing.TestSurfacing;
105 import org.forester.tools.ConfidenceAssessor;
106 import org.forester.tools.SupportCount;
107 import org.forester.tools.TreeSplitMatrix;
108 import org.forester.util.AsciiHistogram;
109 import org.forester.util.BasicDescriptiveStatistics;
110 import org.forester.util.BasicTable;
111 import org.forester.util.BasicTableParser;
112 import org.forester.util.DescriptiveStatistics;
113 import org.forester.util.ForesterConstants;
114 import org.forester.util.ForesterUtil;
115 import org.forester.util.GeneralTable;
116 import org.forester.util.SequenceIdParser;
117 import org.forester.ws.seqdb.SequenceDatabaseEntry;
118 import org.forester.ws.seqdb.SequenceDbWsTools;
119 import org.forester.ws.seqdb.UniProtTaxonomy;
120 import org.forester.ws.wabi.TxSearch;
121 import org.forester.ws.wabi.TxSearch.RANKS;
122 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
123 import org.forester.ws.wabi.TxSearch.TAX_RANK;
124
125 @SuppressWarnings( "unused")
126 public final class Test {
127
128     private final static double  ZERO_DIFF                 = 1.0E-9;
129     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
130                                                                    + ForesterUtil.getFileSeparator() + "test_data"
131                                                                    + ForesterUtil.getFileSeparator();
132     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
133                                                                    + ForesterUtil.getFileSeparator() + "resources"
134                                                                    + ForesterUtil.getFileSeparator();
135     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
136     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
137                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
138                                                                    + ForesterConstants.PHYLO_XML_XSD;
139     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
140                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
141                                                                    + ForesterConstants.PHYLO_XML_XSD;
142
143     public static boolean isEqual( final double a, final double b ) {
144         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
145     }
146
147     public static void main( final String[] args ) {
148         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
149         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
150                 + "]" );
151         Locale.setDefault( Locale.US );
152         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
153         int failed = 0;
154         int succeeded = 0;
155         System.out.print( "[Test if directory with files for testing exists/is readable: " );
156         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
157             System.out.println( "OK.]" );
158         }
159         else {
160             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
161             System.out.println( "Testing aborted." );
162             System.exit( -1 );
163         }
164         System.out.print( "[Test if resources directory exists/is readable: " );
165         if ( testDir( PATH_TO_RESOURCES ) ) {
166             System.out.println( "OK.]" );
167         }
168         else {
169             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
170             System.out.println( "Testing aborted." );
171             System.exit( -1 );
172         }
173         final long start_time = new Date().getTime();
174         System.out.print( "Protein id: " );
175         if ( !testProteinId() ) {
176             System.out.println( "failed." );
177             failed++;
178         }
179         else {
180             succeeded++;
181         }
182         System.out.println( "OK." );
183         System.out.print( "Species: " );
184         if ( !testSpecies() ) {
185             System.out.println( "failed." );
186             failed++;
187         }
188         else {
189             succeeded++;
190         }
191         System.out.println( "OK." );
192         System.out.print( "Basic domain: " );
193         if ( !testBasicDomain() ) {
194             System.out.println( "failed." );
195             failed++;
196         }
197         else {
198             succeeded++;
199         }
200         System.out.println( "OK." );
201         System.out.print( "Basic protein: " );
202         if ( !testBasicProtein() ) {
203             System.out.println( "failed." );
204             failed++;
205         }
206         else {
207             succeeded++;
208         }
209         System.out.println( "OK." );
210         System.out.print( "Sequence writer: " );
211         if ( testSequenceWriter() ) {
212             System.out.println( "OK." );
213             succeeded++;
214         }
215         else {
216             System.out.println( "failed." );
217             failed++;
218         }
219         System.out.print( "Sequence id parsing: " );
220         if ( testSequenceIdParsing() ) {
221             System.out.println( "OK." );
222             succeeded++;
223         }
224         else {
225             System.out.println( "failed." );
226             failed++;
227         }
228         System.out.print( "Hmmscan output parser: " );
229         if ( testHmmscanOutputParser() ) {
230             System.out.println( "OK." );
231             succeeded++;
232         }
233         else {
234             System.out.println( "failed." );
235             failed++;
236         }
237         System.out.print( "Basic node methods: " );
238         if ( Test.testBasicNodeMethods() ) {
239             System.out.println( "OK." );
240             succeeded++;
241         }
242         else {
243             System.out.println( "failed." );
244             failed++;
245         }
246         System.out.print( "Taxonomy code extraction: " );
247         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
248             System.out.println( "OK." );
249             succeeded++;
250         }
251         else {
252             System.out.println( "failed." );
253             failed++;
254         }
255         System.out.print( "SN extraction: " );
256         if ( Test.testExtractSNFromNodeName() ) {
257             System.out.println( "OK." );
258             succeeded++;
259         }
260         else {
261             System.out.println( "failed." );
262             failed++;
263         }
264         System.out.print( "Taxonomy extraction (general): " );
265         if ( Test.testTaxonomyExtraction() ) {
266             System.out.println( "OK." );
267             succeeded++;
268         }
269         else {
270             System.out.println( "failed." );
271             failed++;
272         }
273         System.out.print( "UniProtKB id extraction: " );
274         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
275             System.out.println( "OK." );
276             succeeded++;
277         }
278         else {
279             System.out.println( "failed." );
280             failed++;
281         }
282         System.out.print( "Uri for Aptx web sequence accession: " );
283         if ( Test.testCreateUriForSeqWeb() ) {
284             System.out.println( "OK." );
285             succeeded++;
286         }
287         else {
288             System.out.println( "failed." );
289             failed++;
290         }
291         System.out.print( "Basic node construction and parsing of NHX (node level): " );
292         if ( Test.testNHXNodeParsing() ) {
293             System.out.println( "OK." );
294             succeeded++;
295         }
296         else {
297             System.out.println( "failed." );
298             failed++;
299         }
300         System.out.print( "NHX parsing iterating: " );
301         if ( Test.testNHParsingIter() ) {
302             System.out.println( "OK." );
303             succeeded++;
304         }
305         else {
306             System.out.println( "failed." );
307             failed++;
308         }
309         System.out.print( "NH parsing: " );
310         if ( Test.testNHParsing() ) {
311             System.out.println( "OK." );
312             succeeded++;
313         }
314         else {
315             System.out.println( "failed." );
316             failed++;
317         }
318         System.out.print( "Conversion to NHX (node level): " );
319         if ( Test.testNHXconversion() ) {
320             System.out.println( "OK." );
321             succeeded++;
322         }
323         else {
324             System.out.println( "failed." );
325             failed++;
326         }
327         System.out.print( "NHX parsing: " );
328         if ( Test.testNHXParsing() ) {
329             System.out.println( "OK." );
330             succeeded++;
331         }
332         else {
333             System.out.println( "failed." );
334             failed++;
335         }
336         System.out.print( "NHX parsing with quotes: " );
337         if ( Test.testNHXParsingQuotes() ) {
338             System.out.println( "OK." );
339             succeeded++;
340         }
341         else {
342             System.out.println( "failed." );
343             failed++;
344         }
345         System.out.print( "NHX parsing (MrBayes): " );
346         if ( Test.testNHXParsingMB() ) {
347             System.out.println( "OK." );
348             succeeded++;
349         }
350         else {
351             System.out.println( "failed." );
352             failed++;
353         }
354         System.out.print( "Nexus characters parsing: " );
355         if ( Test.testNexusCharactersParsing() ) {
356             System.out.println( "OK." );
357             succeeded++;
358         }
359         else {
360             System.out.println( "failed." );
361             failed++;
362         }
363         System.out.print( "Nexus tree parsing iterating: " );
364         if ( Test.testNexusTreeParsingIterating() ) {
365             System.out.println( "OK." );
366             succeeded++;
367         }
368         else {
369             System.out.println( "failed." );
370             failed++;
371         }
372         System.out.print( "Nexus tree parsing: " );
373         if ( Test.testNexusTreeParsing() ) {
374             System.out.println( "OK." );
375             succeeded++;
376         }
377         else {
378             System.out.println( "failed." );
379             failed++;
380         }
381         System.out.print( "Nexus tree parsing (translating): " );
382         if ( Test.testNexusTreeParsingTranslating() ) {
383             System.out.println( "OK." );
384             succeeded++;
385         }
386         else {
387             System.out.println( "failed." );
388             failed++;
389         }
390         System.out.print( "Nexus matrix parsing: " );
391         if ( Test.testNexusMatrixParsing() ) {
392             System.out.println( "OK." );
393             succeeded++;
394         }
395         else {
396             System.out.println( "failed." );
397             failed++;
398         }
399         System.out.print( "Basic phyloXML parsing: " );
400         if ( Test.testBasicPhyloXMLparsing() ) {
401             System.out.println( "OK." );
402             succeeded++;
403         }
404         else {
405             System.out.println( "failed." );
406             failed++;
407         }
408         System.out.print( "Basic phyloXML parsing (validating against schema): " );
409         if ( testBasicPhyloXMLparsingValidating() ) {
410             System.out.println( "OK." );
411             succeeded++;
412         }
413         else {
414             System.out.println( "failed." );
415             failed++;
416         }
417         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
418         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
419             System.out.println( "OK." );
420             succeeded++;
421         }
422         else {
423             System.out.println( "failed." );
424             failed++;
425         }
426         System.out.print( "phyloXML Distribution Element: " );
427         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
428             System.out.println( "OK." );
429             succeeded++;
430         }
431         else {
432             System.out.println( "failed." );
433             failed++;
434         }
435         System.out.print( "Tol XML parsing: " );
436         if ( Test.testBasicTolXMLparsing() ) {
437             System.out.println( "OK." );
438             succeeded++;
439         }
440         else {
441             System.out.println( "failed." );
442             failed++;
443         }
444         System.out.print( "Copying of node data: " );
445         if ( Test.testCopyOfNodeData() ) {
446             System.out.println( "OK." );
447             succeeded++;
448         }
449         else {
450             System.out.println( "failed." );
451             failed++;
452         }
453         System.out.print( "Basic tree methods: " );
454         if ( Test.testBasicTreeMethods() ) {
455             System.out.println( "OK." );
456             succeeded++;
457         }
458         else {
459             System.out.println( "failed." );
460             failed++;
461         }
462         System.out.print( "Tree methods: " );
463         if ( Test.testTreeMethods() ) {
464             System.out.println( "OK." );
465             succeeded++;
466         }
467         else {
468             System.out.println( "failed." );
469             failed++;
470         }
471         System.out.print( "Postorder Iterator: " );
472         if ( Test.testPostOrderIterator() ) {
473             System.out.println( "OK." );
474             succeeded++;
475         }
476         else {
477             System.out.println( "failed." );
478             failed++;
479         }
480         System.out.print( "Preorder Iterator: " );
481         if ( Test.testPreOrderIterator() ) {
482             System.out.println( "OK." );
483             succeeded++;
484         }
485         else {
486             System.out.println( "failed." );
487             failed++;
488         }
489         System.out.print( "Levelorder Iterator: " );
490         if ( Test.testLevelOrderIterator() ) {
491             System.out.println( "OK." );
492             succeeded++;
493         }
494         else {
495             System.out.println( "failed." );
496             failed++;
497         }
498         System.out.print( "Re-id methods: " );
499         if ( Test.testReIdMethods() ) {
500             System.out.println( "OK." );
501             succeeded++;
502         }
503         else {
504             System.out.println( "failed." );
505             failed++;
506         }
507         System.out.print( "Methods on last external nodes: " );
508         if ( Test.testLastExternalNodeMethods() ) {
509             System.out.println( "OK." );
510             succeeded++;
511         }
512         else {
513             System.out.println( "failed." );
514             failed++;
515         }
516         System.out.print( "Methods on external nodes: " );
517         if ( Test.testExternalNodeRelatedMethods() ) {
518             System.out.println( "OK." );
519             succeeded++;
520         }
521         else {
522             System.out.println( "failed." );
523             failed++;
524         }
525         System.out.print( "Deletion of external nodes: " );
526         if ( Test.testDeletionOfExternalNodes() ) {
527             System.out.println( "OK." );
528             succeeded++;
529         }
530         else {
531             System.out.println( "failed." );
532             failed++;
533         }
534         System.out.print( "Subtree deletion: " );
535         if ( Test.testSubtreeDeletion() ) {
536             System.out.println( "OK." );
537             succeeded++;
538         }
539         else {
540             System.out.println( "failed." );
541             failed++;
542         }
543         System.out.print( "Phylogeny branch: " );
544         if ( Test.testPhylogenyBranch() ) {
545             System.out.println( "OK." );
546             succeeded++;
547         }
548         else {
549             System.out.println( "failed." );
550             failed++;
551         }
552         System.out.print( "Rerooting: " );
553         if ( Test.testRerooting() ) {
554             System.out.println( "OK." );
555             succeeded++;
556         }
557         else {
558             System.out.println( "failed." );
559             failed++;
560         }
561         System.out.print( "Mipoint rooting: " );
562         if ( Test.testMidpointrooting() ) {
563             System.out.println( "OK." );
564             succeeded++;
565         }
566         else {
567             System.out.println( "failed." );
568             failed++;
569         }
570         System.out.print( "Node removal: " );
571         if ( Test.testNodeRemoval() ) {
572             System.out.println( "OK." );
573             succeeded++;
574         }
575         else {
576             System.out.println( "failed." );
577             failed++;
578         }
579         System.out.print( "Support count: " );
580         if ( Test.testSupportCount() ) {
581             System.out.println( "OK." );
582             succeeded++;
583         }
584         else {
585             System.out.println( "failed." );
586             failed++;
587         }
588         System.out.print( "Support transfer: " );
589         if ( Test.testSupportTransfer() ) {
590             System.out.println( "OK." );
591             succeeded++;
592         }
593         else {
594             System.out.println( "failed." );
595             failed++;
596         }
597         System.out.print( "Finding of LCA: " );
598         if ( Test.testGetLCA() ) {
599             System.out.println( "OK." );
600             succeeded++;
601         }
602         else {
603             System.out.println( "failed." );
604             failed++;
605         }
606         System.out.print( "Finding of LCA 2: " );
607         if ( Test.testGetLCA2() ) {
608             System.out.println( "OK." );
609             succeeded++;
610         }
611         else {
612             System.out.println( "failed." );
613             failed++;
614         }
615         System.out.print( "Calculation of distance between nodes: " );
616         if ( Test.testGetDistance() ) {
617             System.out.println( "OK." );
618             succeeded++;
619         }
620         else {
621             System.out.println( "failed." );
622             failed++;
623         }
624         System.out.print( "Descriptive statistics: " );
625         if ( Test.testDescriptiveStatistics() ) {
626             System.out.println( "OK." );
627             succeeded++;
628         }
629         else {
630             System.out.println( "failed." );
631             failed++;
632         }
633         System.out.print( "Data objects and methods: " );
634         if ( Test.testDataObjects() ) {
635             System.out.println( "OK." );
636             succeeded++;
637         }
638         else {
639             System.out.println( "failed." );
640             failed++;
641         }
642         System.out.print( "Properties map: " );
643         if ( Test.testPropertiesMap() ) {
644             System.out.println( "OK." );
645             succeeded++;
646         }
647         else {
648             System.out.println( "failed." );
649             failed++;
650         }
651         System.out.print( "SDIse: " );
652         if ( Test.testSDIse() ) {
653             System.out.println( "OK." );
654             succeeded++;
655         }
656         else {
657             System.out.println( "failed." );
658             failed++;
659         }
660         System.out.print( "SDIunrooted: " );
661         if ( Test.testSDIunrooted() ) {
662             System.out.println( "OK." );
663             succeeded++;
664         }
665         else {
666             System.out.println( "failed." );
667             failed++;
668         }
669         System.out.print( "GSDI: " );
670         if ( TestGSDI.test() ) {
671             System.out.println( "OK." );
672             succeeded++;
673         }
674         else {
675             System.out.println( "failed." );
676             failed++;
677         }
678         System.out.print( "RIO: " );
679         if ( TestRIO.test() ) {
680             System.out.println( "OK." );
681             succeeded++;
682         }
683         else {
684             System.out.println( "failed." );
685             failed++;
686         }
687         System.out.print( "Phylogeny reconstruction:" );
688         System.out.println();
689         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
690             System.out.println( "OK." );
691             succeeded++;
692         }
693         else {
694             System.out.println( "failed." );
695             failed++;
696         }
697         System.out.print( "Analysis of domain architectures: " );
698         System.out.println();
699         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
700             System.out.println( "OK." );
701             succeeded++;
702         }
703         else {
704             System.out.println( "failed." );
705             failed++;
706         }
707         System.out.print( "GO: " );
708         System.out.println();
709         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
710             System.out.println( "OK." );
711             succeeded++;
712         }
713         else {
714             System.out.println( "failed." );
715             failed++;
716         }
717         System.out.print( "Modeling tools: " );
718         if ( TestPccx.test() ) {
719             System.out.println( "OK." );
720             succeeded++;
721         }
722         else {
723             System.out.println( "failed." );
724             failed++;
725         }
726         System.out.print( "Split Matrix strict: " );
727         if ( Test.testSplitStrict() ) {
728             System.out.println( "OK." );
729             succeeded++;
730         }
731         else {
732             System.out.println( "failed." );
733             failed++;
734         }
735         System.out.print( "Split Matrix: " );
736         if ( Test.testSplit() ) {
737             System.out.println( "OK." );
738             succeeded++;
739         }
740         else {
741             System.out.println( "failed." );
742             failed++;
743         }
744         System.out.print( "Confidence Assessor: " );
745         if ( Test.testConfidenceAssessor() ) {
746             System.out.println( "OK." );
747             succeeded++;
748         }
749         else {
750             System.out.println( "failed." );
751             failed++;
752         }
753         System.out.print( "Basic table: " );
754         if ( Test.testBasicTable() ) {
755             System.out.println( "OK." );
756             succeeded++;
757         }
758         else {
759             System.out.println( "failed." );
760             failed++;
761         }
762         System.out.print( "General table: " );
763         if ( Test.testGeneralTable() ) {
764             System.out.println( "OK." );
765             succeeded++;
766         }
767         else {
768             System.out.println( "failed." );
769             failed++;
770         }
771         System.out.print( "Amino acid sequence: " );
772         if ( Test.testAminoAcidSequence() ) {
773             System.out.println( "OK." );
774             succeeded++;
775         }
776         else {
777             System.out.println( "failed." );
778             failed++;
779         }
780         System.out.print( "General MSA parser: " );
781         if ( Test.testGeneralMsaParser() ) {
782             System.out.println( "OK." );
783             succeeded++;
784         }
785         else {
786             System.out.println( "failed." );
787             failed++;
788         }
789         System.out.print( "Fasta parser for msa: " );
790         if ( Test.testFastaParser() ) {
791             System.out.println( "OK." );
792             succeeded++;
793         }
794         else {
795             System.out.println( "failed." );
796             failed++;
797         }
798         System.out.print( "Creation of balanced phylogeny: " );
799         if ( Test.testCreateBalancedPhylogeny() ) {
800             System.out.println( "OK." );
801             succeeded++;
802         }
803         else {
804             System.out.println( "failed." );
805             failed++;
806         }
807         System.out.print( "EMBL Entry Retrieval: " );
808         if ( Test.testEmblEntryRetrieval() ) {
809             System.out.println( "OK." );
810             succeeded++;
811         }
812         else {
813             System.out.println( "failed." );
814             failed++;
815         }
816         System.out.print( "Uniprot Entry Retrieval: " );
817         if ( Test.testUniprotEntryRetrieval() ) {
818             System.out.println( "OK." );
819             succeeded++;
820         }
821         else {
822             System.out.println( "failed." );
823             failed++;
824         }
825         System.out.print( "Uniprot Taxonomy Search: " );
826         if ( Test.testUniprotTaxonomySearch() ) {
827             System.out.println( "OK." );
828             succeeded++;
829         }
830         else {
831             System.out.println( "failed." );
832             failed++;
833         }
834         //----
835         String path = "";
836         final String os = ForesterUtil.OS_NAME.toLowerCase();
837         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
838             path = "/usr/local/bin/mafft";
839         }
840         else if ( os.indexOf( "win" ) >= 0 ) {
841             path = "C:\\Program Files\\mafft-win\\mafft.bat";
842         }
843         else {
844             path = "/home/czmasek/bin/mafft";
845         }
846         if ( !MsaInferrer.isInstalled( path ) ) {
847             path = "mafft";
848         }
849         if ( !MsaInferrer.isInstalled( path ) ) {
850             path = "/usr/local/bin/mafft";
851         }
852         if ( MsaInferrer.isInstalled( path ) ) {
853             System.out.print( "MAFFT (external program): " );
854             if ( Test.testMafft( path ) ) {
855                 System.out.println( "OK." );
856                 succeeded++;
857             }
858             else {
859                 System.out.println( "failed [will not count towards failed tests]" );
860             }
861         }
862         //----
863         System.out.print( "Next nodes with collapsed: " );
864         if ( Test.testNextNodeWithCollapsing() ) {
865             System.out.println( "OK." );
866             succeeded++;
867         }
868         else {
869             System.out.println( "failed." );
870             failed++;
871         }
872         System.out.print( "Simple MSA quality: " );
873         if ( Test.testMsaQualityMethod() ) {
874             System.out.println( "OK." );
875             succeeded++;
876         }
877         else {
878             System.out.println( "failed." );
879             failed++;
880         }
881         System.out.println();
882         final Runtime rt = java.lang.Runtime.getRuntime();
883         final long free_memory = rt.freeMemory() / 1000000;
884         final long total_memory = rt.totalMemory() / 1000000;
885         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
886                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
887         System.out.println();
888         System.out.println( "Successful tests: " + succeeded );
889         System.out.println( "Failed     tests: " + failed );
890         System.out.println();
891         if ( failed < 1 ) {
892             System.out.println( "OK." );
893         }
894         else {
895             System.out.println( "Not OK." );
896         }
897     }
898
899     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
900         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
901         return p;
902     }
903
904     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
905         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
906     }
907
908     private static boolean testAminoAcidSequence() {
909         try {
910             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
911             if ( aa1.getLength() != 13 ) {
912                 return false;
913             }
914             if ( aa1.getResidueAt( 0 ) != 'A' ) {
915                 return false;
916             }
917             if ( aa1.getResidueAt( 2 ) != 'K' ) {
918                 return false;
919             }
920             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
921                 return false;
922             }
923             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
924             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
925                 return false;
926             }
927             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
928             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
929                 return false;
930             }
931             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
932             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
933                 return false;
934             }
935         }
936         catch ( final Exception e ) {
937             e.printStackTrace();
938             return false;
939         }
940         return true;
941     }
942
943     private static boolean testBasicDomain() {
944         try {
945             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
946             if ( !pd.getDomainId().equals( "id" ) ) {
947                 return false;
948             }
949             if ( pd.getNumber() != 1 ) {
950                 return false;
951             }
952             if ( pd.getTotalCount() != 4 ) {
953                 return false;
954             }
955             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
956                 return false;
957             }
958             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
959             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
960             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
961             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
962             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
963             if ( !a1.equals( a1 ) ) {
964                 return false;
965             }
966             if ( !a1.equals( a1_copy ) ) {
967                 return false;
968             }
969             if ( !a1.equals( a1_equal ) ) {
970                 return false;
971             }
972             if ( !a1.equals( a2 ) ) {
973                 return false;
974             }
975             if ( a1.equals( a3 ) ) {
976                 return false;
977             }
978             if ( a1.compareTo( a1 ) != 0 ) {
979                 return false;
980             }
981             if ( a1.compareTo( a1_copy ) != 0 ) {
982                 return false;
983             }
984             if ( a1.compareTo( a1_equal ) != 0 ) {
985                 return false;
986             }
987             if ( a1.compareTo( a2 ) != 0 ) {
988                 return false;
989             }
990             if ( a1.compareTo( a3 ) == 0 ) {
991                 return false;
992             }
993         }
994         catch ( final Exception e ) {
995             e.printStackTrace( System.out );
996             return false;
997         }
998         return true;
999     }
1000
1001     private static boolean testBasicNodeMethods() {
1002         try {
1003             if ( PhylogenyNode.getNodeCount() != 0 ) {
1004                 return false;
1005             }
1006             final PhylogenyNode n1 = new PhylogenyNode();
1007             final PhylogenyNode n2 = PhylogenyNode
1008                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1009             final PhylogenyNode n3 = PhylogenyNode
1010                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1011             final PhylogenyNode n4 = PhylogenyNode
1012                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1013             if ( n1.isHasAssignedEvent() ) {
1014                 return false;
1015             }
1016             if ( PhylogenyNode.getNodeCount() != 4 ) {
1017                 return false;
1018             }
1019             if ( n3.getIndicator() != 0 ) {
1020                 return false;
1021             }
1022             if ( n3.getNumberOfExternalNodes() != 1 ) {
1023                 return false;
1024             }
1025             if ( !n3.isExternal() ) {
1026                 return false;
1027             }
1028             if ( !n3.isRoot() ) {
1029                 return false;
1030             }
1031             if ( !n4.getName().equals( "n4" ) ) {
1032                 return false;
1033             }
1034         }
1035         catch ( final Exception e ) {
1036             e.printStackTrace( System.out );
1037             return false;
1038         }
1039         return true;
1040     }
1041
1042     private static boolean testBasicPhyloXMLparsing() {
1043         try {
1044             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1045             final PhyloXmlParser xml_parser = new PhyloXmlParser();
1046             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1047                                                               xml_parser );
1048             if ( xml_parser.getErrorCount() > 0 ) {
1049                 System.out.println( xml_parser.getErrorMessages().toString() );
1050                 return false;
1051             }
1052             if ( phylogenies_0.length != 4 ) {
1053                 return false;
1054             }
1055             final Phylogeny t1 = phylogenies_0[ 0 ];
1056             final Phylogeny t2 = phylogenies_0[ 1 ];
1057             final Phylogeny t3 = phylogenies_0[ 2 ];
1058             final Phylogeny t4 = phylogenies_0[ 3 ];
1059             if ( t1.getNumberOfExternalNodes() != 1 ) {
1060                 return false;
1061             }
1062             if ( !t1.isRooted() ) {
1063                 return false;
1064             }
1065             if ( t1.isRerootable() ) {
1066                 return false;
1067             }
1068             if ( !t1.getType().equals( "gene_tree" ) ) {
1069                 return false;
1070             }
1071             if ( t2.getNumberOfExternalNodes() != 2 ) {
1072                 return false;
1073             }
1074             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1075                 return false;
1076             }
1077             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1078                 return false;
1079             }
1080             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1081                 return false;
1082             }
1083             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1084                 return false;
1085             }
1086             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1087                 return false;
1088             }
1089             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1090                 return false;
1091             }
1092             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1093                     .startsWith( "actgtgggggt" ) ) {
1094                 return false;
1095             }
1096             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1097                     .startsWith( "ctgtgatgcat" ) ) {
1098                 return false;
1099             }
1100             if ( t3.getNumberOfExternalNodes() != 4 ) {
1101                 return false;
1102             }
1103             if ( !t1.getName().equals( "t1" ) ) {
1104                 return false;
1105             }
1106             if ( !t2.getName().equals( "t2" ) ) {
1107                 return false;
1108             }
1109             if ( !t3.getName().equals( "t3" ) ) {
1110                 return false;
1111             }
1112             if ( !t4.getName().equals( "t4" ) ) {
1113                 return false;
1114             }
1115             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1116                 return false;
1117             }
1118             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1119                 return false;
1120             }
1121             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1122                 return false;
1123             }
1124             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1125                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1126                 return false;
1127             }
1128             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1129                 return false;
1130             }
1131             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1132                 return false;
1133             }
1134             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1135                 return false;
1136             }
1137             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1138                     .equals( "apoptosis" ) ) {
1139                 return false;
1140             }
1141             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1142                     .equals( "GO:0006915" ) ) {
1143                 return false;
1144             }
1145             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1146                     .equals( "UniProtKB" ) ) {
1147                 return false;
1148             }
1149             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1150                     .equals( "experimental" ) ) {
1151                 return false;
1152             }
1153             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1154                     .equals( "function" ) ) {
1155                 return false;
1156             }
1157             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1158                     .getValue() != 1 ) {
1159                 return false;
1160             }
1161             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1162                     .getType().equals( "ml" ) ) {
1163                 return false;
1164             }
1165             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1166                     .equals( "apoptosis" ) ) {
1167                 return false;
1168             }
1169             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1170                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1171                 return false;
1172             }
1173             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1174                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1175                 return false;
1176             }
1177             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1178                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1179                 return false;
1180             }
1181             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1182                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1183                 return false;
1184             }
1185             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1186                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1187                 return false;
1188             }
1189             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1190                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1191                 return false;
1192             }
1193             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1194                     .equals( "GO:0005829" ) ) {
1195                 return false;
1196             }
1197             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1198                     .equals( "intracellular organelle" ) ) {
1199                 return false;
1200             }
1201             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1202                 return false;
1203             }
1204             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1205                     .equals( "UniProt link" ) ) ) {
1206                 return false;
1207             }
1208             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1209                 return false;
1210             }
1211         }
1212         catch ( final Exception e ) {
1213             e.printStackTrace( System.out );
1214             return false;
1215         }
1216         return true;
1217     }
1218
1219     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1220         try {
1221             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1222             final PhyloXmlParser xml_parser = new PhyloXmlParser();
1223             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1224                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1225             }
1226             else {
1227                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1228             }
1229             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1230                                                               xml_parser );
1231             if ( xml_parser.getErrorCount() > 0 ) {
1232                 System.out.println( xml_parser.getErrorMessages().toString() );
1233                 return false;
1234             }
1235             if ( phylogenies_0.length != 4 ) {
1236                 return false;
1237             }
1238             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1239             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1240             if ( phylogenies_t1.length != 1 ) {
1241                 return false;
1242             }
1243             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1244             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1245                 return false;
1246             }
1247             if ( !t1_rt.isRooted() ) {
1248                 return false;
1249             }
1250             if ( t1_rt.isRerootable() ) {
1251                 return false;
1252             }
1253             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1254                 return false;
1255             }
1256             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1257             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1258             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1259             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1260                 return false;
1261             }
1262             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1263                 return false;
1264             }
1265             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1266                 return false;
1267             }
1268             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1269                 return false;
1270             }
1271             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1272                     .startsWith( "actgtgggggt" ) ) {
1273                 return false;
1274             }
1275             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1276                     .startsWith( "ctgtgatgcat" ) ) {
1277                 return false;
1278             }
1279             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1280             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1281             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1282             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1283             if ( phylogenies_1.length != 1 ) {
1284                 return false;
1285             }
1286             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1287             if ( !t3_rt.getName().equals( "t3" ) ) {
1288                 return false;
1289             }
1290             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1291                 return false;
1292             }
1293             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1294                 return false;
1295             }
1296             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1297                 return false;
1298             }
1299             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1300                 return false;
1301             }
1302             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1303                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1304                 return false;
1305             }
1306             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1307                 return false;
1308             }
1309             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1310                 return false;
1311             }
1312             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1313                     .equals( "UniProtKB" ) ) {
1314                 return false;
1315             }
1316             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1317                     .equals( "apoptosis" ) ) {
1318                 return false;
1319             }
1320             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1321                     .equals( "GO:0006915" ) ) {
1322                 return false;
1323             }
1324             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1325                     .equals( "UniProtKB" ) ) {
1326                 return false;
1327             }
1328             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1329                     .equals( "experimental" ) ) {
1330                 return false;
1331             }
1332             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1333                     .equals( "function" ) ) {
1334                 return false;
1335             }
1336             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1337                     .getValue() != 1 ) {
1338                 return false;
1339             }
1340             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1341                     .getType().equals( "ml" ) ) {
1342                 return false;
1343             }
1344             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1345                     .equals( "apoptosis" ) ) {
1346                 return false;
1347             }
1348             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1349                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1350                 return false;
1351             }
1352             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1353                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1354                 return false;
1355             }
1356             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1357                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1358                 return false;
1359             }
1360             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1361                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1362                 return false;
1363             }
1364             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1365                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1366                 return false;
1367             }
1368             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1369                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1370                 return false;
1371             }
1372             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1373                     .equals( "GO:0005829" ) ) {
1374                 return false;
1375             }
1376             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1377                     .equals( "intracellular organelle" ) ) {
1378                 return false;
1379             }
1380             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1381                 return false;
1382             }
1383             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1384                     .equals( "UniProt link" ) ) ) {
1385                 return false;
1386             }
1387             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1388                 return false;
1389             }
1390             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1391                 return false;
1392             }
1393             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1394                     .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." ) ) ) {
1395                 return false;
1396             }
1397             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1398                 return false;
1399             }
1400             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1401                 return false;
1402             }
1403             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1404                 return false;
1405             }
1406             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1407                 return false;
1408             }
1409             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1410                     .equals( "ncbi" ) ) {
1411                 return false;
1412             }
1413             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1414                 return false;
1415             }
1416             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1417                     .getName().equals( "B" ) ) {
1418                 return false;
1419             }
1420             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1421                     .getFrom() != 21 ) {
1422                 return false;
1423             }
1424             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1425                 return false;
1426             }
1427             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1428                     .getLength() != 24 ) {
1429                 return false;
1430             }
1431             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1432                     .getConfidence() != 2144 ) {
1433                 return false;
1434             }
1435             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1436                     .equals( "pfam" ) ) {
1437                 return false;
1438             }
1439             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1440                 return false;
1441             }
1442             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1443                 return false;
1444             }
1445             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1446                 return false;
1447             }
1448             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1449                 return false;
1450             }
1451             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1452             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1453                 return false;
1454             }
1455             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1456                 return false;
1457             }
1458             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1459                 return false;
1460             }
1461             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1462                 return false;
1463             }
1464             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1465                 return false;
1466             }
1467             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1468                 return false;
1469             }
1470             if ( taxbb.getSynonyms().size() != 2 ) {
1471                 return false;
1472             }
1473             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1474                 return false;
1475             }
1476             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1477                 return false;
1478             }
1479             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1480                 return false;
1481             }
1482             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1483                 return false;
1484             }
1485             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1486                 return false;
1487             }
1488             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1489                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1490                 ;
1491                 return false;
1492             }
1493             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1494                 return false;
1495             }
1496             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1497                 return false;
1498             }
1499             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1500                 return false;
1501             }
1502             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1503                 return false;
1504             }
1505             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1506                 return false;
1507             }
1508             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1509                 return false;
1510             }
1511             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1512                 return false;
1513             }
1514             //
1515             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1516                 return false;
1517             }
1518             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1519                     .equalsIgnoreCase( "435" ) ) {
1520                 return false;
1521             }
1522             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1523                 return false;
1524             }
1525             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1526                     .equalsIgnoreCase( "443.7" ) ) {
1527                 return false;
1528             }
1529             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1530                 return false;
1531             }
1532             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1533                 return false;
1534             }
1535             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1536                     .equalsIgnoreCase( "433" ) ) {
1537                 return false;
1538             }
1539         }
1540         catch ( final Exception e ) {
1541             e.printStackTrace( System.out );
1542             return false;
1543         }
1544         return true;
1545     }
1546
1547     private static boolean testBasicPhyloXMLparsingValidating() {
1548         try {
1549             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1550             PhyloXmlParser xml_parser = null;
1551             try {
1552                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1553             }
1554             catch ( final Exception e ) {
1555                 // Do nothing -- means were not running from jar.
1556             }
1557             if ( xml_parser == null ) {
1558                 xml_parser = new PhyloXmlParser();
1559                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1560                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1561                 }
1562                 else {
1563                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1564                 }
1565             }
1566             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1567                                                               xml_parser );
1568             if ( xml_parser.getErrorCount() > 0 ) {
1569                 System.out.println( xml_parser.getErrorMessages().toString() );
1570                 return false;
1571             }
1572             if ( phylogenies_0.length != 4 ) {
1573                 return false;
1574             }
1575             final Phylogeny t1 = phylogenies_0[ 0 ];
1576             final Phylogeny t2 = phylogenies_0[ 1 ];
1577             final Phylogeny t3 = phylogenies_0[ 2 ];
1578             final Phylogeny t4 = phylogenies_0[ 3 ];
1579             if ( !t1.getName().equals( "t1" ) ) {
1580                 return false;
1581             }
1582             if ( !t2.getName().equals( "t2" ) ) {
1583                 return false;
1584             }
1585             if ( !t3.getName().equals( "t3" ) ) {
1586                 return false;
1587             }
1588             if ( !t4.getName().equals( "t4" ) ) {
1589                 return false;
1590             }
1591             if ( t1.getNumberOfExternalNodes() != 1 ) {
1592                 return false;
1593             }
1594             if ( t2.getNumberOfExternalNodes() != 2 ) {
1595                 return false;
1596             }
1597             if ( t3.getNumberOfExternalNodes() != 4 ) {
1598                 return false;
1599             }
1600             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
1601             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
1602             if ( xml_parser.getErrorCount() > 0 ) {
1603                 System.out.println( "errors:" );
1604                 System.out.println( xml_parser.getErrorMessages().toString() );
1605                 return false;
1606             }
1607             if ( phylogenies_1.length != 4 ) {
1608                 return false;
1609             }
1610             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
1611                                                               xml_parser );
1612             if ( xml_parser.getErrorCount() > 0 ) {
1613                 System.out.println( "errors:" );
1614                 System.out.println( xml_parser.getErrorMessages().toString() );
1615                 return false;
1616             }
1617             if ( phylogenies_2.length != 1 ) {
1618                 return false;
1619             }
1620             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
1621                 return false;
1622             }
1623             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
1624                                                               xml_parser );
1625             if ( xml_parser.getErrorCount() > 0 ) {
1626                 System.out.println( xml_parser.getErrorMessages().toString() );
1627                 return false;
1628             }
1629             if ( phylogenies_3.length != 2 ) {
1630                 return false;
1631             }
1632             final Phylogeny a = phylogenies_3[ 0 ];
1633             if ( !a.getName().equals( "tree 4" ) ) {
1634                 return false;
1635             }
1636             if ( a.getNumberOfExternalNodes() != 3 ) {
1637                 return false;
1638             }
1639             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
1640                 return false;
1641             }
1642             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
1643                 return false;
1644             }
1645             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
1646                                                               xml_parser );
1647             if ( xml_parser.getErrorCount() > 0 ) {
1648                 System.out.println( xml_parser.getErrorMessages().toString() );
1649                 return false;
1650             }
1651             if ( phylogenies_4.length != 1 ) {
1652                 return false;
1653             }
1654             final Phylogeny s = phylogenies_4[ 0 ];
1655             if ( s.getNumberOfExternalNodes() != 6 ) {
1656                 return false;
1657             }
1658             s.getNode( "first" );
1659             s.getNode( "<>" );
1660             s.getNode( "\"<a'b&c'd\">\"" );
1661             s.getNode( "'''\"" );
1662             s.getNode( "\"\"\"" );
1663             s.getNode( "dick & doof" );
1664         }
1665         catch ( final Exception e ) {
1666             e.printStackTrace( System.out );
1667             return false;
1668         }
1669         return true;
1670     }
1671
1672     private static boolean testBasicProtein() {
1673         try {
1674             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
1675             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1676             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
1677             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
1678             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
1679             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
1680             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1681             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1682             p0.addProteinDomain( y );
1683             p0.addProteinDomain( e );
1684             p0.addProteinDomain( b );
1685             p0.addProteinDomain( c );
1686             p0.addProteinDomain( d );
1687             p0.addProteinDomain( a );
1688             p0.addProteinDomain( x );
1689             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
1690                 return false;
1691             }
1692             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
1693                 return false;
1694             }
1695             //
1696             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
1697             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1698             aa0.addProteinDomain( a1 );
1699             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
1700                 return false;
1701             }
1702             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
1703                 return false;
1704             }
1705             //
1706             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
1707             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1708             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
1709             aa1.addProteinDomain( a11 );
1710             aa1.addProteinDomain( a12 );
1711             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
1712                 return false;
1713             }
1714             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
1715                 return false;
1716             }
1717             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1718             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
1719                 return false;
1720             }
1721             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
1722                 return false;
1723             }
1724             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
1725                 return false;
1726             }
1727             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1728             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
1729                 return false;
1730             }
1731             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
1732                 return false;
1733             }
1734             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
1735                 return false;
1736             }
1737             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
1738                 return false;
1739             }
1740             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1741             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
1742                 return false;
1743             }
1744             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
1745                 return false;
1746             }
1747             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
1748                 return false;
1749             }
1750             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
1751                 return false;
1752             }
1753             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1754             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
1755                 return false;
1756             }
1757             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
1758                 return false;
1759             }
1760             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
1761                 return false;
1762             }
1763             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
1764                 return false;
1765             }
1766             //
1767             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
1768             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1769             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
1770             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
1771             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
1772             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
1773             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
1774             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
1775             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
1776             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
1777             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
1778             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1779             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1780             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
1781             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
1782             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
1783             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
1784             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
1785             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
1786             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
1787             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
1788             p00.addProteinDomain( y0 );
1789             p00.addProteinDomain( e0 );
1790             p00.addProteinDomain( b0 );
1791             p00.addProteinDomain( c0 );
1792             p00.addProteinDomain( d0 );
1793             p00.addProteinDomain( a0 );
1794             p00.addProteinDomain( x0 );
1795             p00.addProteinDomain( y1 );
1796             p00.addProteinDomain( y2 );
1797             p00.addProteinDomain( y3 );
1798             p00.addProteinDomain( e1 );
1799             p00.addProteinDomain( e2 );
1800             p00.addProteinDomain( e3 );
1801             p00.addProteinDomain( e4 );
1802             p00.addProteinDomain( e5 );
1803             p00.addProteinDomain( z0 );
1804             p00.addProteinDomain( z1 );
1805             p00.addProteinDomain( z2 );
1806             p00.addProteinDomain( zz0 );
1807             p00.addProteinDomain( zz1 );
1808             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
1809                 return false;
1810             }
1811             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
1812                 return false;
1813             }
1814             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
1815                 return false;
1816             }
1817             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
1818                 return false;
1819             }
1820             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" ) ) {
1821                 return false;
1822             }
1823             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
1824             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1825             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
1826             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
1827             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
1828             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
1829             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
1830             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
1831             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
1832             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
1833             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
1834             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
1835             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
1836             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
1837             p.addProteinDomain( B15 );
1838             p.addProteinDomain( C50 );
1839             p.addProteinDomain( A60 );
1840             p.addProteinDomain( A30 );
1841             p.addProteinDomain( C70 );
1842             p.addProteinDomain( B35 );
1843             p.addProteinDomain( B40 );
1844             p.addProteinDomain( A0 );
1845             p.addProteinDomain( A10 );
1846             p.addProteinDomain( A20 );
1847             p.addProteinDomain( B25 );
1848             p.addProteinDomain( D80 );
1849             List<String> domains_ids = new ArrayList<String>();
1850             domains_ids.add( "A" );
1851             domains_ids.add( "B" );
1852             domains_ids.add( "C" );
1853             if ( !p.contains( domains_ids, false ) ) {
1854                 return false;
1855             }
1856             if ( !p.contains( domains_ids, true ) ) {
1857                 return false;
1858             }
1859             domains_ids.add( "X" );
1860             if ( p.contains( domains_ids, false ) ) {
1861                 return false;
1862             }
1863             if ( p.contains( domains_ids, true ) ) {
1864                 return false;
1865             }
1866             domains_ids = new ArrayList<String>();
1867             domains_ids.add( "A" );
1868             domains_ids.add( "C" );
1869             domains_ids.add( "D" );
1870             if ( !p.contains( domains_ids, false ) ) {
1871                 return false;
1872             }
1873             if ( !p.contains( domains_ids, true ) ) {
1874                 return false;
1875             }
1876             domains_ids = new ArrayList<String>();
1877             domains_ids.add( "A" );
1878             domains_ids.add( "D" );
1879             domains_ids.add( "C" );
1880             if ( !p.contains( domains_ids, false ) ) {
1881                 return false;
1882             }
1883             if ( p.contains( domains_ids, true ) ) {
1884                 return false;
1885             }
1886             domains_ids = new ArrayList<String>();
1887             domains_ids.add( "A" );
1888             domains_ids.add( "A" );
1889             domains_ids.add( "B" );
1890             if ( !p.contains( domains_ids, false ) ) {
1891                 return false;
1892             }
1893             if ( !p.contains( domains_ids, true ) ) {
1894                 return false;
1895             }
1896             domains_ids = new ArrayList<String>();
1897             domains_ids.add( "A" );
1898             domains_ids.add( "A" );
1899             domains_ids.add( "A" );
1900             domains_ids.add( "B" );
1901             domains_ids.add( "B" );
1902             if ( !p.contains( domains_ids, false ) ) {
1903                 return false;
1904             }
1905             if ( !p.contains( domains_ids, true ) ) {
1906                 return false;
1907             }
1908             domains_ids = new ArrayList<String>();
1909             domains_ids.add( "A" );
1910             domains_ids.add( "A" );
1911             domains_ids.add( "B" );
1912             domains_ids.add( "A" );
1913             domains_ids.add( "B" );
1914             domains_ids.add( "B" );
1915             domains_ids.add( "A" );
1916             domains_ids.add( "B" );
1917             domains_ids.add( "C" );
1918             domains_ids.add( "A" );
1919             domains_ids.add( "C" );
1920             domains_ids.add( "D" );
1921             if ( !p.contains( domains_ids, false ) ) {
1922                 return false;
1923             }
1924             if ( p.contains( domains_ids, true ) ) {
1925                 return false;
1926             }
1927         }
1928         catch ( final Exception e ) {
1929             e.printStackTrace( System.out );
1930             return false;
1931         }
1932         return true;
1933     }
1934
1935     private static boolean testBasicTable() {
1936         try {
1937             final BasicTable<String> t0 = new BasicTable<String>();
1938             if ( t0.getNumberOfColumns() != 0 ) {
1939                 return false;
1940             }
1941             if ( t0.getNumberOfRows() != 0 ) {
1942                 return false;
1943             }
1944             t0.setValue( 3, 2, "23" );
1945             t0.setValue( 10, 1, "error" );
1946             t0.setValue( 10, 1, "110" );
1947             t0.setValue( 9, 1, "19" );
1948             t0.setValue( 1, 10, "101" );
1949             t0.setValue( 10, 10, "1010" );
1950             t0.setValue( 100, 10, "10100" );
1951             t0.setValue( 0, 0, "00" );
1952             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
1953                 return false;
1954             }
1955             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
1956                 return false;
1957             }
1958             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
1959                 return false;
1960             }
1961             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
1962                 return false;
1963             }
1964             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
1965                 return false;
1966             }
1967             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
1968                 return false;
1969             }
1970             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
1971                 return false;
1972             }
1973             if ( t0.getNumberOfColumns() != 101 ) {
1974                 return false;
1975             }
1976             if ( t0.getNumberOfRows() != 11 ) {
1977                 return false;
1978             }
1979             if ( t0.getValueAsString( 49, 4 ) != null ) {
1980                 return false;
1981             }
1982             final String l = ForesterUtil.getLineSeparator();
1983             final StringBuffer source = new StringBuffer();
1984             source.append( "" + l );
1985             source.append( "# 1 1 1 1 1 1 1 1" + l );
1986             source.append( " 00 01 02 03" + l );
1987             source.append( "   10 11 12 13  " + l );
1988             source.append( "20 21 22 23 " + l );
1989             source.append( "    30  31    32 33" + l );
1990             source.append( "40 41 42 43" + l );
1991             source.append( "  # 1 1 1 1 1 " + l );
1992             source.append( "50 51 52 53 54" + l );
1993             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
1994             if ( t1.getNumberOfColumns() != 5 ) {
1995                 return false;
1996             }
1997             if ( t1.getNumberOfRows() != 6 ) {
1998                 return false;
1999             }
2000             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2001                 return false;
2002             }
2003             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2004                 return false;
2005             }
2006             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2007                 return false;
2008             }
2009             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2010                 return false;
2011             }
2012             final StringBuffer source1 = new StringBuffer();
2013             source1.append( "" + l );
2014             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2015             source1.append( " 00; 01 ;02;03" + l );
2016             source1.append( "   10; 11; 12; 13  " + l );
2017             source1.append( "20; 21; 22; 23 " + l );
2018             source1.append( "    30;  31;    32; 33" + l );
2019             source1.append( "40;41;42;43" + l );
2020             source1.append( "  # 1 1 1 1 1 " + l );
2021             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2022             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2023             if ( t2.getNumberOfColumns() != 5 ) {
2024                 return false;
2025             }
2026             if ( t2.getNumberOfRows() != 6 ) {
2027                 return false;
2028             }
2029             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2030                 return false;
2031             }
2032             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2033                 return false;
2034             }
2035             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2036                 return false;
2037             }
2038             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2039                 return false;
2040             }
2041             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2042                 return false;
2043             }
2044             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2045                 return false;
2046             }
2047             final StringBuffer source2 = new StringBuffer();
2048             source2.append( "" + l );
2049             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2050             source2.append( " 00; 01 ;02;03" + l );
2051             source2.append( "   10; 11; 12; 13  " + l );
2052             source2.append( "20; 21; 22; 23 " + l );
2053             source2.append( "                     " + l );
2054             source2.append( "    30;  31;    32; 33" + l );
2055             source2.append( "40;41;42;43" + l );
2056             source2.append( "  comment: 1 1 1 1 1 " + l );
2057             source2.append( ";;;50  ;   52; 53;;54   " + l );
2058             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2059                                                                         ';',
2060                                                                         false,
2061                                                                         false,
2062                                                                         "comment:",
2063                                                                         false );
2064             if ( tl.size() != 2 ) {
2065                 return false;
2066             }
2067             final BasicTable<String> t3 = tl.get( 0 );
2068             final BasicTable<String> t4 = tl.get( 1 );
2069             if ( t3.getNumberOfColumns() != 4 ) {
2070                 return false;
2071             }
2072             if ( t3.getNumberOfRows() != 3 ) {
2073                 return false;
2074             }
2075             if ( t4.getNumberOfColumns() != 4 ) {
2076                 return false;
2077             }
2078             if ( t4.getNumberOfRows() != 3 ) {
2079                 return false;
2080             }
2081             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2082                 return false;
2083             }
2084             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2085                 return false;
2086             }
2087         }
2088         catch ( final Exception e ) {
2089             e.printStackTrace( System.out );
2090             return false;
2091         }
2092         return true;
2093     }
2094
2095     private static boolean testBasicTolXMLparsing() {
2096         try {
2097             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2098             final TolParser parser = new TolParser();
2099             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2100             if ( parser.getErrorCount() > 0 ) {
2101                 System.out.println( parser.getErrorMessages().toString() );
2102                 return false;
2103             }
2104             if ( phylogenies_0.length != 1 ) {
2105                 return false;
2106             }
2107             final Phylogeny t1 = phylogenies_0[ 0 ];
2108             if ( t1.getNumberOfExternalNodes() != 5 ) {
2109                 return false;
2110             }
2111             if ( !t1.isRooted() ) {
2112                 return false;
2113             }
2114             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2115                 return false;
2116             }
2117             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2118                 return false;
2119             }
2120             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2121                 return false;
2122             }
2123             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2124                 return false;
2125             }
2126             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2127             if ( parser.getErrorCount() > 0 ) {
2128                 System.out.println( parser.getErrorMessages().toString() );
2129                 return false;
2130             }
2131             if ( phylogenies_1.length != 1 ) {
2132                 return false;
2133             }
2134             final Phylogeny t2 = phylogenies_1[ 0 ];
2135             if ( t2.getNumberOfExternalNodes() != 664 ) {
2136                 return false;
2137             }
2138             if ( !t2.isRooted() ) {
2139                 return false;
2140             }
2141             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2142                 return false;
2143             }
2144             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2145                 return false;
2146             }
2147             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2148                 return false;
2149             }
2150             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2151                 return false;
2152             }
2153             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2154                 return false;
2155             }
2156             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2157                     .equals( "Aquifex" ) ) {
2158                 return false;
2159             }
2160             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2161             if ( parser.getErrorCount() > 0 ) {
2162                 System.out.println( parser.getErrorMessages().toString() );
2163                 return false;
2164             }
2165             if ( phylogenies_2.length != 1 ) {
2166                 return false;
2167             }
2168             final Phylogeny t3 = phylogenies_2[ 0 ];
2169             if ( t3.getNumberOfExternalNodes() != 184 ) {
2170                 return false;
2171             }
2172             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2173                 return false;
2174             }
2175             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2176                 return false;
2177             }
2178             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2179                 return false;
2180             }
2181             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2182             if ( parser.getErrorCount() > 0 ) {
2183                 System.out.println( parser.getErrorMessages().toString() );
2184                 return false;
2185             }
2186             if ( phylogenies_3.length != 1 ) {
2187                 return false;
2188             }
2189             final Phylogeny t4 = phylogenies_3[ 0 ];
2190             if ( t4.getNumberOfExternalNodes() != 1 ) {
2191                 return false;
2192             }
2193             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2194                 return false;
2195             }
2196             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2197                 return false;
2198             }
2199             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2200                 return false;
2201             }
2202             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2203             if ( parser.getErrorCount() > 0 ) {
2204                 System.out.println( parser.getErrorMessages().toString() );
2205                 return false;
2206             }
2207             if ( phylogenies_4.length != 1 ) {
2208                 return false;
2209             }
2210             final Phylogeny t5 = phylogenies_4[ 0 ];
2211             if ( t5.getNumberOfExternalNodes() != 13 ) {
2212                 return false;
2213             }
2214             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2215                 return false;
2216             }
2217             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2218                 return false;
2219             }
2220             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2221                 return false;
2222             }
2223         }
2224         catch ( final Exception e ) {
2225             e.printStackTrace( System.out );
2226             return false;
2227         }
2228         return true;
2229     }
2230
2231     private static boolean testBasicTreeMethods() {
2232         try {
2233             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2234             final Phylogeny t1 = factory.create();
2235             if ( !t1.isEmpty() ) {
2236                 return false;
2237             }
2238             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2239             if ( t2.getNumberOfExternalNodes() != 4 ) {
2240                 return false;
2241             }
2242             if ( t2.getHeight() != 8.5 ) {
2243                 return false;
2244             }
2245             if ( !t2.isCompletelyBinary() ) {
2246                 return false;
2247             }
2248             if ( t2.isEmpty() ) {
2249                 return false;
2250             }
2251             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2252             if ( t3.getNumberOfExternalNodes() != 5 ) {
2253                 return false;
2254             }
2255             if ( t3.getHeight() != 11 ) {
2256                 return false;
2257             }
2258             if ( t3.isCompletelyBinary() ) {
2259                 return false;
2260             }
2261             final PhylogenyNode n = t3.getNode( "ABC" );
2262             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 ];
2263             if ( t4.getNumberOfExternalNodes() != 9 ) {
2264                 return false;
2265             }
2266             if ( t4.getHeight() != 11 ) {
2267                 return false;
2268             }
2269             if ( t4.isCompletelyBinary() ) {
2270                 return false;
2271             }
2272             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)" );
2273             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2274             if ( t5.getNumberOfExternalNodes() != 8 ) {
2275                 return false;
2276             }
2277             if ( t5.getHeight() != 15 ) {
2278                 return false;
2279             }
2280             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)" );
2281             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2282             if ( t6.getHeight() != 15 ) {
2283                 return false;
2284             }
2285             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)" );
2286             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2287             if ( t7.getHeight() != 15 ) {
2288                 return false;
2289             }
2290             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)" );
2291             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2292             if ( t8.getNumberOfExternalNodes() != 10 ) {
2293                 return false;
2294             }
2295             if ( t8.getHeight() != 15 ) {
2296                 return false;
2297             }
2298             final char[] a9 = new char[] { 'a' };
2299             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2300             if ( t9.getHeight() != 0 ) {
2301                 return false;
2302             }
2303             final char[] a10 = new char[] { 'a', ':', '6' };
2304             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2305             if ( t10.getHeight() != 6 ) {
2306                 return false;
2307             }
2308         }
2309         catch ( final Exception e ) {
2310             e.printStackTrace( System.out );
2311             return false;
2312         }
2313         return true;
2314     }
2315
2316     private static boolean testConfidenceAssessor() {
2317         try {
2318             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2319             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2320             final Phylogeny[] ev0 = factory
2321                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2322                              new NHXParser() );
2323             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2324             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2325                 return false;
2326             }
2327             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2328                 return false;
2329             }
2330             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2331             final Phylogeny[] ev1 = factory
2332                     .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)));",
2333                              new NHXParser() );
2334             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2335             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2336                 return false;
2337             }
2338             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2339                 return false;
2340             }
2341             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2342             final Phylogeny[] ev_b = factory
2343                     .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",
2344                              new NHXParser() );
2345             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2346             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2347                 return false;
2348             }
2349             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2350                 return false;
2351             }
2352             //
2353             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2354             final Phylogeny[] ev1x = factory
2355                     .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)));",
2356                              new NHXParser() );
2357             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2358             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2359                 return false;
2360             }
2361             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2362                 return false;
2363             }
2364             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2365             final Phylogeny[] ev_bx = factory
2366                     .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",
2367                              new NHXParser() );
2368             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2369             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2370                 return false;
2371             }
2372             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2373                 return false;
2374             }
2375             //
2376             final Phylogeny[] t2 = factory
2377                     .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);",
2378                              new NHXParser() );
2379             final Phylogeny[] ev2 = factory
2380                     .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);",
2381                              new NHXParser() );
2382             for( final Phylogeny target : t2 ) {
2383                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2384             }
2385             //
2386             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2387                                                  new NHXParser() )[ 0 ];
2388             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2389             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2390             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2391                 return false;
2392             }
2393             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2394                 return false;
2395             }
2396             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2397                 return false;
2398             }
2399         }
2400         catch ( final Exception e ) {
2401             e.printStackTrace();
2402             return false;
2403         }
2404         return true;
2405     }
2406
2407     private static boolean testCopyOfNodeData() {
2408         try {
2409             final PhylogenyNode n1 = PhylogenyNode
2410                     .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]" );
2411             final PhylogenyNode n2 = n1.copyNodeData();
2412             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2413                 return false;
2414             }
2415         }
2416         catch ( final Exception e ) {
2417             e.printStackTrace();
2418             return false;
2419         }
2420         return true;
2421     }
2422
2423     private static boolean testCreateBalancedPhylogeny() {
2424         try {
2425             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
2426             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
2427                 return false;
2428             }
2429             if ( p0.getNumberOfExternalNodes() != 15625 ) {
2430                 return false;
2431             }
2432             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
2433             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
2434                 return false;
2435             }
2436             if ( p1.getNumberOfExternalNodes() != 100 ) {
2437                 return false;
2438             }
2439         }
2440         catch ( final Exception e ) {
2441             e.printStackTrace();
2442             return false;
2443         }
2444         return true;
2445     }
2446
2447     private static boolean testCreateUriForSeqWeb() {
2448         try {
2449             final PhylogenyNode n = new PhylogenyNode();
2450             n.setName( "tr|B3RJ64" );
2451             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
2452                 return false;
2453             }
2454             n.setName( "B0LM41_HUMAN" );
2455             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
2456                 return false;
2457             }
2458             n.setName( "NP_001025424" );
2459             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
2460                 return false;
2461             }
2462             n.setName( "_NM_001030253-" );
2463             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
2464                 return false;
2465             }
2466             n.setName( "XM_002122186" );
2467             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
2468                 return false;
2469             }
2470             n.setName( "dgh_AAA34956_gdg" );
2471             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
2472                 return false;
2473             }
2474             n.setName( "j40f4_Q06891.1_fndn2 fnr3" );
2475             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "Q06891.1" ) ) {
2476                 return false;
2477             }
2478             n.setName( "GI:394892" );
2479             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2480                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2481                 return false;
2482             }
2483             n.setName( "gi_394892" );
2484             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2485                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2486                 return false;
2487             }
2488             n.setName( "gi6335_gi_394892_56635_Gi_43" );
2489             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2490                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2491                 return false;
2492             }
2493         }
2494         catch ( final Exception e ) {
2495             e.printStackTrace( System.out );
2496             return false;
2497         }
2498         return true;
2499     }
2500
2501     private static boolean testDataObjects() {
2502         try {
2503             final Confidence s0 = new Confidence();
2504             final Confidence s1 = new Confidence();
2505             if ( !s0.isEqual( s1 ) ) {
2506                 return false;
2507             }
2508             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2509             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2510             if ( s2.isEqual( s1 ) ) {
2511                 return false;
2512             }
2513             if ( !s2.isEqual( s3 ) ) {
2514                 return false;
2515             }
2516             final Confidence s4 = ( Confidence ) s3.copy();
2517             if ( !s4.isEqual( s3 ) ) {
2518                 return false;
2519             }
2520             s3.asSimpleText();
2521             s3.asText();
2522             // Taxonomy
2523             // ----------
2524             final Taxonomy t1 = new Taxonomy();
2525             final Taxonomy t2 = new Taxonomy();
2526             final Taxonomy t3 = new Taxonomy();
2527             final Taxonomy t4 = new Taxonomy();
2528             final Taxonomy t5 = new Taxonomy();
2529             t1.setIdentifier( new Identifier( "ecoli" ) );
2530             t1.setTaxonomyCode( "ECOLI" );
2531             t1.setScientificName( "E. coli" );
2532             t1.setCommonName( "coli" );
2533             final Taxonomy t0 = ( Taxonomy ) t1.copy();
2534             if ( !t1.isEqual( t0 ) ) {
2535                 return false;
2536             }
2537             t2.setIdentifier( new Identifier( "ecoli" ) );
2538             t2.setTaxonomyCode( "OTHER" );
2539             t2.setScientificName( "what" );
2540             t2.setCommonName( "something" );
2541             if ( !t1.isEqual( t2 ) ) {
2542                 return false;
2543             }
2544             t2.setIdentifier( new Identifier( "nemve" ) );
2545             if ( t1.isEqual( t2 ) ) {
2546                 return false;
2547             }
2548             t1.setIdentifier( null );
2549             t3.setTaxonomyCode( "ECOLI" );
2550             t3.setScientificName( "what" );
2551             t3.setCommonName( "something" );
2552             if ( !t1.isEqual( t3 ) ) {
2553                 return false;
2554             }
2555             t1.setIdentifier( null );
2556             t1.setTaxonomyCode( "" );
2557             t4.setScientificName( "E. ColI" );
2558             t4.setCommonName( "something" );
2559             if ( !t1.isEqual( t4 ) ) {
2560                 return false;
2561             }
2562             t4.setScientificName( "B. subtilis" );
2563             t4.setCommonName( "something" );
2564             if ( t1.isEqual( t4 ) ) {
2565                 return false;
2566             }
2567             t1.setIdentifier( null );
2568             t1.setTaxonomyCode( "" );
2569             t1.setScientificName( "" );
2570             t5.setCommonName( "COLI" );
2571             if ( !t1.isEqual( t5 ) ) {
2572                 return false;
2573             }
2574             t5.setCommonName( "vibrio" );
2575             if ( t1.isEqual( t5 ) ) {
2576                 return false;
2577             }
2578             // Identifier
2579             // ----------
2580             final Identifier id0 = new Identifier( "123", "pfam" );
2581             final Identifier id1 = ( Identifier ) id0.copy();
2582             if ( !id1.isEqual( id1 ) ) {
2583                 return false;
2584             }
2585             if ( !id1.isEqual( id0 ) ) {
2586                 return false;
2587             }
2588             if ( !id0.isEqual( id1 ) ) {
2589                 return false;
2590             }
2591             id1.asSimpleText();
2592             id1.asText();
2593             // ProteinDomain
2594             // ---------------
2595             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
2596             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
2597             if ( !pd1.isEqual( pd1 ) ) {
2598                 return false;
2599             }
2600             if ( !pd1.isEqual( pd0 ) ) {
2601                 return false;
2602             }
2603             pd1.asSimpleText();
2604             pd1.asText();
2605             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
2606             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
2607             if ( !pd3.isEqual( pd3 ) ) {
2608                 return false;
2609             }
2610             if ( !pd2.isEqual( pd3 ) ) {
2611                 return false;
2612             }
2613             if ( !pd0.isEqual( pd3 ) ) {
2614                 return false;
2615             }
2616             pd3.asSimpleText();
2617             pd3.asText();
2618             // DomainArchitecture
2619             // ------------------
2620             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
2621             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
2622             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
2623             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
2624             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
2625             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
2626             domains0.add( d2 );
2627             domains0.add( d0 );
2628             domains0.add( d3 );
2629             domains0.add( d1 );
2630             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
2631             if ( ds0.getNumberOfDomains() != 4 ) {
2632                 return false;
2633             }
2634             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
2635             if ( !ds0.isEqual( ds0 ) ) {
2636                 return false;
2637             }
2638             if ( !ds0.isEqual( ds1 ) ) {
2639                 return false;
2640             }
2641             if ( ds1.getNumberOfDomains() != 4 ) {
2642                 return false;
2643             }
2644             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
2645             domains1.add( d1 );
2646             domains1.add( d2 );
2647             domains1.add( d4 );
2648             domains1.add( d0 );
2649             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
2650             if ( ds0.isEqual( ds2 ) ) {
2651                 return false;
2652             }
2653             ds1.asSimpleText();
2654             ds1.asText();
2655             ds1.toNHX();
2656             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
2657             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
2658                 System.out.println( ds3.toNHX() );
2659                 return false;
2660             }
2661             if ( ds3.getNumberOfDomains() != 3 ) {
2662                 return false;
2663             }
2664             // Event
2665             // -----
2666             final Event e1 = new Event( Event.EventType.fusion );
2667             if ( e1.isDuplication() ) {
2668                 return false;
2669             }
2670             if ( !e1.isFusion() ) {
2671                 return false;
2672             }
2673             if ( !e1.asText().toString().equals( "fusion" ) ) {
2674                 return false;
2675             }
2676             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
2677                 return false;
2678             }
2679             final Event e11 = new Event( Event.EventType.fusion );
2680             if ( !e11.isEqual( e1 ) ) {
2681                 return false;
2682             }
2683             if ( !e11.toNHX().toString().equals( "" ) ) {
2684                 return false;
2685             }
2686             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
2687             if ( e2.isDuplication() ) {
2688                 return false;
2689             }
2690             if ( !e2.isSpeciationOrDuplication() ) {
2691                 return false;
2692             }
2693             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
2694                 return false;
2695             }
2696             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
2697                 return false;
2698             }
2699             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
2700                 return false;
2701             }
2702             if ( e11.isEqual( e2 ) ) {
2703                 return false;
2704             }
2705             final Event e2c = ( Event ) e2.copy();
2706             if ( !e2c.isEqual( e2 ) ) {
2707                 return false;
2708             }
2709             Event e3 = new Event( 1, 2, 3 );
2710             if ( e3.isDuplication() ) {
2711                 return false;
2712             }
2713             if ( e3.isSpeciation() ) {
2714                 return false;
2715             }
2716             if ( e3.isGeneLoss() ) {
2717                 return false;
2718             }
2719             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2720                 return false;
2721             }
2722             final Event e3c = ( Event ) e3.copy();
2723             final Event e3cc = ( Event ) e3c.copy();
2724             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
2725                 return false;
2726             }
2727             e3 = null;
2728             if ( !e3c.isEqual( e3cc ) ) {
2729                 return false;
2730             }
2731             Event e4 = new Event( 1, 2, 3 );
2732             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2733                 return false;
2734             }
2735             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
2736                 return false;
2737             }
2738             final Event e4c = ( Event ) e4.copy();
2739             e4 = null;
2740             final Event e4cc = ( Event ) e4c.copy();
2741             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2742                 return false;
2743             }
2744             if ( !e4c.isEqual( e4cc ) ) {
2745                 return false;
2746             }
2747             final Event e5 = new Event();
2748             if ( !e5.isUnassigned() ) {
2749                 return false;
2750             }
2751             if ( !e5.asText().toString().equals( "unassigned" ) ) {
2752                 return false;
2753             }
2754             if ( !e5.asSimpleText().toString().equals( "" ) ) {
2755                 return false;
2756             }
2757             final Event e6 = new Event( 1, 0, 0 );
2758             if ( !e6.asText().toString().equals( "duplication" ) ) {
2759                 return false;
2760             }
2761             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
2762                 return false;
2763             }
2764             final Event e7 = new Event( 0, 1, 0 );
2765             if ( !e7.asText().toString().equals( "speciation" ) ) {
2766                 return false;
2767             }
2768             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
2769                 return false;
2770             }
2771             final Event e8 = new Event( 0, 0, 1 );
2772             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
2773                 return false;
2774             }
2775             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
2776                 return false;
2777             }
2778         }
2779         catch ( final Exception e ) {
2780             e.printStackTrace( System.out );
2781             return false;
2782         }
2783         return true;
2784     }
2785
2786     private static boolean testDeletionOfExternalNodes() {
2787         try {
2788             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2789             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
2790             final PhylogenyWriter w = new PhylogenyWriter();
2791             if ( t0.isEmpty() ) {
2792                 return false;
2793             }
2794             if ( t0.getNumberOfExternalNodes() != 1 ) {
2795                 return false;
2796             }
2797             t0.deleteSubtree( t0.getNode( "A" ), false );
2798             if ( t0.getNumberOfExternalNodes() != 0 ) {
2799                 return false;
2800             }
2801             if ( !t0.isEmpty() ) {
2802                 return false;
2803             }
2804             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
2805             if ( t1.getNumberOfExternalNodes() != 2 ) {
2806                 return false;
2807             }
2808             t1.deleteSubtree( t1.getNode( "A" ), false );
2809             if ( t1.getNumberOfExternalNodes() != 1 ) {
2810                 return false;
2811             }
2812             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
2813                 return false;
2814             }
2815             t1.deleteSubtree( t1.getNode( "B" ), false );
2816             if ( t1.getNumberOfExternalNodes() != 1 ) {
2817                 return false;
2818             }
2819             t1.deleteSubtree( t1.getNode( "r" ), false );
2820             if ( !t1.isEmpty() ) {
2821                 return false;
2822             }
2823             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
2824             if ( t2.getNumberOfExternalNodes() != 3 ) {
2825                 return false;
2826             }
2827             t2.deleteSubtree( t2.getNode( "B" ), false );
2828             if ( t2.getNumberOfExternalNodes() != 2 ) {
2829                 return false;
2830             }
2831             t2.toNewHampshireX();
2832             PhylogenyNode n = t2.getNode( "A" );
2833             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2834                 return false;
2835             }
2836             t2.deleteSubtree( t2.getNode( "A" ), false );
2837             if ( t2.getNumberOfExternalNodes() != 2 ) {
2838                 return false;
2839             }
2840             t2.deleteSubtree( t2.getNode( "C" ), true );
2841             if ( t2.getNumberOfExternalNodes() != 1 ) {
2842                 return false;
2843             }
2844             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2845             if ( t3.getNumberOfExternalNodes() != 4 ) {
2846                 return false;
2847             }
2848             t3.deleteSubtree( t3.getNode( "B" ), true );
2849             if ( t3.getNumberOfExternalNodes() != 3 ) {
2850                 return false;
2851             }
2852             n = t3.getNode( "A" );
2853             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2854                 return false;
2855             }
2856             n = n.getNextExternalNode();
2857             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2858                 return false;
2859             }
2860             t3.deleteSubtree( t3.getNode( "A" ), true );
2861             if ( t3.getNumberOfExternalNodes() != 2 ) {
2862                 return false;
2863             }
2864             n = t3.getNode( "C" );
2865             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2866                 return false;
2867             }
2868             t3.deleteSubtree( t3.getNode( "C" ), true );
2869             if ( t3.getNumberOfExternalNodes() != 1 ) {
2870                 return false;
2871             }
2872             t3.deleteSubtree( t3.getNode( "D" ), true );
2873             if ( t3.getNumberOfExternalNodes() != 0 ) {
2874                 return false;
2875             }
2876             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2877             if ( t4.getNumberOfExternalNodes() != 6 ) {
2878                 return false;
2879             }
2880             t4.deleteSubtree( t4.getNode( "B2" ), true );
2881             if ( t4.getNumberOfExternalNodes() != 5 ) {
2882                 return false;
2883             }
2884             String s = w.toNewHampshire( t4, false, true ).toString();
2885             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2886                 return false;
2887             }
2888             t4.deleteSubtree( t4.getNode( "B11" ), true );
2889             if ( t4.getNumberOfExternalNodes() != 4 ) {
2890                 return false;
2891             }
2892             t4.deleteSubtree( t4.getNode( "C" ), true );
2893             if ( t4.getNumberOfExternalNodes() != 3 ) {
2894                 return false;
2895             }
2896             n = t4.getNode( "A" );
2897             n = n.getNextExternalNode();
2898             if ( !n.getName().equals( "B12" ) ) {
2899                 return false;
2900             }
2901             n = n.getNextExternalNode();
2902             if ( !n.getName().equals( "D" ) ) {
2903                 return false;
2904             }
2905             s = w.toNewHampshire( t4, false, true ).toString();
2906             if ( !s.equals( "((A,B12),D);" ) ) {
2907                 return false;
2908             }
2909             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2910             t5.deleteSubtree( t5.getNode( "A" ), true );
2911             if ( t5.getNumberOfExternalNodes() != 5 ) {
2912                 return false;
2913             }
2914             s = w.toNewHampshire( t5, false, true ).toString();
2915             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
2916                 return false;
2917             }
2918             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2919             t6.deleteSubtree( t6.getNode( "B11" ), true );
2920             if ( t6.getNumberOfExternalNodes() != 5 ) {
2921                 return false;
2922             }
2923             s = w.toNewHampshire( t6, false, false ).toString();
2924             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
2925                 return false;
2926             }
2927             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2928             t7.deleteSubtree( t7.getNode( "B12" ), true );
2929             if ( t7.getNumberOfExternalNodes() != 5 ) {
2930                 return false;
2931             }
2932             s = w.toNewHampshire( t7, false, true ).toString();
2933             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
2934                 return false;
2935             }
2936             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2937             t8.deleteSubtree( t8.getNode( "B2" ), true );
2938             if ( t8.getNumberOfExternalNodes() != 5 ) {
2939                 return false;
2940             }
2941             s = w.toNewHampshire( t8, false, false ).toString();
2942             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2943                 return false;
2944             }
2945             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2946             t9.deleteSubtree( t9.getNode( "C" ), true );
2947             if ( t9.getNumberOfExternalNodes() != 5 ) {
2948                 return false;
2949             }
2950             s = w.toNewHampshire( t9, false, true ).toString();
2951             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
2952                 return false;
2953             }
2954             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2955             t10.deleteSubtree( t10.getNode( "D" ), true );
2956             if ( t10.getNumberOfExternalNodes() != 5 ) {
2957                 return false;
2958             }
2959             s = w.toNewHampshire( t10, false, true ).toString();
2960             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
2961                 return false;
2962             }
2963             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
2964             t11.deleteSubtree( t11.getNode( "A" ), true );
2965             if ( t11.getNumberOfExternalNodes() != 2 ) {
2966                 return false;
2967             }
2968             s = w.toNewHampshire( t11, false, true ).toString();
2969             if ( !s.equals( "(B,C);" ) ) {
2970                 return false;
2971             }
2972             t11.deleteSubtree( t11.getNode( "C" ), true );
2973             if ( t11.getNumberOfExternalNodes() != 1 ) {
2974                 return false;
2975             }
2976             s = w.toNewHampshire( t11, false, false ).toString();
2977             if ( !s.equals( "B;" ) ) {
2978                 return false;
2979             }
2980             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
2981             t12.deleteSubtree( t12.getNode( "B2" ), true );
2982             if ( t12.getNumberOfExternalNodes() != 8 ) {
2983                 return false;
2984             }
2985             s = w.toNewHampshire( t12, false, true ).toString();
2986             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
2987                 return false;
2988             }
2989             t12.deleteSubtree( t12.getNode( "B3" ), true );
2990             if ( t12.getNumberOfExternalNodes() != 7 ) {
2991                 return false;
2992             }
2993             s = w.toNewHampshire( t12, false, true ).toString();
2994             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
2995                 return false;
2996             }
2997             t12.deleteSubtree( t12.getNode( "C3" ), true );
2998             if ( t12.getNumberOfExternalNodes() != 6 ) {
2999                 return false;
3000             }
3001             s = w.toNewHampshire( t12, false, true ).toString();
3002             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3003                 return false;
3004             }
3005             t12.deleteSubtree( t12.getNode( "A1" ), true );
3006             if ( t12.getNumberOfExternalNodes() != 5 ) {
3007                 return false;
3008             }
3009             s = w.toNewHampshire( t12, false, true ).toString();
3010             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3011                 return false;
3012             }
3013             t12.deleteSubtree( t12.getNode( "B1" ), true );
3014             if ( t12.getNumberOfExternalNodes() != 4 ) {
3015                 return false;
3016             }
3017             s = w.toNewHampshire( t12, false, true ).toString();
3018             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3019                 return false;
3020             }
3021             t12.deleteSubtree( t12.getNode( "A3" ), true );
3022             if ( t12.getNumberOfExternalNodes() != 3 ) {
3023                 return false;
3024             }
3025             s = w.toNewHampshire( t12, false, true ).toString();
3026             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3027                 return false;
3028             }
3029             t12.deleteSubtree( t12.getNode( "A2" ), true );
3030             if ( t12.getNumberOfExternalNodes() != 2 ) {
3031                 return false;
3032             }
3033             s = w.toNewHampshire( t12, false, true ).toString();
3034             if ( !s.equals( "(C1,C2);" ) ) {
3035                 return false;
3036             }
3037             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3038             t13.deleteSubtree( t13.getNode( "D" ), true );
3039             if ( t13.getNumberOfExternalNodes() != 4 ) {
3040                 return false;
3041             }
3042             s = w.toNewHampshire( t13, false, true ).toString();
3043             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3044                 return false;
3045             }
3046             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3047             t14.deleteSubtree( t14.getNode( "E" ), true );
3048             if ( t14.getNumberOfExternalNodes() != 5 ) {
3049                 return false;
3050             }
3051             s = w.toNewHampshire( t14, false, true ).toString();
3052             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3053                 return false;
3054             }
3055             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3056             t15.deleteSubtree( t15.getNode( "B2" ), true );
3057             if ( t15.getNumberOfExternalNodes() != 11 ) {
3058                 return false;
3059             }
3060             t15.deleteSubtree( t15.getNode( "B1" ), true );
3061             if ( t15.getNumberOfExternalNodes() != 10 ) {
3062                 return false;
3063             }
3064             t15.deleteSubtree( t15.getNode( "B3" ), true );
3065             if ( t15.getNumberOfExternalNodes() != 9 ) {
3066                 return false;
3067             }
3068             t15.deleteSubtree( t15.getNode( "B4" ), true );
3069             if ( t15.getNumberOfExternalNodes() != 8 ) {
3070                 return false;
3071             }
3072             t15.deleteSubtree( t15.getNode( "A1" ), true );
3073             if ( t15.getNumberOfExternalNodes() != 7 ) {
3074                 return false;
3075             }
3076             t15.deleteSubtree( t15.getNode( "C4" ), true );
3077             if ( t15.getNumberOfExternalNodes() != 6 ) {
3078                 return false;
3079             }
3080         }
3081         catch ( final Exception e ) {
3082             e.printStackTrace( System.out );
3083             return false;
3084         }
3085         return true;
3086     }
3087
3088     private static boolean testDescriptiveStatistics() {
3089         try {
3090             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3091             dss1.addValue( 82 );
3092             dss1.addValue( 78 );
3093             dss1.addValue( 70 );
3094             dss1.addValue( 58 );
3095             dss1.addValue( 42 );
3096             if ( dss1.getN() != 5 ) {
3097                 return false;
3098             }
3099             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3100                 return false;
3101             }
3102             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3103                 return false;
3104             }
3105             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3106                 return false;
3107             }
3108             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3109                 return false;
3110             }
3111             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3112                 return false;
3113             }
3114             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3115                 return false;
3116             }
3117             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3118                 return false;
3119             }
3120             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3121                 return false;
3122             }
3123             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3124                 return false;
3125             }
3126             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3127                 return false;
3128             }
3129             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3130                 return false;
3131             }
3132             dss1.addValue( 123 );
3133             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3134                 return false;
3135             }
3136             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3137                 return false;
3138             }
3139             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3140                 return false;
3141             }
3142             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3143             dss2.addValue( -1.85 );
3144             dss2.addValue( 57.5 );
3145             dss2.addValue( 92.78 );
3146             dss2.addValue( 57.78 );
3147             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3148                 return false;
3149             }
3150             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3151                 return false;
3152             }
3153             final double[] a = dss2.getDataAsDoubleArray();
3154             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3155                 return false;
3156             }
3157             dss2.addValue( -100 );
3158             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3159                 return false;
3160             }
3161             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3162                 return false;
3163             }
3164             final double[] ds = new double[ 14 ];
3165             ds[ 0 ] = 34;
3166             ds[ 1 ] = 23;
3167             ds[ 2 ] = 1;
3168             ds[ 3 ] = 32;
3169             ds[ 4 ] = 11;
3170             ds[ 5 ] = 2;
3171             ds[ 6 ] = 12;
3172             ds[ 7 ] = 33;
3173             ds[ 8 ] = 13;
3174             ds[ 9 ] = 22;
3175             ds[ 10 ] = 21;
3176             ds[ 11 ] = 35;
3177             ds[ 12 ] = 24;
3178             ds[ 13 ] = 31;
3179             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3180             if ( bins.length != 4 ) {
3181                 return false;
3182             }
3183             if ( bins[ 0 ] != 2 ) {
3184                 return false;
3185             }
3186             if ( bins[ 1 ] != 3 ) {
3187                 return false;
3188             }
3189             if ( bins[ 2 ] != 4 ) {
3190                 return false;
3191             }
3192             if ( bins[ 3 ] != 5 ) {
3193                 return false;
3194             }
3195             final double[] ds1 = new double[ 9 ];
3196             ds1[ 0 ] = 10.0;
3197             ds1[ 1 ] = 19.0;
3198             ds1[ 2 ] = 9.999;
3199             ds1[ 3 ] = 0.0;
3200             ds1[ 4 ] = 39.9;
3201             ds1[ 5 ] = 39.999;
3202             ds1[ 6 ] = 30.0;
3203             ds1[ 7 ] = 19.999;
3204             ds1[ 8 ] = 30.1;
3205             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3206             if ( bins1.length != 4 ) {
3207                 return false;
3208             }
3209             if ( bins1[ 0 ] != 2 ) {
3210                 return false;
3211             }
3212             if ( bins1[ 1 ] != 3 ) {
3213                 return false;
3214             }
3215             if ( bins1[ 2 ] != 0 ) {
3216                 return false;
3217             }
3218             if ( bins1[ 3 ] != 4 ) {
3219                 return false;
3220             }
3221             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3222             if ( bins1_1.length != 3 ) {
3223                 return false;
3224             }
3225             if ( bins1_1[ 0 ] != 3 ) {
3226                 return false;
3227             }
3228             if ( bins1_1[ 1 ] != 2 ) {
3229                 return false;
3230             }
3231             if ( bins1_1[ 2 ] != 4 ) {
3232                 return false;
3233             }
3234             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3235             if ( bins1_2.length != 3 ) {
3236                 return false;
3237             }
3238             if ( bins1_2[ 0 ] != 2 ) {
3239                 return false;
3240             }
3241             if ( bins1_2[ 1 ] != 2 ) {
3242                 return false;
3243             }
3244             if ( bins1_2[ 2 ] != 2 ) {
3245                 return false;
3246             }
3247             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3248             dss3.addValue( 1 );
3249             dss3.addValue( 1 );
3250             dss3.addValue( 1 );
3251             dss3.addValue( 2 );
3252             dss3.addValue( 3 );
3253             dss3.addValue( 4 );
3254             dss3.addValue( 5 );
3255             dss3.addValue( 5 );
3256             dss3.addValue( 5 );
3257             dss3.addValue( 6 );
3258             dss3.addValue( 7 );
3259             dss3.addValue( 8 );
3260             dss3.addValue( 9 );
3261             dss3.addValue( 10 );
3262             dss3.addValue( 10 );
3263             dss3.addValue( 10 );
3264             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3265             histo.toStringBuffer( 10, '=', 40, 5 );
3266             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3267         }
3268         catch ( final Exception e ) {
3269             e.printStackTrace( System.out );
3270             return false;
3271         }
3272         return true;
3273     }
3274
3275     private static boolean testDir( final String file ) {
3276         try {
3277             final File f = new File( file );
3278             if ( !f.exists() ) {
3279                 return false;
3280             }
3281             if ( !f.isDirectory() ) {
3282                 return false;
3283             }
3284             if ( !f.canRead() ) {
3285                 return false;
3286             }
3287         }
3288         catch ( final Exception e ) {
3289             return false;
3290         }
3291         return true;
3292     }
3293
3294     private static boolean testEmblEntryRetrieval() {
3295         //The format for GenBank Accession numbers are:
3296         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
3297         //Protein:    3 letters + 5 numerals
3298         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
3299         if ( !SequenceIdParser.parseGenbankAccessor( "AY423861" ).equals( "AY423861" ) ) {
3300             return false;
3301         }
3302         if ( !SequenceIdParser.parseGenbankAccessor( ".AY423861.2" ).equals( "AY423861.2" ) ) {
3303             return false;
3304         }
3305         if ( !SequenceIdParser.parseGenbankAccessor( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
3306             return false;
3307         }
3308         if ( SequenceIdParser.parseGenbankAccessor( "AAY423861" ) != null ) {
3309             return false;
3310         }
3311         if ( SequenceIdParser.parseGenbankAccessor( "AY4238612" ) != null ) {
3312             return false;
3313         }
3314         if ( SequenceIdParser.parseGenbankAccessor( "AAY4238612" ) != null ) {
3315             return false;
3316         }
3317         if ( SequenceIdParser.parseGenbankAccessor( "Y423861" ) != null ) {
3318             return false;
3319         }
3320         if ( !SequenceIdParser.parseGenbankAccessor( "S12345" ).equals( "S12345" ) ) {
3321             return false;
3322         }
3323         if ( !SequenceIdParser.parseGenbankAccessor( "|S12345|" ).equals( "S12345" ) ) {
3324             return false;
3325         }
3326         if ( SequenceIdParser.parseGenbankAccessor( "|S123456" ) != null ) {
3327             return false;
3328         }
3329         if ( SequenceIdParser.parseGenbankAccessor( "ABC123456" ) != null ) {
3330             return false;
3331         }
3332         if ( !SequenceIdParser.parseGenbankAccessor( "ABC12345" ).equals( "ABC12345" ) ) {
3333             return false;
3334         }
3335         if ( !SequenceIdParser.parseGenbankAccessor( "&ABC12345&" ).equals( "ABC12345" ) ) {
3336             return false;
3337         }
3338         if ( SequenceIdParser.parseGenbankAccessor( "ABCD12345" ) != null ) {
3339             return false;
3340         }
3341         return true;
3342     }
3343
3344     private static boolean testExternalNodeRelatedMethods() {
3345         try {
3346             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3347             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3348             PhylogenyNode n = t1.getNode( "A" );
3349             n = n.getNextExternalNode();
3350             if ( !n.getName().equals( "B" ) ) {
3351                 return false;
3352             }
3353             n = n.getNextExternalNode();
3354             if ( !n.getName().equals( "C" ) ) {
3355                 return false;
3356             }
3357             n = n.getNextExternalNode();
3358             if ( !n.getName().equals( "D" ) ) {
3359                 return false;
3360             }
3361             n = t1.getNode( "B" );
3362             while ( !n.isLastExternalNode() ) {
3363                 n = n.getNextExternalNode();
3364             }
3365             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
3366             n = t2.getNode( "A" );
3367             n = n.getNextExternalNode();
3368             if ( !n.getName().equals( "B" ) ) {
3369                 return false;
3370             }
3371             n = n.getNextExternalNode();
3372             if ( !n.getName().equals( "C" ) ) {
3373                 return false;
3374             }
3375             n = n.getNextExternalNode();
3376             if ( !n.getName().equals( "D" ) ) {
3377                 return false;
3378             }
3379             n = t2.getNode( "B" );
3380             while ( !n.isLastExternalNode() ) {
3381                 n = n.getNextExternalNode();
3382             }
3383             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3384             n = t3.getNode( "A" );
3385             n = n.getNextExternalNode();
3386             if ( !n.getName().equals( "B" ) ) {
3387                 return false;
3388             }
3389             n = n.getNextExternalNode();
3390             if ( !n.getName().equals( "C" ) ) {
3391                 return false;
3392             }
3393             n = n.getNextExternalNode();
3394             if ( !n.getName().equals( "D" ) ) {
3395                 return false;
3396             }
3397             n = n.getNextExternalNode();
3398             if ( !n.getName().equals( "E" ) ) {
3399                 return false;
3400             }
3401             n = n.getNextExternalNode();
3402             if ( !n.getName().equals( "F" ) ) {
3403                 return false;
3404             }
3405             n = n.getNextExternalNode();
3406             if ( !n.getName().equals( "G" ) ) {
3407                 return false;
3408             }
3409             n = n.getNextExternalNode();
3410             if ( !n.getName().equals( "H" ) ) {
3411                 return false;
3412             }
3413             n = t3.getNode( "B" );
3414             while ( !n.isLastExternalNode() ) {
3415                 n = n.getNextExternalNode();
3416             }
3417             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3418             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
3419                 final PhylogenyNode node = iter.next();
3420             }
3421             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3422             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
3423                 final PhylogenyNode node = iter.next();
3424             }
3425             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
3426             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
3427             if ( !iter.next().getName().equals( "A" ) ) {
3428                 return false;
3429             }
3430             if ( !iter.next().getName().equals( "B" ) ) {
3431                 return false;
3432             }
3433             if ( !iter.next().getName().equals( "C" ) ) {
3434                 return false;
3435             }
3436             if ( !iter.next().getName().equals( "D" ) ) {
3437                 return false;
3438             }
3439             if ( !iter.next().getName().equals( "E" ) ) {
3440                 return false;
3441             }
3442             if ( !iter.next().getName().equals( "F" ) ) {
3443                 return false;
3444             }
3445             if ( iter.hasNext() ) {
3446                 return false;
3447             }
3448         }
3449         catch ( final Exception e ) {
3450             e.printStackTrace( System.out );
3451             return false;
3452         }
3453         return true;
3454     }
3455
3456     private static boolean testExtractSNFromNodeName() {
3457         try {
3458             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
3459                 return false;
3460             }
3461             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus" )
3462                     .equals( "Mus musculus musculus" ) ) {
3463                 return false;
3464             }
3465             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus-12" )
3466                     .equals( "Mus musculus musculus" ) ) {
3467                 return false;
3468             }
3469             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus-12" ).equals( "Mus musculus" ) ) {
3470                 return false;
3471             }
3472             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus-12 affrre e" )
3473                     .equals( "Mus musculus" ) ) {
3474                 return false;
3475             }
3476         }
3477         catch ( final Exception e ) {
3478             e.printStackTrace( System.out );
3479             return false;
3480         }
3481         return true;
3482     }
3483
3484     private static boolean testExtractTaxonomyCodeFromNodeName() {
3485         try {
3486             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3487                 return false;
3488             }
3489             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3490                     .equals( "SOYBN" ) ) {
3491                 return false;
3492             }
3493             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
3494                     .equals( "ARATH" ) ) {
3495                 return false;
3496             }
3497             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
3498                     .equals( "ARATH" ) ) {
3499                 return false;
3500             }
3501             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
3502                 return false;
3503             }
3504             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
3505                 return false;
3506             }
3507             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3508                 return false;
3509             }
3510             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3511                     .equals( "SOYBN" ) ) {
3512                 return false;
3513             }
3514             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3515                     .equals( "SOYBN" ) ) {
3516                 return false;
3517             }
3518             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3519                     .equals( "SOYBN" ) ) {
3520                 return false;
3521             }
3522             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3523                     .equals( "SOYBN" ) ) {
3524                 return false;
3525             }
3526             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3527                     .equals( "SOYBN" ) ) {
3528                 return false;
3529             }
3530             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3531                     .equals( "SOYBN" ) ) {
3532                 return false;
3533             }
3534             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
3535                     .equals( "SOYBN" ) ) {
3536                 return false;
3537             }
3538             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
3539                     .equals( "SOYBN" ) ) {
3540                 return false;
3541             }
3542             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
3543                 return false;
3544             }
3545             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
3546                     .equals( "SOYBN" ) ) {
3547                 return false;
3548             }
3549             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
3550                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
3551                 return false;
3552             }
3553             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
3554                     .equals( "9YX45" ) ) {
3555                 return false;
3556             }
3557             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
3558                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3559                     .equals( "MOUSE" ) ) {
3560                 return false;
3561             }
3562             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
3563                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3564                     .equals( "MOUSE" ) ) {
3565                 return false;
3566             }
3567             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
3568                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3569                     .equals( "MOUSE" ) ) {
3570                 return false;
3571             }
3572             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
3573                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3574                 return false;
3575             }
3576             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
3577                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3578                 return false;
3579             }
3580             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
3581                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
3582                 return false;
3583             }
3584             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
3585                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
3586                 return false;
3587             }
3588             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
3589                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
3590                 return false;
3591             }
3592             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
3593                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3594                 return false;
3595             }
3596             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
3597                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3598                 return false;
3599             }
3600             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3601                     .equals( "RAT" ) ) {
3602                 return false;
3603             }
3604             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
3605                     .equals( "PIG" ) ) {
3606                 return false;
3607             }
3608             if ( !ParserUtils
3609                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3610                     .equals( "MOUSE" ) ) {
3611                 return false;
3612             }
3613             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
3614                     .equals( "MOUSE" ) ) {
3615                 return false;
3616             }
3617             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3618                 return false;
3619             }
3620         }
3621         catch ( final Exception e ) {
3622             e.printStackTrace( System.out );
3623             return false;
3624         }
3625         return true;
3626     }
3627
3628     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
3629         try {
3630             PhylogenyNode n = new PhylogenyNode();
3631             n.setName( "tr|B3RJ64" );
3632             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3633                 return false;
3634             }
3635             n.setName( "tr.B3RJ64" );
3636             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3637                 return false;
3638             }
3639             n.setName( "tr=B3RJ64" );
3640             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3641                 return false;
3642             }
3643             n.setName( "tr-B3RJ64" );
3644             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3645                 return false;
3646             }
3647             n.setName( "tr/B3RJ64" );
3648             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3649                 return false;
3650             }
3651             n.setName( "tr\\B3RJ64" );
3652             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3653                 return false;
3654             }
3655             n.setName( "tr_B3RJ64" );
3656             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3657                 return false;
3658             }
3659             n.setName( " tr|B3RJ64 " );
3660             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3661                 return false;
3662             }
3663             n.setName( "-tr|B3RJ64-" );
3664             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3665                 return false;
3666             }
3667             n.setName( "-tr=B3RJ64-" );
3668             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3669                 return false;
3670             }
3671             n.setName( "_tr=B3RJ64_" );
3672             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3673                 return false;
3674             }
3675             n.setName( " tr_tr|B3RJ64_sp|123 " );
3676             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3677                 return false;
3678             }
3679             n.setName( "sp|B3RJ64" );
3680             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3681                 return false;
3682             }
3683             n.setName( "ssp|B3RJ64" );
3684             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3685                 return false;
3686             }
3687             n.setName( "sp|B3RJ64C" );
3688             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3689                 return false;
3690             }
3691             n.setName( "sp B3RJ64" );
3692             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3693                 return false;
3694             }
3695             n.setName( "sp|B3RJ6X" );
3696             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3697                 return false;
3698             }
3699             n.setName( "sp|B3RJ6" );
3700             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3701                 return false;
3702             }
3703             n.setName( "K1PYK7_CRAGI" );
3704             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
3705                 return false;
3706             }
3707             n.setName( "K1PYK7_PEA" );
3708             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PEA" ) ) {
3709                 return false;
3710             }
3711             n.setName( "K1PYK7_RAT" );
3712             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_RAT" ) ) {
3713                 return false;
3714             }
3715             n.setName( "K1PYK7_PIG" );
3716             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PIG" ) ) {
3717                 return false;
3718             }
3719             n.setName( "~K1PYK7_PIG~" );
3720             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PIG" ) ) {
3721                 return false;
3722             }
3723             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
3724             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
3725                 return false;
3726             }
3727             n.setName( "K1PYKX_CRAGI" );
3728             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3729                 return false;
3730             }
3731             n.setName( "XXXXX_CRAGI" );
3732             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "XXXXX_CRAGI" ) ) {
3733                 return false;
3734             }
3735             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
3736             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "H3IB65" ) ) {
3737                 return false;
3738             }
3739             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
3740             if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3741                 return false;
3742             }
3743             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
3744             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "Q86U06" ) ) {
3745                 return false;
3746             }
3747             n = new PhylogenyNode();
3748             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
3749             seq.setSymbol( "K1PYK7_CRAGI" );
3750             n.getNodeData().addSequence( seq );
3751             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
3752                 return false;
3753             }
3754             seq.setSymbol( "tr|B3RJ64" );
3755             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3756                 return false;
3757             }
3758             n = new PhylogenyNode();
3759             seq = new org.forester.phylogeny.data.Sequence();
3760             seq.setName( "K1PYK7_CRAGI" );
3761             n.getNodeData().addSequence( seq );
3762             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
3763                 return false;
3764             }
3765             seq.setName( "tr|B3RJ64" );
3766             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3767                 return false;
3768             }
3769             n = new PhylogenyNode();
3770             seq = new org.forester.phylogeny.data.Sequence();
3771             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
3772             n.getNodeData().addSequence( seq );
3773             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK8_CRAGI" ) ) {
3774                 return false;
3775             }
3776             n = new PhylogenyNode();
3777             seq = new org.forester.phylogeny.data.Sequence();
3778             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
3779             n.getNodeData().addSequence( seq );
3780             if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3781                 return false;
3782             }
3783             //
3784             n = new PhylogenyNode();
3785             n.setName( "ACP19736" );
3786             if ( !ForesterUtil.extractGenbankAccessor( n ).equals( "ACP19736" ) ) {
3787                 return false;
3788             }
3789             n = new PhylogenyNode();
3790             n.setName( "_ACP19736_" );
3791             if ( !ForesterUtil.extractGenbankAccessor( n ).equals( "ACP19736" ) ) {
3792                 return false;
3793             }
3794         }
3795         catch ( final Exception e ) {
3796             e.printStackTrace( System.out );
3797             return false;
3798         }
3799         return true;
3800     }
3801
3802     private static boolean testFastaParser() {
3803         try {
3804             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
3805                 return false;
3806             }
3807             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
3808                 return false;
3809             }
3810             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
3811             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
3812                 return false;
3813             }
3814             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
3815                 return false;
3816             }
3817             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
3818                 return false;
3819             }
3820             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
3821                 return false;
3822             }
3823             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
3824                 return false;
3825             }
3826             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
3827                 return false;
3828             }
3829         }
3830         catch ( final Exception e ) {
3831             e.printStackTrace();
3832             return false;
3833         }
3834         return true;
3835     }
3836
3837     private static boolean testGeneralMsaParser() {
3838         try {
3839             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
3840             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
3841             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
3842             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
3843             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
3844             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
3845             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
3846             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
3847             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
3848                 return false;
3849             }
3850             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
3851                 return false;
3852             }
3853             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
3854                 return false;
3855             }
3856             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
3857                 return false;
3858             }
3859             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
3860                 return false;
3861             }
3862             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
3863                 return false;
3864             }
3865             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
3866                 return false;
3867             }
3868             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
3869                 return false;
3870             }
3871             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
3872                 return false;
3873             }
3874             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
3875                 return false;
3876             }
3877             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
3878                 return false;
3879             }
3880             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
3881                 return false;
3882             }
3883             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
3884             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
3885                 return false;
3886             }
3887             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
3888                 return false;
3889             }
3890             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
3891                 return false;
3892             }
3893             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
3894             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
3895                 return false;
3896             }
3897             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
3898                 return false;
3899             }
3900             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
3901                 return false;
3902             }
3903             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
3904             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
3905                 return false;
3906             }
3907             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
3908                 return false;
3909             }
3910             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
3911                 return false;
3912             }
3913         }
3914         catch ( final Exception e ) {
3915             e.printStackTrace();
3916             return false;
3917         }
3918         return true;
3919     }
3920
3921     private static boolean testGeneralTable() {
3922         try {
3923             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
3924             t0.setValue( 3, 2, "23" );
3925             t0.setValue( 10, 1, "error" );
3926             t0.setValue( 10, 1, "110" );
3927             t0.setValue( 9, 1, "19" );
3928             t0.setValue( 1, 10, "101" );
3929             t0.setValue( 10, 10, "1010" );
3930             t0.setValue( 100, 10, "10100" );
3931             t0.setValue( 0, 0, "00" );
3932             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
3933                 return false;
3934             }
3935             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
3936                 return false;
3937             }
3938             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
3939                 return false;
3940             }
3941             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
3942                 return false;
3943             }
3944             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
3945                 return false;
3946             }
3947             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
3948                 return false;
3949             }
3950             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
3951                 return false;
3952             }
3953             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
3954                 return false;
3955             }
3956             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
3957                 return false;
3958             }
3959             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
3960             t1.setValue( "3", "2", "23" );
3961             t1.setValue( "10", "1", "error" );
3962             t1.setValue( "10", "1", "110" );
3963             t1.setValue( "9", "1", "19" );
3964             t1.setValue( "1", "10", "101" );
3965             t1.setValue( "10", "10", "1010" );
3966             t1.setValue( "100", "10", "10100" );
3967             t1.setValue( "0", "0", "00" );
3968             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
3969             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
3970                 return false;
3971             }
3972             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
3973                 return false;
3974             }
3975             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
3976                 return false;
3977             }
3978             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
3979                 return false;
3980             }
3981             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
3982                 return false;
3983             }
3984             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
3985                 return false;
3986             }
3987             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
3988                 return false;
3989             }
3990             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
3991                 return false;
3992             }
3993             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
3994                 return false;
3995             }
3996             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
3997                 return false;
3998             }
3999         }
4000         catch ( final Exception e ) {
4001             e.printStackTrace( System.out );
4002             return false;
4003         }
4004         return true;
4005     }
4006
4007     private static boolean testGetDistance() {
4008         try {
4009             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4010             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",
4011                                                  new NHXParser() )[ 0 ];
4012             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
4013                 return false;
4014             }
4015             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
4016                 return false;
4017             }
4018             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
4019                 return false;
4020             }
4021             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
4022                 return false;
4023             }
4024             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
4025                 return false;
4026             }
4027             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
4028                 return false;
4029             }
4030             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
4031                 return false;
4032             }
4033             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
4034                 return false;
4035             }
4036             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
4037                 return false;
4038             }
4039             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
4040                 return false;
4041             }
4042             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
4043                 return false;
4044             }
4045             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
4046                 return false;
4047             }
4048             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
4049                 return false;
4050             }
4051             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
4052                 return false;
4053             }
4054             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
4055                 return false;
4056             }
4057             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
4058                 return false;
4059             }
4060             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
4061                 return false;
4062             }
4063             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
4064                 return false;
4065             }
4066             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
4067                 return false;
4068             }
4069             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
4070                 return false;
4071             }
4072             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
4073                 return false;
4074             }
4075             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
4076                 return false;
4077             }
4078             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
4079                 return false;
4080             }
4081             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
4082                 return false;
4083             }
4084             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
4085                 return false;
4086             }
4087             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
4088                 return false;
4089             }
4090             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
4091                 return false;
4092             }
4093             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
4094                 return false;
4095             }
4096             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
4097                 return false;
4098             }
4099             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
4100                 return false;
4101             }
4102             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
4103                 return false;
4104             }
4105             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",
4106                                                  new NHXParser() )[ 0 ];
4107             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
4108                 return false;
4109             }
4110             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
4111                 return false;
4112             }
4113             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
4114                 return false;
4115             }
4116             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
4117                 return false;
4118             }
4119             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
4120                 return false;
4121             }
4122             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
4123                 return false;
4124             }
4125             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
4126                 return false;
4127             }
4128             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
4129                 return false;
4130             }
4131             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
4132                 return false;
4133             }
4134             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
4135                 return false;
4136             }
4137             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
4138                 return false;
4139             }
4140         }
4141         catch ( final Exception e ) {
4142             e.printStackTrace( System.out );
4143             return false;
4144         }
4145         return true;
4146     }
4147
4148     private static boolean testGetLCA() {
4149         try {
4150             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4151             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
4152                                                  new NHXParser() )[ 0 ];
4153             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
4154             if ( !A.getName().equals( "A" ) ) {
4155                 return false;
4156             }
4157             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
4158             if ( !gh.getName().equals( "gh" ) ) {
4159                 return false;
4160             }
4161             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
4162             if ( !ab.getName().equals( "ab" ) ) {
4163                 return false;
4164             }
4165             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
4166             if ( !ab2.getName().equals( "ab" ) ) {
4167                 return false;
4168             }
4169             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
4170             if ( !gh2.getName().equals( "gh" ) ) {
4171                 return false;
4172             }
4173             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
4174             if ( !gh3.getName().equals( "gh" ) ) {
4175                 return false;
4176             }
4177             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
4178             if ( !abc.getName().equals( "abc" ) ) {
4179                 return false;
4180             }
4181             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
4182             if ( !abc2.getName().equals( "abc" ) ) {
4183                 return false;
4184             }
4185             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
4186             if ( !abcd.getName().equals( "abcd" ) ) {
4187                 return false;
4188             }
4189             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
4190             if ( !abcd2.getName().equals( "abcd" ) ) {
4191                 return false;
4192             }
4193             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
4194             if ( !abcdef.getName().equals( "abcdef" ) ) {
4195                 return false;
4196             }
4197             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
4198             if ( !abcdef2.getName().equals( "abcdef" ) ) {
4199                 return false;
4200             }
4201             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
4202             if ( !abcdef3.getName().equals( "abcdef" ) ) {
4203                 return false;
4204             }
4205             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
4206             if ( !abcdef4.getName().equals( "abcdef" ) ) {
4207                 return false;
4208             }
4209             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
4210             if ( !abcde.getName().equals( "abcde" ) ) {
4211                 return false;
4212             }
4213             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
4214             if ( !abcde2.getName().equals( "abcde" ) ) {
4215                 return false;
4216             }
4217             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
4218             if ( !r.getName().equals( "abcdefgh" ) ) {
4219                 return false;
4220             }
4221             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
4222             if ( !r2.getName().equals( "abcdefgh" ) ) {
4223                 return false;
4224             }
4225             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
4226             if ( !r3.getName().equals( "abcdefgh" ) ) {
4227                 return false;
4228             }
4229             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
4230             if ( !abcde3.getName().equals( "abcde" ) ) {
4231                 return false;
4232             }
4233             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
4234             if ( !abcde4.getName().equals( "abcde" ) ) {
4235                 return false;
4236             }
4237             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
4238             if ( !ab3.getName().equals( "ab" ) ) {
4239                 return false;
4240             }
4241             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
4242             if ( !ab4.getName().equals( "ab" ) ) {
4243                 return false;
4244             }
4245             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
4246             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
4247             if ( !cd.getName().equals( "cd" ) ) {
4248                 return false;
4249             }
4250             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
4251             if ( !cd2.getName().equals( "cd" ) ) {
4252                 return false;
4253             }
4254             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
4255             if ( !cde.getName().equals( "cde" ) ) {
4256                 return false;
4257             }
4258             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
4259             if ( !cde2.getName().equals( "cde" ) ) {
4260                 return false;
4261             }
4262             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
4263             if ( !cdef.getName().equals( "cdef" ) ) {
4264                 return false;
4265             }
4266             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
4267             if ( !cdef2.getName().equals( "cdef" ) ) {
4268                 return false;
4269             }
4270             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
4271             if ( !cdef3.getName().equals( "cdef" ) ) {
4272                 return false;
4273             }
4274             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
4275             if ( !rt.getName().equals( "r" ) ) {
4276                 return false;
4277             }
4278             final Phylogeny p3 = factory
4279                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
4280                              new NHXParser() )[ 0 ];
4281             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
4282             if ( !bc_3.getName().equals( "bc" ) ) {
4283                 return false;
4284             }
4285             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
4286             if ( !ac_3.getName().equals( "abc" ) ) {
4287                 return false;
4288             }
4289             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
4290             if ( !ad_3.getName().equals( "abcde" ) ) {
4291                 return false;
4292             }
4293             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
4294             if ( !af_3.getName().equals( "abcdef" ) ) {
4295                 return false;
4296             }
4297             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
4298             if ( !ag_3.getName().equals( "" ) ) {
4299                 return false;
4300             }
4301             if ( !ag_3.isRoot() ) {
4302                 return false;
4303             }
4304             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
4305             if ( !al_3.getName().equals( "" ) ) {
4306                 return false;
4307             }
4308             if ( !al_3.isRoot() ) {
4309                 return false;
4310             }
4311             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
4312             if ( !kl_3.getName().equals( "" ) ) {
4313                 return false;
4314             }
4315             if ( !kl_3.isRoot() ) {
4316                 return false;
4317             }
4318             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
4319             if ( !fl_3.getName().equals( "" ) ) {
4320                 return false;
4321             }
4322             if ( !fl_3.isRoot() ) {
4323                 return false;
4324             }
4325             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
4326             if ( !gk_3.getName().equals( "ghijk" ) ) {
4327                 return false;
4328             }
4329             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
4330             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
4331             if ( !r_4.getName().equals( "r" ) ) {
4332                 return false;
4333             }
4334             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
4335             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
4336             if ( !r_5.getName().equals( "root" ) ) {
4337                 return false;
4338             }
4339             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
4340             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
4341             if ( !r_6.getName().equals( "rot" ) ) {
4342                 return false;
4343             }
4344             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
4345             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
4346             if ( !r_7.getName().equals( "rott" ) ) {
4347                 return false;
4348             }
4349         }
4350         catch ( final Exception e ) {
4351             e.printStackTrace( System.out );
4352             return false;
4353         }
4354         return true;
4355     }
4356
4357     private static boolean testGetLCA2() {
4358         try {
4359             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4360             final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
4361             PhylogenyMethods.preOrderReId( p_a );
4362             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
4363                                                                                               p_a.getNode( "a" ) );
4364             if ( !p_a_1.getName().equals( "a" ) ) {
4365                 return false;
4366             }
4367             final Phylogeny p_b = factory.create( "((a)b)", new NHXParser() )[ 0 ];
4368             PhylogenyMethods.preOrderReId( p_b );
4369             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
4370                                                                                               p_b.getNode( "a" ) );
4371             if ( !p_b_1.getName().equals( "b" ) ) {
4372                 return false;
4373             }
4374             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
4375                                                                                               p_b.getNode( "b" ) );
4376             if ( !p_b_2.getName().equals( "b" ) ) {
4377                 return false;
4378             }
4379             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
4380             PhylogenyMethods.preOrderReId( p_c );
4381             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
4382                                                                                               p_c.getNode( "a" ) );
4383             if ( !p_c_1.getName().equals( "b" ) ) {
4384                 return false;
4385             }
4386             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
4387                                                                                               p_c.getNode( "c" ) );
4388             if ( !p_c_2.getName().equals( "c" ) ) {
4389                 System.out.println( p_c_2.getName() );
4390                 System.exit( -1 );
4391                 return false;
4392             }
4393             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
4394                                                                                               p_c.getNode( "b" ) );
4395             if ( !p_c_3.getName().equals( "b" ) ) {
4396                 return false;
4397             }
4398             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
4399                                                                                               p_c.getNode( "a" ) );
4400             if ( !p_c_4.getName().equals( "c" ) ) {
4401                 return false;
4402             }
4403             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
4404                                                  new NHXParser() )[ 0 ];
4405             PhylogenyMethods.preOrderReId( p1 );
4406             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4407                                                                                           p1.getNode( "A" ) );
4408             if ( !A.getName().equals( "A" ) ) {
4409                 return false;
4410             }
4411             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
4412                                                                                            p1.getNode( "gh" ) );
4413             if ( !gh.getName().equals( "gh" ) ) {
4414                 return false;
4415             }
4416             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4417                                                                                            p1.getNode( "B" ) );
4418             if ( !ab.getName().equals( "ab" ) ) {
4419                 return false;
4420             }
4421             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
4422                                                                                             p1.getNode( "A" ) );
4423             if ( !ab2.getName().equals( "ab" ) ) {
4424                 return false;
4425             }
4426             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
4427                                                                                             p1.getNode( "G" ) );
4428             if ( !gh2.getName().equals( "gh" ) ) {
4429                 return false;
4430             }
4431             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
4432                                                                                             p1.getNode( "H" ) );
4433             if ( !gh3.getName().equals( "gh" ) ) {
4434                 return false;
4435             }
4436             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
4437                                                                                             p1.getNode( "A" ) );
4438             if ( !abc.getName().equals( "abc" ) ) {
4439                 return false;
4440             }
4441             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4442                                                                                              p1.getNode( "C" ) );
4443             if ( !abc2.getName().equals( "abc" ) ) {
4444                 return false;
4445             }
4446             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4447                                                                                              p1.getNode( "D" ) );
4448             if ( !abcd.getName().equals( "abcd" ) ) {
4449                 return false;
4450             }
4451             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
4452                                                                                               p1.getNode( "A" ) );
4453             if ( !abcd2.getName().equals( "abcd" ) ) {
4454                 return false;
4455             }
4456             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4457                                                                                                p1.getNode( "F" ) );
4458             if ( !abcdef.getName().equals( "abcdef" ) ) {
4459                 return false;
4460             }
4461             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
4462                                                                                                 p1.getNode( "A" ) );
4463             if ( !abcdef2.getName().equals( "abcdef" ) ) {
4464                 return false;
4465             }
4466             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
4467                                                                                                 p1.getNode( "F" ) );
4468             if ( !abcdef3.getName().equals( "abcdef" ) ) {
4469                 return false;
4470             }
4471             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
4472                                                                                                 p1.getNode( "ab" ) );
4473             if ( !abcdef4.getName().equals( "abcdef" ) ) {
4474                 return false;
4475             }
4476             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4477                                                                                               p1.getNode( "E" ) );
4478             if ( !abcde.getName().equals( "abcde" ) ) {
4479                 return false;
4480             }
4481             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
4482                                                                                                p1.getNode( "A" ) );
4483             if ( !abcde2.getName().equals( "abcde" ) ) {
4484                 return false;
4485             }
4486             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
4487                                                                                           p1.getNode( "abcdefgh" ) );
4488             if ( !r.getName().equals( "abcdefgh" ) ) {
4489                 return false;
4490             }
4491             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4492                                                                                            p1.getNode( "H" ) );
4493             if ( !r2.getName().equals( "abcdefgh" ) ) {
4494                 return false;
4495             }
4496             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
4497                                                                                            p1.getNode( "A" ) );
4498             if ( !r3.getName().equals( "abcdefgh" ) ) {
4499                 return false;
4500             }
4501             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
4502                                                                                                p1.getNode( "abcde" ) );
4503             if ( !abcde3.getName().equals( "abcde" ) ) {
4504                 return false;
4505             }
4506             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
4507                                                                                                p1.getNode( "E" ) );
4508             if ( !abcde4.getName().equals( "abcde" ) ) {
4509                 return false;
4510             }
4511             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
4512                                                                                             p1.getNode( "B" ) );
4513             if ( !ab3.getName().equals( "ab" ) ) {
4514                 return false;
4515             }
4516             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
4517                                                                                             p1.getNode( "ab" ) );
4518             if ( !ab4.getName().equals( "ab" ) ) {
4519                 return false;
4520             }
4521             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
4522             PhylogenyMethods.preOrderReId( p2 );
4523             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4524                                                                                            p2.getNode( "d" ) );
4525             if ( !cd.getName().equals( "cd" ) ) {
4526                 return false;
4527             }
4528             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
4529                                                                                             p2.getNode( "c" ) );
4530             if ( !cd2.getName().equals( "cd" ) ) {
4531                 return false;
4532             }
4533             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4534                                                                                             p2.getNode( "e" ) );
4535             if ( !cde.getName().equals( "cde" ) ) {
4536                 return false;
4537             }
4538             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
4539                                                                                              p2.getNode( "c" ) );
4540             if ( !cde2.getName().equals( "cde" ) ) {
4541                 return false;
4542             }
4543             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4544                                                                                              p2.getNode( "f" ) );
4545             if ( !cdef.getName().equals( "cdef" ) ) {
4546                 return false;
4547             }
4548             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
4549                                                                                               p2.getNode( "f" ) );
4550             if ( !cdef2.getName().equals( "cdef" ) ) {
4551                 return false;
4552             }
4553             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
4554                                                                                               p2.getNode( "d" ) );
4555             if ( !cdef3.getName().equals( "cdef" ) ) {
4556                 return false;
4557             }
4558             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4559                                                                                            p2.getNode( "a" ) );
4560             if ( !rt.getName().equals( "r" ) ) {
4561                 return false;
4562             }
4563             final Phylogeny p3 = factory
4564                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
4565                              new NHXParser() )[ 0 ];
4566             PhylogenyMethods.preOrderReId( p3 );
4567             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
4568                                                                                              p3.getNode( "c" ) );
4569             if ( !bc_3.getName().equals( "bc" ) ) {
4570                 return false;
4571             }
4572             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4573                                                                                              p3.getNode( "c" ) );
4574             if ( !ac_3.getName().equals( "abc" ) ) {
4575                 return false;
4576             }
4577             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4578                                                                                              p3.getNode( "d" ) );
4579             if ( !ad_3.getName().equals( "abcde" ) ) {
4580                 return false;
4581             }
4582             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4583                                                                                              p3.getNode( "f" ) );
4584             if ( !af_3.getName().equals( "abcdef" ) ) {
4585                 return false;
4586             }
4587             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4588                                                                                              p3.getNode( "g" ) );
4589             if ( !ag_3.getName().equals( "" ) ) {
4590                 return false;
4591             }
4592             if ( !ag_3.isRoot() ) {
4593                 return false;
4594             }
4595             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4596                                                                                              p3.getNode( "l" ) );
4597             if ( !al_3.getName().equals( "" ) ) {
4598                 return false;
4599             }
4600             if ( !al_3.isRoot() ) {
4601                 return false;
4602             }
4603             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
4604                                                                                              p3.getNode( "l" ) );
4605             if ( !kl_3.getName().equals( "" ) ) {
4606                 return false;
4607             }
4608             if ( !kl_3.isRoot() ) {
4609                 return false;
4610             }
4611             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
4612                                                                                              p3.getNode( "l" ) );
4613             if ( !fl_3.getName().equals( "" ) ) {
4614                 return false;
4615             }
4616             if ( !fl_3.isRoot() ) {
4617                 return false;
4618             }
4619             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
4620                                                                                              p3.getNode( "k" ) );
4621             if ( !gk_3.getName().equals( "ghijk" ) ) {
4622                 return false;
4623             }
4624             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
4625             PhylogenyMethods.preOrderReId( p4 );
4626             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
4627                                                                                             p4.getNode( "c" ) );
4628             if ( !r_4.getName().equals( "r" ) ) {
4629                 return false;
4630             }
4631             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
4632             PhylogenyMethods.preOrderReId( p5 );
4633             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
4634                                                                                             p5.getNode( "c" ) );
4635             if ( !r_5.getName().equals( "root" ) ) {
4636                 return false;
4637             }
4638             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
4639             PhylogenyMethods.preOrderReId( p6 );
4640             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
4641                                                                                             p6.getNode( "a" ) );
4642             if ( !r_6.getName().equals( "rot" ) ) {
4643                 return false;
4644             }
4645             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
4646             PhylogenyMethods.preOrderReId( p7 );
4647             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
4648                                                                                             p7.getNode( "e" ) );
4649             if ( !r_7.getName().equals( "rott" ) ) {
4650                 return false;
4651             }
4652             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4653                                                                                              p7.getNode( "a" ) );
4654             if ( !r_71.getName().equals( "rott" ) ) {
4655                 return false;
4656             }
4657             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4658                                                                                              p7.getNode( "rott" ) );
4659             if ( !r_72.getName().equals( "rott" ) ) {
4660                 return false;
4661             }
4662             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
4663                                                                                              p7.getNode( "a" ) );
4664             if ( !r_73.getName().equals( "rott" ) ) {
4665                 return false;
4666             }
4667             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
4668                                                                                              p7.getNode( "rott" ) );
4669             if ( !r_74.getName().equals( "rott" ) ) {
4670                 return false;
4671             }
4672             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4673                                                                                              p7.getNode( "e" ) );
4674             if ( !r_75.getName().equals( "e" ) ) {
4675                 return false;
4676             }
4677         }
4678         catch ( final Exception e ) {
4679             e.printStackTrace( System.out );
4680             return false;
4681         }
4682         return true;
4683     }
4684
4685     private static boolean testHmmscanOutputParser() {
4686         final String test_dir = Test.PATH_TO_TEST_DATA;
4687         try {
4688             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
4689                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4690             parser1.parse();
4691             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
4692                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4693             final List<Protein> proteins = parser2.parse();
4694             if ( parser2.getProteinsEncountered() != 4 ) {
4695                 return false;
4696             }
4697             if ( proteins.size() != 4 ) {
4698                 return false;
4699             }
4700             if ( parser2.getDomainsEncountered() != 69 ) {
4701                 return false;
4702             }
4703             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
4704                 return false;
4705             }
4706             if ( parser2.getDomainsIgnoredDueToEval() != 0 ) {
4707                 return false;
4708             }
4709             final Protein p1 = proteins.get( 0 );
4710             if ( p1.getNumberOfProteinDomains() != 15 ) {
4711                 return false;
4712             }
4713             if ( p1.getLength() != 850 ) {
4714                 return false;
4715             }
4716             final Protein p2 = proteins.get( 1 );
4717             if ( p2.getNumberOfProteinDomains() != 51 ) {
4718                 return false;
4719             }
4720             if ( p2.getLength() != 1291 ) {
4721                 return false;
4722             }
4723             final Protein p3 = proteins.get( 2 );
4724             if ( p3.getNumberOfProteinDomains() != 2 ) {
4725                 return false;
4726             }
4727             final Protein p4 = proteins.get( 3 );
4728             if ( p4.getNumberOfProteinDomains() != 1 ) {
4729                 return false;
4730             }
4731             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
4732                 return false;
4733             }
4734             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
4735                 return false;
4736             }
4737             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
4738                 return false;
4739             }
4740             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
4741                 return false;
4742             }
4743             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
4744                 return false;
4745             }
4746             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) {
4747                 return false;
4748             }
4749             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) {
4750                 return false;
4751             }
4752             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
4753                 return false;
4754             }
4755             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
4756                 return false;
4757             }
4758         }
4759         catch ( final Exception e ) {
4760             e.printStackTrace( System.out );
4761             return false;
4762         }
4763         return true;
4764     }
4765
4766     private static boolean testLastExternalNodeMethods() {
4767         try {
4768             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4769             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
4770             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
4771             final PhylogenyNode n1 = t0.getNode( "A" );
4772             if ( n1.isLastExternalNode() ) {
4773                 return false;
4774             }
4775             final PhylogenyNode n2 = t0.getNode( "B" );
4776             if ( n2.isLastExternalNode() ) {
4777                 return false;
4778             }
4779             final PhylogenyNode n3 = t0.getNode( "C" );
4780             if ( n3.isLastExternalNode() ) {
4781                 return false;
4782             }
4783             final PhylogenyNode n4 = t0.getNode( "D" );
4784             if ( !n4.isLastExternalNode() ) {
4785                 return false;
4786             }
4787         }
4788         catch ( final Exception e ) {
4789             e.printStackTrace( System.out );
4790             return false;
4791         }
4792         return true;
4793     }
4794
4795     private static boolean testLevelOrderIterator() {
4796         try {
4797             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4798             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
4799             PhylogenyNodeIterator it0;
4800             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
4801                 it0.next();
4802             }
4803             for( it0.reset(); it0.hasNext(); ) {
4804                 it0.next();
4805             }
4806             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
4807             if ( !it.next().getName().equals( "r" ) ) {
4808                 return false;
4809             }
4810             if ( !it.next().getName().equals( "ab" ) ) {
4811                 return false;
4812             }
4813             if ( !it.next().getName().equals( "cd" ) ) {
4814                 return false;
4815             }
4816             if ( !it.next().getName().equals( "A" ) ) {
4817                 return false;
4818             }
4819             if ( !it.next().getName().equals( "B" ) ) {
4820                 return false;
4821             }
4822             if ( !it.next().getName().equals( "C" ) ) {
4823                 return false;
4824             }
4825             if ( !it.next().getName().equals( "D" ) ) {
4826                 return false;
4827             }
4828             if ( it.hasNext() ) {
4829                 return false;
4830             }
4831             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",
4832                                                  new NHXParser() )[ 0 ];
4833             PhylogenyNodeIterator it2;
4834             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
4835                 it2.next();
4836             }
4837             for( it2.reset(); it2.hasNext(); ) {
4838                 it2.next();
4839             }
4840             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
4841             if ( !it3.next().getName().equals( "r" ) ) {
4842                 return false;
4843             }
4844             if ( !it3.next().getName().equals( "abc" ) ) {
4845                 return false;
4846             }
4847             if ( !it3.next().getName().equals( "defg" ) ) {
4848                 return false;
4849             }
4850             if ( !it3.next().getName().equals( "A" ) ) {
4851                 return false;
4852             }
4853             if ( !it3.next().getName().equals( "B" ) ) {
4854                 return false;
4855             }
4856             if ( !it3.next().getName().equals( "C" ) ) {
4857                 return false;
4858             }
4859             if ( !it3.next().getName().equals( "D" ) ) {
4860                 return false;
4861             }
4862             if ( !it3.next().getName().equals( "E" ) ) {
4863                 return false;
4864             }
4865             if ( !it3.next().getName().equals( "F" ) ) {
4866                 return false;
4867             }
4868             if ( !it3.next().getName().equals( "G" ) ) {
4869                 return false;
4870             }
4871             if ( !it3.next().getName().equals( "1" ) ) {
4872                 return false;
4873             }
4874             if ( !it3.next().getName().equals( "2" ) ) {
4875                 return false;
4876             }
4877             if ( !it3.next().getName().equals( "3" ) ) {
4878                 return false;
4879             }
4880             if ( !it3.next().getName().equals( "4" ) ) {
4881                 return false;
4882             }
4883             if ( !it3.next().getName().equals( "5" ) ) {
4884                 return false;
4885             }
4886             if ( !it3.next().getName().equals( "6" ) ) {
4887                 return false;
4888             }
4889             if ( !it3.next().getName().equals( "f1" ) ) {
4890                 return false;
4891             }
4892             if ( !it3.next().getName().equals( "f2" ) ) {
4893                 return false;
4894             }
4895             if ( !it3.next().getName().equals( "f3" ) ) {
4896                 return false;
4897             }
4898             if ( !it3.next().getName().equals( "a" ) ) {
4899                 return false;
4900             }
4901             if ( !it3.next().getName().equals( "b" ) ) {
4902                 return false;
4903             }
4904             if ( !it3.next().getName().equals( "f21" ) ) {
4905                 return false;
4906             }
4907             if ( !it3.next().getName().equals( "X" ) ) {
4908                 return false;
4909             }
4910             if ( !it3.next().getName().equals( "Y" ) ) {
4911                 return false;
4912             }
4913             if ( !it3.next().getName().equals( "Z" ) ) {
4914                 return false;
4915             }
4916             if ( it3.hasNext() ) {
4917                 return false;
4918             }
4919             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
4920             PhylogenyNodeIterator it4;
4921             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
4922                 it4.next();
4923             }
4924             for( it4.reset(); it4.hasNext(); ) {
4925                 it4.next();
4926             }
4927             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
4928             if ( !it5.next().getName().equals( "r" ) ) {
4929                 return false;
4930             }
4931             if ( !it5.next().getName().equals( "A" ) ) {
4932                 return false;
4933             }
4934             if ( !it5.next().getName().equals( "B" ) ) {
4935                 return false;
4936             }
4937             if ( !it5.next().getName().equals( "C" ) ) {
4938                 return false;
4939             }
4940             if ( !it5.next().getName().equals( "D" ) ) {
4941                 return false;
4942             }
4943             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
4944             PhylogenyNodeIterator it6;
4945             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
4946                 it6.next();
4947             }
4948             for( it6.reset(); it6.hasNext(); ) {
4949                 it6.next();
4950             }
4951             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
4952             if ( !it7.next().getName().equals( "A" ) ) {
4953                 return false;
4954             }
4955             if ( it.hasNext() ) {
4956                 return false;
4957             }
4958         }
4959         catch ( final Exception e ) {
4960             e.printStackTrace( System.out );
4961             return false;
4962         }
4963         return true;
4964     }
4965
4966     private static boolean testMafft( final String path ) {
4967         try {
4968             final List<String> opts = new ArrayList<String>();
4969             opts.add( "--maxiterate" );
4970             opts.add( "1000" );
4971             opts.add( "--localpair" );
4972             opts.add( "--quiet" );
4973             Msa msa = null;
4974             final MsaInferrer mafft = Mafft.createInstance( path );
4975             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
4976             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
4977                 return false;
4978             }
4979             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
4980                 return false;
4981             }
4982         }
4983         catch ( final Exception e ) {
4984             e.printStackTrace( System.out );
4985             return false;
4986         }
4987         return true;
4988     }
4989
4990     private static boolean testMidpointrooting() {
4991         try {
4992             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4993             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
4994             PhylogenyMethods.midpointRoot( t0 );
4995             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
4996                 return false;
4997             }
4998             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
4999                 return false;
5000             }
5001             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
5002                            1 ) ) {
5003                 return false;
5004             }
5005             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",
5006                                                  new NHXParser() )[ 0 ];
5007             if ( !t1.isRooted() ) {
5008                 return false;
5009             }
5010             PhylogenyMethods.midpointRoot( t1 );
5011             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5012                 return false;
5013             }
5014             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5015                 return false;
5016             }
5017             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5018                 return false;
5019             }
5020             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5021                 return false;
5022             }
5023             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5024                 return false;
5025             }
5026             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5027                 return false;
5028             }
5029             t1.reRoot( t1.getNode( "A" ) );
5030             PhylogenyMethods.midpointRoot( t1 );
5031             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5032                 return false;
5033             }
5034             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5035                 return false;
5036             }
5037             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5038                 return false;
5039             }
5040             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5041                 return false;
5042             }
5043             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5044                 System.exit( -1 );
5045                 return false;
5046             }
5047             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5048                 return false;
5049             }
5050         }
5051         catch ( final Exception e ) {
5052             e.printStackTrace( System.out );
5053             return false;
5054         }
5055         return true;
5056     }
5057
5058     private static boolean testMsaQualityMethod() {
5059         try {
5060             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
5061             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
5062             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
5063             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
5064             final List<Sequence> l = new ArrayList<Sequence>();
5065             l.add( s0 );
5066             l.add( s1 );
5067             l.add( s2 );
5068             l.add( s3 );
5069             final Msa msa = BasicMsa.createInstance( l );
5070             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
5071                 return false;
5072             }
5073             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
5074                 return false;
5075             }
5076             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
5077                 return false;
5078             }
5079             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
5080                 return false;
5081             }
5082         }
5083         catch ( final Exception e ) {
5084             e.printStackTrace( System.out );
5085             return false;
5086         }
5087         return true;
5088     }
5089
5090     private static boolean testNextNodeWithCollapsing() {
5091         try {
5092             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5093             PhylogenyNode n;
5094             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
5095             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5096             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
5097             t0.getNode( "cd" ).setCollapse( true );
5098             t0.getNode( "cde" ).setCollapse( true );
5099             n = t0.getFirstExternalNode();
5100             while ( n != null ) {
5101                 ext.add( n );
5102                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5103             }
5104             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5105                 return false;
5106             }
5107             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5108                 return false;
5109             }
5110             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
5111                 return false;
5112             }
5113             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
5114                 return false;
5115             }
5116             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
5117                 return false;
5118             }
5119             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
5120                 return false;
5121             }
5122             ext.clear();
5123             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5124             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
5125             t1.getNode( "ab" ).setCollapse( true );
5126             t1.getNode( "cd" ).setCollapse( true );
5127             t1.getNode( "cde" ).setCollapse( true );
5128             n = t1.getNode( "ab" );
5129             ext = new ArrayList<PhylogenyNode>();
5130             while ( n != null ) {
5131                 ext.add( n );
5132                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5133             }
5134             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5135                 return false;
5136             }
5137             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5138                 return false;
5139             }
5140             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5141                 return false;
5142             }
5143             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
5144                 return false;
5145             }
5146             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
5147                 return false;
5148             }
5149             //
5150             //
5151             ext.clear();
5152             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5153             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
5154             t2.getNode( "ab" ).setCollapse( true );
5155             t2.getNode( "cd" ).setCollapse( true );
5156             t2.getNode( "cde" ).setCollapse( true );
5157             t2.getNode( "c" ).setCollapse( true );
5158             t2.getNode( "d" ).setCollapse( true );
5159             t2.getNode( "e" ).setCollapse( true );
5160             t2.getNode( "gh" ).setCollapse( true );
5161             n = t2.getNode( "ab" );
5162             ext = new ArrayList<PhylogenyNode>();
5163             while ( n != null ) {
5164                 ext.add( n );
5165                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5166             }
5167             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5168                 return false;
5169             }
5170             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5171                 return false;
5172             }
5173             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5174                 return false;
5175             }
5176             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
5177                 return false;
5178             }
5179             //
5180             //
5181             ext.clear();
5182             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5183             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
5184             t3.getNode( "ab" ).setCollapse( true );
5185             t3.getNode( "cd" ).setCollapse( true );
5186             t3.getNode( "cde" ).setCollapse( true );
5187             t3.getNode( "c" ).setCollapse( true );
5188             t3.getNode( "d" ).setCollapse( true );
5189             t3.getNode( "e" ).setCollapse( true );
5190             t3.getNode( "gh" ).setCollapse( true );
5191             t3.getNode( "fgh" ).setCollapse( true );
5192             n = t3.getNode( "ab" );
5193             ext = new ArrayList<PhylogenyNode>();
5194             while ( n != null ) {
5195                 ext.add( n );
5196                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5197             }
5198             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5199                 return false;
5200             }
5201             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5202                 return false;
5203             }
5204             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
5205                 return false;
5206             }
5207             //
5208             //
5209             ext.clear();
5210             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5211             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
5212             t4.getNode( "ab" ).setCollapse( true );
5213             t4.getNode( "cd" ).setCollapse( true );
5214             t4.getNode( "cde" ).setCollapse( true );
5215             t4.getNode( "c" ).setCollapse( true );
5216             t4.getNode( "d" ).setCollapse( true );
5217             t4.getNode( "e" ).setCollapse( true );
5218             t4.getNode( "gh" ).setCollapse( true );
5219             t4.getNode( "fgh" ).setCollapse( true );
5220             t4.getNode( "abcdefgh" ).setCollapse( true );
5221             n = t4.getNode( "abcdefgh" );
5222             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
5223                 return false;
5224             }
5225             //
5226             //
5227             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5228             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
5229             ext.clear();
5230             n = t5.getFirstExternalNode();
5231             while ( n != null ) {
5232                 ext.add( n );
5233                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5234             }
5235             if ( ext.size() != 8 ) {
5236                 return false;
5237             }
5238             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5239                 return false;
5240             }
5241             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5242                 return false;
5243             }
5244             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5245                 return false;
5246             }
5247             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5248                 return false;
5249             }
5250             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5251                 return false;
5252             }
5253             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5254                 return false;
5255             }
5256             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
5257                 return false;
5258             }
5259             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
5260                 return false;
5261             }
5262             //
5263             //
5264             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5265             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
5266             ext.clear();
5267             t6.getNode( "ab" ).setCollapse( true );
5268             n = t6.getNode( "ab" );
5269             while ( n != null ) {
5270                 ext.add( n );
5271                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5272             }
5273             if ( ext.size() != 7 ) {
5274                 return false;
5275             }
5276             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5277                 return false;
5278             }
5279             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5280                 return false;
5281             }
5282             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5283                 return false;
5284             }
5285             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5286                 return false;
5287             }
5288             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5289                 return false;
5290             }
5291             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5292                 return false;
5293             }
5294             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5295                 return false;
5296             }
5297             //
5298             //
5299             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5300             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
5301             ext.clear();
5302             t7.getNode( "cd" ).setCollapse( true );
5303             n = t7.getNode( "a" );
5304             while ( n != null ) {
5305                 ext.add( n );
5306                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5307             }
5308             if ( ext.size() != 7 ) {
5309                 return false;
5310             }
5311             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5312                 return false;
5313             }
5314             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5315                 return false;
5316             }
5317             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
5318                 return false;
5319             }
5320             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5321                 return false;
5322             }
5323             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5324                 return false;
5325             }
5326             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5327                 return false;
5328             }
5329             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5330                 return false;
5331             }
5332             //
5333             //
5334             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5335             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
5336             ext.clear();
5337             t8.getNode( "cd" ).setCollapse( true );
5338             t8.getNode( "c" ).setCollapse( true );
5339             t8.getNode( "d" ).setCollapse( true );
5340             n = t8.getNode( "a" );
5341             while ( n != null ) {
5342                 ext.add( n );
5343                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5344             }
5345             if ( ext.size() != 7 ) {
5346                 return false;
5347             }
5348             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5349                 return false;
5350             }
5351             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5352                 return false;
5353             }
5354             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
5355                 System.out.println( "2 fail" );
5356                 return false;
5357             }
5358             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5359                 return false;
5360             }
5361             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5362                 return false;
5363             }
5364             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5365                 return false;
5366             }
5367             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5368                 return false;
5369             }
5370             //
5371             //
5372             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5373             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
5374             ext.clear();
5375             t9.getNode( "gh" ).setCollapse( true );
5376             n = t9.getNode( "a" );
5377             while ( n != null ) {
5378                 ext.add( n );
5379                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5380             }
5381             if ( ext.size() != 7 ) {
5382                 return false;
5383             }
5384             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5385                 return false;
5386             }
5387             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5388                 return false;
5389             }
5390             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5391                 return false;
5392             }
5393             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5394                 return false;
5395             }
5396             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5397                 return false;
5398             }
5399             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5400                 return false;
5401             }
5402             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
5403                 return false;
5404             }
5405             //
5406             //
5407             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5408             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
5409             ext.clear();
5410             t10.getNode( "gh" ).setCollapse( true );
5411             t10.getNode( "g" ).setCollapse( true );
5412             t10.getNode( "h" ).setCollapse( true );
5413             n = t10.getNode( "a" );
5414             while ( n != null ) {
5415                 ext.add( n );
5416                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5417             }
5418             if ( ext.size() != 7 ) {
5419                 return false;
5420             }
5421             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5422                 return false;
5423             }
5424             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5425                 return false;
5426             }
5427             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5428                 return false;
5429             }
5430             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5431                 return false;
5432             }
5433             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5434                 return false;
5435             }
5436             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5437                 return false;
5438             }
5439             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
5440                 return false;
5441             }
5442             //
5443             //
5444             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5445             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
5446             ext.clear();
5447             t11.getNode( "gh" ).setCollapse( true );
5448             t11.getNode( "fgh" ).setCollapse( true );
5449             n = t11.getNode( "a" );
5450             while ( n != null ) {
5451                 ext.add( n );
5452                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5453             }
5454             if ( ext.size() != 6 ) {
5455                 return false;
5456             }
5457             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5458                 return false;
5459             }
5460             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5461                 return false;
5462             }
5463             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5464                 return false;
5465             }
5466             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5467                 return false;
5468             }
5469             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5470                 return false;
5471             }
5472             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
5473                 return false;
5474             }
5475             //
5476             //
5477             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5478             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
5479             ext.clear();
5480             t12.getNode( "gh" ).setCollapse( true );
5481             t12.getNode( "fgh" ).setCollapse( true );
5482             t12.getNode( "g" ).setCollapse( true );
5483             t12.getNode( "h" ).setCollapse( true );
5484             t12.getNode( "f" ).setCollapse( true );
5485             n = t12.getNode( "a" );
5486             while ( n != null ) {
5487                 ext.add( n );
5488                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5489             }
5490             if ( ext.size() != 6 ) {
5491                 return false;
5492             }
5493             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5494                 return false;
5495             }
5496             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5497                 return false;
5498             }
5499             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5500                 return false;
5501             }
5502             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5503                 return false;
5504             }
5505             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5506                 return false;
5507             }
5508             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
5509                 return false;
5510             }
5511             //
5512             //
5513             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5514             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
5515             ext.clear();
5516             t13.getNode( "ab" ).setCollapse( true );
5517             t13.getNode( "b" ).setCollapse( true );
5518             t13.getNode( "fgh" ).setCollapse( true );
5519             t13.getNode( "gh" ).setCollapse( true );
5520             n = t13.getNode( "ab" );
5521             while ( n != null ) {
5522                 ext.add( n );
5523                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5524             }
5525             if ( ext.size() != 5 ) {
5526                 return false;
5527             }
5528             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5529                 return false;
5530             }
5531             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5532                 return false;
5533             }
5534             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5535                 return false;
5536             }
5537             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5538                 return false;
5539             }
5540             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
5541                 return false;
5542             }
5543             //
5544             //
5545             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
5546             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
5547             ext.clear();
5548             t14.getNode( "ab" ).setCollapse( true );
5549             t14.getNode( "a" ).setCollapse( true );
5550             t14.getNode( "fgh" ).setCollapse( true );
5551             t14.getNode( "gh" ).setCollapse( true );
5552             n = t14.getNode( "ab" );
5553             while ( n != null ) {
5554                 ext.add( n );
5555                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5556             }
5557             if ( ext.size() != 5 ) {
5558                 return false;
5559             }
5560             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5561                 return false;
5562             }
5563             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5564                 return false;
5565             }
5566             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5567                 return false;
5568             }
5569             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5570                 return false;
5571             }
5572             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
5573                 return false;
5574             }
5575             //
5576             //
5577             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" );
5578             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
5579             ext.clear();
5580             t15.getNode( "ab" ).setCollapse( true );
5581             t15.getNode( "a" ).setCollapse( true );
5582             t15.getNode( "fgh" ).setCollapse( true );
5583             t15.getNode( "gh" ).setCollapse( true );
5584             n = t15.getNode( "ab" );
5585             while ( n != null ) {
5586                 ext.add( n );
5587                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5588             }
5589             if ( ext.size() != 6 ) {
5590                 return false;
5591             }
5592             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5593                 return false;
5594             }
5595             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5596                 return false;
5597             }
5598             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5599                 return false;
5600             }
5601             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5602                 return false;
5603             }
5604             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
5605                 return false;
5606             }
5607             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
5608                 return false;
5609             }
5610             //
5611             //
5612             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" );
5613             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
5614             ext.clear();
5615             t16.getNode( "ab" ).setCollapse( true );
5616             t16.getNode( "a" ).setCollapse( true );
5617             t16.getNode( "fgh" ).setCollapse( true );
5618             t16.getNode( "gh" ).setCollapse( true );
5619             t16.getNode( "cd" ).setCollapse( true );
5620             t16.getNode( "cde" ).setCollapse( true );
5621             t16.getNode( "d" ).setCollapse( true );
5622             t16.getNode( "x" ).setCollapse( true );
5623             n = t16.getNode( "ab" );
5624             while ( n != null ) {
5625                 ext.add( n );
5626                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5627             }
5628             if ( ext.size() != 4 ) {
5629                 return false;
5630             }
5631             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5632                 return false;
5633             }
5634             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5635                 return false;
5636             }
5637             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
5638                 return false;
5639             }
5640             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
5641                 return false;
5642             }
5643         }
5644         catch ( final Exception e ) {
5645             e.printStackTrace( System.out );
5646             return false;
5647         }
5648         return true;
5649     }
5650
5651     private static boolean testNexusCharactersParsing() {
5652         try {
5653             final NexusCharactersParser parser = new NexusCharactersParser();
5654             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
5655             parser.parse();
5656             String[] labels = parser.getCharStateLabels();
5657             if ( labels.length != 7 ) {
5658                 return false;
5659             }
5660             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5661                 return false;
5662             }
5663             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5664                 return false;
5665             }
5666             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5667                 return false;
5668             }
5669             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5670                 return false;
5671             }
5672             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
5673                 return false;
5674             }
5675             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
5676                 return false;
5677             }
5678             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
5679                 return false;
5680             }
5681             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
5682             parser.parse();
5683             labels = parser.getCharStateLabels();
5684             if ( labels.length != 7 ) {
5685                 return false;
5686             }
5687             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5688                 return false;
5689             }
5690             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5691                 return false;
5692             }
5693             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5694                 return false;
5695             }
5696             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5697                 return false;
5698             }
5699             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
5700                 return false;
5701             }
5702             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
5703                 return false;
5704             }
5705             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
5706                 return false;
5707             }
5708         }
5709         catch ( final Exception e ) {
5710             e.printStackTrace( System.out );
5711             return false;
5712         }
5713         return true;
5714     }
5715
5716     private static boolean testNexusMatrixParsing() {
5717         try {
5718             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
5719             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
5720             parser.parse();
5721             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
5722             if ( m.getNumberOfCharacters() != 9 ) {
5723                 return false;
5724             }
5725             if ( m.getNumberOfIdentifiers() != 5 ) {
5726                 return false;
5727             }
5728             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
5729                 return false;
5730             }
5731             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
5732                 return false;
5733             }
5734             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
5735                 return false;
5736             }
5737             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
5738                 return false;
5739             }
5740             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
5741                 return false;
5742             }
5743             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
5744                 return false;
5745             }
5746             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
5747                 return false;
5748             }
5749             //            if ( labels.length != 7 ) {
5750             //                return false;
5751             //            }
5752             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5753             //                return false;
5754             //            }
5755             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5756             //                return false;
5757             //            }
5758             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5759             //                return false;
5760             //            }
5761             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5762             //                return false;
5763             //            }
5764             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
5765             //                return false;
5766             //            }
5767             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
5768             //                return false;
5769             //            }
5770             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
5771             //                return false;
5772             //            }
5773             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
5774             //            parser.parse();
5775             //            labels = parser.getCharStateLabels();
5776             //            if ( labels.length != 7 ) {
5777             //                return false;
5778             //            }
5779             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5780             //                return false;
5781             //            }
5782             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5783             //                return false;
5784             //            }
5785             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5786             //                return false;
5787             //            }
5788             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5789             //                return false;
5790             //            }
5791             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
5792             //                return false;
5793             //            }
5794             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
5795             //                return false;
5796             //            }
5797             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
5798             //                return false;
5799             //            }
5800         }
5801         catch ( final Exception e ) {
5802             e.printStackTrace( System.out );
5803             return false;
5804         }
5805         return true;
5806     }
5807
5808     private static boolean testNexusTreeParsing() {
5809         try {
5810             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5811             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
5812             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
5813             if ( phylogenies.length != 1 ) {
5814                 return false;
5815             }
5816             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
5817                 return false;
5818             }
5819             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
5820                 return false;
5821             }
5822             phylogenies = null;
5823             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
5824             if ( phylogenies.length != 1 ) {
5825                 return false;
5826             }
5827             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
5828                 return false;
5829             }
5830             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
5831                 return false;
5832             }
5833             phylogenies = null;
5834             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
5835             if ( phylogenies.length != 1 ) {
5836                 return false;
5837             }
5838             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5839                 return false;
5840             }
5841             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
5842                 return false;
5843             }
5844             if ( phylogenies[ 0 ].isRooted() ) {
5845                 return false;
5846             }
5847             phylogenies = null;
5848             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
5849             if ( phylogenies.length != 18 ) {
5850                 return false;
5851             }
5852             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
5853                 return false;
5854             }
5855             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
5856                 return false;
5857             }
5858             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
5859                 return false;
5860             }
5861             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
5862                 return false;
5863             }
5864             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
5865                 return false;
5866             }
5867             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
5868                 return false;
5869             }
5870             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
5871                 return false;
5872             }
5873             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
5874                 return false;
5875             }
5876             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
5877                 return false;
5878             }
5879             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
5880                 return false;
5881             }
5882             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
5883                 return false;
5884             }
5885             if ( phylogenies[ 8 ].isRooted() ) {
5886                 return false;
5887             }
5888             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
5889                 return false;
5890             }
5891             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
5892                 return false;
5893             }
5894             if ( !phylogenies[ 9 ].isRooted() ) {
5895                 return false;
5896             }
5897             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
5898                 return false;
5899             }
5900             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
5901                 return false;
5902             }
5903             if ( !phylogenies[ 10 ].isRooted() ) {
5904                 return false;
5905             }
5906             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
5907                 return false;
5908             }
5909             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
5910                 return false;
5911             }
5912             if ( phylogenies[ 11 ].isRooted() ) {
5913                 return false;
5914             }
5915             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
5916                 return false;
5917             }
5918             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
5919                 return false;
5920             }
5921             if ( !phylogenies[ 12 ].isRooted() ) {
5922                 return false;
5923             }
5924             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
5925                 return false;
5926             }
5927             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
5928                 return false;
5929             }
5930             if ( !phylogenies[ 13 ].isRooted() ) {
5931                 return false;
5932             }
5933             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
5934                 return false;
5935             }
5936             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
5937                 return false;
5938             }
5939             if ( !phylogenies[ 14 ].isRooted() ) {
5940                 return false;
5941             }
5942             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
5943                 return false;
5944             }
5945             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
5946                 return false;
5947             }
5948             if ( phylogenies[ 15 ].isRooted() ) {
5949                 return false;
5950             }
5951             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
5952                 return false;
5953             }
5954             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
5955                 return false;
5956             }
5957             if ( !phylogenies[ 16 ].isRooted() ) {
5958                 return false;
5959             }
5960             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
5961                 return false;
5962             }
5963             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
5964                 return false;
5965             }
5966             if ( phylogenies[ 17 ].isRooted() ) {
5967                 return false;
5968             }
5969             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
5970                 return false;
5971             }
5972         }
5973         catch ( final Exception e ) {
5974             e.printStackTrace( System.out );
5975             return false;
5976         }
5977         return true;
5978     }
5979
5980     private static boolean testNexusTreeParsingIterating() {
5981         try {
5982             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
5983             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
5984             if ( !p.hasNext() ) {
5985                 return false;
5986             }
5987             Phylogeny phy = p.next();
5988             if ( phy == null ) {
5989                 return false;
5990             }
5991             if ( phy.getNumberOfExternalNodes() != 25 ) {
5992                 return false;
5993             }
5994             if ( !phy.getName().equals( "" ) ) {
5995                 return false;
5996             }
5997             if ( p.hasNext() ) {
5998                 return false;
5999             }
6000             phy = p.next();
6001             if ( phy != null ) {
6002                 return false;
6003             }
6004             //
6005             p.reset();
6006             if ( !p.hasNext() ) {
6007                 return false;
6008             }
6009             phy = p.next();
6010             if ( phy == null ) {
6011                 return false;
6012             }
6013             if ( phy.getNumberOfExternalNodes() != 25 ) {
6014                 return false;
6015             }
6016             if ( !phy.getName().equals( "" ) ) {
6017                 return false;
6018             }
6019             if ( p.hasNext() ) {
6020                 return false;
6021             }
6022             phy = p.next();
6023             if ( phy != null ) {
6024                 return false;
6025             }
6026             ////
6027             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
6028             if ( !p.hasNext() ) {
6029                 return false;
6030             }
6031             phy = p.next();
6032             if ( phy == null ) {
6033                 return false;
6034             }
6035             if ( phy.getNumberOfExternalNodes() != 10 ) {
6036                 return false;
6037             }
6038             if ( !phy.getName().equals( "name" ) ) {
6039                 return false;
6040             }
6041             if ( p.hasNext() ) {
6042                 return false;
6043             }
6044             phy = p.next();
6045             if ( phy != null ) {
6046                 return false;
6047             }
6048             //
6049             p.reset();
6050             if ( !p.hasNext() ) {
6051                 return false;
6052             }
6053             phy = p.next();
6054             if ( phy == null ) {
6055                 return false;
6056             }
6057             if ( phy.getNumberOfExternalNodes() != 10 ) {
6058                 return false;
6059             }
6060             if ( !phy.getName().equals( "name" ) ) {
6061                 return false;
6062             }
6063             if ( p.hasNext() ) {
6064                 return false;
6065             }
6066             phy = p.next();
6067             if ( phy != null ) {
6068                 return false;
6069             }
6070             ////
6071             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
6072             if ( !p.hasNext() ) {
6073                 return false;
6074             }
6075             phy = p.next();
6076             if ( phy == null ) {
6077                 return false;
6078             }
6079             if ( phy.getNumberOfExternalNodes() != 3 ) {
6080                 return false;
6081             }
6082             if ( !phy.getName().equals( "" ) ) {
6083                 return false;
6084             }
6085             if ( phy.isRooted() ) {
6086                 return false;
6087             }
6088             if ( p.hasNext() ) {
6089                 return false;
6090             }
6091             phy = p.next();
6092             if ( phy != null ) {
6093                 return false;
6094             }
6095             //
6096             p.reset();
6097             if ( !p.hasNext() ) {
6098                 return false;
6099             }
6100             phy = p.next();
6101             if ( phy == null ) {
6102                 return false;
6103             }
6104             if ( phy.getNumberOfExternalNodes() != 3 ) {
6105                 return false;
6106             }
6107             if ( !phy.getName().equals( "" ) ) {
6108                 return false;
6109             }
6110             if ( p.hasNext() ) {
6111                 return false;
6112             }
6113             phy = p.next();
6114             if ( phy != null ) {
6115                 return false;
6116             }
6117             ////
6118             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
6119             //            if ( phylogenies.length != 18 ) {
6120             //                return false;
6121             //            }
6122             //0
6123             if ( !p.hasNext() ) {
6124                 return false;
6125             }
6126             phy = p.next();
6127             if ( phy == null ) {
6128                 return false;
6129             }
6130             if ( phy.getNumberOfExternalNodes() != 10 ) {
6131                 return false;
6132             }
6133             if ( !phy.getName().equals( "tree 0" ) ) {
6134                 return false;
6135             }
6136             //1
6137             if ( !p.hasNext() ) {
6138                 return false;
6139             }
6140             phy = p.next();
6141             if ( phy == null ) {
6142                 return false;
6143             }
6144             if ( phy.getNumberOfExternalNodes() != 10 ) {
6145                 return false;
6146             }
6147             if ( !phy.getName().equals( "tree 1" ) ) {
6148                 return false;
6149             }
6150             //2
6151             if ( !p.hasNext() ) {
6152                 return false;
6153             }
6154             phy = p.next();
6155             if ( phy == null ) {
6156                 return false;
6157             }
6158             if ( phy.getNumberOfExternalNodes() != 3 ) {
6159                 return false;
6160             }
6161             if ( !phy.getName().equals( "" ) ) {
6162                 return false;
6163             }
6164             if ( phy.isRooted() ) {
6165                 return false;
6166             }
6167             //3
6168             if ( !p.hasNext() ) {
6169                 return false;
6170             }
6171             phy = p.next();
6172             if ( phy == null ) {
6173                 return false;
6174             }
6175             if ( phy.getNumberOfExternalNodes() != 4 ) {
6176                 return false;
6177             }
6178             if ( !phy.getName().equals( "" ) ) {
6179                 return false;
6180             }
6181             if ( !phy.isRooted() ) {
6182                 return false;
6183             }
6184             //4
6185             if ( !p.hasNext() ) {
6186                 return false;
6187             }
6188             phy = p.next();
6189             if ( phy == null ) {
6190                 return false;
6191             }
6192             if ( phy.getNumberOfExternalNodes() != 5 ) {
6193                 System.out.println( phy.getNumberOfExternalNodes() );
6194                 return false;
6195             }
6196             if ( !phy.getName().equals( "" ) ) {
6197                 return false;
6198             }
6199             if ( !phy.isRooted() ) {
6200                 return false;
6201             }
6202             //5
6203             if ( !p.hasNext() ) {
6204                 return false;
6205             }
6206             phy = p.next();
6207             if ( phy == null ) {
6208                 return false;
6209             }
6210             if ( phy.getNumberOfExternalNodes() != 3 ) {
6211                 return false;
6212             }
6213             if ( !phy.getName().equals( "" ) ) {
6214                 return false;
6215             }
6216             if ( phy.isRooted() ) {
6217                 return false;
6218             }
6219             //6
6220             if ( !p.hasNext() ) {
6221                 return false;
6222             }
6223             phy = p.next();
6224             if ( phy == null ) {
6225                 return false;
6226             }
6227             if ( phy.getNumberOfExternalNodes() != 2 ) {
6228                 return false;
6229             }
6230             if ( !phy.getName().equals( "" ) ) {
6231                 return false;
6232             }
6233             if ( !phy.isRooted() ) {
6234                 return false;
6235             }
6236             //7
6237             if ( !p.hasNext() ) {
6238                 return false;
6239             }
6240             phy = p.next();
6241             if ( phy.getNumberOfExternalNodes() != 3 ) {
6242                 return false;
6243             }
6244             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6245                 return false;
6246             }
6247             if ( !phy.isRooted() ) {
6248                 return false;
6249             }
6250             //8
6251             if ( !p.hasNext() ) {
6252                 return false;
6253             }
6254             phy = p.next();
6255             if ( phy.getNumberOfExternalNodes() != 3 ) {
6256                 return false;
6257             }
6258             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
6259                 return false;
6260             }
6261             if ( !phy.getName().equals( "tree 8" ) ) {
6262                 return false;
6263             }
6264             //9
6265             if ( !p.hasNext() ) {
6266                 return false;
6267             }
6268             phy = p.next();
6269             if ( phy.getNumberOfExternalNodes() != 3 ) {
6270                 return false;
6271             }
6272             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
6273                 return false;
6274             }
6275             if ( !phy.getName().equals( "tree 9" ) ) {
6276                 return false;
6277             }
6278             //10
6279             if ( !p.hasNext() ) {
6280                 return false;
6281             }
6282             phy = p.next();
6283             if ( phy.getNumberOfExternalNodes() != 3 ) {
6284                 return false;
6285             }
6286             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6287                 return false;
6288             }
6289             if ( !phy.getName().equals( "tree 10" ) ) {
6290                 return false;
6291             }
6292             if ( !phy.isRooted() ) {
6293                 return false;
6294             }
6295             //11
6296             if ( !p.hasNext() ) {
6297                 return false;
6298             }
6299             phy = p.next();
6300             if ( phy.getNumberOfExternalNodes() != 3 ) {
6301                 return false;
6302             }
6303             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
6304                 return false;
6305             }
6306             if ( !phy.getName().equals( "tree 11" ) ) {
6307                 return false;
6308             }
6309             if ( phy.isRooted() ) {
6310                 return false;
6311             }
6312             //12
6313             if ( !p.hasNext() ) {
6314                 return false;
6315             }
6316             phy = p.next();
6317             if ( phy.getNumberOfExternalNodes() != 3 ) {
6318                 return false;
6319             }
6320             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
6321                 return false;
6322             }
6323             if ( !phy.getName().equals( "tree 12" ) ) {
6324                 return false;
6325             }
6326             if ( !phy.isRooted() ) {
6327                 return false;
6328             }
6329             //13
6330             if ( !p.hasNext() ) {
6331                 return false;
6332             }
6333             phy = p.next();
6334             if ( phy.getNumberOfExternalNodes() != 3 ) {
6335                 return false;
6336             }
6337             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6338                 return false;
6339             }
6340             if ( !phy.getName().equals( "tree 13" ) ) {
6341                 return false;
6342             }
6343             if ( !phy.isRooted() ) {
6344                 return false;
6345             }
6346             //14
6347             if ( !p.hasNext() ) {
6348                 return false;
6349             }
6350             phy = p.next();
6351             if ( phy.getNumberOfExternalNodes() != 10 ) {
6352                 System.out.println( phy.getNumberOfExternalNodes() );
6353                 return false;
6354             }
6355             if ( !phy
6356                     .toNewHampshire()
6357                     .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;" ) ) {
6358                 System.out.println( phy.toNewHampshire() );
6359                 return false;
6360             }
6361             if ( !phy.getName().equals( "tree 14" ) ) {
6362                 return false;
6363             }
6364             if ( !phy.isRooted() ) {
6365                 return false;
6366             }
6367             //15
6368             if ( !p.hasNext() ) {
6369                 return false;
6370             }
6371             phy = p.next();
6372             if ( phy.getNumberOfExternalNodes() != 10 ) {
6373                 System.out.println( phy.getNumberOfExternalNodes() );
6374                 return false;
6375             }
6376             if ( !phy
6377                     .toNewHampshire()
6378                     .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;" ) ) {
6379                 System.out.println( phy.toNewHampshire() );
6380                 return false;
6381             }
6382             if ( !phy.getName().equals( "tree 15" ) ) {
6383                 return false;
6384             }
6385             if ( phy.isRooted() ) {
6386                 return false;
6387             }
6388             //16
6389             if ( !p.hasNext() ) {
6390                 return false;
6391             }
6392             phy = p.next();
6393             if ( phy.getNumberOfExternalNodes() != 10 ) {
6394                 System.out.println( phy.getNumberOfExternalNodes() );
6395                 return false;
6396             }
6397             if ( !phy
6398                     .toNewHampshire()
6399                     .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;" ) ) {
6400                 System.out.println( phy.toNewHampshire() );
6401                 return false;
6402             }
6403             if ( !phy.getName().equals( "tree 16" ) ) {
6404                 return false;
6405             }
6406             if ( !phy.isRooted() ) {
6407                 return false;
6408             }
6409             //17
6410             if ( !p.hasNext() ) {
6411                 return false;
6412             }
6413             phy = p.next();
6414             if ( phy.getNumberOfExternalNodes() != 10 ) {
6415                 System.out.println( phy.getNumberOfExternalNodes() );
6416                 return false;
6417             }
6418             if ( !phy
6419                     .toNewHampshire()
6420                     .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;" ) ) {
6421                 System.out.println( phy.toNewHampshire() );
6422                 return false;
6423             }
6424             if ( !phy.getName().equals( "tree 17" ) ) {
6425                 return false;
6426             }
6427             if ( phy.isRooted() ) {
6428                 return false;
6429             }
6430             //
6431             if ( p.hasNext() ) {
6432                 return false;
6433             }
6434             phy = p.next();
6435             if ( phy != null ) {
6436                 return false;
6437             }
6438             p.reset();
6439             //0
6440             if ( !p.hasNext() ) {
6441                 return false;
6442             }
6443             phy = p.next();
6444             if ( phy == null ) {
6445                 return false;
6446             }
6447             if ( phy.getNumberOfExternalNodes() != 10 ) {
6448                 return false;
6449             }
6450             if ( !phy.getName().equals( "tree 0" ) ) {
6451                 return false;
6452             }
6453             //1
6454             if ( !p.hasNext() ) {
6455                 return false;
6456             }
6457             phy = p.next();
6458             if ( phy == null ) {
6459                 return false;
6460             }
6461             if ( phy.getNumberOfExternalNodes() != 10 ) {
6462                 return false;
6463             }
6464             if ( !phy.getName().equals( "tree 1" ) ) {
6465                 return false;
6466             }
6467             //2
6468             if ( !p.hasNext() ) {
6469                 return false;
6470             }
6471             phy = p.next();
6472             if ( phy == null ) {
6473                 return false;
6474             }
6475             if ( phy.getNumberOfExternalNodes() != 3 ) {
6476                 return false;
6477             }
6478             if ( !phy.getName().equals( "" ) ) {
6479                 return false;
6480             }
6481             if ( phy.isRooted() ) {
6482                 return false;
6483             }
6484             //3
6485             if ( !p.hasNext() ) {
6486                 return false;
6487             }
6488             phy = p.next();
6489             if ( phy == null ) {
6490                 return false;
6491             }
6492             if ( phy.getNumberOfExternalNodes() != 4 ) {
6493                 return false;
6494             }
6495             if ( !phy.getName().equals( "" ) ) {
6496                 return false;
6497             }
6498             if ( !phy.isRooted() ) {
6499                 return false;
6500             }
6501             //4
6502             if ( !p.hasNext() ) {
6503                 return false;
6504             }
6505             phy = p.next();
6506             if ( phy == null ) {
6507                 return false;
6508             }
6509             if ( phy.getNumberOfExternalNodes() != 5 ) {
6510                 System.out.println( phy.getNumberOfExternalNodes() );
6511                 return false;
6512             }
6513             if ( !phy.getName().equals( "" ) ) {
6514                 return false;
6515             }
6516             if ( !phy.isRooted() ) {
6517                 return false;
6518             }
6519             //5
6520             if ( !p.hasNext() ) {
6521                 return false;
6522             }
6523             phy = p.next();
6524             if ( phy == null ) {
6525                 return false;
6526             }
6527             if ( phy.getNumberOfExternalNodes() != 3 ) {
6528                 return false;
6529             }
6530             if ( !phy.getName().equals( "" ) ) {
6531                 return false;
6532             }
6533             if ( phy.isRooted() ) {
6534                 return false;
6535             }
6536         }
6537         catch ( final Exception e ) {
6538             e.printStackTrace( System.out );
6539             return false;
6540         }
6541         return true;
6542     }
6543
6544     private static boolean testNexusTreeParsingTranslating() {
6545         try {
6546             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6547             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
6548             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
6549             if ( phylogenies.length != 1 ) {
6550                 return false;
6551             }
6552             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6553                 return false;
6554             }
6555             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
6556                 return false;
6557             }
6558             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6559                 return false;
6560             }
6561             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6562                 return false;
6563             }
6564             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6565                     .equals( "Aranaeus" ) ) {
6566                 return false;
6567             }
6568             phylogenies = null;
6569             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
6570             if ( phylogenies.length != 3 ) {
6571                 return false;
6572             }
6573             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6574                 return false;
6575             }
6576             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
6577                 return false;
6578             }
6579             if ( phylogenies[ 0 ].isRooted() ) {
6580                 return false;
6581             }
6582             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6583                 return false;
6584             }
6585             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6586                 return false;
6587             }
6588             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6589                     .equals( "Aranaeus" ) ) {
6590                 return false;
6591             }
6592             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
6593                 return false;
6594             }
6595             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
6596                 return false;
6597             }
6598             if ( phylogenies[ 1 ].isRooted() ) {
6599                 return false;
6600             }
6601             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6602                 return false;
6603             }
6604             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6605                 return false;
6606             }
6607             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6608                     .equals( "Aranaeus" ) ) {
6609                 return false;
6610             }
6611             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6612                 return false;
6613             }
6614             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
6615                 return false;
6616             }
6617             if ( !phylogenies[ 2 ].isRooted() ) {
6618                 return false;
6619             }
6620             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6621                 return false;
6622             }
6623             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6624                 return false;
6625             }
6626             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6627                     .equals( "Aranaeus" ) ) {
6628                 return false;
6629             }
6630             phylogenies = null;
6631             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
6632             if ( phylogenies.length != 3 ) {
6633                 return false;
6634             }
6635             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6636                 return false;
6637             }
6638             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
6639                 return false;
6640             }
6641             if ( phylogenies[ 0 ].isRooted() ) {
6642                 return false;
6643             }
6644             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6645                 return false;
6646             }
6647             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6648                 return false;
6649             }
6650             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6651                     .equals( "Aranaeus" ) ) {
6652                 return false;
6653             }
6654             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
6655                 return false;
6656             }
6657             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
6658                 return false;
6659             }
6660             if ( phylogenies[ 1 ].isRooted() ) {
6661                 return false;
6662             }
6663             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6664                 return false;
6665             }
6666             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6667                 return false;
6668             }
6669             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6670                     .equals( "Aranaeus" ) ) {
6671                 return false;
6672             }
6673             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6674                 return false;
6675             }
6676             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
6677                 return false;
6678             }
6679             if ( !phylogenies[ 2 ].isRooted() ) {
6680                 return false;
6681             }
6682             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6683                 return false;
6684             }
6685             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6686                 return false;
6687             }
6688             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6689                     .equals( "Aranaeus" ) ) {
6690                 return false;
6691             }
6692         }
6693         catch ( final Exception e ) {
6694             e.printStackTrace( System.out );
6695             return false;
6696         }
6697         return true;
6698     }
6699
6700     private static boolean testNHParsing() {
6701         try {
6702             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6703             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
6704             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
6705                 return false;
6706             }
6707             final NHXParser nhxp = new NHXParser();
6708             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
6709             nhxp.setReplaceUnderscores( true );
6710             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
6711             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
6712                 return false;
6713             }
6714             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
6715                 return false;
6716             }
6717             final Phylogeny p1b = factory
6718                     .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 ",
6719                              new NHXParser() )[ 0 ];
6720             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
6721                 return false;
6722             }
6723             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
6724                 return false;
6725             }
6726             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
6727             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
6728             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
6729             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
6730             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
6731             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
6732             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
6733             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
6734             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
6735             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
6736             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
6737                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
6738                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
6739                                                     new NHXParser() );
6740             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
6741                 return false;
6742             }
6743             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
6744                 return false;
6745             }
6746             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
6747                 return false;
6748             }
6749             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
6750                 return false;
6751             }
6752             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
6753             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
6754             final String p16_S = "((A,B),C)";
6755             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
6756             if ( p16.length != 1 ) {
6757                 return false;
6758             }
6759             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
6760                 return false;
6761             }
6762             final String p17_S = "(C,(A,B))";
6763             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
6764             if ( p17.length != 1 ) {
6765                 return false;
6766             }
6767             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
6768                 return false;
6769             }
6770             final String p18_S = "((A,B),(C,D))";
6771             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
6772             if ( p18.length != 1 ) {
6773                 return false;
6774             }
6775             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
6776                 return false;
6777             }
6778             final String p19_S = "(((A,B),C),D)";
6779             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
6780             if ( p19.length != 1 ) {
6781                 return false;
6782             }
6783             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
6784                 return false;
6785             }
6786             final String p20_S = "(A,(B,(C,D)))";
6787             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
6788             if ( p20.length != 1 ) {
6789                 return false;
6790             }
6791             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
6792                 return false;
6793             }
6794             final String p21_S = "(A,(B,(C,(D,E))))";
6795             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
6796             if ( p21.length != 1 ) {
6797                 return false;
6798             }
6799             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
6800                 return false;
6801             }
6802             final String p22_S = "((((A,B),C),D),E)";
6803             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
6804             if ( p22.length != 1 ) {
6805                 return false;
6806             }
6807             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
6808                 return false;
6809             }
6810             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
6811             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
6812             if ( p23.length != 1 ) {
6813                 System.out.println( "xl=" + p23.length );
6814                 System.exit( -1 );
6815                 return false;
6816             }
6817             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
6818                 return false;
6819             }
6820             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6821             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
6822             if ( p24.length != 1 ) {
6823                 return false;
6824             }
6825             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
6826                 return false;
6827             }
6828             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
6829             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6830             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
6831             if ( p241.length != 2 ) {
6832                 return false;
6833             }
6834             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
6835                 return false;
6836             }
6837             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
6838                 return false;
6839             }
6840             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
6841                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
6842                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
6843                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
6844                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
6845                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
6846                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
6847                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
6848             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
6849             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
6850                 return false;
6851             }
6852             final String p26_S = "(A,B)ab";
6853             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
6854             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
6855                 return false;
6856             }
6857             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6858             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
6859             if ( p27s.length != 1 ) {
6860                 System.out.println( "xxl=" + p27s.length );
6861                 System.exit( -1 );
6862                 return false;
6863             }
6864             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
6865                 System.out.println( p27s[ 0 ].toNewHampshireX() );
6866                 System.exit( -1 );
6867                 return false;
6868             }
6869             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
6870                                                     new NHXParser() );
6871             if ( p27.length != 1 ) {
6872                 System.out.println( "yl=" + p27.length );
6873                 System.exit( -1 );
6874                 return false;
6875             }
6876             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
6877                 System.out.println( p27[ 0 ].toNewHampshireX() );
6878                 System.exit( -1 );
6879                 return false;
6880             }
6881             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6882             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
6883             final String p28_S3 = "(A,B)ab";
6884             final String p28_S4 = "((((A,B),C),D),;E;)";
6885             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
6886                                                     new NHXParser() );
6887             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
6888                 return false;
6889             }
6890             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
6891                 return false;
6892             }
6893             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
6894                 return false;
6895             }
6896             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
6897                 return false;
6898             }
6899             if ( p28.length != 4 ) {
6900                 return false;
6901             }
6902             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";
6903             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
6904             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
6905                 return false;
6906             }
6907             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";
6908             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
6909             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
6910                 return false;
6911             }
6912             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
6913             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
6914             if ( ( p32.length != 0 ) ) {
6915                 return false;
6916             }
6917             final String p33_S = "A";
6918             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
6919             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
6920                 return false;
6921             }
6922             final String p34_S = "B;";
6923             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
6924             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
6925                 return false;
6926             }
6927             final String p35_S = "B:0.2";
6928             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
6929             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
6930                 return false;
6931             }
6932             final String p36_S = "(A)";
6933             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
6934             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
6935                 return false;
6936             }
6937             final String p37_S = "((A))";
6938             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
6939             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
6940                 return false;
6941             }
6942             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
6943             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
6944             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
6945                 return false;
6946             }
6947             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
6948             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
6949             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
6950                 return false;
6951             }
6952             final String p40_S = "(A,B,C)";
6953             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
6954             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
6955                 return false;
6956             }
6957             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
6958             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
6959             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
6960                 return false;
6961             }
6962             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
6963             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
6964             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
6965                 return false;
6966             }
6967             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)";
6968             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
6969             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
6970                 return false;
6971             }
6972             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)))";
6973             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
6974             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
6975                 return false;
6976             }
6977             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
6978             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
6979             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
6980                 return false;
6981             }
6982             final String p46_S = "";
6983             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
6984             if ( p46.length != 0 ) {
6985                 return false;
6986             }
6987             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
6988             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
6989                 return false;
6990             }
6991             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
6992             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
6993                 return false;
6994             }
6995             final Phylogeny p49 = factory
6996                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
6997                              new NHXParser() )[ 0 ];
6998             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
6999                 return false;
7000             }
7001             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7002             if ( p50.getNode( "A" ) == null ) {
7003                 return false;
7004             }
7005             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7006                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
7007                 return false;
7008             }
7009             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
7010                 return false;
7011             }
7012             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
7013                     .equals( "((A,B)88:2.0,C);" ) ) {
7014                 return false;
7015             }
7016             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7017             if ( p51.getNode( "A(A" ) == null ) {
7018                 return false;
7019             }
7020             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7021             if ( p52.getNode( "A(A" ) == null ) {
7022                 return false;
7023             }
7024             final Phylogeny p53 = factory
7025                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
7026                              new NHXParser() )[ 0 ];
7027             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
7028                 return false;
7029             }
7030             // 
7031             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
7032             if ( p54.getNode( "A" ) == null ) {
7033                 return false;
7034             }
7035             if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7036                     .equals( "((A,B)[88],C);" ) ) {
7037                 return false;
7038             }
7039         }
7040         catch ( final Exception e ) {
7041             e.printStackTrace( System.out );
7042             return false;
7043         }
7044         return true;
7045     }
7046
7047     private static boolean testNHParsingIter() {
7048         try {
7049             final String p0_str = "(A,B);";
7050             final NHXParser p = new NHXParser();
7051             p.setSource( p0_str );
7052             if ( !p.hasNext() ) {
7053                 return false;
7054             }
7055             final Phylogeny p0 = p.next();
7056             if ( !p0.toNewHampshire().equals( p0_str ) ) {
7057                 System.out.println( p0.toNewHampshire() );
7058                 return false;
7059             }
7060             if ( p.hasNext() ) {
7061                 return false;
7062             }
7063             if ( p.next() != null ) {
7064                 return false;
7065             }
7066             //
7067             final String p00_str = "(A,B)root;";
7068             p.setSource( p00_str );
7069             final Phylogeny p00 = p.next();
7070             if ( !p00.toNewHampshire().equals( p00_str ) ) {
7071                 System.out.println( p00.toNewHampshire() );
7072                 return false;
7073             }
7074             //
7075             final String p000_str = "A;";
7076             p.setSource( p000_str );
7077             final Phylogeny p000 = p.next();
7078             if ( !p000.toNewHampshire().equals( p000_str ) ) {
7079                 System.out.println( p000.toNewHampshire() );
7080                 return false;
7081             }
7082             //
7083             final String p0000_str = "A";
7084             p.setSource( p0000_str );
7085             final Phylogeny p0000 = p.next();
7086             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
7087                 System.out.println( p0000.toNewHampshire() );
7088                 return false;
7089             }
7090             //
7091             p.setSource( "(A)" );
7092             final Phylogeny p00000 = p.next();
7093             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
7094                 System.out.println( p00000.toNewHampshire() );
7095                 return false;
7096             }
7097             //
7098             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
7099             p.setSource( p1_str );
7100             if ( !p.hasNext() ) {
7101                 return false;
7102             }
7103             final Phylogeny p1_0 = p.next();
7104             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
7105                 System.out.println( p1_0.toNewHampshire() );
7106                 return false;
7107             }
7108             if ( !p.hasNext() ) {
7109                 return false;
7110             }
7111             final Phylogeny p1_1 = p.next();
7112             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
7113                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
7114                 return false;
7115             }
7116             if ( !p.hasNext() ) {
7117                 return false;
7118             }
7119             final Phylogeny p1_2 = p.next();
7120             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
7121                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
7122                 return false;
7123             }
7124             if ( !p.hasNext() ) {
7125                 return false;
7126             }
7127             final Phylogeny p1_3 = p.next();
7128             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
7129                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
7130                 return false;
7131             }
7132             if ( p.hasNext() ) {
7133                 return false;
7134             }
7135             if ( p.next() != null ) {
7136                 return false;
7137             }
7138             //
7139             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
7140             p.setSource( p2_str );
7141             if ( !p.hasNext() ) {
7142                 return false;
7143             }
7144             Phylogeny p2_0 = p.next();
7145             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
7146                 System.out.println( p2_0.toNewHampshire() );
7147                 return false;
7148             }
7149             if ( !p.hasNext() ) {
7150                 return false;
7151             }
7152             Phylogeny p2_1 = p.next();
7153             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
7154                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
7155                 return false;
7156             }
7157             if ( !p.hasNext() ) {
7158                 return false;
7159             }
7160             Phylogeny p2_2 = p.next();
7161             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
7162                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
7163                 return false;
7164             }
7165             if ( !p.hasNext() ) {
7166                 return false;
7167             }
7168             Phylogeny p2_3 = p.next();
7169             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
7170                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
7171                 return false;
7172             }
7173             if ( !p.hasNext() ) {
7174                 return false;
7175             }
7176             Phylogeny p2_4 = p.next();
7177             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
7178                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
7179                 return false;
7180             }
7181             if ( p.hasNext() ) {
7182                 return false;
7183             }
7184             if ( p.next() != null ) {
7185                 return false;
7186             }
7187             ////
7188             p.reset();
7189             if ( !p.hasNext() ) {
7190                 return false;
7191             }
7192             p2_0 = p.next();
7193             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
7194                 System.out.println( p2_0.toNewHampshire() );
7195                 return false;
7196             }
7197             if ( !p.hasNext() ) {
7198                 return false;
7199             }
7200             p2_1 = p.next();
7201             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
7202                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
7203                 return false;
7204             }
7205             if ( !p.hasNext() ) {
7206                 return false;
7207             }
7208             p2_2 = p.next();
7209             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
7210                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
7211                 return false;
7212             }
7213             if ( !p.hasNext() ) {
7214                 return false;
7215             }
7216             p2_3 = p.next();
7217             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
7218                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
7219                 return false;
7220             }
7221             if ( !p.hasNext() ) {
7222                 return false;
7223             }
7224             p2_4 = p.next();
7225             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
7226                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
7227                 return false;
7228             }
7229             if ( p.hasNext() ) {
7230                 return false;
7231             }
7232             if ( p.next() != null ) {
7233                 return false;
7234             }
7235             //
7236             final String p3_str = "((A,B),C)abc";
7237             p.setSource( p3_str );
7238             if ( !p.hasNext() ) {
7239                 return false;
7240             }
7241             final Phylogeny p3_0 = p.next();
7242             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
7243                 return false;
7244             }
7245             if ( p.hasNext() ) {
7246                 return false;
7247             }
7248             if ( p.next() != null ) {
7249                 return false;
7250             }
7251             //
7252             final String p4_str = "((A,B)ab,C)abc";
7253             p.setSource( p4_str );
7254             if ( !p.hasNext() ) {
7255                 return false;
7256             }
7257             final Phylogeny p4_0 = p.next();
7258             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
7259                 return false;
7260             }
7261             if ( p.hasNext() ) {
7262                 return false;
7263             }
7264             if ( p.next() != null ) {
7265                 return false;
7266             }
7267             //
7268             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
7269             p.setSource( p5_str );
7270             if ( !p.hasNext() ) {
7271                 return false;
7272             }
7273             final Phylogeny p5_0 = p.next();
7274             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
7275                 return false;
7276             }
7277             if ( p.hasNext() ) {
7278                 return false;
7279             }
7280             if ( p.next() != null ) {
7281                 return false;
7282             }
7283             //
7284             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7285             p.setSource( p6_str );
7286             if ( !p.hasNext() ) {
7287                 return false;
7288             }
7289             Phylogeny p6_0 = p.next();
7290             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
7291                 return false;
7292             }
7293             if ( p.hasNext() ) {
7294                 return false;
7295             }
7296             if ( p.next() != null ) {
7297                 return false;
7298             }
7299             p.reset();
7300             if ( !p.hasNext() ) {
7301                 return false;
7302             }
7303             p6_0 = p.next();
7304             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
7305                 return false;
7306             }
7307             if ( p.hasNext() ) {
7308                 return false;
7309             }
7310             if ( p.next() != null ) {
7311                 return false;
7312             }
7313             //
7314             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7315             p.setSource( p7_str );
7316             if ( !p.hasNext() ) {
7317                 return false;
7318             }
7319             Phylogeny p7_0 = p.next();
7320             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7321                 return false;
7322             }
7323             if ( p.hasNext() ) {
7324                 return false;
7325             }
7326             if ( p.next() != null ) {
7327                 return false;
7328             }
7329             p.reset();
7330             if ( !p.hasNext() ) {
7331                 return false;
7332             }
7333             p7_0 = p.next();
7334             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7335                 return false;
7336             }
7337             if ( p.hasNext() ) {
7338                 return false;
7339             }
7340             if ( p.next() != null ) {
7341                 return false;
7342             }
7343             //
7344             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
7345             p.setSource( p8_str );
7346             if ( !p.hasNext() ) {
7347                 return false;
7348             }
7349             Phylogeny p8_0 = p.next();
7350             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7351                 return false;
7352             }
7353             if ( !p.hasNext() ) {
7354                 return false;
7355             }
7356             if ( !p.hasNext() ) {
7357                 return false;
7358             }
7359             Phylogeny p8_1 = p.next();
7360             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
7361                 return false;
7362             }
7363             if ( p.hasNext() ) {
7364                 return false;
7365             }
7366             if ( p.next() != null ) {
7367                 return false;
7368             }
7369             p.reset();
7370             if ( !p.hasNext() ) {
7371                 return false;
7372             }
7373             p8_0 = p.next();
7374             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7375                 return false;
7376             }
7377             if ( !p.hasNext() ) {
7378                 return false;
7379             }
7380             p8_1 = p.next();
7381             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
7382                 return false;
7383             }
7384             if ( p.hasNext() ) {
7385                 return false;
7386             }
7387             if ( p.next() != null ) {
7388                 return false;
7389             }
7390             p.reset();
7391             //
7392             p.setSource( "" );
7393             if ( p.hasNext() ) {
7394                 return false;
7395             }
7396             //
7397             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
7398             if ( !p.hasNext() ) {
7399                 return false;
7400             }
7401             Phylogeny p_27 = p.next();
7402             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
7403                 System.out.println( p_27.toNewHampshireX() );
7404                 System.exit( -1 );
7405                 return false;
7406             }
7407             if ( p.hasNext() ) {
7408                 return false;
7409             }
7410             if ( p.next() != null ) {
7411                 return false;
7412             }
7413             p.reset();
7414             if ( !p.hasNext() ) {
7415                 return false;
7416             }
7417             p_27 = p.next();
7418             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
7419                 System.out.println( p_27.toNewHampshireX() );
7420                 System.exit( -1 );
7421                 return false;
7422             }
7423             if ( p.hasNext() ) {
7424                 return false;
7425             }
7426             if ( p.next() != null ) {
7427                 return false;
7428             }
7429         }
7430         catch ( final Exception e ) {
7431             e.printStackTrace( System.out );
7432             return false;
7433         }
7434         return true;
7435     }
7436
7437     private static boolean testNHXconversion() {
7438         try {
7439             final PhylogenyNode n1 = new PhylogenyNode();
7440             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
7441             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
7442             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
7443             final PhylogenyNode n5 = PhylogenyNode
7444                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
7445             final PhylogenyNode n6 = PhylogenyNode
7446                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
7447             if ( !n1.toNewHampshireX().equals( "" ) ) {
7448                 return false;
7449             }
7450             if ( !n2.toNewHampshireX().equals( "" ) ) {
7451                 return false;
7452             }
7453             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
7454                 return false;
7455             }
7456             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
7457                 return false;
7458             }
7459             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
7460                 return false;
7461             }
7462             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
7463                 System.out.println( n6.toNewHampshireX() );
7464                 return false;
7465             }
7466         }
7467         catch ( final Exception e ) {
7468             e.printStackTrace( System.out );
7469             return false;
7470         }
7471         return true;
7472     }
7473
7474     private static boolean testNHXNodeParsing() {
7475         try {
7476             final PhylogenyNode n1 = new PhylogenyNode();
7477             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
7478             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
7479             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
7480             final PhylogenyNode n5 = PhylogenyNode
7481                     .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]" );
7482             if ( !n3.getName().equals( "n3" ) ) {
7483                 return false;
7484             }
7485             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
7486                 return false;
7487             }
7488             if ( n3.isDuplication() ) {
7489                 return false;
7490             }
7491             if ( n3.isHasAssignedEvent() ) {
7492                 return false;
7493             }
7494             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
7495                 return false;
7496             }
7497             if ( !n4.getName().equals( "n4" ) ) {
7498                 return false;
7499             }
7500             if ( n4.getDistanceToParent() != 0.01 ) {
7501                 return false;
7502             }
7503             if ( !n5.getName().equals( "n5" ) ) {
7504                 return false;
7505             }
7506             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
7507                 return false;
7508             }
7509             if ( n5.getDistanceToParent() != 0.1 ) {
7510                 return false;
7511             }
7512             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
7513                 return false;
7514             }
7515             if ( !n5.isDuplication() ) {
7516                 return false;
7517             }
7518             if ( !n5.isHasAssignedEvent() ) {
7519                 return false;
7520             }
7521             final PhylogenyNode n8 = PhylogenyNode
7522                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
7523                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7524             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
7525                 return false;
7526             }
7527             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
7528                 return false;
7529             }
7530             final PhylogenyNode n9 = PhylogenyNode
7531                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
7532                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7533             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
7534                 return false;
7535             }
7536             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
7537                 return false;
7538             }
7539             final PhylogenyNode n10 = PhylogenyNode
7540                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7541             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
7542                 return false;
7543             }
7544             final PhylogenyNode n20 = PhylogenyNode
7545                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7546             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
7547                 return false;
7548             }
7549             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
7550                 return false;
7551             }
7552             final PhylogenyNode n20x = PhylogenyNode
7553                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7554             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
7555                 return false;
7556             }
7557             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
7558                 return false;
7559             }
7560             final PhylogenyNode n20xx = PhylogenyNode
7561                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7562             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
7563                 return false;
7564             }
7565             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
7566                 return false;
7567             }
7568             final PhylogenyNode n20xxx = PhylogenyNode
7569                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7570             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
7571                 return false;
7572             }
7573             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
7574                 return false;
7575             }
7576             final PhylogenyNode n20xxxx = PhylogenyNode
7577                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7578             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
7579                 return false;
7580             }
7581             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
7582                 return false;
7583             }
7584             final PhylogenyNode n21 = PhylogenyNode
7585                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7586             if ( !n21.getName().equals( "N21_PIG" ) ) {
7587                 return false;
7588             }
7589             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
7590                 return false;
7591             }
7592             final PhylogenyNode n21x = PhylogenyNode
7593                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7594             if ( !n21x.getName().equals( "n21_PIG" ) ) {
7595                 return false;
7596             }
7597             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
7598                 return false;
7599             }
7600             final PhylogenyNode n22 = PhylogenyNode
7601                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7602             if ( !n22.getName().equals( "n22/PIG" ) ) {
7603                 return false;
7604             }
7605             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
7606                 return false;
7607             }
7608             final PhylogenyNode n23 = PhylogenyNode
7609                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7610             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
7611                 return false;
7612             }
7613             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
7614                 return false;
7615             }
7616             final PhylogenyNode a = PhylogenyNode
7617                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7618             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
7619                 return false;
7620             }
7621             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
7622                 return false;
7623             }
7624             final PhylogenyNode c1 = PhylogenyNode
7625                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
7626                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7627             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
7628                 return false;
7629             }
7630             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
7631                 return false;
7632             }
7633             final PhylogenyNode c2 = PhylogenyNode
7634                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
7635                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7636             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
7637                 return false;
7638             }
7639             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
7640                 return false;
7641             }
7642             final PhylogenyNode e3 = PhylogenyNode
7643                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7644             if ( !e3.getName().equals( "n10_RAT~" ) ) {
7645                 return false;
7646             }
7647             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
7648                 return false;
7649             }
7650             final PhylogenyNode n11 = PhylogenyNode
7651                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
7652                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7653             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
7654                 return false;
7655             }
7656             if ( n11.getDistanceToParent() != 0.4 ) {
7657                 return false;
7658             }
7659             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
7660                 return false;
7661             }
7662             final PhylogenyNode n12 = PhylogenyNode
7663                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
7664                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7665             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
7666                 return false;
7667             }
7668             if ( n12.getDistanceToParent() != 0.4 ) {
7669                 return false;
7670             }
7671             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
7672                 return false;
7673             }
7674             final PhylogenyNode o = PhylogenyNode
7675                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7676             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
7677                 return false;
7678             }
7679             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
7680                 return false;
7681             }
7682             if ( n1.getName().compareTo( "" ) != 0 ) {
7683                 return false;
7684             }
7685             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
7686                 return false;
7687             }
7688             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
7689                 return false;
7690             }
7691             if ( n2.getName().compareTo( "" ) != 0 ) {
7692                 return false;
7693             }
7694             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
7695                 return false;
7696             }
7697             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
7698                 return false;
7699             }
7700             final PhylogenyNode n00 = PhylogenyNode
7701                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
7702             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
7703                 return false;
7704             }
7705             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
7706                 return false;
7707             }
7708             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
7709             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
7710                 return false;
7711             }
7712             final PhylogenyNode n13 = PhylogenyNode
7713                     .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7714             if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
7715                 return false;
7716             }
7717             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
7718                 return false;
7719             }
7720             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
7721                 return false;
7722             }
7723             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
7724                 return false;
7725             }
7726             final PhylogenyNode n14 = PhylogenyNode
7727                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7728             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
7729                 return false;
7730             }
7731             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
7732                 return false;
7733             }
7734             final PhylogenyNode n15 = PhylogenyNode
7735                     .createInstanceFromNhxString( "something_wicked[123]",
7736                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7737             if ( !n15.getName().equals( "something_wicked" ) ) {
7738                 return false;
7739             }
7740             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
7741                 return false;
7742             }
7743             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
7744                 return false;
7745             }
7746             final PhylogenyNode n16 = PhylogenyNode
7747                     .createInstanceFromNhxString( "something_wicked2[9]",
7748                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7749             if ( !n16.getName().equals( "something_wicked2" ) ) {
7750                 return false;
7751             }
7752             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
7753                 return false;
7754             }
7755             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
7756                 return false;
7757             }
7758             final PhylogenyNode n17 = PhylogenyNode
7759                     .createInstanceFromNhxString( "something_wicked3[a]",
7760                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7761             if ( !n17.getName().equals( "something_wicked3" ) ) {
7762                 return false;
7763             }
7764             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
7765                 return false;
7766             }
7767             final PhylogenyNode n18 = PhylogenyNode
7768                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7769             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
7770                 return false;
7771             }
7772             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
7773                 return false;
7774             }
7775             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
7776                 return false;
7777             }
7778             final PhylogenyNode n19 = PhylogenyNode
7779                     .createInstanceFromNhxString( "blah_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7780             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
7781                 return false;
7782             }
7783             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
7784                 return false;
7785             }
7786             final PhylogenyNode n30 = PhylogenyNode
7787                     .createInstanceFromNhxString( "blah_1234567-roejojoej",
7788                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7789             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
7790                 return false;
7791             }
7792             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
7793                 return false;
7794             }
7795             final PhylogenyNode n31 = PhylogenyNode
7796                     .createInstanceFromNhxString( "blah_12345678-roejojoej",
7797                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7798             if ( n31.getNodeData().isHasTaxonomy() ) {
7799                 return false;
7800             }
7801             final PhylogenyNode n32 = PhylogenyNode
7802                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7803             if ( n32.getNodeData().isHasTaxonomy() ) {
7804                 return false;
7805             }
7806             final PhylogenyNode n40 = PhylogenyNode
7807                     .createInstanceFromNhxString( "bcl2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7808             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
7809                 return false;
7810             }
7811             final PhylogenyNode n41 = PhylogenyNode
7812                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7813             if ( n41.getNodeData().isHasTaxonomy() ) {
7814                 return false;
7815             }
7816             final PhylogenyNode n42 = PhylogenyNode
7817                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7818             if ( n42.getNodeData().isHasTaxonomy() ) {
7819                 return false;
7820             }
7821             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
7822                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
7823             if ( n43.getNodeData().isHasTaxonomy() ) {
7824                 return false;
7825             }
7826             final PhylogenyNode n44 = PhylogenyNode
7827                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7828             if ( n44.getNodeData().isHasTaxonomy() ) {
7829                 return false;
7830             }
7831         }
7832         catch ( final Exception e ) {
7833             e.printStackTrace( System.out );
7834             return false;
7835         }
7836         return true;
7837     }
7838
7839     private static boolean testNHXParsing() {
7840         try {
7841             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7842             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
7843             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
7844                 return false;
7845             }
7846             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]";
7847             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
7848             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
7849                 return false;
7850             }
7851             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]";
7852             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
7853             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
7854                 return false;
7855             }
7856             final Phylogeny[] p3 = factory
7857                     .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]",
7858                              new NHXParser() );
7859             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
7860                 return false;
7861             }
7862             final Phylogeny[] p4 = factory
7863                     .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(]",
7864                              new NHXParser() );
7865             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
7866                 return false;
7867             }
7868             final Phylogeny[] p5 = factory
7869                     .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(((]",
7870                              new NHXParser() );
7871             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
7872                 return false;
7873             }
7874             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)";
7875             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)";
7876             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
7877             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
7878                 return false;
7879             }
7880             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)))";
7881             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)))";
7882             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
7883             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
7884                 return false;
7885             }
7886             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])   ))[,,, ])))))))";
7887             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
7888             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
7889             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
7890                 return false;
7891             }
7892             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
7893             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
7894                 return false;
7895             }
7896             final Phylogeny p10 = factory
7897                     .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]",
7898                              new NHXParser() )[ 0 ];
7899             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
7900                 return false;
7901             }
7902         }
7903         catch ( final Exception e ) {
7904             e.printStackTrace( System.out );
7905             return false;
7906         }
7907         return true;
7908     }
7909
7910     private static boolean testNHXParsingMB() {
7911         try {
7912             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7913             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
7914                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
7915                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
7916                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
7917                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
7918                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
7919                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
7920                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
7921                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
7922             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
7923                 return false;
7924             }
7925             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
7926                 return false;
7927             }
7928             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
7929                            0.1100000000000000e+00 ) ) {
7930                 return false;
7931             }
7932             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
7933                 return false;
7934             }
7935             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
7936                 return false;
7937             }
7938             final Phylogeny p2 = factory
7939                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
7940                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
7941                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
7942                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
7943                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
7944                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
7945                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
7946                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
7947                                      + "7.369400000000000e-02}])",
7948                              new NHXParser() )[ 0 ];
7949             if ( p2.getNode( "1" ) == null ) {
7950                 return false;
7951             }
7952             if ( p2.getNode( "2" ) == null ) {
7953                 return false;
7954             }
7955         }
7956         catch ( final Exception e ) {
7957             e.printStackTrace( System.out );
7958             System.exit( -1 );
7959             return false;
7960         }
7961         return true;
7962     }
7963
7964     private static boolean testNHXParsingQuotes() {
7965         try {
7966             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7967             final NHXParser p = new NHXParser();
7968             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
7969             if ( phylogenies_0.length != 5 ) {
7970                 return false;
7971             }
7972             final Phylogeny phy = phylogenies_0[ 4 ];
7973             if ( phy.getNumberOfExternalNodes() != 7 ) {
7974                 return false;
7975             }
7976             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
7977                 return false;
7978             }
7979             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
7980                 return false;
7981             }
7982             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
7983                     .getScientificName().equals( "hsapiens" ) ) {
7984                 return false;
7985             }
7986             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
7987                 return false;
7988             }
7989             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
7990                 return false;
7991             }
7992             if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
7993                 return false;
7994             }
7995             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
7996                 return false;
7997             }
7998             if ( phy.getNodes( "A   (  B    C '" ).size() != 1 ) {
7999                 return false;
8000             }
8001             final NHXParser p1p = new NHXParser();
8002             p1p.setIgnoreQuotes( true );
8003             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
8004             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
8005                 return false;
8006             }
8007             final NHXParser p2p = new NHXParser();
8008             p1p.setIgnoreQuotes( false );
8009             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
8010             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
8011                 return false;
8012             }
8013             final NHXParser p3p = new NHXParser();
8014             p3p.setIgnoreQuotes( false );
8015             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
8016             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
8017                 return false;
8018             }
8019             final NHXParser p4p = new NHXParser();
8020             p4p.setIgnoreQuotes( false );
8021             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
8022             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
8023                 return false;
8024             }
8025             final Phylogeny p10 = factory
8026                     .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]",
8027                              new NHXParser() )[ 0 ];
8028             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]";
8029             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
8030                 return false;
8031             }
8032             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
8033             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
8034                 return false;
8035             }
8036             //
8037             final Phylogeny p12 = factory
8038                     .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]",
8039                              new NHXParser() )[ 0 ];
8040             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]";
8041             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
8042                 return false;
8043             }
8044             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
8045             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
8046                 return false;
8047             }
8048             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;";
8049             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
8050                 return false;
8051             }
8052             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
8053             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
8054                 return false;
8055             }
8056         }
8057         catch ( final Exception e ) {
8058             e.printStackTrace( System.out );
8059             return false;
8060         }
8061         return true;
8062     }
8063
8064     private static boolean testNodeRemoval() {
8065         try {
8066             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8067             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
8068             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
8069             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
8070                 return false;
8071             }
8072             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
8073             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
8074             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
8075                 return false;
8076             }
8077             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
8078             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
8079             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
8080                 return false;
8081             }
8082         }
8083         catch ( final Exception e ) {
8084             e.printStackTrace( System.out );
8085             return false;
8086         }
8087         return true;
8088     }
8089
8090     private static boolean testPhylogenyBranch() {
8091         try {
8092             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
8093             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
8094             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
8095             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
8096             if ( !a1b1.equals( a1b1 ) ) {
8097                 return false;
8098             }
8099             if ( !a1b1.equals( b1a1 ) ) {
8100                 return false;
8101             }
8102             if ( !b1a1.equals( a1b1 ) ) {
8103                 return false;
8104             }
8105             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
8106             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
8107             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
8108             if ( a1_b1.equals( b1_a1 ) ) {
8109                 return false;
8110             }
8111             if ( a1_b1.equals( a1_b1_ ) ) {
8112                 return false;
8113             }
8114             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
8115             if ( !a1_b1.equals( b1_a1_ ) ) {
8116                 return false;
8117             }
8118             if ( a1_b1_.equals( b1_a1_ ) ) {
8119                 return false;
8120             }
8121             if ( !a1_b1_.equals( b1_a1 ) ) {
8122                 return false;
8123             }
8124         }
8125         catch ( final Exception e ) {
8126             e.printStackTrace( System.out );
8127             return false;
8128         }
8129         return true;
8130     }
8131
8132     private static boolean testPhyloXMLparsingOfDistributionElement() {
8133         try {
8134             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8135             PhyloXmlParser xml_parser = null;
8136             try {
8137                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
8138             }
8139             catch ( final Exception e ) {
8140                 // Do nothing -- means were not running from jar.
8141             }
8142             if ( xml_parser == null ) {
8143                 xml_parser = new PhyloXmlParser();
8144                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
8145                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
8146                 }
8147                 else {
8148                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
8149                 }
8150             }
8151             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
8152                                                               xml_parser );
8153             if ( xml_parser.getErrorCount() > 0 ) {
8154                 System.out.println( xml_parser.getErrorMessages().toString() );
8155                 return false;
8156             }
8157             if ( phylogenies_0.length != 1 ) {
8158                 return false;
8159             }
8160             final Phylogeny t1 = phylogenies_0[ 0 ];
8161             PhylogenyNode n = null;
8162             Distribution d = null;
8163             n = t1.getNode( "root node" );
8164             if ( !n.getNodeData().isHasDistribution() ) {
8165                 return false;
8166             }
8167             if ( n.getNodeData().getDistributions().size() != 1 ) {
8168                 return false;
8169             }
8170             d = n.getNodeData().getDistribution();
8171             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
8172                 return false;
8173             }
8174             if ( d.getPoints().size() != 1 ) {
8175                 return false;
8176             }
8177             if ( d.getPolygons() != null ) {
8178                 return false;
8179             }
8180             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
8181                 return false;
8182             }
8183             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8184                 return false;
8185             }
8186             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8187                 return false;
8188             }
8189             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
8190                 return false;
8191             }
8192             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
8193                 return false;
8194             }
8195             n = t1.getNode( "node a" );
8196             if ( !n.getNodeData().isHasDistribution() ) {
8197                 return false;
8198             }
8199             if ( n.getNodeData().getDistributions().size() != 2 ) {
8200                 return false;
8201             }
8202             d = n.getNodeData().getDistribution( 1 );
8203             if ( !d.getDesc().equals( "San Diego" ) ) {
8204                 return false;
8205             }
8206             if ( d.getPoints().size() != 1 ) {
8207                 return false;
8208             }
8209             if ( d.getPolygons() != null ) {
8210                 return false;
8211             }
8212             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
8213                 return false;
8214             }
8215             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8216                 return false;
8217             }
8218             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8219                 return false;
8220             }
8221             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
8222                 return false;
8223             }
8224             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
8225                 return false;
8226             }
8227             n = t1.getNode( "node bb" );
8228             if ( !n.getNodeData().isHasDistribution() ) {
8229                 return false;
8230             }
8231             if ( n.getNodeData().getDistributions().size() != 1 ) {
8232                 return false;
8233             }
8234             d = n.getNodeData().getDistribution( 0 );
8235             if ( d.getPoints().size() != 3 ) {
8236                 return false;
8237             }
8238             if ( d.getPolygons().size() != 2 ) {
8239                 return false;
8240             }
8241             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
8242                 return false;
8243             }
8244             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
8245                 return false;
8246             }
8247             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
8248                 return false;
8249             }
8250             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
8251                 return false;
8252             }
8253             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
8254                 return false;
8255             }
8256             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
8257                 return false;
8258             }
8259             Polygon p = d.getPolygons().get( 0 );
8260             if ( p.getPoints().size() != 3 ) {
8261                 return false;
8262             }
8263             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
8264                 return false;
8265             }
8266             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
8267                 return false;
8268             }
8269             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8270                 return false;
8271             }
8272             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
8273                 return false;
8274             }
8275             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
8276                 return false;
8277             }
8278             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
8279                 return false;
8280             }
8281             p = d.getPolygons().get( 1 );
8282             if ( p.getPoints().size() != 3 ) {
8283                 return false;
8284             }
8285             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
8286                 return false;
8287             }
8288             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
8289                 return false;
8290             }
8291             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8292                 return false;
8293             }
8294             // Roundtrip:
8295             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
8296             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
8297             if ( rt.length != 1 ) {
8298                 return false;
8299             }
8300             final Phylogeny t1_rt = rt[ 0 ];
8301             n = t1_rt.getNode( "root node" );
8302             if ( !n.getNodeData().isHasDistribution() ) {
8303                 return false;
8304             }
8305             if ( n.getNodeData().getDistributions().size() != 1 ) {
8306                 return false;
8307             }
8308             d = n.getNodeData().getDistribution();
8309             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
8310                 return false;
8311             }
8312             if ( d.getPoints().size() != 1 ) {
8313                 return false;
8314             }
8315             if ( d.getPolygons() != null ) {
8316                 return false;
8317             }
8318             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
8319                 return false;
8320             }
8321             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8322                 return false;
8323             }
8324             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8325                 return false;
8326             }
8327             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
8328                 return false;
8329             }
8330             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
8331                 return false;
8332             }
8333             n = t1_rt.getNode( "node a" );
8334             if ( !n.getNodeData().isHasDistribution() ) {
8335                 return false;
8336             }
8337             if ( n.getNodeData().getDistributions().size() != 2 ) {
8338                 return false;
8339             }
8340             d = n.getNodeData().getDistribution( 1 );
8341             if ( !d.getDesc().equals( "San Diego" ) ) {
8342                 return false;
8343             }
8344             if ( d.getPoints().size() != 1 ) {
8345                 return false;
8346             }
8347             if ( d.getPolygons() != null ) {
8348                 return false;
8349             }
8350             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
8351                 return false;
8352             }
8353             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8354                 return false;
8355             }
8356             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8357                 return false;
8358             }
8359             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
8360                 return false;
8361             }
8362             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
8363                 return false;
8364             }
8365             n = t1_rt.getNode( "node bb" );
8366             if ( !n.getNodeData().isHasDistribution() ) {
8367                 return false;
8368             }
8369             if ( n.getNodeData().getDistributions().size() != 1 ) {
8370                 return false;
8371             }
8372             d = n.getNodeData().getDistribution( 0 );
8373             if ( d.getPoints().size() != 3 ) {
8374                 return false;
8375             }
8376             if ( d.getPolygons().size() != 2 ) {
8377                 return false;
8378             }
8379             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
8380                 return false;
8381             }
8382             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
8383                 return false;
8384             }
8385             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
8386                 return false;
8387             }
8388             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
8389                 return false;
8390             }
8391             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
8392                 return false;
8393             }
8394             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
8395                 return false;
8396             }
8397             p = d.getPolygons().get( 0 );
8398             if ( p.getPoints().size() != 3 ) {
8399                 return false;
8400             }
8401             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
8402                 return false;
8403             }
8404             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
8405                 return false;
8406             }
8407             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8408                 return false;
8409             }
8410             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
8411                 return false;
8412             }
8413             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
8414                 return false;
8415             }
8416             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
8417                 return false;
8418             }
8419             p = d.getPolygons().get( 1 );
8420             if ( p.getPoints().size() != 3 ) {
8421                 return false;
8422             }
8423             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
8424                 return false;
8425             }
8426             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
8427                 return false;
8428             }
8429             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8430                 return false;
8431             }
8432         }
8433         catch ( final Exception e ) {
8434             e.printStackTrace( System.out );
8435             return false;
8436         }
8437         return true;
8438     }
8439
8440     private static boolean testPostOrderIterator() {
8441         try {
8442             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8443             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
8444             PhylogenyNodeIterator it0;
8445             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
8446                 it0.next();
8447             }
8448             for( it0.reset(); it0.hasNext(); ) {
8449                 it0.next();
8450             }
8451             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
8452             final PhylogenyNodeIterator it = t1.iteratorPostorder();
8453             if ( !it.next().getName().equals( "A" ) ) {
8454                 return false;
8455             }
8456             if ( !it.next().getName().equals( "B" ) ) {
8457                 return false;
8458             }
8459             if ( !it.next().getName().equals( "ab" ) ) {
8460                 return false;
8461             }
8462             if ( !it.next().getName().equals( "C" ) ) {
8463                 return false;
8464             }
8465             if ( !it.next().getName().equals( "D" ) ) {
8466                 return false;
8467             }
8468             if ( !it.next().getName().equals( "cd" ) ) {
8469                 return false;
8470             }
8471             if ( !it.next().getName().equals( "abcd" ) ) {
8472                 return false;
8473             }
8474             if ( !it.next().getName().equals( "E" ) ) {
8475                 return false;
8476             }
8477             if ( !it.next().getName().equals( "F" ) ) {
8478                 return false;
8479             }
8480             if ( !it.next().getName().equals( "ef" ) ) {
8481                 return false;
8482             }
8483             if ( !it.next().getName().equals( "G" ) ) {
8484                 return false;
8485             }
8486             if ( !it.next().getName().equals( "H" ) ) {
8487                 return false;
8488             }
8489             if ( !it.next().getName().equals( "gh" ) ) {
8490                 return false;
8491             }
8492             if ( !it.next().getName().equals( "efgh" ) ) {
8493                 return false;
8494             }
8495             if ( !it.next().getName().equals( "r" ) ) {
8496                 return false;
8497             }
8498             if ( it.hasNext() ) {
8499                 return false;
8500             }
8501         }
8502         catch ( final Exception e ) {
8503             e.printStackTrace( System.out );
8504             return false;
8505         }
8506         return true;
8507     }
8508
8509     private static boolean testPreOrderIterator() {
8510         try {
8511             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8512             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
8513             PhylogenyNodeIterator it0;
8514             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
8515                 it0.next();
8516             }
8517             for( it0.reset(); it0.hasNext(); ) {
8518                 it0.next();
8519             }
8520             PhylogenyNodeIterator it = t0.iteratorPreorder();
8521             if ( !it.next().getName().equals( "r" ) ) {
8522                 return false;
8523             }
8524             if ( !it.next().getName().equals( "ab" ) ) {
8525                 return false;
8526             }
8527             if ( !it.next().getName().equals( "A" ) ) {
8528                 return false;
8529             }
8530             if ( !it.next().getName().equals( "B" ) ) {
8531                 return false;
8532             }
8533             if ( !it.next().getName().equals( "cd" ) ) {
8534                 return false;
8535             }
8536             if ( !it.next().getName().equals( "C" ) ) {
8537                 return false;
8538             }
8539             if ( !it.next().getName().equals( "D" ) ) {
8540                 return false;
8541             }
8542             if ( it.hasNext() ) {
8543                 return false;
8544             }
8545             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
8546             it = t1.iteratorPreorder();
8547             if ( !it.next().getName().equals( "r" ) ) {
8548                 return false;
8549             }
8550             if ( !it.next().getName().equals( "abcd" ) ) {
8551                 return false;
8552             }
8553             if ( !it.next().getName().equals( "ab" ) ) {
8554                 return false;
8555             }
8556             if ( !it.next().getName().equals( "A" ) ) {
8557                 return false;
8558             }
8559             if ( !it.next().getName().equals( "B" ) ) {
8560                 return false;
8561             }
8562             if ( !it.next().getName().equals( "cd" ) ) {
8563                 return false;
8564             }
8565             if ( !it.next().getName().equals( "C" ) ) {
8566                 return false;
8567             }
8568             if ( !it.next().getName().equals( "D" ) ) {
8569                 return false;
8570             }
8571             if ( !it.next().getName().equals( "efgh" ) ) {
8572                 return false;
8573             }
8574             if ( !it.next().getName().equals( "ef" ) ) {
8575                 return false;
8576             }
8577             if ( !it.next().getName().equals( "E" ) ) {
8578                 return false;
8579             }
8580             if ( !it.next().getName().equals( "F" ) ) {
8581                 return false;
8582             }
8583             if ( !it.next().getName().equals( "gh" ) ) {
8584                 return false;
8585             }
8586             if ( !it.next().getName().equals( "G" ) ) {
8587                 return false;
8588             }
8589             if ( !it.next().getName().equals( "H" ) ) {
8590                 return false;
8591             }
8592             if ( it.hasNext() ) {
8593                 return false;
8594             }
8595         }
8596         catch ( final Exception e ) {
8597             e.printStackTrace( System.out );
8598             return false;
8599         }
8600         return true;
8601     }
8602
8603     private static boolean testPropertiesMap() {
8604         try {
8605             final PropertiesMap pm = new PropertiesMap();
8606             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
8607             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
8608             final Property p2 = new Property( "something:else",
8609                                               "?",
8610                                               "improbable:research",
8611                                               "xsd:decimal",
8612                                               AppliesTo.NODE );
8613             pm.addProperty( p0 );
8614             pm.addProperty( p1 );
8615             pm.addProperty( p2 );
8616             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
8617                 return false;
8618             }
8619             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
8620                 return false;
8621             }
8622             if ( pm.getProperties().size() != 3 ) {
8623                 return false;
8624             }
8625             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
8626                 return false;
8627             }
8628             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
8629                 return false;
8630             }
8631             if ( pm.getProperties().size() != 3 ) {
8632                 return false;
8633             }
8634             pm.removeProperty( "dimensions:diameter" );
8635             if ( pm.getProperties().size() != 2 ) {
8636                 return false;
8637             }
8638             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
8639                 return false;
8640             }
8641             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
8642                 return false;
8643             }
8644         }
8645         catch ( final Exception e ) {
8646             e.printStackTrace( System.out );
8647             return false;
8648         }
8649         return true;
8650     }
8651
8652     private static boolean testProteinId() {
8653         try {
8654             final ProteinId id1 = new ProteinId( "a" );
8655             final ProteinId id2 = new ProteinId( "a" );
8656             final ProteinId id3 = new ProteinId( "A" );
8657             final ProteinId id4 = new ProteinId( "b" );
8658             if ( !id1.equals( id1 ) ) {
8659                 return false;
8660             }
8661             if ( id1.getId().equals( "x" ) ) {
8662                 return false;
8663             }
8664             if ( id1.getId().equals( null ) ) {
8665                 return false;
8666             }
8667             if ( !id1.equals( id2 ) ) {
8668                 return false;
8669             }
8670             if ( id1.equals( id3 ) ) {
8671                 return false;
8672             }
8673             if ( id1.hashCode() != id1.hashCode() ) {
8674                 return false;
8675             }
8676             if ( id1.hashCode() != id2.hashCode() ) {
8677                 return false;
8678             }
8679             if ( id1.hashCode() == id3.hashCode() ) {
8680                 return false;
8681             }
8682             if ( id1.compareTo( id1 ) != 0 ) {
8683                 return false;
8684             }
8685             if ( id1.compareTo( id2 ) != 0 ) {
8686                 return false;
8687             }
8688             if ( id1.compareTo( id3 ) != 0 ) {
8689                 return false;
8690             }
8691             if ( id1.compareTo( id4 ) >= 0 ) {
8692                 return false;
8693             }
8694             if ( id4.compareTo( id1 ) <= 0 ) {
8695                 return false;
8696             }
8697             if ( !id4.getId().equals( "b" ) ) {
8698                 return false;
8699             }
8700             final ProteinId id5 = new ProteinId( " C " );
8701             if ( !id5.getId().equals( "C" ) ) {
8702                 return false;
8703             }
8704             if ( id5.equals( id1 ) ) {
8705                 return false;
8706             }
8707         }
8708         catch ( final Exception e ) {
8709             e.printStackTrace( System.out );
8710             return false;
8711         }
8712         return true;
8713     }
8714
8715     private static boolean testReIdMethods() {
8716         try {
8717             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8718             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
8719             final long count = PhylogenyNode.getNodeCount();
8720             p.levelOrderReID();
8721             if ( p.getNode( "r" ).getId() != count ) {
8722                 return false;
8723             }
8724             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
8725                 return false;
8726             }
8727             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
8728                 return false;
8729             }
8730             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
8731                 return false;
8732             }
8733             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
8734                 return false;
8735             }
8736             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
8737                 return false;
8738             }
8739             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
8740                 return false;
8741             }
8742             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
8743                 return false;
8744             }
8745             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
8746                 return false;
8747             }
8748             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
8749                 return false;
8750             }
8751             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
8752                 return false;
8753             }
8754             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
8755                 return false;
8756             }
8757             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
8758                 return false;
8759             }
8760             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
8761                 return false;
8762             }
8763             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
8764                 return false;
8765             }
8766         }
8767         catch ( final Exception e ) {
8768             e.printStackTrace( System.out );
8769             return false;
8770         }
8771         return true;
8772     }
8773
8774     private static boolean testRerooting() {
8775         try {
8776             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8777             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",
8778                                                  new NHXParser() )[ 0 ];
8779             if ( !t1.isRooted() ) {
8780                 return false;
8781             }
8782             t1.reRoot( t1.getNode( "D" ) );
8783             t1.reRoot( t1.getNode( "CD" ) );
8784             t1.reRoot( t1.getNode( "A" ) );
8785             t1.reRoot( t1.getNode( "B" ) );
8786             t1.reRoot( t1.getNode( "AB" ) );
8787             t1.reRoot( t1.getNode( "D" ) );
8788             t1.reRoot( t1.getNode( "C" ) );
8789             t1.reRoot( t1.getNode( "CD" ) );
8790             t1.reRoot( t1.getNode( "A" ) );
8791             t1.reRoot( t1.getNode( "B" ) );
8792             t1.reRoot( t1.getNode( "AB" ) );
8793             t1.reRoot( t1.getNode( "D" ) );
8794             t1.reRoot( t1.getNode( "D" ) );
8795             t1.reRoot( t1.getNode( "C" ) );
8796             t1.reRoot( t1.getNode( "A" ) );
8797             t1.reRoot( t1.getNode( "B" ) );
8798             t1.reRoot( t1.getNode( "AB" ) );
8799             t1.reRoot( t1.getNode( "C" ) );
8800             t1.reRoot( t1.getNode( "D" ) );
8801             t1.reRoot( t1.getNode( "CD" ) );
8802             t1.reRoot( t1.getNode( "D" ) );
8803             t1.reRoot( t1.getNode( "A" ) );
8804             t1.reRoot( t1.getNode( "B" ) );
8805             t1.reRoot( t1.getNode( "AB" ) );
8806             t1.reRoot( t1.getNode( "C" ) );
8807             t1.reRoot( t1.getNode( "D" ) );
8808             t1.reRoot( t1.getNode( "CD" ) );
8809             t1.reRoot( t1.getNode( "D" ) );
8810             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
8811                 return false;
8812             }
8813             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
8814                 return false;
8815             }
8816             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
8817                 return false;
8818             }
8819             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
8820                 return false;
8821             }
8822             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
8823                 return false;
8824             }
8825             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
8826                 return false;
8827             }
8828             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",
8829                                                  new NHXParser() )[ 0 ];
8830             t2.reRoot( t2.getNode( "A" ) );
8831             t2.reRoot( t2.getNode( "D" ) );
8832             t2.reRoot( t2.getNode( "ABC" ) );
8833             t2.reRoot( t2.getNode( "A" ) );
8834             t2.reRoot( t2.getNode( "B" ) );
8835             t2.reRoot( t2.getNode( "D" ) );
8836             t2.reRoot( t2.getNode( "C" ) );
8837             t2.reRoot( t2.getNode( "ABC" ) );
8838             t2.reRoot( t2.getNode( "A" ) );
8839             t2.reRoot( t2.getNode( "B" ) );
8840             t2.reRoot( t2.getNode( "AB" ) );
8841             t2.reRoot( t2.getNode( "AB" ) );
8842             t2.reRoot( t2.getNode( "D" ) );
8843             t2.reRoot( t2.getNode( "C" ) );
8844             t2.reRoot( t2.getNode( "B" ) );
8845             t2.reRoot( t2.getNode( "AB" ) );
8846             t2.reRoot( t2.getNode( "D" ) );
8847             t2.reRoot( t2.getNode( "D" ) );
8848             t2.reRoot( t2.getNode( "ABC" ) );
8849             t2.reRoot( t2.getNode( "A" ) );
8850             t2.reRoot( t2.getNode( "B" ) );
8851             t2.reRoot( t2.getNode( "AB" ) );
8852             t2.reRoot( t2.getNode( "D" ) );
8853             t2.reRoot( t2.getNode( "C" ) );
8854             t2.reRoot( t2.getNode( "ABC" ) );
8855             t2.reRoot( t2.getNode( "A" ) );
8856             t2.reRoot( t2.getNode( "B" ) );
8857             t2.reRoot( t2.getNode( "AB" ) );
8858             t2.reRoot( t2.getNode( "D" ) );
8859             t2.reRoot( t2.getNode( "D" ) );
8860             t2.reRoot( t2.getNode( "C" ) );
8861             t2.reRoot( t2.getNode( "A" ) );
8862             t2.reRoot( t2.getNode( "B" ) );
8863             t2.reRoot( t2.getNode( "AB" ) );
8864             t2.reRoot( t2.getNode( "C" ) );
8865             t2.reRoot( t2.getNode( "D" ) );
8866             t2.reRoot( t2.getNode( "ABC" ) );
8867             t2.reRoot( t2.getNode( "D" ) );
8868             t2.reRoot( t2.getNode( "A" ) );
8869             t2.reRoot( t2.getNode( "B" ) );
8870             t2.reRoot( t2.getNode( "AB" ) );
8871             t2.reRoot( t2.getNode( "C" ) );
8872             t2.reRoot( t2.getNode( "D" ) );
8873             t2.reRoot( t2.getNode( "ABC" ) );
8874             t2.reRoot( t2.getNode( "D" ) );
8875             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8876                 return false;
8877             }
8878             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8879                 return false;
8880             }
8881             t2.reRoot( t2.getNode( "ABC" ) );
8882             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8883                 return false;
8884             }
8885             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8886                 return false;
8887             }
8888             t2.reRoot( t2.getNode( "AB" ) );
8889             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8890                 return false;
8891             }
8892             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8893                 return false;
8894             }
8895             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8896                 return false;
8897             }
8898             t2.reRoot( t2.getNode( "AB" ) );
8899             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8900                 return false;
8901             }
8902             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8903                 return false;
8904             }
8905             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8906                 return false;
8907             }
8908             t2.reRoot( t2.getNode( "D" ) );
8909             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8910                 return false;
8911             }
8912             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8913                 return false;
8914             }
8915             t2.reRoot( t2.getNode( "ABC" ) );
8916             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
8917                 return false;
8918             }
8919             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
8920                 return false;
8921             }
8922             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
8923                                                  new NHXParser() )[ 0 ];
8924             t3.reRoot( t3.getNode( "B" ) );
8925             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
8926                 return false;
8927             }
8928             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
8929                 return false;
8930             }
8931             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
8932                 return false;
8933             }
8934             t3.reRoot( t3.getNode( "B" ) );
8935             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
8936                 return false;
8937             }
8938             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
8939                 return false;
8940             }
8941             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
8942                 return false;
8943             }
8944             t3.reRoot( t3.getRoot() );
8945             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
8946                 return false;
8947             }
8948             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
8949                 return false;
8950             }
8951             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
8952                 return false;
8953             }
8954         }
8955         catch ( final Exception e ) {
8956             e.printStackTrace( System.out );
8957             return false;
8958         }
8959         return true;
8960     }
8961
8962     private static boolean testSDIse() {
8963         try {
8964             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8965             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
8966             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
8967             gene1.setRooted( true );
8968             species1.setRooted( true );
8969             final SDI sdi = new SDI( gene1, species1 );
8970             if ( !gene1.getRoot().isDuplication() ) {
8971                 return false;
8972             }
8973             final Phylogeny species2 = factory
8974                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
8975                              new NHXParser() )[ 0 ];
8976             final Phylogeny gene2 = factory
8977                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
8978                              new NHXParser() )[ 0 ];
8979             species2.setRooted( true );
8980             gene2.setRooted( true );
8981             final SDI sdi2 = new SDI( gene2, species2 );
8982             if ( sdi2.getDuplicationsSum() != 0 ) {
8983                 return false;
8984             }
8985             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
8986                 return false;
8987             }
8988             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
8989                 return false;
8990             }
8991             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
8992                 return false;
8993             }
8994             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
8995                 return false;
8996             }
8997             if ( !gene2.getNode( "r" ).isSpeciation() ) {
8998                 return false;
8999             }
9000             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
9001                 return false;
9002             }
9003             final Phylogeny species3 = factory
9004                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9005                              new NHXParser() )[ 0 ];
9006             final Phylogeny gene3 = factory
9007                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9008                              new NHXParser() )[ 0 ];
9009             species3.setRooted( true );
9010             gene3.setRooted( true );
9011             final SDI sdi3 = new SDI( gene3, species3 );
9012             if ( sdi3.getDuplicationsSum() != 1 ) {
9013                 return false;
9014             }
9015             if ( !gene3.getNode( "aa" ).isDuplication() ) {
9016                 return false;
9017             }
9018             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
9019                 return false;
9020             }
9021             final Phylogeny species4 = factory
9022                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9023                              new NHXParser() )[ 0 ];
9024             final Phylogeny gene4 = factory
9025                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9026                              new NHXParser() )[ 0 ];
9027             species4.setRooted( true );
9028             gene4.setRooted( true );
9029             final SDI sdi4 = new SDI( gene4, species4 );
9030             if ( sdi4.getDuplicationsSum() != 1 ) {
9031                 return false;
9032             }
9033             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
9034                 return false;
9035             }
9036             if ( !gene4.getNode( "abc" ).isDuplication() ) {
9037                 return false;
9038             }
9039             if ( gene4.getNode( "abcd" ).isDuplication() ) {
9040                 return false;
9041             }
9042             if ( species4.getNumberOfExternalNodes() != 6 ) {
9043                 return false;
9044             }
9045             if ( gene4.getNumberOfExternalNodes() != 6 ) {
9046                 return false;
9047             }
9048             final Phylogeny species5 = factory
9049                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9050                              new NHXParser() )[ 0 ];
9051             final Phylogeny gene5 = factory
9052                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9053                              new NHXParser() )[ 0 ];
9054             species5.setRooted( true );
9055             gene5.setRooted( true );
9056             final SDI sdi5 = new SDI( gene5, species5 );
9057             if ( sdi5.getDuplicationsSum() != 2 ) {
9058                 return false;
9059             }
9060             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
9061                 return false;
9062             }
9063             if ( !gene5.getNode( "adc" ).isDuplication() ) {
9064                 return false;
9065             }
9066             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
9067                 return false;
9068             }
9069             if ( species5.getNumberOfExternalNodes() != 6 ) {
9070                 return false;
9071             }
9072             if ( gene5.getNumberOfExternalNodes() != 6 ) {
9073                 return false;
9074             }
9075             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
9076             // Conjecture for Comparing Molecular Phylogenies"
9077             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
9078             final Phylogeny species6 = factory
9079                     .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,"
9080                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9081                              new NHXParser() )[ 0 ];
9082             final Phylogeny gene6 = factory
9083                     .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,"
9084                                      + "((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,"
9085                                      + "(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;",
9086                              new NHXParser() )[ 0 ];
9087             species6.setRooted( true );
9088             gene6.setRooted( true );
9089             final SDI sdi6 = new SDI( gene6, species6 );
9090             if ( sdi6.getDuplicationsSum() != 3 ) {
9091                 return false;
9092             }
9093             if ( !gene6.getNode( "r" ).isDuplication() ) {
9094                 return false;
9095             }
9096             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
9097                 return false;
9098             }
9099             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
9100                 return false;
9101             }
9102             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
9103                 return false;
9104             }
9105             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
9106                 return false;
9107             }
9108             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
9109                 return false;
9110             }
9111             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
9112                 return false;
9113             }
9114             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
9115                 return false;
9116             }
9117             sdi6.computeMappingCostL();
9118             if ( sdi6.computeMappingCostL() != 17 ) {
9119                 return false;
9120             }
9121             if ( species6.getNumberOfExternalNodes() != 9 ) {
9122                 return false;
9123             }
9124             if ( gene6.getNumberOfExternalNodes() != 9 ) {
9125                 return false;
9126             }
9127             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
9128                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
9129                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
9130                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
9131                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
9132             species7.setRooted( true );
9133             final Phylogeny gene7_1 = Test
9134                     .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])" );
9135             gene7_1.setRooted( true );
9136             final SDI sdi7 = new SDI( gene7_1, species7 );
9137             if ( sdi7.getDuplicationsSum() != 0 ) {
9138                 return false;
9139             }
9140             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
9141                 return false;
9142             }
9143             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
9144                 return false;
9145             }
9146             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
9147                 return false;
9148             }
9149             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
9150                 return false;
9151             }
9152             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
9153                 return false;
9154             }
9155             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
9156                 return false;
9157             }
9158             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
9159                 return false;
9160             }
9161             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
9162                 return false;
9163             }
9164             final Phylogeny gene7_2 = Test
9165                     .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])" );
9166             gene7_2.setRooted( true );
9167             final SDI sdi7_2 = new SDI( gene7_2, species7 );
9168             if ( sdi7_2.getDuplicationsSum() != 1 ) {
9169                 return false;
9170             }
9171             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
9172                 return false;
9173             }
9174             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
9175                 return false;
9176             }
9177             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
9178                 return false;
9179             }
9180             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
9181                 return false;
9182             }
9183             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
9184                 return false;
9185             }
9186             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
9187                 return false;
9188             }
9189             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
9190                 return false;
9191             }
9192             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
9193                 return false;
9194             }
9195             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
9196                 return false;
9197             }
9198         }
9199         catch ( final Exception e ) {
9200             return false;
9201         }
9202         return true;
9203     }
9204
9205     private static boolean testSDIunrooted() {
9206         try {
9207             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9208             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
9209             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
9210             final Iterator<PhylogenyBranch> iter = l.iterator();
9211             PhylogenyBranch br = iter.next();
9212             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
9213                 return false;
9214             }
9215             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
9216                 return false;
9217             }
9218             br = iter.next();
9219             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
9220                 return false;
9221             }
9222             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
9223                 return false;
9224             }
9225             br = iter.next();
9226             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
9227                 return false;
9228             }
9229             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
9230                 return false;
9231             }
9232             br = iter.next();
9233             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9234                 return false;
9235             }
9236             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9237                 return false;
9238             }
9239             br = iter.next();
9240             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9241                 return false;
9242             }
9243             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9244                 return false;
9245             }
9246             br = iter.next();
9247             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
9248                 return false;
9249             }
9250             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
9251                 return false;
9252             }
9253             br = iter.next();
9254             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9255                 return false;
9256             }
9257             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9258                 return false;
9259             }
9260             br = iter.next();
9261             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9262                 return false;
9263             }
9264             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9265                 return false;
9266             }
9267             br = iter.next();
9268             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9269                 return false;
9270             }
9271             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9272                 return false;
9273             }
9274             br = iter.next();
9275             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9276                 return false;
9277             }
9278             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9279                 return false;
9280             }
9281             br = iter.next();
9282             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
9283                 return false;
9284             }
9285             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
9286                 return false;
9287             }
9288             br = iter.next();
9289             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
9290                 return false;
9291             }
9292             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
9293                 return false;
9294             }
9295             br = iter.next();
9296             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
9297                 return false;
9298             }
9299             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
9300                 return false;
9301             }
9302             br = iter.next();
9303             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
9304                 return false;
9305             }
9306             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
9307                 return false;
9308             }
9309             br = iter.next();
9310             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
9311                 return false;
9312             }
9313             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
9314                 return false;
9315             }
9316             if ( iter.hasNext() ) {
9317                 return false;
9318             }
9319             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
9320             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
9321             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
9322             br = iter1.next();
9323             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
9324                 return false;
9325             }
9326             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
9327                 return false;
9328             }
9329             br = iter1.next();
9330             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9331                 return false;
9332             }
9333             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9334                 return false;
9335             }
9336             br = iter1.next();
9337             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9338                 return false;
9339             }
9340             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9341                 return false;
9342             }
9343             if ( iter1.hasNext() ) {
9344                 return false;
9345             }
9346             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
9347             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
9348             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
9349             br = iter2.next();
9350             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
9351                 return false;
9352             }
9353             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
9354                 return false;
9355             }
9356             br = iter2.next();
9357             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9358                 return false;
9359             }
9360             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9361                 return false;
9362             }
9363             br = iter2.next();
9364             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9365                 return false;
9366             }
9367             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9368                 return false;
9369             }
9370             if ( iter2.hasNext() ) {
9371                 return false;
9372             }
9373             final Phylogeny species0 = factory
9374                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9375                              new NHXParser() )[ 0 ];
9376             final Phylogeny gene1 = factory
9377                     .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])",
9378                              new NHXParser() )[ 0 ];
9379             species0.setRooted( true );
9380             gene1.setRooted( true );
9381             final SDIR sdi_unrooted = new SDIR();
9382             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
9383             if ( sdi_unrooted.getCount() != 1 ) {
9384                 return false;
9385             }
9386             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
9387                 return false;
9388             }
9389             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
9390                 return false;
9391             }
9392             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
9393                 return false;
9394             }
9395             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9396                 return false;
9397             }
9398             final Phylogeny gene2 = factory
9399                     .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])",
9400                              new NHXParser() )[ 0 ];
9401             gene2.setRooted( true );
9402             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
9403             if ( sdi_unrooted.getCount() != 1 ) {
9404                 return false;
9405             }
9406             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9407                 return false;
9408             }
9409             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9410                 return false;
9411             }
9412             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
9413                 return false;
9414             }
9415             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9416                 return false;
9417             }
9418             final Phylogeny species6 = factory
9419                     .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,"
9420                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9421                              new NHXParser() )[ 0 ];
9422             final Phylogeny gene6 = factory
9423                     .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],"
9424                                      + "(((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],"
9425                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
9426                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
9427                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
9428                              new NHXParser() )[ 0 ];
9429             species6.setRooted( true );
9430             gene6.setRooted( true );
9431             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
9432             if ( sdi_unrooted.getCount() != 1 ) {
9433                 return false;
9434             }
9435             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9436                 return false;
9437             }
9438             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
9439                 return false;
9440             }
9441             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9442                 return false;
9443             }
9444             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9445                 return false;
9446             }
9447             if ( !p6[ 0 ].getRoot().isDuplication() ) {
9448                 return false;
9449             }
9450             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
9451                 return false;
9452             }
9453             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
9454                 return false;
9455             }
9456             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
9457                 return false;
9458             }
9459             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
9460                 return false;
9461             }
9462             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
9463                 return false;
9464             }
9465             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
9466                 return false;
9467             }
9468             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
9469                 return false;
9470             }
9471             p6 = null;
9472             final Phylogeny species7 = factory
9473                     .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,"
9474                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9475                              new NHXParser() )[ 0 ];
9476             final Phylogeny gene7 = factory
9477                     .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],"
9478                                      + "(((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],"
9479                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
9480                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
9481                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
9482                              new NHXParser() )[ 0 ];
9483             species7.setRooted( true );
9484             gene7.setRooted( true );
9485             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
9486             if ( sdi_unrooted.getCount() != 1 ) {
9487                 return false;
9488             }
9489             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9490                 return false;
9491             }
9492             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
9493                 return false;
9494             }
9495             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9496                 return false;
9497             }
9498             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
9499                 return false;
9500             }
9501             if ( !p7[ 0 ].getRoot().isDuplication() ) {
9502                 return false;
9503             }
9504             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
9505                 return false;
9506             }
9507             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
9508                 return false;
9509             }
9510             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
9511                 return false;
9512             }
9513             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
9514                 return false;
9515             }
9516             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
9517                 return false;
9518             }
9519             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
9520                 return false;
9521             }
9522             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
9523                 return false;
9524             }
9525             p7 = null;
9526             final Phylogeny species8 = factory
9527                     .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,"
9528                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9529                              new NHXParser() )[ 0 ];
9530             final Phylogeny gene8 = factory
9531                     .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],"
9532                                      + "(((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],"
9533                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
9534                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
9535                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
9536                              new NHXParser() )[ 0 ];
9537             species8.setRooted( true );
9538             gene8.setRooted( true );
9539             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
9540             if ( sdi_unrooted.getCount() != 1 ) {
9541                 return false;
9542             }
9543             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9544                 return false;
9545             }
9546             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
9547                 return false;
9548             }
9549             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9550                 return false;
9551             }
9552             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9553                 return false;
9554             }
9555             if ( !p8[ 0 ].getRoot().isDuplication() ) {
9556                 return false;
9557             }
9558             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
9559                 return false;
9560             }
9561             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
9562                 return false;
9563             }
9564             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
9565                 return false;
9566             }
9567             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
9568                 return false;
9569             }
9570             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
9571                 return false;
9572             }
9573             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
9574                 return false;
9575             }
9576             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
9577                 return false;
9578             }
9579             p8 = null;
9580         }
9581         catch ( final Exception e ) {
9582             e.printStackTrace( System.out );
9583             return false;
9584         }
9585         return true;
9586     }
9587
9588     private static boolean testSequenceIdParsing() {
9589         try {
9590             Identifier id = SequenceIdParser.parse( "gb_ADF31344_segmented_worms_" );
9591             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9592                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
9593                 if ( id != null ) {
9594                     System.out.println( "value   =" + id.getValue() );
9595                     System.out.println( "provider=" + id.getProvider() );
9596                 }
9597                 return false;
9598             }
9599             //
9600             id = SequenceIdParser.parse( "segmented worms|gb_ADF31344" );
9601             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9602                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
9603                 if ( id != null ) {
9604                     System.out.println( "value   =" + id.getValue() );
9605                     System.out.println( "provider=" + id.getProvider() );
9606                 }
9607                 return false;
9608             }
9609             //
9610             id = SequenceIdParser.parse( "segmented worms gb_ADF31344 and more" );
9611             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9612                     || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
9613                 if ( id != null ) {
9614                     System.out.println( "value   =" + id.getValue() );
9615                     System.out.println( "provider=" + id.getProvider() );
9616                 }
9617                 return false;
9618             }
9619             // 
9620             id = SequenceIdParser.parse( "gb_AAA96518_1" );
9621             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9622                     || !id.getValue().equals( "AAA96518" ) || !id.getProvider().equals( "ncbi" ) ) {
9623                 if ( id != null ) {
9624                     System.out.println( "value   =" + id.getValue() );
9625                     System.out.println( "provider=" + id.getProvider() );
9626                 }
9627                 return false;
9628             }
9629             // 
9630             id = SequenceIdParser.parse( "gb_EHB07727_1_rodents_" );
9631             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9632                     || !id.getValue().equals( "EHB07727" ) || !id.getProvider().equals( "ncbi" ) ) {
9633                 if ( id != null ) {
9634                     System.out.println( "value   =" + id.getValue() );
9635                     System.out.println( "provider=" + id.getProvider() );
9636                 }
9637                 return false;
9638             }
9639             // 
9640             id = SequenceIdParser.parse( "dbj_BAF37827_1_turtles_" );
9641             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9642                     || !id.getValue().equals( "BAF37827" ) || !id.getProvider().equals( "ncbi" ) ) {
9643                 if ( id != null ) {
9644                     System.out.println( "value   =" + id.getValue() );
9645                     System.out.println( "provider=" + id.getProvider() );
9646                 }
9647                 return false;
9648             }
9649             // 
9650             id = SequenceIdParser.parse( "emb_CAA73223_1_primates_" );
9651             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9652                     || !id.getValue().equals( "CAA73223" ) || !id.getProvider().equals( "ncbi" ) ) {
9653                 if ( id != null ) {
9654                     System.out.println( "value   =" + id.getValue() );
9655                     System.out.println( "provider=" + id.getProvider() );
9656                 }
9657                 return false;
9658             }
9659             // 
9660             id = SequenceIdParser.parse( "mites|ref_XP_002434188_1" );
9661             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9662                     || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
9663                 if ( id != null ) {
9664                     System.out.println( "value   =" + id.getValue() );
9665                     System.out.println( "provider=" + id.getProvider() );
9666                 }
9667                 return false;
9668             }
9669             // 
9670             id = SequenceIdParser.parse( "mites_ref_XP_002434188_1_bla_XP_12345" );
9671             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9672                     || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
9673                 if ( id != null ) {
9674                     System.out.println( "value   =" + id.getValue() );
9675                     System.out.println( "provider=" + id.getProvider() );
9676                 }
9677                 return false;
9678             }
9679             // 
9680             id = SequenceIdParser.parse( "P4A123" );
9681             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9682                     || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
9683                 if ( id != null ) {
9684                     System.out.println( "value   =" + id.getValue() );
9685                     System.out.println( "provider=" + id.getProvider() );
9686                 }
9687                 return false;
9688             }
9689             // 
9690             id = SequenceIdParser.parse( "pllf[pok P4A123_osdjfosnqo035-9233332904i000490 vf tmv x45" );
9691             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9692                     || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
9693                 if ( id != null ) {
9694                     System.out.println( "value   =" + id.getValue() );
9695                     System.out.println( "provider=" + id.getProvider() );
9696                 }
9697                 return false;
9698             }
9699             // 
9700             id = SequenceIdParser.parse( "XP_12345" );
9701             if ( id != null ) {
9702                 System.out.println( "value   =" + id.getValue() );
9703                 System.out.println( "provider=" + id.getProvider() );
9704                 return false;
9705             }
9706             // lcl_91970_unknown_
9707         }
9708         catch ( final Exception e ) {
9709             e.printStackTrace( System.out );
9710             return false;
9711         }
9712         return true;
9713     }
9714
9715     private static boolean testSequenceWriter() {
9716         try {
9717             final String n = ForesterUtil.LINE_SEPARATOR;
9718             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
9719                 return false;
9720             }
9721             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
9722                 return false;
9723             }
9724             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
9725                 return false;
9726             }
9727             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
9728                 return false;
9729             }
9730             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
9731                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
9732                 return false;
9733             }
9734             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
9735                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
9736                 return false;
9737             }
9738         }
9739         catch ( final Exception e ) {
9740             e.printStackTrace();
9741             return false;
9742         }
9743         return true;
9744     }
9745
9746     private static boolean testSpecies() {
9747         try {
9748             final Species s1 = new BasicSpecies( "a" );
9749             final Species s2 = new BasicSpecies( "a" );
9750             final Species s3 = new BasicSpecies( "A" );
9751             final Species s4 = new BasicSpecies( "b" );
9752             if ( !s1.equals( s1 ) ) {
9753                 return false;
9754             }
9755             if ( s1.getSpeciesId().equals( "x" ) ) {
9756                 return false;
9757             }
9758             if ( s1.getSpeciesId().equals( null ) ) {
9759                 return false;
9760             }
9761             if ( !s1.equals( s2 ) ) {
9762                 return false;
9763             }
9764             if ( s1.equals( s3 ) ) {
9765                 return false;
9766             }
9767             if ( s1.hashCode() != s1.hashCode() ) {
9768                 return false;
9769             }
9770             if ( s1.hashCode() != s2.hashCode() ) {
9771                 return false;
9772             }
9773             if ( s1.hashCode() == s3.hashCode() ) {
9774                 return false;
9775             }
9776             if ( s1.compareTo( s1 ) != 0 ) {
9777                 return false;
9778             }
9779             if ( s1.compareTo( s2 ) != 0 ) {
9780                 return false;
9781             }
9782             if ( s1.compareTo( s3 ) != 0 ) {
9783                 return false;
9784             }
9785             if ( s1.compareTo( s4 ) >= 0 ) {
9786                 return false;
9787             }
9788             if ( s4.compareTo( s1 ) <= 0 ) {
9789                 return false;
9790             }
9791             if ( !s4.getSpeciesId().equals( "b" ) ) {
9792                 return false;
9793             }
9794             final Species s5 = new BasicSpecies( " C " );
9795             if ( !s5.getSpeciesId().equals( "C" ) ) {
9796                 return false;
9797             }
9798             if ( s5.equals( s1 ) ) {
9799                 return false;
9800             }
9801         }
9802         catch ( final Exception e ) {
9803             e.printStackTrace( System.out );
9804             return false;
9805         }
9806         return true;
9807     }
9808
9809     private static boolean testSplit() {
9810         try {
9811             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9812             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
9813             //Archaeopteryx.createApplication( p0 );
9814             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
9815             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9816             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9817             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9818             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9819             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9820             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9821             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9822             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
9823             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
9824             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
9825             // System.out.println( s0.toString() );
9826             //
9827             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
9828             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9829             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9830             if ( s0.match( query_nodes ) ) {
9831                 return false;
9832             }
9833             query_nodes = new HashSet<PhylogenyNode>();
9834             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9835             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9836             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9837             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9838             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9839             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9840             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9841             if ( !s0.match( query_nodes ) ) {
9842                 return false;
9843             }
9844             //
9845             query_nodes = new HashSet<PhylogenyNode>();
9846             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9847             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9848             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9849             if ( !s0.match( query_nodes ) ) {
9850                 return false;
9851             }
9852             //
9853             query_nodes = new HashSet<PhylogenyNode>();
9854             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9855             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9856             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9857             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9858             if ( !s0.match( query_nodes ) ) {
9859                 return false;
9860             }
9861             //
9862             query_nodes = new HashSet<PhylogenyNode>();
9863             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9864             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9865             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9866             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9867             if ( !s0.match( query_nodes ) ) {
9868                 return false;
9869             }
9870             //
9871             query_nodes = new HashSet<PhylogenyNode>();
9872             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9873             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9874             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9875             if ( !s0.match( query_nodes ) ) {
9876                 return false;
9877             }
9878             //
9879             query_nodes = new HashSet<PhylogenyNode>();
9880             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9881             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9882             if ( !s0.match( query_nodes ) ) {
9883                 return false;
9884             }
9885             //
9886             query_nodes = new HashSet<PhylogenyNode>();
9887             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9888             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9889             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9890             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9891             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9892             if ( !s0.match( query_nodes ) ) {
9893                 return false;
9894             }
9895             //
9896             query_nodes = new HashSet<PhylogenyNode>();
9897             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9898             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9899             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9900             if ( !s0.match( query_nodes ) ) {
9901                 return false;
9902             }
9903             //
9904             query_nodes = new HashSet<PhylogenyNode>();
9905             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9906             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9907             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9908             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9909             if ( !s0.match( query_nodes ) ) {
9910                 return false;
9911             }
9912             //
9913             query_nodes = new HashSet<PhylogenyNode>();
9914             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9915             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9916             if ( s0.match( query_nodes ) ) {
9917                 return false;
9918             }
9919             //
9920             query_nodes = new HashSet<PhylogenyNode>();
9921             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9922             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9923             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9924             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9925             if ( s0.match( query_nodes ) ) {
9926                 return false;
9927             }
9928             //
9929             query_nodes = new HashSet<PhylogenyNode>();
9930             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9931             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9932             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9933             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9934             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9935             if ( s0.match( query_nodes ) ) {
9936                 return false;
9937             }
9938             //
9939             query_nodes = new HashSet<PhylogenyNode>();
9940             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9941             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9942             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9943             if ( s0.match( query_nodes ) ) {
9944                 return false;
9945             }
9946             //
9947             query_nodes = new HashSet<PhylogenyNode>();
9948             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9949             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9950             if ( s0.match( query_nodes ) ) {
9951                 return false;
9952             }
9953             //
9954             query_nodes = new HashSet<PhylogenyNode>();
9955             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9956             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9957             if ( s0.match( query_nodes ) ) {
9958                 return false;
9959             }
9960             //
9961             query_nodes = new HashSet<PhylogenyNode>();
9962             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9963             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
9964             if ( s0.match( query_nodes ) ) {
9965                 return false;
9966             }
9967             //
9968             query_nodes = new HashSet<PhylogenyNode>();
9969             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9970             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9971             if ( s0.match( query_nodes ) ) {
9972                 return false;
9973             }
9974             //
9975             query_nodes = new HashSet<PhylogenyNode>();
9976             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9977             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9978             if ( s0.match( query_nodes ) ) {
9979                 return false;
9980             }
9981             //
9982             query_nodes = new HashSet<PhylogenyNode>();
9983             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9984             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9985             if ( s0.match( query_nodes ) ) {
9986                 return false;
9987             }
9988             //
9989             query_nodes = new HashSet<PhylogenyNode>();
9990             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9991             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9992             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9993             if ( s0.match( query_nodes ) ) {
9994                 return false;
9995             }
9996             //
9997             query_nodes = new HashSet<PhylogenyNode>();
9998             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9999             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10000             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10001             if ( s0.match( query_nodes ) ) {
10002                 return false;
10003             }
10004             //
10005             query_nodes = new HashSet<PhylogenyNode>();
10006             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10007             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10008             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10009             if ( s0.match( query_nodes ) ) {
10010                 return false;
10011             }
10012             //
10013             query_nodes = new HashSet<PhylogenyNode>();
10014             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10015             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10016             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10017             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10018             if ( s0.match( query_nodes ) ) {
10019                 return false;
10020             }
10021             /////////
10022             //            query_nodes = new HashSet<PhylogenyNode>();
10023             //            query_nodes.add( new PhylogenyNode( "X" ) );
10024             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10025             //            query_nodes.add( new PhylogenyNode( "A" ) );
10026             //            query_nodes.add( new PhylogenyNode( "B" ) );
10027             //            query_nodes.add( new PhylogenyNode( "C" ) );
10028             //            query_nodes.add( new PhylogenyNode( "D" ) );
10029             //            query_nodes.add( new PhylogenyNode( "E" ) );
10030             //            query_nodes.add( new PhylogenyNode( "F" ) );
10031             //            query_nodes.add( new PhylogenyNode( "G" ) );
10032             //            if ( !s0.match( query_nodes ) ) {
10033             //                return false;
10034             //            }
10035             //            query_nodes = new HashSet<PhylogenyNode>();
10036             //            query_nodes.add( new PhylogenyNode( "X" ) );
10037             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10038             //            query_nodes.add( new PhylogenyNode( "A" ) );
10039             //            query_nodes.add( new PhylogenyNode( "B" ) );
10040             //            query_nodes.add( new PhylogenyNode( "C" ) );
10041             //            if ( !s0.match( query_nodes ) ) {
10042             //                return false;
10043             //            }
10044             //            //
10045             //            query_nodes = new HashSet<PhylogenyNode>();
10046             //            query_nodes.add( new PhylogenyNode( "X" ) );
10047             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10048             //            query_nodes.add( new PhylogenyNode( "D" ) );
10049             //            query_nodes.add( new PhylogenyNode( "E" ) );
10050             //            query_nodes.add( new PhylogenyNode( "F" ) );
10051             //            query_nodes.add( new PhylogenyNode( "G" ) );
10052             //            if ( !s0.match( query_nodes ) ) {
10053             //                return false;
10054             //            }
10055             //            //
10056             //            query_nodes = new HashSet<PhylogenyNode>();
10057             //            query_nodes.add( new PhylogenyNode( "X" ) );
10058             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10059             //            query_nodes.add( new PhylogenyNode( "A" ) );
10060             //            query_nodes.add( new PhylogenyNode( "B" ) );
10061             //            query_nodes.add( new PhylogenyNode( "C" ) );
10062             //            query_nodes.add( new PhylogenyNode( "D" ) );
10063             //            if ( !s0.match( query_nodes ) ) {
10064             //                return false;
10065             //            }
10066             //            //
10067             //            query_nodes = new HashSet<PhylogenyNode>();
10068             //            query_nodes.add( new PhylogenyNode( "X" ) );
10069             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10070             //            query_nodes.add( new PhylogenyNode( "E" ) );
10071             //            query_nodes.add( new PhylogenyNode( "F" ) );
10072             //            query_nodes.add( new PhylogenyNode( "G" ) );
10073             //            if ( !s0.match( query_nodes ) ) {
10074             //                return false;
10075             //            }
10076             //            //
10077             //            query_nodes = new HashSet<PhylogenyNode>();
10078             //            query_nodes.add( new PhylogenyNode( "X" ) );
10079             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10080             //            query_nodes.add( new PhylogenyNode( "F" ) );
10081             //            query_nodes.add( new PhylogenyNode( "G" ) );
10082             //            if ( !s0.match( query_nodes ) ) {
10083             //                return false;
10084             //            }
10085             //
10086             query_nodes = new HashSet<PhylogenyNode>();
10087             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10088             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10089             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10090             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10091             if ( s0.match( query_nodes ) ) {
10092                 return false;
10093             }
10094             //
10095             query_nodes = new HashSet<PhylogenyNode>();
10096             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10097             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10098             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10099             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10100             if ( s0.match( query_nodes ) ) {
10101                 return false;
10102             }
10103             ///////////////////////////
10104             //
10105             query_nodes = new HashSet<PhylogenyNode>();
10106             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10107             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10108             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10109             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10110             if ( s0.match( query_nodes ) ) {
10111                 return false;
10112             }
10113             //
10114             query_nodes = new HashSet<PhylogenyNode>();
10115             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10116             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10117             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10118             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10119             if ( s0.match( query_nodes ) ) {
10120                 return false;
10121             }
10122             //
10123             query_nodes = new HashSet<PhylogenyNode>();
10124             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10125             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10126             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10127             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10128             if ( s0.match( query_nodes ) ) {
10129                 return false;
10130             }
10131             //
10132             query_nodes = new HashSet<PhylogenyNode>();
10133             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10134             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10135             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10136             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10137             if ( s0.match( query_nodes ) ) {
10138                 return false;
10139             }
10140             //
10141             query_nodes = new HashSet<PhylogenyNode>();
10142             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10143             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10144             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10145             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10146             if ( s0.match( query_nodes ) ) {
10147                 return false;
10148             }
10149             //
10150             query_nodes = new HashSet<PhylogenyNode>();
10151             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10152             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10153             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10154             if ( s0.match( query_nodes ) ) {
10155                 return false;
10156             }
10157             //
10158             query_nodes = new HashSet<PhylogenyNode>();
10159             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10160             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10161             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10162             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10163             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10164             if ( s0.match( query_nodes ) ) {
10165                 return false;
10166             }
10167             //
10168             query_nodes = new HashSet<PhylogenyNode>();
10169             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10170             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10171             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10172             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10173             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10174             if ( s0.match( query_nodes ) ) {
10175                 return false;
10176             }
10177             //
10178             query_nodes = new HashSet<PhylogenyNode>();
10179             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10180             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10181             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10182             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10183             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10184             if ( s0.match( query_nodes ) ) {
10185                 return false;
10186             }
10187             //
10188             query_nodes = new HashSet<PhylogenyNode>();
10189             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10190             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10191             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10192             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10193             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10194             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10195             if ( s0.match( query_nodes ) ) {
10196                 return false;
10197             }
10198         }
10199         catch ( final Exception e ) {
10200             e.printStackTrace();
10201             return false;
10202         }
10203         return true;
10204     }
10205
10206     private static boolean testSplitStrict() {
10207         try {
10208             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10209             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
10210             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
10211             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10212             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10213             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10214             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10215             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10216             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10217             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10218             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
10219             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
10220             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10221             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10222             if ( s0.match( query_nodes ) ) {
10223                 return false;
10224             }
10225             query_nodes = new HashSet<PhylogenyNode>();
10226             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10227             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10228             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10229             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10230             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10231             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10232             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10233             if ( !s0.match( query_nodes ) ) {
10234                 return false;
10235             }
10236             //
10237             query_nodes = new HashSet<PhylogenyNode>();
10238             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10239             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10240             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10241             if ( !s0.match( query_nodes ) ) {
10242                 return false;
10243             }
10244             //
10245             query_nodes = new HashSet<PhylogenyNode>();
10246             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10247             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10248             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10249             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10250             if ( !s0.match( query_nodes ) ) {
10251                 return false;
10252             }
10253             //
10254             query_nodes = new HashSet<PhylogenyNode>();
10255             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10256             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10257             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10258             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10259             if ( !s0.match( query_nodes ) ) {
10260                 return false;
10261             }
10262             //
10263             query_nodes = new HashSet<PhylogenyNode>();
10264             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10265             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10266             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10267             if ( !s0.match( query_nodes ) ) {
10268                 return false;
10269             }
10270             //
10271             query_nodes = new HashSet<PhylogenyNode>();
10272             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10273             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10274             if ( !s0.match( query_nodes ) ) {
10275                 return false;
10276             }
10277             //
10278             query_nodes = new HashSet<PhylogenyNode>();
10279             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10280             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10281             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10282             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10283             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10284             if ( !s0.match( query_nodes ) ) {
10285                 return false;
10286             }
10287             //
10288             query_nodes = new HashSet<PhylogenyNode>();
10289             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10290             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10291             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10292             if ( !s0.match( query_nodes ) ) {
10293                 return false;
10294             }
10295             //
10296             query_nodes = new HashSet<PhylogenyNode>();
10297             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10298             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10299             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10300             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10301             if ( !s0.match( query_nodes ) ) {
10302                 return false;
10303             }
10304             //
10305             query_nodes = new HashSet<PhylogenyNode>();
10306             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10307             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10308             if ( s0.match( query_nodes ) ) {
10309                 return false;
10310             }
10311             //
10312             query_nodes = new HashSet<PhylogenyNode>();
10313             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10314             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10315             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10316             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10317             if ( s0.match( query_nodes ) ) {
10318                 return false;
10319             }
10320             //
10321             query_nodes = new HashSet<PhylogenyNode>();
10322             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10323             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10324             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10325             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10326             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10327             if ( s0.match( query_nodes ) ) {
10328                 return false;
10329             }
10330             //
10331             query_nodes = new HashSet<PhylogenyNode>();
10332             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10333             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10334             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10335             if ( s0.match( query_nodes ) ) {
10336                 return false;
10337             }
10338             //
10339             query_nodes = new HashSet<PhylogenyNode>();
10340             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10341             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10342             if ( s0.match( query_nodes ) ) {
10343                 return false;
10344             }
10345             //
10346             query_nodes = new HashSet<PhylogenyNode>();
10347             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10348             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10349             if ( s0.match( query_nodes ) ) {
10350                 return false;
10351             }
10352             //
10353             query_nodes = new HashSet<PhylogenyNode>();
10354             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10355             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10356             if ( s0.match( query_nodes ) ) {
10357                 return false;
10358             }
10359             //
10360             query_nodes = new HashSet<PhylogenyNode>();
10361             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10362             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10363             if ( s0.match( query_nodes ) ) {
10364                 return false;
10365             }
10366             //
10367             query_nodes = new HashSet<PhylogenyNode>();
10368             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10369             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10370             if ( s0.match( query_nodes ) ) {
10371                 return false;
10372             }
10373             //
10374             query_nodes = new HashSet<PhylogenyNode>();
10375             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10376             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10377             if ( s0.match( query_nodes ) ) {
10378                 return false;
10379             }
10380             //
10381             query_nodes = new HashSet<PhylogenyNode>();
10382             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10383             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10384             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10385             if ( s0.match( query_nodes ) ) {
10386                 return false;
10387             }
10388             //
10389             query_nodes = new HashSet<PhylogenyNode>();
10390             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10391             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10392             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10393             if ( s0.match( query_nodes ) ) {
10394                 return false;
10395             }
10396             //
10397             query_nodes = new HashSet<PhylogenyNode>();
10398             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10399             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10400             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10401             if ( s0.match( query_nodes ) ) {
10402                 return false;
10403             }
10404             //
10405             query_nodes = new HashSet<PhylogenyNode>();
10406             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10407             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10408             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10409             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10410             if ( s0.match( query_nodes ) ) {
10411                 return false;
10412             }
10413         }
10414         catch ( final Exception e ) {
10415             e.printStackTrace();
10416             return false;
10417         }
10418         return true;
10419     }
10420
10421     private static boolean testSubtreeDeletion() {
10422         try {
10423             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10424             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
10425             t1.deleteSubtree( t1.getNode( "A" ), false );
10426             if ( t1.getNumberOfExternalNodes() != 5 ) {
10427                 return false;
10428             }
10429             t1.toNewHampshireX();
10430             t1.deleteSubtree( t1.getNode( "E" ), false );
10431             if ( t1.getNumberOfExternalNodes() != 4 ) {
10432                 return false;
10433             }
10434             t1.toNewHampshireX();
10435             t1.deleteSubtree( t1.getNode( "F" ), false );
10436             if ( t1.getNumberOfExternalNodes() != 3 ) {
10437                 return false;
10438             }
10439             t1.toNewHampshireX();
10440             t1.deleteSubtree( t1.getNode( "D" ), false );
10441             t1.toNewHampshireX();
10442             if ( t1.getNumberOfExternalNodes() != 3 ) {
10443                 return false;
10444             }
10445             t1.deleteSubtree( t1.getNode( "def" ), false );
10446             t1.toNewHampshireX();
10447             if ( t1.getNumberOfExternalNodes() != 2 ) {
10448                 return false;
10449             }
10450             t1.deleteSubtree( t1.getNode( "B" ), false );
10451             t1.toNewHampshireX();
10452             if ( t1.getNumberOfExternalNodes() != 1 ) {
10453                 return false;
10454             }
10455             t1.deleteSubtree( t1.getNode( "C" ), false );
10456             t1.toNewHampshireX();
10457             if ( t1.getNumberOfExternalNodes() != 1 ) {
10458                 return false;
10459             }
10460             t1.deleteSubtree( t1.getNode( "abc" ), false );
10461             t1.toNewHampshireX();
10462             if ( t1.getNumberOfExternalNodes() != 1 ) {
10463                 return false;
10464             }
10465             t1.deleteSubtree( t1.getNode( "r" ), false );
10466             if ( t1.getNumberOfExternalNodes() != 0 ) {
10467                 return false;
10468             }
10469             if ( !t1.isEmpty() ) {
10470                 return false;
10471             }
10472             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
10473             t2.deleteSubtree( t2.getNode( "A" ), false );
10474             t2.toNewHampshireX();
10475             if ( t2.getNumberOfExternalNodes() != 5 ) {
10476                 return false;
10477             }
10478             t2.deleteSubtree( t2.getNode( "abc" ), false );
10479             t2.toNewHampshireX();
10480             if ( t2.getNumberOfExternalNodes() != 3 ) {
10481                 return false;
10482             }
10483             t2.deleteSubtree( t2.getNode( "def" ), false );
10484             t2.toNewHampshireX();
10485             if ( t2.getNumberOfExternalNodes() != 1 ) {
10486                 return false;
10487             }
10488         }
10489         catch ( final Exception e ) {
10490             e.printStackTrace( System.out );
10491             return false;
10492         }
10493         return true;
10494     }
10495
10496     private static boolean testSupportCount() {
10497         try {
10498             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10499             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
10500             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
10501                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
10502                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
10503                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
10504                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
10505                                                               new NHXParser() );
10506             SupportCount.count( t0_1, phylogenies_1, true, false );
10507             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
10508             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
10509                                                                       + "(((((A,B),C),D),E),((F,G),X))"
10510                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
10511                                                                       + "(((((A,B),C),D),E),(F,G))"
10512                                                                       + "(((((A,B),C),D),E),(F,G))"
10513                                                                       + "(((((A,B),C),D),E),(F,G))"
10514                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
10515                                                                       + "(((((A,B),C),D),E),(F,G))"
10516                                                                       + "((((((A,B),C),D),E),F),G)"
10517                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
10518                                                               new NHXParser() );
10519             SupportCount.count( t0_2, phylogenies_2, true, false );
10520             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
10521             while ( it.hasNext() ) {
10522                 final PhylogenyNode n = it.next();
10523                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
10524                     return false;
10525                 }
10526             }
10527             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
10528             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
10529                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
10530             SupportCount.count( t0_3, phylogenies_3, true, false );
10531             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
10532             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
10533                 return false;
10534             }
10535             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
10536                 return false;
10537             }
10538             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
10539                 return false;
10540             }
10541             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
10542                 return false;
10543             }
10544             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
10545                 return false;
10546             }
10547             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
10548                 return false;
10549             }
10550             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
10551                 return false;
10552             }
10553             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
10554                 return false;
10555             }
10556             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
10557                 return false;
10558             }
10559             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
10560                 return false;
10561             }
10562             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10563             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
10564                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
10565             SupportCount.count( t0_4, phylogenies_4, true, false );
10566             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
10567             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
10568                 return false;
10569             }
10570             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
10571                 return false;
10572             }
10573             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
10574                 return false;
10575             }
10576             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
10577                 return false;
10578             }
10579             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
10580                 return false;
10581             }
10582             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
10583                 return false;
10584             }
10585             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
10586                 return false;
10587             }
10588             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
10589                 return false;
10590             }
10591             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
10592                 return false;
10593             }
10594             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
10595                 return false;
10596             }
10597             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10598             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10599             double d = SupportCount.compare( b1, a, true, true, true );
10600             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
10601                 return false;
10602             }
10603             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10604             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10605             d = SupportCount.compare( b2, a, true, true, true );
10606             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
10607                 return false;
10608             }
10609             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10610             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
10611             d = SupportCount.compare( b3, a, true, true, true );
10612             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
10613                 return false;
10614             }
10615             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
10616             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
10617             d = SupportCount.compare( b4, a, true, true, false );
10618             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
10619                 return false;
10620             }
10621         }
10622         catch ( final Exception e ) {
10623             e.printStackTrace( System.out );
10624             return false;
10625         }
10626         return true;
10627     }
10628
10629     private static boolean testSupportTransfer() {
10630         try {
10631             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10632             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)",
10633                                                  new NHXParser() )[ 0 ];
10634             final Phylogeny p2 = factory
10635                     .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 ];
10636             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
10637                 return false;
10638             }
10639             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
10640                 return false;
10641             }
10642             support_transfer.moveBranchLengthsToBootstrap( p1 );
10643             support_transfer.transferSupportValues( p1, p2 );
10644             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
10645                 return false;
10646             }
10647             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
10648                 return false;
10649             }
10650             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
10651                 return false;
10652             }
10653             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
10654                 return false;
10655             }
10656             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
10657                 return false;
10658             }
10659             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
10660                 return false;
10661             }
10662             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
10663                 return false;
10664             }
10665             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
10666                 return false;
10667             }
10668         }
10669         catch ( final Exception e ) {
10670             e.printStackTrace( System.out );
10671             return false;
10672         }
10673         return true;
10674     }
10675
10676     private static boolean testTaxonomyExtraction() {
10677         try {
10678             final PhylogenyNode n0 = PhylogenyNode
10679                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10680             if ( n0.getNodeData().isHasTaxonomy() ) {
10681                 return false;
10682             }
10683             final PhylogenyNode n1 = PhylogenyNode
10684                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10685             if ( n1.getNodeData().isHasTaxonomy() ) {
10686                 System.out.println( n1.toString() );
10687                 return false;
10688             }
10689             final PhylogenyNode n2x = PhylogenyNode
10690                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10691             if ( n2x.getNodeData().isHasTaxonomy() ) {
10692                 return false;
10693             }
10694             final PhylogenyNode n3 = PhylogenyNode
10695                     .createInstanceFromNhxString( "blag_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10696             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
10697                 System.out.println( n3.toString() );
10698                 return false;
10699             }
10700             final PhylogenyNode n4 = PhylogenyNode
10701                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10702             if ( n4.getNodeData().isHasTaxonomy() ) {
10703                 System.out.println( n4.toString() );
10704                 return false;
10705             }
10706             final PhylogenyNode n5 = PhylogenyNode
10707                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10708             if ( n5.getNodeData().isHasTaxonomy() ) {
10709                 System.out.println( n5.toString() );
10710                 return false;
10711             }
10712             final PhylogenyNode n6 = PhylogenyNode
10713                     .createInstanceFromNhxString( "blag-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10714             if ( n6.getNodeData().isHasTaxonomy() ) {
10715                 System.out.println( n6.toString() );
10716                 return false;
10717             }
10718             final PhylogenyNode n7 = PhylogenyNode
10719                     .createInstanceFromNhxString( "blag-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10720             if ( n7.getNodeData().isHasTaxonomy() ) {
10721                 System.out.println( n7.toString() );
10722                 return false;
10723             }
10724             final PhylogenyNode n8 = PhylogenyNode
10725                     .createInstanceFromNhxString( "blag_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10726             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
10727                 System.out.println( n8.toString() );
10728                 return false;
10729             }
10730             final PhylogenyNode n9 = PhylogenyNode
10731                     .createInstanceFromNhxString( "blag_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10732             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
10733                 System.out.println( n9.toString() );
10734                 return false;
10735             }
10736             final PhylogenyNode n10x = PhylogenyNode
10737                     .createInstanceFromNhxString( "blag_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10738             if ( n10x.getNodeData().isHasTaxonomy() ) {
10739                 System.out.println( n10x.toString() );
10740                 return false;
10741             }
10742             final PhylogenyNode n10xx = PhylogenyNode
10743                     .createInstanceFromNhxString( "blag_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10744             if ( n10xx.getNodeData().isHasTaxonomy() ) {
10745                 System.out.println( n10xx.toString() );
10746                 return false;
10747             }
10748             final PhylogenyNode n10 = PhylogenyNode
10749                     .createInstanceFromNhxString( "blag_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10750             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
10751                 System.out.println( n10.toString() );
10752                 return false;
10753             }
10754             final PhylogenyNode n11 = PhylogenyNode
10755                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
10756             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
10757                 System.out.println( n11.toString() );
10758                 return false;
10759             }
10760             final PhylogenyNode n12 = PhylogenyNode
10761                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
10762                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
10763             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
10764                 System.out.println( n12.toString() );
10765                 return false;
10766             }
10767             final PhylogenyNode n13 = PhylogenyNode
10768                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
10769             if ( n13.getNodeData().isHasTaxonomy() ) {
10770                 System.out.println( n13.toString() );
10771                 return false;
10772             }
10773         }
10774         catch ( final Exception e ) {
10775             e.printStackTrace( System.out );
10776             return false;
10777         }
10778         return true;
10779     }
10780
10781     private static boolean testTreeMethods() {
10782         try {
10783             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10784             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
10785             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
10786             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
10787                 System.out.println( t0.toNewHampshireX() );
10788                 return false;
10789             }
10790             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
10791             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
10792             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
10793                 return false;
10794             }
10795             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
10796                 return false;
10797             }
10798             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
10799                 return false;
10800             }
10801         }
10802         catch ( final Exception e ) {
10803             e.printStackTrace( System.out );
10804             return false;
10805         }
10806         return true;
10807     }
10808
10809     private static boolean testUniprotEntryRetrieval() {
10810         try {
10811             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
10812             if ( !entry.getAccession().equals( "P12345" ) ) {
10813                 return false;
10814             }
10815             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
10816                 return false;
10817             }
10818             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
10819                 return false;
10820             }
10821             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
10822                 return false;
10823             }
10824         }
10825         catch ( final IOException e ) {
10826             System.out.println();
10827             System.out.println( "the following might be due to absence internet connection:" );
10828             e.printStackTrace( System.out );
10829             return true;
10830         }
10831         catch ( final Exception e ) {
10832             return false;
10833         }
10834         return true;
10835     }
10836
10837     private static boolean testUniprotTaxonomySearch() {
10838         try {
10839             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
10840                                                                                                  10 );
10841             if ( results.size() != 1 ) {
10842                 return false;
10843             }
10844             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
10845                 return false;
10846             }
10847             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
10848                 return false;
10849             }
10850             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
10851                 return false;
10852             }
10853             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
10854                 return false;
10855             }
10856             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
10857                 return false;
10858             }
10859             results = null;
10860             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
10861             if ( results.size() != 1 ) {
10862                 return false;
10863             }
10864             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
10865                 return false;
10866             }
10867             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
10868                 return false;
10869             }
10870             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
10871                 return false;
10872             }
10873             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
10874                 return false;
10875             }
10876             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
10877                 return false;
10878             }
10879             results = null;
10880             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
10881             if ( results.size() != 1 ) {
10882                 return false;
10883             }
10884             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
10885                 return false;
10886             }
10887             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
10888                 return false;
10889             }
10890             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
10891                 return false;
10892             }
10893             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
10894                 return false;
10895             }
10896             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
10897                 return false;
10898             }
10899             results = null;
10900             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
10901             if ( results.size() != 1 ) {
10902                 return false;
10903             }
10904             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
10905                 return false;
10906             }
10907             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
10908                 return false;
10909             }
10910             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
10911                 return false;
10912             }
10913             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
10914                 return false;
10915             }
10916             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
10917                 return false;
10918             }
10919             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
10920                 return false;
10921             }
10922             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
10923                 return false;
10924             }
10925             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
10926                     .equals( "Nematostella vectensis" ) ) {
10927                 System.out.println( results.get( 0 ).getLineage() );
10928                 return false;
10929             }
10930             //
10931             results = null;
10932             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
10933             if ( results.size() != 1 ) {
10934                 return false;
10935             }
10936             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
10937                 return false;
10938             }
10939             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
10940                 return false;
10941             }
10942             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
10943                 return false;
10944             }
10945             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
10946                 return false;
10947             }
10948             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
10949                 return false;
10950             }
10951             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
10952                     .equals( "Xenopus tropicalis" ) ) {
10953                 System.out.println( results.get( 0 ).getLineage() );
10954                 return false;
10955             }
10956             //
10957             results = null;
10958             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
10959             if ( results.size() != 1 ) {
10960                 return false;
10961             }
10962             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
10963                 return false;
10964             }
10965             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
10966                 return false;
10967             }
10968             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
10969                 return false;
10970             }
10971             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
10972                 return false;
10973             }
10974             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
10975                 return false;
10976             }
10977             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
10978                     .equals( "Xenopus tropicalis" ) ) {
10979                 System.out.println( results.get( 0 ).getLineage() );
10980                 return false;
10981             }
10982             //
10983             results = null;
10984             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
10985             if ( results.size() != 1 ) {
10986                 return false;
10987             }
10988             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
10989                 return false;
10990             }
10991             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
10992                 return false;
10993             }
10994             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
10995                 return false;
10996             }
10997             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
10998                 return false;
10999             }
11000             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11001                 return false;
11002             }
11003             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11004                     .equals( "Xenopus tropicalis" ) ) {
11005                 System.out.println( results.get( 0 ).getLineage() );
11006                 return false;
11007             }
11008         }
11009         catch ( final IOException e ) {
11010             System.out.println();
11011             System.out.println( "the following might be due to absence internet connection:" );
11012             e.printStackTrace( System.out );
11013             return true;
11014         }
11015         catch ( final Exception e ) {
11016             return false;
11017         }
11018         return true;
11019     }
11020
11021     private static boolean testWabiTxSearch() {
11022         try {
11023             String result = "";
11024             result = TxSearch.searchSimple( "nematostella" );
11025             result = TxSearch.getTxId( "nematostella" );
11026             if ( !result.equals( "45350" ) ) {
11027                 return false;
11028             }
11029             result = TxSearch.getTxName( "45350" );
11030             if ( !result.equals( "Nematostella" ) ) {
11031                 return false;
11032             }
11033             result = TxSearch.getTxId( "nematostella vectensis" );
11034             if ( !result.equals( "45351" ) ) {
11035                 return false;
11036             }
11037             result = TxSearch.getTxName( "45351" );
11038             if ( !result.equals( "Nematostella vectensis" ) ) {
11039                 return false;
11040             }
11041             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
11042             if ( !result.equals( "536089" ) ) {
11043                 return false;
11044             }
11045             result = TxSearch.getTxName( "536089" );
11046             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
11047                 return false;
11048             }
11049             final List<String> queries = new ArrayList<String>();
11050             queries.add( "Campylobacter coli" );
11051             queries.add( "Escherichia coli" );
11052             queries.add( "Arabidopsis" );
11053             queries.add( "Trichoplax" );
11054             queries.add( "Samanea saman" );
11055             queries.add( "Kluyveromyces marxianus" );
11056             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
11057             queries.add( "Bornavirus parrot/PDD/2008" );
11058             final List<RANKS> ranks = new ArrayList<RANKS>();
11059             ranks.add( RANKS.SUPERKINGDOM );
11060             ranks.add( RANKS.KINGDOM );
11061             ranks.add( RANKS.FAMILY );
11062             ranks.add( RANKS.GENUS );
11063             ranks.add( RANKS.TRIBE );
11064             result = TxSearch.searchLineage( queries, ranks );
11065             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
11066             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
11067         }
11068         catch ( final Exception e ) {
11069             System.out.println();
11070             System.out.println( "the following might be due to absence internet connection:" );
11071             e.printStackTrace( System.out );
11072             return false;
11073         }
11074         return true;
11075     }
11076 }