df8fce2b8ee3322549c619e1610830ba630a6096
[jalview.git] / forester / java / src / org / forester / test / Test.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2014 Christian M. Zmasek
6 // Copyright (C) 2014 Sanford-Burnham Medical Research Institute
7 // All rights reserved
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 //
23 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
24
25 package org.forester.test;
26
27 import java.io.ByteArrayInputStream;
28 import java.io.File;
29 import java.io.FileInputStream;
30 import java.io.IOException;
31 import java.io.StringWriter;
32 import java.io.Writer;
33 import java.net.URL;
34 import java.util.ArrayList;
35 import java.util.Date;
36 import java.util.HashSet;
37 import java.util.Iterator;
38 import java.util.List;
39 import java.util.Locale;
40 import java.util.Set;
41 import java.util.SortedSet;
42
43 import org.forester.application.support_transfer;
44 import org.forester.archaeopteryx.TreePanelUtil;
45 import org.forester.archaeopteryx.webservices.WebserviceUtil;
46 import org.forester.development.DevelopmentTools;
47 import org.forester.evoinference.TestPhylogenyReconstruction;
48 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
49 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
50 import org.forester.go.TestGo;
51 import org.forester.io.parsers.FastaParser;
52 import org.forester.io.parsers.GeneralMsaParser;
53 import org.forester.io.parsers.HmmscanPerDomainTableParser;
54 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
55 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
56 import org.forester.io.parsers.nexus.NexusCharactersParser;
57 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
58 import org.forester.io.parsers.nhx.NHXParser;
59 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
60 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
61 import org.forester.io.parsers.tol.TolParser;
62 import org.forester.io.parsers.util.ParserUtils;
63 import org.forester.io.writers.PhylogenyWriter;
64 import org.forester.io.writers.SequenceWriter;
65 import org.forester.msa.BasicMsa;
66 import org.forester.msa.DeleteableMsa;
67 import org.forester.msa.Mafft;
68 import org.forester.msa.Msa;
69 import org.forester.msa.Msa.MSA_FORMAT;
70 import org.forester.msa.MsaInferrer;
71 import org.forester.msa.MsaMethods;
72 import org.forester.pccx.TestPccx;
73 import org.forester.phylogeny.Phylogeny;
74 import org.forester.phylogeny.PhylogenyBranch;
75 import org.forester.phylogeny.PhylogenyMethods;
76 import org.forester.phylogeny.PhylogenyNode;
77 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
78 import org.forester.phylogeny.data.Accession;
79 import org.forester.phylogeny.data.Accession.Source;
80 import org.forester.phylogeny.data.BinaryCharacters;
81 import org.forester.phylogeny.data.BranchWidth;
82 import org.forester.phylogeny.data.Confidence;
83 import org.forester.phylogeny.data.Distribution;
84 import org.forester.phylogeny.data.DomainArchitecture;
85 import org.forester.phylogeny.data.Event;
86 import org.forester.phylogeny.data.Identifier;
87 import org.forester.phylogeny.data.PhylogenyData;
88 import org.forester.phylogeny.data.PhylogenyDataUtil;
89 import org.forester.phylogeny.data.Polygon;
90 import org.forester.phylogeny.data.PropertiesMap;
91 import org.forester.phylogeny.data.Property;
92 import org.forester.phylogeny.data.Property.AppliesTo;
93 import org.forester.phylogeny.data.ProteinDomain;
94 import org.forester.phylogeny.data.Taxonomy;
95 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
96 import org.forester.phylogeny.factories.PhylogenyFactory;
97 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
98 import org.forester.protein.BasicDomain;
99 import org.forester.protein.BasicProtein;
100 import org.forester.protein.Domain;
101 import org.forester.protein.Protein;
102 import org.forester.protein.ProteinId;
103 import org.forester.rio.TestRIO;
104 import org.forester.sdi.SDI;
105 import org.forester.sdi.SDIR;
106 import org.forester.sdi.TestGSDI;
107 import org.forester.sequence.BasicSequence;
108 import org.forester.sequence.Sequence;
109 import org.forester.species.BasicSpecies;
110 import org.forester.species.Species;
111 import org.forester.surfacing.TestSurfacing;
112 import org.forester.tools.ConfidenceAssessor;
113 import org.forester.tools.SupportCount;
114 import org.forester.tools.TreeSplitMatrix;
115 import org.forester.util.AsciiHistogram;
116 import org.forester.util.BasicDescriptiveStatistics;
117 import org.forester.util.BasicTable;
118 import org.forester.util.BasicTableParser;
119 import org.forester.util.DescriptiveStatistics;
120 import org.forester.util.ForesterConstants;
121 import org.forester.util.ForesterUtil;
122 import org.forester.util.GeneralTable;
123 import org.forester.util.SequenceAccessionTools;
124 import org.forester.ws.seqdb.SequenceDatabaseEntry;
125 import org.forester.ws.seqdb.SequenceDbWsTools;
126 import org.forester.ws.seqdb.UniProtTaxonomy;
127 import org.forester.ws.wabi.TxSearch;
128 import org.forester.ws.wabi.TxSearch.RANKS;
129 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
130 import org.forester.ws.wabi.TxSearch.TAX_RANK;
131
132 @SuppressWarnings( "unused")
133 public final class Test {
134
135     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
136                                                                    + ForesterUtil.getFileSeparator() + "resources"
137                                                                    + ForesterUtil.getFileSeparator();
138     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
139                                                                    + ForesterUtil.getFileSeparator() + "test_data"
140                                                                    + ForesterUtil.getFileSeparator();
141     private final static boolean PERFORM_DB_TESTS          = false;
142     private static final boolean PERFORM_WEB_TREE_ACCESS   = true;
143     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
144                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
145                                                                    + ForesterConstants.PHYLO_XML_XSD;
146     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
147                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
148                                                                    + ForesterConstants.PHYLO_XML_XSD;
149     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
150     private final static double  ZERO_DIFF                 = 1.0E-9;
151
152     public static boolean isEqual( final double a, final double b ) {
153         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
154     }
155
156     public static void main( final String[] args ) {
157         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
158         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
159                 + "]" );
160         Locale.setDefault( Locale.US );
161         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
162         int failed = 0;
163         int succeeded = 0;
164         System.out.print( "[Test if directory with files for testing exists/is readable: " );
165         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
166             System.out.println( "OK.]" );
167         }
168         else {
169             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
170             System.out.println( "Testing aborted." );
171             System.exit( -1 );
172         }
173         System.out.print( "[Test if resources directory exists/is readable: " );
174         if ( testDir( PATH_TO_RESOURCES ) ) {
175             System.out.println( "OK.]" );
176         }
177         else {
178             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
179             System.out.println( "Testing aborted." );
180             System.exit( -1 );
181         }
182         final long start_time = new Date().getTime();
183         System.out.print( "Basic node methods: " );
184         if ( Test.testBasicNodeMethods() ) {
185             System.out.println( "OK." );
186             succeeded++;
187         }
188         else {
189             System.out.println( "failed." );
190             failed++;
191         }
192         System.out.print( "Protein id: " );
193         if ( !testProteinId() ) {
194             System.out.println( "failed." );
195             failed++;
196         }
197         else {
198             succeeded++;
199         }
200         System.out.println( "OK." );
201         System.out.print( "Species: " );
202         if ( !testSpecies() ) {
203             System.out.println( "failed." );
204             failed++;
205         }
206         else {
207             succeeded++;
208         }
209         System.out.println( "OK." );
210         System.out.print( "Basic domain: " );
211         if ( !testBasicDomain() ) {
212             System.out.println( "failed." );
213             failed++;
214         }
215         else {
216             succeeded++;
217         }
218         System.out.println( "OK." );
219         System.out.print( "Basic protein: " );
220         if ( !testBasicProtein() ) {
221             System.out.println( "failed." );
222             failed++;
223         }
224         else {
225             succeeded++;
226         }
227         System.out.println( "OK." );
228         System.out.print( "Sequence writer: " );
229         if ( testSequenceWriter() ) {
230             System.out.println( "OK." );
231             succeeded++;
232         }
233         else {
234             System.out.println( "failed." );
235             failed++;
236         }
237         System.out.print( "Sequence id parsing: " );
238         if ( testSequenceIdParsing() ) {
239             System.out.println( "OK." );
240             succeeded++;
241         }
242         else {
243             System.out.println( "failed." );
244             failed++;
245         }
246         System.out.print( "UniProtKB id extraction: " );
247         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
248             System.out.println( "OK." );
249             succeeded++;
250         }
251         else {
252             System.out.println( "failed." );
253             failed++;
254         }
255         System.out.print( "Sequence DB tools 1: " );
256         if ( testSequenceDbWsTools1() ) {
257             System.out.println( "OK." );
258             succeeded++;
259         }
260         else {
261             System.out.println( "failed." );
262             failed++;
263         }
264         System.out.print( "Hmmscan output parser: " );
265         if ( testHmmscanOutputParser() ) {
266             System.out.println( "OK." );
267             succeeded++;
268         }
269         else {
270             System.out.println( "failed." );
271             failed++;
272         }
273         System.out.print( "Overlap removal: " );
274         if ( !org.forester.test.Test.testOverlapRemoval() ) {
275             System.out.println( "failed." );
276             failed++;
277         }
278         else {
279             succeeded++;
280         }
281         System.out.println( "OK." );
282         System.out.print( "Engulfing overlap removal: " );
283         if ( !Test.testEngulfingOverlapRemoval() ) {
284             System.out.println( "failed." );
285             failed++;
286         }
287         else {
288             succeeded++;
289         }
290         System.out.println( "OK." );
291         System.out.print( "Taxonomy code extraction: " );
292         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
293             System.out.println( "OK." );
294             succeeded++;
295         }
296         else {
297             System.out.println( "failed." );
298             failed++;
299         }
300         System.out.print( "SN extraction: " );
301         if ( Test.testExtractSNFromNodeName() ) {
302             System.out.println( "OK." );
303             succeeded++;
304         }
305         else {
306             System.out.println( "failed." );
307             failed++;
308         }
309         System.out.print( "Taxonomy extraction (general): " );
310         if ( Test.testTaxonomyExtraction() ) {
311             System.out.println( "OK." );
312             succeeded++;
313         }
314         else {
315             System.out.println( "failed." );
316             failed++;
317         }
318         System.out.print( "Uri for Aptx web sequence accession: " );
319         if ( Test.testCreateUriForSeqWeb() ) {
320             System.out.println( "OK." );
321             succeeded++;
322         }
323         else {
324             System.out.println( "failed." );
325             failed++;
326         }
327         System.out.print( "Basic node construction and parsing of NHX (node level): " );
328         if ( Test.testNHXNodeParsing() ) {
329             System.out.println( "OK." );
330             succeeded++;
331         }
332         else {
333             System.out.println( "failed." );
334             failed++;
335         }
336         System.out.print( "NHX parsing iterating: " );
337         if ( Test.testNHParsingIter() ) {
338             System.out.println( "OK." );
339             succeeded++;
340         }
341         else {
342             System.out.println( "failed." );
343             failed++;
344         }
345         System.out.print( "NH parsing: " );
346         if ( Test.testNHParsing() ) {
347             System.out.println( "OK." );
348             succeeded++;
349         }
350         else {
351             System.out.println( "failed." );
352             failed++;
353         }
354         System.out.print( "Conversion to NHX (node level): " );
355         if ( Test.testNHXconversion() ) {
356             System.out.println( "OK." );
357             succeeded++;
358         }
359         else {
360             System.out.println( "failed." );
361             failed++;
362         }
363         System.out.print( "NHX parsing: " );
364         if ( Test.testNHXParsing() ) {
365             System.out.println( "OK." );
366             succeeded++;
367         }
368         else {
369             System.out.println( "failed." );
370             failed++;
371         }
372         System.out.print( "NHX parsing with quotes: " );
373         if ( Test.testNHXParsingQuotes() ) {
374             System.out.println( "OK." );
375             succeeded++;
376         }
377         else {
378             System.out.println( "failed." );
379             failed++;
380         }
381         System.out.print( "NHX parsing (MrBayes): " );
382         if ( Test.testNHXParsingMB() ) {
383             System.out.println( "OK." );
384             succeeded++;
385         }
386         else {
387             System.out.println( "failed." );
388             failed++;
389         }
390         System.out.print( "Nexus characters parsing: " );
391         if ( Test.testNexusCharactersParsing() ) {
392             System.out.println( "OK." );
393             succeeded++;
394         }
395         else {
396             System.out.println( "failed." );
397             failed++;
398         }
399         System.out.print( "Nexus tree parsing iterating: " );
400         if ( Test.testNexusTreeParsingIterating() ) {
401             System.out.println( "OK." );
402             succeeded++;
403         }
404         else {
405             System.out.println( "failed." );
406             failed++;
407         }
408         System.out.print( "Nexus tree parsing: " );
409         if ( Test.testNexusTreeParsing() ) {
410             System.out.println( "OK." );
411             succeeded++;
412         }
413         else {
414             System.out.println( "failed." );
415             failed++;
416         }
417         System.out.print( "Nexus tree parsing (translating): " );
418         if ( Test.testNexusTreeParsingTranslating() ) {
419             System.out.println( "OK." );
420             succeeded++;
421         }
422         else {
423             System.out.println( "failed." );
424             failed++;
425         }
426         System.out.print( "Nexus matrix parsing: " );
427         if ( Test.testNexusMatrixParsing() ) {
428             System.out.println( "OK." );
429             succeeded++;
430         }
431         else {
432             System.out.println( "failed." );
433             failed++;
434         }
435         System.out.print( "Basic phyloXML parsing: " );
436         if ( Test.testBasicPhyloXMLparsing() ) {
437             System.out.println( "OK." );
438             succeeded++;
439         }
440         else {
441             System.out.println( "failed." );
442             failed++;
443         }
444         System.out.print( "Basic phyloXML parsing (validating against schema): " );
445         if ( testBasicPhyloXMLparsingValidating() ) {
446             System.out.println( "OK." );
447             succeeded++;
448         }
449         else {
450             System.out.println( "failed." );
451             failed++;
452         }
453         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
454         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
455             System.out.println( "OK." );
456             succeeded++;
457         }
458         else {
459             System.out.println( "failed." );
460             failed++;
461         }
462         System.out.print( "phyloXML Distribution Element: " );
463         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
464             System.out.println( "OK." );
465             succeeded++;
466         }
467         else {
468             System.out.println( "failed." );
469             failed++;
470         }
471         System.out.print( "Tol XML parsing: " );
472         if ( Test.testBasicTolXMLparsing() ) {
473             System.out.println( "OK." );
474             succeeded++;
475         }
476         else {
477             System.out.println( "failed." );
478             failed++;
479         }
480         System.out.print( "Copying of node data: " );
481         if ( Test.testCopyOfNodeData() ) {
482             System.out.println( "OK." );
483             succeeded++;
484         }
485         else {
486             System.out.println( "failed." );
487             failed++;
488         }
489         System.out.print( "Tree copy: " );
490         if ( Test.testTreeCopy() ) {
491             System.out.println( "OK." );
492             succeeded++;
493         }
494         else {
495             System.out.println( "failed." );
496             failed++;
497         }
498         System.out.print( "Basic tree methods: " );
499         if ( Test.testBasicTreeMethods() ) {
500             System.out.println( "OK." );
501             succeeded++;
502         }
503         else {
504             System.out.println( "failed." );
505             failed++;
506         }
507         System.out.print( "Tree methods: " );
508         if ( Test.testTreeMethods() ) {
509             System.out.println( "OK." );
510             succeeded++;
511         }
512         else {
513             System.out.println( "failed." );
514             failed++;
515         }
516         System.out.print( "Postorder Iterator: " );
517         if ( Test.testPostOrderIterator() ) {
518             System.out.println( "OK." );
519             succeeded++;
520         }
521         else {
522             System.out.println( "failed." );
523             failed++;
524         }
525         System.out.print( "Preorder Iterator: " );
526         if ( Test.testPreOrderIterator() ) {
527             System.out.println( "OK." );
528             succeeded++;
529         }
530         else {
531             System.out.println( "failed." );
532             failed++;
533         }
534         System.out.print( "Levelorder Iterator: " );
535         if ( Test.testLevelOrderIterator() ) {
536             System.out.println( "OK." );
537             succeeded++;
538         }
539         else {
540             System.out.println( "failed." );
541             failed++;
542         }
543         System.out.print( "Re-id methods: " );
544         if ( Test.testReIdMethods() ) {
545             System.out.println( "OK." );
546             succeeded++;
547         }
548         else {
549             System.out.println( "failed." );
550             failed++;
551         }
552         System.out.print( "Methods on last external nodes: " );
553         if ( Test.testLastExternalNodeMethods() ) {
554             System.out.println( "OK." );
555             succeeded++;
556         }
557         else {
558             System.out.println( "failed." );
559             failed++;
560         }
561         System.out.print( "Methods on external nodes: " );
562         if ( Test.testExternalNodeRelatedMethods() ) {
563             System.out.println( "OK." );
564             succeeded++;
565         }
566         else {
567             System.out.println( "failed." );
568             failed++;
569         }
570         System.out.print( "Deletion of external nodes: " );
571         if ( Test.testDeletionOfExternalNodes() ) {
572             System.out.println( "OK." );
573             succeeded++;
574         }
575         else {
576             System.out.println( "failed." );
577             failed++;
578         }
579         System.out.print( "Subtree deletion: " );
580         if ( Test.testSubtreeDeletion() ) {
581             System.out.println( "OK." );
582             succeeded++;
583         }
584         else {
585             System.out.println( "failed." );
586             failed++;
587         }
588         System.out.print( "Phylogeny branch: " );
589         if ( Test.testPhylogenyBranch() ) {
590             System.out.println( "OK." );
591             succeeded++;
592         }
593         else {
594             System.out.println( "failed." );
595             failed++;
596         }
597         System.out.print( "Rerooting: " );
598         if ( Test.testRerooting() ) {
599             System.out.println( "OK." );
600             succeeded++;
601         }
602         else {
603             System.out.println( "failed." );
604             failed++;
605         }
606         System.out.print( "Mipoint rooting: " );
607         if ( Test.testMidpointrooting() ) {
608             System.out.println( "OK." );
609             succeeded++;
610         }
611         else {
612             System.out.println( "failed." );
613             failed++;
614         }
615         System.out.print( "Node removal: " );
616         if ( Test.testNodeRemoval() ) {
617             System.out.println( "OK." );
618             succeeded++;
619         }
620         else {
621             System.out.println( "failed." );
622             failed++;
623         }
624         System.out.print( "Support count: " );
625         if ( Test.testSupportCount() ) {
626             System.out.println( "OK." );
627             succeeded++;
628         }
629         else {
630             System.out.println( "failed." );
631             failed++;
632         }
633         System.out.print( "Support transfer: " );
634         if ( Test.testSupportTransfer() ) {
635             System.out.println( "OK." );
636             succeeded++;
637         }
638         else {
639             System.out.println( "failed." );
640             failed++;
641         }
642         System.out.print( "Finding of LCA: " );
643         if ( Test.testGetLCA() ) {
644             System.out.println( "OK." );
645             succeeded++;
646         }
647         else {
648             System.out.println( "failed." );
649             failed++;
650         }
651         System.out.print( "Finding of LCA 2: " );
652         if ( Test.testGetLCA2() ) {
653             System.out.println( "OK." );
654             succeeded++;
655         }
656         else {
657             System.out.println( "failed." );
658             failed++;
659         }
660         System.out.print( "Calculation of distance between nodes: " );
661         if ( Test.testGetDistance() ) {
662             System.out.println( "OK." );
663             succeeded++;
664         }
665         else {
666             System.out.println( "failed." );
667             failed++;
668         }
669         System.out.print( "Descriptive statistics: " );
670         if ( Test.testDescriptiveStatistics() ) {
671             System.out.println( "OK." );
672             succeeded++;
673         }
674         else {
675             System.out.println( "failed." );
676             failed++;
677         }
678         System.out.print( "Data objects and methods: " );
679         if ( Test.testDataObjects() ) {
680             System.out.println( "OK." );
681             succeeded++;
682         }
683         else {
684             System.out.println( "failed." );
685             failed++;
686         }
687         System.out.print( "Properties map: " );
688         if ( Test.testPropertiesMap() ) {
689             System.out.println( "OK." );
690             succeeded++;
691         }
692         else {
693             System.out.println( "failed." );
694             failed++;
695         }
696         System.out.print( "SDIse: " );
697         if ( Test.testSDIse() ) {
698             System.out.println( "OK." );
699             succeeded++;
700         }
701         else {
702             System.out.println( "failed." );
703             failed++;
704         }
705         System.out.print( "SDIunrooted: " );
706         if ( Test.testSDIunrooted() ) {
707             System.out.println( "OK." );
708             succeeded++;
709         }
710         else {
711             System.out.println( "failed." );
712             failed++;
713         }
714         System.out.print( "GSDI: " );
715         if ( TestGSDI.test() ) {
716             System.out.println( "OK." );
717             succeeded++;
718         }
719         else {
720             System.out.println( "failed." );
721             failed++;
722         }
723         System.out.print( "RIO: " );
724         if ( TestRIO.test() ) {
725             System.out.println( "OK." );
726             succeeded++;
727         }
728         else {
729             System.out.println( "failed." );
730             failed++;
731         }
732         System.out.print( "Phylogeny reconstruction:" );
733         System.out.println();
734         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
735             System.out.println( "OK." );
736             succeeded++;
737         }
738         else {
739             System.out.println( "failed." );
740             failed++;
741         }
742         System.out.print( "Analysis of domain architectures: " );
743         System.out.println();
744         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
745             System.out.println( "OK." );
746             succeeded++;
747         }
748         else {
749             System.out.println( "failed." );
750             failed++;
751         }
752         System.out.print( "GO: " );
753         System.out.println();
754         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
755             System.out.println( "OK." );
756             succeeded++;
757         }
758         else {
759             System.out.println( "failed." );
760             failed++;
761         }
762         System.out.print( "Modeling tools: " );
763         if ( TestPccx.test() ) {
764             System.out.println( "OK." );
765             succeeded++;
766         }
767         else {
768             System.out.println( "failed." );
769             failed++;
770         }
771         System.out.print( "Split Matrix strict: " );
772         if ( Test.testSplitStrict() ) {
773             System.out.println( "OK." );
774             succeeded++;
775         }
776         else {
777             System.out.println( "failed." );
778             failed++;
779         }
780         System.out.print( "Split Matrix: " );
781         if ( Test.testSplit() ) {
782             System.out.println( "OK." );
783             succeeded++;
784         }
785         else {
786             System.out.println( "failed." );
787             failed++;
788         }
789         System.out.print( "Confidence Assessor: " );
790         if ( Test.testConfidenceAssessor() ) {
791             System.out.println( "OK." );
792             succeeded++;
793         }
794         else {
795             System.out.println( "failed." );
796             failed++;
797         }
798         System.out.print( "Basic table: " );
799         if ( Test.testBasicTable() ) {
800             System.out.println( "OK." );
801             succeeded++;
802         }
803         else {
804             System.out.println( "failed." );
805             failed++;
806         }
807         System.out.print( "General table: " );
808         if ( Test.testGeneralTable() ) {
809             System.out.println( "OK." );
810             succeeded++;
811         }
812         else {
813             System.out.println( "failed." );
814             failed++;
815         }
816         System.out.print( "Amino acid sequence: " );
817         if ( Test.testAminoAcidSequence() ) {
818             System.out.println( "OK." );
819             succeeded++;
820         }
821         else {
822             System.out.println( "failed." );
823             failed++;
824         }
825         System.out.print( "General MSA parser: " );
826         if ( Test.testGeneralMsaParser() ) {
827             System.out.println( "OK." );
828             succeeded++;
829         }
830         else {
831             System.out.println( "failed." );
832             failed++;
833         }
834         System.out.print( "Fasta parser for msa: " );
835         if ( Test.testFastaParser() ) {
836             System.out.println( "OK." );
837             succeeded++;
838         }
839         else {
840             System.out.println( "failed." );
841             failed++;
842         }
843         System.out.print( "Creation of balanced phylogeny: " );
844         if ( Test.testCreateBalancedPhylogeny() ) {
845             System.out.println( "OK." );
846             succeeded++;
847         }
848         else {
849             System.out.println( "failed." );
850             failed++;
851         }
852         System.out.print( "Genbank accessor parsing: " );
853         if ( Test.testGenbankAccessorParsing() ) {
854             System.out.println( "OK." );
855             succeeded++;
856         }
857         else {
858             System.out.println( "failed." );
859             failed++;
860         }
861         String path = "";
862         final String os = ForesterUtil.OS_NAME.toLowerCase();
863         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
864             path = "/usr/local/bin/mafft";
865         }
866         else if ( os.indexOf( "win" ) >= 0 ) {
867             path = "C:\\Program Files\\mafft-win\\mafft.bat";
868         }
869         else {
870             path = "mafft";
871             if ( !MsaInferrer.isInstalled( path ) ) {
872                 path = "/usr/bin/mafft";
873             }
874             if ( !MsaInferrer.isInstalled( path ) ) {
875                 path = "/usr/local/bin/mafft";
876             }
877         }
878         if ( MsaInferrer.isInstalled( path ) ) {
879             System.out.print( "MAFFT (external program): " );
880             if ( Test.testMafft( path ) ) {
881                 System.out.println( "OK." );
882                 succeeded++;
883             }
884             else {
885                 System.out.println( "failed [will not count towards failed tests]" );
886             }
887         }
888         System.out.print( "Next nodes with collapsed: " );
889         if ( Test.testNextNodeWithCollapsing() ) {
890             System.out.println( "OK." );
891             succeeded++;
892         }
893         else {
894             System.out.println( "failed." );
895             failed++;
896         }
897         System.out.print( "Simple MSA quality: " );
898         if ( Test.testMsaQualityMethod() ) {
899             System.out.println( "OK." );
900             succeeded++;
901         }
902         else {
903             System.out.println( "failed." );
904             failed++;
905         }
906         System.out.print( "Deleteable MSA: " );
907         if ( Test.testDeleteableMsa() ) {
908             System.out.println( "OK." );
909             succeeded++;
910         }
911         else {
912             System.out.println( "failed." );
913             failed++;
914         }
915         if ( PERFORM_DB_TESTS ) {
916             System.out.print( "Uniprot Entry Retrieval: " );
917             if ( Test.testUniprotEntryRetrieval() ) {
918                 System.out.println( "OK." );
919                 succeeded++;
920             }
921             else {
922                 System.out.println( "failed." );
923                 failed++;
924             }
925             System.out.print( "Ebi Entry Retrieval: " );
926             if ( Test.testEbiEntryRetrieval() ) {
927                 System.out.println( "OK." );
928                 succeeded++;
929             }
930             else {
931                 System.out.println( "failed." );
932                 failed++;
933             }
934             System.out.print( "Sequence DB tools 2: " );
935             if ( testSequenceDbWsTools2() ) {
936                 System.out.println( "OK." );
937                 succeeded++;
938             }
939             else {
940                 System.out.println( "failed." );
941                 failed++;
942                 System.exit( -1 );
943             }
944             System.out.print( "Uniprot Taxonomy Search: " );
945             if ( Test.testUniprotTaxonomySearch() ) {
946                 System.out.println( "OK." );
947                 succeeded++;
948             }
949             else {
950                 System.out.println( "failed." );
951                 failed++;
952             }
953         }
954         if ( PERFORM_WEB_TREE_ACCESS ) {
955             System.out.print( "NHX parsing from URL: " );
956             if ( Test.testNHXparsingFromURL() ) {
957                 System.out.println( "OK." );
958                 succeeded++;
959             }
960             else {
961                 System.out.println( "failed." );
962                 failed++;
963             }
964             System.out.print( "phyloXML parsing from URL: " );
965             if ( Test.testPhyloXMLparsingFromURL() ) {
966                 System.out.println( "OK." );
967                 succeeded++;
968             }
969             else {
970                 System.out.println( "failed." );
971                 failed++;
972             }
973             System.out.print( "TreeBase acccess: " );
974             if ( Test.testTreeBaseReading() ) {
975                 System.out.println( "OK." );
976                 succeeded++;
977             }
978             else {
979                 System.out.println( "failed." );
980                 failed++;
981             }
982             //
983             System.out.print( "ToL access: " );
984             if ( Test.testToLReading() ) {
985                 System.out.println( "OK." );
986                 succeeded++;
987             }
988             else {
989                 System.out.println( "failed." );
990                 failed++;
991             }
992             //
993             System.out.print( "TreeFam access: " );
994             if ( Test.testTreeFamReading() ) {
995                 System.out.println( "OK." );
996                 succeeded++;
997             }
998             else {
999                 System.out.println( "failed." );
1000                 failed++;
1001             }
1002             //
1003             //
1004             System.out.print( "Pfam tree access: " );
1005             if ( Test.testPfamTreeReading() ) {
1006                 System.out.println( "OK." );
1007                 succeeded++;
1008             }
1009             else {
1010                 System.out.println( "failed." );
1011                 failed++;
1012             }
1013         }
1014         System.out.println();
1015         final Runtime rt = java.lang.Runtime.getRuntime();
1016         final long free_memory = rt.freeMemory() / 1000000;
1017         final long total_memory = rt.totalMemory() / 1000000;
1018         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1019                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1020         System.out.println();
1021         System.out.println( "Successful tests: " + succeeded );
1022         System.out.println( "Failed     tests: " + failed );
1023         System.out.println();
1024         if ( failed < 1 ) {
1025             System.out.println( "OK." );
1026         }
1027         else {
1028             System.out.println( "Not OK." );
1029         }
1030     }
1031
1032     public static boolean testEngulfingOverlapRemoval() {
1033         try {
1034             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1035             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1036             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1037             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1038             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1039             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1040             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1041             final List<Boolean> covered = new ArrayList<Boolean>();
1042             covered.add( true ); // 0
1043             covered.add( false ); // 1
1044             covered.add( true ); // 2
1045             covered.add( false ); // 3
1046             covered.add( true ); // 4
1047             covered.add( true ); // 5
1048             covered.add( false ); // 6
1049             covered.add( true ); // 7
1050             covered.add( true ); // 8
1051             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1052                 return false;
1053             }
1054             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1055                 return false;
1056             }
1057             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1058                 return false;
1059             }
1060             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1061                 return false;
1062             }
1063             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1064                 return false;
1065             }
1066             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1067                 return false;
1068             }
1069             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1070                 return false;
1071             }
1072             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1073             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1074             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1075             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1076             abc.addProteinDomain( a );
1077             abc.addProteinDomain( b );
1078             abc.addProteinDomain( c );
1079             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1080             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1081             if ( abc.getNumberOfProteinDomains() != 3 ) {
1082                 return false;
1083             }
1084             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1085                 return false;
1086             }
1087             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1088                 return false;
1089             }
1090             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1091                 return false;
1092             }
1093             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1094                 return false;
1095             }
1096             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1097             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1098             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1099             final Protein def = new BasicProtein( "def", "nemve", 0 );
1100             def.addProteinDomain( d );
1101             def.addProteinDomain( e );
1102             def.addProteinDomain( f );
1103             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1104             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1105             if ( def.getNumberOfProteinDomains() != 3 ) {
1106                 return false;
1107             }
1108             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1109                 return false;
1110             }
1111             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1112                 return false;
1113             }
1114             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1115                 return false;
1116             }
1117             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1118                 return false;
1119             }
1120             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1121                 return false;
1122             }
1123         }
1124         catch ( final Exception e ) {
1125             e.printStackTrace( System.out );
1126             return false;
1127         }
1128         return true;
1129     }
1130
1131     public static final boolean testNHXparsingFromURL() {
1132         try {
1133             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1134             final URL u = new URL( s );
1135             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1136             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1137             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1138                 return false;
1139             }
1140             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1141                 System.out.println( phys[ 0 ].toNewHampshire() );
1142                 return false;
1143             }
1144             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1145                 System.out.println( phys[ 1 ].toNewHampshire() );
1146                 return false;
1147             }
1148             final Phylogeny[] phys2 = factory.create( u.openStream(), new NHXParser() );
1149             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1150                 return false;
1151             }
1152             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1153                 System.out.println( phys2[ 0 ].toNewHampshire() );
1154                 return false;
1155             }
1156             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1157             final NHXParser p = new NHXParser();
1158             final URL u2 = new URL( s );
1159             p.setSource( u2 );
1160             if ( !p.hasNext() ) {
1161                 return false;
1162             }
1163             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1164                 return false;
1165             }
1166             if ( !p.hasNext() ) {
1167                 return false;
1168             }
1169             p.reset();
1170             if ( !p.hasNext() ) {
1171                 return false;
1172             }
1173             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1174                 return false;
1175             }
1176             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1177                 return false;
1178             }
1179             p.reset();
1180             if ( !p.hasNext() ) {
1181                 return false;
1182             }
1183             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1184                 return false;
1185             }
1186             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1187                 return false;
1188             }
1189         }
1190         catch ( final Exception e ) {
1191             e.printStackTrace();
1192         }
1193         return true;
1194     }
1195
1196     public static boolean testOverlapRemoval() {
1197         try {
1198             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1199             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1200             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1201             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1202             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1203             final List<Boolean> covered = new ArrayList<Boolean>();
1204             covered.add( true ); // 0
1205             covered.add( false ); // 1
1206             covered.add( true ); // 2
1207             covered.add( false ); // 3
1208             covered.add( true ); // 4
1209             covered.add( true ); // 5
1210             covered.add( false ); // 6
1211             covered.add( true ); // 7
1212             covered.add( true ); // 8
1213             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1214                 return false;
1215             }
1216             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1217                 return false;
1218             }
1219             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1220                 return false;
1221             }
1222             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1223                 return false;
1224             }
1225             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1226                 return false;
1227             }
1228             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1229             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1230             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1231             ab.addProteinDomain( a );
1232             ab.addProteinDomain( b );
1233             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1234             if ( ab.getNumberOfProteinDomains() != 2 ) {
1235                 return false;
1236             }
1237             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1238                 return false;
1239             }
1240             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1241                 return false;
1242             }
1243             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1244             if ( ab.getNumberOfProteinDomains() != 2 ) {
1245                 return false;
1246             }
1247             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1248                 return false;
1249             }
1250             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1251             final Domain d = new BasicDomain( "d",
1252                                               ( short ) 10000,
1253                                               ( short ) 10500,
1254                                               ( short ) 1,
1255                                               ( short ) 1,
1256                                               0.0000001,
1257                                               1 );
1258             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1259             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1260             cde.addProteinDomain( c );
1261             cde.addProteinDomain( d );
1262             cde.addProteinDomain( e );
1263             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1264             if ( cde.getNumberOfProteinDomains() != 3 ) {
1265                 return false;
1266             }
1267             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1268                 return false;
1269             }
1270             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1271             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1272             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1273             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1274             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1275             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1276             fghi.addProteinDomain( f );
1277             fghi.addProteinDomain( g );
1278             fghi.addProteinDomain( h );
1279             fghi.addProteinDomain( i );
1280             fghi.addProteinDomain( i );
1281             fghi.addProteinDomain( i );
1282             fghi.addProteinDomain( i2 );
1283             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1284             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1285                 return false;
1286             }
1287             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1288                 return false;
1289             }
1290             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1291                 return false;
1292             }
1293             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1294             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1295                 return false;
1296             }
1297             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1298                 return false;
1299             }
1300             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1301             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1302             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1303             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1304             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1305             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1306             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1307             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1308             jklm.addProteinDomain( j );
1309             jklm.addProteinDomain( k );
1310             jklm.addProteinDomain( l );
1311             jklm.addProteinDomain( m );
1312             jklm.addProteinDomain( m0 );
1313             jklm.addProteinDomain( m1 );
1314             jklm.addProteinDomain( m2 );
1315             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1316             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1317                 return false;
1318             }
1319             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1320                 return false;
1321             }
1322             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1323                 return false;
1324             }
1325             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1326             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1327                 return false;
1328             }
1329             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1330                 return false;
1331             }
1332             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1333             final Protein od = new BasicProtein( "od", "varanus", 0 );
1334             od.addProteinDomain( only );
1335             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1336             if ( od.getNumberOfProteinDomains() != 1 ) {
1337                 return false;
1338             }
1339             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1340                 return false;
1341             }
1342         }
1343         catch ( final Exception e ) {
1344             e.printStackTrace( System.out );
1345             return false;
1346         }
1347         return true;
1348     }
1349
1350     public static final boolean testPfamTreeReading() {
1351         try {
1352             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1353             final NHXParser parser = new NHXParser();
1354             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1355             parser.setReplaceUnderscores( false );
1356             parser.setGuessRootedness( true );
1357             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1358             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1359             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1360                 return false;
1361             }
1362             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1363                 return false;
1364             }
1365         }
1366         catch ( final Exception e ) {
1367             e.printStackTrace();
1368         }
1369         return true;
1370     }
1371
1372     public static final boolean testPhyloXMLparsingFromURL() {
1373         try {
1374             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1375             final URL u = new URL( s );
1376             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1377             final Phylogeny[] phys = factory.create( u.openStream(), PhyloXmlParser.createPhyloXmlParser() );
1378             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1379                 return false;
1380             }
1381         }
1382         catch ( final Exception e ) {
1383             e.printStackTrace();
1384         }
1385         return true;
1386     }
1387
1388     public static final boolean testToLReading() {
1389         try {
1390             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1391             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1392             final Phylogeny[] phys = factory.create( u.openStream(), new TolParser() );
1393             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1394                 return false;
1395             }
1396             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1397                 return false;
1398             }
1399             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Protacanthopterygii" ) ) {
1400                 return false;
1401             }
1402             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1403                 return false;
1404             }
1405         }
1406         catch ( final Exception e ) {
1407             e.printStackTrace();
1408         }
1409         return true;
1410     }
1411
1412     public static final boolean testTreeBaseReading() {
1413         try {
1414             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );
1415             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1416             parser.setReplaceUnderscores( true );
1417             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1418             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1419             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1420                 return false;
1421             }
1422             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1423             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1424             parser2.setReplaceUnderscores( true );
1425             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1426             final Phylogeny[] phys2 = factory2.create( u2.openStream(), parser2 );
1427             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1428                 return false;
1429             }
1430         }
1431         catch ( final Exception e ) {
1432             e.printStackTrace();
1433         }
1434         return true;
1435     }
1436
1437     public static final boolean testTreeFamReading() {
1438         try {
1439             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1440             final NHXParser parser = new NHXParser();
1441             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1442             parser.setReplaceUnderscores( false );
1443             parser.setGuessRootedness( true );
1444             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1445             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1446             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1447                 return false;
1448             }
1449             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1450                 return false;
1451             }
1452         }
1453         catch ( final Exception e ) {
1454             e.printStackTrace();
1455         }
1456         return true;
1457     }
1458
1459     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1460         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1461         return p;
1462     }
1463
1464     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1465         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1466     }
1467
1468     private static boolean testAminoAcidSequence() {
1469         try {
1470             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1471             if ( aa1.getLength() != 13 ) {
1472                 return false;
1473             }
1474             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1475                 return false;
1476             }
1477             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1478                 return false;
1479             }
1480             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1481                 return false;
1482             }
1483             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1484             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
1485                 return false;
1486             }
1487             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1488             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1489                 return false;
1490             }
1491             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1492             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1493                 return false;
1494             }
1495         }
1496         catch ( final Exception e ) {
1497             e.printStackTrace();
1498             return false;
1499         }
1500         return true;
1501     }
1502
1503     private static boolean testBasicDomain() {
1504         try {
1505             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1506             if ( !pd.getDomainId().equals( "id" ) ) {
1507                 return false;
1508             }
1509             if ( pd.getNumber() != 1 ) {
1510                 return false;
1511             }
1512             if ( pd.getTotalCount() != 4 ) {
1513                 return false;
1514             }
1515             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1516                 return false;
1517             }
1518             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1519             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1520             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1521             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1522             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1523             if ( !a1.equals( a1 ) ) {
1524                 return false;
1525             }
1526             if ( !a1.equals( a1_copy ) ) {
1527                 return false;
1528             }
1529             if ( !a1.equals( a1_equal ) ) {
1530                 return false;
1531             }
1532             if ( !a1.equals( a2 ) ) {
1533                 return false;
1534             }
1535             if ( a1.equals( a3 ) ) {
1536                 return false;
1537             }
1538             if ( a1.compareTo( a1 ) != 0 ) {
1539                 return false;
1540             }
1541             if ( a1.compareTo( a1_copy ) != 0 ) {
1542                 return false;
1543             }
1544             if ( a1.compareTo( a1_equal ) != 0 ) {
1545                 return false;
1546             }
1547             if ( a1.compareTo( a2 ) != 0 ) {
1548                 return false;
1549             }
1550             if ( a1.compareTo( a3 ) == 0 ) {
1551                 return false;
1552             }
1553         }
1554         catch ( final Exception e ) {
1555             e.printStackTrace( System.out );
1556             return false;
1557         }
1558         return true;
1559     }
1560
1561     private static boolean testBasicNodeMethods() {
1562         try {
1563             if ( PhylogenyNode.getNodeCount() != 0 ) {
1564                 return false;
1565             }
1566             final PhylogenyNode n1 = new PhylogenyNode();
1567             final PhylogenyNode n2 = PhylogenyNode
1568                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1569             final PhylogenyNode n3 = PhylogenyNode
1570                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1571             final PhylogenyNode n4 = PhylogenyNode
1572                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1573             if ( n1.isHasAssignedEvent() ) {
1574                 return false;
1575             }
1576             if ( PhylogenyNode.getNodeCount() != 4 ) {
1577                 return false;
1578             }
1579             if ( n3.getIndicator() != 0 ) {
1580                 return false;
1581             }
1582             if ( n3.getNumberOfExternalNodes() != 1 ) {
1583                 return false;
1584             }
1585             if ( !n3.isExternal() ) {
1586                 return false;
1587             }
1588             if ( !n3.isRoot() ) {
1589                 return false;
1590             }
1591             if ( !n4.getName().equals( "n4" ) ) {
1592                 return false;
1593             }
1594         }
1595         catch ( final Exception e ) {
1596             e.printStackTrace( System.out );
1597             return false;
1598         }
1599         return true;
1600     }
1601
1602     private static boolean testBasicPhyloXMLparsing() {
1603         try {
1604             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1605             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1606             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1607                                                               xml_parser );
1608             if ( xml_parser.getErrorCount() > 0 ) {
1609                 System.out.println( xml_parser.getErrorMessages().toString() );
1610                 return false;
1611             }
1612             if ( phylogenies_0.length != 4 ) {
1613                 return false;
1614             }
1615             final Phylogeny t1 = phylogenies_0[ 0 ];
1616             final Phylogeny t2 = phylogenies_0[ 1 ];
1617             final Phylogeny t3 = phylogenies_0[ 2 ];
1618             final Phylogeny t4 = phylogenies_0[ 3 ];
1619             if ( t1.getNumberOfExternalNodes() != 1 ) {
1620                 return false;
1621             }
1622             if ( !t1.isRooted() ) {
1623                 return false;
1624             }
1625             if ( t1.isRerootable() ) {
1626                 return false;
1627             }
1628             if ( !t1.getType().equals( "gene_tree" ) ) {
1629                 return false;
1630             }
1631             if ( t2.getNumberOfExternalNodes() != 2 ) {
1632                 return false;
1633             }
1634             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1635                 return false;
1636             }
1637             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1638                 return false;
1639             }
1640             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1641                 return false;
1642             }
1643             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1644                 return false;
1645             }
1646             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1647                 return false;
1648             }
1649             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1650                 return false;
1651             }
1652             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1653                     .startsWith( "actgtgggggt" ) ) {
1654                 return false;
1655             }
1656             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1657                     .startsWith( "ctgtgatgcat" ) ) {
1658                 return false;
1659             }
1660             if ( t3.getNumberOfExternalNodes() != 4 ) {
1661                 return false;
1662             }
1663             if ( !t1.getName().equals( "t1" ) ) {
1664                 return false;
1665             }
1666             if ( !t2.getName().equals( "t2" ) ) {
1667                 return false;
1668             }
1669             if ( !t3.getName().equals( "t3" ) ) {
1670                 return false;
1671             }
1672             if ( !t4.getName().equals( "t4" ) ) {
1673                 return false;
1674             }
1675             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1676                 return false;
1677             }
1678             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1679                 return false;
1680             }
1681             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1682                 return false;
1683             }
1684             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1685                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1686                 return false;
1687             }
1688             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1689                 return false;
1690             }
1691             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1692                 return false;
1693             }
1694             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1695                 return false;
1696             }
1697             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1698                     .equals( "apoptosis" ) ) {
1699                 return false;
1700             }
1701             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1702                     .equals( "GO:0006915" ) ) {
1703                 return false;
1704             }
1705             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1706                     .equals( "UniProtKB" ) ) {
1707                 return false;
1708             }
1709             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1710                     .equals( "experimental" ) ) {
1711                 return false;
1712             }
1713             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1714                     .equals( "function" ) ) {
1715                 return false;
1716             }
1717             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1718                     .getValue() != 1 ) {
1719                 return false;
1720             }
1721             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1722                     .getType().equals( "ml" ) ) {
1723                 return false;
1724             }
1725             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1726                     .equals( "apoptosis" ) ) {
1727                 return false;
1728             }
1729             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1730                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1731                 return false;
1732             }
1733             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1734                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1735                 return false;
1736             }
1737             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1738                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1739                 return false;
1740             }
1741             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1742                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1743                 return false;
1744             }
1745             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1746                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1747                 return false;
1748             }
1749             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1750                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1751                 return false;
1752             }
1753             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1754                     .equals( "GO:0005829" ) ) {
1755                 return false;
1756             }
1757             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1758                     .equals( "intracellular organelle" ) ) {
1759                 return false;
1760             }
1761             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1762                 return false;
1763             }
1764             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1765                     .equals( "UniProt link" ) ) ) {
1766                 return false;
1767             }
1768             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1769                 return false;
1770             }
1771             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1772             if ( x.size() != 4 ) {
1773                 return false;
1774             }
1775             int c = 0;
1776             for( final Accession acc : x ) {
1777                 if ( c == 0 ) {
1778                     if ( !acc.getSource().equals( "KEGG" ) ) {
1779                         return false;
1780                     }
1781                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1782                         return false;
1783                     }
1784                 }
1785                 c++;
1786             }
1787         }
1788         catch ( final Exception e ) {
1789             e.printStackTrace( System.out );
1790             return false;
1791         }
1792         return true;
1793     }
1794
1795     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1796         try {
1797             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1798             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1799             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1800                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1801             }
1802             else {
1803                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1804             }
1805             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1806                                                               xml_parser );
1807             if ( xml_parser.getErrorCount() > 0 ) {
1808                 System.out.println( xml_parser.getErrorMessages().toString() );
1809                 return false;
1810             }
1811             if ( phylogenies_0.length != 4 ) {
1812                 return false;
1813             }
1814             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1815             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1816             if ( phylogenies_t1.length != 1 ) {
1817                 return false;
1818             }
1819             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1820             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1821                 return false;
1822             }
1823             if ( !t1_rt.isRooted() ) {
1824                 return false;
1825             }
1826             if ( t1_rt.isRerootable() ) {
1827                 return false;
1828             }
1829             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1830                 return false;
1831             }
1832             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1833             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1834             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1835             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1836                 return false;
1837             }
1838             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1839                 return false;
1840             }
1841             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1842                 return false;
1843             }
1844             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1845                 return false;
1846             }
1847             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1848                     .startsWith( "actgtgggggt" ) ) {
1849                 return false;
1850             }
1851             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1852                     .startsWith( "ctgtgatgcat" ) ) {
1853                 return false;
1854             }
1855             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1856             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1857             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1858             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1859             if ( phylogenies_1.length != 1 ) {
1860                 return false;
1861             }
1862             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1863             if ( !t3_rt.getName().equals( "t3" ) ) {
1864                 return false;
1865             }
1866             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1867                 return false;
1868             }
1869             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1870                 return false;
1871             }
1872             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1873                 return false;
1874             }
1875             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1876                 return false;
1877             }
1878             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1879                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1880                 return false;
1881             }
1882             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1883                 return false;
1884             }
1885             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1886                 return false;
1887             }
1888             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1889                     .equals( "UniProtKB" ) ) {
1890                 return false;
1891             }
1892             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1893                     .equals( "apoptosis" ) ) {
1894                 return false;
1895             }
1896             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1897                     .equals( "GO:0006915" ) ) {
1898                 return false;
1899             }
1900             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1901                     .equals( "UniProtKB" ) ) {
1902                 return false;
1903             }
1904             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1905                     .equals( "experimental" ) ) {
1906                 return false;
1907             }
1908             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1909                     .equals( "function" ) ) {
1910                 return false;
1911             }
1912             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1913                     .getValue() != 1 ) {
1914                 return false;
1915             }
1916             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1917                     .getType().equals( "ml" ) ) {
1918                 return false;
1919             }
1920             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1921                     .equals( "apoptosis" ) ) {
1922                 return false;
1923             }
1924             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1925                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1926                 return false;
1927             }
1928             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1929                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1930                 return false;
1931             }
1932             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1933                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1934                 return false;
1935             }
1936             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1937                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1938                 return false;
1939             }
1940             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1941                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1942                 return false;
1943             }
1944             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1945                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1946                 return false;
1947             }
1948             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1949                     .equals( "GO:0005829" ) ) {
1950                 return false;
1951             }
1952             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1953                     .equals( "intracellular organelle" ) ) {
1954                 return false;
1955             }
1956             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1957                 return false;
1958             }
1959             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1960                     .equals( "UniProt link" ) ) ) {
1961                 return false;
1962             }
1963             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1964                 return false;
1965             }
1966             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1967                 return false;
1968             }
1969             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1970                     .equals( "Aguinaldo, A. M. A.; J. M. Turbeville, L. S. Linford, M. C. Rivera, J. R. Garey, R. A. Raff, & J. A. Lake (1997). \"Evidence for a clade of nematodes, arthropods and other moulting animals\". Nature 387 (6632): 489–493." ) ) ) {
1971                 return false;
1972             }
1973             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1974                 return false;
1975             }
1976             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1977                 return false;
1978             }
1979             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1980                 return false;
1981             }
1982             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1983                 return false;
1984             }
1985             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1986                     .equals( "ncbi" ) ) {
1987                 return false;
1988             }
1989             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1990                 return false;
1991             }
1992             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1993                     .getName().equals( "B" ) ) {
1994                 return false;
1995             }
1996             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1997                     .getFrom() != 21 ) {
1998                 return false;
1999             }
2000             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
2001                 return false;
2002             }
2003             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2004                     .getLength() != 24 ) {
2005                 return false;
2006             }
2007             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2008                     .getConfidence() != 2144 ) {
2009                 return false;
2010             }
2011             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2012                     .equals( "pfam" ) ) {
2013                 return false;
2014             }
2015             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2016                 return false;
2017             }
2018             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2019                 return false;
2020             }
2021             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2022                 return false;
2023             }
2024             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2025                 return false;
2026             }
2027             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2028             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2029                 return false;
2030             }
2031             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2032                 return false;
2033             }
2034             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2035                 return false;
2036             }
2037             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2038                 return false;
2039             }
2040             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2041                 return false;
2042             }
2043             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2044                 return false;
2045             }
2046             if ( taxbb.getSynonyms().size() != 2 ) {
2047                 return false;
2048             }
2049             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2050                 return false;
2051             }
2052             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2053                 return false;
2054             }
2055             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2056                 return false;
2057             }
2058             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2059                 return false;
2060             }
2061             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2062                 return false;
2063             }
2064             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2065                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2066                 return false;
2067             }
2068             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2069                 return false;
2070             }
2071             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2072                 return false;
2073             }
2074             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2075                 return false;
2076             }
2077             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2078                 return false;
2079             }
2080             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2081                 return false;
2082             }
2083             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2084                 return false;
2085             }
2086             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2087                 return false;
2088             }
2089             //
2090             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2091                 return false;
2092             }
2093             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2094                     .equalsIgnoreCase( "435" ) ) {
2095                 return false;
2096             }
2097             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
2098                 return false;
2099             }
2100             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2101                     .equalsIgnoreCase( "443.7" ) ) {
2102                 return false;
2103             }
2104             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2105                 return false;
2106             }
2107             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2108                 return false;
2109             }
2110             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2111                     .equalsIgnoreCase( "433" ) ) {
2112                 return false;
2113             }
2114             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2115                     .getCrossReferences();
2116             if ( x.size() != 4 ) {
2117                 return false;
2118             }
2119             int c = 0;
2120             for( final Accession acc : x ) {
2121                 if ( c == 0 ) {
2122                     if ( !acc.getSource().equals( "KEGG" ) ) {
2123                         return false;
2124                     }
2125                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2126                         return false;
2127                     }
2128                 }
2129                 c++;
2130             }
2131         }
2132         catch ( final Exception e ) {
2133             e.printStackTrace( System.out );
2134             return false;
2135         }
2136         return true;
2137     }
2138
2139     private static boolean testBasicPhyloXMLparsingValidating() {
2140         try {
2141             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2142             PhyloXmlParser xml_parser = null;
2143             try {
2144                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2145             }
2146             catch ( final Exception e ) {
2147                 // Do nothing -- means were not running from jar.
2148             }
2149             if ( xml_parser == null ) {
2150                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2151                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2152                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2153                 }
2154                 else {
2155                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2156                 }
2157             }
2158             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
2159                                                               xml_parser );
2160             if ( xml_parser.getErrorCount() > 0 ) {
2161                 System.out.println( xml_parser.getErrorMessages().toString() );
2162                 return false;
2163             }
2164             if ( phylogenies_0.length != 4 ) {
2165                 return false;
2166             }
2167             final Phylogeny t1 = phylogenies_0[ 0 ];
2168             final Phylogeny t2 = phylogenies_0[ 1 ];
2169             final Phylogeny t3 = phylogenies_0[ 2 ];
2170             final Phylogeny t4 = phylogenies_0[ 3 ];
2171             if ( !t1.getName().equals( "t1" ) ) {
2172                 return false;
2173             }
2174             if ( !t2.getName().equals( "t2" ) ) {
2175                 return false;
2176             }
2177             if ( !t3.getName().equals( "t3" ) ) {
2178                 return false;
2179             }
2180             if ( !t4.getName().equals( "t4" ) ) {
2181                 return false;
2182             }
2183             if ( t1.getNumberOfExternalNodes() != 1 ) {
2184                 return false;
2185             }
2186             if ( t2.getNumberOfExternalNodes() != 2 ) {
2187                 return false;
2188             }
2189             if ( t3.getNumberOfExternalNodes() != 4 ) {
2190                 return false;
2191             }
2192             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2193             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
2194             if ( xml_parser.getErrorCount() > 0 ) {
2195                 System.out.println( "errors:" );
2196                 System.out.println( xml_parser.getErrorMessages().toString() );
2197                 return false;
2198             }
2199             if ( phylogenies_1.length != 4 ) {
2200                 return false;
2201             }
2202             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
2203                                                               xml_parser );
2204             if ( xml_parser.getErrorCount() > 0 ) {
2205                 System.out.println( "errors:" );
2206                 System.out.println( xml_parser.getErrorMessages().toString() );
2207                 return false;
2208             }
2209             if ( phylogenies_2.length != 1 ) {
2210                 return false;
2211             }
2212             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2213                 return false;
2214             }
2215             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
2216                                                               xml_parser );
2217             if ( xml_parser.getErrorCount() > 0 ) {
2218                 System.out.println( xml_parser.getErrorMessages().toString() );
2219                 return false;
2220             }
2221             if ( phylogenies_3.length != 2 ) {
2222                 return false;
2223             }
2224             final Phylogeny a = phylogenies_3[ 0 ];
2225             if ( !a.getName().equals( "tree 4" ) ) {
2226                 return false;
2227             }
2228             if ( a.getNumberOfExternalNodes() != 3 ) {
2229                 return false;
2230             }
2231             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2232                 return false;
2233             }
2234             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2235                 return false;
2236             }
2237             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
2238                                                               xml_parser );
2239             if ( xml_parser.getErrorCount() > 0 ) {
2240                 System.out.println( xml_parser.getErrorMessages().toString() );
2241                 return false;
2242             }
2243             if ( phylogenies_4.length != 1 ) {
2244                 return false;
2245             }
2246             final Phylogeny s = phylogenies_4[ 0 ];
2247             if ( s.getNumberOfExternalNodes() != 6 ) {
2248                 return false;
2249             }
2250             s.getNode( "first" );
2251             s.getNode( "<>" );
2252             s.getNode( "\"<a'b&c'd\">\"" );
2253             s.getNode( "'''\"" );
2254             s.getNode( "\"\"\"" );
2255             s.getNode( "dick & doof" );
2256         }
2257         catch ( final Exception e ) {
2258             e.printStackTrace( System.out );
2259             return false;
2260         }
2261         return true;
2262     }
2263
2264     private static boolean testBasicProtein() {
2265         try {
2266             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2267             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2268             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2269             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2270             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2271             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2272             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2273             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2274             p0.addProteinDomain( y );
2275             p0.addProteinDomain( e );
2276             p0.addProteinDomain( b );
2277             p0.addProteinDomain( c );
2278             p0.addProteinDomain( d );
2279             p0.addProteinDomain( a );
2280             p0.addProteinDomain( x );
2281             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2282                 return false;
2283             }
2284             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2285                 return false;
2286             }
2287             //
2288             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2289             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2290             aa0.addProteinDomain( a1 );
2291             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2292                 return false;
2293             }
2294             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2295                 return false;
2296             }
2297             //
2298             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2299             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2300             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2301             aa1.addProteinDomain( a11 );
2302             aa1.addProteinDomain( a12 );
2303             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2304                 return false;
2305             }
2306             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2307                 return false;
2308             }
2309             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2310             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2311                 return false;
2312             }
2313             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2314                 return false;
2315             }
2316             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2317                 return false;
2318             }
2319             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2320             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2321                 return false;
2322             }
2323             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2324                 return false;
2325             }
2326             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2327                 return false;
2328             }
2329             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2330                 return false;
2331             }
2332             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2333             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2334                 return false;
2335             }
2336             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2337                 return false;
2338             }
2339             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2340                 return false;
2341             }
2342             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2343                 return false;
2344             }
2345             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2346             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2347                 return false;
2348             }
2349             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2350                 return false;
2351             }
2352             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2353                 return false;
2354             }
2355             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2356                 return false;
2357             }
2358             //
2359             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2360             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2361             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2362             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2363             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2364             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2365             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2366             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2367             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2368             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2369             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2370             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2371             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2372             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2373             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2374             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2375             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2376             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2377             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2378             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2379             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2380             p00.addProteinDomain( y0 );
2381             p00.addProteinDomain( e0 );
2382             p00.addProteinDomain( b0 );
2383             p00.addProteinDomain( c0 );
2384             p00.addProteinDomain( d0 );
2385             p00.addProteinDomain( a0 );
2386             p00.addProteinDomain( x0 );
2387             p00.addProteinDomain( y1 );
2388             p00.addProteinDomain( y2 );
2389             p00.addProteinDomain( y3 );
2390             p00.addProteinDomain( e1 );
2391             p00.addProteinDomain( e2 );
2392             p00.addProteinDomain( e3 );
2393             p00.addProteinDomain( e4 );
2394             p00.addProteinDomain( e5 );
2395             p00.addProteinDomain( z0 );
2396             p00.addProteinDomain( z1 );
2397             p00.addProteinDomain( z2 );
2398             p00.addProteinDomain( zz0 );
2399             p00.addProteinDomain( zz1 );
2400             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2401                 return false;
2402             }
2403             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2404                 return false;
2405             }
2406             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2407                 return false;
2408             }
2409             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2410                 return false;
2411             }
2412             if ( !p00.toDomainArchitectureString( "~", 7, "" ).equals( "a~b~c~d~e~e~e~e~e~e~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2413                 return false;
2414             }
2415             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2416             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2417             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2418             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2419             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2420             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2421             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2422             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2423             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2424             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2425             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2426             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2427             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2428             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2429             p.addProteinDomain( B15 );
2430             p.addProteinDomain( C50 );
2431             p.addProteinDomain( A60 );
2432             p.addProteinDomain( A30 );
2433             p.addProteinDomain( C70 );
2434             p.addProteinDomain( B35 );
2435             p.addProteinDomain( B40 );
2436             p.addProteinDomain( A0 );
2437             p.addProteinDomain( A10 );
2438             p.addProteinDomain( A20 );
2439             p.addProteinDomain( B25 );
2440             p.addProteinDomain( D80 );
2441             List<String> domains_ids = new ArrayList<String>();
2442             domains_ids.add( "A" );
2443             domains_ids.add( "B" );
2444             domains_ids.add( "C" );
2445             if ( !p.contains( domains_ids, false ) ) {
2446                 return false;
2447             }
2448             if ( !p.contains( domains_ids, true ) ) {
2449                 return false;
2450             }
2451             domains_ids.add( "X" );
2452             if ( p.contains( domains_ids, false ) ) {
2453                 return false;
2454             }
2455             if ( p.contains( domains_ids, true ) ) {
2456                 return false;
2457             }
2458             domains_ids = new ArrayList<String>();
2459             domains_ids.add( "A" );
2460             domains_ids.add( "C" );
2461             domains_ids.add( "D" );
2462             if ( !p.contains( domains_ids, false ) ) {
2463                 return false;
2464             }
2465             if ( !p.contains( domains_ids, true ) ) {
2466                 return false;
2467             }
2468             domains_ids = new ArrayList<String>();
2469             domains_ids.add( "A" );
2470             domains_ids.add( "D" );
2471             domains_ids.add( "C" );
2472             if ( !p.contains( domains_ids, false ) ) {
2473                 return false;
2474             }
2475             if ( p.contains( domains_ids, true ) ) {
2476                 return false;
2477             }
2478             domains_ids = new ArrayList<String>();
2479             domains_ids.add( "A" );
2480             domains_ids.add( "A" );
2481             domains_ids.add( "B" );
2482             if ( !p.contains( domains_ids, false ) ) {
2483                 return false;
2484             }
2485             if ( !p.contains( domains_ids, true ) ) {
2486                 return false;
2487             }
2488             domains_ids = new ArrayList<String>();
2489             domains_ids.add( "A" );
2490             domains_ids.add( "A" );
2491             domains_ids.add( "A" );
2492             domains_ids.add( "B" );
2493             domains_ids.add( "B" );
2494             if ( !p.contains( domains_ids, false ) ) {
2495                 return false;
2496             }
2497             if ( !p.contains( domains_ids, true ) ) {
2498                 return false;
2499             }
2500             domains_ids = new ArrayList<String>();
2501             domains_ids.add( "A" );
2502             domains_ids.add( "A" );
2503             domains_ids.add( "B" );
2504             domains_ids.add( "A" );
2505             domains_ids.add( "B" );
2506             domains_ids.add( "B" );
2507             domains_ids.add( "A" );
2508             domains_ids.add( "B" );
2509             domains_ids.add( "C" );
2510             domains_ids.add( "A" );
2511             domains_ids.add( "C" );
2512             domains_ids.add( "D" );
2513             if ( !p.contains( domains_ids, false ) ) {
2514                 return false;
2515             }
2516             if ( p.contains( domains_ids, true ) ) {
2517                 return false;
2518             }
2519         }
2520         catch ( final Exception e ) {
2521             e.printStackTrace( System.out );
2522             return false;
2523         }
2524         return true;
2525     }
2526
2527     private static boolean testBasicTable() {
2528         try {
2529             final BasicTable<String> t0 = new BasicTable<String>();
2530             if ( t0.getNumberOfColumns() != 0 ) {
2531                 return false;
2532             }
2533             if ( t0.getNumberOfRows() != 0 ) {
2534                 return false;
2535             }
2536             t0.setValue( 3, 2, "23" );
2537             t0.setValue( 10, 1, "error" );
2538             t0.setValue( 10, 1, "110" );
2539             t0.setValue( 9, 1, "19" );
2540             t0.setValue( 1, 10, "101" );
2541             t0.setValue( 10, 10, "1010" );
2542             t0.setValue( 100, 10, "10100" );
2543             t0.setValue( 0, 0, "00" );
2544             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2545                 return false;
2546             }
2547             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2548                 return false;
2549             }
2550             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2551                 return false;
2552             }
2553             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2554                 return false;
2555             }
2556             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2557                 return false;
2558             }
2559             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2560                 return false;
2561             }
2562             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2563                 return false;
2564             }
2565             if ( t0.getNumberOfColumns() != 101 ) {
2566                 return false;
2567             }
2568             if ( t0.getNumberOfRows() != 11 ) {
2569                 return false;
2570             }
2571             if ( t0.getValueAsString( 49, 4 ) != null ) {
2572                 return false;
2573             }
2574             final String l = ForesterUtil.getLineSeparator();
2575             final StringBuffer source = new StringBuffer();
2576             source.append( "" + l );
2577             source.append( "# 1 1 1 1 1 1 1 1" + l );
2578             source.append( " 00 01 02 03" + l );
2579             source.append( "   10 11 12 13  " + l );
2580             source.append( "20 21 22 23 " + l );
2581             source.append( "    30  31    32 33" + l );
2582             source.append( "40 41 42 43" + l );
2583             source.append( "  # 1 1 1 1 1 " + l );
2584             source.append( "50 51 52 53 54" + l );
2585             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2586             if ( t1.getNumberOfColumns() != 5 ) {
2587                 return false;
2588             }
2589             if ( t1.getNumberOfRows() != 6 ) {
2590                 return false;
2591             }
2592             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2593                 return false;
2594             }
2595             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2596                 return false;
2597             }
2598             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2599                 return false;
2600             }
2601             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2602                 return false;
2603             }
2604             final StringBuffer source1 = new StringBuffer();
2605             source1.append( "" + l );
2606             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2607             source1.append( " 00; 01 ;02;03" + l );
2608             source1.append( "   10; 11; 12; 13  " + l );
2609             source1.append( "20; 21; 22; 23 " + l );
2610             source1.append( "    30;  31;    32; 33" + l );
2611             source1.append( "40;41;42;43" + l );
2612             source1.append( "  # 1 1 1 1 1 " + l );
2613             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2614             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2615             if ( t2.getNumberOfColumns() != 5 ) {
2616                 return false;
2617             }
2618             if ( t2.getNumberOfRows() != 6 ) {
2619                 return false;
2620             }
2621             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2622                 return false;
2623             }
2624             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2625                 return false;
2626             }
2627             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2628                 return false;
2629             }
2630             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2631                 return false;
2632             }
2633             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2634                 return false;
2635             }
2636             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2637                 return false;
2638             }
2639             final StringBuffer source2 = new StringBuffer();
2640             source2.append( "" + l );
2641             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2642             source2.append( " 00; 01 ;02;03" + l );
2643             source2.append( "   10; 11; 12; 13  " + l );
2644             source2.append( "20; 21; 22; 23 " + l );
2645             source2.append( "                     " + l );
2646             source2.append( "    30;  31;    32; 33" + l );
2647             source2.append( "40;41;42;43" + l );
2648             source2.append( "  comment: 1 1 1 1 1 " + l );
2649             source2.append( ";;;50  ;   52; 53;;54   " + l );
2650             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2651                                                                         ';',
2652                                                                         false,
2653                                                                         false,
2654                                                                         "comment:",
2655                                                                         false );
2656             if ( tl.size() != 2 ) {
2657                 return false;
2658             }
2659             final BasicTable<String> t3 = tl.get( 0 );
2660             final BasicTable<String> t4 = tl.get( 1 );
2661             if ( t3.getNumberOfColumns() != 4 ) {
2662                 return false;
2663             }
2664             if ( t3.getNumberOfRows() != 3 ) {
2665                 return false;
2666             }
2667             if ( t4.getNumberOfColumns() != 4 ) {
2668                 return false;
2669             }
2670             if ( t4.getNumberOfRows() != 3 ) {
2671                 return false;
2672             }
2673             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2674                 return false;
2675             }
2676             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2677                 return false;
2678             }
2679         }
2680         catch ( final Exception e ) {
2681             e.printStackTrace( System.out );
2682             return false;
2683         }
2684         return true;
2685     }
2686
2687     private static boolean testBasicTolXMLparsing() {
2688         try {
2689             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2690             final TolParser parser = new TolParser();
2691             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2692             if ( parser.getErrorCount() > 0 ) {
2693                 System.out.println( parser.getErrorMessages().toString() );
2694                 return false;
2695             }
2696             if ( phylogenies_0.length != 1 ) {
2697                 return false;
2698             }
2699             final Phylogeny t1 = phylogenies_0[ 0 ];
2700             if ( t1.getNumberOfExternalNodes() != 5 ) {
2701                 return false;
2702             }
2703             if ( !t1.isRooted() ) {
2704                 return false;
2705             }
2706             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2707                 return false;
2708             }
2709             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2710                 return false;
2711             }
2712             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2713                 return false;
2714             }
2715             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2716                 return false;
2717             }
2718             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2719             if ( parser.getErrorCount() > 0 ) {
2720                 System.out.println( parser.getErrorMessages().toString() );
2721                 return false;
2722             }
2723             if ( phylogenies_1.length != 1 ) {
2724                 return false;
2725             }
2726             final Phylogeny t2 = phylogenies_1[ 0 ];
2727             if ( t2.getNumberOfExternalNodes() != 664 ) {
2728                 return false;
2729             }
2730             if ( !t2.isRooted() ) {
2731                 return false;
2732             }
2733             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2734                 return false;
2735             }
2736             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2737                 return false;
2738             }
2739             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2740                 return false;
2741             }
2742             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2743                 return false;
2744             }
2745             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2746                 return false;
2747             }
2748             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2749                     .equals( "Aquifex" ) ) {
2750                 return false;
2751             }
2752             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2753             if ( parser.getErrorCount() > 0 ) {
2754                 System.out.println( parser.getErrorMessages().toString() );
2755                 return false;
2756             }
2757             if ( phylogenies_2.length != 1 ) {
2758                 return false;
2759             }
2760             final Phylogeny t3 = phylogenies_2[ 0 ];
2761             if ( t3.getNumberOfExternalNodes() != 184 ) {
2762                 return false;
2763             }
2764             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2765                 return false;
2766             }
2767             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2768                 return false;
2769             }
2770             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2771                 return false;
2772             }
2773             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2774             if ( parser.getErrorCount() > 0 ) {
2775                 System.out.println( parser.getErrorMessages().toString() );
2776                 return false;
2777             }
2778             if ( phylogenies_3.length != 1 ) {
2779                 return false;
2780             }
2781             final Phylogeny t4 = phylogenies_3[ 0 ];
2782             if ( t4.getNumberOfExternalNodes() != 1 ) {
2783                 return false;
2784             }
2785             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2786                 return false;
2787             }
2788             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2789                 return false;
2790             }
2791             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2792                 return false;
2793             }
2794             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2795             if ( parser.getErrorCount() > 0 ) {
2796                 System.out.println( parser.getErrorMessages().toString() );
2797                 return false;
2798             }
2799             if ( phylogenies_4.length != 1 ) {
2800                 return false;
2801             }
2802             final Phylogeny t5 = phylogenies_4[ 0 ];
2803             if ( t5.getNumberOfExternalNodes() != 13 ) {
2804                 return false;
2805             }
2806             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2807                 return false;
2808             }
2809             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2810                 return false;
2811             }
2812             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2813                 return false;
2814             }
2815         }
2816         catch ( final Exception e ) {
2817             e.printStackTrace( System.out );
2818             return false;
2819         }
2820         return true;
2821     }
2822
2823     private static boolean testBasicTreeMethods() {
2824         try {
2825             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2826             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2827             if ( t2.getNumberOfExternalNodes() != 4 ) {
2828                 return false;
2829             }
2830             if ( t2.getHeight() != 8.5 ) {
2831                 return false;
2832             }
2833             if ( !t2.isCompletelyBinary() ) {
2834                 return false;
2835             }
2836             if ( t2.isEmpty() ) {
2837                 return false;
2838             }
2839             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2840             if ( t3.getNumberOfExternalNodes() != 5 ) {
2841                 return false;
2842             }
2843             if ( t3.getHeight() != 11 ) {
2844                 return false;
2845             }
2846             if ( t3.isCompletelyBinary() ) {
2847                 return false;
2848             }
2849             final PhylogenyNode n = t3.getNode( "ABC" );
2850             final Phylogeny t4 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3,(F,G,H,I))", new NHXParser() )[ 0 ];
2851             if ( t4.getNumberOfExternalNodes() != 9 ) {
2852                 return false;
2853             }
2854             if ( t4.getHeight() != 11 ) {
2855                 return false;
2856             }
2857             if ( t4.isCompletelyBinary() ) {
2858                 return false;
2859             }
2860             final StringBuffer sb5 = new StringBuffer( "(((A11:2)A1:2,(A21:1,A22:2,A23)A2:11,A3:2)A:2,B:10,C:3,D:8)" );
2861             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2862             if ( t5.getNumberOfExternalNodes() != 8 ) {
2863                 return false;
2864             }
2865             if ( t5.getHeight() != 15 ) {
2866                 return false;
2867             }
2868             final StringBuffer sb6 = new StringBuffer( "(X,Y,Z,(((A111)A11:2)A1:2,(X,Y,Z,A21:1,A22:2,A23)A2:11,A3:2)A:2,B:10,C:3,D:8)" );
2869             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2870             if ( t6.getHeight() != 15 ) {
2871                 return false;
2872             }
2873             final StringBuffer sb7 = new StringBuffer( "(((A11:2)A1:2,(A21:1,A22:2,A23)A2:11,A3:2)A:2,B:10,C:15,D:8)" );
2874             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2875             if ( t7.getHeight() != 15 ) {
2876                 return false;
2877             }
2878             final StringBuffer sb8 = new StringBuffer( "(((A11:11)A1:2,(A21:2,A22:2,A23,A24,AA:)A2:11,A3:2)A:2,B:15,C:15,D:15)" );
2879             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2880             if ( t8.getNumberOfExternalNodes() != 10 ) {
2881                 return false;
2882             }
2883             if ( t8.getHeight() != 15 ) {
2884                 return false;
2885             }
2886             final char[] a9 = new char[] { 'a' };
2887             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2888             if ( t9.getHeight() != 0 ) {
2889                 return false;
2890             }
2891             final char[] a10 = new char[] { 'a', ':', '6' };
2892             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2893             if ( t10.getHeight() != 6 ) {
2894                 return false;
2895             }
2896         }
2897         catch ( final Exception e ) {
2898             e.printStackTrace( System.out );
2899             return false;
2900         }
2901         return true;
2902     }
2903
2904     private static boolean testConfidenceAssessor() {
2905         try {
2906             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2907             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2908             final Phylogeny[] ev0 = factory
2909                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2910                              new NHXParser() );
2911             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2912             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2913                 return false;
2914             }
2915             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2916                 return false;
2917             }
2918             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2919             final Phylogeny[] ev1 = factory
2920                     .create( "((((A,B),C),D),E);((A,B),((E,D),C));(((A,B),C),(E,D));(A,(((E,D),C),B));(B,(A,((E,D),C)));(C,((E,D),(A,B)));(D,(E,((A,B),C)));",
2921                              new NHXParser() );
2922             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2923             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2924                 return false;
2925             }
2926             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2927                 return false;
2928             }
2929             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2930             final Phylogeny[] ev_b = factory
2931                     .create( "((A,C),X);((A,X),C);(A,C);((((A,B),C),D),E);((A,B),((E,D),C));(((A,B),C),(E,D));(A,(((E,D),C),B));(B,(A,((E,D),C)));(C,((E,D),(A,B)));(D,(E,((A,B),C)));((((A,C)ac,D)acd,E)acde,B)abcd",
2932                              new NHXParser() );
2933             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2934             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2935                 return false;
2936             }
2937             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2938                 return false;
2939             }
2940             //
2941             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2942             final Phylogeny[] ev1x = factory
2943                     .create( "((((A,B),C),D),E);((A,B),((E,D),C));(((A,B),C),(E,D));(A,(((E,D),C),B));(B,(A,((E,D),C)));(C,((E,D),(A,B)));(D,(E,((A,B),C)));",
2944                              new NHXParser() );
2945             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2946             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2947                 return false;
2948             }
2949             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2950                 return false;
2951             }
2952             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2953             final Phylogeny[] ev_bx = factory
2954                     .create( "((((A,B),C),D),E);((A,B),((E,D),C));(((A,B),C),(E,D));(A,(((E,D),C),B));(B,(A,((E,D),C)));(C,((E,D),(A,B)));(D,(E,((A,B),C)));((((A,C)ac,D)acd,E)acde,B)abcd",
2955                              new NHXParser() );
2956             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2957             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2958                 return false;
2959             }
2960             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2961                 return false;
2962             }
2963             //
2964             final Phylogeny[] t2 = factory
2965                     .create( "((((a,b),c),d),e);(((a,b),c),(d,e));(((((a,b),c),d),e),f);((((a,b),c),(d,e)),f);(((a,b),c),d,e);((a,b,c),d,e);",
2966                              new NHXParser() );
2967             final Phylogeny[] ev2 = factory
2968                     .create( "((((a,b),c),d),e);((((a,b),c),d),e);((((a,b),e),d),c);((((a,b),e),d),c);(((a,b),(c,d)),e);((a,b),x);((a,b),(x,y));(a,b);(a,e);(a,b,c);",
2969                              new NHXParser() );
2970             for( final Phylogeny target : t2 ) {
2971                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2972             }
2973             //
2974             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2975                                                  new NHXParser() )[ 0 ];
2976             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2977             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2978             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2979                 return false;
2980             }
2981             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2982                 return false;
2983             }
2984             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2985                 return false;
2986             }
2987         }
2988         catch ( final Exception e ) {
2989             e.printStackTrace();
2990             return false;
2991         }
2992         return true;
2993     }
2994
2995     private static boolean testCopyOfNodeData() {
2996         try {
2997             final PhylogenyNode n1 = PhylogenyNode
2998                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1:O=22:SO=33:SN=44:W=2:C=10.20.30:XN=S=tag1=value1=unit1]" );
2999             final PhylogenyNode n2 = n1.copyNodeData();
3000             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
3001                 return false;
3002             }
3003         }
3004         catch ( final Exception e ) {
3005             e.printStackTrace();
3006             return false;
3007         }
3008         return true;
3009     }
3010
3011     private static boolean testCreateBalancedPhylogeny() {
3012         try {
3013             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3014             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3015                 return false;
3016             }
3017             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3018                 return false;
3019             }
3020             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3021             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3022                 return false;
3023             }
3024             if ( p1.getNumberOfExternalNodes() != 100 ) {
3025                 return false;
3026             }
3027         }
3028         catch ( final Exception e ) {
3029             e.printStackTrace();
3030             return false;
3031         }
3032         return true;
3033     }
3034
3035     private static boolean testCreateUriForSeqWeb() {
3036         try {
3037             final PhylogenyNode n = new PhylogenyNode();
3038             n.setName( "tr|B3RJ64" );
3039             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3040                 return false;
3041             }
3042             n.setName( "B0LM41_HUMAN" );
3043             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3044                 return false;
3045             }
3046             n.setName( "NP_001025424" );
3047             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3048                 return false;
3049             }
3050             n.setName( "_NM_001030253-" );
3051             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3052                 return false;
3053             }
3054             n.setName( "XM_002122186" );
3055             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3056                 return false;
3057             }
3058             n.setName( "dgh_AAA34956_gdg" );
3059             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3060                 return false;
3061             }
3062             n.setName( "AAA34956" );
3063             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3064                 return false;
3065             }
3066             n.setName( "GI:394892" );
3067             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3068                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3069                 return false;
3070             }
3071             n.setName( "gi_394892" );
3072             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3073                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3074                 return false;
3075             }
3076             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3077             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3078                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3079                 return false;
3080             }
3081             n.setName( "P12345" );
3082             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3083                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3084                 return false;
3085             }
3086             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3087             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3088                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3089                 return false;
3090             }
3091         }
3092         catch ( final Exception e ) {
3093             e.printStackTrace( System.out );
3094             return false;
3095         }
3096         return true;
3097     }
3098
3099     private static boolean testDataObjects() {
3100         try {
3101             final Confidence s0 = new Confidence();
3102             final Confidence s1 = new Confidence();
3103             if ( !s0.isEqual( s1 ) ) {
3104                 return false;
3105             }
3106             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3107             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3108             if ( s2.isEqual( s1 ) ) {
3109                 return false;
3110             }
3111             if ( !s2.isEqual( s3 ) ) {
3112                 return false;
3113             }
3114             final Confidence s4 = ( Confidence ) s3.copy();
3115             if ( !s4.isEqual( s3 ) ) {
3116                 return false;
3117             }
3118             s3.asSimpleText();
3119             s3.asText();
3120             // Taxonomy
3121             // ----------
3122             final Taxonomy t1 = new Taxonomy();
3123             final Taxonomy t2 = new Taxonomy();
3124             final Taxonomy t3 = new Taxonomy();
3125             final Taxonomy t4 = new Taxonomy();
3126             final Taxonomy t5 = new Taxonomy();
3127             t1.setIdentifier( new Identifier( "ecoli" ) );
3128             t1.setTaxonomyCode( "ECOLI" );
3129             t1.setScientificName( "E. coli" );
3130             t1.setCommonName( "coli" );
3131             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3132             if ( !t1.isEqual( t0 ) ) {
3133                 return false;
3134             }
3135             t2.setIdentifier( new Identifier( "ecoli" ) );
3136             t2.setTaxonomyCode( "OTHER" );
3137             t2.setScientificName( "what" );
3138             t2.setCommonName( "something" );
3139             if ( !t1.isEqual( t2 ) ) {
3140                 return false;
3141             }
3142             t2.setIdentifier( new Identifier( "nemve" ) );
3143             if ( t1.isEqual( t2 ) ) {
3144                 return false;
3145             }
3146             t1.setIdentifier( null );
3147             t3.setTaxonomyCode( "ECOLI" );
3148             t3.setScientificName( "what" );
3149             t3.setCommonName( "something" );
3150             if ( !t1.isEqual( t3 ) ) {
3151                 return false;
3152             }
3153             t1.setIdentifier( null );
3154             t1.setTaxonomyCode( "" );
3155             t4.setScientificName( "E. ColI" );
3156             t4.setCommonName( "something" );
3157             if ( !t1.isEqual( t4 ) ) {
3158                 return false;
3159             }
3160             t4.setScientificName( "B. subtilis" );
3161             t4.setCommonName( "something" );
3162             if ( t1.isEqual( t4 ) ) {
3163                 return false;
3164             }
3165             t1.setIdentifier( null );
3166             t1.setTaxonomyCode( "" );
3167             t1.setScientificName( "" );
3168             t5.setCommonName( "COLI" );
3169             if ( !t1.isEqual( t5 ) ) {
3170                 return false;
3171             }
3172             t5.setCommonName( "vibrio" );
3173             if ( t1.isEqual( t5 ) ) {
3174                 return false;
3175             }
3176             // Identifier
3177             // ----------
3178             final Identifier id0 = new Identifier( "123", "pfam" );
3179             final Identifier id1 = ( Identifier ) id0.copy();
3180             if ( !id1.isEqual( id1 ) ) {
3181                 return false;
3182             }
3183             if ( !id1.isEqual( id0 ) ) {
3184                 return false;
3185             }
3186             if ( !id0.isEqual( id1 ) ) {
3187                 return false;
3188             }
3189             id1.asSimpleText();
3190             id1.asText();
3191             // ProteinDomain
3192             // ---------------
3193             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3194             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3195             if ( !pd1.isEqual( pd1 ) ) {
3196                 return false;
3197             }
3198             if ( !pd1.isEqual( pd0 ) ) {
3199                 return false;
3200             }
3201             pd1.asSimpleText();
3202             pd1.asText();
3203             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3204             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3205             if ( !pd3.isEqual( pd3 ) ) {
3206                 return false;
3207             }
3208             if ( !pd2.isEqual( pd3 ) ) {
3209                 return false;
3210             }
3211             if ( !pd0.isEqual( pd3 ) ) {
3212                 return false;
3213             }
3214             pd3.asSimpleText();
3215             pd3.asText();
3216             // DomainArchitecture
3217             // ------------------
3218             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3219             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3220             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3221             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3222             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3223             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3224             domains0.add( d2 );
3225             domains0.add( d0 );
3226             domains0.add( d3 );
3227             domains0.add( d1 );
3228             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3229             if ( ds0.getNumberOfDomains() != 4 ) {
3230                 return false;
3231             }
3232             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3233             if ( !ds0.isEqual( ds0 ) ) {
3234                 return false;
3235             }
3236             if ( !ds0.isEqual( ds1 ) ) {
3237                 return false;
3238             }
3239             if ( ds1.getNumberOfDomains() != 4 ) {
3240                 return false;
3241             }
3242             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3243             domains1.add( d1 );
3244             domains1.add( d2 );
3245             domains1.add( d4 );
3246             domains1.add( d0 );
3247             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3248             if ( ds0.isEqual( ds2 ) ) {
3249                 return false;
3250             }
3251             ds1.asSimpleText();
3252             ds1.asText();
3253             ds1.toNHX();
3254             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3255             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3256                 System.out.println( ds3.toNHX() );
3257                 return false;
3258             }
3259             if ( ds3.getNumberOfDomains() != 3 ) {
3260                 return false;
3261             }
3262             // Event
3263             // -----
3264             final Event e1 = new Event( Event.EventType.fusion );
3265             if ( e1.isDuplication() ) {
3266                 return false;
3267             }
3268             if ( !e1.isFusion() ) {
3269                 return false;
3270             }
3271             if ( !e1.asText().toString().equals( "fusion" ) ) {
3272                 return false;
3273             }
3274             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3275                 return false;
3276             }
3277             final Event e11 = new Event( Event.EventType.fusion );
3278             if ( !e11.isEqual( e1 ) ) {
3279                 return false;
3280             }
3281             if ( !e11.toNHX().toString().equals( "" ) ) {
3282                 return false;
3283             }
3284             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3285             if ( e2.isDuplication() ) {
3286                 return false;
3287             }
3288             if ( !e2.isSpeciationOrDuplication() ) {
3289                 return false;
3290             }
3291             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3292                 return false;
3293             }
3294             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3295                 return false;
3296             }
3297             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3298                 return false;
3299             }
3300             if ( e11.isEqual( e2 ) ) {
3301                 return false;
3302             }
3303             final Event e2c = ( Event ) e2.copy();
3304             if ( !e2c.isEqual( e2 ) ) {
3305                 return false;
3306             }
3307             Event e3 = new Event( 1, 2, 3 );
3308             if ( e3.isDuplication() ) {
3309                 return false;
3310             }
3311             if ( e3.isSpeciation() ) {
3312                 return false;
3313             }
3314             if ( e3.isGeneLoss() ) {
3315                 return false;
3316             }
3317             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3318                 return false;
3319             }
3320             final Event e3c = ( Event ) e3.copy();
3321             final Event e3cc = ( Event ) e3c.copy();
3322             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3323                 return false;
3324             }
3325             e3 = null;
3326             if ( !e3c.isEqual( e3cc ) ) {
3327                 return false;
3328             }
3329             Event e4 = new Event( 1, 2, 3 );
3330             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3331                 return false;
3332             }
3333             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3334                 return false;
3335             }
3336             final Event e4c = ( Event ) e4.copy();
3337             e4 = null;
3338             final Event e4cc = ( Event ) e4c.copy();
3339             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3340                 return false;
3341             }
3342             if ( !e4c.isEqual( e4cc ) ) {
3343                 return false;
3344             }
3345             final Event e5 = new Event();
3346             if ( !e5.isUnassigned() ) {
3347                 return false;
3348             }
3349             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3350                 return false;
3351             }
3352             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3353                 return false;
3354             }
3355             final Event e6 = new Event( 1, 0, 0 );
3356             if ( !e6.asText().toString().equals( "duplication" ) ) {
3357                 return false;
3358             }
3359             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3360                 return false;
3361             }
3362             final Event e7 = new Event( 0, 1, 0 );
3363             if ( !e7.asText().toString().equals( "speciation" ) ) {
3364                 return false;
3365             }
3366             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3367                 return false;
3368             }
3369             final Event e8 = new Event( 0, 0, 1 );
3370             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3371                 return false;
3372             }
3373             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3374                 return false;
3375             }
3376         }
3377         catch ( final Exception e ) {
3378             e.printStackTrace( System.out );
3379             return false;
3380         }
3381         return true;
3382     }
3383
3384     private static boolean testDeletionOfExternalNodes() {
3385         try {
3386             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3387             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3388             final PhylogenyWriter w = new PhylogenyWriter();
3389             if ( t0.isEmpty() ) {
3390                 return false;
3391             }
3392             if ( t0.getNumberOfExternalNodes() != 1 ) {
3393                 return false;
3394             }
3395             t0.deleteSubtree( t0.getNode( "A" ), false );
3396             if ( t0.getNumberOfExternalNodes() != 0 ) {
3397                 return false;
3398             }
3399             if ( !t0.isEmpty() ) {
3400                 return false;
3401             }
3402             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3403             if ( t1.getNumberOfExternalNodes() != 2 ) {
3404                 return false;
3405             }
3406             t1.deleteSubtree( t1.getNode( "A" ), false );
3407             if ( t1.getNumberOfExternalNodes() != 1 ) {
3408                 return false;
3409             }
3410             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3411                 return false;
3412             }
3413             t1.deleteSubtree( t1.getNode( "B" ), false );
3414             if ( t1.getNumberOfExternalNodes() != 1 ) {
3415                 return false;
3416             }
3417             t1.deleteSubtree( t1.getNode( "r" ), false );
3418             if ( !t1.isEmpty() ) {
3419                 return false;
3420             }
3421             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3422             if ( t2.getNumberOfExternalNodes() != 3 ) {
3423                 return false;
3424             }
3425             t2.deleteSubtree( t2.getNode( "B" ), false );
3426             if ( t2.getNumberOfExternalNodes() != 2 ) {
3427                 return false;
3428             }
3429             t2.toNewHampshireX();
3430             PhylogenyNode n = t2.getNode( "A" );
3431             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3432                 return false;
3433             }
3434             t2.deleteSubtree( t2.getNode( "A" ), false );
3435             if ( t2.getNumberOfExternalNodes() != 2 ) {
3436                 return false;
3437             }
3438             t2.deleteSubtree( t2.getNode( "C" ), true );
3439             if ( t2.getNumberOfExternalNodes() != 1 ) {
3440                 return false;
3441             }
3442             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3443             if ( t3.getNumberOfExternalNodes() != 4 ) {
3444                 return false;
3445             }
3446             t3.deleteSubtree( t3.getNode( "B" ), true );
3447             if ( t3.getNumberOfExternalNodes() != 3 ) {
3448                 return false;
3449             }
3450             n = t3.getNode( "A" );
3451             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3452                 return false;
3453             }
3454             n = n.getNextExternalNode();
3455             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3456                 return false;
3457             }
3458             t3.deleteSubtree( t3.getNode( "A" ), true );
3459             if ( t3.getNumberOfExternalNodes() != 2 ) {
3460                 return false;
3461             }
3462             n = t3.getNode( "C" );
3463             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3464                 return false;
3465             }
3466             t3.deleteSubtree( t3.getNode( "C" ), true );
3467             if ( t3.getNumberOfExternalNodes() != 1 ) {
3468                 return false;
3469             }
3470             t3.deleteSubtree( t3.getNode( "D" ), true );
3471             if ( t3.getNumberOfExternalNodes() != 0 ) {
3472                 return false;
3473             }
3474             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3475             if ( t4.getNumberOfExternalNodes() != 6 ) {
3476                 return false;
3477             }
3478             t4.deleteSubtree( t4.getNode( "B2" ), true );
3479             if ( t4.getNumberOfExternalNodes() != 5 ) {
3480                 return false;
3481             }
3482             String s = w.toNewHampshire( t4, true ).toString();
3483             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3484                 return false;
3485             }
3486             t4.deleteSubtree( t4.getNode( "B11" ), true );
3487             if ( t4.getNumberOfExternalNodes() != 4 ) {
3488                 return false;
3489             }
3490             t4.deleteSubtree( t4.getNode( "C" ), true );
3491             if ( t4.getNumberOfExternalNodes() != 3 ) {
3492                 return false;
3493             }
3494             n = t4.getNode( "A" );
3495             n = n.getNextExternalNode();
3496             if ( !n.getName().equals( "B12" ) ) {
3497                 return false;
3498             }
3499             n = n.getNextExternalNode();
3500             if ( !n.getName().equals( "D" ) ) {
3501                 return false;
3502             }
3503             s = w.toNewHampshire( t4, true ).toString();
3504             if ( !s.equals( "((A,B12),D);" ) ) {
3505                 return false;
3506             }
3507             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3508             t5.deleteSubtree( t5.getNode( "A" ), true );
3509             if ( t5.getNumberOfExternalNodes() != 5 ) {
3510                 return false;
3511             }
3512             s = w.toNewHampshire( t5, true ).toString();
3513             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3514                 return false;
3515             }
3516             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3517             t6.deleteSubtree( t6.getNode( "B11" ), true );
3518             if ( t6.getNumberOfExternalNodes() != 5 ) {
3519                 return false;
3520             }
3521             s = w.toNewHampshire( t6, false ).toString();
3522             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3523                 return false;
3524             }
3525             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3526             t7.deleteSubtree( t7.getNode( "B12" ), true );
3527             if ( t7.getNumberOfExternalNodes() != 5 ) {
3528                 return false;
3529             }
3530             s = w.toNewHampshire( t7, true ).toString();
3531             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3532                 return false;
3533             }
3534             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3535             t8.deleteSubtree( t8.getNode( "B2" ), true );
3536             if ( t8.getNumberOfExternalNodes() != 5 ) {
3537                 return false;
3538             }
3539             s = w.toNewHampshire( t8, false ).toString();
3540             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3541                 return false;
3542             }
3543             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3544             t9.deleteSubtree( t9.getNode( "C" ), true );
3545             if ( t9.getNumberOfExternalNodes() != 5 ) {
3546                 return false;
3547             }
3548             s = w.toNewHampshire( t9, true ).toString();
3549             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3550                 return false;
3551             }
3552             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3553             t10.deleteSubtree( t10.getNode( "D" ), true );
3554             if ( t10.getNumberOfExternalNodes() != 5 ) {
3555                 return false;
3556             }
3557             s = w.toNewHampshire( t10, true ).toString();
3558             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3559                 return false;
3560             }
3561             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3562             t11.deleteSubtree( t11.getNode( "A" ), true );
3563             if ( t11.getNumberOfExternalNodes() != 2 ) {
3564                 return false;
3565             }
3566             s = w.toNewHampshire( t11, true ).toString();
3567             if ( !s.equals( "(B,C);" ) ) {
3568                 return false;
3569             }
3570             t11.deleteSubtree( t11.getNode( "C" ), true );
3571             if ( t11.getNumberOfExternalNodes() != 1 ) {
3572                 return false;
3573             }
3574             s = w.toNewHampshire( t11, false ).toString();
3575             if ( !s.equals( "B;" ) ) {
3576                 return false;
3577             }
3578             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3579             t12.deleteSubtree( t12.getNode( "B2" ), true );
3580             if ( t12.getNumberOfExternalNodes() != 8 ) {
3581                 return false;
3582             }
3583             s = w.toNewHampshire( t12, true ).toString();
3584             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3585                 return false;
3586             }
3587             t12.deleteSubtree( t12.getNode( "B3" ), true );
3588             if ( t12.getNumberOfExternalNodes() != 7 ) {
3589                 return false;
3590             }
3591             s = w.toNewHampshire( t12, true ).toString();
3592             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3593                 return false;
3594             }
3595             t12.deleteSubtree( t12.getNode( "C3" ), true );
3596             if ( t12.getNumberOfExternalNodes() != 6 ) {
3597                 return false;
3598             }
3599             s = w.toNewHampshire( t12, true ).toString();
3600             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3601                 return false;
3602             }
3603             t12.deleteSubtree( t12.getNode( "A1" ), true );
3604             if ( t12.getNumberOfExternalNodes() != 5 ) {
3605                 return false;
3606             }
3607             s = w.toNewHampshire( t12, true ).toString();
3608             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3609                 return false;
3610             }
3611             t12.deleteSubtree( t12.getNode( "B1" ), true );
3612             if ( t12.getNumberOfExternalNodes() != 4 ) {
3613                 return false;
3614             }
3615             s = w.toNewHampshire( t12, true ).toString();
3616             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3617                 return false;
3618             }
3619             t12.deleteSubtree( t12.getNode( "A3" ), true );
3620             if ( t12.getNumberOfExternalNodes() != 3 ) {
3621                 return false;
3622             }
3623             s = w.toNewHampshire( t12, true ).toString();
3624             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3625                 return false;
3626             }
3627             t12.deleteSubtree( t12.getNode( "A2" ), true );
3628             if ( t12.getNumberOfExternalNodes() != 2 ) {
3629                 return false;
3630             }
3631             s = w.toNewHampshire( t12, true ).toString();
3632             if ( !s.equals( "(C1,C2);" ) ) {
3633                 return false;
3634             }
3635             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3636             t13.deleteSubtree( t13.getNode( "D" ), true );
3637             if ( t13.getNumberOfExternalNodes() != 4 ) {
3638                 return false;
3639             }
3640             s = w.toNewHampshire( t13, true ).toString();
3641             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3642                 return false;
3643             }
3644             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3645             t14.deleteSubtree( t14.getNode( "E" ), true );
3646             if ( t14.getNumberOfExternalNodes() != 5 ) {
3647                 return false;
3648             }
3649             s = w.toNewHampshire( t14, true ).toString();
3650             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3651                 return false;
3652             }
3653             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3654             t15.deleteSubtree( t15.getNode( "B2" ), true );
3655             if ( t15.getNumberOfExternalNodes() != 11 ) {
3656                 return false;
3657             }
3658             t15.deleteSubtree( t15.getNode( "B1" ), true );
3659             if ( t15.getNumberOfExternalNodes() != 10 ) {
3660                 return false;
3661             }
3662             t15.deleteSubtree( t15.getNode( "B3" ), true );
3663             if ( t15.getNumberOfExternalNodes() != 9 ) {
3664                 return false;
3665             }
3666             t15.deleteSubtree( t15.getNode( "B4" ), true );
3667             if ( t15.getNumberOfExternalNodes() != 8 ) {
3668                 return false;
3669             }
3670             t15.deleteSubtree( t15.getNode( "A1" ), true );
3671             if ( t15.getNumberOfExternalNodes() != 7 ) {
3672                 return false;
3673             }
3674             t15.deleteSubtree( t15.getNode( "C4" ), true );
3675             if ( t15.getNumberOfExternalNodes() != 6 ) {
3676                 return false;
3677             }
3678         }
3679         catch ( final Exception e ) {
3680             e.printStackTrace( System.out );
3681             return false;
3682         }
3683         return true;
3684     }
3685
3686     private static boolean testDescriptiveStatistics() {
3687         try {
3688             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3689             dss1.addValue( 82 );
3690             dss1.addValue( 78 );
3691             dss1.addValue( 70 );
3692             dss1.addValue( 58 );
3693             dss1.addValue( 42 );
3694             if ( dss1.getN() != 5 ) {
3695                 return false;
3696             }
3697             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3698                 return false;
3699             }
3700             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3701                 return false;
3702             }
3703             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3704                 return false;
3705             }
3706             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3707                 return false;
3708             }
3709             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3710                 return false;
3711             }
3712             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3713                 return false;
3714             }
3715             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3716                 return false;
3717             }
3718             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3719                 return false;
3720             }
3721             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3722                 return false;
3723             }
3724             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3725                 return false;
3726             }
3727             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3728                 return false;
3729             }
3730             dss1.addValue( 123 );
3731             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3732                 return false;
3733             }
3734             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3735                 return false;
3736             }
3737             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3738                 return false;
3739             }
3740             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3741             dss2.addValue( -1.85 );
3742             dss2.addValue( 57.5 );
3743             dss2.addValue( 92.78 );
3744             dss2.addValue( 57.78 );
3745             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3746                 return false;
3747             }
3748             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3749                 return false;
3750             }
3751             final double[] a = dss2.getDataAsDoubleArray();
3752             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3753                 return false;
3754             }
3755             dss2.addValue( -100 );
3756             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3757                 return false;
3758             }
3759             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3760                 return false;
3761             }
3762             final double[] ds = new double[ 14 ];
3763             ds[ 0 ] = 34;
3764             ds[ 1 ] = 23;
3765             ds[ 2 ] = 1;
3766             ds[ 3 ] = 32;
3767             ds[ 4 ] = 11;
3768             ds[ 5 ] = 2;
3769             ds[ 6 ] = 12;
3770             ds[ 7 ] = 33;
3771             ds[ 8 ] = 13;
3772             ds[ 9 ] = 22;
3773             ds[ 10 ] = 21;
3774             ds[ 11 ] = 35;
3775             ds[ 12 ] = 24;
3776             ds[ 13 ] = 31;
3777             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3778             if ( bins.length != 4 ) {
3779                 return false;
3780             }
3781             if ( bins[ 0 ] != 2 ) {
3782                 return false;
3783             }
3784             if ( bins[ 1 ] != 3 ) {
3785                 return false;
3786             }
3787             if ( bins[ 2 ] != 4 ) {
3788                 return false;
3789             }
3790             if ( bins[ 3 ] != 5 ) {
3791                 return false;
3792             }
3793             final double[] ds1 = new double[ 9 ];
3794             ds1[ 0 ] = 10.0;
3795             ds1[ 1 ] = 19.0;
3796             ds1[ 2 ] = 9.999;
3797             ds1[ 3 ] = 0.0;
3798             ds1[ 4 ] = 39.9;
3799             ds1[ 5 ] = 39.999;
3800             ds1[ 6 ] = 30.0;
3801             ds1[ 7 ] = 19.999;
3802             ds1[ 8 ] = 30.1;
3803             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3804             if ( bins1.length != 4 ) {
3805                 return false;
3806             }
3807             if ( bins1[ 0 ] != 2 ) {
3808                 return false;
3809             }
3810             if ( bins1[ 1 ] != 3 ) {
3811                 return false;
3812             }
3813             if ( bins1[ 2 ] != 0 ) {
3814                 return false;
3815             }
3816             if ( bins1[ 3 ] != 4 ) {
3817                 return false;
3818             }
3819             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3820             if ( bins1_1.length != 3 ) {
3821                 return false;
3822             }
3823             if ( bins1_1[ 0 ] != 3 ) {
3824                 return false;
3825             }
3826             if ( bins1_1[ 1 ] != 2 ) {
3827                 return false;
3828             }
3829             if ( bins1_1[ 2 ] != 4 ) {
3830                 return false;
3831             }
3832             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3833             if ( bins1_2.length != 3 ) {
3834                 return false;
3835             }
3836             if ( bins1_2[ 0 ] != 2 ) {
3837                 return false;
3838             }
3839             if ( bins1_2[ 1 ] != 2 ) {
3840                 return false;
3841             }
3842             if ( bins1_2[ 2 ] != 2 ) {
3843                 return false;
3844             }
3845             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3846             dss3.addValue( 1 );
3847             dss3.addValue( 1 );
3848             dss3.addValue( 1 );
3849             dss3.addValue( 2 );
3850             dss3.addValue( 3 );
3851             dss3.addValue( 4 );
3852             dss3.addValue( 5 );
3853             dss3.addValue( 5 );
3854             dss3.addValue( 5 );
3855             dss3.addValue( 6 );
3856             dss3.addValue( 7 );
3857             dss3.addValue( 8 );
3858             dss3.addValue( 9 );
3859             dss3.addValue( 10 );
3860             dss3.addValue( 10 );
3861             dss3.addValue( 10 );
3862             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3863             histo.toStringBuffer( 10, '=', 40, 5 );
3864             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3865         }
3866         catch ( final Exception e ) {
3867             e.printStackTrace( System.out );
3868             return false;
3869         }
3870         return true;
3871     }
3872
3873     private static boolean testDir( final String file ) {
3874         try {
3875             final File f = new File( file );
3876             if ( !f.exists() ) {
3877                 return false;
3878             }
3879             if ( !f.isDirectory() ) {
3880                 return false;
3881             }
3882             if ( !f.canRead() ) {
3883                 return false;
3884             }
3885         }
3886         catch ( final Exception e ) {
3887             return false;
3888         }
3889         return true;
3890     }
3891
3892     private static boolean testEbiEntryRetrieval() {
3893         try {
3894             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
3895             if ( !entry.getAccession().equals( "AAK41263" ) ) {
3896                 System.out.println( entry.getAccession() );
3897                 return false;
3898             }
3899             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
3900                 System.out.println( entry.getTaxonomyScientificName() );
3901                 return false;
3902             }
3903             if ( !entry.getSequenceName()
3904                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
3905                 System.out.println( entry.getSequenceName() );
3906                 return false;
3907             }
3908             // if ( !entry.getSequenceSymbol().equals( "" ) ) {
3909             //     System.out.println( entry.getSequenceSymbol() );
3910             //     return false;
3911             // }
3912             if ( !entry.getGeneName().equals( "treX-like" ) ) {
3913                 System.out.println( entry.getGeneName() );
3914                 return false;
3915             }
3916             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
3917                 System.out.println( entry.getTaxonomyIdentifier() );
3918                 return false;
3919             }
3920             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
3921                 System.out.println( entry.getAnnotations().first().getRefValue() );
3922                 return false;
3923             }
3924             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
3925                 System.out.println( entry.getAnnotations().first().getRefSource() );
3926                 return false;
3927             }
3928             if ( entry.getCrossReferences().size() != 5 ) {
3929                 return false;
3930             }
3931             //
3932             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
3933             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
3934                 return false;
3935             }
3936             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
3937                 System.out.println( entry1.getTaxonomyScientificName() );
3938                 return false;
3939             }
3940             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
3941                 System.out.println( entry1.getSequenceName() );
3942                 return false;
3943             }
3944             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
3945                 System.out.println( entry1.getTaxonomyIdentifier() );
3946                 return false;
3947             }
3948             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
3949                 System.out.println( entry1.getGeneName() );
3950                 return false;
3951             }
3952             if ( entry1.getCrossReferences().size() != 6 ) {
3953                 return false;
3954             }
3955             //
3956             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
3957             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
3958                 return false;
3959             }
3960             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
3961                 System.out.println( entry2.getTaxonomyScientificName() );
3962                 return false;
3963             }
3964             if ( !entry2.getSequenceName()
3965                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
3966                 System.out.println( entry2.getSequenceName() );
3967                 return false;
3968             }
3969             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
3970                 System.out.println( entry2.getTaxonomyIdentifier() );
3971                 return false;
3972             }
3973             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
3974                 System.out.println( entry2.getGeneName() );
3975                 return false;
3976             }
3977             if ( entry2.getCrossReferences().size() != 3 ) {
3978                 return false;
3979             }
3980             //
3981             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
3982             if ( !entry3.getAccession().equals( "HM043801" ) ) {
3983                 return false;
3984             }
3985             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
3986                 System.out.println( entry3.getTaxonomyScientificName() );
3987                 return false;
3988             }
3989             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
3990                 System.out.println( entry3.getSequenceName() );
3991                 return false;
3992             }
3993             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
3994                 System.out.println( entry3.getTaxonomyIdentifier() );
3995                 return false;
3996             }
3997             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
3998                 System.out.println( entry3.getSequenceSymbol() );
3999                 return false;
4000             }
4001             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
4002                 return false;
4003             }
4004             if ( entry3.getCrossReferences().size() != 8 ) {
4005                 return false;
4006             }
4007             //
4008             //
4009             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
4010             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
4011                 return false;
4012             }
4013             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4014                 System.out.println( entry4.getTaxonomyScientificName() );
4015                 return false;
4016             }
4017             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4018                 System.out.println( entry4.getSequenceName() );
4019                 return false;
4020             }
4021             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4022                 System.out.println( entry4.getTaxonomyIdentifier() );
4023                 return false;
4024             }
4025             if ( !entry4.getGeneName().equals( "ras" ) ) {
4026                 System.out.println( entry4.getGeneName() );
4027                 return false;
4028             }
4029             //   if ( !entry4.getChromosome().equals( "ras" ) ) {
4030             //     System.out.println( entry4.getChromosome() );
4031             //     return false;
4032             // }
4033             // if ( !entry4.getMap().equals( "ras" ) ) {
4034             //     System.out.println( entry4.getMap() );
4035             //     return false;
4036             // }
4037             //TODO FIXME gi...
4038             //
4039             //TODO fails:
4040             //            final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "M30539" );
4041             //            if ( !entry5.getAccession().equals( "HM043801" ) ) {
4042             //                return false;
4043             //            }
4044             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4045             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4046                 return false;
4047             }
4048             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4049                 System.out.println( entry5.getTaxonomyScientificName() );
4050                 return false;
4051             }
4052             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4053                 System.out.println( entry5.getSequenceName() );
4054                 return false;
4055             }
4056             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4057                 System.out.println( entry5.getTaxonomyIdentifier() );
4058                 return false;
4059             }
4060         }
4061         catch ( final IOException e ) {
4062             System.out.println();
4063             System.out.println( "the following might be due to absence internet connection:" );
4064             e.printStackTrace( System.out );
4065             return true;
4066         }
4067         catch ( final Exception e ) {
4068             e.printStackTrace();
4069             return false;
4070         }
4071         return true;
4072     }
4073
4074     private static boolean testExternalNodeRelatedMethods() {
4075         try {
4076             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4077             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4078             PhylogenyNode n = t1.getNode( "A" );
4079             n = n.getNextExternalNode();
4080             if ( !n.getName().equals( "B" ) ) {
4081                 return false;
4082             }
4083             n = n.getNextExternalNode();
4084             if ( !n.getName().equals( "C" ) ) {
4085                 return false;
4086             }
4087             n = n.getNextExternalNode();
4088             if ( !n.getName().equals( "D" ) ) {
4089                 return false;
4090             }
4091             n = t1.getNode( "B" );
4092             while ( !n.isLastExternalNode() ) {
4093                 n = n.getNextExternalNode();
4094             }
4095             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4096             n = t2.getNode( "A" );
4097             n = n.getNextExternalNode();
4098             if ( !n.getName().equals( "B" ) ) {
4099                 return false;
4100             }
4101             n = n.getNextExternalNode();
4102             if ( !n.getName().equals( "C" ) ) {
4103                 return false;
4104             }
4105             n = n.getNextExternalNode();
4106             if ( !n.getName().equals( "D" ) ) {
4107                 return false;
4108             }
4109             n = t2.getNode( "B" );
4110             while ( !n.isLastExternalNode() ) {
4111                 n = n.getNextExternalNode();
4112             }
4113             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4114             n = t3.getNode( "A" );
4115             n = n.getNextExternalNode();
4116             if ( !n.getName().equals( "B" ) ) {
4117                 return false;
4118             }
4119             n = n.getNextExternalNode();
4120             if ( !n.getName().equals( "C" ) ) {
4121                 return false;
4122             }
4123             n = n.getNextExternalNode();
4124             if ( !n.getName().equals( "D" ) ) {
4125                 return false;
4126             }
4127             n = n.getNextExternalNode();
4128             if ( !n.getName().equals( "E" ) ) {
4129                 return false;
4130             }
4131             n = n.getNextExternalNode();
4132             if ( !n.getName().equals( "F" ) ) {
4133                 return false;
4134             }
4135             n = n.getNextExternalNode();
4136             if ( !n.getName().equals( "G" ) ) {
4137                 return false;
4138             }
4139             n = n.getNextExternalNode();
4140             if ( !n.getName().equals( "H" ) ) {
4141                 return false;
4142             }
4143             n = t3.getNode( "B" );
4144             while ( !n.isLastExternalNode() ) {
4145                 n = n.getNextExternalNode();
4146             }
4147             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4148             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4149                 final PhylogenyNode node = iter.next();
4150             }
4151             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4152             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4153                 final PhylogenyNode node = iter.next();
4154             }
4155             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4156             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4157             if ( !iter.next().getName().equals( "A" ) ) {
4158                 return false;
4159             }
4160             if ( !iter.next().getName().equals( "B" ) ) {
4161                 return false;
4162             }
4163             if ( !iter.next().getName().equals( "C" ) ) {
4164                 return false;
4165             }
4166             if ( !iter.next().getName().equals( "D" ) ) {
4167                 return false;
4168             }
4169             if ( !iter.next().getName().equals( "E" ) ) {
4170                 return false;
4171             }
4172             if ( !iter.next().getName().equals( "F" ) ) {
4173                 return false;
4174             }
4175             if ( iter.hasNext() ) {
4176                 return false;
4177             }
4178         }
4179         catch ( final Exception e ) {
4180             e.printStackTrace( System.out );
4181             return false;
4182         }
4183         return true;
4184     }
4185
4186     private static boolean testExtractSNFromNodeName() {
4187         try {
4188             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4189                 return false;
4190             }
4191             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4192                 return false;
4193             }
4194             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4195                 return false;
4196             }
4197             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4198                     .equals( "Mus musculus musculus" ) ) {
4199                 return false;
4200             }
4201             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4202                     .equals( "Mus musculus musculus" ) ) {
4203                 return false;
4204             }
4205             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4206                     .equals( "Mus musculus musculus" ) ) {
4207                 return false;
4208             }
4209             if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4210                     .equals( "Mus musculus musculus" ) ) {
4211                 return false;
4212             }
4213             if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4214                 return false;
4215             }
4216             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4217                     .equals( "Mus musculus musculus" ) ) {
4218                 return false;
4219             }
4220             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4221                     .equals( "Mus musculus musculus" ) ) {
4222                 return false;
4223             }
4224             if ( ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
4225                 return false;
4226             }
4227             if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
4228                 return false;
4229             }
4230             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
4231                 return false;
4232             }
4233             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
4234                 return false;
4235             }
4236             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
4237                     .equals( "Mus musculus musculus" ) ) {
4238                 return false;
4239             }
4240             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
4241                 return false;
4242             }
4243             if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
4244                 return false;
4245             }
4246             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
4247                 return false;
4248             }
4249             if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
4250                 return false;
4251             }
4252             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
4253                 return false;
4254             }
4255             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
4256                 return false;
4257             }
4258             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
4259                 return false;
4260             }
4261             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
4262                 return false;
4263             }
4264             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
4265                     .equals( "Mus musculus" ) ) {
4266                 return false;
4267             }
4268             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
4269                     .equals( "Mus musculus" ) ) {
4270                 return false;
4271             }
4272             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4273                 return false;
4274             }
4275             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4276                     .equals( "Mus musculus musculus" ) ) {
4277                 return false;
4278             }
4279             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4280                     .equals( "Mus musculus musculus" ) ) {
4281                 return false;
4282             }
4283             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
4284                     .equals( "Mus musculus musculus" ) ) {
4285                 return false;
4286             }
4287             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4288                 return false;
4289             }
4290             if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
4291                     .equals( "Pilostyles mexicana" ) ) {
4292                 return false;
4293             }
4294             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
4295                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
4296                 return false;
4297             }
4298             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
4299                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4300                 return false;
4301             }
4302             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
4303                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4304                 return false;
4305             }
4306             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
4307                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4308                 return false;
4309             }
4310             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
4311                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4312                 return false;
4313             }
4314             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
4315                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4316                 return false;
4317             }
4318             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
4319                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4320                 return false;
4321             }
4322             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
4323                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4324                 return false;
4325             }
4326             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
4327                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
4328                 return false;
4329             }
4330             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
4331                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
4332                 return false;
4333             }
4334             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
4335                     .equals( "Escherichia coli (strain K12)" ) ) {
4336                 return false;
4337             }
4338             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
4339                     .equals( "Escherichia coli (strain K12)" ) ) {
4340                 return false;
4341             }
4342             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
4343                     .equals( "Escherichia coli (str. K12)" ) ) {
4344                 return false;
4345             }
4346             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
4347                     .equals( "Escherichia coli (str. K12)" ) ) {
4348                 return false;
4349             }
4350             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
4351                     .equals( "Escherichia coli (str. K12)" ) ) {
4352                 return false;
4353             }
4354             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
4355                     .equals( "Escherichia coli (var. K12)" ) ) {
4356                 return false;
4357             }
4358             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K-12 substr. MG1655star" )
4359                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4360                 return false;
4361             }
4362             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star" )
4363                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4364                 return false;
4365             }
4366             if ( !ParserUtils
4367                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star" )
4368                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4369                 return false;
4370             }
4371             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
4372                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4373                 return false;
4374             }
4375             if ( !ParserUtils
4376                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
4377                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4378                 return false;
4379             }
4380             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4381                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4382                 return false;
4383             }
4384             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4385                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4386                 return false;
4387             }
4388             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
4389                 return false;
4390             }
4391             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
4392                 return false;
4393             }
4394             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
4395                 return false;
4396             }
4397             if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
4398                     .equals( "Macrocera sp." ) ) {
4399                 return false;
4400             }
4401             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
4402                 return false;
4403             }
4404             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
4405                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4406                 return false;
4407             }
4408             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
4409                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4410                 return false;
4411             }
4412             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
4413                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4414                 return false;
4415             }
4416             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
4417                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4418                 return false;
4419             }
4420         }
4421         catch ( final Exception e ) {
4422             e.printStackTrace( System.out );
4423             return false;
4424         }
4425         return true;
4426     }
4427
4428     private static boolean testExtractTaxonomyCodeFromNodeName() {
4429         try {
4430             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4431                 return false;
4432             }
4433             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4434                     .equals( "SOYBN" ) ) {
4435                 return false;
4436             }
4437             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4438                     .equals( "ARATH" ) ) {
4439                 return false;
4440             }
4441             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4442                     .equals( "ARATH" ) ) {
4443                 return false;
4444             }
4445             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4446                 return false;
4447             }
4448             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4449                 return false;
4450             }
4451             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4452                 return false;
4453             }
4454             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4455                     .equals( "SOYBN" ) ) {
4456                 return false;
4457             }
4458             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4459                     .equals( "SOYBN" ) ) {
4460                 return false;
4461             }
4462             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4463                     .equals( "SOYBN" ) ) {
4464                 return false;
4465             }
4466             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4467                     .equals( "SOYBN" ) ) {
4468                 return false;
4469             }
4470             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4471                     .equals( "SOYBN" ) ) {
4472                 return false;
4473             }
4474             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4475                     .equals( "SOYBN" ) ) {
4476                 return false;
4477             }
4478             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4479                     .equals( "SOYBN" ) ) {
4480                 return false;
4481             }
4482             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
4483                     .equals( "SOYBN" ) ) {
4484                 return false;
4485             }
4486             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
4487                 return false;
4488             }
4489             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
4490                     .equals( "SOYBN" ) ) {
4491                 return false;
4492             }
4493             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
4494                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
4495                 return false;
4496             }
4497             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
4498                     .equals( "9YX45" ) ) {
4499                 return false;
4500             }
4501             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
4502                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4503                     .equals( "MOUSE" ) ) {
4504                 return false;
4505             }
4506             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
4507                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4508                     .equals( "MOUSE" ) ) {
4509                 return false;
4510             }
4511             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
4512                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4513                     .equals( "MOUSE" ) ) {
4514                 return false;
4515             }
4516             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
4517                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4518                 return false;
4519             }
4520             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
4521                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4522                 return false;
4523             }
4524             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4525                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4526                 return false;
4527             }
4528             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4529                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4530                 return false;
4531             }
4532             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
4533                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4534                 return false;
4535             }
4536             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
4537                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4538                 return false;
4539             }
4540             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
4541                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4542                 return false;
4543             }
4544             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4545                     .equals( "RAT" ) ) {
4546                 return false;
4547             }
4548             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4549                     .equals( "PIG" ) ) {
4550                 return false;
4551             }
4552             if ( !ParserUtils
4553                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4554                     .equals( "MOUSE" ) ) {
4555                 return false;
4556             }
4557             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4558                     .equals( "MOUSE" ) ) {
4559                 return false;
4560             }
4561             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4562                 return false;
4563             }
4564         }
4565         catch ( final Exception e ) {
4566             e.printStackTrace( System.out );
4567             return false;
4568         }
4569         return true;
4570     }
4571
4572     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
4573         try {
4574             PhylogenyNode n = new PhylogenyNode();
4575             n.setName( "tr|B3RJ64" );
4576             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4577                 return false;
4578             }
4579             n.setName( "tr.B3RJ64" );
4580             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4581                 return false;
4582             }
4583             n.setName( "tr=B3RJ64" );
4584             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4585                 return false;
4586             }
4587             n.setName( "tr-B3RJ64" );
4588             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4589                 return false;
4590             }
4591             n.setName( "tr/B3RJ64" );
4592             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4593                 return false;
4594             }
4595             n.setName( "tr\\B3RJ64" );
4596             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4597                 return false;
4598             }
4599             n.setName( "tr_B3RJ64" );
4600             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4601                 return false;
4602             }
4603             n.setName( " tr|B3RJ64 " );
4604             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4605                 return false;
4606             }
4607             n.setName( "-tr|B3RJ64-" );
4608             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4609                 return false;
4610             }
4611             n.setName( "-tr=B3RJ64-" );
4612             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4613                 return false;
4614             }
4615             n.setName( "_tr=B3RJ64_" );
4616             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4617                 return false;
4618             }
4619             n.setName( " tr_tr|B3RJ64_sp|123 " );
4620             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4621                 return false;
4622             }
4623             n.setName( "B3RJ64" );
4624             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4625                 return false;
4626             }
4627             n.setName( "sp|B3RJ64" );
4628             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4629                 return false;
4630             }
4631             n.setName( "sp|B3RJ64C" );
4632             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4633                 return false;
4634             }
4635             n.setName( "sp B3RJ64" );
4636             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4637                 return false;
4638             }
4639             n.setName( "sp|B3RJ6X" );
4640             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4641                 return false;
4642             }
4643             n.setName( "sp|B3RJ6" );
4644             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4645                 return false;
4646             }
4647             n.setName( "K1PYK7_CRAGI" );
4648             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4649                 return false;
4650             }
4651             n.setName( "K1PYK7_PEA" );
4652             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
4653                 return false;
4654             }
4655             n.setName( "K1PYK7_RAT" );
4656             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
4657                 return false;
4658             }
4659             n.setName( "K1PYK7_PIG" );
4660             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4661                 return false;
4662             }
4663             n.setName( "~K1PYK7_PIG~" );
4664             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4665                 return false;
4666             }
4667             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
4668             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4669                 return false;
4670             }
4671             n.setName( "K1PYKX_CRAGI" );
4672             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4673                 return false;
4674             }
4675             n.setName( "XXXXX_CRAGI" );
4676             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
4677                 return false;
4678             }
4679             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
4680             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
4681                 return false;
4682             }
4683             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
4684             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4685                 return false;
4686             }
4687             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
4688             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
4689                 return false;
4690             }
4691             n = new PhylogenyNode();
4692             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
4693             seq.setSymbol( "K1PYK7_CRAGI" );
4694             n.getNodeData().addSequence( seq );
4695             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4696                 return false;
4697             }
4698             seq.setSymbol( "tr|B3RJ64" );
4699             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4700                 return false;
4701             }
4702             n = new PhylogenyNode();
4703             seq = new org.forester.phylogeny.data.Sequence();
4704             seq.setName( "K1PYK7_CRAGI" );
4705             n.getNodeData().addSequence( seq );
4706             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4707                 return false;
4708             }
4709             seq.setName( "tr|B3RJ64" );
4710             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4711                 return false;
4712             }
4713             n = new PhylogenyNode();
4714             seq = new org.forester.phylogeny.data.Sequence();
4715             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4716             n.getNodeData().addSequence( seq );
4717             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
4718                 return false;
4719             }
4720             n = new PhylogenyNode();
4721             seq = new org.forester.phylogeny.data.Sequence();
4722             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4723             n.getNodeData().addSequence( seq );
4724             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4725                 return false;
4726             }
4727             //
4728             n = new PhylogenyNode();
4729             n.setName( "ACP19736" );
4730             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4731                 return false;
4732             }
4733             n = new PhylogenyNode();
4734             n.setName( "|ACP19736|" );
4735             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4736                 return false;
4737             }
4738         }
4739         catch ( final Exception e ) {
4740             e.printStackTrace( System.out );
4741             return false;
4742         }
4743         return true;
4744     }
4745
4746     private static boolean testFastaParser() {
4747         try {
4748             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
4749                 return false;
4750             }
4751             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
4752                 return false;
4753             }
4754             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
4755             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
4756                 return false;
4757             }
4758             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
4759                 return false;
4760             }
4761             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
4762                 return false;
4763             }
4764             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
4765                 return false;
4766             }
4767             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
4768                 return false;
4769             }
4770             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
4771                 return false;
4772             }
4773         }
4774         catch ( final Exception e ) {
4775             e.printStackTrace();
4776             return false;
4777         }
4778         return true;
4779     }
4780
4781     private static boolean testGenbankAccessorParsing() {
4782         //The format for GenBank Accession numbers are:
4783         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
4784         //Protein:    3 letters + 5 numerals
4785         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
4786         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
4787             return false;
4788         }
4789         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
4790             return false;
4791         }
4792         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
4793             return false;
4794         }
4795         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
4796             return false;
4797         }
4798         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
4799             return false;
4800         }
4801         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
4802             return false;
4803         }
4804         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
4805             return false;
4806         }
4807         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
4808             return false;
4809         }
4810         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
4811             return false;
4812         }
4813         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
4814             return false;
4815         }
4816         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
4817             return false;
4818         }
4819         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
4820             return false;
4821         }
4822         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
4823             return false;
4824         }
4825         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
4826             return false;
4827         }
4828         return true;
4829     }
4830
4831     private static boolean testGeneralMsaParser() {
4832         try {
4833             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
4834             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
4835             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
4836             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
4837             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
4838             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
4839             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
4840             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
4841             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4842                 return false;
4843             }
4844             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4845                 return false;
4846             }
4847             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4848                 return false;
4849             }
4850             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4851                 return false;
4852             }
4853             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4854                 return false;
4855             }
4856             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4857                 return false;
4858             }
4859             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4860                 return false;
4861             }
4862             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4863                 return false;
4864             }
4865             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4866                 return false;
4867             }
4868             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4869                 return false;
4870             }
4871             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4872                 return false;
4873             }
4874             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4875                 return false;
4876             }
4877             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
4878             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4879                 return false;
4880             }
4881             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4882                 return false;
4883             }
4884             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4885                 return false;
4886             }
4887             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
4888             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
4889                 return false;
4890             }
4891             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
4892                 return false;
4893             }
4894             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
4895                 return false;
4896             }
4897             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
4898             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4899                 return false;
4900             }
4901             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4902                 return false;
4903             }
4904             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4905                 return false;
4906             }
4907         }
4908         catch ( final Exception e ) {
4909             e.printStackTrace();
4910             return false;
4911         }
4912         return true;
4913     }
4914
4915     private static boolean testGeneralTable() {
4916         try {
4917             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
4918             t0.setValue( 3, 2, "23" );
4919             t0.setValue( 10, 1, "error" );
4920             t0.setValue( 10, 1, "110" );
4921             t0.setValue( 9, 1, "19" );
4922             t0.setValue( 1, 10, "101" );
4923             t0.setValue( 10, 10, "1010" );
4924             t0.setValue( 100, 10, "10100" );
4925             t0.setValue( 0, 0, "00" );
4926             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
4927                 return false;
4928             }
4929             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
4930                 return false;
4931             }
4932             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
4933                 return false;
4934             }
4935             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
4936                 return false;
4937             }
4938             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
4939                 return false;
4940             }
4941             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
4942                 return false;
4943             }
4944             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
4945                 return false;
4946             }
4947             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
4948                 return false;
4949             }
4950             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
4951                 return false;
4952             }
4953             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
4954             t1.setValue( "3", "2", "23" );
4955             t1.setValue( "10", "1", "error" );
4956             t1.setValue( "10", "1", "110" );
4957             t1.setValue( "9", "1", "19" );
4958             t1.setValue( "1", "10", "101" );
4959             t1.setValue( "10", "10", "1010" );
4960             t1.setValue( "100", "10", "10100" );
4961             t1.setValue( "0", "0", "00" );
4962             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
4963             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
4964                 return false;
4965             }
4966             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
4967                 return false;
4968             }
4969             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
4970                 return false;
4971             }
4972             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
4973                 return false;
4974             }
4975             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
4976                 return false;
4977             }
4978             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
4979                 return false;
4980             }
4981             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
4982                 return false;
4983             }
4984             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
4985                 return false;
4986             }
4987             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
4988                 return false;
4989             }
4990             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
4991                 return false;
4992             }
4993         }
4994         catch ( final Exception e ) {
4995             e.printStackTrace( System.out );
4996             return false;
4997         }
4998         return true;
4999     }
5000
5001     private static boolean testGetDistance() {
5002         try {
5003             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5004             final Phylogeny p1 = factory.create( "(((A:1,B:2,X:100)ab:3,C:4)abc:5,(D:7,(E:9,F:10)ef:8)def:6)r",
5005                                                  new NHXParser() )[ 0 ];
5006             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
5007                 return false;
5008             }
5009             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
5010                 return false;
5011             }
5012             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5013                 return false;
5014             }
5015             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5016                 return false;
5017             }
5018             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5019                 return false;
5020             }
5021             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5022                 return false;
5023             }
5024             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5025                 return false;
5026             }
5027             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5028                 return false;
5029             }
5030             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5031                 return false;
5032             }
5033             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5034                 return false;
5035             }
5036             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5037                 return false;
5038             }
5039             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5040                 return false;
5041             }
5042             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5043                 return false;
5044             }
5045             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5046                 return false;
5047             }
5048             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5049                 return false;
5050             }
5051             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5052                 return false;
5053             }
5054             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5055                 return false;
5056             }
5057             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5058                 return false;
5059             }
5060             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5061                 return false;
5062             }
5063             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5064                 return false;
5065             }
5066             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5067                 return false;
5068             }
5069             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5070                 return false;
5071             }
5072             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5073                 return false;
5074             }
5075             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5076                 return false;
5077             }
5078             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5079                 return false;
5080             }
5081             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5082                 return false;
5083             }
5084             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5085                 return false;
5086             }
5087             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5088                 return false;
5089             }
5090             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5091                 return false;
5092             }
5093             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5094                 return false;
5095             }
5096             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5097                 return false;
5098             }
5099             final Phylogeny p2 = factory.create( "((A:4,B:5,C:6)abc:1,(D:7,E:8,F:9)def:2,(G:10,H:11,I:12)ghi:3)r",
5100                                                  new NHXParser() )[ 0 ];
5101             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5102                 return false;
5103             }
5104             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5105                 return false;
5106             }
5107             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5108                 return false;
5109             }
5110             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5111                 return false;
5112             }
5113             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5114                 return false;
5115             }
5116             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5117                 return false;
5118             }
5119             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5120                 return false;
5121             }
5122             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5123                 return false;
5124             }
5125             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5126                 return false;
5127             }
5128             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5129                 return false;
5130             }
5131             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5132                 return false;
5133             }
5134         }
5135         catch ( final Exception e ) {
5136             e.printStackTrace( System.out );
5137             return false;
5138         }
5139         return true;
5140     }
5141
5142     private static boolean testGetLCA() {
5143         try {
5144             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5145             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5146                                                  new NHXParser() )[ 0 ];
5147             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5148             if ( !A.getName().equals( "A" ) ) {
5149                 return false;
5150             }
5151             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5152             if ( !gh.getName().equals( "gh" ) ) {
5153                 return false;
5154             }
5155             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5156             if ( !ab.getName().equals( "ab" ) ) {
5157                 return false;
5158             }
5159             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5160             if ( !ab2.getName().equals( "ab" ) ) {
5161                 return false;
5162             }
5163             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5164             if ( !gh2.getName().equals( "gh" ) ) {
5165                 return false;
5166             }
5167             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5168             if ( !gh3.getName().equals( "gh" ) ) {
5169                 return false;
5170             }
5171             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5172             if ( !abc.getName().equals( "abc" ) ) {
5173                 return false;
5174             }
5175             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5176             if ( !abc2.getName().equals( "abc" ) ) {
5177                 return false;
5178             }
5179             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5180             if ( !abcd.getName().equals( "abcd" ) ) {
5181                 return false;
5182             }
5183             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5184             if ( !abcd2.getName().equals( "abcd" ) ) {
5185                 return false;
5186             }
5187             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5188             if ( !abcdef.getName().equals( "abcdef" ) ) {
5189                 return false;
5190             }
5191             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5192             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5193                 return false;
5194             }
5195             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5196             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5197                 return false;
5198             }
5199             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5200             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5201                 return false;
5202             }
5203             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
5204             if ( !abcde.getName().equals( "abcde" ) ) {
5205                 return false;
5206             }
5207             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
5208             if ( !abcde2.getName().equals( "abcde" ) ) {
5209                 return false;
5210             }
5211             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
5212             if ( !r.getName().equals( "abcdefgh" ) ) {
5213                 return false;
5214             }
5215             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5216             if ( !r2.getName().equals( "abcdefgh" ) ) {
5217                 return false;
5218             }
5219             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5220             if ( !r3.getName().equals( "abcdefgh" ) ) {
5221                 return false;
5222             }
5223             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5224             if ( !abcde3.getName().equals( "abcde" ) ) {
5225                 return false;
5226             }
5227             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5228             if ( !abcde4.getName().equals( "abcde" ) ) {
5229                 return false;
5230             }
5231             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5232             if ( !ab3.getName().equals( "ab" ) ) {
5233                 return false;
5234             }
5235             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5236             if ( !ab4.getName().equals( "ab" ) ) {
5237                 return false;
5238             }
5239             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5240             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5241             if ( !cd.getName().equals( "cd" ) ) {
5242                 return false;
5243             }
5244             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5245             if ( !cd2.getName().equals( "cd" ) ) {
5246                 return false;
5247             }
5248             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5249             if ( !cde.getName().equals( "cde" ) ) {
5250                 return false;
5251             }
5252             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5253             if ( !cde2.getName().equals( "cde" ) ) {
5254                 return false;
5255             }
5256             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5257             if ( !cdef.getName().equals( "cdef" ) ) {
5258                 return false;
5259             }
5260             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5261             if ( !cdef2.getName().equals( "cdef" ) ) {
5262                 return false;
5263             }
5264             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5265             if ( !cdef3.getName().equals( "cdef" ) ) {
5266                 return false;
5267             }
5268             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5269             if ( !rt.getName().equals( "r" ) ) {
5270                 return false;
5271             }
5272             final Phylogeny p3 = factory
5273                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5274                              new NHXParser() )[ 0 ];
5275             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5276             if ( !bc_3.getName().equals( "bc" ) ) {
5277                 return false;
5278             }
5279             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5280             if ( !ac_3.getName().equals( "abc" ) ) {
5281                 return false;
5282             }
5283             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5284             if ( !ad_3.getName().equals( "abcde" ) ) {
5285                 return false;
5286             }
5287             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5288             if ( !af_3.getName().equals( "abcdef" ) ) {
5289                 return false;
5290             }
5291             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5292             if ( !ag_3.getName().equals( "" ) ) {
5293                 return false;
5294             }
5295             if ( !ag_3.isRoot() ) {
5296                 return false;
5297             }
5298             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5299             if ( !al_3.getName().equals( "" ) ) {
5300                 return false;
5301             }
5302             if ( !al_3.isRoot() ) {
5303                 return false;
5304             }
5305             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5306             if ( !kl_3.getName().equals( "" ) ) {
5307                 return false;
5308             }
5309             if ( !kl_3.isRoot() ) {
5310                 return false;
5311             }
5312             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5313             if ( !fl_3.getName().equals( "" ) ) {
5314                 return false;
5315             }
5316             if ( !fl_3.isRoot() ) {
5317                 return false;
5318             }
5319             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5320             if ( !gk_3.getName().equals( "ghijk" ) ) {
5321                 return false;
5322             }
5323             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5324             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5325             if ( !r_4.getName().equals( "r" ) ) {
5326                 return false;
5327             }
5328             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5329             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5330             if ( !r_5.getName().equals( "root" ) ) {
5331                 return false;
5332             }
5333             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5334             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5335             if ( !r_6.getName().equals( "rot" ) ) {
5336                 return false;
5337             }
5338             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5339             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5340             if ( !r_7.getName().equals( "rott" ) ) {
5341                 return false;
5342             }
5343         }
5344         catch ( final Exception e ) {
5345             e.printStackTrace( System.out );
5346             return false;
5347         }
5348         return true;
5349     }
5350
5351     private static boolean testGetLCA2() {
5352         try {
5353             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5354             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5355             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5356             PhylogenyMethods.preOrderReId( p_a );
5357             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5358                                                                                               p_a.getNode( "a" ) );
5359             if ( !p_a_1.getName().equals( "a" ) ) {
5360                 return false;
5361             }
5362             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5363             PhylogenyMethods.preOrderReId( p_b );
5364             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5365                                                                                               p_b.getNode( "a" ) );
5366             if ( !p_b_1.getName().equals( "b" ) ) {
5367                 return false;
5368             }
5369             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5370                                                                                               p_b.getNode( "b" ) );
5371             if ( !p_b_2.getName().equals( "b" ) ) {
5372                 return false;
5373             }
5374             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5375             PhylogenyMethods.preOrderReId( p_c );
5376             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5377                                                                                               p_c.getNode( "a" ) );
5378             if ( !p_c_1.getName().equals( "b" ) ) {
5379                 return false;
5380             }
5381             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5382                                                                                               p_c.getNode( "c" ) );
5383             if ( !p_c_2.getName().equals( "c" ) ) {
5384                 System.out.println( p_c_2.getName() );
5385                 System.exit( -1 );
5386                 return false;
5387             }
5388             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5389                                                                                               p_c.getNode( "b" ) );
5390             if ( !p_c_3.getName().equals( "b" ) ) {
5391                 return false;
5392             }
5393             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5394                                                                                               p_c.getNode( "a" ) );
5395             if ( !p_c_4.getName().equals( "c" ) ) {
5396                 return false;
5397             }
5398             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5399                                                  new NHXParser() )[ 0 ];
5400             PhylogenyMethods.preOrderReId( p1 );
5401             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5402                                                                                           p1.getNode( "A" ) );
5403             if ( !A.getName().equals( "A" ) ) {
5404                 return false;
5405             }
5406             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5407                                                                                            p1.getNode( "gh" ) );
5408             if ( !gh.getName().equals( "gh" ) ) {
5409                 return false;
5410             }
5411             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5412                                                                                            p1.getNode( "B" ) );
5413             if ( !ab.getName().equals( "ab" ) ) {
5414                 return false;
5415             }
5416             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5417                                                                                             p1.getNode( "A" ) );
5418             if ( !ab2.getName().equals( "ab" ) ) {
5419                 return false;
5420             }
5421             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5422                                                                                             p1.getNode( "G" ) );
5423             if ( !gh2.getName().equals( "gh" ) ) {
5424                 return false;
5425             }
5426             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5427                                                                                             p1.getNode( "H" ) );
5428             if ( !gh3.getName().equals( "gh" ) ) {
5429                 return false;
5430             }
5431             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5432                                                                                             p1.getNode( "A" ) );
5433             if ( !abc.getName().equals( "abc" ) ) {
5434                 return false;
5435             }
5436             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5437                                                                                              p1.getNode( "C" ) );
5438             if ( !abc2.getName().equals( "abc" ) ) {
5439                 return false;
5440             }
5441             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5442                                                                                              p1.getNode( "D" ) );
5443             if ( !abcd.getName().equals( "abcd" ) ) {
5444                 return false;
5445             }
5446             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5447                                                                                               p1.getNode( "A" ) );
5448             if ( !abcd2.getName().equals( "abcd" ) ) {
5449                 return false;
5450             }
5451             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5452                                                                                                p1.getNode( "F" ) );
5453             if ( !abcdef.getName().equals( "abcdef" ) ) {
5454                 return false;
5455             }
5456             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5457                                                                                                 p1.getNode( "A" ) );
5458             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5459                 return false;
5460             }
5461             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5462                                                                                                 p1.getNode( "F" ) );
5463             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5464                 return false;
5465             }
5466             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5467                                                                                                 p1.getNode( "ab" ) );
5468             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5469                 return false;
5470             }
5471             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5472                                                                                               p1.getNode( "E" ) );
5473             if ( !abcde.getName().equals( "abcde" ) ) {
5474                 return false;
5475             }
5476             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5477                                                                                                p1.getNode( "A" ) );
5478             if ( !abcde2.getName().equals( "abcde" ) ) {
5479                 return false;
5480             }
5481             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
5482                                                                                           p1.getNode( "abcdefgh" ) );
5483             if ( !r.getName().equals( "abcdefgh" ) ) {
5484                 return false;
5485             }
5486             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5487                                                                                            p1.getNode( "H" ) );
5488             if ( !r2.getName().equals( "abcdefgh" ) ) {
5489                 return false;
5490             }
5491             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5492                                                                                            p1.getNode( "A" ) );
5493             if ( !r3.getName().equals( "abcdefgh" ) ) {
5494                 return false;
5495             }
5496             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5497                                                                                                p1.getNode( "abcde" ) );
5498             if ( !abcde3.getName().equals( "abcde" ) ) {
5499                 return false;
5500             }
5501             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
5502                                                                                                p1.getNode( "E" ) );
5503             if ( !abcde4.getName().equals( "abcde" ) ) {
5504                 return false;
5505             }
5506             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5507                                                                                             p1.getNode( "B" ) );
5508             if ( !ab3.getName().equals( "ab" ) ) {
5509                 return false;
5510             }
5511             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5512                                                                                             p1.getNode( "ab" ) );
5513             if ( !ab4.getName().equals( "ab" ) ) {
5514                 return false;
5515             }
5516             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5517             PhylogenyMethods.preOrderReId( p2 );
5518             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5519                                                                                            p2.getNode( "d" ) );
5520             if ( !cd.getName().equals( "cd" ) ) {
5521                 return false;
5522             }
5523             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5524                                                                                             p2.getNode( "c" ) );
5525             if ( !cd2.getName().equals( "cd" ) ) {
5526                 return false;
5527             }
5528             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5529                                                                                             p2.getNode( "e" ) );
5530             if ( !cde.getName().equals( "cde" ) ) {
5531                 return false;
5532             }
5533             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
5534                                                                                              p2.getNode( "c" ) );
5535             if ( !cde2.getName().equals( "cde" ) ) {
5536                 return false;
5537             }
5538             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5539                                                                                              p2.getNode( "f" ) );
5540             if ( !cdef.getName().equals( "cdef" ) ) {
5541                 return false;
5542             }
5543             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5544                                                                                               p2.getNode( "f" ) );
5545             if ( !cdef2.getName().equals( "cdef" ) ) {
5546                 return false;
5547             }
5548             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
5549                                                                                               p2.getNode( "d" ) );
5550             if ( !cdef3.getName().equals( "cdef" ) ) {
5551                 return false;
5552             }
5553             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5554                                                                                            p2.getNode( "a" ) );
5555             if ( !rt.getName().equals( "r" ) ) {
5556                 return false;
5557             }
5558             final Phylogeny p3 = factory
5559                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5560                              new NHXParser() )[ 0 ];
5561             PhylogenyMethods.preOrderReId( p3 );
5562             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
5563                                                                                              p3.getNode( "c" ) );
5564             if ( !bc_3.getName().equals( "bc" ) ) {
5565                 return false;
5566             }
5567             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5568                                                                                              p3.getNode( "c" ) );
5569             if ( !ac_3.getName().equals( "abc" ) ) {
5570                 return false;
5571             }
5572             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5573                                                                                              p3.getNode( "d" ) );
5574             if ( !ad_3.getName().equals( "abcde" ) ) {
5575                 return false;
5576             }
5577             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5578                                                                                              p3.getNode( "f" ) );
5579             if ( !af_3.getName().equals( "abcdef" ) ) {
5580                 return false;
5581             }
5582             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5583                                                                                              p3.getNode( "g" ) );
5584             if ( !ag_3.getName().equals( "" ) ) {
5585                 return false;
5586             }
5587             if ( !ag_3.isRoot() ) {
5588                 return false;
5589             }
5590             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5591                                                                                              p3.getNode( "l" ) );
5592             if ( !al_3.getName().equals( "" ) ) {
5593                 return false;
5594             }
5595             if ( !al_3.isRoot() ) {
5596                 return false;
5597             }
5598             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
5599                                                                                              p3.getNode( "l" ) );
5600             if ( !kl_3.getName().equals( "" ) ) {
5601                 return false;
5602             }
5603             if ( !kl_3.isRoot() ) {
5604                 return false;
5605             }
5606             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
5607                                                                                              p3.getNode( "l" ) );
5608             if ( !fl_3.getName().equals( "" ) ) {
5609                 return false;
5610             }
5611             if ( !fl_3.isRoot() ) {
5612                 return false;
5613             }
5614             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
5615                                                                                              p3.getNode( "k" ) );
5616             if ( !gk_3.getName().equals( "ghijk" ) ) {
5617                 return false;
5618             }
5619             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5620             PhylogenyMethods.preOrderReId( p4 );
5621             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
5622                                                                                             p4.getNode( "c" ) );
5623             if ( !r_4.getName().equals( "r" ) ) {
5624                 return false;
5625             }
5626             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5627             PhylogenyMethods.preOrderReId( p5 );
5628             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
5629                                                                                             p5.getNode( "c" ) );
5630             if ( !r_5.getName().equals( "root" ) ) {
5631                 return false;
5632             }
5633             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5634             PhylogenyMethods.preOrderReId( p6 );
5635             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
5636                                                                                             p6.getNode( "a" ) );
5637             if ( !r_6.getName().equals( "rot" ) ) {
5638                 return false;
5639             }
5640             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5641             PhylogenyMethods.preOrderReId( p7 );
5642             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
5643                                                                                             p7.getNode( "e" ) );
5644             if ( !r_7.getName().equals( "rott" ) ) {
5645                 return false;
5646             }
5647             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5648                                                                                              p7.getNode( "a" ) );
5649             if ( !r_71.getName().equals( "rott" ) ) {
5650                 return false;
5651             }
5652             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5653                                                                                              p7.getNode( "rott" ) );
5654             if ( !r_72.getName().equals( "rott" ) ) {
5655                 return false;
5656             }
5657             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5658                                                                                              p7.getNode( "a" ) );
5659             if ( !r_73.getName().equals( "rott" ) ) {
5660                 return false;
5661             }
5662             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5663                                                                                              p7.getNode( "rott" ) );
5664             if ( !r_74.getName().equals( "rott" ) ) {
5665                 return false;
5666             }
5667             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5668                                                                                              p7.getNode( "e" ) );
5669             if ( !r_75.getName().equals( "e" ) ) {
5670                 return false;
5671             }
5672         }
5673         catch ( final Exception e ) {
5674             e.printStackTrace( System.out );
5675             return false;
5676         }
5677         return true;
5678     }
5679
5680     private static boolean testHmmscanOutputParser() {
5681         final String test_dir = Test.PATH_TO_TEST_DATA;
5682         try {
5683             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
5684                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5685             parser1.parse();
5686             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
5687                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5688             final List<Protein> proteins = parser2.parse();
5689             if ( parser2.getProteinsEncountered() != 4 ) {
5690                 return false;
5691             }
5692             if ( proteins.size() != 4 ) {
5693                 return false;
5694             }
5695             if ( parser2.getDomainsEncountered() != 69 ) {
5696                 return false;
5697             }
5698             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
5699                 return false;
5700             }
5701             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
5702                 return false;
5703             }
5704             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
5705                 return false;
5706             }
5707             final Protein p1 = proteins.get( 0 );
5708             if ( p1.getNumberOfProteinDomains() != 15 ) {
5709                 return false;
5710             }
5711             if ( p1.getLength() != 850 ) {
5712                 return false;
5713             }
5714             final Protein p2 = proteins.get( 1 );
5715             if ( p2.getNumberOfProteinDomains() != 51 ) {
5716                 return false;
5717             }
5718             if ( p2.getLength() != 1291 ) {
5719                 return false;
5720             }
5721             final Protein p3 = proteins.get( 2 );
5722             if ( p3.getNumberOfProteinDomains() != 2 ) {
5723                 return false;
5724             }
5725             final Protein p4 = proteins.get( 3 );
5726             if ( p4.getNumberOfProteinDomains() != 1 ) {
5727                 return false;
5728             }
5729             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
5730                 return false;
5731             }
5732             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
5733                 return false;
5734             }
5735             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
5736                 return false;
5737             }
5738             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
5739                 return false;
5740             }
5741             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
5742                 return false;
5743             }
5744             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
5745                 return false;
5746             }
5747             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
5748                 return false;
5749             }
5750         }
5751         catch ( final Exception e ) {
5752             e.printStackTrace( System.out );
5753             return false;
5754         }
5755         return true;
5756     }
5757
5758     private static boolean testLastExternalNodeMethods() {
5759         try {
5760             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5761             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
5762             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
5763             final PhylogenyNode n1 = t0.getNode( "A" );
5764             if ( n1.isLastExternalNode() ) {
5765                 return false;
5766             }
5767             final PhylogenyNode n2 = t0.getNode( "B" );
5768             if ( n2.isLastExternalNode() ) {
5769                 return false;
5770             }
5771             final PhylogenyNode n3 = t0.getNode( "C" );
5772             if ( n3.isLastExternalNode() ) {
5773                 return false;
5774             }
5775             final PhylogenyNode n4 = t0.getNode( "D" );
5776             if ( !n4.isLastExternalNode() ) {
5777                 return false;
5778             }
5779         }
5780         catch ( final Exception e ) {
5781             e.printStackTrace( System.out );
5782             return false;
5783         }
5784         return true;
5785     }
5786
5787     private static boolean testLevelOrderIterator() {
5788         try {
5789             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5790             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5791             PhylogenyNodeIterator it0;
5792             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
5793                 it0.next();
5794             }
5795             for( it0.reset(); it0.hasNext(); ) {
5796                 it0.next();
5797             }
5798             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
5799             if ( !it.next().getName().equals( "r" ) ) {
5800                 return false;
5801             }
5802             if ( !it.next().getName().equals( "ab" ) ) {
5803                 return false;
5804             }
5805             if ( !it.next().getName().equals( "cd" ) ) {
5806                 return false;
5807             }
5808             if ( !it.next().getName().equals( "A" ) ) {
5809                 return false;
5810             }
5811             if ( !it.next().getName().equals( "B" ) ) {
5812                 return false;
5813             }
5814             if ( !it.next().getName().equals( "C" ) ) {
5815                 return false;
5816             }
5817             if ( !it.next().getName().equals( "D" ) ) {
5818                 return false;
5819             }
5820             if ( it.hasNext() ) {
5821                 return false;
5822             }
5823             final Phylogeny t2 = factory.create( "(((1,2,(a,(X,Y,Z)b)3,4,5,6)A,B,C)abc,(D,E,(f1,(f21)f2,f3)F,G)defg)r",
5824                                                  new NHXParser() )[ 0 ];
5825             PhylogenyNodeIterator it2;
5826             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
5827                 it2.next();
5828             }
5829             for( it2.reset(); it2.hasNext(); ) {
5830                 it2.next();
5831             }
5832             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
5833             if ( !it3.next().getName().equals( "r" ) ) {
5834                 return false;
5835             }
5836             if ( !it3.next().getName().equals( "abc" ) ) {
5837                 return false;
5838             }
5839             if ( !it3.next().getName().equals( "defg" ) ) {
5840                 return false;
5841             }
5842             if ( !it3.next().getName().equals( "A" ) ) {
5843                 return false;
5844             }
5845             if ( !it3.next().getName().equals( "B" ) ) {
5846                 return false;
5847             }
5848             if ( !it3.next().getName().equals( "C" ) ) {
5849                 return false;
5850             }
5851             if ( !it3.next().getName().equals( "D" ) ) {
5852                 return false;
5853             }
5854             if ( !it3.next().getName().equals( "E" ) ) {
5855                 return false;
5856             }
5857             if ( !it3.next().getName().equals( "F" ) ) {
5858                 return false;
5859             }
5860             if ( !it3.next().getName().equals( "G" ) ) {
5861                 return false;
5862             }
5863             if ( !it3.next().getName().equals( "1" ) ) {
5864                 return false;
5865             }
5866             if ( !it3.next().getName().equals( "2" ) ) {
5867                 return false;
5868             }
5869             if ( !it3.next().getName().equals( "3" ) ) {
5870                 return false;
5871             }
5872             if ( !it3.next().getName().equals( "4" ) ) {
5873                 return false;
5874             }
5875             if ( !it3.next().getName().equals( "5" ) ) {
5876                 return false;
5877             }
5878             if ( !it3.next().getName().equals( "6" ) ) {
5879                 return false;
5880             }
5881             if ( !it3.next().getName().equals( "f1" ) ) {
5882                 return false;
5883             }
5884             if ( !it3.next().getName().equals( "f2" ) ) {
5885                 return false;
5886             }
5887             if ( !it3.next().getName().equals( "f3" ) ) {
5888                 return false;
5889             }
5890             if ( !it3.next().getName().equals( "a" ) ) {
5891                 return false;
5892             }
5893             if ( !it3.next().getName().equals( "b" ) ) {
5894                 return false;
5895             }
5896             if ( !it3.next().getName().equals( "f21" ) ) {
5897                 return false;
5898             }
5899             if ( !it3.next().getName().equals( "X" ) ) {
5900                 return false;
5901             }
5902             if ( !it3.next().getName().equals( "Y" ) ) {
5903                 return false;
5904             }
5905             if ( !it3.next().getName().equals( "Z" ) ) {
5906                 return false;
5907             }
5908             if ( it3.hasNext() ) {
5909                 return false;
5910             }
5911             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
5912             PhylogenyNodeIterator it4;
5913             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
5914                 it4.next();
5915             }
5916             for( it4.reset(); it4.hasNext(); ) {
5917                 it4.next();
5918             }
5919             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
5920             if ( !it5.next().getName().equals( "r" ) ) {
5921                 return false;
5922             }
5923             if ( !it5.next().getName().equals( "A" ) ) {
5924                 return false;
5925             }
5926             if ( !it5.next().getName().equals( "B" ) ) {
5927                 return false;
5928             }
5929             if ( !it5.next().getName().equals( "C" ) ) {
5930                 return false;
5931             }
5932             if ( !it5.next().getName().equals( "D" ) ) {
5933                 return false;
5934             }
5935             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
5936             PhylogenyNodeIterator it6;
5937             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
5938                 it6.next();
5939             }
5940             for( it6.reset(); it6.hasNext(); ) {
5941                 it6.next();
5942             }
5943             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
5944             if ( !it7.next().getName().equals( "A" ) ) {
5945                 return false;
5946             }
5947             if ( it.hasNext() ) {
5948                 return false;
5949             }
5950         }
5951         catch ( final Exception e ) {
5952             e.printStackTrace( System.out );
5953             return false;
5954         }
5955         return true;
5956     }
5957
5958     private static boolean testMafft( final String path ) {
5959         try {
5960             final List<String> opts = new ArrayList<String>();
5961             opts.add( "--maxiterate" );
5962             opts.add( "1000" );
5963             opts.add( "--localpair" );
5964             opts.add( "--quiet" );
5965             Msa msa = null;
5966             final MsaInferrer mafft = Mafft.createInstance( path );
5967             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
5968             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
5969                 return false;
5970             }
5971             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
5972                 return false;
5973             }
5974         }
5975         catch ( final Exception e ) {
5976             e.printStackTrace( System.out );
5977             return false;
5978         }
5979         return true;
5980     }
5981
5982     private static boolean testMidpointrooting() {
5983         try {
5984             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5985             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
5986             PhylogenyMethods.midpointRoot( t0 );
5987             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
5988                 return false;
5989             }
5990             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
5991                 return false;
5992             }
5993             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
5994                            1 ) ) {
5995                 return false;
5996             }
5997             final Phylogeny t1 = factory.create( "((A:1,B:2)AB:1[&&NHX:B=55],(C:3,D:4)CD:3[&&NHX:B=10])ABCD:0.5",
5998                                                  new NHXParser() )[ 0 ];
5999             if ( !t1.isRooted() ) {
6000                 return false;
6001             }
6002             PhylogenyMethods.midpointRoot( t1 );
6003             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6004                 return false;
6005             }
6006             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6007                 return false;
6008             }
6009             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6010                 return false;
6011             }
6012             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6013                 return false;
6014             }
6015             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6016                 return false;
6017             }
6018             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6019                 return false;
6020             }
6021             t1.reRoot( t1.getNode( "A" ) );
6022             PhylogenyMethods.midpointRoot( t1 );
6023             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6024                 return false;
6025             }
6026             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6027                 return false;
6028             }
6029             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6030                 return false;
6031             }
6032             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6033                 return false;
6034             }
6035             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6036                 System.exit( -1 );
6037                 return false;
6038             }
6039             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6040                 return false;
6041             }
6042         }
6043         catch ( final Exception e ) {
6044             e.printStackTrace( System.out );
6045             return false;
6046         }
6047         return true;
6048     }
6049
6050     private static boolean testMsaQualityMethod() {
6051         try {
6052             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6053             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6054             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6055             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6056             final List<Sequence> l = new ArrayList<Sequence>();
6057             l.add( s0 );
6058             l.add( s1 );
6059             l.add( s2 );
6060             l.add( s3 );
6061             final Msa msa = BasicMsa.createInstance( l );
6062             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6063                 return false;
6064             }
6065             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6066                 return false;
6067             }
6068             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6069                 return false;
6070             }
6071             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6072                 return false;
6073             }
6074             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6075                 return false;
6076             }
6077             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6078                 return false;
6079             }
6080             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6081                 return false;
6082             }
6083         }
6084         catch ( final Exception e ) {
6085             e.printStackTrace( System.out );
6086             return false;
6087         }
6088         return true;
6089     }
6090
6091     private static boolean testDeleteableMsa() {
6092         try {
6093             final Sequence s0 = BasicSequence.createAaSequence( "a", "AAAA" );
6094             final Sequence s1 = BasicSequence.createAaSequence( "b", "BAAA" );
6095             final Sequence s2 = BasicSequence.createAaSequence( "c", "CAAA" );
6096             final Sequence s3 = BasicSequence.createAaSequence( "d", "DAAA" );
6097             final Sequence s4 = BasicSequence.createAaSequence( "e", "EAAA" );
6098             final Sequence s5 = BasicSequence.createAaSequence( "f", "FAAA" );
6099             final List<Sequence> l0 = new ArrayList<Sequence>();
6100             l0.add( s0 );
6101             l0.add( s1 );
6102             l0.add( s2 );
6103             l0.add( s3 );
6104             l0.add( s4 );
6105             l0.add( s5 );
6106             final DeleteableMsa dmsa0 = DeleteableMsa.createInstance( l0 );
6107             dmsa0.deleteRow( "b", false );
6108             if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) {
6109                 return false;
6110             }
6111             dmsa0.deleteRow( "e", false );
6112             dmsa0.deleteRow( "a", false );
6113             dmsa0.deleteRow( "f", false );
6114             if ( dmsa0.getLength() != 4 ) {
6115                 return false;
6116             }
6117             if ( dmsa0.getNumberOfSequences() != 2 ) {
6118                 return false;
6119             }
6120             if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) {
6121                 return false;
6122             }
6123             if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) {
6124                 return false;
6125             }
6126             if ( dmsa0.getResidueAt( 0, 0 ) != 'C' ) {
6127                 return false;
6128             }
6129             if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" ) ) {
6130                 return false;
6131             }
6132             if ( dmsa0.getColumnAt( 0 ).size() != 2 ) {
6133                 return false;
6134             }
6135             dmsa0.deleteRow( "c", false );
6136             dmsa0.deleteRow( "d", false );
6137             if ( dmsa0.getNumberOfSequences() != 0 ) {
6138                 return false;
6139             }
6140             //
6141             final Sequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C--X----" );
6142             final Sequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C-------" );
6143             final Sequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C------Z" );
6144             final Sequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C-------" );
6145             final Sequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C-------" );
6146             final Sequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--Y---" );
6147             final List<Sequence> l1 = new ArrayList<Sequence>();
6148             l1.add( s_0 );
6149             l1.add( s_1 );
6150             l1.add( s_2 );
6151             l1.add( s_3 );
6152             l1.add( s_4 );
6153             l1.add( s_5 );
6154             final DeleteableMsa dmsa1 = DeleteableMsa.createInstance( l1 );
6155             dmsa1.deleteGapOnlyColumns();
6156             dmsa1.deleteRow( "a", false );
6157             dmsa1.deleteRow( "f", false );
6158             dmsa1.deleteRow( "d", false );
6159             dmsa1.deleteGapOnlyColumns();
6160             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C-" ) ) {
6161                 return false;
6162             }
6163             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "CABCZ" ) ) {
6164                 return false;
6165             }
6166             if ( !dmsa1.getSequenceAsString( 2 ).toString().equals( "EAAC-" ) ) {
6167                 return false;
6168             }
6169             dmsa1.deleteRow( "c", false );
6170             dmsa1.deleteGapOnlyColumns();
6171             final Writer w0 = new StringWriter();
6172             dmsa1.write( w0, MSA_FORMAT.FASTA );
6173             final Writer w1 = new StringWriter();
6174             dmsa1.write( w1, MSA_FORMAT.PHYLIP );
6175             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C" ) ) {
6176                 return false;
6177             }
6178             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "EAAC" ) ) {
6179                 return false;
6180             }
6181             //
6182             final Sequence s__0 = BasicSequence.createAaSequence( "a", "A------" );
6183             final Sequence s__1 = BasicSequence.createAaSequence( "b", "BB-----" );
6184             final Sequence s__2 = BasicSequence.createAaSequence( "c", "CCC----" );
6185             final Sequence s__3 = BasicSequence.createAaSequence( "d", "DDDD---" );
6186             final Sequence s__4 = BasicSequence.createAaSequence( "e", "EEEEE--" );
6187             final Sequence s__5 = BasicSequence.createAaSequence( "f", "FFFFFF-" );
6188             final List<Sequence> l2 = new ArrayList<Sequence>();
6189             l2.add( s__0 );
6190             l2.add( s__1 );
6191             l2.add( s__2 );
6192             l2.add( s__3 );
6193             l2.add( s__4 );
6194             l2.add( s__5 );
6195             final DeleteableMsa dmsa2 = DeleteableMsa.createInstance( l2 );
6196             dmsa2.deleteGapColumns( 0.5 );
6197             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A---" ) ) {
6198                 return false;
6199             }
6200             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB--" ) ) {
6201                 return false;
6202             }
6203             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CCC-" ) ) {
6204                 return false;
6205             }
6206             dmsa2.deleteGapColumns( 0.2 );
6207             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A-" ) ) {
6208                 return false;
6209             }
6210             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB" ) ) {
6211                 return false;
6212             }
6213             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CC" ) ) {
6214                 return false;
6215             }
6216             dmsa2.deleteGapColumns( 0 );
6217             dmsa2.deleteRow( "a", false );
6218             dmsa2.deleteRow( "b", false );
6219             dmsa2.deleteRow( "f", false );
6220             dmsa2.deleteRow( "e", false );
6221             dmsa2.setIdentifier( 0, "new_c" );
6222             dmsa2.setIdentifier( 1, "new_d" );
6223             dmsa2.setResidueAt( 0, 0, 'x' );
6224             final Sequence s = dmsa2.deleteRow( "new_d", true );
6225             if ( !s.getMolecularSequenceAsString().equals( "D" ) ) {
6226                 return false;
6227             }
6228             final Writer w = new StringWriter();
6229             dmsa2.write( w, MSA_FORMAT.PHYLIP );
6230             final String phylip = w.toString();
6231             if ( !phylip.equals( "new_c x" + ForesterUtil.LINE_SEPARATOR ) ) {
6232                 return false;
6233             }
6234             final Writer w2 = new StringWriter();
6235             dmsa2.write( w2, MSA_FORMAT.FASTA );
6236             final String fasta = w2.toString();
6237             if ( !fasta.equals( ">new_c" + ForesterUtil.LINE_SEPARATOR + "x" + ForesterUtil.LINE_SEPARATOR ) ) {
6238                 return false;
6239             }
6240         }
6241         catch ( final Exception e ) {
6242             e.printStackTrace( System.out );
6243             return false;
6244         }
6245         return true;
6246     }
6247
6248     private static boolean testNextNodeWithCollapsing() {
6249         try {
6250             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6251             PhylogenyNode n;
6252             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
6253             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6254             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
6255             t0.getNode( "cd" ).setCollapse( true );
6256             t0.getNode( "cde" ).setCollapse( true );
6257             n = t0.getFirstExternalNode();
6258             while ( n != null ) {
6259                 ext.add( n );
6260                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6261             }
6262             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6263                 return false;
6264             }
6265             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6266                 return false;
6267             }
6268             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
6269                 return false;
6270             }
6271             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
6272                 return false;
6273             }
6274             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
6275                 return false;
6276             }
6277             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
6278                 return false;
6279             }
6280             ext.clear();
6281             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6282             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
6283             t1.getNode( "ab" ).setCollapse( true );
6284             t1.getNode( "cd" ).setCollapse( true );
6285             t1.getNode( "cde" ).setCollapse( true );
6286             n = t1.getNode( "ab" );
6287             ext = new ArrayList<PhylogenyNode>();
6288             while ( n != null ) {
6289                 ext.add( n );
6290                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6291             }
6292             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6293                 return false;
6294             }
6295             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6296                 return false;
6297             }
6298             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6299                 return false;
6300             }
6301             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
6302                 return false;
6303             }
6304             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
6305                 return false;
6306             }
6307             //
6308             //
6309             ext.clear();
6310             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6311             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
6312             t2.getNode( "ab" ).setCollapse( true );
6313             t2.getNode( "cd" ).setCollapse( true );
6314             t2.getNode( "cde" ).setCollapse( true );
6315             t2.getNode( "c" ).setCollapse( true );
6316             t2.getNode( "d" ).setCollapse( true );
6317             t2.getNode( "e" ).setCollapse( true );
6318             t2.getNode( "gh" ).setCollapse( true );
6319             n = t2.getNode( "ab" );
6320             ext = new ArrayList<PhylogenyNode>();
6321             while ( n != null ) {
6322                 ext.add( n );
6323                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6324             }
6325             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6326                 return false;
6327             }
6328             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6329                 return false;
6330             }
6331             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6332                 return false;
6333             }
6334             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
6335                 return false;
6336             }
6337             //
6338             //
6339             ext.clear();
6340             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6341             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
6342             t3.getNode( "ab" ).setCollapse( true );
6343             t3.getNode( "cd" ).setCollapse( true );
6344             t3.getNode( "cde" ).setCollapse( true );
6345             t3.getNode( "c" ).setCollapse( true );
6346             t3.getNode( "d" ).setCollapse( true );
6347             t3.getNode( "e" ).setCollapse( true );
6348             t3.getNode( "gh" ).setCollapse( true );
6349             t3.getNode( "fgh" ).setCollapse( true );
6350             n = t3.getNode( "ab" );
6351             ext = new ArrayList<PhylogenyNode>();
6352             while ( n != null ) {
6353                 ext.add( n );
6354                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6355             }
6356             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6357                 return false;
6358             }
6359             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6360                 return false;
6361             }
6362             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
6363                 return false;
6364             }
6365             //
6366             //
6367             ext.clear();
6368             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6369             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
6370             t4.getNode( "ab" ).setCollapse( true );
6371             t4.getNode( "cd" ).setCollapse( true );
6372             t4.getNode( "cde" ).setCollapse( true );
6373             t4.getNode( "c" ).setCollapse( true );
6374             t4.getNode( "d" ).setCollapse( true );
6375             t4.getNode( "e" ).setCollapse( true );
6376             t4.getNode( "gh" ).setCollapse( true );
6377             t4.getNode( "fgh" ).setCollapse( true );
6378             t4.getNode( "abcdefgh" ).setCollapse( true );
6379             n = t4.getNode( "abcdefgh" );
6380             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
6381                 return false;
6382             }
6383             //
6384             //
6385             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6386             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
6387             ext.clear();
6388             n = t5.getFirstExternalNode();
6389             while ( n != null ) {
6390                 ext.add( n );
6391                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6392             }
6393             if ( ext.size() != 8 ) {
6394                 return false;
6395             }
6396             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6397                 return false;
6398             }
6399             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6400                 return false;
6401             }
6402             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6403                 return false;
6404             }
6405             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6406                 return false;
6407             }
6408             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6409                 return false;
6410             }
6411             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6412                 return false;
6413             }
6414             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
6415                 return false;
6416             }
6417             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
6418                 return false;
6419             }
6420             //
6421             //
6422             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6423             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
6424             ext.clear();
6425             t6.getNode( "ab" ).setCollapse( true );
6426             n = t6.getNode( "ab" );
6427             while ( n != null ) {
6428                 ext.add( n );
6429                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6430             }
6431             if ( ext.size() != 7 ) {
6432                 return false;
6433             }
6434             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6435                 return false;
6436             }
6437             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6438                 return false;
6439             }
6440             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6441                 return false;
6442             }
6443             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6444                 return false;
6445             }
6446             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6447                 return false;
6448             }
6449             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6450                 return false;
6451             }
6452             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6453                 return false;
6454             }
6455             //
6456             //
6457             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6458             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
6459             ext.clear();
6460             t7.getNode( "cd" ).setCollapse( true );
6461             n = t7.getNode( "a" );
6462             while ( n != null ) {
6463                 ext.add( n );
6464                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6465             }
6466             if ( ext.size() != 7 ) {
6467                 return false;
6468             }
6469             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6470                 return false;
6471             }
6472             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6473                 return false;
6474             }
6475             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6476                 return false;
6477             }
6478             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6479                 return false;
6480             }
6481             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6482                 return false;
6483             }
6484             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6485                 return false;
6486             }
6487             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6488                 return false;
6489             }
6490             //
6491             //
6492             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6493             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
6494             ext.clear();
6495             t8.getNode( "cd" ).setCollapse( true );
6496             t8.getNode( "c" ).setCollapse( true );
6497             t8.getNode( "d" ).setCollapse( true );
6498             n = t8.getNode( "a" );
6499             while ( n != null ) {
6500                 ext.add( n );
6501                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6502             }
6503             if ( ext.size() != 7 ) {
6504                 return false;
6505             }
6506             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6507                 return false;
6508             }
6509             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6510                 return false;
6511             }
6512             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6513                 System.out.println( "2 fail" );
6514                 return false;
6515             }
6516             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6517                 return false;
6518             }
6519             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6520                 return false;
6521             }
6522             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6523                 return false;
6524             }
6525             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6526                 return false;
6527             }
6528             //
6529             //
6530             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6531             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
6532             ext.clear();
6533             t9.getNode( "gh" ).setCollapse( true );
6534             n = t9.getNode( "a" );
6535             while ( n != null ) {
6536                 ext.add( n );
6537                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6538             }
6539             if ( ext.size() != 7 ) {
6540                 return false;
6541             }
6542             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6543                 return false;
6544             }
6545             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6546                 return false;
6547             }
6548             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6549                 return false;
6550             }
6551             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6552                 return false;
6553             }
6554             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6555                 return false;
6556             }
6557             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6558                 return false;
6559             }
6560             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6561                 return false;
6562             }
6563             //
6564             //
6565             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6566             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
6567             ext.clear();
6568             t10.getNode( "gh" ).setCollapse( true );
6569             t10.getNode( "g" ).setCollapse( true );
6570             t10.getNode( "h" ).setCollapse( true );
6571             n = t10.getNode( "a" );
6572             while ( n != null ) {
6573                 ext.add( n );
6574                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6575             }
6576             if ( ext.size() != 7 ) {
6577                 return false;
6578             }
6579             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6580                 return false;
6581             }
6582             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6583                 return false;
6584             }
6585             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6586                 return false;
6587             }
6588             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6589                 return false;
6590             }
6591             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6592                 return false;
6593             }
6594             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6595                 return false;
6596             }
6597             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6598                 return false;
6599             }
6600             //
6601             //
6602             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6603             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
6604             ext.clear();
6605             t11.getNode( "gh" ).setCollapse( true );
6606             t11.getNode( "fgh" ).setCollapse( true );
6607             n = t11.getNode( "a" );
6608             while ( n != null ) {
6609                 ext.add( n );
6610                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6611             }
6612             if ( ext.size() != 6 ) {
6613                 return false;
6614             }
6615             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6616                 return false;
6617             }
6618             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6619                 return false;
6620             }
6621             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6622                 return false;
6623             }
6624             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6625                 return false;
6626             }
6627             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6628                 return false;
6629             }
6630             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6631                 return false;
6632             }
6633             //
6634             //
6635             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6636             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
6637             ext.clear();
6638             t12.getNode( "gh" ).setCollapse( true );
6639             t12.getNode( "fgh" ).setCollapse( true );
6640             t12.getNode( "g" ).setCollapse( true );
6641             t12.getNode( "h" ).setCollapse( true );
6642             t12.getNode( "f" ).setCollapse( true );
6643             n = t12.getNode( "a" );
6644             while ( n != null ) {
6645                 ext.add( n );
6646                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6647             }
6648             if ( ext.size() != 6 ) {
6649                 return false;
6650             }
6651             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6652                 return false;
6653             }
6654             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6655                 return false;
6656             }
6657             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6658                 return false;
6659             }
6660             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6661                 return false;
6662             }
6663             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6664                 return false;
6665             }
6666             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6667                 return false;
6668             }
6669             //
6670             //
6671             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6672             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
6673             ext.clear();
6674             t13.getNode( "ab" ).setCollapse( true );
6675             t13.getNode( "b" ).setCollapse( true );
6676             t13.getNode( "fgh" ).setCollapse( true );
6677             t13.getNode( "gh" ).setCollapse( true );
6678             n = t13.getNode( "ab" );
6679             while ( n != null ) {
6680                 ext.add( n );
6681                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6682             }
6683             if ( ext.size() != 5 ) {
6684                 return false;
6685             }
6686             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6687                 return false;
6688             }
6689             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6690                 return false;
6691             }
6692             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6693                 return false;
6694             }
6695             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6696                 return false;
6697             }
6698             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6699                 return false;
6700             }
6701             //
6702             //
6703             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
6704             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
6705             ext.clear();
6706             t14.getNode( "ab" ).setCollapse( true );
6707             t14.getNode( "a" ).setCollapse( true );
6708             t14.getNode( "fgh" ).setCollapse( true );
6709             t14.getNode( "gh" ).setCollapse( true );
6710             n = t14.getNode( "ab" );
6711             while ( n != null ) {
6712                 ext.add( n );
6713                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6714             }
6715             if ( ext.size() != 5 ) {
6716                 return false;
6717             }
6718             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6719                 return false;
6720             }
6721             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6722                 return false;
6723             }
6724             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6725                 return false;
6726             }
6727             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6728                 return false;
6729             }
6730             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6731                 return false;
6732             }
6733             //
6734             //
6735             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" );
6736             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
6737             ext.clear();
6738             t15.getNode( "ab" ).setCollapse( true );
6739             t15.getNode( "a" ).setCollapse( true );
6740             t15.getNode( "fgh" ).setCollapse( true );
6741             t15.getNode( "gh" ).setCollapse( true );
6742             n = t15.getNode( "ab" );
6743             while ( n != null ) {
6744                 ext.add( n );
6745                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6746             }
6747             if ( ext.size() != 6 ) {
6748                 return false;
6749             }
6750             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6751                 return false;
6752             }
6753             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6754                 return false;
6755             }
6756             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6757                 return false;
6758             }
6759             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6760                 return false;
6761             }
6762             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
6763                 return false;
6764             }
6765             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6766                 return false;
6767             }
6768             //
6769             //
6770             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" );
6771             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
6772             ext.clear();
6773             t16.getNode( "ab" ).setCollapse( true );
6774             t16.getNode( "a" ).setCollapse( true );
6775             t16.getNode( "fgh" ).setCollapse( true );
6776             t16.getNode( "gh" ).setCollapse( true );
6777             t16.getNode( "cd" ).setCollapse( true );
6778             t16.getNode( "cde" ).setCollapse( true );
6779             t16.getNode( "d" ).setCollapse( true );
6780             t16.getNode( "x" ).setCollapse( true );
6781             n = t16.getNode( "ab" );
6782             while ( n != null ) {
6783                 ext.add( n );
6784                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6785             }
6786             if ( ext.size() != 4 ) {
6787                 return false;
6788             }
6789             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6790                 return false;
6791             }
6792             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6793                 return false;
6794             }
6795             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
6796                 return false;
6797             }
6798             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
6799                 return false;
6800             }
6801         }
6802         catch ( final Exception e ) {
6803             e.printStackTrace( System.out );
6804             return false;
6805         }
6806         return true;
6807     }
6808
6809     private static boolean testNexusCharactersParsing() {
6810         try {
6811             final NexusCharactersParser parser = new NexusCharactersParser();
6812             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
6813             parser.parse();
6814             String[] labels = parser.getCharStateLabels();
6815             if ( labels.length != 7 ) {
6816                 return false;
6817             }
6818             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6819                 return false;
6820             }
6821             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6822                 return false;
6823             }
6824             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6825                 return false;
6826             }
6827             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6828                 return false;
6829             }
6830             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6831                 return false;
6832             }
6833             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6834                 return false;
6835             }
6836             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6837                 return false;
6838             }
6839             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6840             parser.parse();
6841             labels = parser.getCharStateLabels();
6842             if ( labels.length != 7 ) {
6843                 return false;
6844             }
6845             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6846                 return false;
6847             }
6848             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6849                 return false;
6850             }
6851             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6852                 return false;
6853             }
6854             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6855                 return false;
6856             }
6857             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6858                 return false;
6859             }
6860             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6861                 return false;
6862             }
6863             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6864                 return false;
6865             }
6866         }
6867         catch ( final Exception e ) {
6868             e.printStackTrace( System.out );
6869             return false;
6870         }
6871         return true;
6872     }
6873
6874     private static boolean testNexusMatrixParsing() {
6875         try {
6876             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
6877             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
6878             parser.parse();
6879             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
6880             if ( m.getNumberOfCharacters() != 9 ) {
6881                 return false;
6882             }
6883             if ( m.getNumberOfIdentifiers() != 5 ) {
6884                 return false;
6885             }
6886             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
6887                 return false;
6888             }
6889             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
6890                 return false;
6891             }
6892             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
6893                 return false;
6894             }
6895             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
6896                 return false;
6897             }
6898             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
6899                 return false;
6900             }
6901             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
6902                 return false;
6903             }
6904             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
6905                 return false;
6906             }
6907             //            if ( labels.length != 7 ) {
6908             //                return false;
6909             //            }
6910             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6911             //                return false;
6912             //            }
6913             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6914             //                return false;
6915             //            }
6916             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6917             //                return false;
6918             //            }
6919             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6920             //                return false;
6921             //            }
6922             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6923             //                return false;
6924             //            }
6925             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6926             //                return false;
6927             //            }
6928             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6929             //                return false;
6930             //            }
6931             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6932             //            parser.parse();
6933             //            labels = parser.getCharStateLabels();
6934             //            if ( labels.length != 7 ) {
6935             //                return false;
6936             //            }
6937             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6938             //                return false;
6939             //            }
6940             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6941             //                return false;
6942             //            }
6943             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6944             //                return false;
6945             //            }
6946             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6947             //                return false;
6948             //            }
6949             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6950             //                return false;
6951             //            }
6952             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6953             //                return false;
6954             //            }
6955             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6956             //                return false;
6957             //            }
6958         }
6959         catch ( final Exception e ) {
6960             e.printStackTrace( System.out );
6961             return false;
6962         }
6963         return true;
6964     }
6965
6966     private static boolean testNexusTreeParsing() {
6967         try {
6968             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6969             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
6970             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
6971             if ( phylogenies.length != 1 ) {
6972                 return false;
6973             }
6974             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
6975                 return false;
6976             }
6977             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6978                 return false;
6979             }
6980             phylogenies = null;
6981             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
6982             if ( phylogenies.length != 1 ) {
6983                 return false;
6984             }
6985             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6986                 return false;
6987             }
6988             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
6989                 return false;
6990             }
6991             phylogenies = null;
6992             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
6993             if ( phylogenies.length != 1 ) {
6994                 return false;
6995             }
6996             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6997                 return false;
6998             }
6999             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7000                 return false;
7001             }
7002             if ( phylogenies[ 0 ].isRooted() ) {
7003                 return false;
7004             }
7005             phylogenies = null;
7006             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
7007             if ( phylogenies.length != 18 ) {
7008                 return false;
7009             }
7010             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7011                 return false;
7012             }
7013             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
7014                 return false;
7015             }
7016             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
7017                 return false;
7018             }
7019             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
7020                 return false;
7021             }
7022             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7023                 return false;
7024             }
7025             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
7026                 return false;
7027             }
7028             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
7029                 return false;
7030             }
7031             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
7032                 return false;
7033             }
7034             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
7035                 return false;
7036             }
7037             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
7038                 return false;
7039             }
7040             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
7041                 return false;
7042             }
7043             if ( phylogenies[ 8 ].isRooted() ) {
7044                 return false;
7045             }
7046             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
7047                 return false;
7048             }
7049             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
7050                 return false;
7051             }
7052             if ( !phylogenies[ 9 ].isRooted() ) {
7053                 return false;
7054             }
7055             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
7056                 return false;
7057             }
7058             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
7059                 return false;
7060             }
7061             if ( !phylogenies[ 10 ].isRooted() ) {
7062                 return false;
7063             }
7064             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
7065                 return false;
7066             }
7067             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
7068                 return false;
7069             }
7070             if ( phylogenies[ 11 ].isRooted() ) {
7071                 return false;
7072             }
7073             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
7074                 return false;
7075             }
7076             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
7077                 return false;
7078             }
7079             if ( !phylogenies[ 12 ].isRooted() ) {
7080                 return false;
7081             }
7082             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
7083                 return false;
7084             }
7085             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
7086                 return false;
7087             }
7088             if ( !phylogenies[ 13 ].isRooted() ) {
7089                 return false;
7090             }
7091             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
7092                 return false;
7093             }
7094             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
7095                 return false;
7096             }
7097             if ( !phylogenies[ 14 ].isRooted() ) {
7098                 return false;
7099             }
7100             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
7101                 return false;
7102             }
7103             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
7104                 return false;
7105             }
7106             if ( phylogenies[ 15 ].isRooted() ) {
7107                 return false;
7108             }
7109             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
7110                 return false;
7111             }
7112             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
7113                 return false;
7114             }
7115             if ( !phylogenies[ 16 ].isRooted() ) {
7116                 return false;
7117             }
7118             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
7119                 return false;
7120             }
7121             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
7122                 return false;
7123             }
7124             if ( phylogenies[ 17 ].isRooted() ) {
7125                 return false;
7126             }
7127             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
7128                 return false;
7129             }
7130             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7131             phylogenies = null;
7132             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
7133             if ( phylogenies.length != 9 ) {
7134                 return false;
7135             }
7136             if ( !isEqual( 0.48039661496919533, phylogenies[ 0 ].getNode( "Diadocidia_spinosula" )
7137                     .getDistanceToParent() ) ) {
7138                 return false;
7139             }
7140             if ( !isEqual( 0.3959796191512233, phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" )
7141                     .getDistanceToParent() ) ) {
7142                 return false;
7143             }
7144             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
7145                 return false;
7146             }
7147             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7148                 return false;
7149             }
7150             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7151                 return false;
7152             }
7153             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7154                 return false;
7155             }
7156             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7157                 return false;
7158             }
7159         }
7160         catch ( final Exception e ) {
7161             e.printStackTrace( System.out );
7162             return false;
7163         }
7164         return true;
7165     }
7166
7167     private static boolean testNexusTreeParsingIterating() {
7168         try {
7169             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
7170             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
7171             if ( !p.hasNext() ) {
7172                 return false;
7173             }
7174             Phylogeny phy = p.next();
7175             if ( phy == null ) {
7176                 return false;
7177             }
7178             if ( phy.getNumberOfExternalNodes() != 25 ) {
7179                 return false;
7180             }
7181             if ( !phy.getName().equals( "" ) ) {
7182                 return false;
7183             }
7184             if ( p.hasNext() ) {
7185                 return false;
7186             }
7187             phy = p.next();
7188             if ( phy != null ) {
7189                 return false;
7190             }
7191             //
7192             p.reset();
7193             if ( !p.hasNext() ) {
7194                 return false;
7195             }
7196             phy = p.next();
7197             if ( phy == null ) {
7198                 return false;
7199             }
7200             if ( phy.getNumberOfExternalNodes() != 25 ) {
7201                 return false;
7202             }
7203             if ( !phy.getName().equals( "" ) ) {
7204                 return false;
7205             }
7206             if ( p.hasNext() ) {
7207                 return false;
7208             }
7209             phy = p.next();
7210             if ( phy != null ) {
7211                 return false;
7212             }
7213             ////
7214             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
7215             if ( !p.hasNext() ) {
7216                 return false;
7217             }
7218             phy = p.next();
7219             if ( phy == null ) {
7220                 return false;
7221             }
7222             if ( phy.getNumberOfExternalNodes() != 10 ) {
7223                 return false;
7224             }
7225             if ( !phy.getName().equals( "name" ) ) {
7226                 return false;
7227             }
7228             if ( p.hasNext() ) {
7229                 return false;
7230             }
7231             phy = p.next();
7232             if ( phy != null ) {
7233                 return false;
7234             }
7235             //
7236             p.reset();
7237             if ( !p.hasNext() ) {
7238                 return false;
7239             }
7240             phy = p.next();
7241             if ( phy == null ) {
7242                 return false;
7243             }
7244             if ( phy.getNumberOfExternalNodes() != 10 ) {
7245                 return false;
7246             }
7247             if ( !phy.getName().equals( "name" ) ) {
7248                 return false;
7249             }
7250             if ( p.hasNext() ) {
7251                 return false;
7252             }
7253             phy = p.next();
7254             if ( phy != null ) {
7255                 return false;
7256             }
7257             //
7258             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
7259             if ( !p.hasNext() ) {
7260                 return false;
7261             }
7262             phy = p.next();
7263             if ( phy == null ) {
7264                 return false;
7265             }
7266             if ( phy.getNumberOfExternalNodes() != 3 ) {
7267                 return false;
7268             }
7269             if ( !phy.getName().equals( "" ) ) {
7270                 return false;
7271             }
7272             if ( phy.isRooted() ) {
7273                 return false;
7274             }
7275             if ( p.hasNext() ) {
7276                 return false;
7277             }
7278             phy = p.next();
7279             if ( phy != null ) {
7280                 return false;
7281             }
7282             //
7283             p.reset();
7284             if ( !p.hasNext() ) {
7285                 return false;
7286             }
7287             phy = p.next();
7288             if ( phy == null ) {
7289                 return false;
7290             }
7291             if ( phy.getNumberOfExternalNodes() != 3 ) {
7292                 return false;
7293             }
7294             if ( !phy.getName().equals( "" ) ) {
7295                 return false;
7296             }
7297             if ( p.hasNext() ) {
7298                 return false;
7299             }
7300             phy = p.next();
7301             if ( phy != null ) {
7302                 return false;
7303             }
7304             //
7305             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
7306             if ( !p.hasNext() ) {
7307                 return false;
7308             }
7309             //0
7310             phy = p.next();
7311             if ( phy == null ) {
7312                 return false;
7313             }
7314             if ( phy.getNumberOfExternalNodes() != 10 ) {
7315                 return false;
7316             }
7317             if ( !phy.getName().equals( "tree 0" ) ) {
7318                 return false;
7319             }
7320             //1
7321             if ( !p.hasNext() ) {
7322                 return false;
7323             }
7324             phy = p.next();
7325             if ( phy == null ) {
7326                 return false;
7327             }
7328             if ( phy.getNumberOfExternalNodes() != 10 ) {
7329                 return false;
7330             }
7331             if ( !phy.getName().equals( "tree 1" ) ) {
7332                 return false;
7333             }
7334             //2
7335             if ( !p.hasNext() ) {
7336                 return false;
7337             }
7338             phy = p.next();
7339             if ( phy == null ) {
7340                 return false;
7341             }
7342             if ( phy.getNumberOfExternalNodes() != 3 ) {
7343                 System.out.println( phy.toString() );
7344                 return false;
7345             }
7346             if ( !phy.getName().equals( "" ) ) {
7347                 return false;
7348             }
7349             if ( phy.isRooted() ) {
7350                 return false;
7351             }
7352             //3
7353             if ( !p.hasNext() ) {
7354                 return false;
7355             }
7356             phy = p.next();
7357             if ( phy == null ) {
7358                 return false;
7359             }
7360             if ( phy.getNumberOfExternalNodes() != 4 ) {
7361                 return false;
7362             }
7363             if ( !phy.getName().equals( "" ) ) {
7364                 return false;
7365             }
7366             if ( !phy.isRooted() ) {
7367                 return false;
7368             }
7369             //4
7370             if ( !p.hasNext() ) {
7371                 return false;
7372             }
7373             phy = p.next();
7374             if ( phy == null ) {
7375                 return false;
7376             }
7377             if ( phy.getNumberOfExternalNodes() != 5 ) {
7378                 System.out.println( phy.getNumberOfExternalNodes() );
7379                 return false;
7380             }
7381             if ( !phy.getName().equals( "" ) ) {
7382                 return false;
7383             }
7384             if ( !phy.isRooted() ) {
7385                 return false;
7386             }
7387             //5
7388             if ( !p.hasNext() ) {
7389                 return false;
7390             }
7391             phy = p.next();
7392             if ( phy == null ) {
7393                 return false;
7394             }
7395             if ( phy.getNumberOfExternalNodes() != 3 ) {
7396                 return false;
7397             }
7398             if ( !phy.getName().equals( "" ) ) {
7399                 return false;
7400             }
7401             if ( phy.isRooted() ) {
7402                 return false;
7403             }
7404             //6
7405             if ( !p.hasNext() ) {
7406                 return false;
7407             }
7408             phy = p.next();
7409             if ( phy == null ) {
7410                 return false;
7411             }
7412             if ( phy.getNumberOfExternalNodes() != 2 ) {
7413                 return false;
7414             }
7415             if ( !phy.getName().equals( "" ) ) {
7416                 return false;
7417             }
7418             if ( !phy.isRooted() ) {
7419                 return false;
7420             }
7421             //7
7422             if ( !p.hasNext() ) {
7423                 return false;
7424             }
7425             phy = p.next();
7426             if ( phy.getNumberOfExternalNodes() != 3 ) {
7427                 return false;
7428             }
7429             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7430                 return false;
7431             }
7432             if ( !phy.isRooted() ) {
7433                 return false;
7434             }
7435             //8
7436             if ( !p.hasNext() ) {
7437                 return false;
7438             }
7439             phy = p.next();
7440             if ( phy.getNumberOfExternalNodes() != 3 ) {
7441                 return false;
7442             }
7443             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
7444                 return false;
7445             }
7446             if ( !phy.getName().equals( "tree 8" ) ) {
7447                 return false;
7448             }
7449             //9
7450             if ( !p.hasNext() ) {
7451                 return false;
7452             }
7453             phy = p.next();
7454             if ( phy.getNumberOfExternalNodes() != 3 ) {
7455                 return false;
7456             }
7457             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
7458                 return false;
7459             }
7460             if ( !phy.getName().equals( "tree 9" ) ) {
7461                 return false;
7462             }
7463             //10
7464             if ( !p.hasNext() ) {
7465                 return false;
7466             }
7467             phy = p.next();
7468             if ( phy.getNumberOfExternalNodes() != 3 ) {
7469                 return false;
7470             }
7471             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7472                 return false;
7473             }
7474             if ( !phy.getName().equals( "tree 10" ) ) {
7475                 return false;
7476             }
7477             if ( !phy.isRooted() ) {
7478                 return false;
7479             }
7480             //11
7481             if ( !p.hasNext() ) {
7482                 return false;
7483             }
7484             phy = p.next();
7485             if ( phy.getNumberOfExternalNodes() != 3 ) {
7486                 return false;
7487             }
7488             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
7489                 return false;
7490             }
7491             if ( !phy.getName().equals( "tree 11" ) ) {
7492                 return false;
7493             }
7494             if ( phy.isRooted() ) {
7495                 return false;
7496             }
7497             //12
7498             if ( !p.hasNext() ) {
7499                 return false;
7500             }
7501             phy = p.next();
7502             if ( phy.getNumberOfExternalNodes() != 3 ) {
7503                 return false;
7504             }
7505             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
7506                 return false;
7507             }
7508             if ( !phy.getName().equals( "tree 12" ) ) {
7509                 return false;
7510             }
7511             if ( !phy.isRooted() ) {
7512                 return false;
7513             }
7514             //13
7515             if ( !p.hasNext() ) {
7516                 return false;
7517             }
7518             phy = p.next();
7519             if ( phy.getNumberOfExternalNodes() != 3 ) {
7520                 return false;
7521             }
7522             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7523                 return false;
7524             }
7525             if ( !phy.getName().equals( "tree 13" ) ) {
7526                 return false;
7527             }
7528             if ( !phy.isRooted() ) {
7529                 return false;
7530             }
7531             //14
7532             if ( !p.hasNext() ) {
7533                 return false;
7534             }
7535             phy = p.next();
7536             if ( phy.getNumberOfExternalNodes() != 10 ) {
7537                 System.out.println( phy.getNumberOfExternalNodes() );
7538                 return false;
7539             }
7540             if ( !phy
7541                     .toNewHampshire()
7542                     .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;" ) ) {
7543                 System.out.println( phy.toNewHampshire() );
7544                 return false;
7545             }
7546             if ( !phy.getName().equals( "tree 14" ) ) {
7547                 return false;
7548             }
7549             if ( !phy.isRooted() ) {
7550                 return false;
7551             }
7552             //15
7553             if ( !p.hasNext() ) {
7554                 return false;
7555             }
7556             phy = p.next();
7557             if ( phy.getNumberOfExternalNodes() != 10 ) {
7558                 System.out.println( phy.getNumberOfExternalNodes() );
7559                 return false;
7560             }
7561             if ( !phy
7562                     .toNewHampshire()
7563                     .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;" ) ) {
7564                 System.out.println( phy.toNewHampshire() );
7565                 return false;
7566             }
7567             if ( !phy.getName().equals( "tree 15" ) ) {
7568                 return false;
7569             }
7570             if ( phy.isRooted() ) {
7571                 return false;
7572             }
7573             //16
7574             if ( !p.hasNext() ) {
7575                 return false;
7576             }
7577             phy = p.next();
7578             if ( phy.getNumberOfExternalNodes() != 10 ) {
7579                 System.out.println( phy.getNumberOfExternalNodes() );
7580                 return false;
7581             }
7582             if ( !phy
7583                     .toNewHampshire()
7584                     .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;" ) ) {
7585                 System.out.println( phy.toNewHampshire() );
7586                 return false;
7587             }
7588             if ( !phy.getName().equals( "tree 16" ) ) {
7589                 return false;
7590             }
7591             if ( !phy.isRooted() ) {
7592                 return false;
7593             }
7594             //17
7595             if ( !p.hasNext() ) {
7596                 return false;
7597             }
7598             phy = p.next();
7599             if ( phy.getNumberOfExternalNodes() != 10 ) {
7600                 System.out.println( phy.getNumberOfExternalNodes() );
7601                 return false;
7602             }
7603             if ( !phy
7604                     .toNewHampshire()
7605                     .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;" ) ) {
7606                 System.out.println( phy.toNewHampshire() );
7607                 return false;
7608             }
7609             if ( !phy.getName().equals( "tree 17" ) ) {
7610                 return false;
7611             }
7612             if ( phy.isRooted() ) {
7613                 return false;
7614             }
7615             //
7616             if ( p.hasNext() ) {
7617                 return false;
7618             }
7619             phy = p.next();
7620             if ( phy != null ) {
7621                 return false;
7622             }
7623             p.reset();
7624             //0
7625             if ( !p.hasNext() ) {
7626                 return false;
7627             }
7628             phy = p.next();
7629             if ( phy == null ) {
7630                 return false;
7631             }
7632             if ( phy.getNumberOfExternalNodes() != 10 ) {
7633                 return false;
7634             }
7635             if ( !phy.getName().equals( "tree 0" ) ) {
7636                 return false;
7637             }
7638             //1
7639             if ( !p.hasNext() ) {
7640                 return false;
7641             }
7642             phy = p.next();
7643             if ( phy == null ) {
7644                 return false;
7645             }
7646             if ( phy.getNumberOfExternalNodes() != 10 ) {
7647                 return false;
7648             }
7649             if ( !phy.getName().equals( "tree 1" ) ) {
7650                 return false;
7651             }
7652             //2
7653             if ( !p.hasNext() ) {
7654                 return false;
7655             }
7656             phy = p.next();
7657             if ( phy == null ) {
7658                 return false;
7659             }
7660             if ( phy.getNumberOfExternalNodes() != 3 ) {
7661                 return false;
7662             }
7663             if ( !phy.getName().equals( "" ) ) {
7664                 return false;
7665             }
7666             if ( phy.isRooted() ) {
7667                 return false;
7668             }
7669             //3
7670             if ( !p.hasNext() ) {
7671                 return false;
7672             }
7673             phy = p.next();
7674             if ( phy == null ) {
7675                 return false;
7676             }
7677             if ( phy.getNumberOfExternalNodes() != 4 ) {
7678                 return false;
7679             }
7680             if ( !phy.getName().equals( "" ) ) {
7681                 return false;
7682             }
7683             if ( !phy.isRooted() ) {
7684                 return false;
7685             }
7686             //4
7687             if ( !p.hasNext() ) {
7688                 return false;
7689             }
7690             phy = p.next();
7691             if ( phy == null ) {
7692                 return false;
7693             }
7694             if ( phy.getNumberOfExternalNodes() != 5 ) {
7695                 System.out.println( phy.getNumberOfExternalNodes() );
7696                 return false;
7697             }
7698             if ( !phy.getName().equals( "" ) ) {
7699                 return false;
7700             }
7701             if ( !phy.isRooted() ) {
7702                 return false;
7703             }
7704             //5
7705             if ( !p.hasNext() ) {
7706                 return false;
7707             }
7708             phy = p.next();
7709             if ( phy == null ) {
7710                 return false;
7711             }
7712             if ( phy.getNumberOfExternalNodes() != 3 ) {
7713                 return false;
7714             }
7715             if ( !phy.getName().equals( "" ) ) {
7716                 return false;
7717             }
7718             if ( phy.isRooted() ) {
7719                 return false;
7720             }
7721             //
7722             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7723             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
7724             // 0
7725             if ( !p2.hasNext() ) {
7726                 return false;
7727             }
7728             phy = p2.next();
7729             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7730                 return false;
7731             }
7732             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7733                 return false;
7734             }
7735             // 1
7736             if ( !p2.hasNext() ) {
7737                 return false;
7738             }
7739             phy = p2.next();
7740             // 2
7741             if ( !p2.hasNext() ) {
7742                 return false;
7743             }
7744             phy = p2.next();
7745             // 3
7746             if ( !p2.hasNext() ) {
7747                 return false;
7748             }
7749             phy = p2.next();
7750             // 4
7751             if ( !p2.hasNext() ) {
7752                 return false;
7753             }
7754             phy = p2.next();
7755             // 5
7756             if ( !p2.hasNext() ) {
7757                 return false;
7758             }
7759             phy = p2.next();
7760             // 6
7761             if ( !p2.hasNext() ) {
7762                 return false;
7763             }
7764             phy = p2.next();
7765             // 7
7766             if ( !p2.hasNext() ) {
7767                 return false;
7768             }
7769             phy = p2.next();
7770             // 8
7771             if ( !p2.hasNext() ) {
7772                 return false;
7773             }
7774             phy = p2.next();
7775             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7776                 return false;
7777             }
7778             if ( p2.hasNext() ) {
7779                 return false;
7780             }
7781             phy = p2.next();
7782             if ( phy != null ) {
7783                 return false;
7784             }
7785             // 0
7786             p2.reset();
7787             if ( !p2.hasNext() ) {
7788                 return false;
7789             }
7790             phy = p2.next();
7791             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7792                 return false;
7793             }
7794             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7795                 return false;
7796             }
7797         }
7798         catch ( final Exception e ) {
7799             e.printStackTrace( System.out );
7800             return false;
7801         }
7802         return true;
7803     }
7804
7805     private static boolean testNexusTreeParsingTranslating() {
7806         try {
7807             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7808             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7809             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
7810             if ( phylogenies.length != 1 ) {
7811                 return false;
7812             }
7813             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7814                 return false;
7815             }
7816             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7817                 return false;
7818             }
7819             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7820                 return false;
7821             }
7822             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7823                 return false;
7824             }
7825             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7826                     .equals( "Aranaeus" ) ) {
7827                 return false;
7828             }
7829             phylogenies = null;
7830             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
7831             if ( phylogenies.length != 3 ) {
7832                 return false;
7833             }
7834             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7835                 return false;
7836             }
7837             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7838                 return false;
7839             }
7840             if ( phylogenies[ 0 ].isRooted() ) {
7841                 return false;
7842             }
7843             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7844                 return false;
7845             }
7846             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7847                 return false;
7848             }
7849             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7850                     .equals( "Aranaeus" ) ) {
7851                 return false;
7852             }
7853             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7854                 return false;
7855             }
7856             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7857                 return false;
7858             }
7859             if ( phylogenies[ 1 ].isRooted() ) {
7860                 return false;
7861             }
7862             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7863                 return false;
7864             }
7865             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7866                 return false;
7867             }
7868             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7869                     .equals( "Aranaeus" ) ) {
7870                 return false;
7871             }
7872             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7873                 return false;
7874             }
7875             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7876                 return false;
7877             }
7878             if ( !phylogenies[ 2 ].isRooted() ) {
7879                 return false;
7880             }
7881             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7882                 return false;
7883             }
7884             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7885                 return false;
7886             }
7887             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7888                     .equals( "Aranaeus" ) ) {
7889                 return false;
7890             }
7891             phylogenies = null;
7892             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
7893             if ( phylogenies.length != 3 ) {
7894                 return false;
7895             }
7896             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7897                 return false;
7898             }
7899             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7900                 return false;
7901             }
7902             if ( phylogenies[ 0 ].isRooted() ) {
7903                 return false;
7904             }
7905             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7906                 return false;
7907             }
7908             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7909                 return false;
7910             }
7911             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7912                     .equals( "Aranaeus" ) ) {
7913                 return false;
7914             }
7915             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7916                 return false;
7917             }
7918             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7919                 return false;
7920             }
7921             if ( phylogenies[ 1 ].isRooted() ) {
7922                 return false;
7923             }
7924             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7925                 return false;
7926             }
7927             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7928                 return false;
7929             }
7930             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7931                     .equals( "Aranaeus" ) ) {
7932                 return false;
7933             }
7934             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7935                 return false;
7936             }
7937             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7938                 return false;
7939             }
7940             if ( !phylogenies[ 2 ].isRooted() ) {
7941                 return false;
7942             }
7943             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7944                 return false;
7945             }
7946             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7947                 return false;
7948             }
7949             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7950                     .equals( "Aranaeus" ) ) {
7951                 return false;
7952             }
7953             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
7954             if ( phylogenies.length != 3 ) {
7955                 return false;
7956             }
7957             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
7958                            0.00100049 ) ) {
7959                 return false;
7960             }
7961         }
7962         catch ( final Exception e ) {
7963             e.printStackTrace( System.out );
7964             return false;
7965         }
7966         return true;
7967     }
7968
7969     private static boolean testNHParsing() {
7970         try {
7971             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7972             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
7973             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
7974                 return false;
7975             }
7976             final NHXParser nhxp = new NHXParser();
7977             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
7978             nhxp.setReplaceUnderscores( true );
7979             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
7980             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
7981                 return false;
7982             }
7983             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
7984                 return false;
7985             }
7986             final Phylogeny p1b = factory
7987                     .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 ",
7988                              new NHXParser() )[ 0 ];
7989             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
7990                 return false;
7991             }
7992             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
7993                 return false;
7994             }
7995             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
7996             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
7997             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
7998             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
7999             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
8000             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
8001             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
8002             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
8003             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
8004             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
8005             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
8006                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
8007                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
8008                                                     new NHXParser() );
8009             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
8010                 return false;
8011             }
8012             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
8013                 return false;
8014             }
8015             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
8016                 return false;
8017             }
8018             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
8019                 return false;
8020             }
8021             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
8022             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
8023             final String p16_S = "((A,B),C)";
8024             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
8025             if ( p16.length != 1 ) {
8026                 return false;
8027             }
8028             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
8029                 return false;
8030             }
8031             final String p17_S = "(C,(A,B))";
8032             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
8033             if ( p17.length != 1 ) {
8034                 return false;
8035             }
8036             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
8037                 return false;
8038             }
8039             final String p18_S = "((A,B),(C,D))";
8040             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
8041             if ( p18.length != 1 ) {
8042                 return false;
8043             }
8044             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
8045                 return false;
8046             }
8047             final String p19_S = "(((A,B),C),D)";
8048             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
8049             if ( p19.length != 1 ) {
8050                 return false;
8051             }
8052             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
8053                 return false;
8054             }
8055             final String p20_S = "(A,(B,(C,D)))";
8056             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
8057             if ( p20.length != 1 ) {
8058                 return false;
8059             }
8060             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
8061                 return false;
8062             }
8063             final String p21_S = "(A,(B,(C,(D,E))))";
8064             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
8065             if ( p21.length != 1 ) {
8066                 return false;
8067             }
8068             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
8069                 return false;
8070             }
8071             final String p22_S = "((((A,B),C),D),E)";
8072             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
8073             if ( p22.length != 1 ) {
8074                 return false;
8075             }
8076             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
8077                 return false;
8078             }
8079             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8080             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
8081             if ( p23.length != 1 ) {
8082                 System.out.println( "xl=" + p23.length );
8083                 System.exit( -1 );
8084                 return false;
8085             }
8086             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
8087                 return false;
8088             }
8089             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8090             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
8091             if ( p24.length != 1 ) {
8092                 return false;
8093             }
8094             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
8095                 return false;
8096             }
8097             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8098             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8099             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
8100             if ( p241.length != 2 ) {
8101                 return false;
8102             }
8103             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
8104                 return false;
8105             }
8106             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
8107                 return false;
8108             }
8109             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
8110                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
8111                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
8112                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
8113                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
8114                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
8115                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
8116                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
8117             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
8118             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
8119                 return false;
8120             }
8121             final String p26_S = "(A,B)ab";
8122             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
8123             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
8124                 return false;
8125             }
8126             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8127             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
8128             if ( p27s.length != 1 ) {
8129                 System.out.println( "xxl=" + p27s.length );
8130                 System.exit( -1 );
8131                 return false;
8132             }
8133             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8134                 System.out.println( p27s[ 0 ].toNewHampshireX() );
8135                 System.exit( -1 );
8136                 return false;
8137             }
8138             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
8139                                                     new NHXParser() );
8140             if ( p27.length != 1 ) {
8141                 System.out.println( "yl=" + p27.length );
8142                 System.exit( -1 );
8143                 return false;
8144             }
8145             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8146                 System.out.println( p27[ 0 ].toNewHampshireX() );
8147                 System.exit( -1 );
8148                 return false;
8149             }
8150             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8151             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8152             final String p28_S3 = "(A,B)ab";
8153             final String p28_S4 = "((((A,B),C),D),;E;)";
8154             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
8155                                                     new NHXParser() );
8156             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
8157                 return false;
8158             }
8159             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
8160                 return false;
8161             }
8162             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
8163                 return false;
8164             }
8165             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
8166                 return false;
8167             }
8168             if ( p28.length != 4 ) {
8169                 return false;
8170             }
8171             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";
8172             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
8173             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
8174                 return false;
8175             }
8176             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";
8177             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
8178             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
8179                 return false;
8180             }
8181             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
8182             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
8183             if ( ( p32.length != 0 ) ) {
8184                 return false;
8185             }
8186             final String p33_S = "A";
8187             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
8188             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
8189                 return false;
8190             }
8191             final String p34_S = "B;";
8192             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
8193             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
8194                 return false;
8195             }
8196             final String p35_S = "B:0.2";
8197             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
8198             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
8199                 return false;
8200             }
8201             final String p36_S = "(A)";
8202             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
8203             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
8204                 return false;
8205             }
8206             final String p37_S = "((A))";
8207             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
8208             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
8209                 return false;
8210             }
8211             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8212             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
8213             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
8214                 return false;
8215             }
8216             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8217             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
8218             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
8219                 return false;
8220             }
8221             final String p40_S = "(A,B,C)";
8222             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
8223             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
8224                 return false;
8225             }
8226             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
8227             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
8228             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
8229                 return false;
8230             }
8231             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
8232             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
8233             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
8234                 return false;
8235             }
8236             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)";
8237             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
8238             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
8239                 return false;
8240             }
8241             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)))";
8242             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
8243             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
8244                 return false;
8245             }
8246             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
8247             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
8248             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
8249                 return false;
8250             }
8251             final String p46_S = "";
8252             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
8253             if ( p46.length != 0 ) {
8254                 return false;
8255             }
8256             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
8257             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8258                 return false;
8259             }
8260             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8261             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8262                 return false;
8263             }
8264             final Phylogeny p49 = factory
8265                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
8266                              new NHXParser() )[ 0 ];
8267             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8268                 return false;
8269             }
8270             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8271             if ( p50.getNode( "A" ) == null ) {
8272                 return false;
8273             }
8274             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8275                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
8276                 return false;
8277             }
8278             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
8279                 return false;
8280             }
8281             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
8282                     .equals( "((A,B)88:2.0,C);" ) ) {
8283                 return false;
8284             }
8285             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8286             if ( p51.getNode( "A(A" ) == null ) {
8287                 return false;
8288             }
8289             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8290             if ( p52.getNode( "A(A" ) == null ) {
8291                 return false;
8292             }
8293             final Phylogeny p53 = factory
8294                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
8295                              new NHXParser() )[ 0 ];
8296             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
8297                 return false;
8298             }
8299             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
8300             if ( p54.getNode( "A" ) == null ) {
8301                 return false;
8302             }
8303             if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ).equals( "((A,B)[88],C);" ) ) {
8304                 return false;
8305             }
8306             final Phylogeny p55 = factory
8307                     .create( new StringBuffer( "((\"lcl|HPV32_L1.:1  s\":0.195593,\"lcl|HPV30_L1.1|;a\":0.114237):0.0359322,\"lcl|HPV56_L1.1|,d\":0.0727412,\"lcl|HPV66_L1.1x\":0.0798012);" ),
8308                              new NHXParser() )[ 0 ];
8309             if ( !p55
8310                     .toNewHampshire()
8311                     .equals( "(('lcl|HPV32_L1.:1 s':0.195593,'lcl|HPV30_L1.1|;a':0.114237):0.0359322,'lcl|HPV56_L1.1|,d':0.0727412,lcl|HPV66_L1.1x:0.0798012);" ) ) {
8312                 System.out.println( p55.toNewHampshire() );
8313                 return false;
8314             }
8315             final Phylogeny p56 = factory
8316                     .create( new StringBuffer( "((\"lcl|HPV32_L1.:1      s\":0.195593,\"lcl|HPV30_L1.1|;a\":0.114\n237):0.0359322,\"lcl|HPV56_L1.1|,d\":0.0727412,\"lcl|HPV66_L1.1:x\":0.0798012);" ),
8317                              new NHXParser() )[ 0 ];
8318             if ( !p56
8319                     .toNewHampshire()
8320                     .equals( "(('lcl|HPV32_L1.:1 s':0.195593,'lcl|HPV30_L1.1|;a':0.114237):0.0359322,'lcl|HPV56_L1.1|,d':0.0727412,'lcl|HPV66_L1.1:x':0.0798012);" ) ) {
8321                 System.out.println( p56.toNewHampshire() );
8322                 return false;
8323             }
8324             final Phylogeny p57 = factory
8325                     .create( new StringBuffer( "((\"lcl|HPV32_L1.:1      s\":0.195593,\"lcl|HPV30_L1.1|;a\":0.114\n237):0.0359322,\"lcl|HPV56_L1.1|,d\":0.0727412,\"lcl|HPV66_L1.1:x\":0.0798012);" ),
8326                              new NHXParser() )[ 0 ];
8327             if ( !p57
8328                     .toNewHampshire()
8329                     .equals( "(('lcl|HPV32_L1.:1 s':0.195593,'lcl|HPV30_L1.1|;a':0.114237):0.0359322,'lcl|HPV56_L1.1|,d':0.0727412,'lcl|HPV66_L1.1:x':0.0798012);" ) ) {
8330                 System.out.println( p56.toNewHampshire() );
8331                 return false;
8332             }
8333             final String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
8334             final Phylogeny p58 = factory.create( new StringBuffer( s58 ), new NHXParser() )[ 0 ];
8335             if ( !p58.toNewHampshire().equals( s58 ) ) {
8336                 System.out.println( p58.toNewHampshire() );
8337                 return false;
8338             }
8339             final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
8340             final Phylogeny p59 = factory.create( new StringBuffer( s59 ), new NHXParser() )[ 0 ];
8341             if ( !p59.toNewHampshire().equals( s59 ) ) {
8342                 System.out.println( p59.toNewHampshire() );
8343                 return false;
8344             }
8345             final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
8346             final Phylogeny p60 = factory.create( new StringBuffer( s60 ), new NHXParser() )[ 0 ];
8347             if ( !p60.toNewHampshire().equals( s60 ) ) {
8348                 System.out.println( p60.toNewHampshire() );
8349                 return false;
8350             }
8351             final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
8352             final Phylogeny p61 = factory.create( new StringBuffer( s61 ), new NHXParser() )[ 0 ];
8353             if ( !p61.toNewHampshire()
8354                     .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
8355                 System.out.println( p61.toNewHampshire() );
8356                 return false;
8357             }
8358         }
8359         catch ( final Exception e ) {
8360             e.printStackTrace( System.out );
8361             return false;
8362         }
8363         return true;
8364     }
8365
8366     private static boolean testNHParsingIter() {
8367         try {
8368             final String p0_str = "(A,B);";
8369             final NHXParser p = new NHXParser();
8370             p.setSource( p0_str );
8371             if ( !p.hasNext() ) {
8372                 return false;
8373             }
8374             final Phylogeny p0 = p.next();
8375             if ( !p0.toNewHampshire().equals( p0_str ) ) {
8376                 System.out.println( p0.toNewHampshire() );
8377                 return false;
8378             }
8379             if ( p.hasNext() ) {
8380                 return false;
8381             }
8382             if ( p.next() != null ) {
8383                 return false;
8384             }
8385             //
8386             final String p00_str = "(A,B)root;";
8387             p.setSource( p00_str );
8388             final Phylogeny p00 = p.next();
8389             if ( !p00.toNewHampshire().equals( p00_str ) ) {
8390                 System.out.println( p00.toNewHampshire() );
8391                 return false;
8392             }
8393             //
8394             final String p000_str = "A;";
8395             p.setSource( p000_str );
8396             final Phylogeny p000 = p.next();
8397             if ( !p000.toNewHampshire().equals( p000_str ) ) {
8398                 System.out.println( p000.toNewHampshire() );
8399                 return false;
8400             }
8401             //
8402             final String p0000_str = "A";
8403             p.setSource( p0000_str );
8404             final Phylogeny p0000 = p.next();
8405             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
8406                 System.out.println( p0000.toNewHampshire() );
8407                 return false;
8408             }
8409             //
8410             p.setSource( "(A)" );
8411             final Phylogeny p00000 = p.next();
8412             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
8413                 System.out.println( p00000.toNewHampshire() );
8414                 return false;
8415             }
8416             //
8417             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
8418             p.setSource( p1_str );
8419             if ( !p.hasNext() ) {
8420                 return false;
8421             }
8422             final Phylogeny p1_0 = p.next();
8423             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
8424                 System.out.println( p1_0.toNewHampshire() );
8425                 return false;
8426             }
8427             if ( !p.hasNext() ) {
8428                 return false;
8429             }
8430             final Phylogeny p1_1 = p.next();
8431             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
8432                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
8433                 return false;
8434             }
8435             if ( !p.hasNext() ) {
8436                 return false;
8437             }
8438             final Phylogeny p1_2 = p.next();
8439             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
8440                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
8441                 return false;
8442             }
8443             if ( !p.hasNext() ) {
8444                 return false;
8445             }
8446             final Phylogeny p1_3 = p.next();
8447             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
8448                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
8449                 return false;
8450             }
8451             if ( p.hasNext() ) {
8452                 return false;
8453             }
8454             if ( p.next() != null ) {
8455                 return false;
8456             }
8457             //
8458             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
8459             p.setSource( p2_str );
8460             if ( !p.hasNext() ) {
8461                 return false;
8462             }
8463             Phylogeny p2_0 = p.next();
8464             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8465                 System.out.println( p2_0.toNewHampshire() );
8466                 return false;
8467             }
8468             if ( !p.hasNext() ) {
8469                 return false;
8470             }
8471             Phylogeny p2_1 = p.next();
8472             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8473                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8474                 return false;
8475             }
8476             if ( !p.hasNext() ) {
8477                 return false;
8478             }
8479             Phylogeny p2_2 = p.next();
8480             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8481                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8482                 return false;
8483             }
8484             if ( !p.hasNext() ) {
8485                 return false;
8486             }
8487             Phylogeny p2_3 = p.next();
8488             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8489                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8490                 return false;
8491             }
8492             if ( !p.hasNext() ) {
8493                 return false;
8494             }
8495             Phylogeny p2_4 = p.next();
8496             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8497                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8498                 return false;
8499             }
8500             if ( p.hasNext() ) {
8501                 return false;
8502             }
8503             if ( p.next() != null ) {
8504                 return false;
8505             }
8506             ////
8507             p.reset();
8508             if ( !p.hasNext() ) {
8509                 return false;
8510             }
8511             p2_0 = p.next();
8512             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8513                 System.out.println( p2_0.toNewHampshire() );
8514                 return false;
8515             }
8516             if ( !p.hasNext() ) {
8517                 return false;
8518             }
8519             p2_1 = p.next();
8520             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8521                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8522                 return false;
8523             }
8524             if ( !p.hasNext() ) {
8525                 return false;
8526             }
8527             p2_2 = p.next();
8528             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8529                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8530                 return false;
8531             }
8532             if ( !p.hasNext() ) {
8533                 return false;
8534             }
8535             p2_3 = p.next();
8536             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8537                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8538                 return false;
8539             }
8540             if ( !p.hasNext() ) {
8541                 return false;
8542             }
8543             p2_4 = p.next();
8544             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8545                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8546                 return false;
8547             }
8548             if ( p.hasNext() ) {
8549                 return false;
8550             }
8551             if ( p.next() != null ) {
8552                 return false;
8553             }
8554             //
8555             final String p3_str = "((A,B),C)abc";
8556             p.setSource( p3_str );
8557             if ( !p.hasNext() ) {
8558                 return false;
8559             }
8560             final Phylogeny p3_0 = p.next();
8561             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
8562                 return false;
8563             }
8564             if ( p.hasNext() ) {
8565                 return false;
8566             }
8567             if ( p.next() != null ) {
8568                 return false;
8569             }
8570             //
8571             final String p4_str = "((A,B)ab,C)abc";
8572             p.setSource( p4_str );
8573             if ( !p.hasNext() ) {
8574                 return false;
8575             }
8576             final Phylogeny p4_0 = p.next();
8577             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
8578                 return false;
8579             }
8580             if ( p.hasNext() ) {
8581                 return false;
8582             }
8583             if ( p.next() != null ) {
8584                 return false;
8585             }
8586             //
8587             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
8588             p.setSource( p5_str );
8589             if ( !p.hasNext() ) {
8590                 return false;
8591             }
8592             final Phylogeny p5_0 = p.next();
8593             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
8594                 return false;
8595             }
8596             if ( p.hasNext() ) {
8597                 return false;
8598             }
8599             if ( p.next() != null ) {
8600                 return false;
8601             }
8602             //
8603             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8604             p.setSource( p6_str );
8605             if ( !p.hasNext() ) {
8606                 return false;
8607             }
8608             Phylogeny p6_0 = p.next();
8609             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8610                 return false;
8611             }
8612             if ( p.hasNext() ) {
8613                 return false;
8614             }
8615             if ( p.next() != null ) {
8616                 return false;
8617             }
8618             p.reset();
8619             if ( !p.hasNext() ) {
8620                 return false;
8621             }
8622             p6_0 = p.next();
8623             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8624                 return false;
8625             }
8626             if ( p.hasNext() ) {
8627                 return false;
8628             }
8629             if ( p.next() != null ) {
8630                 return false;
8631             }
8632             //
8633             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8634             p.setSource( p7_str );
8635             if ( !p.hasNext() ) {
8636                 return false;
8637             }
8638             Phylogeny p7_0 = p.next();
8639             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8640                 return false;
8641             }
8642             if ( p.hasNext() ) {
8643                 return false;
8644             }
8645             if ( p.next() != null ) {
8646                 return false;
8647             }
8648             p.reset();
8649             if ( !p.hasNext() ) {
8650                 return false;
8651             }
8652             p7_0 = p.next();
8653             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8654                 return false;
8655             }
8656             if ( p.hasNext() ) {
8657                 return false;
8658             }
8659             if ( p.next() != null ) {
8660                 return false;
8661             }
8662             //
8663             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
8664             p.setSource( p8_str );
8665             if ( !p.hasNext() ) {
8666                 return false;
8667             }
8668             Phylogeny p8_0 = p.next();
8669             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8670                 return false;
8671             }
8672             if ( !p.hasNext() ) {
8673                 return false;
8674             }
8675             if ( !p.hasNext() ) {
8676                 return false;
8677             }
8678             Phylogeny p8_1 = p.next();
8679             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8680                 return false;
8681             }
8682             if ( p.hasNext() ) {
8683                 return false;
8684             }
8685             if ( p.next() != null ) {
8686                 return false;
8687             }
8688             p.reset();
8689             if ( !p.hasNext() ) {
8690                 return false;
8691             }
8692             p8_0 = p.next();
8693             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8694                 return false;
8695             }
8696             if ( !p.hasNext() ) {
8697                 return false;
8698             }
8699             p8_1 = p.next();
8700             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8701                 return false;
8702             }
8703             if ( p.hasNext() ) {
8704                 return false;
8705             }
8706             if ( p.next() != null ) {
8707                 return false;
8708             }
8709             p.reset();
8710             //
8711             p.setSource( "" );
8712             if ( p.hasNext() ) {
8713                 return false;
8714             }
8715             //
8716             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
8717             if ( !p.hasNext() ) {
8718                 return false;
8719             }
8720             Phylogeny p_27 = p.next();
8721             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8722                 System.out.println( p_27.toNewHampshireX() );
8723                 System.exit( -1 );
8724                 return false;
8725             }
8726             if ( p.hasNext() ) {
8727                 return false;
8728             }
8729             if ( p.next() != null ) {
8730                 return false;
8731             }
8732             p.reset();
8733             if ( !p.hasNext() ) {
8734                 return false;
8735             }
8736             p_27 = p.next();
8737             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8738                 System.out.println( p_27.toNewHampshireX() );
8739                 System.exit( -1 );
8740                 return false;
8741             }
8742             if ( p.hasNext() ) {
8743                 return false;
8744             }
8745             if ( p.next() != null ) {
8746                 return false;
8747             }
8748             //
8749             final String p30_str = "(A,B);(C,D)";
8750             final NHXParser p30 = new NHXParser();
8751             p30.setSource( p30_str );
8752             if ( !p30.hasNext() ) {
8753                 return false;
8754             }
8755             Phylogeny phy30 = p30.next();
8756             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8757                 System.out.println( phy30.toNewHampshire() );
8758                 return false;
8759             }
8760             if ( !p30.hasNext() ) {
8761                 return false;
8762             }
8763             Phylogeny phy301 = p30.next();
8764             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8765                 System.out.println( phy301.toNewHampshire() );
8766                 return false;
8767             }
8768             if ( p30.hasNext() ) {
8769                 return false;
8770             }
8771             if ( p30.hasNext() ) {
8772                 return false;
8773             }
8774             if ( p30.next() != null ) {
8775                 return false;
8776             }
8777             if ( p30.next() != null ) {
8778                 return false;
8779             }
8780             p30.reset();
8781             if ( !p30.hasNext() ) {
8782                 return false;
8783             }
8784             phy30 = p30.next();
8785             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8786                 System.out.println( phy30.toNewHampshire() );
8787                 return false;
8788             }
8789             if ( !p30.hasNext() ) {
8790                 return false;
8791             }
8792             phy301 = p30.next();
8793             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8794                 System.out.println( phy301.toNewHampshire() );
8795                 return false;
8796             }
8797             if ( p30.hasNext() ) {
8798                 return false;
8799             }
8800             if ( p30.hasNext() ) {
8801                 return false;
8802             }
8803             if ( p30.next() != null ) {
8804                 return false;
8805             }
8806             if ( p30.next() != null ) {
8807                 return false;
8808             }
8809         }
8810         catch ( final Exception e ) {
8811             e.printStackTrace( System.out );
8812             return false;
8813         }
8814         return true;
8815     }
8816
8817     private static boolean testNHXconversion() {
8818         try {
8819             final PhylogenyNode n1 = new PhylogenyNode();
8820             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8821             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8822             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8823             final PhylogenyNode n5 = PhylogenyNode
8824                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
8825             final PhylogenyNode n6 = PhylogenyNode
8826                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
8827             if ( !n1.toNewHampshireX().equals( "" ) ) {
8828                 return false;
8829             }
8830             if ( !n2.toNewHampshireX().equals( "" ) ) {
8831                 return false;
8832             }
8833             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
8834                 return false;
8835             }
8836             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
8837                 return false;
8838             }
8839             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
8840                 return false;
8841             }
8842             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
8843                 System.out.println( n6.toNewHampshireX() );
8844                 return false;
8845             }
8846             final PhylogenyNode n7 = new PhylogenyNode();
8847             n7.setName( "   gks:dr-m4 \"    '    `@:[]sadq04 " );
8848             if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8849                     .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
8850                 System.out.println( n7
8851                         .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
8852                 return false;
8853             }
8854         }
8855         catch ( final Exception e ) {
8856             e.printStackTrace( System.out );
8857             return false;
8858         }
8859         return true;
8860     }
8861
8862     private static boolean testNHXNodeParsing() {
8863         try {
8864             final PhylogenyNode n1 = new PhylogenyNode();
8865             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
8866             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
8867             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
8868             final PhylogenyNode n5 = PhylogenyNode
8869                     .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]" );
8870             if ( !n3.getName().equals( "n3" ) ) {
8871                 return false;
8872             }
8873             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8874                 return false;
8875             }
8876             if ( n3.isDuplication() ) {
8877                 return false;
8878             }
8879             if ( n3.isHasAssignedEvent() ) {
8880                 return false;
8881             }
8882             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
8883                 return false;
8884             }
8885             if ( !n4.getName().equals( "n4" ) ) {
8886                 return false;
8887             }
8888             if ( n4.getDistanceToParent() != 0.01 ) {
8889                 return false;
8890             }
8891             if ( !n5.getName().equals( "n5" ) ) {
8892                 return false;
8893             }
8894             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
8895                 return false;
8896             }
8897             if ( n5.getDistanceToParent() != 0.1 ) {
8898                 return false;
8899             }
8900             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
8901                 return false;
8902             }
8903             if ( !n5.isDuplication() ) {
8904                 return false;
8905             }
8906             if ( !n5.isHasAssignedEvent() ) {
8907                 return false;
8908             }
8909             final PhylogenyNode n8 = PhylogenyNode
8910                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
8911                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8912             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8913                 return false;
8914             }
8915             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
8916                 return false;
8917             }
8918             final PhylogenyNode n9 = PhylogenyNode
8919                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
8920                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8921             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
8922                 return false;
8923             }
8924             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
8925                 return false;
8926             }
8927             final PhylogenyNode n10 = PhylogenyNode
8928                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8929             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
8930                 return false;
8931             }
8932             final PhylogenyNode n20 = PhylogenyNode
8933                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8934             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8935                 return false;
8936             }
8937             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
8938                 return false;
8939             }
8940             final PhylogenyNode n20x = PhylogenyNode
8941                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8942             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
8943                 return false;
8944             }
8945             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
8946                 return false;
8947             }
8948             final PhylogenyNode n20xx = PhylogenyNode
8949                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8950             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
8951                 return false;
8952             }
8953             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
8954                 return false;
8955             }
8956             final PhylogenyNode n20xxx = PhylogenyNode
8957                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8958             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
8959                 return false;
8960             }
8961             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
8962                 return false;
8963             }
8964             final PhylogenyNode n20xxxx = PhylogenyNode
8965                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8966             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
8967                 return false;
8968             }
8969             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
8970                 return false;
8971             }
8972             final PhylogenyNode n21 = PhylogenyNode
8973                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8974             if ( !n21.getName().equals( "N21_PIG" ) ) {
8975                 return false;
8976             }
8977             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
8978                 return false;
8979             }
8980             final PhylogenyNode n21x = PhylogenyNode
8981                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8982             if ( !n21x.getName().equals( "n21_PIG" ) ) {
8983                 return false;
8984             }
8985             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
8986                 return false;
8987             }
8988             final PhylogenyNode n22 = PhylogenyNode
8989                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8990             if ( !n22.getName().equals( "n22/PIG" ) ) {
8991                 return false;
8992             }
8993             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
8994                 return false;
8995             }
8996             final PhylogenyNode n23 = PhylogenyNode
8997                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8998             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
8999                 return false;
9000             }
9001             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
9002                 return false;
9003             }
9004             final PhylogenyNode a = PhylogenyNode
9005                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9006             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9007                 return false;
9008             }
9009             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
9010                 return false;
9011             }
9012             final PhylogenyNode c1 = PhylogenyNode
9013                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
9014                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9015             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
9016                 return false;
9017             }
9018             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
9019                 return false;
9020             }
9021             final PhylogenyNode c2 = PhylogenyNode
9022                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
9023                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9024             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
9025                 return false;
9026             }
9027             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
9028                 return false;
9029             }
9030             final PhylogenyNode e3 = PhylogenyNode
9031                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9032             if ( !e3.getName().equals( "n10_RAT~" ) ) {
9033                 return false;
9034             }
9035             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
9036                 return false;
9037             }
9038             final PhylogenyNode n11 = PhylogenyNode
9039                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
9040                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9041             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
9042                 return false;
9043             }
9044             if ( n11.getDistanceToParent() != 0.4 ) {
9045                 return false;
9046             }
9047             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
9048                 return false;
9049             }
9050             final PhylogenyNode n12 = PhylogenyNode
9051                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
9052                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9053             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
9054                 return false;
9055             }
9056             if ( n12.getDistanceToParent() != 0.4 ) {
9057                 return false;
9058             }
9059             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
9060                 return false;
9061             }
9062             final PhylogenyNode o = PhylogenyNode
9063                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9064             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
9065                 return false;
9066             }
9067             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
9068                 return false;
9069             }
9070             if ( n1.getName().compareTo( "" ) != 0 ) {
9071                 return false;
9072             }
9073             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9074                 return false;
9075             }
9076             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9077                 return false;
9078             }
9079             if ( n2.getName().compareTo( "" ) != 0 ) {
9080                 return false;
9081             }
9082             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9083                 return false;
9084             }
9085             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9086                 return false;
9087             }
9088             final PhylogenyNode n00 = PhylogenyNode
9089                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
9090             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
9091                 return false;
9092             }
9093             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
9094                 return false;
9095             }
9096             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
9097             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
9098                 return false;
9099             }
9100             final PhylogenyNode n13 = PhylogenyNode
9101                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9102             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
9103                 return false;
9104             }
9105             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
9106                 return false;
9107             }
9108             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9109                 return false;
9110             }
9111             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9112                 return false;
9113             }
9114             final PhylogenyNode n14 = PhylogenyNode
9115                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9116             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
9117                 return false;
9118             }
9119             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
9120                 return false;
9121             }
9122             final PhylogenyNode n15 = PhylogenyNode
9123                     .createInstanceFromNhxString( "something_wicked[123]",
9124                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9125             if ( !n15.getName().equals( "something_wicked" ) ) {
9126                 return false;
9127             }
9128             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
9129                 return false;
9130             }
9131             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
9132                 return false;
9133             }
9134             final PhylogenyNode n16 = PhylogenyNode
9135                     .createInstanceFromNhxString( "something_wicked2[9]",
9136                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9137             if ( !n16.getName().equals( "something_wicked2" ) ) {
9138                 return false;
9139             }
9140             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
9141                 return false;
9142             }
9143             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
9144                 return false;
9145             }
9146             final PhylogenyNode n17 = PhylogenyNode
9147                     .createInstanceFromNhxString( "something_wicked3[a]",
9148                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9149             if ( !n17.getName().equals( "something_wicked3" ) ) {
9150                 return false;
9151             }
9152             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
9153                 return false;
9154             }
9155             final PhylogenyNode n18 = PhylogenyNode
9156                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9157             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
9158                 return false;
9159             }
9160             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
9161                 return false;
9162             }
9163             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
9164                 return false;
9165             }
9166             final PhylogenyNode n19 = PhylogenyNode
9167                     .createInstanceFromNhxString( "BLAH_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9168             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
9169                 return false;
9170             }
9171             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9172                 return false;
9173             }
9174             final PhylogenyNode n30 = PhylogenyNode
9175                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
9176                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9177             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
9178                 return false;
9179             }
9180             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9181                 return false;
9182             }
9183             final PhylogenyNode n31 = PhylogenyNode
9184                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
9185                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9186             if ( n31.getNodeData().isHasTaxonomy() ) {
9187                 return false;
9188             }
9189             final PhylogenyNode n32 = PhylogenyNode
9190                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9191             if ( n32.getNodeData().isHasTaxonomy() ) {
9192                 return false;
9193             }
9194             final PhylogenyNode n40 = PhylogenyNode
9195                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9196             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9197                 return false;
9198             }
9199             final PhylogenyNode n41 = PhylogenyNode
9200                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9201             if ( n41.getNodeData().isHasTaxonomy() ) {
9202                 return false;
9203             }
9204             final PhylogenyNode n42 = PhylogenyNode
9205                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9206             if ( n42.getNodeData().isHasTaxonomy() ) {
9207                 return false;
9208             }
9209             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
9210                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
9211             if ( n43.getNodeData().isHasTaxonomy() ) {
9212                 return false;
9213             }
9214             final PhylogenyNode n44 = PhylogenyNode
9215                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9216             if ( n44.getNodeData().isHasTaxonomy() ) {
9217                 return false;
9218             }
9219         }
9220         catch ( final Exception e ) {
9221             e.printStackTrace( System.out );
9222             return false;
9223         }
9224         return true;
9225     }
9226
9227     private static boolean testNHXParsing() {
9228         try {
9229             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9230             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
9231             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
9232                 return false;
9233             }
9234             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]";
9235             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
9236             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9237                 return false;
9238             }
9239             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]";
9240             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
9241             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
9242                 return false;
9243             }
9244             final Phylogeny[] p3 = factory
9245                     .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]",
9246                              new NHXParser() );
9247             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9248                 return false;
9249             }
9250             final Phylogeny[] p4 = factory
9251                     .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(]",
9252                              new NHXParser() );
9253             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9254                 return false;
9255             }
9256             final Phylogeny[] p5 = factory
9257                     .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(((]",
9258                              new NHXParser() );
9259             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9260                 return false;
9261             }
9262             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)";
9263             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)";
9264             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
9265             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
9266                 return false;
9267             }
9268             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)))";
9269             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)))";
9270             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
9271             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
9272                 return false;
9273             }
9274             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])   ))[,,, ])))))))";
9275             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
9276             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
9277             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
9278                 return false;
9279             }
9280             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
9281             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9282                 return false;
9283             }
9284             final Phylogeny p10 = factory
9285                     .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]",
9286                              new NHXParser() )[ 0 ];
9287             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9288                 return false;
9289             }
9290             final Phylogeny p11 = factory
9291                     .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]",
9292                              new NHXParser() )[ 0 ];
9293             if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9294                 return false;
9295             }
9296         }
9297         catch ( final Exception e ) {
9298             e.printStackTrace( System.out );
9299             return false;
9300         }
9301         return true;
9302     }
9303
9304     private static boolean testNHXParsingMB() {
9305         try {
9306             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9307             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
9308                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9309                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9310                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9311                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9312                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9313                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9314                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9315                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
9316             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
9317                 return false;
9318             }
9319             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
9320                 return false;
9321             }
9322             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
9323                            0.1100000000000000e+00 ) ) {
9324                 return false;
9325             }
9326             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
9327                 return false;
9328             }
9329             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
9330                 return false;
9331             }
9332             final Phylogeny p2 = factory
9333                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
9334                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9335                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9336                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9337                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9338                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9339                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9340                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9341                                      + "7.369400000000000e-02}])",
9342                              new NHXParser() )[ 0 ];
9343             if ( p2.getNode( "1" ) == null ) {
9344                 return false;
9345             }
9346             if ( p2.getNode( "2" ) == null ) {
9347                 return false;
9348             }
9349         }
9350         catch ( final Exception e ) {
9351             e.printStackTrace( System.out );
9352             System.exit( -1 );
9353             return false;
9354         }
9355         return true;
9356     }
9357
9358     private static boolean testNHXParsingQuotes() {
9359         try {
9360             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9361             final NHXParser p = new NHXParser();
9362             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
9363             if ( phylogenies_0.length != 5 ) {
9364                 return false;
9365             }
9366             final Phylogeny phy = phylogenies_0[ 4 ];
9367             if ( phy.getNumberOfExternalNodes() != 7 ) {
9368                 return false;
9369             }
9370             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
9371                 return false;
9372             }
9373             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
9374                 return false;
9375             }
9376             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
9377                     .getScientificName().equals( "hsapiens" ) ) {
9378                 return false;
9379             }
9380             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
9381                 return false;
9382             }
9383             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
9384                 return false;
9385             }
9386             if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
9387                 return false;
9388             }
9389             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
9390                 return false;
9391             }
9392             if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
9393                 return false;
9394             }
9395             final NHXParser p1p = new NHXParser();
9396             p1p.setIgnoreQuotes( true );
9397             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
9398             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
9399                 return false;
9400             }
9401             final NHXParser p2p = new NHXParser();
9402             p1p.setIgnoreQuotes( false );
9403             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
9404             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
9405                 return false;
9406             }
9407             final NHXParser p3p = new NHXParser();
9408             p3p.setIgnoreQuotes( false );
9409             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
9410             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
9411                 return false;
9412             }
9413             final NHXParser p4p = new NHXParser();
9414             p4p.setIgnoreQuotes( false );
9415             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
9416             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
9417                 return false;
9418             }
9419             final Phylogeny p10 = factory
9420                     .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]",
9421                              new NHXParser() )[ 0 ];
9422             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]";
9423             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
9424                 return false;
9425             }
9426             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
9427             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
9428                 return false;
9429             }
9430             final Phylogeny p12 = factory
9431                     .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]",
9432                              new NHXParser() )[ 0 ];
9433             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]";
9434             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
9435                 return false;
9436             }
9437             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
9438             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
9439                 return false;
9440             }
9441             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;";
9442             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
9443                 return false;
9444             }
9445             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
9446             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
9447                 return false;
9448             }
9449         }
9450         catch ( final Exception e ) {
9451             e.printStackTrace( System.out );
9452             return false;
9453         }
9454         return true;
9455     }
9456
9457     private static boolean testNodeRemoval() {
9458         try {
9459             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9460             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
9461             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
9462             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
9463                 return false;
9464             }
9465             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
9466             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
9467             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
9468                 return false;
9469             }
9470             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
9471             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
9472             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
9473                 return false;
9474             }
9475         }
9476         catch ( final Exception e ) {
9477             e.printStackTrace( System.out );
9478             return false;
9479         }
9480         return true;
9481     }
9482
9483     private static boolean testPhylogenyBranch() {
9484         try {
9485             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
9486             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
9487             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
9488             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
9489             if ( !a1b1.equals( a1b1 ) ) {
9490                 return false;
9491             }
9492             if ( !a1b1.equals( b1a1 ) ) {
9493                 return false;
9494             }
9495             if ( !b1a1.equals( a1b1 ) ) {
9496                 return false;
9497             }
9498             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
9499             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
9500             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
9501             if ( a1_b1.equals( b1_a1 ) ) {
9502                 return false;
9503             }
9504             if ( a1_b1.equals( a1_b1_ ) ) {
9505                 return false;
9506             }
9507             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
9508             if ( !a1_b1.equals( b1_a1_ ) ) {
9509                 return false;
9510             }
9511             if ( a1_b1_.equals( b1_a1_ ) ) {
9512                 return false;
9513             }
9514             if ( !a1_b1_.equals( b1_a1 ) ) {
9515                 return false;
9516             }
9517         }
9518         catch ( final Exception e ) {
9519             e.printStackTrace( System.out );
9520             return false;
9521         }
9522         return true;
9523     }
9524
9525     private static boolean testPhyloXMLparsingOfDistributionElement() {
9526         try {
9527             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9528             PhyloXmlParser xml_parser = null;
9529             try {
9530                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
9531             }
9532             catch ( final Exception e ) {
9533                 // Do nothing -- means were not running from jar.
9534             }
9535             if ( xml_parser == null ) {
9536                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
9537                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
9538                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
9539                 }
9540                 else {
9541                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
9542                 }
9543             }
9544             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
9545                                                               xml_parser );
9546             if ( xml_parser.getErrorCount() > 0 ) {
9547                 System.out.println( xml_parser.getErrorMessages().toString() );
9548                 return false;
9549             }
9550             if ( phylogenies_0.length != 1 ) {
9551                 return false;
9552             }
9553             final Phylogeny t1 = phylogenies_0[ 0 ];
9554             PhylogenyNode n = null;
9555             Distribution d = null;
9556             n = t1.getNode( "root node" );
9557             if ( !n.getNodeData().isHasDistribution() ) {
9558                 return false;
9559             }
9560             if ( n.getNodeData().getDistributions().size() != 1 ) {
9561                 return false;
9562             }
9563             d = n.getNodeData().getDistribution();
9564             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9565                 return false;
9566             }
9567             if ( d.getPoints().size() != 1 ) {
9568                 return false;
9569             }
9570             if ( d.getPolygons() != null ) {
9571                 return false;
9572             }
9573             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9574                 return false;
9575             }
9576             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9577                 return false;
9578             }
9579             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9580                 return false;
9581             }
9582             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9583                 return false;
9584             }
9585             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9586                 return false;
9587             }
9588             n = t1.getNode( "node a" );
9589             if ( !n.getNodeData().isHasDistribution() ) {
9590                 return false;
9591             }
9592             if ( n.getNodeData().getDistributions().size() != 2 ) {
9593                 return false;
9594             }
9595             d = n.getNodeData().getDistribution( 1 );
9596             if ( !d.getDesc().equals( "San Diego" ) ) {
9597                 return false;
9598             }
9599             if ( d.getPoints().size() != 1 ) {
9600                 return false;
9601             }
9602             if ( d.getPolygons() != null ) {
9603                 return false;
9604             }
9605             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9606                 return false;
9607             }
9608             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9609                 return false;
9610             }
9611             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9612                 return false;
9613             }
9614             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9615                 return false;
9616             }
9617             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9618                 return false;
9619             }
9620             n = t1.getNode( "node bb" );
9621             if ( !n.getNodeData().isHasDistribution() ) {
9622                 return false;
9623             }
9624             if ( n.getNodeData().getDistributions().size() != 1 ) {
9625                 return false;
9626             }
9627             d = n.getNodeData().getDistribution( 0 );
9628             if ( d.getPoints().size() != 3 ) {
9629                 return false;
9630             }
9631             if ( d.getPolygons().size() != 2 ) {
9632                 return false;
9633             }
9634             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9635                 return false;
9636             }
9637             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9638                 return false;
9639             }
9640             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9641                 return false;
9642             }
9643             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9644                 return false;
9645             }
9646             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9647                 return false;
9648             }
9649             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9650                 return false;
9651             }
9652             Polygon p = d.getPolygons().get( 0 );
9653             if ( p.getPoints().size() != 3 ) {
9654                 return false;
9655             }
9656             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9657                 return false;
9658             }
9659             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9660                 return false;
9661             }
9662             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9663                 return false;
9664             }
9665             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9666                 return false;
9667             }
9668             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9669                 return false;
9670             }
9671             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9672                 return false;
9673             }
9674             p = d.getPolygons().get( 1 );
9675             if ( p.getPoints().size() != 3 ) {
9676                 return false;
9677             }
9678             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9679                 return false;
9680             }
9681             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9682                 return false;
9683             }
9684             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9685                 return false;
9686             }
9687             // Roundtrip:
9688             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
9689             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
9690             if ( rt.length != 1 ) {
9691                 return false;
9692             }
9693             final Phylogeny t1_rt = rt[ 0 ];
9694             n = t1_rt.getNode( "root node" );
9695             if ( !n.getNodeData().isHasDistribution() ) {
9696                 return false;
9697             }
9698             if ( n.getNodeData().getDistributions().size() != 1 ) {
9699                 return false;
9700             }
9701             d = n.getNodeData().getDistribution();
9702             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9703                 return false;
9704             }
9705             if ( d.getPoints().size() != 1 ) {
9706                 return false;
9707             }
9708             if ( d.getPolygons() != null ) {
9709                 return false;
9710             }
9711             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9712                 return false;
9713             }
9714             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9715                 return false;
9716             }
9717             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9718                 return false;
9719             }
9720             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9721                 return false;
9722             }
9723             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9724                 return false;
9725             }
9726             n = t1_rt.getNode( "node a" );
9727             if ( !n.getNodeData().isHasDistribution() ) {
9728                 return false;
9729             }
9730             if ( n.getNodeData().getDistributions().size() != 2 ) {
9731                 return false;
9732             }
9733             d = n.getNodeData().getDistribution( 1 );
9734             if ( !d.getDesc().equals( "San Diego" ) ) {
9735                 return false;
9736             }
9737             if ( d.getPoints().size() != 1 ) {
9738                 return false;
9739             }
9740             if ( d.getPolygons() != null ) {
9741                 return false;
9742             }
9743             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9744                 return false;
9745             }
9746             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9747                 return false;
9748             }
9749             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9750                 return false;
9751             }
9752             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9753                 return false;
9754             }
9755             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9756                 return false;
9757             }
9758             n = t1_rt.getNode( "node bb" );
9759             if ( !n.getNodeData().isHasDistribution() ) {
9760                 return false;
9761             }
9762             if ( n.getNodeData().getDistributions().size() != 1 ) {
9763                 return false;
9764             }
9765             d = n.getNodeData().getDistribution( 0 );
9766             if ( d.getPoints().size() != 3 ) {
9767                 return false;
9768             }
9769             if ( d.getPolygons().size() != 2 ) {
9770                 return false;
9771             }
9772             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9773                 return false;
9774             }
9775             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9776                 return false;
9777             }
9778             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9779                 return false;
9780             }
9781             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9782                 return false;
9783             }
9784             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9785                 return false;
9786             }
9787             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9788                 return false;
9789             }
9790             p = d.getPolygons().get( 0 );
9791             if ( p.getPoints().size() != 3 ) {
9792                 return false;
9793             }
9794             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9795                 return false;
9796             }
9797             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9798                 return false;
9799             }
9800             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9801                 return false;
9802             }
9803             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9804                 return false;
9805             }
9806             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9807                 return false;
9808             }
9809             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9810                 return false;
9811             }
9812             p = d.getPolygons().get( 1 );
9813             if ( p.getPoints().size() != 3 ) {
9814                 return false;
9815             }
9816             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9817                 return false;
9818             }
9819             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9820                 return false;
9821             }
9822             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9823                 return false;
9824             }
9825         }
9826         catch ( final Exception e ) {
9827             e.printStackTrace( System.out );
9828             return false;
9829         }
9830         return true;
9831     }
9832
9833     private static boolean testPostOrderIterator() {
9834         try {
9835             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9836             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9837             PhylogenyNodeIterator it0;
9838             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
9839                 it0.next();
9840             }
9841             for( it0.reset(); it0.hasNext(); ) {
9842                 it0.next();
9843             }
9844             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9845             final PhylogenyNodeIterator it = t1.iteratorPostorder();
9846             if ( !it.next().getName().equals( "A" ) ) {
9847                 return false;
9848             }
9849             if ( !it.next().getName().equals( "B" ) ) {
9850                 return false;
9851             }
9852             if ( !it.next().getName().equals( "ab" ) ) {
9853                 return false;
9854             }
9855             if ( !it.next().getName().equals( "C" ) ) {
9856                 return false;
9857             }
9858             if ( !it.next().getName().equals( "D" ) ) {
9859                 return false;
9860             }
9861             if ( !it.next().getName().equals( "cd" ) ) {
9862                 return false;
9863             }
9864             if ( !it.next().getName().equals( "abcd" ) ) {
9865                 return false;
9866             }
9867             if ( !it.next().getName().equals( "E" ) ) {
9868                 return false;
9869             }
9870             if ( !it.next().getName().equals( "F" ) ) {
9871                 return false;
9872             }
9873             if ( !it.next().getName().equals( "ef" ) ) {
9874                 return false;
9875             }
9876             if ( !it.next().getName().equals( "G" ) ) {
9877                 return false;
9878             }
9879             if ( !it.next().getName().equals( "H" ) ) {
9880                 return false;
9881             }
9882             if ( !it.next().getName().equals( "gh" ) ) {
9883                 return false;
9884             }
9885             if ( !it.next().getName().equals( "efgh" ) ) {
9886                 return false;
9887             }
9888             if ( !it.next().getName().equals( "r" ) ) {
9889                 return false;
9890             }
9891             if ( it.hasNext() ) {
9892                 return false;
9893             }
9894         }
9895         catch ( final Exception e ) {
9896             e.printStackTrace( System.out );
9897             return false;
9898         }
9899         return true;
9900     }
9901
9902     private static boolean testPreOrderIterator() {
9903         try {
9904             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9905             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9906             PhylogenyNodeIterator it0;
9907             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
9908                 it0.next();
9909             }
9910             for( it0.reset(); it0.hasNext(); ) {
9911                 it0.next();
9912             }
9913             PhylogenyNodeIterator it = t0.iteratorPreorder();
9914             if ( !it.next().getName().equals( "r" ) ) {
9915                 return false;
9916             }
9917             if ( !it.next().getName().equals( "ab" ) ) {
9918                 return false;
9919             }
9920             if ( !it.next().getName().equals( "A" ) ) {
9921                 return false;
9922             }
9923             if ( !it.next().getName().equals( "B" ) ) {
9924                 return false;
9925             }
9926             if ( !it.next().getName().equals( "cd" ) ) {
9927                 return false;
9928             }
9929             if ( !it.next().getName().equals( "C" ) ) {
9930                 return false;
9931             }
9932             if ( !it.next().getName().equals( "D" ) ) {
9933                 return false;
9934             }
9935             if ( it.hasNext() ) {
9936                 return false;
9937             }
9938             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9939             it = t1.iteratorPreorder();
9940             if ( !it.next().getName().equals( "r" ) ) {
9941                 return false;
9942             }
9943             if ( !it.next().getName().equals( "abcd" ) ) {
9944                 return false;
9945             }
9946             if ( !it.next().getName().equals( "ab" ) ) {
9947                 return false;
9948             }
9949             if ( !it.next().getName().equals( "A" ) ) {
9950                 return false;
9951             }
9952             if ( !it.next().getName().equals( "B" ) ) {
9953                 return false;
9954             }
9955             if ( !it.next().getName().equals( "cd" ) ) {
9956                 return false;
9957             }
9958             if ( !it.next().getName().equals( "C" ) ) {
9959                 return false;
9960             }
9961             if ( !it.next().getName().equals( "D" ) ) {
9962                 return false;
9963             }
9964             if ( !it.next().getName().equals( "efgh" ) ) {
9965                 return false;
9966             }
9967             if ( !it.next().getName().equals( "ef" ) ) {
9968                 return false;
9969             }
9970             if ( !it.next().getName().equals( "E" ) ) {
9971                 return false;
9972             }
9973             if ( !it.next().getName().equals( "F" ) ) {
9974                 return false;
9975             }
9976             if ( !it.next().getName().equals( "gh" ) ) {
9977                 return false;
9978             }
9979             if ( !it.next().getName().equals( "G" ) ) {
9980                 return false;
9981             }
9982             if ( !it.next().getName().equals( "H" ) ) {
9983                 return false;
9984             }
9985             if ( it.hasNext() ) {
9986                 return false;
9987             }
9988         }
9989         catch ( final Exception e ) {
9990             e.printStackTrace( System.out );
9991             return false;
9992         }
9993         return true;
9994     }
9995
9996     private static boolean testPropertiesMap() {
9997         try {
9998             final PropertiesMap pm = new PropertiesMap();
9999             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10000             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10001             final Property p2 = new Property( "something:else",
10002                                               "?",
10003                                               "improbable:research",
10004                                               "xsd:decimal",
10005                                               AppliesTo.NODE );
10006             pm.addProperty( p0 );
10007             pm.addProperty( p1 );
10008             pm.addProperty( p2 );
10009             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
10010                 return false;
10011             }
10012             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
10013                 return false;
10014             }
10015             if ( pm.getProperties().size() != 3 ) {
10016                 return false;
10017             }
10018             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
10019                 return false;
10020             }
10021             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10022                 return false;
10023             }
10024             if ( pm.getProperties().size() != 3 ) {
10025                 return false;
10026             }
10027             pm.removeProperty( "dimensions:diameter" );
10028             if ( pm.getProperties().size() != 2 ) {
10029                 return false;
10030             }
10031             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
10032                 return false;
10033             }
10034             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10035                 return false;
10036             }
10037         }
10038         catch ( final Exception e ) {
10039             e.printStackTrace( System.out );
10040             return false;
10041         }
10042         return true;
10043     }
10044
10045     private static boolean testProteinId() {
10046         try {
10047             final ProteinId id1 = new ProteinId( "a" );
10048             final ProteinId id2 = new ProteinId( "a" );
10049             final ProteinId id3 = new ProteinId( "A" );
10050             final ProteinId id4 = new ProteinId( "b" );
10051             if ( !id1.equals( id1 ) ) {
10052                 return false;
10053             }
10054             if ( id1.getId().equals( "x" ) ) {
10055                 return false;
10056             }
10057             if ( id1.getId().equals( null ) ) {
10058                 return false;
10059             }
10060             if ( !id1.equals( id2 ) ) {
10061                 return false;
10062             }
10063             if ( id1.equals( id3 ) ) {
10064                 return false;
10065             }
10066             if ( id1.hashCode() != id1.hashCode() ) {
10067                 return false;
10068             }
10069             if ( id1.hashCode() != id2.hashCode() ) {
10070                 return false;
10071             }
10072             if ( id1.hashCode() == id3.hashCode() ) {
10073                 return false;
10074             }
10075             if ( id1.compareTo( id1 ) != 0 ) {
10076                 return false;
10077             }
10078             if ( id1.compareTo( id2 ) != 0 ) {
10079                 return false;
10080             }
10081             if ( id1.compareTo( id3 ) != 0 ) {
10082                 return false;
10083             }
10084             if ( id1.compareTo( id4 ) >= 0 ) {
10085                 return false;
10086             }
10087             if ( id4.compareTo( id1 ) <= 0 ) {
10088                 return false;
10089             }
10090             if ( !id4.getId().equals( "b" ) ) {
10091                 return false;
10092             }
10093             final ProteinId id5 = new ProteinId( " C " );
10094             if ( !id5.getId().equals( "C" ) ) {
10095                 return false;
10096             }
10097             if ( id5.equals( id1 ) ) {
10098                 return false;
10099             }
10100         }
10101         catch ( final Exception e ) {
10102             e.printStackTrace( System.out );
10103             return false;
10104         }
10105         return true;
10106     }
10107
10108     private static boolean testReIdMethods() {
10109         try {
10110             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10111             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
10112             final long count = PhylogenyNode.getNodeCount();
10113             p.levelOrderReID();
10114             if ( p.getNode( "r" ).getId() != count ) {
10115                 return false;
10116             }
10117             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
10118                 return false;
10119             }
10120             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
10121                 return false;
10122             }
10123             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
10124                 return false;
10125             }
10126             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
10127                 return false;
10128             }
10129             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
10130                 return false;
10131             }
10132             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
10133                 return false;
10134             }
10135             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
10136                 return false;
10137             }
10138             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
10139                 return false;
10140             }
10141             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
10142                 return false;
10143             }
10144             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
10145                 return false;
10146             }
10147             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
10148                 return false;
10149             }
10150             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
10151                 return false;
10152             }
10153             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
10154                 return false;
10155             }
10156             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
10157                 return false;
10158             }
10159         }
10160         catch ( final Exception e ) {
10161             e.printStackTrace( System.out );
10162             return false;
10163         }
10164         return true;
10165     }
10166
10167     private static boolean testRerooting() {
10168         try {
10169             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10170             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",
10171                                                  new NHXParser() )[ 0 ];
10172             if ( !t1.isRooted() ) {
10173                 return false;
10174             }
10175             t1.reRoot( t1.getNode( "D" ) );
10176             t1.reRoot( t1.getNode( "CD" ) );
10177             t1.reRoot( t1.getNode( "A" ) );
10178             t1.reRoot( t1.getNode( "B" ) );
10179             t1.reRoot( t1.getNode( "AB" ) );
10180             t1.reRoot( t1.getNode( "D" ) );
10181             t1.reRoot( t1.getNode( "C" ) );
10182             t1.reRoot( t1.getNode( "CD" ) );
10183             t1.reRoot( t1.getNode( "A" ) );
10184             t1.reRoot( t1.getNode( "B" ) );
10185             t1.reRoot( t1.getNode( "AB" ) );
10186             t1.reRoot( t1.getNode( "D" ) );
10187             t1.reRoot( t1.getNode( "D" ) );
10188             t1.reRoot( t1.getNode( "C" ) );
10189             t1.reRoot( t1.getNode( "A" ) );
10190             t1.reRoot( t1.getNode( "B" ) );
10191             t1.reRoot( t1.getNode( "AB" ) );
10192             t1.reRoot( t1.getNode( "C" ) );
10193             t1.reRoot( t1.getNode( "D" ) );
10194             t1.reRoot( t1.getNode( "CD" ) );
10195             t1.reRoot( t1.getNode( "D" ) );
10196             t1.reRoot( t1.getNode( "A" ) );
10197             t1.reRoot( t1.getNode( "B" ) );
10198             t1.reRoot( t1.getNode( "AB" ) );
10199             t1.reRoot( t1.getNode( "C" ) );
10200             t1.reRoot( t1.getNode( "D" ) );
10201             t1.reRoot( t1.getNode( "CD" ) );
10202             t1.reRoot( t1.getNode( "D" ) );
10203             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
10204                 return false;
10205             }
10206             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
10207                 return false;
10208             }
10209             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
10210                 return false;
10211             }
10212             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
10213                 return false;
10214             }
10215             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
10216                 return false;
10217             }
10218             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
10219                 return false;
10220             }
10221             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",
10222                                                  new NHXParser() )[ 0 ];
10223             t2.reRoot( t2.getNode( "A" ) );
10224             t2.reRoot( t2.getNode( "D" ) );
10225             t2.reRoot( t2.getNode( "ABC" ) );
10226             t2.reRoot( t2.getNode( "A" ) );
10227             t2.reRoot( t2.getNode( "B" ) );
10228             t2.reRoot( t2.getNode( "D" ) );
10229             t2.reRoot( t2.getNode( "C" ) );
10230             t2.reRoot( t2.getNode( "ABC" ) );
10231             t2.reRoot( t2.getNode( "A" ) );
10232             t2.reRoot( t2.getNode( "B" ) );
10233             t2.reRoot( t2.getNode( "AB" ) );
10234             t2.reRoot( t2.getNode( "AB" ) );
10235             t2.reRoot( t2.getNode( "D" ) );
10236             t2.reRoot( t2.getNode( "C" ) );
10237             t2.reRoot( t2.getNode( "B" ) );
10238             t2.reRoot( t2.getNode( "AB" ) );
10239             t2.reRoot( t2.getNode( "D" ) );
10240             t2.reRoot( t2.getNode( "D" ) );
10241             t2.reRoot( t2.getNode( "ABC" ) );
10242             t2.reRoot( t2.getNode( "A" ) );
10243             t2.reRoot( t2.getNode( "B" ) );
10244             t2.reRoot( t2.getNode( "AB" ) );
10245             t2.reRoot( t2.getNode( "D" ) );
10246             t2.reRoot( t2.getNode( "C" ) );
10247             t2.reRoot( t2.getNode( "ABC" ) );
10248             t2.reRoot( t2.getNode( "A" ) );
10249             t2.reRoot( t2.getNode( "B" ) );
10250             t2.reRoot( t2.getNode( "AB" ) );
10251             t2.reRoot( t2.getNode( "D" ) );
10252             t2.reRoot( t2.getNode( "D" ) );
10253             t2.reRoot( t2.getNode( "C" ) );
10254             t2.reRoot( t2.getNode( "A" ) );
10255             t2.reRoot( t2.getNode( "B" ) );
10256             t2.reRoot( t2.getNode( "AB" ) );
10257             t2.reRoot( t2.getNode( "C" ) );
10258             t2.reRoot( t2.getNode( "D" ) );
10259             t2.reRoot( t2.getNode( "ABC" ) );
10260             t2.reRoot( t2.getNode( "D" ) );
10261             t2.reRoot( t2.getNode( "A" ) );
10262             t2.reRoot( t2.getNode( "B" ) );
10263             t2.reRoot( t2.getNode( "AB" ) );
10264             t2.reRoot( t2.getNode( "C" ) );
10265             t2.reRoot( t2.getNode( "D" ) );
10266             t2.reRoot( t2.getNode( "ABC" ) );
10267             t2.reRoot( t2.getNode( "D" ) );
10268             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10269                 return false;
10270             }
10271             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10272                 return false;
10273             }
10274             t2.reRoot( t2.getNode( "ABC" ) );
10275             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10276                 return false;
10277             }
10278             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10279                 return false;
10280             }
10281             t2.reRoot( t2.getNode( "AB" ) );
10282             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10283                 return false;
10284             }
10285             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10286                 return false;
10287             }
10288             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10289                 return false;
10290             }
10291             t2.reRoot( t2.getNode( "AB" ) );
10292             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10293                 return false;
10294             }
10295             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10296                 return false;
10297             }
10298             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10299                 return false;
10300             }
10301             t2.reRoot( t2.getNode( "D" ) );
10302             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10303                 return false;
10304             }
10305             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10306                 return false;
10307             }
10308             t2.reRoot( t2.getNode( "ABC" ) );
10309             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10310                 return false;
10311             }
10312             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10313                 return false;
10314             }
10315             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
10316                                                  new NHXParser() )[ 0 ];
10317             t3.reRoot( t3.getNode( "B" ) );
10318             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10319                 return false;
10320             }
10321             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10322                 return false;
10323             }
10324             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10325                 return false;
10326             }
10327             t3.reRoot( t3.getNode( "B" ) );
10328             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10329                 return false;
10330             }
10331             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10332                 return false;
10333             }
10334             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10335                 return false;
10336             }
10337             t3.reRoot( t3.getRoot() );
10338             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10339                 return false;
10340             }
10341             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10342                 return false;
10343             }
10344             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10345                 return false;
10346             }
10347         }
10348         catch ( final Exception e ) {
10349             e.printStackTrace( System.out );
10350             return false;
10351         }
10352         return true;
10353     }
10354
10355     private static boolean testSDIse() {
10356         try {
10357             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10358             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
10359             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
10360             gene1.setRooted( true );
10361             species1.setRooted( true );
10362             final SDI sdi = new SDI( gene1, species1 );
10363             if ( !gene1.getRoot().isDuplication() ) {
10364                 return false;
10365             }
10366             final Phylogeny species2 = factory
10367                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10368                              new NHXParser() )[ 0 ];
10369             final Phylogeny gene2 = factory
10370                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10371                              new NHXParser() )[ 0 ];
10372             species2.setRooted( true );
10373             gene2.setRooted( true );
10374             final SDI sdi2 = new SDI( gene2, species2 );
10375             if ( sdi2.getDuplicationsSum() != 0 ) {
10376                 return false;
10377             }
10378             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
10379                 return false;
10380             }
10381             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
10382                 return false;
10383             }
10384             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
10385                 return false;
10386             }
10387             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
10388                 return false;
10389             }
10390             if ( !gene2.getNode( "r" ).isSpeciation() ) {
10391                 return false;
10392             }
10393             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
10394                 return false;
10395             }
10396             final Phylogeny species3 = factory
10397                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10398                              new NHXParser() )[ 0 ];
10399             final Phylogeny gene3 = factory
10400                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10401                              new NHXParser() )[ 0 ];
10402             species3.setRooted( true );
10403             gene3.setRooted( true );
10404             final SDI sdi3 = new SDI( gene3, species3 );
10405             if ( sdi3.getDuplicationsSum() != 1 ) {
10406                 return false;
10407             }
10408             if ( !gene3.getNode( "aa" ).isDuplication() ) {
10409                 return false;
10410             }
10411             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
10412                 return false;
10413             }
10414             final Phylogeny species4 = factory
10415                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10416                              new NHXParser() )[ 0 ];
10417             final Phylogeny gene4 = factory
10418                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10419                              new NHXParser() )[ 0 ];
10420             species4.setRooted( true );
10421             gene4.setRooted( true );
10422             final SDI sdi4 = new SDI( gene4, species4 );
10423             if ( sdi4.getDuplicationsSum() != 1 ) {
10424                 return false;
10425             }
10426             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
10427                 return false;
10428             }
10429             if ( !gene4.getNode( "abc" ).isDuplication() ) {
10430                 return false;
10431             }
10432             if ( gene4.getNode( "abcd" ).isDuplication() ) {
10433                 return false;
10434             }
10435             if ( species4.getNumberOfExternalNodes() != 6 ) {
10436                 return false;
10437             }
10438             if ( gene4.getNumberOfExternalNodes() != 6 ) {
10439                 return false;
10440             }
10441             final Phylogeny species5 = factory
10442                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10443                              new NHXParser() )[ 0 ];
10444             final Phylogeny gene5 = factory
10445                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10446                              new NHXParser() )[ 0 ];
10447             species5.setRooted( true );
10448             gene5.setRooted( true );
10449             final SDI sdi5 = new SDI( gene5, species5 );
10450             if ( sdi5.getDuplicationsSum() != 2 ) {
10451                 return false;
10452             }
10453             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
10454                 return false;
10455             }
10456             if ( !gene5.getNode( "adc" ).isDuplication() ) {
10457                 return false;
10458             }
10459             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
10460                 return false;
10461             }
10462             if ( species5.getNumberOfExternalNodes() != 6 ) {
10463                 return false;
10464             }
10465             if ( gene5.getNumberOfExternalNodes() != 6 ) {
10466                 return false;
10467             }
10468             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
10469             // Conjecture for Comparing Molecular Phylogenies"
10470             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
10471             final Phylogeny species6 = factory
10472                     .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,"
10473                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10474                              new NHXParser() )[ 0 ];
10475             final Phylogeny gene6 = factory
10476                     .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,"
10477                                      + "((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,"
10478                                      + "(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;",
10479                              new NHXParser() )[ 0 ];
10480             species6.setRooted( true );
10481             gene6.setRooted( true );
10482             final SDI sdi6 = new SDI( gene6, species6 );
10483             if ( sdi6.getDuplicationsSum() != 3 ) {
10484                 return false;
10485             }
10486             if ( !gene6.getNode( "r" ).isDuplication() ) {
10487                 return false;
10488             }
10489             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
10490                 return false;
10491             }
10492             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
10493                 return false;
10494             }
10495             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
10496                 return false;
10497             }
10498             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
10499                 return false;
10500             }
10501             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
10502                 return false;
10503             }
10504             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
10505                 return false;
10506             }
10507             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
10508                 return false;
10509             }
10510             sdi6.computeMappingCostL();
10511             if ( sdi6.computeMappingCostL() != 17 ) {
10512                 return false;
10513             }
10514             if ( species6.getNumberOfExternalNodes() != 9 ) {
10515                 return false;
10516             }
10517             if ( gene6.getNumberOfExternalNodes() != 9 ) {
10518                 return false;
10519             }
10520             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
10521                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
10522                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
10523                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
10524                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
10525             species7.setRooted( true );
10526             final Phylogeny gene7_1 = Test
10527                     .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])" );
10528             gene7_1.setRooted( true );
10529             final SDI sdi7 = new SDI( gene7_1, species7 );
10530             if ( sdi7.getDuplicationsSum() != 0 ) {
10531                 return false;
10532             }
10533             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
10534                 return false;
10535             }
10536             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
10537                 return false;
10538             }
10539             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
10540                 return false;
10541             }
10542             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
10543                 return false;
10544             }
10545             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
10546                 return false;
10547             }
10548             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
10549                 return false;
10550             }
10551             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
10552                 return false;
10553             }
10554             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
10555                 return false;
10556             }
10557             final Phylogeny gene7_2 = Test
10558                     .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])" );
10559             gene7_2.setRooted( true );
10560             final SDI sdi7_2 = new SDI( gene7_2, species7 );
10561             if ( sdi7_2.getDuplicationsSum() != 1 ) {
10562                 return false;
10563             }
10564             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
10565                 return false;
10566             }
10567             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
10568                 return false;
10569             }
10570             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
10571                 return false;
10572             }
10573             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
10574                 return false;
10575             }
10576             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
10577                 return false;
10578             }
10579             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
10580                 return false;
10581             }
10582             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
10583                 return false;
10584             }
10585             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
10586                 return false;
10587             }
10588             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
10589                 return false;
10590             }
10591         }
10592         catch ( final Exception e ) {
10593             return false;
10594         }
10595         return true;
10596     }
10597
10598     private static boolean testSDIunrooted() {
10599         try {
10600             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10601             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
10602             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
10603             final Iterator<PhylogenyBranch> iter = l.iterator();
10604             PhylogenyBranch br = iter.next();
10605             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
10606                 return false;
10607             }
10608             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
10609                 return false;
10610             }
10611             br = iter.next();
10612             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10613                 return false;
10614             }
10615             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10616                 return false;
10617             }
10618             br = iter.next();
10619             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
10620                 return false;
10621             }
10622             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
10623                 return false;
10624             }
10625             br = iter.next();
10626             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10627                 return false;
10628             }
10629             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10630                 return false;
10631             }
10632             br = iter.next();
10633             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10634                 return false;
10635             }
10636             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10637                 return false;
10638             }
10639             br = iter.next();
10640             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10641                 return false;
10642             }
10643             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10644                 return false;
10645             }
10646             br = iter.next();
10647             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10648                 return false;
10649             }
10650             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10651                 return false;
10652             }
10653             br = iter.next();
10654             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10655                 return false;
10656             }
10657             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10658                 return false;
10659             }
10660             br = iter.next();
10661             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10662                 return false;
10663             }
10664             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10665                 return false;
10666             }
10667             br = iter.next();
10668             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10669                 return false;
10670             }
10671             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10672                 return false;
10673             }
10674             br = iter.next();
10675             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10676                 return false;
10677             }
10678             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10679                 return false;
10680             }
10681             br = iter.next();
10682             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
10683                 return false;
10684             }
10685             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
10686                 return false;
10687             }
10688             br = iter.next();
10689             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10690                 return false;
10691             }
10692             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10693                 return false;
10694             }
10695             br = iter.next();
10696             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
10697                 return false;
10698             }
10699             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
10700                 return false;
10701             }
10702             br = iter.next();
10703             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
10704                 return false;
10705             }
10706             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
10707                 return false;
10708             }
10709             if ( iter.hasNext() ) {
10710                 return false;
10711             }
10712             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
10713             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
10714             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
10715             br = iter1.next();
10716             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10717                 return false;
10718             }
10719             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10720                 return false;
10721             }
10722             br = iter1.next();
10723             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10724                 return false;
10725             }
10726             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10727                 return false;
10728             }
10729             br = iter1.next();
10730             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10731                 return false;
10732             }
10733             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10734                 return false;
10735             }
10736             if ( iter1.hasNext() ) {
10737                 return false;
10738             }
10739             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
10740             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
10741             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
10742             br = iter2.next();
10743             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10744                 return false;
10745             }
10746             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10747                 return false;
10748             }
10749             br = iter2.next();
10750             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10751                 return false;
10752             }
10753             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10754                 return false;
10755             }
10756             br = iter2.next();
10757             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10758                 return false;
10759             }
10760             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10761                 return false;
10762             }
10763             if ( iter2.hasNext() ) {
10764                 return false;
10765             }
10766             final Phylogeny species0 = factory
10767                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10768                              new NHXParser() )[ 0 ];
10769             final Phylogeny gene1 = factory
10770                     .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])",
10771                              new NHXParser() )[ 0 ];
10772             species0.setRooted( true );
10773             gene1.setRooted( true );
10774             final SDIR sdi_unrooted = new SDIR();
10775             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
10776             if ( sdi_unrooted.getCount() != 1 ) {
10777                 return false;
10778             }
10779             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
10780                 return false;
10781             }
10782             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
10783                 return false;
10784             }
10785             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
10786                 return false;
10787             }
10788             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10789                 return false;
10790             }
10791             final Phylogeny gene2 = factory
10792                     .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])",
10793                              new NHXParser() )[ 0 ];
10794             gene2.setRooted( true );
10795             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
10796             if ( sdi_unrooted.getCount() != 1 ) {
10797                 return false;
10798             }
10799             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10800                 return false;
10801             }
10802             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10803                 return false;
10804             }
10805             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
10806                 return false;
10807             }
10808             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10809                 return false;
10810             }
10811             final Phylogeny species6 = factory
10812                     .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,"
10813                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10814                              new NHXParser() )[ 0 ];
10815             final Phylogeny gene6 = factory
10816                     .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],"
10817                                      + "(((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],"
10818                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10819                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10820                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10821                              new NHXParser() )[ 0 ];
10822             species6.setRooted( true );
10823             gene6.setRooted( true );
10824             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
10825             if ( sdi_unrooted.getCount() != 1 ) {
10826                 return false;
10827             }
10828             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10829                 return false;
10830             }
10831             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10832                 return false;
10833             }
10834             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10835                 return false;
10836             }
10837             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10838                 return false;
10839             }
10840             if ( !p6[ 0 ].getRoot().isDuplication() ) {
10841                 return false;
10842             }
10843             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10844                 return false;
10845             }
10846             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10847                 return false;
10848             }
10849             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
10850                 return false;
10851             }
10852             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10853                 return false;
10854             }
10855             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
10856                 return false;
10857             }
10858             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
10859                 return false;
10860             }
10861             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10862                 return false;
10863             }
10864             p6 = null;
10865             final Phylogeny species7 = factory
10866                     .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,"
10867                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10868                              new NHXParser() )[ 0 ];
10869             final Phylogeny gene7 = factory
10870                     .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],"
10871                                      + "(((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],"
10872                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10873                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10874                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10875                              new NHXParser() )[ 0 ];
10876             species7.setRooted( true );
10877             gene7.setRooted( true );
10878             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
10879             if ( sdi_unrooted.getCount() != 1 ) {
10880                 return false;
10881             }
10882             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10883                 return false;
10884             }
10885             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10886                 return false;
10887             }
10888             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10889                 return false;
10890             }
10891             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
10892                 return false;
10893             }
10894             if ( !p7[ 0 ].getRoot().isDuplication() ) {
10895                 return false;
10896             }
10897             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10898                 return false;
10899             }
10900             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10901                 return false;
10902             }
10903             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
10904                 return false;
10905             }
10906             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10907                 return false;
10908             }
10909             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
10910                 return false;
10911             }
10912             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
10913                 return false;
10914             }
10915             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10916                 return false;
10917             }
10918             p7 = null;
10919             final Phylogeny species8 = factory
10920                     .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,"
10921                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10922                              new NHXParser() )[ 0 ];
10923             final Phylogeny gene8 = factory
10924                     .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],"
10925                                      + "(((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],"
10926                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10927                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10928                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10929                              new NHXParser() )[ 0 ];
10930             species8.setRooted( true );
10931             gene8.setRooted( true );
10932             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
10933             if ( sdi_unrooted.getCount() != 1 ) {
10934                 return false;
10935             }
10936             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10937                 return false;
10938             }
10939             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10940                 return false;
10941             }
10942             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10943                 return false;
10944             }
10945             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10946                 return false;
10947             }
10948             if ( !p8[ 0 ].getRoot().isDuplication() ) {
10949                 return false;
10950             }
10951             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10952                 return false;
10953             }
10954             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10955                 return false;
10956             }
10957             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
10958                 return false;
10959             }
10960             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10961                 return false;
10962             }
10963             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
10964                 return false;
10965             }
10966             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
10967                 return false;
10968             }
10969             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10970                 return false;
10971             }
10972             p8 = null;
10973         }
10974         catch ( final Exception e ) {
10975             e.printStackTrace( System.out );
10976             return false;
10977         }
10978         return true;
10979     }
10980
10981     private static boolean testSequenceDbWsTools1() {
10982         try {
10983             final PhylogenyNode n = new PhylogenyNode();
10984             n.setName( "NP_001025424" );
10985             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
10986             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10987                     || !acc.getValue().equals( "NP_001025424" ) ) {
10988                 return false;
10989             }
10990             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
10991             acc = SequenceDbWsTools.obtainSeqAccession( n );
10992             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10993                     || !acc.getValue().equals( "NP_001025424" ) ) {
10994                 return false;
10995             }
10996             n.setName( "NP_001025424.1" );
10997             acc = SequenceDbWsTools.obtainSeqAccession( n );
10998             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
10999                     || !acc.getValue().equals( "NP_001025424" ) ) {
11000                 return false;
11001             }
11002             n.setName( "NM_001030253" );
11003             acc = SequenceDbWsTools.obtainSeqAccession( n );
11004             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11005                     || !acc.getValue().equals( "NM_001030253" ) ) {
11006                 return false;
11007             }
11008             n.setName( "BCL2_HUMAN" );
11009             acc = SequenceDbWsTools.obtainSeqAccession( n );
11010             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11011                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
11012                 System.out.println( acc.toString() );
11013                 return false;
11014             }
11015             n.setName( "P10415" );
11016             acc = SequenceDbWsTools.obtainSeqAccession( n );
11017             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11018                     || !acc.getValue().equals( "P10415" ) ) {
11019                 System.out.println( acc.toString() );
11020                 return false;
11021             }
11022             n.setName( " P10415 " );
11023             acc = SequenceDbWsTools.obtainSeqAccession( n );
11024             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11025                     || !acc.getValue().equals( "P10415" ) ) {
11026                 System.out.println( acc.toString() );
11027                 return false;
11028             }
11029             n.setName( "_P10415|" );
11030             acc = SequenceDbWsTools.obtainSeqAccession( n );
11031             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11032                     || !acc.getValue().equals( "P10415" ) ) {
11033                 System.out.println( acc.toString() );
11034                 return false;
11035             }
11036             n.setName( "AY695820" );
11037             acc = SequenceDbWsTools.obtainSeqAccession( n );
11038             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11039                     || !acc.getValue().equals( "AY695820" ) ) {
11040                 System.out.println( acc.toString() );
11041                 return false;
11042             }
11043             n.setName( "_AY695820_" );
11044             acc = SequenceDbWsTools.obtainSeqAccession( n );
11045             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11046                     || !acc.getValue().equals( "AY695820" ) ) {
11047                 System.out.println( acc.toString() );
11048                 return false;
11049             }
11050             n.setName( "AAA59452" );
11051             acc = SequenceDbWsTools.obtainSeqAccession( n );
11052             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11053                     || !acc.getValue().equals( "AAA59452" ) ) {
11054                 System.out.println( acc.toString() );
11055                 return false;
11056             }
11057             n.setName( "_AAA59452_" );
11058             acc = SequenceDbWsTools.obtainSeqAccession( n );
11059             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11060                     || !acc.getValue().equals( "AAA59452" ) ) {
11061                 System.out.println( acc.toString() );
11062                 return false;
11063             }
11064             n.setName( "AAA59452.1" );
11065             acc = SequenceDbWsTools.obtainSeqAccession( n );
11066             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11067                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11068                 System.out.println( acc.toString() );
11069                 return false;
11070             }
11071             n.setName( "_AAA59452.1_" );
11072             acc = SequenceDbWsTools.obtainSeqAccession( n );
11073             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11074                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11075                 System.out.println( acc.toString() );
11076                 return false;
11077             }
11078             n.setName( "GI:94894583" );
11079             acc = SequenceDbWsTools.obtainSeqAccession( n );
11080             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11081                     || !acc.getValue().equals( "94894583" ) ) {
11082                 System.out.println( acc.toString() );
11083                 return false;
11084             }
11085             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11086             acc = SequenceDbWsTools.obtainSeqAccession( n );
11087             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11088                     || !acc.getValue().equals( "71845847" ) ) {
11089                 System.out.println( acc.toString() );
11090                 return false;
11091             }
11092             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11093             acc = SequenceDbWsTools.obtainSeqAccession( n );
11094             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11095                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
11096                 System.out.println( acc.toString() );
11097                 return false;
11098             }
11099         }
11100         catch ( final Exception e ) {
11101             return false;
11102         }
11103         return true;
11104     }
11105
11106     private static boolean testSequenceDbWsTools2() {
11107         try {
11108             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
11109             SequenceDbWsTools.obtainSeqInformation( n1 );
11110             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
11111                 return false;
11112             }
11113             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11114                 return false;
11115             }
11116             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11117                 return false;
11118             }
11119             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
11120                 return false;
11121             }
11122             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
11123             SequenceDbWsTools.obtainSeqInformation( n2 );
11124             if ( !n2.getNodeData().getSequence().getName()
11125                     .equals( "Danio rerio B-cell leukemia/lymphoma 2 (bcl2), mRNA" ) ) {
11126                 return false;
11127             }
11128             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11129                 return false;
11130             }
11131             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11132                 return false;
11133             }
11134             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
11135                 return false;
11136             }
11137             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
11138             SequenceDbWsTools.obtainSeqInformation( n3 );
11139             if ( !n3.getNodeData().getSequence().getName()
11140                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
11141                 return false;
11142             }
11143             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
11144                 return false;
11145             }
11146             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11147                 return false;
11148             }
11149             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
11150                 return false;
11151             }
11152         }
11153         catch ( final IOException e ) {
11154             System.out.println();
11155             System.out.println( "the following might be due to absence internet connection:" );
11156             e.printStackTrace( System.out );
11157             return true;
11158         }
11159         catch ( final Exception e ) {
11160             e.printStackTrace();
11161             return false;
11162         }
11163         return true;
11164     }
11165
11166     private static boolean testSequenceIdParsing() {
11167         try {
11168             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
11169             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11170                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11171                 if ( id != null ) {
11172                     System.out.println( "value   =" + id.getValue() );
11173                     System.out.println( "provider=" + id.getSource() );
11174                 }
11175                 return false;
11176             }
11177             //
11178             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
11179             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11180                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11181                 if ( id != null ) {
11182                     System.out.println( "value   =" + id.getValue() );
11183                     System.out.println( "provider=" + id.getSource() );
11184                 }
11185                 return false;
11186             }
11187             //
11188             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
11189             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11190                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11191                 if ( id != null ) {
11192                     System.out.println( "value   =" + id.getValue() );
11193                     System.out.println( "provider=" + id.getSource() );
11194                 }
11195                 return false;
11196             }
11197             // 
11198             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
11199             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11200                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
11201                 if ( id != null ) {
11202                     System.out.println( "value   =" + id.getValue() );
11203                     System.out.println( "provider=" + id.getSource() );
11204                 }
11205                 return false;
11206             }
11207             // 
11208             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
11209             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11210                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
11211                 if ( id != null ) {
11212                     System.out.println( "value   =" + id.getValue() );
11213                     System.out.println( "provider=" + id.getSource() );
11214                 }
11215                 return false;
11216             }
11217             // 
11218             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
11219             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11220                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
11221                 if ( id != null ) {
11222                     System.out.println( "value   =" + id.getValue() );
11223                     System.out.println( "provider=" + id.getSource() );
11224                 }
11225                 return false;
11226             }
11227             // 
11228             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
11229             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11230                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
11231                 if ( id != null ) {
11232                     System.out.println( "value   =" + id.getValue() );
11233                     System.out.println( "provider=" + id.getSource() );
11234                 }
11235                 return false;
11236             }
11237             // 
11238             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
11239             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11240                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11241                 if ( id != null ) {
11242                     System.out.println( "value   =" + id.getValue() );
11243                     System.out.println( "provider=" + id.getSource() );
11244                 }
11245                 return false;
11246             }
11247             // 
11248             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
11249             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11250                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11251                 if ( id != null ) {
11252                     System.out.println( "value   =" + id.getValue() );
11253                     System.out.println( "provider=" + id.getSource() );
11254                 }
11255                 return false;
11256             }
11257             // 
11258             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
11259             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11260                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
11261                 if ( id != null ) {
11262                     System.out.println( "value   =" + id.getValue() );
11263                     System.out.println( "provider=" + id.getSource() );
11264                 }
11265                 return false;
11266             }
11267             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
11268             if ( id != null ) {
11269                 System.out.println( "value   =" + id.getValue() );
11270                 System.out.println( "provider=" + id.getSource() );
11271                 return false;
11272             }
11273         }
11274         catch ( final Exception e ) {
11275             e.printStackTrace( System.out );
11276             return false;
11277         }
11278         return true;
11279     }
11280
11281     private static boolean testSequenceWriter() {
11282         try {
11283             final String n = ForesterUtil.LINE_SEPARATOR;
11284             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
11285                 return false;
11286             }
11287             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
11288                 return false;
11289             }
11290             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
11291                 return false;
11292             }
11293             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
11294                 return false;
11295             }
11296             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
11297                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
11298                 return false;
11299             }
11300             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
11301                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
11302                 return false;
11303             }
11304         }
11305         catch ( final Exception e ) {
11306             e.printStackTrace();
11307             return false;
11308         }
11309         return true;
11310     }
11311
11312     private static boolean testSpecies() {
11313         try {
11314             final Species s1 = new BasicSpecies( "a" );
11315             final Species s2 = new BasicSpecies( "a" );
11316             final Species s3 = new BasicSpecies( "A" );
11317             final Species s4 = new BasicSpecies( "b" );
11318             if ( !s1.equals( s1 ) ) {
11319                 return false;
11320             }
11321             if ( s1.getSpeciesId().equals( "x" ) ) {
11322                 return false;
11323             }
11324             if ( s1.getSpeciesId().equals( null ) ) {
11325                 return false;
11326             }
11327             if ( !s1.equals( s2 ) ) {
11328                 return false;
11329             }
11330             if ( s1.equals( s3 ) ) {
11331                 return false;
11332             }
11333             if ( s1.hashCode() != s1.hashCode() ) {
11334                 return false;
11335             }
11336             if ( s1.hashCode() != s2.hashCode() ) {
11337                 return false;
11338             }
11339             if ( s1.hashCode() == s3.hashCode() ) {
11340                 return false;
11341             }
11342             if ( s1.compareTo( s1 ) != 0 ) {
11343                 return false;
11344             }
11345             if ( s1.compareTo( s2 ) != 0 ) {
11346                 return false;
11347             }
11348             if ( s1.compareTo( s3 ) != 0 ) {
11349                 return false;
11350             }
11351             if ( s1.compareTo( s4 ) >= 0 ) {
11352                 return false;
11353             }
11354             if ( s4.compareTo( s1 ) <= 0 ) {
11355                 return false;
11356             }
11357             if ( !s4.getSpeciesId().equals( "b" ) ) {
11358                 return false;
11359             }
11360             final Species s5 = new BasicSpecies( " C " );
11361             if ( !s5.getSpeciesId().equals( "C" ) ) {
11362                 return false;
11363             }
11364             if ( s5.equals( s1 ) ) {
11365                 return false;
11366             }
11367         }
11368         catch ( final Exception e ) {
11369             e.printStackTrace( System.out );
11370             return false;
11371         }
11372         return true;
11373     }
11374
11375     private static boolean testSplit() {
11376         try {
11377             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11378             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11379             //Archaeopteryx.createApplication( p0 );
11380             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11381             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11382             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11383             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11384             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11385             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11386             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11387             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11388             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11389             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11390             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
11391             // System.out.println( s0.toString() );
11392             //
11393             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11394             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11395             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11396             if ( s0.match( query_nodes ) ) {
11397                 return false;
11398             }
11399             query_nodes = new HashSet<PhylogenyNode>();
11400             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11401             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11402             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11403             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11404             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11405             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11406             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11407             if ( !s0.match( query_nodes ) ) {
11408                 return false;
11409             }
11410             //
11411             query_nodes = new HashSet<PhylogenyNode>();
11412             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11413             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11414             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11415             if ( !s0.match( query_nodes ) ) {
11416                 return false;
11417             }
11418             //
11419             query_nodes = new HashSet<PhylogenyNode>();
11420             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11421             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11422             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11423             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11424             if ( !s0.match( query_nodes ) ) {
11425                 return false;
11426             }
11427             //
11428             query_nodes = new HashSet<PhylogenyNode>();
11429             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11430             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11431             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11432             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11433             if ( !s0.match( query_nodes ) ) {
11434                 return false;
11435             }
11436             //
11437             query_nodes = new HashSet<PhylogenyNode>();
11438             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11439             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11440             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11441             if ( !s0.match( query_nodes ) ) {
11442                 return false;
11443             }
11444             //
11445             query_nodes = new HashSet<PhylogenyNode>();
11446             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11447             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11448             if ( !s0.match( query_nodes ) ) {
11449                 return false;
11450             }
11451             //
11452             query_nodes = new HashSet<PhylogenyNode>();
11453             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11454             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11455             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11456             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11457             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11458             if ( !s0.match( query_nodes ) ) {
11459                 return false;
11460             }
11461             //
11462             query_nodes = new HashSet<PhylogenyNode>();
11463             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11464             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11465             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11466             if ( !s0.match( query_nodes ) ) {
11467                 return false;
11468             }
11469             //
11470             query_nodes = new HashSet<PhylogenyNode>();
11471             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11472             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11473             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11474             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11475             if ( !s0.match( query_nodes ) ) {
11476                 return false;
11477             }
11478             //
11479             query_nodes = new HashSet<PhylogenyNode>();
11480             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11481             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11482             if ( s0.match( query_nodes ) ) {
11483                 return false;
11484             }
11485             //
11486             query_nodes = new HashSet<PhylogenyNode>();
11487             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11488             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11489             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11490             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11491             if ( s0.match( query_nodes ) ) {
11492                 return false;
11493             }
11494             //
11495             query_nodes = new HashSet<PhylogenyNode>();
11496             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11497             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11498             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11499             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11500             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11501             if ( s0.match( query_nodes ) ) {
11502                 return false;
11503             }
11504             //
11505             query_nodes = new HashSet<PhylogenyNode>();
11506             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11507             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11508             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11509             if ( s0.match( query_nodes ) ) {
11510                 return false;
11511             }
11512             //
11513             query_nodes = new HashSet<PhylogenyNode>();
11514             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11515             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11516             if ( s0.match( query_nodes ) ) {
11517                 return false;
11518             }
11519             //
11520             query_nodes = new HashSet<PhylogenyNode>();
11521             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11522             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11523             if ( s0.match( query_nodes ) ) {
11524                 return false;
11525             }
11526             //
11527             query_nodes = new HashSet<PhylogenyNode>();
11528             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11529             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11530             if ( s0.match( query_nodes ) ) {
11531                 return false;
11532             }
11533             //
11534             query_nodes = new HashSet<PhylogenyNode>();
11535             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11536             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11537             if ( s0.match( query_nodes ) ) {
11538                 return false;
11539             }
11540             //
11541             query_nodes = new HashSet<PhylogenyNode>();
11542             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11543             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11544             if ( s0.match( query_nodes ) ) {
11545                 return false;
11546             }
11547             //
11548             query_nodes = new HashSet<PhylogenyNode>();
11549             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11550             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11551             if ( s0.match( query_nodes ) ) {
11552                 return false;
11553             }
11554             //
11555             query_nodes = new HashSet<PhylogenyNode>();
11556             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11557             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11558             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11559             if ( s0.match( query_nodes ) ) {
11560                 return false;
11561             }
11562             //
11563             query_nodes = new HashSet<PhylogenyNode>();
11564             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11565             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11566             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11567             if ( s0.match( query_nodes ) ) {
11568                 return false;
11569             }
11570             //
11571             query_nodes = new HashSet<PhylogenyNode>();
11572             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11573             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11574             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11575             if ( s0.match( query_nodes ) ) {
11576                 return false;
11577             }
11578             //
11579             query_nodes = new HashSet<PhylogenyNode>();
11580             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11581             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11582             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11583             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11584             if ( s0.match( query_nodes ) ) {
11585                 return false;
11586             }
11587             /////////
11588             //            query_nodes = new HashSet<PhylogenyNode>();
11589             //            query_nodes.add( new PhylogenyNode( "X" ) );
11590             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11591             //            query_nodes.add( new PhylogenyNode( "A" ) );
11592             //            query_nodes.add( new PhylogenyNode( "B" ) );
11593             //            query_nodes.add( new PhylogenyNode( "C" ) );
11594             //            query_nodes.add( new PhylogenyNode( "D" ) );
11595             //            query_nodes.add( new PhylogenyNode( "E" ) );
11596             //            query_nodes.add( new PhylogenyNode( "F" ) );
11597             //            query_nodes.add( new PhylogenyNode( "G" ) );
11598             //            if ( !s0.match( query_nodes ) ) {
11599             //                return false;
11600             //            }
11601             //            query_nodes = new HashSet<PhylogenyNode>();
11602             //            query_nodes.add( new PhylogenyNode( "X" ) );
11603             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11604             //            query_nodes.add( new PhylogenyNode( "A" ) );
11605             //            query_nodes.add( new PhylogenyNode( "B" ) );
11606             //            query_nodes.add( new PhylogenyNode( "C" ) );
11607             //            if ( !s0.match( query_nodes ) ) {
11608             //                return false;
11609             //            }
11610             //            //
11611             //            query_nodes = new HashSet<PhylogenyNode>();
11612             //            query_nodes.add( new PhylogenyNode( "X" ) );
11613             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11614             //            query_nodes.add( new PhylogenyNode( "D" ) );
11615             //            query_nodes.add( new PhylogenyNode( "E" ) );
11616             //            query_nodes.add( new PhylogenyNode( "F" ) );
11617             //            query_nodes.add( new PhylogenyNode( "G" ) );
11618             //            if ( !s0.match( query_nodes ) ) {
11619             //                return false;
11620             //            }
11621             //            //
11622             //            query_nodes = new HashSet<PhylogenyNode>();
11623             //            query_nodes.add( new PhylogenyNode( "X" ) );
11624             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11625             //            query_nodes.add( new PhylogenyNode( "A" ) );
11626             //            query_nodes.add( new PhylogenyNode( "B" ) );
11627             //            query_nodes.add( new PhylogenyNode( "C" ) );
11628             //            query_nodes.add( new PhylogenyNode( "D" ) );
11629             //            if ( !s0.match( query_nodes ) ) {
11630             //                return false;
11631             //            }
11632             //            //
11633             //            query_nodes = new HashSet<PhylogenyNode>();
11634             //            query_nodes.add( new PhylogenyNode( "X" ) );
11635             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11636             //            query_nodes.add( new PhylogenyNode( "E" ) );
11637             //            query_nodes.add( new PhylogenyNode( "F" ) );
11638             //            query_nodes.add( new PhylogenyNode( "G" ) );
11639             //            if ( !s0.match( query_nodes ) ) {
11640             //                return false;
11641             //            }
11642             //            //
11643             //            query_nodes = new HashSet<PhylogenyNode>();
11644             //            query_nodes.add( new PhylogenyNode( "X" ) );
11645             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11646             //            query_nodes.add( new PhylogenyNode( "F" ) );
11647             //            query_nodes.add( new PhylogenyNode( "G" ) );
11648             //            if ( !s0.match( query_nodes ) ) {
11649             //                return false;
11650             //            }
11651             //
11652             query_nodes = new HashSet<PhylogenyNode>();
11653             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11654             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11655             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11656             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11657             if ( s0.match( query_nodes ) ) {
11658                 return false;
11659             }
11660             //
11661             query_nodes = new HashSet<PhylogenyNode>();
11662             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11663             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11664             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11665             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11666             if ( s0.match( query_nodes ) ) {
11667                 return false;
11668             }
11669             ///////////////////////////
11670             //
11671             query_nodes = new HashSet<PhylogenyNode>();
11672             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11673             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11674             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11675             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11676             if ( s0.match( query_nodes ) ) {
11677                 return false;
11678             }
11679             //
11680             query_nodes = new HashSet<PhylogenyNode>();
11681             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11682             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11683             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11684             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11685             if ( s0.match( query_nodes ) ) {
11686                 return false;
11687             }
11688             //
11689             query_nodes = new HashSet<PhylogenyNode>();
11690             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11691             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11692             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11693             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11694             if ( s0.match( query_nodes ) ) {
11695                 return false;
11696             }
11697             //
11698             query_nodes = new HashSet<PhylogenyNode>();
11699             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11700             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11701             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11702             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11703             if ( s0.match( query_nodes ) ) {
11704                 return false;
11705             }
11706             //
11707             query_nodes = new HashSet<PhylogenyNode>();
11708             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11709             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11710             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11711             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11712             if ( s0.match( query_nodes ) ) {
11713                 return false;
11714             }
11715             //
11716             query_nodes = new HashSet<PhylogenyNode>();
11717             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11718             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11719             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11720             if ( s0.match( query_nodes ) ) {
11721                 return false;
11722             }
11723             //
11724             query_nodes = new HashSet<PhylogenyNode>();
11725             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11726             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11727             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11728             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11729             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11730             if ( s0.match( query_nodes ) ) {
11731                 return false;
11732             }
11733             //
11734             query_nodes = new HashSet<PhylogenyNode>();
11735             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11736             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11737             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11738             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11739             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11740             if ( s0.match( query_nodes ) ) {
11741                 return false;
11742             }
11743             //
11744             query_nodes = new HashSet<PhylogenyNode>();
11745             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11746             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11747             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11748             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11749             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11750             if ( s0.match( query_nodes ) ) {
11751                 return false;
11752             }
11753             //
11754             query_nodes = new HashSet<PhylogenyNode>();
11755             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11756             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11757             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11758             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11759             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11760             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11761             if ( s0.match( query_nodes ) ) {
11762                 return false;
11763             }
11764         }
11765         catch ( final Exception e ) {
11766             e.printStackTrace();
11767             return false;
11768         }
11769         return true;
11770     }
11771
11772     private static boolean testSplitStrict() {
11773         try {
11774             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11775             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11776             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11777             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11778             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11779             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11780             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11781             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11782             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11783             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11784             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
11785             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11786             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11787             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11788             if ( s0.match( query_nodes ) ) {
11789                 return false;
11790             }
11791             query_nodes = new HashSet<PhylogenyNode>();
11792             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11793             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11794             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11795             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11796             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11797             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11798             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11799             if ( !s0.match( query_nodes ) ) {
11800                 return false;
11801             }
11802             //
11803             query_nodes = new HashSet<PhylogenyNode>();
11804             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11805             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11806             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11807             if ( !s0.match( query_nodes ) ) {
11808                 return false;
11809             }
11810             //
11811             query_nodes = new HashSet<PhylogenyNode>();
11812             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11813             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11814             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11815             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11816             if ( !s0.match( query_nodes ) ) {
11817                 return false;
11818             }
11819             //
11820             query_nodes = new HashSet<PhylogenyNode>();
11821             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11822             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11823             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11824             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11825             if ( !s0.match( query_nodes ) ) {
11826                 return false;
11827             }
11828             //
11829             query_nodes = new HashSet<PhylogenyNode>();
11830             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11831             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11832             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11833             if ( !s0.match( query_nodes ) ) {
11834                 return false;
11835             }
11836             //
11837             query_nodes = new HashSet<PhylogenyNode>();
11838             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11839             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11840             if ( !s0.match( query_nodes ) ) {
11841                 return false;
11842             }
11843             //
11844             query_nodes = new HashSet<PhylogenyNode>();
11845             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11846             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11847             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11848             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11849             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11850             if ( !s0.match( query_nodes ) ) {
11851                 return false;
11852             }
11853             //
11854             query_nodes = new HashSet<PhylogenyNode>();
11855             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11856             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11857             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11858             if ( !s0.match( query_nodes ) ) {
11859                 return false;
11860             }
11861             //
11862             query_nodes = new HashSet<PhylogenyNode>();
11863             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11864             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11865             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11866             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11867             if ( !s0.match( query_nodes ) ) {
11868                 return false;
11869             }
11870             //
11871             query_nodes = new HashSet<PhylogenyNode>();
11872             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11873             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11874             if ( s0.match( query_nodes ) ) {
11875                 return false;
11876             }
11877             //
11878             query_nodes = new HashSet<PhylogenyNode>();
11879             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11880             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11881             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11882             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11883             if ( s0.match( query_nodes ) ) {
11884                 return false;
11885             }
11886             //
11887             query_nodes = new HashSet<PhylogenyNode>();
11888             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11889             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11890             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11891             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11892             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11893             if ( s0.match( query_nodes ) ) {
11894                 return false;
11895             }
11896             //
11897             query_nodes = new HashSet<PhylogenyNode>();
11898             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11899             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11900             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11901             if ( s0.match( query_nodes ) ) {
11902                 return false;
11903             }
11904             //
11905             query_nodes = new HashSet<PhylogenyNode>();
11906             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11907             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11908             if ( s0.match( query_nodes ) ) {
11909                 return false;
11910             }
11911             //
11912             query_nodes = new HashSet<PhylogenyNode>();
11913             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11914             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11915             if ( s0.match( query_nodes ) ) {
11916                 return false;
11917             }
11918             //
11919             query_nodes = new HashSet<PhylogenyNode>();
11920             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11921             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11922             if ( s0.match( query_nodes ) ) {
11923                 return false;
11924             }
11925             //
11926             query_nodes = new HashSet<PhylogenyNode>();
11927             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11928             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11929             if ( s0.match( query_nodes ) ) {
11930                 return false;
11931             }
11932             //
11933             query_nodes = new HashSet<PhylogenyNode>();
11934             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11935             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11936             if ( s0.match( query_nodes ) ) {
11937                 return false;
11938             }
11939             //
11940             query_nodes = new HashSet<PhylogenyNode>();
11941             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11942             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11943             if ( s0.match( query_nodes ) ) {
11944                 return false;
11945             }
11946             //
11947             query_nodes = new HashSet<PhylogenyNode>();
11948             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11949             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11950             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11951             if ( s0.match( query_nodes ) ) {
11952                 return false;
11953             }
11954             //
11955             query_nodes = new HashSet<PhylogenyNode>();
11956             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11957             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11958             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11959             if ( s0.match( query_nodes ) ) {
11960                 return false;
11961             }
11962             //
11963             query_nodes = new HashSet<PhylogenyNode>();
11964             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11965             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11966             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11967             if ( s0.match( query_nodes ) ) {
11968                 return false;
11969             }
11970             //
11971             query_nodes = new HashSet<PhylogenyNode>();
11972             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11973             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11974             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11975             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11976             if ( s0.match( query_nodes ) ) {
11977                 return false;
11978             }
11979         }
11980         catch ( final Exception e ) {
11981             e.printStackTrace();
11982             return false;
11983         }
11984         return true;
11985     }
11986
11987     private static boolean testSubtreeDeletion() {
11988         try {
11989             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11990             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
11991             t1.deleteSubtree( t1.getNode( "A" ), false );
11992             if ( t1.getNumberOfExternalNodes() != 5 ) {
11993                 return false;
11994             }
11995             t1.toNewHampshireX();
11996             t1.deleteSubtree( t1.getNode( "E" ), false );
11997             if ( t1.getNumberOfExternalNodes() != 4 ) {
11998                 return false;
11999             }
12000             t1.toNewHampshireX();
12001             t1.deleteSubtree( t1.getNode( "F" ), false );
12002             if ( t1.getNumberOfExternalNodes() != 3 ) {
12003                 return false;
12004             }
12005             t1.toNewHampshireX();
12006             t1.deleteSubtree( t1.getNode( "D" ), false );
12007             t1.toNewHampshireX();
12008             if ( t1.getNumberOfExternalNodes() != 3 ) {
12009                 return false;
12010             }
12011             t1.deleteSubtree( t1.getNode( "def" ), false );
12012             t1.toNewHampshireX();
12013             if ( t1.getNumberOfExternalNodes() != 2 ) {
12014                 return false;
12015             }
12016             t1.deleteSubtree( t1.getNode( "B" ), false );
12017             t1.toNewHampshireX();
12018             if ( t1.getNumberOfExternalNodes() != 1 ) {
12019                 return false;
12020             }
12021             t1.deleteSubtree( t1.getNode( "C" ), false );
12022             t1.toNewHampshireX();
12023             if ( t1.getNumberOfExternalNodes() != 1 ) {
12024                 return false;
12025             }
12026             t1.deleteSubtree( t1.getNode( "abc" ), false );
12027             t1.toNewHampshireX();
12028             if ( t1.getNumberOfExternalNodes() != 1 ) {
12029                 return false;
12030             }
12031             t1.deleteSubtree( t1.getNode( "r" ), false );
12032             if ( t1.getNumberOfExternalNodes() != 0 ) {
12033                 return false;
12034             }
12035             if ( !t1.isEmpty() ) {
12036                 return false;
12037             }
12038             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12039             t2.deleteSubtree( t2.getNode( "A" ), false );
12040             t2.toNewHampshireX();
12041             if ( t2.getNumberOfExternalNodes() != 5 ) {
12042                 return false;
12043             }
12044             t2.deleteSubtree( t2.getNode( "abc" ), false );
12045             t2.toNewHampshireX();
12046             if ( t2.getNumberOfExternalNodes() != 3 ) {
12047                 return false;
12048             }
12049             t2.deleteSubtree( t2.getNode( "def" ), false );
12050             t2.toNewHampshireX();
12051             if ( t2.getNumberOfExternalNodes() != 1 ) {
12052                 return false;
12053             }
12054         }
12055         catch ( final Exception e ) {
12056             e.printStackTrace( System.out );
12057             return false;
12058         }
12059         return true;
12060     }
12061
12062     private static boolean testSupportCount() {
12063         try {
12064             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12065             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
12066             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
12067                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
12068                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
12069                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
12070                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
12071                                                               new NHXParser() );
12072             SupportCount.count( t0_1, phylogenies_1, true, false );
12073             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
12074             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
12075                                                                       + "(((((A,B),C),D),E),((F,G),X))"
12076                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
12077                                                                       + "(((((A,B),C),D),E),(F,G))"
12078                                                                       + "(((((A,B),C),D),E),(F,G))"
12079                                                                       + "(((((A,B),C),D),E),(F,G))"
12080                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
12081                                                                       + "(((((A,B),C),D),E),(F,G))"
12082                                                                       + "((((((A,B),C),D),E),F),G)"
12083                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
12084                                                               new NHXParser() );
12085             SupportCount.count( t0_2, phylogenies_2, true, false );
12086             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
12087             while ( it.hasNext() ) {
12088                 final PhylogenyNode n = it.next();
12089                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
12090                     return false;
12091                 }
12092             }
12093             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
12094             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
12095                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
12096             SupportCount.count( t0_3, phylogenies_3, true, false );
12097             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
12098             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
12099                 return false;
12100             }
12101             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
12102                 return false;
12103             }
12104             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
12105                 return false;
12106             }
12107             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
12108                 return false;
12109             }
12110             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
12111                 return false;
12112             }
12113             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
12114                 return false;
12115             }
12116             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
12117                 return false;
12118             }
12119             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
12120                 return false;
12121             }
12122             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
12123                 return false;
12124             }
12125             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
12126                 return false;
12127             }
12128             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12129             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
12130                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
12131             SupportCount.count( t0_4, phylogenies_4, true, false );
12132             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
12133             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
12134                 return false;
12135             }
12136             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
12137                 return false;
12138             }
12139             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
12140                 return false;
12141             }
12142             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
12143                 return false;
12144             }
12145             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
12146                 return false;
12147             }
12148             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
12149                 return false;
12150             }
12151             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
12152                 return false;
12153             }
12154             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
12155                 return false;
12156             }
12157             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
12158                 return false;
12159             }
12160             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
12161                 return false;
12162             }
12163             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12164             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12165             double d = SupportCount.compare( b1, a, true, true, true );
12166             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
12167                 return false;
12168             }
12169             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12170             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12171             d = SupportCount.compare( b2, a, true, true, true );
12172             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
12173                 return false;
12174             }
12175             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12176             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
12177             d = SupportCount.compare( b3, a, true, true, true );
12178             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
12179                 return false;
12180             }
12181             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
12182             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
12183             d = SupportCount.compare( b4, a, true, true, false );
12184             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
12185                 return false;
12186             }
12187         }
12188         catch ( final Exception e ) {
12189             e.printStackTrace( System.out );
12190             return false;
12191         }
12192         return true;
12193     }
12194
12195     private static boolean testSupportTransfer() {
12196         try {
12197             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12198             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)",
12199                                                  new NHXParser() )[ 0 ];
12200             final Phylogeny p2 = factory
12201                     .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 ];
12202             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
12203                 return false;
12204             }
12205             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
12206                 return false;
12207             }
12208             support_transfer.moveBranchLengthsToBootstrap( p1 );
12209             support_transfer.transferSupportValues( p1, p2 );
12210             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
12211                 return false;
12212             }
12213             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
12214                 return false;
12215             }
12216             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
12217                 return false;
12218             }
12219             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
12220                 return false;
12221             }
12222             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
12223                 return false;
12224             }
12225             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
12226                 return false;
12227             }
12228             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
12229                 return false;
12230             }
12231             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
12232                 return false;
12233             }
12234         }
12235         catch ( final Exception e ) {
12236             e.printStackTrace( System.out );
12237             return false;
12238         }
12239         return true;
12240     }
12241
12242     private static boolean testTaxonomyExtraction() {
12243         try {
12244             final PhylogenyNode n0 = PhylogenyNode
12245                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12246             if ( n0.getNodeData().isHasTaxonomy() ) {
12247                 return false;
12248             }
12249             final PhylogenyNode n1 = PhylogenyNode
12250                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12251             if ( n1.getNodeData().isHasTaxonomy() ) {
12252                 System.out.println( n1.toString() );
12253                 return false;
12254             }
12255             final PhylogenyNode n2x = PhylogenyNode
12256                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12257             if ( n2x.getNodeData().isHasTaxonomy() ) {
12258                 return false;
12259             }
12260             final PhylogenyNode n3 = PhylogenyNode
12261                     .createInstanceFromNhxString( "BLAG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12262             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12263                 System.out.println( n3.toString() );
12264                 return false;
12265             }
12266             final PhylogenyNode n4 = PhylogenyNode
12267                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12268             if ( n4.getNodeData().isHasTaxonomy() ) {
12269                 System.out.println( n4.toString() );
12270                 return false;
12271             }
12272             final PhylogenyNode n5 = PhylogenyNode
12273                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12274             if ( n5.getNodeData().isHasTaxonomy() ) {
12275                 System.out.println( n5.toString() );
12276                 return false;
12277             }
12278             final PhylogenyNode n6 = PhylogenyNode
12279                     .createInstanceFromNhxString( "BLAG-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12280             if ( n6.getNodeData().isHasTaxonomy() ) {
12281                 System.out.println( n6.toString() );
12282                 return false;
12283             }
12284             final PhylogenyNode n7 = PhylogenyNode
12285                     .createInstanceFromNhxString( "BLAG-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12286             if ( n7.getNodeData().isHasTaxonomy() ) {
12287                 System.out.println( n7.toString() );
12288                 return false;
12289             }
12290             final PhylogenyNode n8 = PhylogenyNode
12291                     .createInstanceFromNhxString( "BLAG_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12292             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12293                 System.out.println( n8.toString() );
12294                 return false;
12295             }
12296             final PhylogenyNode n9 = PhylogenyNode
12297                     .createInstanceFromNhxString( "BLAG_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12298             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12299                 System.out.println( n9.toString() );
12300                 return false;
12301             }
12302             final PhylogenyNode n10x = PhylogenyNode
12303                     .createInstanceFromNhxString( "BLAG_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12304             if ( n10x.getNodeData().isHasTaxonomy() ) {
12305                 System.out.println( n10x.toString() );
12306                 return false;
12307             }
12308             final PhylogenyNode n10xx = PhylogenyNode
12309                     .createInstanceFromNhxString( "BLAG_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12310             if ( n10xx.getNodeData().isHasTaxonomy() ) {
12311                 System.out.println( n10xx.toString() );
12312                 return false;
12313             }
12314             final PhylogenyNode n10 = PhylogenyNode
12315                     .createInstanceFromNhxString( "BLAG_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12316             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
12317                 System.out.println( n10.toString() );
12318                 return false;
12319             }
12320             final PhylogenyNode n11 = PhylogenyNode
12321                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12322             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12323                 System.out.println( n11.toString() );
12324                 return false;
12325             }
12326             final PhylogenyNode n12 = PhylogenyNode
12327                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
12328                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12329             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12330                 System.out.println( n12.toString() );
12331                 return false;
12332             }
12333             final PhylogenyNode n13 = PhylogenyNode
12334                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12335             if ( n13.getNodeData().isHasTaxonomy() ) {
12336                 System.out.println( n13.toString() );
12337                 return false;
12338             }
12339             final PhylogenyNode n14 = PhylogenyNode
12340                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12341             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12342                 System.out.println( n14.toString() );
12343                 return false;
12344             }
12345             final PhylogenyNode n15 = PhylogenyNode
12346                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12347             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12348                 System.out.println( n15.toString() );
12349                 return false;
12350             }
12351             final PhylogenyNode n16 = PhylogenyNode
12352                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12353             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12354                 System.out.println( n16.toString() );
12355                 return false;
12356             }
12357             final PhylogenyNode n17 = PhylogenyNode
12358                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12359             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12360                 System.out.println( n17.toString() );
12361                 return false;
12362             }
12363             //
12364             final PhylogenyNode n18 = PhylogenyNode
12365                     .createInstanceFromNhxString( "Mus_musculus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12366             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12367                 System.out.println( n18.toString() );
12368                 return false;
12369             }
12370             final PhylogenyNode n19 = PhylogenyNode
12371                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
12372                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12373             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12374                 System.out.println( n19.toString() );
12375                 return false;
12376             }
12377             final PhylogenyNode n20 = PhylogenyNode
12378                     .createInstanceFromNhxString( "Mus musculus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12379             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12380                 System.out.println( n20.toString() );
12381                 return false;
12382             }
12383             final PhylogenyNode n21 = PhylogenyNode
12384                     .createInstanceFromNhxString( "Mus musculus musculus K392",
12385                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12386             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12387                 System.out.println( n21.toString() );
12388                 return false;
12389             }
12390             final PhylogenyNode n22 = PhylogenyNode
12391                     .createInstanceFromNhxString( "NEMVE_Nematostella_vectensis",
12392                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12393             if ( !n22.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12394                 System.out.println( n22.toString() );
12395                 return false;
12396             }
12397             final PhylogenyNode n23 = PhylogenyNode
12398                     .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
12399                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12400             if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12401                 System.out.println( n23.toString() );
12402                 return false;
12403             }
12404             final PhylogenyNode n24 = PhylogenyNode
12405                     .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12406             if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12407                 System.out.println( n24.toString() );
12408                 return false;
12409             }
12410             //
12411             final PhylogenyNode n25 = PhylogenyNode
12412                     .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
12413                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12414             if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12415                 System.out.println( n25.toString() );
12416                 return false;
12417             }
12418             final PhylogenyNode n26 = PhylogenyNode
12419                     .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
12420                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12421             if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12422                 System.out.println( n26.toString() );
12423                 return false;
12424             }
12425             final PhylogenyNode n27 = PhylogenyNode
12426                     .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12427             if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12428                 System.out.println( n27.toString() );
12429                 return false;
12430             }
12431         }
12432         catch ( final Exception e ) {
12433             e.printStackTrace( System.out );
12434             return false;
12435         }
12436         return true;
12437     }
12438
12439     private static boolean testTreeCopy() {
12440         try {
12441             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
12442             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
12443             final Phylogeny t1 = t0.copy();
12444             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
12445                 return false;
12446             }
12447             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12448                 return false;
12449             }
12450             t0.deleteSubtree( t0.getNode( "c" ), true );
12451             t0.deleteSubtree( t0.getNode( "a" ), true );
12452             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
12453             t0.getNode( "b" ).setName( "Bee" );
12454             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
12455                 return false;
12456             }
12457             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12458                 return false;
12459             }
12460             t0.deleteSubtree( t0.getNode( "e" ), true );
12461             t0.deleteSubtree( t0.getNode( "Bee" ), true );
12462             t0.deleteSubtree( t0.getNode( "d" ), true );
12463             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12464                 return false;
12465             }
12466         }
12467         catch ( final Exception e ) {
12468             e.printStackTrace();
12469             return false;
12470         }
12471         return true;
12472     }
12473
12474     private static boolean testTreeMethods() {
12475         try {
12476             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12477             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
12478             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
12479             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
12480                 System.out.println( t0.toNewHampshireX() );
12481                 return false;
12482             }
12483             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
12484             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
12485             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
12486                 return false;
12487             }
12488             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
12489                 return false;
12490             }
12491             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
12492                 return false;
12493             }
12494         }
12495         catch ( final Exception e ) {
12496             e.printStackTrace( System.out );
12497             return false;
12498         }
12499         return true;
12500     }
12501
12502     private static boolean testUniprotEntryRetrieval() {
12503         try {
12504             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
12505             if ( !entry.getAccession().equals( "P12345" ) ) {
12506                 return false;
12507             }
12508             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
12509                 return false;
12510             }
12511             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
12512                 return false;
12513             }
12514             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
12515                 return false;
12516             }
12517             if ( !entry.getGeneName().equals( "GOT2" ) ) {
12518                 return false;
12519             }
12520             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
12521                 return false;
12522             }
12523         }
12524         catch ( final IOException e ) {
12525             System.out.println();
12526             System.out.println( "the following might be due to absence internet connection:" );
12527             e.printStackTrace( System.out );
12528             return true;
12529         }
12530         catch ( final Exception e ) {
12531             return false;
12532         }
12533         return true;
12534     }
12535
12536     private static boolean testUniprotTaxonomySearch() {
12537         try {
12538             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
12539                                                                                                  10 );
12540             if ( results.size() != 1 ) {
12541                 return false;
12542             }
12543             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12544                 return false;
12545             }
12546             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12547                 return false;
12548             }
12549             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12550                 return false;
12551             }
12552             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12553                 return false;
12554             }
12555             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12556                 return false;
12557             }
12558             results = null;
12559             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
12560             if ( results.size() != 1 ) {
12561                 return false;
12562             }
12563             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12564                 return false;
12565             }
12566             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12567                 return false;
12568             }
12569             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12570                 return false;
12571             }
12572             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12573                 return false;
12574             }
12575             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12576                 return false;
12577             }
12578             results = null;
12579             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
12580             if ( results.size() != 1 ) {
12581                 return false;
12582             }
12583             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12584                 return false;
12585             }
12586             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12587                 return false;
12588             }
12589             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12590                 return false;
12591             }
12592             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12593                 return false;
12594             }
12595             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12596                 return false;
12597             }
12598             results = null;
12599             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
12600             if ( results.size() != 1 ) {
12601                 return false;
12602             }
12603             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12604                 return false;
12605             }
12606             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12607                 return false;
12608             }
12609             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12610                 return false;
12611             }
12612             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12613                 return false;
12614             }
12615             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12616                 return false;
12617             }
12618             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
12619                 return false;
12620             }
12621             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
12622                 return false;
12623             }
12624             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12625                     .equals( "Nematostella vectensis" ) ) {
12626                 System.out.println( results.get( 0 ).getLineage() );
12627                 return false;
12628             }
12629             //
12630             results = null;
12631             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
12632             if ( results.size() != 1 ) {
12633                 return false;
12634             }
12635             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12636                 return false;
12637             }
12638             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12639                 return false;
12640             }
12641             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12642                 return false;
12643             }
12644             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12645                 return false;
12646             }
12647             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12648                 return false;
12649             }
12650             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12651                     .equals( "Xenopus tropicalis" ) ) {
12652                 System.out.println( results.get( 0 ).getLineage() );
12653                 return false;
12654             }
12655             //
12656             results = null;
12657             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
12658             if ( results.size() != 1 ) {
12659                 return false;
12660             }
12661             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12662                 return false;
12663             }
12664             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12665                 return false;
12666             }
12667             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12668                 return false;
12669             }
12670             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12671                 return false;
12672             }
12673             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12674                 return false;
12675             }
12676             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12677                     .equals( "Xenopus tropicalis" ) ) {
12678                 System.out.println( results.get( 0 ).getLineage() );
12679                 return false;
12680             }
12681             //
12682             results = null;
12683             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
12684             if ( results.size() != 1 ) {
12685                 return false;
12686             }
12687             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12688                 return false;
12689             }
12690             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12691                 return false;
12692             }
12693             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12694                 return false;
12695             }
12696             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12697                 return false;
12698             }
12699             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12700                 return false;
12701             }
12702             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12703                     .equals( "Xenopus tropicalis" ) ) {
12704                 System.out.println( results.get( 0 ).getLineage() );
12705                 return false;
12706             }
12707         }
12708         catch ( final IOException e ) {
12709             System.out.println();
12710             System.out.println( "the following might be due to absence internet connection:" );
12711             e.printStackTrace( System.out );
12712             return true;
12713         }
12714         catch ( final Exception e ) {
12715             return false;
12716         }
12717         return true;
12718     }
12719
12720     private static boolean testWabiTxSearch() {
12721         try {
12722             String result = "";
12723             result = TxSearch.searchSimple( "nematostella" );
12724             result = TxSearch.getTxId( "nematostella" );
12725             if ( !result.equals( "45350" ) ) {
12726                 return false;
12727             }
12728             result = TxSearch.getTxName( "45350" );
12729             if ( !result.equals( "Nematostella" ) ) {
12730                 return false;
12731             }
12732             result = TxSearch.getTxId( "nematostella vectensis" );
12733             if ( !result.equals( "45351" ) ) {
12734                 return false;
12735             }
12736             result = TxSearch.getTxName( "45351" );
12737             if ( !result.equals( "Nematostella vectensis" ) ) {
12738                 return false;
12739             }
12740             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
12741             if ( !result.equals( "536089" ) ) {
12742                 return false;
12743             }
12744             result = TxSearch.getTxName( "536089" );
12745             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
12746                 return false;
12747             }
12748             final List<String> queries = new ArrayList<String>();
12749             queries.add( "Campylobacter coli" );
12750             queries.add( "Escherichia coli" );
12751             queries.add( "Arabidopsis" );
12752             queries.add( "Trichoplax" );
12753             queries.add( "Samanea saman" );
12754             queries.add( "Kluyveromyces marxianus" );
12755             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
12756             queries.add( "Bornavirus parrot/PDD/2008" );
12757             final List<RANKS> ranks = new ArrayList<RANKS>();
12758             ranks.add( RANKS.SUPERKINGDOM );
12759             ranks.add( RANKS.KINGDOM );
12760             ranks.add( RANKS.FAMILY );
12761             ranks.add( RANKS.GENUS );
12762             ranks.add( RANKS.TRIBE );
12763             result = TxSearch.searchLineage( queries, ranks );
12764             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
12765             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
12766         }
12767         catch ( final Exception e ) {
12768             System.out.println();
12769             System.out.println( "the following might be due to absence internet connection:" );
12770             e.printStackTrace( System.out );
12771             return false;
12772         }
12773         return true;
12774     }
12775 }