bcda899767e1bc1b0a34d41a40e59051cd81d9b3
[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 javax.net.ssl.HttpsURLConnection;
44 import javax.net.ssl.SSLContext;
45
46 import org.forester.application.support_transfer;
47 import org.forester.archaeopteryx.AptxUtil;
48 import org.forester.archaeopteryx.TreePanelUtil;
49 import org.forester.archaeopteryx.webservices.WebserviceUtil;
50 import org.forester.development.DevelopmentTools;
51 import org.forester.evoinference.TestPhylogenyReconstruction;
52 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
53 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
54 import org.forester.go.TestGo;
55 import org.forester.io.parsers.FastaParser;
56 import org.forester.io.parsers.GeneralMsaParser;
57 import org.forester.io.parsers.HmmscanPerDomainTableParser;
58 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
59 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
60 import org.forester.io.parsers.nexus.NexusCharactersParser;
61 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
62 import org.forester.io.parsers.nhx.NHXParser;
63 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
64 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
65 import org.forester.io.parsers.tol.TolParser;
66 import org.forester.io.parsers.util.ParserUtils;
67 import org.forester.io.writers.PhylogenyWriter;
68 import org.forester.io.writers.SequenceWriter;
69 import org.forester.msa.BasicMsa;
70 import org.forester.msa.DeleteableMsa;
71 import org.forester.msa.Mafft;
72 import org.forester.msa.Msa;
73 import org.forester.msa.Msa.MSA_FORMAT;
74 import org.forester.msa.MsaInferrer;
75 import org.forester.msa.MsaMethods;
76 import org.forester.pccx.TestPccx;
77 import org.forester.phylogeny.Phylogeny;
78 import org.forester.phylogeny.PhylogenyBranch;
79 import org.forester.phylogeny.PhylogenyMethods;
80 import org.forester.phylogeny.PhylogenyNode;
81 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
82 import org.forester.phylogeny.data.Accession;
83 import org.forester.phylogeny.data.Accession.Source;
84 import org.forester.phylogeny.data.BinaryCharacters;
85 import org.forester.phylogeny.data.BranchWidth;
86 import org.forester.phylogeny.data.Confidence;
87 import org.forester.phylogeny.data.Distribution;
88 import org.forester.phylogeny.data.DomainArchitecture;
89 import org.forester.phylogeny.data.Event;
90 import org.forester.phylogeny.data.Identifier;
91 import org.forester.phylogeny.data.PhylogenyData;
92 import org.forester.phylogeny.data.PhylogenyDataUtil;
93 import org.forester.phylogeny.data.Polygon;
94 import org.forester.phylogeny.data.PropertiesMap;
95 import org.forester.phylogeny.data.Property;
96 import org.forester.phylogeny.data.Property.AppliesTo;
97 import org.forester.phylogeny.data.ProteinDomain;
98 import org.forester.phylogeny.data.Taxonomy;
99 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
100 import org.forester.phylogeny.factories.PhylogenyFactory;
101 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
102 import org.forester.protein.BasicDomain;
103 import org.forester.protein.BasicProtein;
104 import org.forester.protein.Domain;
105 import org.forester.protein.Protein;
106 import org.forester.protein.ProteinId;
107 import org.forester.rio.TestRIO;
108 import org.forester.sdi.SDI;
109 import org.forester.sdi.SDIR;
110 import org.forester.sdi.TestGSDI;
111 import org.forester.sequence.BasicSequence;
112 import org.forester.sequence.MolecularSequence;
113 import org.forester.species.BasicSpecies;
114 import org.forester.species.Species;
115 import org.forester.surfacing.TestSurfacing;
116 import org.forester.tools.ConfidenceAssessor;
117 import org.forester.tools.SupportCount;
118 import org.forester.tools.TreeSplitMatrix;
119 import org.forester.util.AsciiHistogram;
120 import org.forester.util.BasicDescriptiveStatistics;
121 import org.forester.util.BasicTable;
122 import org.forester.util.BasicTableParser;
123 import org.forester.util.DescriptiveStatistics;
124 import org.forester.util.ForesterConstants;
125 import org.forester.util.ForesterUtil;
126 import org.forester.util.GeneralTable;
127 import org.forester.util.SequenceAccessionTools;
128 import org.forester.util.TrustManager;
129 import org.forester.ws.seqdb.SequenceDatabaseEntry;
130 import org.forester.ws.seqdb.SequenceDbWsTools;
131 import org.forester.ws.seqdb.UniProtTaxonomy;
132
133
134 @SuppressWarnings( "unused")
135 public final class Test {
136
137     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
138             + ForesterUtil.getFileSeparator() + "resources"
139             + ForesterUtil.getFileSeparator();
140     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
141             + ForesterUtil.getFileSeparator() + "test_data"
142             + ForesterUtil.getFileSeparator();
143     private final static boolean PERFORM_DB_TESTS          = true;
144     private static final boolean PERFORM_WEB_TREE_ACCESS   = true;
145     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
146             + ForesterConstants.PHYLO_XML_VERSION + "/"
147             + ForesterConstants.PHYLO_XML_XSD;
148     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
149             + ForesterConstants.PHYLO_XML_VERSION + "/"
150             + ForesterConstants.PHYLO_XML_XSD;
151     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
152     private final static double  ZERO_DIFF                 = 1.0E-9;
153
154     private static boolean isEqual( final double a, final double b ) {
155         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
156     }
157
158     public static void main( final String[] args ) {
159         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
160         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
161                             + "]" );
162         Locale.setDefault( Locale.US );
163         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
164         int failed = 0;
165         int succeeded = 0;
166         System.out.print( "[Test if directory with files for testing exists/is readable: " );
167         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
168             System.out.println( "OK.]" );
169         }
170         else {
171             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
172             System.out.println( "Testing aborted." );
173             System.exit( -1 );
174         }
175         System.out.print( "[Test if resources directory exists/is readable: " );
176         if ( testDir( PATH_TO_RESOURCES ) ) {
177             System.out.println( "OK.]" );
178         }
179         else {
180             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
181             System.out.println( "Testing aborted." );
182             System.exit( -1 );
183         }
184         final long start_time = new Date().getTime();
185         
186         
187         
188         System.out.print( "TreeBase acccess: " );
189         if ( Test.testTreeBaseReading() ) {
190             System.out.println( "OK." );
191             succeeded++;
192         }
193         else {
194             System.out.println( "failed." );
195             failed++;
196         }
197         System.exit( -1 );
198         
199         
200         
201         
202         System.out.print( "Basic node methods: " );
203         if ( Test.testBasicNodeMethods() ) {
204             System.out.println( "OK." );
205             succeeded++;
206         }
207         else {
208             System.out.println( "failed." );
209             failed++;
210         }
211         System.out.print( "Protein id: " );
212         if ( !testProteinId() ) {
213             System.out.println( "failed." );
214             failed++;
215         }
216         else {
217             succeeded++;
218         }
219         System.out.println( "OK." );
220         System.out.print( "Species: " );
221         if ( !testSpecies() ) {
222             System.out.println( "failed." );
223             failed++;
224         }
225         else {
226             succeeded++;
227         }
228         System.out.println( "OK." );
229         System.out.print( "Basic domain: " );
230         if ( !testBasicDomain() ) {
231             System.out.println( "failed." );
232             failed++;
233         }
234         else {
235             succeeded++;
236         }
237         System.out.println( "OK." );
238         System.out.print( "Basic protein: " );
239         if ( !testBasicProtein() ) {
240             System.out.println( "failed." );
241             failed++;
242         }
243         else {
244             succeeded++;
245         }
246         System.out.println( "OK." );
247         System.out.print( "Sequence writer: " );
248         if ( testSequenceWriter() ) {
249             System.out.println( "OK." );
250             succeeded++;
251         }
252         else {
253             System.out.println( "failed." );
254             failed++;
255         }
256         System.out.print( "Sequence id parsing: " );
257         if ( testSequenceIdParsing() ) {
258             System.out.println( "OK." );
259             succeeded++;
260         }
261         else {
262             System.out.println( "failed." );
263             failed++;
264         }
265         System.out.print( "UniProtKB id extraction: " );
266         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
267             System.out.println( "OK." );
268             succeeded++;
269         }
270         else {
271             System.out.println( "failed." );
272             failed++;
273         }
274         System.out.print( "Sequence DB tools 1: " );
275         if ( testSequenceDbWsTools1() ) {
276             System.out.println( "OK." );
277             succeeded++;
278         }
279         else {
280             System.out.println( "failed." );
281             failed++;
282         }
283         System.out.print( "Hmmscan output parser: " );
284         if ( testHmmscanOutputParser() ) {
285             System.out.println( "OK." );
286             succeeded++;
287         }
288         else {
289             System.out.println( "failed." );
290             failed++;
291         }
292         System.out.print( "Overlap removal: " );
293         if ( !org.forester.test.Test.testOverlapRemoval() ) {
294             System.out.println( "failed." );
295             failed++;
296         }
297         else {
298             succeeded++;
299         }
300         System.out.println( "OK." );
301         System.out.print( "Engulfing overlap removal: " );
302         if ( !Test.testEngulfingOverlapRemoval() ) {
303             System.out.println( "failed." );
304             failed++;
305         }
306         else {
307             succeeded++;
308         }
309         System.out.println( "OK." );
310         System.out.print( "Taxonomy data extraction: " );
311         if ( Test.testExtractTaxonomyDataFromNodeName() ) {
312             System.out.println( "OK." );
313             succeeded++;
314         }
315         else {
316             System.out.println( "failed." );
317             failed++;
318         }
319         System.out.print( "Taxonomy code extraction: " );
320         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
321             System.out.println( "OK." );
322             succeeded++;
323         }
324         else {
325             System.out.println( "failed." );
326             failed++;
327         }
328         System.out.print( "SN extraction: " );
329         if ( Test.testExtractSNFromNodeName() ) {
330             System.out.println( "OK." );
331             succeeded++;
332         }
333         else {
334             System.out.println( "failed." );
335             failed++;
336         }
337         System.out.print( "Taxonomy extraction (general): " );
338         if ( Test.testTaxonomyExtraction() ) {
339             System.out.println( "OK." );
340             succeeded++;
341         }
342         else {
343             System.out.println( "failed." );
344             failed++;
345         }
346         System.out.print( "Uri for Aptx web sequence accession: " );
347         if ( Test.testCreateUriForSeqWeb() ) {
348             System.out.println( "OK." );
349             succeeded++;
350         }
351         else {
352             System.out.println( "failed." );
353             failed++;
354         }
355         System.out.print( "Basic node construction and parsing of NHX (node level): " );
356         if ( Test.testNHXNodeParsing() ) {
357             System.out.println( "OK." );
358             succeeded++;
359         }
360         else {
361             System.out.println( "failed." );
362             failed++;
363         }
364         System.out.print( "NHX parsing iterating: " );
365         if ( Test.testNHParsingIter() ) {
366             System.out.println( "OK." );
367             succeeded++;
368         }
369         else {
370             System.out.println( "failed." );
371             failed++;
372         }
373         System.out.print( "NH parsing: " );
374         if ( Test.testNHParsing() ) {
375             System.out.println( "OK." );
376             succeeded++;
377         }
378         else {
379             System.out.println( "failed." );
380             failed++;
381         }
382         System.out.print( "Conversion to NHX (node level): " );
383         if ( Test.testNHXconversion() ) {
384             System.out.println( "OK." );
385             succeeded++;
386         }
387         else {
388             System.out.println( "failed." );
389             failed++;
390         }
391         System.out.print( "NHX parsing: " );
392         if ( Test.testNHXParsing() ) {
393             System.out.println( "OK." );
394             succeeded++;
395         }
396         else {
397             System.out.println( "failed." );
398             failed++;
399         }
400         System.out.print( "NHX parsing with quotes: " );
401         if ( Test.testNHXParsingQuotes() ) {
402             System.out.println( "OK." );
403             succeeded++;
404         }
405         else {
406             System.out.println( "failed." );
407             failed++;
408         }
409         System.out.print( "NHX parsing (MrBayes): " );
410         if ( Test.testNHXParsingMB() ) {
411             System.out.println( "OK." );
412             succeeded++;
413         }
414         else {
415             System.out.println( "failed." );
416             failed++;
417         }
418         System.out.print( "Nexus characters parsing: " );
419         if ( Test.testNexusCharactersParsing() ) {
420             System.out.println( "OK." );
421             succeeded++;
422         }
423         else {
424             System.out.println( "failed." );
425             failed++;
426         }
427         System.out.print( "Nexus tree parsing iterating: " );
428         if ( Test.testNexusTreeParsingIterating() ) {
429             System.out.println( "OK." );
430             succeeded++;
431         }
432         else {
433             System.out.println( "failed." );
434             failed++;
435         }
436         System.out.print( "Nexus tree parsing: " );
437         if ( Test.testNexusTreeParsing() ) {
438             System.out.println( "OK." );
439             succeeded++;
440         }
441         else {
442             System.out.println( "failed." );
443             failed++;
444         }
445         System.out.print( "Nexus tree parsing (translating): " );
446         if ( Test.testNexusTreeParsingTranslating() ) {
447             System.out.println( "OK." );
448             succeeded++;
449         }
450         else {
451             System.out.println( "failed." );
452             failed++;
453         }
454         System.out.print( "Nexus matrix parsing: " );
455         if ( Test.testNexusMatrixParsing() ) {
456             System.out.println( "OK." );
457             succeeded++;
458         }
459         else {
460             System.out.println( "failed." );
461             failed++;
462         }
463         System.out.print( "Basic phyloXML parsing: " );
464         if ( Test.testBasicPhyloXMLparsing() ) {
465             System.out.println( "OK." );
466             succeeded++;
467         }
468         else {
469             System.out.println( "failed." );
470             failed++;
471         }
472         System.out.print( "Basic phyloXML parsing (validating against schema): " );
473         if ( testBasicPhyloXMLparsingValidating() ) {
474             System.out.println( "OK." );
475             succeeded++;
476         }
477         else {
478             System.out.println( "failed." );
479             failed++;
480         }
481         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
482         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
483             System.out.println( "OK." );
484             succeeded++;
485         }
486         else {
487             System.out.println( "failed." );
488             failed++;
489         }
490         System.out.print( "phyloXML Distribution Element: " );
491         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
492             System.out.println( "OK." );
493             succeeded++;
494         }
495         else {
496             System.out.println( "failed." );
497             failed++;
498         }
499         System.out.print( "Tol XML parsing: " );
500         if ( Test.testBasicTolXMLparsing() ) {
501             System.out.println( "OK." );
502             succeeded++;
503         }
504         else {
505             System.out.println( "failed." );
506             failed++;
507         }
508         System.out.print( "Copying of node data: " );
509         if ( Test.testCopyOfNodeData() ) {
510             System.out.println( "OK." );
511             succeeded++;
512         }
513         else {
514             System.out.println( "failed." );
515             failed++;
516         }
517         System.out.print( "Tree copy: " );
518         if ( Test.testTreeCopy() ) {
519             System.out.println( "OK." );
520             succeeded++;
521         }
522         else {
523             System.out.println( "failed." );
524             failed++;
525         }
526         System.out.print( "Basic tree methods: " );
527         if ( Test.testBasicTreeMethods() ) {
528             System.out.println( "OK." );
529             succeeded++;
530         }
531         else {
532             System.out.println( "failed." );
533             failed++;
534         }
535         System.out.print( "Tree methods: " );
536         if ( Test.testTreeMethods() ) {
537             System.out.println( "OK." );
538             succeeded++;
539         }
540         else {
541             System.out.println( "failed." );
542             failed++;
543         }
544         System.out.print( "Postorder Iterator: " );
545         if ( Test.testPostOrderIterator() ) {
546             System.out.println( "OK." );
547             succeeded++;
548         }
549         else {
550             System.out.println( "failed." );
551             failed++;
552         }
553         System.out.print( "Preorder Iterator: " );
554         if ( Test.testPreOrderIterator() ) {
555             System.out.println( "OK." );
556             succeeded++;
557         }
558         else {
559             System.out.println( "failed." );
560             failed++;
561         }
562         System.out.print( "Levelorder Iterator: " );
563         if ( Test.testLevelOrderIterator() ) {
564             System.out.println( "OK." );
565             succeeded++;
566         }
567         else {
568             System.out.println( "failed." );
569             failed++;
570         }
571         System.out.print( "Re-id methods: " );
572         if ( Test.testReIdMethods() ) {
573             System.out.println( "OK." );
574             succeeded++;
575         }
576         else {
577             System.out.println( "failed." );
578             failed++;
579         }
580         System.out.print( "Methods on last external nodes: " );
581         if ( Test.testLastExternalNodeMethods() ) {
582             System.out.println( "OK." );
583             succeeded++;
584         }
585         else {
586             System.out.println( "failed." );
587             failed++;
588         }
589         System.out.print( "Methods on external nodes: " );
590         if ( Test.testExternalNodeRelatedMethods() ) {
591             System.out.println( "OK." );
592             succeeded++;
593         }
594         else {
595             System.out.println( "failed." );
596             failed++;
597         }
598         System.out.print( "Deletion of external nodes: " );
599         if ( Test.testDeletionOfExternalNodes() ) {
600             System.out.println( "OK." );
601             succeeded++;
602         }
603         else {
604             System.out.println( "failed." );
605             failed++;
606         }
607         System.out.print( "Subtree deletion: " );
608         if ( Test.testSubtreeDeletion() ) {
609             System.out.println( "OK." );
610             succeeded++;
611         }
612         else {
613             System.out.println( "failed." );
614             failed++;
615         }
616         System.out.print( "Phylogeny branch: " );
617         if ( Test.testPhylogenyBranch() ) {
618             System.out.println( "OK." );
619             succeeded++;
620         }
621         else {
622             System.out.println( "failed." );
623             failed++;
624         }
625         System.out.print( "Rerooting: " );
626         if ( Test.testRerooting() ) {
627             System.out.println( "OK." );
628             succeeded++;
629         }
630         else {
631             System.out.println( "failed." );
632             failed++;
633         }
634         System.out.print( "Mipoint rooting: " );
635         if ( Test.testMidpointrooting() ) {
636             System.out.println( "OK." );
637             succeeded++;
638         }
639         else {
640             System.out.println( "failed." );
641             failed++;
642         }
643         System.out.print( "Node removal: " );
644         if ( Test.testNodeRemoval() ) {
645             System.out.println( "OK." );
646             succeeded++;
647         }
648         else {
649             System.out.println( "failed." );
650             failed++;
651         }
652         System.out.print( "Support count: " );
653         if ( Test.testSupportCount() ) {
654             System.out.println( "OK." );
655             succeeded++;
656         }
657         else {
658             System.out.println( "failed." );
659             failed++;
660         }
661         System.out.print( "Support transfer: " );
662         if ( Test.testSupportTransfer() ) {
663             System.out.println( "OK." );
664             succeeded++;
665         }
666         else {
667             System.out.println( "failed." );
668             failed++;
669         }
670         System.out.print( "Finding of LCA: " );
671         if ( Test.testGetLCA() ) {
672             System.out.println( "OK." );
673             succeeded++;
674         }
675         else {
676             System.out.println( "failed." );
677             failed++;
678         }
679         System.out.print( "Finding of LCA 2: " );
680         if ( Test.testGetLCA2() ) {
681             System.out.println( "OK." );
682             succeeded++;
683         }
684         else {
685             System.out.println( "failed." );
686             failed++;
687         }
688         System.out.print( "Calculation of distance between nodes: " );
689         if ( Test.testGetDistance() ) {
690             System.out.println( "OK." );
691             succeeded++;
692         }
693         else {
694             System.out.println( "failed." );
695             failed++;
696         }
697         System.out.print( "Descriptive statistics: " );
698         if ( Test.testDescriptiveStatistics() ) {
699             System.out.println( "OK." );
700             succeeded++;
701         }
702         else {
703             System.out.println( "failed." );
704             failed++;
705         }
706         System.out.print( "Data objects and methods: " );
707         if ( Test.testDataObjects() ) {
708             System.out.println( "OK." );
709             succeeded++;
710         }
711         else {
712             System.out.println( "failed." );
713             failed++;
714         }
715         System.out.print( "Properties map: " );
716         if ( Test.testPropertiesMap() ) {
717             System.out.println( "OK." );
718             succeeded++;
719         }
720         else {
721             System.out.println( "failed." );
722             failed++;
723         }
724         System.out.print( "SDIse: " );
725         if ( Test.testSDIse() ) {
726             System.out.println( "OK." );
727             succeeded++;
728         }
729         else {
730             System.out.println( "failed." );
731             failed++;
732         }
733         System.out.print( "SDIunrooted: " );
734         if ( Test.testSDIunrooted() ) {
735             System.out.println( "OK." );
736             succeeded++;
737         }
738         else {
739             System.out.println( "failed." );
740             failed++;
741         }
742         System.out.print( "GSDI: " );
743         if ( TestGSDI.test() ) {
744             System.out.println( "OK." );
745             succeeded++;
746         }
747         else {
748             System.out.println( "failed." );
749             failed++;
750         }
751         System.out.print( "RIO: " );
752         if ( TestRIO.test() ) {
753             System.out.println( "OK." );
754             succeeded++;
755         }
756         else {
757             System.out.println( "failed." );
758             failed++;
759         }
760         System.out.print( "Phylogeny reconstruction:" );
761         System.out.println();
762         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
763             System.out.println( "OK." );
764             succeeded++;
765         }
766         else {
767             System.out.println( "failed." );
768             failed++;
769         }
770         System.out.print( "Analysis of domain architectures: " );
771         System.out.println();
772         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
773             System.out.println( "OK." );
774             succeeded++;
775         }
776         else {
777             System.out.println( "failed." );
778             failed++;
779         }
780         System.out.print( "GO: " );
781         System.out.println();
782         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
783             System.out.println( "OK." );
784             succeeded++;
785         }
786         else {
787             System.out.println( "failed." );
788             failed++;
789         }
790         System.out.print( "Modeling tools: " );
791         if ( TestPccx.test() ) {
792             System.out.println( "OK." );
793             succeeded++;
794         }
795         else {
796             System.out.println( "failed." );
797             failed++;
798         }
799         System.out.print( "Split Matrix strict: " );
800         if ( Test.testSplitStrict() ) {
801             System.out.println( "OK." );
802             succeeded++;
803         }
804         else {
805             System.out.println( "failed." );
806             failed++;
807         }
808         System.out.print( "Split Matrix: " );
809         if ( Test.testSplit() ) {
810             System.out.println( "OK." );
811             succeeded++;
812         }
813         else {
814             System.out.println( "failed." );
815             failed++;
816         }
817         System.out.print( "Confidence Assessor: " );
818         if ( Test.testConfidenceAssessor() ) {
819             System.out.println( "OK." );
820             succeeded++;
821         }
822         else {
823             System.out.println( "failed." );
824             failed++;
825         }
826         System.out.print( "Basic table: " );
827         if ( Test.testBasicTable() ) {
828             System.out.println( "OK." );
829             succeeded++;
830         }
831         else {
832             System.out.println( "failed." );
833             failed++;
834         }
835         System.out.print( "General table: " );
836         if ( Test.testGeneralTable() ) {
837             System.out.println( "OK." );
838             succeeded++;
839         }
840         else {
841             System.out.println( "failed." );
842             failed++;
843         }
844         System.out.print( "Amino acid sequence: " );
845         if ( Test.testAminoAcidSequence() ) {
846             System.out.println( "OK." );
847             succeeded++;
848         }
849         else {
850             System.out.println( "failed." );
851             failed++;
852         }
853         System.out.print( "General MSA parser: " );
854         if ( Test.testGeneralMsaParser() ) {
855             System.out.println( "OK." );
856             succeeded++;
857         }
858         else {
859             System.out.println( "failed." );
860             failed++;
861         }
862         System.out.print( "Fasta parser for msa: " );
863         if ( Test.testFastaParser() ) {
864             System.out.println( "OK." );
865             succeeded++;
866         }
867         else {
868             System.out.println( "failed." );
869             failed++;
870         }
871         System.out.print( "Creation of balanced phylogeny: " );
872         if ( Test.testCreateBalancedPhylogeny() ) {
873             System.out.println( "OK." );
874             succeeded++;
875         }
876         else {
877             System.out.println( "failed." );
878             failed++;
879         }
880         System.out.print( "Genbank accessor parsing: " );
881         if ( Test.testGenbankAccessorParsing() ) {
882             System.out.println( "OK." );
883             succeeded++;
884         }
885         else {
886             System.out.println( "failed." );
887             failed++;
888         }
889         String path = "";
890         final String os = ForesterUtil.OS_NAME.toLowerCase();
891         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
892             path = "/usr/local/bin/mafft";
893         }
894         else if ( os.indexOf( "win" ) >= 0 ) {
895             path = "C:\\Program Files\\mafft-win\\mafft.bat";
896         }
897         else {
898             path = "mafft";
899             if ( !MsaInferrer.isInstalled( path ) ) {
900                 path = "/usr/bin/mafft";
901             }
902             if ( !MsaInferrer.isInstalled( path ) ) {
903                 path = "/usr/local/bin/mafft";
904             }
905         }
906         if ( MsaInferrer.isInstalled( path ) ) {
907             System.out.print( "MAFFT (external program): " );
908             if ( Test.testMafft( path ) ) {
909                 System.out.println( "OK." );
910                 succeeded++;
911             }
912             else {
913                 System.out.println( "failed [will not count towards failed tests]" );
914             }
915         }
916         System.out.print( "Next nodes with collapsed: " );
917         if ( Test.testNextNodeWithCollapsing() ) {
918             System.out.println( "OK." );
919             succeeded++;
920         }
921         else {
922             System.out.println( "failed." );
923             failed++;
924         }
925         System.out.print( "Simple MSA quality: " );
926         if ( Test.testMsaQualityMethod() ) {
927             System.out.println( "OK." );
928             succeeded++;
929         }
930         else {
931             System.out.println( "failed." );
932             failed++;
933         }
934         System.out.print( "Deleteable MSA: " );
935         if ( Test.testDeleteableMsa() ) {
936             System.out.println( "OK." );
937             succeeded++;
938         }
939         else {
940             System.out.println( "failed." );
941             failed++;
942         }
943         System.out.print( "MSA entropy: " );
944         if ( Test.testMsaEntropy() ) {
945             System.out.println( "OK." );
946             succeeded++;
947         }
948         else {
949             System.out.println( "failed." );
950             failed++;
951         }
952         if ( PERFORM_DB_TESTS ) {
953             System.out.print( "Uniprot Entry Retrieval: " );
954             if ( Test.testUniprotEntryRetrieval() ) {
955                 System.out.println( "OK." );
956                 succeeded++;
957             }
958             else {
959                 System.out.println( "failed." );
960                 failed++;
961             }
962             System.out.print( "Ebi Entry Retrieval: " );
963             if ( Test.testEbiEntryRetrieval() ) {
964                 System.out.println( "OK." );
965                 succeeded++;
966             }
967             else {
968                 System.out.println( "failed." );
969                 failed++;
970             }
971             System.out.print( "Sequence DB tools 2: " );
972             if ( testSequenceDbWsTools2() ) {
973                 System.out.println( "OK." );
974                 succeeded++;
975             }
976             else {
977                 System.out.println( "failed." );
978                 failed++;
979                 System.exit( -1 );
980             }
981             System.out.print( "Uniprot Taxonomy Search: " );
982             if ( Test.testUniprotTaxonomySearch() ) {
983                 System.out.println( "OK." );
984                 succeeded++;
985             }
986             else {
987                 System.out.println( "failed." );
988                 failed++;
989             }
990         }
991         if ( PERFORM_WEB_TREE_ACCESS ) {
992             System.out.print( "NHX parsing from URL: " );
993             if ( Test.testNHXparsingFromURL() ) {
994                 System.out.println( "OK." );
995                 succeeded++;
996             }
997             else {
998                 System.out.println( "failed." );
999                 failed++;
1000             }
1001             System.out.print( "NHX parsing from URL 2: " );
1002             if ( Test.testNHXparsingFromURL2() ) {
1003                 System.out.println( "OK." );
1004                 succeeded++;
1005             }
1006             else {
1007                 System.out.println( "failed." );
1008                 failed++;
1009             }
1010             System.out.print( "phyloXML parsing from URL: " );
1011             if ( Test.testPhyloXMLparsingFromURL() ) {
1012                 System.out.println( "OK." );
1013                 succeeded++;
1014             }
1015             else {
1016                 System.out.println( "failed." );
1017                 failed++;
1018             }
1019             System.out.print( "TreeBase acccess: " );
1020             if ( Test.testTreeBaseReading() ) {
1021                 System.out.println( "OK." );
1022                 succeeded++;
1023             }
1024             else {
1025                 System.out.println( "failed." );
1026                 failed++;
1027             }
1028             System.out.print( "ToL access: " );
1029             if ( Test.testToLReading() ) {
1030                 System.out.println( "OK." );
1031                 succeeded++;
1032             }
1033             else {
1034                 System.out.println( "failed." );
1035                 failed++;
1036             }
1037             //
1038             System.out.print( "TreeFam access: " );
1039             if ( Test.testTreeFamReading() ) {
1040                 System.out.println( "OK." );
1041                 succeeded++;
1042             }
1043             else {
1044                 System.out.println( "failed." );
1045                 failed++;
1046             }
1047             //
1048             //
1049             System.out.print( "Pfam tree access: " );
1050             if ( Test.testPfamTreeReading() ) {
1051                 System.out.println( "OK." );
1052                 succeeded++;
1053             }
1054             else {
1055                 System.out.println( "failed." );
1056                 failed++;
1057             }
1058         }
1059         System.out.println();
1060         final Runtime rt = java.lang.Runtime.getRuntime();
1061         final long free_memory = rt.freeMemory() / 1000000;
1062         final long total_memory = rt.totalMemory() / 1000000;
1063         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1064                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1065         System.out.println();
1066         System.out.println( "Successful tests: " + succeeded );
1067         System.out.println( "Failed     tests: " + failed );
1068         System.out.println();
1069         if ( failed < 1 ) {
1070             System.out.println( "OK." );
1071         }
1072         else {
1073             System.out.println( "Not OK." );
1074         }
1075     }
1076
1077     private static boolean testEngulfingOverlapRemoval() {
1078         try {
1079             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1080             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1081             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1082             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1083             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1084             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1085             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1086             final List<Boolean> covered = new ArrayList<Boolean>();
1087             covered.add( true ); // 0
1088             covered.add( false ); // 1
1089             covered.add( true ); // 2
1090             covered.add( false ); // 3
1091             covered.add( true ); // 4
1092             covered.add( true ); // 5
1093             covered.add( false ); // 6
1094             covered.add( true ); // 7
1095             covered.add( true ); // 8
1096             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1097                 return false;
1098             }
1099             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1100                 return false;
1101             }
1102             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1103                 return false;
1104             }
1105             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1106                 return false;
1107             }
1108             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1109                 return false;
1110             }
1111             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1112                 return false;
1113             }
1114             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1115                 return false;
1116             }
1117             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1118             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1119             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1120             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1121             abc.addProteinDomain( a );
1122             abc.addProteinDomain( b );
1123             abc.addProteinDomain( c );
1124             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1125             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1126             if ( abc.getNumberOfProteinDomains() != 3 ) {
1127                 return false;
1128             }
1129             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1130                 return false;
1131             }
1132             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1133                 return false;
1134             }
1135             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1136                 return false;
1137             }
1138             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1139                 return false;
1140             }
1141             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1142             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1143             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1144             final Protein def = new BasicProtein( "def", "nemve", 0 );
1145             def.addProteinDomain( d );
1146             def.addProteinDomain( e );
1147             def.addProteinDomain( f );
1148             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1149             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1150             if ( def.getNumberOfProteinDomains() != 3 ) {
1151                 return false;
1152             }
1153             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1154                 return false;
1155             }
1156             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1157                 return false;
1158             }
1159             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1160                 return false;
1161             }
1162             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1163                 return false;
1164             }
1165             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1166                 return false;
1167             }
1168         }
1169         catch ( final Exception e ) {
1170             e.printStackTrace( System.out );
1171             return false;
1172         }
1173         return true;
1174     }
1175
1176     private static final boolean testNHXparsingFromURL2() {
1177         try {
1178             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1179             final Phylogeny phys[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1180                                                                       false,
1181                                                                       false,
1182                                                                       false,
1183                                                                       TAXONOMY_EXTRACTION.NO,
1184                                                                       false );
1185             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1186                 return false;
1187             }
1188             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1189                 System.out.println( phys[ 0 ].toNewHampshire() );
1190                 return false;
1191             }
1192             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1193                 System.out.println( phys[ 1 ].toNewHampshire() );
1194                 return false;
1195             }
1196             final Phylogeny phys2[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1197                                                                        false,
1198                                                                        false,
1199                                                                        false,
1200                                                                        TAXONOMY_EXTRACTION.NO,
1201                                                                        false );
1202             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1203                 return false;
1204             }
1205             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1206                 System.out.println( phys2[ 0 ].toNewHampshire() );
1207                 return false;
1208             }
1209             if ( !phys2[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1210                 System.out.println( phys2[ 1 ].toNewHampshire() );
1211                 return false;
1212             }
1213             final Phylogeny phys3[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1214                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1215             if ( ( phys3 == null ) || ( phys3.length != 1 ) ) {
1216                 return false;
1217             }
1218             if ( !phys3[ 0 ]
1219                     .toNewHampshire()
1220                     .equals( "((((POP23a_CIOIN_ENSCING00000016202,POP23b_CIOIN_ENSCING00000016169),POP23_CIOSA_ENSCSAVG00000000248),((POP23a_BRAFL_C3ZMF1,POP23b_BRAFL_121417),(((POP3_ORYLA_ENSORLG00000019669,POP3_GASAC_ENSGACG00000014023,POP3_DANRE_Q6JWW1),(POP3_XENTR_B1H1F6,(POP3_CHICK_Q9DG25,(POP3_ORNAN_ENSOANG00000004179,POP3_MONDO_ENSMODG00000018033,((POP3_MOUSE_Q9ES81,POP3_RAT_Q3BCU3),POP3_RABIT_ENSOCUG00000025973,POP3_MACMU_ENSMMUG00000014473,POP3_HUMAN_Q9HBV1))))),(((POP2_GASAC_ENSGACG00000001420,POP2_ORYLA_ENSORLG00000008627,POP2_TAKRU_ENSTRUG00000015933),POP2_DANRE_ENSDARG00000069922),POP2_XENTR_ENSXETG00000018064,(((POP2_TAEGU_ENSTGUG00000013383,POP2_CHICK_Q6T9Z5),POP2_ANOCA_ENSACAG00000003557),((POP2_MACEU_ENSMEUG00000015825,POP2_MONDO_ENSMODG00000018205),((POP2_RABIT_ENSOCUG00000009515,(POP2_RAT_Q6P722,POP2_MOUSE_Q9ES82)),(POP2_MACMU_ENSMMUG00000000905,POP2_HUMAN_Q9HBU9)))))))),((POP1_CIOSA_ENSCSAVG00000000247,POP1_CIOIN_ENSCING00000000496),((POP1_DANRE_Q5PQZ7,(POP1_ORYLA_ENSORLG00000019663,POP1_GASAC_ENSGACG00000014015,POP1_TAKRU_ENSORLG00000019663)),(POP1_XENTR_B1H1G2,(POP1_ANOCA_ENSACAG00000003910,(POP1_TAEGU_ENSTGUG00000012218,POP1_CHICK_Q9DG23)),POP1_ORNAN_ENSOANG00000004180,POP1_MONDO_ENSMODG00000018034,(POP1_RABIT_ENSOCUG00000016944,(POP1_RAT_Q3BCU4,POP1_MOUSE_Q9ES83),(POP1_HUMAN_Q8NE79,POP1_MACMU_ENSMMUG00000014471))))));" ) ) {
1221                 System.out.println( phys3[ 0 ].toNewHampshire() );
1222                 return false;
1223             }
1224             final Phylogeny phys4[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1225                     + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1226             if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1227                 return false;
1228             }
1229             if ( !phys4[ 0 ]
1230                     .toNewHampshire()
1231                     .equals( "((((POP23a_CIOIN_ENSCING00000016202,POP23b_CIOIN_ENSCING00000016169),POP23_CIOSA_ENSCSAVG00000000248),((POP23a_BRAFL_C3ZMF1,POP23b_BRAFL_121417),(((POP3_ORYLA_ENSORLG00000019669,POP3_GASAC_ENSGACG00000014023,POP3_DANRE_Q6JWW1),(POP3_XENTR_B1H1F6,(POP3_CHICK_Q9DG25,(POP3_ORNAN_ENSOANG00000004179,POP3_MONDO_ENSMODG00000018033,((POP3_MOUSE_Q9ES81,POP3_RAT_Q3BCU3),POP3_RABIT_ENSOCUG00000025973,POP3_MACMU_ENSMMUG00000014473,POP3_HUMAN_Q9HBV1))))),(((POP2_GASAC_ENSGACG00000001420,POP2_ORYLA_ENSORLG00000008627,POP2_TAKRU_ENSTRUG00000015933),POP2_DANRE_ENSDARG00000069922),POP2_XENTR_ENSXETG00000018064,(((POP2_TAEGU_ENSTGUG00000013383,POP2_CHICK_Q6T9Z5),POP2_ANOCA_ENSACAG00000003557),((POP2_MACEU_ENSMEUG00000015825,POP2_MONDO_ENSMODG00000018205),((POP2_RABIT_ENSOCUG00000009515,(POP2_RAT_Q6P722,POP2_MOUSE_Q9ES82)),(POP2_MACMU_ENSMMUG00000000905,POP2_HUMAN_Q9HBU9)))))))),((POP1_CIOSA_ENSCSAVG00000000247,POP1_CIOIN_ENSCING00000000496),((POP1_DANRE_Q5PQZ7,(POP1_ORYLA_ENSORLG00000019663,POP1_GASAC_ENSGACG00000014015,POP1_TAKRU_ENSORLG00000019663)),(POP1_XENTR_B1H1G2,(POP1_ANOCA_ENSACAG00000003910,(POP1_TAEGU_ENSTGUG00000012218,POP1_CHICK_Q9DG23)),POP1_ORNAN_ENSOANG00000004180,POP1_MONDO_ENSMODG00000018034,(POP1_RABIT_ENSOCUG00000016944,(POP1_RAT_Q3BCU4,POP1_MOUSE_Q9ES83),(POP1_HUMAN_Q8NE79,POP1_MACMU_ENSMMUG00000014471))))));" ) ) {
1232                 System.out.println( phys4[ 0 ].toNewHampshire() );
1233                 return false;
1234             }
1235         }
1236         catch ( final Exception e ) {
1237             e.printStackTrace();
1238             return false;
1239         }
1240         return true;
1241     }
1242
1243     private static final boolean testNHXparsingFromURL() {
1244         try {
1245             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1246             final URL u = new URL( s );
1247             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1248             final Phylogeny[] phys = factory.create( u, new NHXParser() );
1249             if ( ( phys == null ) || ( phys.length != 5 ) ) {
1250                 return false;
1251             }
1252             if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1253                 System.out.println( phys[ 0 ].toNewHampshire() );
1254                 return false;
1255             }
1256             if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1257                 System.out.println( phys[ 1 ].toNewHampshire() );
1258                 return false;
1259             }
1260             final URL u2 = new URL( s );
1261             final Phylogeny[] phys2 = factory.create( u2.openStream(), new NHXParser() );
1262             if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1263                 return false;
1264             }
1265             if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1266                 System.out.println( phys2[ 0 ].toNewHampshire() );
1267                 return false;
1268             }
1269             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1270             final NHXParser p = new NHXParser();
1271             final URL u3 = new URL( s );
1272             p.setSource( u3 );
1273             if ( !p.hasNext() ) {
1274                 return false;
1275             }
1276             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1277                 return false;
1278             }
1279             if ( !p.hasNext() ) {
1280                 return false;
1281             }
1282             p.reset();
1283             if ( !p.hasNext() ) {
1284                 return false;
1285             }
1286             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1287                 return false;
1288             }
1289             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1290                 return false;
1291             }
1292             p.reset();
1293             if ( !p.hasNext() ) {
1294                 return false;
1295             }
1296             if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1297                 return false;
1298             }
1299             if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1300                 return false;
1301             }
1302         }
1303         catch ( final Exception e ) {
1304             System.out.println( e.toString() );
1305             e.printStackTrace();
1306             return false;
1307         }
1308         return true;
1309     }
1310
1311     private static boolean testOverlapRemoval() {
1312         try {
1313             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1314             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1315             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1316             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1317             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1318             final List<Boolean> covered = new ArrayList<Boolean>();
1319             covered.add( true ); // 0
1320             covered.add( false ); // 1
1321             covered.add( true ); // 2
1322             covered.add( false ); // 3
1323             covered.add( true ); // 4
1324             covered.add( true ); // 5
1325             covered.add( false ); // 6
1326             covered.add( true ); // 7
1327             covered.add( true ); // 8
1328             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1329                 return false;
1330             }
1331             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1332                 return false;
1333             }
1334             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1335                 return false;
1336             }
1337             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1338                 return false;
1339             }
1340             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1341                 return false;
1342             }
1343             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1344             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1345             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1346             ab.addProteinDomain( a );
1347             ab.addProteinDomain( b );
1348             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1349             if ( ab.getNumberOfProteinDomains() != 2 ) {
1350                 return false;
1351             }
1352             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1353                 return false;
1354             }
1355             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1356                 return false;
1357             }
1358             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1359             if ( ab.getNumberOfProteinDomains() != 2 ) {
1360                 return false;
1361             }
1362             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1363                 return false;
1364             }
1365             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1366             final Domain d = new BasicDomain( "d",
1367                                               ( short ) 10000,
1368                                               ( short ) 10500,
1369                                               ( short ) 1,
1370                                               ( short ) 1,
1371                                               0.0000001,
1372                                               1 );
1373             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1374             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1375             cde.addProteinDomain( c );
1376             cde.addProteinDomain( d );
1377             cde.addProteinDomain( e );
1378             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1379             if ( cde.getNumberOfProteinDomains() != 3 ) {
1380                 return false;
1381             }
1382             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1383                 return false;
1384             }
1385             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1386             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1387             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1388             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1389             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1390             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1391             fghi.addProteinDomain( f );
1392             fghi.addProteinDomain( g );
1393             fghi.addProteinDomain( h );
1394             fghi.addProteinDomain( i );
1395             fghi.addProteinDomain( i );
1396             fghi.addProteinDomain( i );
1397             fghi.addProteinDomain( i2 );
1398             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1399             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1400                 return false;
1401             }
1402             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1403                 return false;
1404             }
1405             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1406                 return false;
1407             }
1408             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1409             if ( fghi.getNumberOfProteinDomains() != 7 ) {
1410                 return false;
1411             }
1412             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1413                 return false;
1414             }
1415             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1416             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1417             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1418             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1419             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1420             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1421             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1422             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1423             jklm.addProteinDomain( j );
1424             jklm.addProteinDomain( k );
1425             jklm.addProteinDomain( l );
1426             jklm.addProteinDomain( m );
1427             jklm.addProteinDomain( m0 );
1428             jklm.addProteinDomain( m1 );
1429             jklm.addProteinDomain( m2 );
1430             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1431             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1432                 return false;
1433             }
1434             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1435                 return false;
1436             }
1437             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1438                 return false;
1439             }
1440             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1441             if ( jklm.getNumberOfProteinDomains() != 7 ) {
1442                 return false;
1443             }
1444             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1445                 return false;
1446             }
1447             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1448             final Protein od = new BasicProtein( "od", "varanus", 0 );
1449             od.addProteinDomain( only );
1450             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1451             if ( od.getNumberOfProteinDomains() != 1 ) {
1452                 return false;
1453             }
1454             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1455                 return false;
1456             }
1457         }
1458         catch ( final Exception e ) {
1459             e.printStackTrace( System.out );
1460             return false;
1461         }
1462         return true;
1463     }
1464
1465     private static final boolean testPfamTreeReading() {
1466         try {
1467             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1468             final NHXParser parser = new NHXParser();
1469             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1470             parser.setReplaceUnderscores( false );
1471             parser.setGuessRootedness( true );
1472             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1473             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1474             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1475                 return false;
1476             }
1477             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1478                 return false;
1479             }
1480         }
1481         catch ( final Exception e ) {
1482             e.printStackTrace();
1483         }
1484         return true;
1485     }
1486
1487     private static final boolean testPhyloXMLparsingFromURL() {
1488         try {
1489             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1490             final URL u = new URL( s );
1491             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1492             final Phylogeny[] phys = factory.create( u.openStream(), PhyloXmlParser.createPhyloXmlParser() );
1493             if ( ( phys == null ) || ( phys.length != 2 ) ) {
1494                 return false;
1495             }
1496         }
1497         catch ( final Exception e ) {
1498             e.printStackTrace();
1499         }
1500         return true;
1501     }
1502
1503     private static final boolean testToLReading() {
1504         try {
1505             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1506             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1507             final Phylogeny[] phys = factory.create( u.openStream(), new TolParser() );
1508             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1509                 return false;
1510             }
1511             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1512                 return false;
1513             }
1514             if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Protacanthopterygii" ) ) {
1515                 return false;
1516             }
1517             if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1518                 return false;
1519             }
1520         }
1521         catch ( final Exception e ) {
1522             e.printStackTrace();
1523         }
1524         return true;
1525     }
1526
1527     private static final boolean testTreeBaseReading() {
1528         try {
1529             final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "72557?format=nexus" );
1530             System.out.println( u.toString() );
1531                
1532             final HttpsURLConnection con = TrustManager.makeHttpsURLConnection( u );
1533           
1534             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1535             parser.setReplaceUnderscores( true );
1536             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1537             
1538             
1539             final Phylogeny[] phys = factory.create( con.getInputStream(), parser );
1540             if ( ( phys == null ) || ( phys.length < 1 ) ) {
1541                 return false;
1542             }
1543             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1544             final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1545             parser2.setReplaceUnderscores( true );
1546             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1547             final Phylogeny[] phys2 = factory2.create( u2.openStream(), parser2 );
1548             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1549                 //return false;
1550             }
1551         }
1552         catch ( final Exception e ) {
1553             e.printStackTrace();
1554         }
1555         return true;
1556     }
1557
1558     private static final boolean testTreeFamReading() {
1559         try {
1560             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1561             final NHXParser parser = new NHXParser();
1562             parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1563             parser.setReplaceUnderscores( false );
1564             parser.setGuessRootedness( true );
1565             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1566             final Phylogeny[] phys = factory.create( u.openStream(), parser );
1567             if ( ( phys == null ) || ( phys.length != 1 ) ) {
1568                 return false;
1569             }
1570             if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1571                 return false;
1572             }
1573         }
1574         catch ( final Exception e ) {
1575             e.printStackTrace();
1576         }
1577         return true;
1578     }
1579
1580     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1581         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1582         return p;
1583     }
1584
1585     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1586         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1587     }
1588
1589     private static boolean testAminoAcidSequence() {
1590         try {
1591             final MolecularSequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1592             if ( aa1.getLength() != 13 ) {
1593                 return false;
1594             }
1595             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1596                 return false;
1597             }
1598             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1599                 return false;
1600             }
1601             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1602                 return false;
1603             }
1604             final MolecularSequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1605             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZOXU" ) ) {
1606                 return false;
1607             }
1608             final MolecularSequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1609             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1610                 return false;
1611             }
1612             final MolecularSequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1613             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1614                 return false;
1615             }
1616         }
1617         catch ( final Exception e ) {
1618             e.printStackTrace();
1619             return false;
1620         }
1621         return true;
1622     }
1623
1624     private static boolean testBasicDomain() {
1625         try {
1626             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1627             if ( !pd.getDomainId().equals( "id" ) ) {
1628                 return false;
1629             }
1630             if ( pd.getNumber() != 1 ) {
1631                 return false;
1632             }
1633             if ( pd.getTotalCount() != 4 ) {
1634                 return false;
1635             }
1636             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1637                 return false;
1638             }
1639             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1640             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1641             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1642             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1643             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1644             if ( !a1.equals( a1 ) ) {
1645                 return false;
1646             }
1647             if ( !a1.equals( a1_copy ) ) {
1648                 return false;
1649             }
1650             if ( !a1.equals( a1_equal ) ) {
1651                 return false;
1652             }
1653             if ( !a1.equals( a2 ) ) {
1654                 return false;
1655             }
1656             if ( a1.equals( a3 ) ) {
1657                 return false;
1658             }
1659             if ( a1.compareTo( a1 ) != 0 ) {
1660                 return false;
1661             }
1662             if ( a1.compareTo( a1_copy ) != 0 ) {
1663                 return false;
1664             }
1665             if ( a1.compareTo( a1_equal ) != 0 ) {
1666                 return false;
1667             }
1668             if ( a1.compareTo( a2 ) != 0 ) {
1669                 return false;
1670             }
1671             if ( a1.compareTo( a3 ) == 0 ) {
1672                 return false;
1673             }
1674         }
1675         catch ( final Exception e ) {
1676             e.printStackTrace( System.out );
1677             return false;
1678         }
1679         return true;
1680     }
1681
1682     private static boolean testBasicNodeMethods() {
1683         try {
1684             if ( PhylogenyNode.getNodeCount() != 0 ) {
1685                 return false;
1686             }
1687             final PhylogenyNode n1 = new PhylogenyNode();
1688             final PhylogenyNode n2 = PhylogenyNode
1689                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1690             final PhylogenyNode n3 = PhylogenyNode
1691                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1692             final PhylogenyNode n4 = PhylogenyNode
1693                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1694             if ( n1.isHasAssignedEvent() ) {
1695                 return false;
1696             }
1697             if ( PhylogenyNode.getNodeCount() != 4 ) {
1698                 return false;
1699             }
1700             if ( n3.getIndicator() != 0 ) {
1701                 return false;
1702             }
1703             if ( n3.getNumberOfExternalNodes() != 1 ) {
1704                 return false;
1705             }
1706             if ( !n3.isExternal() ) {
1707                 return false;
1708             }
1709             if ( !n3.isRoot() ) {
1710                 return false;
1711             }
1712             if ( !n4.getName().equals( "n4" ) ) {
1713                 return false;
1714             }
1715         }
1716         catch ( final Exception e ) {
1717             e.printStackTrace( System.out );
1718             return false;
1719         }
1720         return true;
1721     }
1722
1723     private static boolean testBasicPhyloXMLparsing() {
1724         try {
1725             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1726             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1727             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1728                                                               xml_parser );
1729             if ( xml_parser.getErrorCount() > 0 ) {
1730                 System.out.println( xml_parser.getErrorMessages().toString() );
1731                 return false;
1732             }
1733             if ( phylogenies_0.length != 4 ) {
1734                 return false;
1735             }
1736             final Phylogeny t1 = phylogenies_0[ 0 ];
1737             final Phylogeny t2 = phylogenies_0[ 1 ];
1738             final Phylogeny t3 = phylogenies_0[ 2 ];
1739             final Phylogeny t4 = phylogenies_0[ 3 ];
1740             if ( t1.getNumberOfExternalNodes() != 1 ) {
1741                 return false;
1742             }
1743             if ( !t1.isRooted() ) {
1744                 return false;
1745             }
1746             if ( t1.isRerootable() ) {
1747                 return false;
1748             }
1749             if ( !t1.getType().equals( "gene_tree" ) ) {
1750                 return false;
1751             }
1752             if ( t2.getNumberOfExternalNodes() != 2 ) {
1753                 return false;
1754             }
1755             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1756                 return false;
1757             }
1758             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1759                 return false;
1760             }
1761             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1762                 return false;
1763             }
1764             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1765                 return false;
1766             }
1767             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1768                 return false;
1769             }
1770             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1771                 return false;
1772             }
1773             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1774                     .startsWith( "actgtgggggt" ) ) {
1775                 return false;
1776             }
1777             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1778                     .startsWith( "ctgtgatgcat" ) ) {
1779                 return false;
1780             }
1781             if ( t3.getNumberOfExternalNodes() != 4 ) {
1782                 return false;
1783             }
1784             if ( !t1.getName().equals( "t1" ) ) {
1785                 return false;
1786             }
1787             if ( !t2.getName().equals( "t2" ) ) {
1788                 return false;
1789             }
1790             if ( !t3.getName().equals( "t3" ) ) {
1791                 return false;
1792             }
1793             if ( !t4.getName().equals( "t4" ) ) {
1794                 return false;
1795             }
1796             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1797                 return false;
1798             }
1799             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1800                 return false;
1801             }
1802             if ( !t3.getNode( "root node" ).isDuplication() ) {
1803                 return false;
1804             }
1805             if ( !t3.getNode( "node a" ).isDuplication() ) {
1806                 return false;
1807             }
1808             if ( t3.getNode( "node a" ).isSpeciation() ) {
1809                 return false;
1810             }
1811             if ( t3.getNode( "node bc" ).isDuplication() ) {
1812                 return false;
1813             }
1814             if ( !t3.getNode( "node bc" ).isSpeciation() ) {
1815                 return false;
1816             }
1817             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1818                 return false;
1819             }
1820             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1821                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1822                 return false;
1823             }
1824             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1825                 return false;
1826             }
1827             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1828                 return false;
1829             }
1830             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1831                 return false;
1832             }
1833             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1834                     .equals( "apoptosis" ) ) {
1835                 return false;
1836             }
1837             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1838                     .equals( "GO:0006915" ) ) {
1839                 return false;
1840             }
1841             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1842                     .equals( "UniProtKB" ) ) {
1843                 return false;
1844             }
1845             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1846                     .equals( "experimental" ) ) {
1847                 return false;
1848             }
1849             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1850                     .equals( "function" ) ) {
1851                 return false;
1852             }
1853             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1854                     .getValue() != 1 ) {
1855                 return false;
1856             }
1857             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1858                     .getType().equals( "ml" ) ) {
1859                 return false;
1860             }
1861             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1862                     .equals( "apoptosis" ) ) {
1863                 return false;
1864             }
1865             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1866                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1867                 return false;
1868             }
1869             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1870                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1871                 return false;
1872             }
1873             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1874                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1875                 return false;
1876             }
1877             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1878                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1879                 return false;
1880             }
1881             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1882                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1883                 return false;
1884             }
1885             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1886                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1887                 return false;
1888             }
1889             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1890                     .equals( "GO:0005829" ) ) {
1891                 return false;
1892             }
1893             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1894                     .equals( "intracellular organelle" ) ) {
1895                 return false;
1896             }
1897             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1898                 return false;
1899             }
1900             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1901                     .equals( "UniProt link" ) ) ) {
1902                 return false;
1903             }
1904             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1905                 return false;
1906             }
1907             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1908             if ( x.size() != 4 ) {
1909                 return false;
1910             }
1911             int c = 0;
1912             for( final Accession acc : x ) {
1913                 if ( c == 0 ) {
1914                     if ( !acc.getSource().equals( "KEGG" ) ) {
1915                         return false;
1916                     }
1917                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1918                         return false;
1919                     }
1920                 }
1921                 c++;
1922             }
1923         }
1924         catch ( final Exception e ) {
1925             e.printStackTrace( System.out );
1926             return false;
1927         }
1928         return true;
1929     }
1930
1931     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1932         try {
1933             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1934             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1935             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1936                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1937             }
1938             else {
1939                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1940             }
1941             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1942                                                               xml_parser );
1943             if ( xml_parser.getErrorCount() > 0 ) {
1944                 System.out.println( xml_parser.getErrorMessages().toString() );
1945                 return false;
1946             }
1947             if ( phylogenies_0.length != 4 ) {
1948                 return false;
1949             }
1950             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1951             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1952             if ( phylogenies_t1.length != 1 ) {
1953                 return false;
1954             }
1955             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1956             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1957                 return false;
1958             }
1959             if ( !t1_rt.isRooted() ) {
1960                 return false;
1961             }
1962             if ( t1_rt.isRerootable() ) {
1963                 return false;
1964             }
1965             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1966                 return false;
1967             }
1968             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1969             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1970             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1971             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1972                 return false;
1973             }
1974             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1975                 return false;
1976             }
1977             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1978                 return false;
1979             }
1980             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1981                 return false;
1982             }
1983             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1984                     .startsWith( "actgtgggggt" ) ) {
1985                 return false;
1986             }
1987             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1988                     .startsWith( "ctgtgatgcat" ) ) {
1989                 return false;
1990             }
1991             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1992             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1993             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1994             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1995             if ( phylogenies_1.length != 1 ) {
1996                 return false;
1997             }
1998             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1999             if ( !t3_rt.getName().equals( "t3" ) ) {
2000                 return false;
2001             }
2002             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
2003                 return false;
2004             }
2005             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
2006                 return false;
2007             }
2008             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
2009                 return false;
2010             }
2011             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
2012                 return false;
2013             }
2014             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
2015                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
2016                 return false;
2017             }
2018             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
2019                 return false;
2020             }
2021             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
2022                 return false;
2023             }
2024             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
2025                     .equals( "UniProtKB" ) ) {
2026                 return false;
2027             }
2028             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2029                     .equals( "apoptosis" ) ) {
2030                 return false;
2031             }
2032             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
2033                     .equals( "GO:0006915" ) ) {
2034                 return false;
2035             }
2036             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
2037                     .equals( "UniProtKB" ) ) {
2038                 return false;
2039             }
2040             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
2041                     .equals( "experimental" ) ) {
2042                 return false;
2043             }
2044             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2045                     .equals( "function" ) ) {
2046                 return false;
2047             }
2048             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2049                     .getValue() != 1 ) {
2050                 return false;
2051             }
2052             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2053                     .getType().equals( "ml" ) ) {
2054                 return false;
2055             }
2056             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2057                     .equals( "apoptosis" ) ) {
2058                 return false;
2059             }
2060             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2061                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2062                 return false;
2063             }
2064             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2065                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
2066                 return false;
2067             }
2068             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2069                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
2070                 return false;
2071             }
2072             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2073                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
2074                 return false;
2075             }
2076             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2077                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
2078                 return false;
2079             }
2080             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2081                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
2082                 return false;
2083             }
2084             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2085                     .equals( "GO:0005829" ) ) {
2086                 return false;
2087             }
2088             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2089                     .equals( "intracellular organelle" ) ) {
2090                 return false;
2091             }
2092             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
2093                 return false;
2094             }
2095             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2096                     .equals( "UniProt link" ) ) ) {
2097                 return false;
2098             }
2099             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2100                 return false;
2101             }
2102             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
2103                 return false;
2104             }
2105             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
2106                     .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." ) ) ) {
2107                 return false;
2108             }
2109             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
2110                 return false;
2111             }
2112             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
2113                 return false;
2114             }
2115             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
2116                 return false;
2117             }
2118             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
2119                 return false;
2120             }
2121             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
2122                     .equals( "ncbi" ) ) {
2123                 return false;
2124             }
2125             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
2126                 return false;
2127             }
2128             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2129                     .getName().equals( "B" ) ) {
2130                 return false;
2131             }
2132             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2133                     .getFrom() != 21 ) {
2134                 return false;
2135             }
2136             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
2137                 return false;
2138             }
2139             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2140                     .getLength() != 24 ) {
2141                 return false;
2142             }
2143             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2144                     .getConfidence() != 0 ) {
2145                 return false;
2146             }
2147             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2148                     .equals( "pfam" ) ) {
2149                 return false;
2150             }
2151             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2152                 return false;
2153             }
2154             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2155                 return false;
2156             }
2157             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2158                 return false;
2159             }
2160             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2161                 return false;
2162             }
2163             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2164             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2165                 return false;
2166             }
2167             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2168                 return false;
2169             }
2170             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2171                 return false;
2172             }
2173             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2174                 return false;
2175             }
2176             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2177                 return false;
2178             }
2179             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2180                 return false;
2181             }
2182             if ( taxbb.getSynonyms().size() != 2 ) {
2183                 return false;
2184             }
2185             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2186                 return false;
2187             }
2188             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2189                 return false;
2190             }
2191             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2192                 return false;
2193             }
2194             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2195                 return false;
2196             }
2197             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2198                 return false;
2199             }
2200             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2201                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2202                 return false;
2203             }
2204             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2205                 return false;
2206             }
2207             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2208                 return false;
2209             }
2210             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2211                 return false;
2212             }
2213             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2214                 return false;
2215             }
2216             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2217                 return false;
2218             }
2219             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2220                 return false;
2221             }
2222             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2223                 return false;
2224             }
2225             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2226                 return false;
2227             }
2228             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2229                     .equalsIgnoreCase( "435" ) ) {
2230                 return false;
2231             }
2232             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
2233                 return false;
2234             }
2235             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2236                     .equalsIgnoreCase( "443.7" ) ) {
2237                 return false;
2238             }
2239             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2240                 return false;
2241             }
2242             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2243                 return false;
2244             }
2245             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2246                     .equalsIgnoreCase( "433" ) ) {
2247                 return false;
2248             }
2249             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2250                     .getCrossReferences();
2251             if ( x.size() != 4 ) {
2252                 return false;
2253             }
2254             int c = 0;
2255             for( final Accession acc : x ) {
2256                 if ( c == 0 ) {
2257                     if ( !acc.getSource().equals( "KEGG" ) ) {
2258                         return false;
2259                     }
2260                     if ( !acc.getValue().equals( "hsa:596" ) ) {
2261                         return false;
2262                     }
2263                 }
2264                 c++;
2265             }
2266         }
2267         catch ( final Exception e ) {
2268             e.printStackTrace( System.out );
2269             return false;
2270         }
2271         return true;
2272     }
2273
2274     private static boolean testBasicPhyloXMLparsingValidating() {
2275         try {
2276             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2277             PhyloXmlParser xml_parser = null;
2278             try {
2279                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2280             }
2281             catch ( final Exception e ) {
2282                 // Do nothing -- means were not running from jar.
2283             }
2284             if ( xml_parser == null ) {
2285                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2286                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2287                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2288                 }
2289                 else {
2290                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2291                 }
2292             }
2293             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
2294                                                               xml_parser );
2295             if ( xml_parser.getErrorCount() > 0 ) {
2296                 System.out.println( xml_parser.getErrorMessages().toString() );
2297                 return false;
2298             }
2299             if ( phylogenies_0.length != 4 ) {
2300                 return false;
2301             }
2302             final Phylogeny t1 = phylogenies_0[ 0 ];
2303             final Phylogeny t2 = phylogenies_0[ 1 ];
2304             final Phylogeny t3 = phylogenies_0[ 2 ];
2305             final Phylogeny t4 = phylogenies_0[ 3 ];
2306             if ( !t1.getName().equals( "t1" ) ) {
2307                 return false;
2308             }
2309             if ( !t2.getName().equals( "t2" ) ) {
2310                 return false;
2311             }
2312             if ( !t3.getName().equals( "t3" ) ) {
2313                 return false;
2314             }
2315             if ( !t4.getName().equals( "t4" ) ) {
2316                 return false;
2317             }
2318             if ( t1.getNumberOfExternalNodes() != 1 ) {
2319                 return false;
2320             }
2321             if ( t2.getNumberOfExternalNodes() != 2 ) {
2322                 return false;
2323             }
2324             if ( t3.getNumberOfExternalNodes() != 4 ) {
2325                 return false;
2326             }
2327             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2328             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
2329             if ( xml_parser.getErrorCount() > 0 ) {
2330                 System.out.println( "errors:" );
2331                 System.out.println( xml_parser.getErrorMessages().toString() );
2332                 return false;
2333             }
2334             if ( phylogenies_1.length != 4 ) {
2335                 return false;
2336             }
2337             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
2338                                                               xml_parser );
2339             if ( xml_parser.getErrorCount() > 0 ) {
2340                 System.out.println( "errors:" );
2341                 System.out.println( xml_parser.getErrorMessages().toString() );
2342                 return false;
2343             }
2344             if ( phylogenies_2.length != 1 ) {
2345                 return false;
2346             }
2347             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2348                 return false;
2349             }
2350             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
2351                                                               xml_parser );
2352             if ( xml_parser.getErrorCount() > 0 ) {
2353                 System.out.println( xml_parser.getErrorMessages().toString() );
2354                 return false;
2355             }
2356             if ( phylogenies_3.length != 2 ) {
2357                 return false;
2358             }
2359             final Phylogeny a = phylogenies_3[ 0 ];
2360             if ( !a.getName().equals( "tree 4" ) ) {
2361                 return false;
2362             }
2363             if ( a.getNumberOfExternalNodes() != 3 ) {
2364                 return false;
2365             }
2366             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2367                 return false;
2368             }
2369             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2370                 return false;
2371             }
2372             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
2373                                                               xml_parser );
2374             if ( xml_parser.getErrorCount() > 0 ) {
2375                 System.out.println( xml_parser.getErrorMessages().toString() );
2376                 return false;
2377             }
2378             if ( phylogenies_4.length != 1 ) {
2379                 return false;
2380             }
2381             final Phylogeny s = phylogenies_4[ 0 ];
2382             if ( s.getNumberOfExternalNodes() != 6 ) {
2383                 return false;
2384             }
2385             s.getNode( "first" );
2386             s.getNode( "<>" );
2387             s.getNode( "\"<a'b&c'd\">\"" );
2388             s.getNode( "'''\"" );
2389             s.getNode( "\"\"\"" );
2390             s.getNode( "dick & doof" );
2391         }
2392         catch ( final Exception e ) {
2393             e.printStackTrace( System.out );
2394             return false;
2395         }
2396         return true;
2397     }
2398
2399     private static boolean testBasicProtein() {
2400         try {
2401             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2402             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2403             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2404             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2405             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2406             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2407             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2408             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2409             p0.addProteinDomain( y );
2410             p0.addProteinDomain( e );
2411             p0.addProteinDomain( b );
2412             p0.addProteinDomain( c );
2413             p0.addProteinDomain( d );
2414             p0.addProteinDomain( a );
2415             p0.addProteinDomain( x );
2416             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2417                 return false;
2418             }
2419             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2420                 return false;
2421             }
2422             //
2423             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2424             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2425             aa0.addProteinDomain( a1 );
2426             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2427                 return false;
2428             }
2429             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2430                 return false;
2431             }
2432             //
2433             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2434             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2435             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2436             aa1.addProteinDomain( a11 );
2437             aa1.addProteinDomain( a12 );
2438             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2439                 return false;
2440             }
2441             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2442                 return false;
2443             }
2444             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2445             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2446                 return false;
2447             }
2448             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2449                 return false;
2450             }
2451             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2452                 return false;
2453             }
2454             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2455             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2456                 return false;
2457             }
2458             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2459                 return false;
2460             }
2461             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2462                 return false;
2463             }
2464             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2465                 return false;
2466             }
2467             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2468             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2469                 return false;
2470             }
2471             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2472                 return false;
2473             }
2474             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2475                 return false;
2476             }
2477             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2478                 return false;
2479             }
2480             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2481             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2482                 return false;
2483             }
2484             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2485                 return false;
2486             }
2487             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2488                 return false;
2489             }
2490             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2491                 return false;
2492             }
2493             //
2494             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2495             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2496             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2497             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2498             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2499             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2500             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2501             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2502             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2503             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2504             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2505             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2506             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2507             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2508             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2509             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2510             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2511             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2512             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2513             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2514             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2515             p00.addProteinDomain( y0 );
2516             p00.addProteinDomain( e0 );
2517             p00.addProteinDomain( b0 );
2518             p00.addProteinDomain( c0 );
2519             p00.addProteinDomain( d0 );
2520             p00.addProteinDomain( a0 );
2521             p00.addProteinDomain( x0 );
2522             p00.addProteinDomain( y1 );
2523             p00.addProteinDomain( y2 );
2524             p00.addProteinDomain( y3 );
2525             p00.addProteinDomain( e1 );
2526             p00.addProteinDomain( e2 );
2527             p00.addProteinDomain( e3 );
2528             p00.addProteinDomain( e4 );
2529             p00.addProteinDomain( e5 );
2530             p00.addProteinDomain( z0 );
2531             p00.addProteinDomain( z1 );
2532             p00.addProteinDomain( z2 );
2533             p00.addProteinDomain( zz0 );
2534             p00.addProteinDomain( zz1 );
2535             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2536                 return false;
2537             }
2538             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2539                 return false;
2540             }
2541             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2542                 return false;
2543             }
2544             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2545                 return false;
2546             }
2547             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" ) ) {
2548                 return false;
2549             }
2550             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2551             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2552             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2553             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2554             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2555             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2556             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2557             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2558             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2559             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2560             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2561             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2562             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2563             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2564             p.addProteinDomain( B15 );
2565             p.addProteinDomain( C50 );
2566             p.addProteinDomain( A60 );
2567             p.addProteinDomain( A30 );
2568             p.addProteinDomain( C70 );
2569             p.addProteinDomain( B35 );
2570             p.addProteinDomain( B40 );
2571             p.addProteinDomain( A0 );
2572             p.addProteinDomain( A10 );
2573             p.addProteinDomain( A20 );
2574             p.addProteinDomain( B25 );
2575             p.addProteinDomain( D80 );
2576             List<String> domains_ids = new ArrayList<String>();
2577             domains_ids.add( "A" );
2578             domains_ids.add( "B" );
2579             domains_ids.add( "C" );
2580             if ( !p.contains( domains_ids, false ) ) {
2581                 return false;
2582             }
2583             if ( !p.contains( domains_ids, true ) ) {
2584                 return false;
2585             }
2586             domains_ids.add( "X" );
2587             if ( p.contains( domains_ids, false ) ) {
2588                 return false;
2589             }
2590             if ( p.contains( domains_ids, true ) ) {
2591                 return false;
2592             }
2593             domains_ids = new ArrayList<String>();
2594             domains_ids.add( "A" );
2595             domains_ids.add( "C" );
2596             domains_ids.add( "D" );
2597             if ( !p.contains( domains_ids, false ) ) {
2598                 return false;
2599             }
2600             if ( !p.contains( domains_ids, true ) ) {
2601                 return false;
2602             }
2603             domains_ids = new ArrayList<String>();
2604             domains_ids.add( "A" );
2605             domains_ids.add( "D" );
2606             domains_ids.add( "C" );
2607             if ( !p.contains( domains_ids, false ) ) {
2608                 return false;
2609             }
2610             if ( p.contains( domains_ids, true ) ) {
2611                 return false;
2612             }
2613             domains_ids = new ArrayList<String>();
2614             domains_ids.add( "A" );
2615             domains_ids.add( "A" );
2616             domains_ids.add( "B" );
2617             if ( !p.contains( domains_ids, false ) ) {
2618                 return false;
2619             }
2620             if ( !p.contains( domains_ids, true ) ) {
2621                 return false;
2622             }
2623             domains_ids = new ArrayList<String>();
2624             domains_ids.add( "A" );
2625             domains_ids.add( "A" );
2626             domains_ids.add( "A" );
2627             domains_ids.add( "B" );
2628             domains_ids.add( "B" );
2629             if ( !p.contains( domains_ids, false ) ) {
2630                 return false;
2631             }
2632             if ( !p.contains( domains_ids, true ) ) {
2633                 return false;
2634             }
2635             domains_ids = new ArrayList<String>();
2636             domains_ids.add( "A" );
2637             domains_ids.add( "A" );
2638             domains_ids.add( "B" );
2639             domains_ids.add( "A" );
2640             domains_ids.add( "B" );
2641             domains_ids.add( "B" );
2642             domains_ids.add( "A" );
2643             domains_ids.add( "B" );
2644             domains_ids.add( "C" );
2645             domains_ids.add( "A" );
2646             domains_ids.add( "C" );
2647             domains_ids.add( "D" );
2648             if ( !p.contains( domains_ids, false ) ) {
2649                 return false;
2650             }
2651             if ( p.contains( domains_ids, true ) ) {
2652                 return false;
2653             }
2654         }
2655         catch ( final Exception e ) {
2656             e.printStackTrace( System.out );
2657             return false;
2658         }
2659         return true;
2660     }
2661
2662     private static boolean testBasicTable() {
2663         try {
2664             final BasicTable<String> t0 = new BasicTable<String>();
2665             if ( t0.getNumberOfColumns() != 0 ) {
2666                 return false;
2667             }
2668             if ( t0.getNumberOfRows() != 0 ) {
2669                 return false;
2670             }
2671             t0.setValue( 3, 2, "23" );
2672             t0.setValue( 10, 1, "error" );
2673             t0.setValue( 10, 1, "110" );
2674             t0.setValue( 9, 1, "19" );
2675             t0.setValue( 1, 10, "101" );
2676             t0.setValue( 10, 10, "1010" );
2677             t0.setValue( 100, 10, "10100" );
2678             t0.setValue( 0, 0, "00" );
2679             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2680                 return false;
2681             }
2682             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2683                 return false;
2684             }
2685             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2686                 return false;
2687             }
2688             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2689                 return false;
2690             }
2691             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2692                 return false;
2693             }
2694             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2695                 return false;
2696             }
2697             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2698                 return false;
2699             }
2700             if ( t0.getNumberOfColumns() != 101 ) {
2701                 return false;
2702             }
2703             if ( t0.getNumberOfRows() != 11 ) {
2704                 return false;
2705             }
2706             if ( t0.getValueAsString( 49, 4 ) != null ) {
2707                 return false;
2708             }
2709             final String l = ForesterUtil.getLineSeparator();
2710             final StringBuffer source = new StringBuffer();
2711             source.append( "" + l );
2712             source.append( "# 1 1 1 1 1 1 1 1" + l );
2713             source.append( " 00 01 02 03" + l );
2714             source.append( "   10 11 12 13  " + l );
2715             source.append( "20 21 22 23 " + l );
2716             source.append( "    30  31    32 33" + l );
2717             source.append( "40 41 42 43" + l );
2718             source.append( "  # 1 1 1 1 1 " + l );
2719             source.append( "50 51 52 53 54" + l );
2720             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2721             if ( t1.getNumberOfColumns() != 5 ) {
2722                 return false;
2723             }
2724             if ( t1.getNumberOfRows() != 6 ) {
2725                 return false;
2726             }
2727             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2728                 return false;
2729             }
2730             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2731                 return false;
2732             }
2733             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2734                 return false;
2735             }
2736             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2737                 return false;
2738             }
2739             final StringBuffer source1 = new StringBuffer();
2740             source1.append( "" + l );
2741             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2742             source1.append( " 00; 01 ;02;03" + l );
2743             source1.append( "   10; 11; 12; 13  " + l );
2744             source1.append( "20; 21; 22; 23 " + l );
2745             source1.append( "    30;  31;    32; 33" + l );
2746             source1.append( "40;41;42;43" + l );
2747             source1.append( "  # 1 1 1 1 1 " + l );
2748             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2749             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2750             if ( t2.getNumberOfColumns() != 5 ) {
2751                 return false;
2752             }
2753             if ( t2.getNumberOfRows() != 6 ) {
2754                 return false;
2755             }
2756             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2757                 return false;
2758             }
2759             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2760                 return false;
2761             }
2762             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2763                 return false;
2764             }
2765             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2766                 return false;
2767             }
2768             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2769                 return false;
2770             }
2771             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2772                 return false;
2773             }
2774             final StringBuffer source2 = new StringBuffer();
2775             source2.append( "" + l );
2776             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2777             source2.append( " 00; 01 ;02;03" + l );
2778             source2.append( "   10; 11; 12; 13  " + l );
2779             source2.append( "20; 21; 22; 23 " + l );
2780             source2.append( "                     " + l );
2781             source2.append( "    30;  31;    32; 33" + l );
2782             source2.append( "40;41;42;43" + l );
2783             source2.append( "  comment: 1 1 1 1 1 " + l );
2784             source2.append( ";;;50  ;   52; 53;;54   " + l );
2785             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2786                                                                         ';',
2787                                                                         false,
2788                                                                         false,
2789                                                                         "comment:",
2790                                                                         false );
2791             if ( tl.size() != 2 ) {
2792                 return false;
2793             }
2794             final BasicTable<String> t3 = tl.get( 0 );
2795             final BasicTable<String> t4 = tl.get( 1 );
2796             if ( t3.getNumberOfColumns() != 4 ) {
2797                 return false;
2798             }
2799             if ( t3.getNumberOfRows() != 3 ) {
2800                 return false;
2801             }
2802             if ( t4.getNumberOfColumns() != 4 ) {
2803                 return false;
2804             }
2805             if ( t4.getNumberOfRows() != 3 ) {
2806                 return false;
2807             }
2808             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2809                 return false;
2810             }
2811             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2812                 return false;
2813             }
2814         }
2815         catch ( final Exception e ) {
2816             e.printStackTrace( System.out );
2817             return false;
2818         }
2819         return true;
2820     }
2821
2822     private static boolean testBasicTolXMLparsing() {
2823         try {
2824             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2825             final TolParser parser = new TolParser();
2826             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2827             if ( parser.getErrorCount() > 0 ) {
2828                 System.out.println( parser.getErrorMessages().toString() );
2829                 return false;
2830             }
2831             if ( phylogenies_0.length != 1 ) {
2832                 return false;
2833             }
2834             final Phylogeny t1 = phylogenies_0[ 0 ];
2835             if ( t1.getNumberOfExternalNodes() != 5 ) {
2836                 return false;
2837             }
2838             if ( !t1.isRooted() ) {
2839                 return false;
2840             }
2841             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2842                 return false;
2843             }
2844             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2845                 return false;
2846             }
2847             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2848                 return false;
2849             }
2850             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2851                 return false;
2852             }
2853             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2854             if ( parser.getErrorCount() > 0 ) {
2855                 System.out.println( parser.getErrorMessages().toString() );
2856                 return false;
2857             }
2858             if ( phylogenies_1.length != 1 ) {
2859                 return false;
2860             }
2861             final Phylogeny t2 = phylogenies_1[ 0 ];
2862             if ( t2.getNumberOfExternalNodes() != 664 ) {
2863                 return false;
2864             }
2865             if ( !t2.isRooted() ) {
2866                 return false;
2867             }
2868             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2869                 return false;
2870             }
2871             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2872                 return false;
2873             }
2874             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2875                 return false;
2876             }
2877             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2878                 return false;
2879             }
2880             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2881                 return false;
2882             }
2883             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2884                     .equals( "Aquifex" ) ) {
2885                 return false;
2886             }
2887             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2888             if ( parser.getErrorCount() > 0 ) {
2889                 System.out.println( parser.getErrorMessages().toString() );
2890                 return false;
2891             }
2892             if ( phylogenies_2.length != 1 ) {
2893                 return false;
2894             }
2895             final Phylogeny t3 = phylogenies_2[ 0 ];
2896             if ( t3.getNumberOfExternalNodes() != 184 ) {
2897                 return false;
2898             }
2899             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2900                 return false;
2901             }
2902             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2903                 return false;
2904             }
2905             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2906                 return false;
2907             }
2908             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2909             if ( parser.getErrorCount() > 0 ) {
2910                 System.out.println( parser.getErrorMessages().toString() );
2911                 return false;
2912             }
2913             if ( phylogenies_3.length != 1 ) {
2914                 return false;
2915             }
2916             final Phylogeny t4 = phylogenies_3[ 0 ];
2917             if ( t4.getNumberOfExternalNodes() != 1 ) {
2918                 return false;
2919             }
2920             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2921                 return false;
2922             }
2923             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2924                 return false;
2925             }
2926             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2927                 return false;
2928             }
2929             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2930             if ( parser.getErrorCount() > 0 ) {
2931                 System.out.println( parser.getErrorMessages().toString() );
2932                 return false;
2933             }
2934             if ( phylogenies_4.length != 1 ) {
2935                 return false;
2936             }
2937             final Phylogeny t5 = phylogenies_4[ 0 ];
2938             if ( t5.getNumberOfExternalNodes() != 13 ) {
2939                 return false;
2940             }
2941             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2942                 return false;
2943             }
2944             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2945                 return false;
2946             }
2947             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2948                 return false;
2949             }
2950         }
2951         catch ( final Exception e ) {
2952             e.printStackTrace( System.out );
2953             return false;
2954         }
2955         return true;
2956     }
2957
2958     private static boolean testBasicTreeMethods() {
2959         try {
2960             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2961             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2962             if ( t2.getNumberOfExternalNodes() != 4 ) {
2963                 return false;
2964             }
2965             if ( t2.getHeight() != 8.5 ) {
2966                 return false;
2967             }
2968             if ( !t2.isCompletelyBinary() ) {
2969                 return false;
2970             }
2971             if ( t2.isEmpty() ) {
2972                 return false;
2973             }
2974             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2975             if ( t3.getNumberOfExternalNodes() != 5 ) {
2976                 return false;
2977             }
2978             if ( t3.getHeight() != 11 ) {
2979                 return false;
2980             }
2981             if ( t3.isCompletelyBinary() ) {
2982                 return false;
2983             }
2984             final PhylogenyNode n = t3.getNode( "ABC" );
2985             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 ];
2986             if ( t4.getNumberOfExternalNodes() != 9 ) {
2987                 return false;
2988             }
2989             if ( t4.getHeight() != 11 ) {
2990                 return false;
2991             }
2992             if ( t4.isCompletelyBinary() ) {
2993                 return false;
2994             }
2995             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)" );
2996             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2997             if ( t5.getNumberOfExternalNodes() != 8 ) {
2998                 return false;
2999             }
3000             if ( t5.getHeight() != 15 ) {
3001                 return false;
3002             }
3003             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)" );
3004             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
3005             if ( t6.getHeight() != 15 ) {
3006                 return false;
3007             }
3008             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)" );
3009             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
3010             if ( t7.getHeight() != 15 ) {
3011                 return false;
3012             }
3013             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)" );
3014             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
3015             if ( t8.getNumberOfExternalNodes() != 10 ) {
3016                 return false;
3017             }
3018             if ( t8.getHeight() != 15 ) {
3019                 return false;
3020             }
3021             final char[] a9 = new char[] { 'a' };
3022             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
3023             if ( t9.getHeight() != 0 ) {
3024                 return false;
3025             }
3026             final char[] a10 = new char[] { 'a', ':', '6' };
3027             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
3028             if ( t10.getHeight() != 6 ) {
3029                 return false;
3030             }
3031         }
3032         catch ( final Exception e ) {
3033             e.printStackTrace( System.out );
3034             return false;
3035         }
3036         return true;
3037     }
3038
3039     private static boolean testConfidenceAssessor() {
3040         try {
3041             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3042             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3043             final Phylogeny[] ev0 = factory
3044                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
3045                              new NHXParser() );
3046             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
3047             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3048                 return false;
3049             }
3050             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3051                 return false;
3052             }
3053             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3054             final Phylogeny[] ev1 = factory
3055                     .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)));",
3056                              new NHXParser() );
3057             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
3058             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
3059                 return false;
3060             }
3061             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3062                 return false;
3063             }
3064             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3065             final Phylogeny[] ev_b = factory
3066                     .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",
3067                              new NHXParser() );
3068             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
3069             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
3070                 return false;
3071             }
3072             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3073                 return false;
3074             }
3075             //
3076             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3077             final Phylogeny[] ev1x = factory
3078                     .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)));",
3079                              new NHXParser() );
3080             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
3081             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3082                 return false;
3083             }
3084             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3085                 return false;
3086             }
3087             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3088             final Phylogeny[] ev_bx = factory
3089                     .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",
3090                              new NHXParser() );
3091             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
3092             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3093                 return false;
3094             }
3095             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3096                 return false;
3097             }
3098             final Phylogeny[] t2 = factory
3099                     .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);",
3100                              new NHXParser() );
3101             final Phylogeny[] ev2 = factory
3102                     .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);",
3103                              new NHXParser() );
3104             for( final Phylogeny target : t2 ) {
3105                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
3106             }
3107             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
3108                                                  new NHXParser() )[ 0 ];
3109             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
3110             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
3111             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3112                 return false;
3113             }
3114             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
3115                 return false;
3116             }
3117             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3118                 return false;
3119             }
3120         }
3121         catch ( final Exception e ) {
3122             e.printStackTrace();
3123             return false;
3124         }
3125         return true;
3126     }
3127
3128     private static boolean testCopyOfNodeData() {
3129         try {
3130             final PhylogenyNode n1 = PhylogenyNode
3131                     .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]" );
3132             final PhylogenyNode n2 = n1.copyNodeData();
3133             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
3134                 return false;
3135             }
3136         }
3137         catch ( final Exception e ) {
3138             e.printStackTrace();
3139             return false;
3140         }
3141         return true;
3142     }
3143
3144     private static boolean testCreateBalancedPhylogeny() {
3145         try {
3146             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3147             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3148                 return false;
3149             }
3150             if ( p0.getNumberOfExternalNodes() != 15625 ) {
3151                 return false;
3152             }
3153             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3154             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3155                 return false;
3156             }
3157             if ( p1.getNumberOfExternalNodes() != 100 ) {
3158                 return false;
3159             }
3160         }
3161         catch ( final Exception e ) {
3162             e.printStackTrace();
3163             return false;
3164         }
3165         return true;
3166     }
3167
3168     private static boolean testCreateUriForSeqWeb() {
3169         try {
3170             final PhylogenyNode n = new PhylogenyNode();
3171             n.setName( "tr|B3RJ64" );
3172             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3173                 return false;
3174             }
3175             n.setName( "B0LM41_HUMAN" );
3176             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3177                 return false;
3178             }
3179             n.setName( "NP_001025424" );
3180             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3181                 return false;
3182             }
3183             n.setName( "_NM_001030253-" );
3184             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3185                 return false;
3186             }
3187             n.setName( "XM_002122186" );
3188             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3189                 return false;
3190             }
3191             n.setName( "dgh_AAA34956_gdg" );
3192             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3193                 return false;
3194             }
3195             n.setName( "AAA34956" );
3196             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3197                 return false;
3198             }
3199             n.setName( "GI:394892" );
3200             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3201                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3202                 return false;
3203             }
3204             n.setName( "gi_394892" );
3205             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3206                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3207                 return false;
3208             }
3209             n.setName( "gi6335_gi_394892_56635_Gi_43" );
3210             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3211                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3212                 return false;
3213             }
3214             n.setName( "P12345" );
3215             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3216                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3217                 return false;
3218             }
3219             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3220             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3221                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3222                 return false;
3223             }
3224         }
3225         catch ( final Exception e ) {
3226             e.printStackTrace( System.out );
3227             return false;
3228         }
3229         return true;
3230     }
3231
3232     private static boolean testDataObjects() {
3233         try {
3234             final Confidence s0 = new Confidence();
3235             final Confidence s1 = new Confidence();
3236             if ( !s0.isEqual( s1 ) ) {
3237                 return false;
3238             }
3239             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3240             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3241             if ( s2.isEqual( s1 ) ) {
3242                 return false;
3243             }
3244             if ( !s2.isEqual( s3 ) ) {
3245                 return false;
3246             }
3247             final Confidence s4 = ( Confidence ) s3.copy();
3248             if ( !s4.isEqual( s3 ) ) {
3249                 return false;
3250             }
3251             s3.asSimpleText();
3252             s3.asText();
3253             // Taxonomy
3254             // ----------
3255             final Taxonomy t1 = new Taxonomy();
3256             final Taxonomy t2 = new Taxonomy();
3257             final Taxonomy t3 = new Taxonomy();
3258             final Taxonomy t4 = new Taxonomy();
3259             final Taxonomy t5 = new Taxonomy();
3260             t1.setIdentifier( new Identifier( "ecoli" ) );
3261             t1.setTaxonomyCode( "ECOLI" );
3262             t1.setScientificName( "E. coli" );
3263             t1.setCommonName( "coli" );
3264             final Taxonomy t0 = ( Taxonomy ) t1.copy();
3265             if ( !t1.isEqual( t0 ) ) {
3266                 return false;
3267             }
3268             t2.setIdentifier( new Identifier( "ecoli" ) );
3269             t2.setTaxonomyCode( "OTHER" );
3270             t2.setScientificName( "what" );
3271             t2.setCommonName( "something" );
3272             if ( !t1.isEqual( t2 ) ) {
3273                 return false;
3274             }
3275             t2.setIdentifier( new Identifier( "nemve" ) );
3276             if ( t1.isEqual( t2 ) ) {
3277                 return false;
3278             }
3279             t1.setIdentifier( null );
3280             t3.setTaxonomyCode( "ECOLI" );
3281             t3.setScientificName( "what" );
3282             t3.setCommonName( "something" );
3283             if ( !t1.isEqual( t3 ) ) {
3284                 return false;
3285             }
3286             t1.setIdentifier( null );
3287             t1.setTaxonomyCode( "" );
3288             t4.setScientificName( "E. ColI" );
3289             t4.setCommonName( "something" );
3290             if ( !t1.isEqual( t4 ) ) {
3291                 return false;
3292             }
3293             t4.setScientificName( "B. subtilis" );
3294             t4.setCommonName( "something" );
3295             if ( t1.isEqual( t4 ) ) {
3296                 return false;
3297             }
3298             t1.setIdentifier( null );
3299             t1.setTaxonomyCode( "" );
3300             t1.setScientificName( "" );
3301             t5.setCommonName( "COLI" );
3302             if ( !t1.isEqual( t5 ) ) {
3303                 return false;
3304             }
3305             t5.setCommonName( "vibrio" );
3306             if ( t1.isEqual( t5 ) ) {
3307                 return false;
3308             }
3309             // Identifier
3310             // ----------
3311             final Identifier id0 = new Identifier( "123", "pfam" );
3312             final Identifier id1 = ( Identifier ) id0.copy();
3313             if ( !id1.isEqual( id1 ) ) {
3314                 return false;
3315             }
3316             if ( !id1.isEqual( id0 ) ) {
3317                 return false;
3318             }
3319             if ( !id0.isEqual( id1 ) ) {
3320                 return false;
3321             }
3322             id1.asSimpleText();
3323             id1.asText();
3324             // ProteinDomain
3325             // ---------------
3326             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3327             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3328             if ( !pd1.isEqual( pd1 ) ) {
3329                 return false;
3330             }
3331             if ( !pd1.isEqual( pd0 ) ) {
3332                 return false;
3333             }
3334             pd1.asSimpleText();
3335             pd1.asText();
3336             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3337             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3338             if ( !pd3.isEqual( pd3 ) ) {
3339                 return false;
3340             }
3341             if ( !pd2.isEqual( pd3 ) ) {
3342                 return false;
3343             }
3344             if ( !pd0.isEqual( pd3 ) ) {
3345                 return false;
3346             }
3347             pd3.asSimpleText();
3348             pd3.asText();
3349             // DomainArchitecture
3350             // ------------------
3351             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3352             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3353             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3354             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3355             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3356             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3357             domains0.add( d2 );
3358             domains0.add( d0 );
3359             domains0.add( d3 );
3360             domains0.add( d1 );
3361             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3362             if ( ds0.getNumberOfDomains() != 4 ) {
3363                 return false;
3364             }
3365             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3366             if ( !ds0.isEqual( ds0 ) ) {
3367                 return false;
3368             }
3369             if ( !ds0.isEqual( ds1 ) ) {
3370                 return false;
3371             }
3372             if ( ds1.getNumberOfDomains() != 4 ) {
3373                 return false;
3374             }
3375             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3376             domains1.add( d1 );
3377             domains1.add( d2 );
3378             domains1.add( d4 );
3379             domains1.add( d0 );
3380             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3381             if ( ds0.isEqual( ds2 ) ) {
3382                 return false;
3383             }
3384             ds1.asSimpleText();
3385             ds1.asText();
3386             ds1.toNHX();
3387             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3388             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3389                 System.out.println( ds3.toNHX() );
3390                 return false;
3391             }
3392             if ( ds3.getNumberOfDomains() != 3 ) {
3393                 return false;
3394             }
3395             // Event
3396             // -----
3397             final Event e1 = new Event( Event.EventType.fusion );
3398             if ( e1.isDuplication() ) {
3399                 return false;
3400             }
3401             if ( !e1.isFusion() ) {
3402                 return false;
3403             }
3404             if ( !e1.asText().toString().equals( "fusion" ) ) {
3405                 return false;
3406             }
3407             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3408                 return false;
3409             }
3410             final Event e11 = new Event( Event.EventType.fusion );
3411             if ( !e11.isEqual( e1 ) ) {
3412                 return false;
3413             }
3414             if ( !e11.toNHX().toString().equals( "" ) ) {
3415                 return false;
3416             }
3417             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3418             if ( e2.isDuplication() ) {
3419                 return false;
3420             }
3421             if ( !e2.isSpeciationOrDuplication() ) {
3422                 return false;
3423             }
3424             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3425                 return false;
3426             }
3427             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3428                 return false;
3429             }
3430             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3431                 return false;
3432             }
3433             if ( e11.isEqual( e2 ) ) {
3434                 return false;
3435             }
3436             final Event e2c = ( Event ) e2.copy();
3437             if ( !e2c.isEqual( e2 ) ) {
3438                 return false;
3439             }
3440             Event e3 = new Event( 1, 2, 3 );
3441             if ( e3.isDuplication() ) {
3442                 return false;
3443             }
3444             if ( e3.isSpeciation() ) {
3445                 return false;
3446             }
3447             if ( e3.isGeneLoss() ) {
3448                 return false;
3449             }
3450             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3451                 return false;
3452             }
3453             final Event e3c = ( Event ) e3.copy();
3454             final Event e3cc = ( Event ) e3c.copy();
3455             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3456                 return false;
3457             }
3458             e3 = null;
3459             if ( !e3c.isEqual( e3cc ) ) {
3460                 return false;
3461             }
3462             Event e4 = new Event( 1, 2, 3 );
3463             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3464                 return false;
3465             }
3466             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3467                 return false;
3468             }
3469             final Event e4c = ( Event ) e4.copy();
3470             e4 = null;
3471             final Event e4cc = ( Event ) e4c.copy();
3472             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3473                 return false;
3474             }
3475             if ( !e4c.isEqual( e4cc ) ) {
3476                 return false;
3477             }
3478             final Event e5 = new Event();
3479             if ( !e5.isUnassigned() ) {
3480                 return false;
3481             }
3482             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3483                 return false;
3484             }
3485             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3486                 return false;
3487             }
3488             final Event e6 = new Event( 1, 0, 0 );
3489             if ( !e6.asText().toString().equals( "duplication" ) ) {
3490                 return false;
3491             }
3492             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3493                 return false;
3494             }
3495             final Event e7 = new Event( 0, 1, 0 );
3496             if ( !e7.asText().toString().equals( "speciation" ) ) {
3497                 return false;
3498             }
3499             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3500                 return false;
3501             }
3502             final Event e8 = new Event( 0, 0, 1 );
3503             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3504                 return false;
3505             }
3506             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3507                 return false;
3508             }
3509         }
3510         catch ( final Exception e ) {
3511             e.printStackTrace( System.out );
3512             return false;
3513         }
3514         return true;
3515     }
3516
3517     private static boolean testDeletionOfExternalNodes() {
3518         try {
3519             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3520             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3521             final PhylogenyWriter w = new PhylogenyWriter();
3522             if ( t0.isEmpty() ) {
3523                 return false;
3524             }
3525             if ( t0.getNumberOfExternalNodes() != 1 ) {
3526                 return false;
3527             }
3528             t0.deleteSubtree( t0.getNode( "A" ), false );
3529             if ( t0.getNumberOfExternalNodes() != 0 ) {
3530                 return false;
3531             }
3532             if ( !t0.isEmpty() ) {
3533                 return false;
3534             }
3535             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3536             if ( t1.getNumberOfExternalNodes() != 2 ) {
3537                 return false;
3538             }
3539             t1.deleteSubtree( t1.getNode( "A" ), false );
3540             if ( t1.getNumberOfExternalNodes() != 1 ) {
3541                 return false;
3542             }
3543             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3544                 return false;
3545             }
3546             t1.deleteSubtree( t1.getNode( "B" ), false );
3547             if ( t1.getNumberOfExternalNodes() != 1 ) {
3548                 return false;
3549             }
3550             t1.deleteSubtree( t1.getNode( "r" ), false );
3551             if ( !t1.isEmpty() ) {
3552                 return false;
3553             }
3554             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3555             if ( t2.getNumberOfExternalNodes() != 3 ) {
3556                 return false;
3557             }
3558             t2.deleteSubtree( t2.getNode( "B" ), false );
3559             if ( t2.getNumberOfExternalNodes() != 2 ) {
3560                 return false;
3561             }
3562             t2.toNewHampshireX();
3563             PhylogenyNode n = t2.getNode( "A" );
3564             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3565                 return false;
3566             }
3567             t2.deleteSubtree( t2.getNode( "A" ), false );
3568             if ( t2.getNumberOfExternalNodes() != 2 ) {
3569                 return false;
3570             }
3571             t2.deleteSubtree( t2.getNode( "C" ), true );
3572             if ( t2.getNumberOfExternalNodes() != 1 ) {
3573                 return false;
3574             }
3575             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3576             if ( t3.getNumberOfExternalNodes() != 4 ) {
3577                 return false;
3578             }
3579             t3.deleteSubtree( t3.getNode( "B" ), true );
3580             if ( t3.getNumberOfExternalNodes() != 3 ) {
3581                 return false;
3582             }
3583             n = t3.getNode( "A" );
3584             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3585                 return false;
3586             }
3587             n = n.getNextExternalNode();
3588             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3589                 return false;
3590             }
3591             t3.deleteSubtree( t3.getNode( "A" ), true );
3592             if ( t3.getNumberOfExternalNodes() != 2 ) {
3593                 return false;
3594             }
3595             n = t3.getNode( "C" );
3596             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3597                 return false;
3598             }
3599             t3.deleteSubtree( t3.getNode( "C" ), true );
3600             if ( t3.getNumberOfExternalNodes() != 1 ) {
3601                 return false;
3602             }
3603             t3.deleteSubtree( t3.getNode( "D" ), true );
3604             if ( t3.getNumberOfExternalNodes() != 0 ) {
3605                 return false;
3606             }
3607             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3608             if ( t4.getNumberOfExternalNodes() != 6 ) {
3609                 return false;
3610             }
3611             t4.deleteSubtree( t4.getNode( "B2" ), true );
3612             if ( t4.getNumberOfExternalNodes() != 5 ) {
3613                 return false;
3614             }
3615             String s = w.toNewHampshire( t4, true ).toString();
3616             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3617                 return false;
3618             }
3619             t4.deleteSubtree( t4.getNode( "B11" ), true );
3620             if ( t4.getNumberOfExternalNodes() != 4 ) {
3621                 return false;
3622             }
3623             t4.deleteSubtree( t4.getNode( "C" ), true );
3624             if ( t4.getNumberOfExternalNodes() != 3 ) {
3625                 return false;
3626             }
3627             n = t4.getNode( "A" );
3628             n = n.getNextExternalNode();
3629             if ( !n.getName().equals( "B12" ) ) {
3630                 return false;
3631             }
3632             n = n.getNextExternalNode();
3633             if ( !n.getName().equals( "D" ) ) {
3634                 return false;
3635             }
3636             s = w.toNewHampshire( t4, true ).toString();
3637             if ( !s.equals( "((A,B12),D);" ) ) {
3638                 return false;
3639             }
3640             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3641             t5.deleteSubtree( t5.getNode( "A" ), true );
3642             if ( t5.getNumberOfExternalNodes() != 5 ) {
3643                 return false;
3644             }
3645             s = w.toNewHampshire( t5, true ).toString();
3646             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3647                 return false;
3648             }
3649             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3650             t6.deleteSubtree( t6.getNode( "B11" ), true );
3651             if ( t6.getNumberOfExternalNodes() != 5 ) {
3652                 return false;
3653             }
3654             s = w.toNewHampshire( t6, false ).toString();
3655             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3656                 return false;
3657             }
3658             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3659             t7.deleteSubtree( t7.getNode( "B12" ), true );
3660             if ( t7.getNumberOfExternalNodes() != 5 ) {
3661                 return false;
3662             }
3663             s = w.toNewHampshire( t7, true ).toString();
3664             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3665                 return false;
3666             }
3667             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3668             t8.deleteSubtree( t8.getNode( "B2" ), true );
3669             if ( t8.getNumberOfExternalNodes() != 5 ) {
3670                 return false;
3671             }
3672             s = w.toNewHampshire( t8, false ).toString();
3673             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3674                 return false;
3675             }
3676             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3677             t9.deleteSubtree( t9.getNode( "C" ), true );
3678             if ( t9.getNumberOfExternalNodes() != 5 ) {
3679                 return false;
3680             }
3681             s = w.toNewHampshire( t9, true ).toString();
3682             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3683                 return false;
3684             }
3685             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3686             t10.deleteSubtree( t10.getNode( "D" ), true );
3687             if ( t10.getNumberOfExternalNodes() != 5 ) {
3688                 return false;
3689             }
3690             s = w.toNewHampshire( t10, true ).toString();
3691             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3692                 return false;
3693             }
3694             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3695             t11.deleteSubtree( t11.getNode( "A" ), true );
3696             if ( t11.getNumberOfExternalNodes() != 2 ) {
3697                 return false;
3698             }
3699             s = w.toNewHampshire( t11, true ).toString();
3700             if ( !s.equals( "(B,C);" ) ) {
3701                 return false;
3702             }
3703             t11.deleteSubtree( t11.getNode( "C" ), true );
3704             if ( t11.getNumberOfExternalNodes() != 1 ) {
3705                 return false;
3706             }
3707             s = w.toNewHampshire( t11, false ).toString();
3708             if ( !s.equals( "B;" ) ) {
3709                 return false;
3710             }
3711             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3712             t12.deleteSubtree( t12.getNode( "B2" ), true );
3713             if ( t12.getNumberOfExternalNodes() != 8 ) {
3714                 return false;
3715             }
3716             s = w.toNewHampshire( t12, true ).toString();
3717             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3718                 return false;
3719             }
3720             t12.deleteSubtree( t12.getNode( "B3" ), true );
3721             if ( t12.getNumberOfExternalNodes() != 7 ) {
3722                 return false;
3723             }
3724             s = w.toNewHampshire( t12, true ).toString();
3725             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3726                 return false;
3727             }
3728             t12.deleteSubtree( t12.getNode( "C3" ), true );
3729             if ( t12.getNumberOfExternalNodes() != 6 ) {
3730                 return false;
3731             }
3732             s = w.toNewHampshire( t12, true ).toString();
3733             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3734                 return false;
3735             }
3736             t12.deleteSubtree( t12.getNode( "A1" ), true );
3737             if ( t12.getNumberOfExternalNodes() != 5 ) {
3738                 return false;
3739             }
3740             s = w.toNewHampshire( t12, true ).toString();
3741             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3742                 return false;
3743             }
3744             t12.deleteSubtree( t12.getNode( "B1" ), true );
3745             if ( t12.getNumberOfExternalNodes() != 4 ) {
3746                 return false;
3747             }
3748             s = w.toNewHampshire( t12, true ).toString();
3749             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3750                 return false;
3751             }
3752             t12.deleteSubtree( t12.getNode( "A3" ), true );
3753             if ( t12.getNumberOfExternalNodes() != 3 ) {
3754                 return false;
3755             }
3756             s = w.toNewHampshire( t12, true ).toString();
3757             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3758                 return false;
3759             }
3760             t12.deleteSubtree( t12.getNode( "A2" ), true );
3761             if ( t12.getNumberOfExternalNodes() != 2 ) {
3762                 return false;
3763             }
3764             s = w.toNewHampshire( t12, true ).toString();
3765             if ( !s.equals( "(C1,C2);" ) ) {
3766                 return false;
3767             }
3768             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3769             t13.deleteSubtree( t13.getNode( "D" ), true );
3770             if ( t13.getNumberOfExternalNodes() != 4 ) {
3771                 return false;
3772             }
3773             s = w.toNewHampshire( t13, true ).toString();
3774             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3775                 return false;
3776             }
3777             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3778             t14.deleteSubtree( t14.getNode( "E" ), true );
3779             if ( t14.getNumberOfExternalNodes() != 5 ) {
3780                 return false;
3781             }
3782             s = w.toNewHampshire( t14, true ).toString();
3783             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3784                 return false;
3785             }
3786             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3787             t15.deleteSubtree( t15.getNode( "B2" ), true );
3788             if ( t15.getNumberOfExternalNodes() != 11 ) {
3789                 return false;
3790             }
3791             t15.deleteSubtree( t15.getNode( "B1" ), true );
3792             if ( t15.getNumberOfExternalNodes() != 10 ) {
3793                 return false;
3794             }
3795             t15.deleteSubtree( t15.getNode( "B3" ), true );
3796             if ( t15.getNumberOfExternalNodes() != 9 ) {
3797                 return false;
3798             }
3799             t15.deleteSubtree( t15.getNode( "B4" ), true );
3800             if ( t15.getNumberOfExternalNodes() != 8 ) {
3801                 return false;
3802             }
3803             t15.deleteSubtree( t15.getNode( "A1" ), true );
3804             if ( t15.getNumberOfExternalNodes() != 7 ) {
3805                 return false;
3806             }
3807             t15.deleteSubtree( t15.getNode( "C4" ), true );
3808             if ( t15.getNumberOfExternalNodes() != 6 ) {
3809                 return false;
3810             }
3811         }
3812         catch ( final Exception e ) {
3813             e.printStackTrace( System.out );
3814             return false;
3815         }
3816         return true;
3817     }
3818
3819     private static boolean testDescriptiveStatistics() {
3820         try {
3821             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3822             dss1.addValue( 82 );
3823             dss1.addValue( 78 );
3824             dss1.addValue( 70 );
3825             dss1.addValue( 58 );
3826             dss1.addValue( 42 );
3827             if ( dss1.getN() != 5 ) {
3828                 return false;
3829             }
3830             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3831                 return false;
3832             }
3833             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3834                 return false;
3835             }
3836             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3837                 return false;
3838             }
3839             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3840                 return false;
3841             }
3842             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3843                 return false;
3844             }
3845             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3846                 return false;
3847             }
3848             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3849                 return false;
3850             }
3851             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3852                 return false;
3853             }
3854             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3855                 return false;
3856             }
3857             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3858                 return false;
3859             }
3860             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3861                 return false;
3862             }
3863             dss1.addValue( 123 );
3864             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3865                 return false;
3866             }
3867             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3868                 return false;
3869             }
3870             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3871                 return false;
3872             }
3873             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3874             dss2.addValue( -1.85 );
3875             dss2.addValue( 57.5 );
3876             dss2.addValue( 92.78 );
3877             dss2.addValue( 57.78 );
3878             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3879                 return false;
3880             }
3881             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3882                 return false;
3883             }
3884             final double[] a = dss2.getDataAsDoubleArray();
3885             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3886                 return false;
3887             }
3888             dss2.addValue( -100 );
3889             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3890                 return false;
3891             }
3892             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3893                 return false;
3894             }
3895             final double[] ds = new double[ 14 ];
3896             ds[ 0 ] = 34;
3897             ds[ 1 ] = 23;
3898             ds[ 2 ] = 1;
3899             ds[ 3 ] = 32;
3900             ds[ 4 ] = 11;
3901             ds[ 5 ] = 2;
3902             ds[ 6 ] = 12;
3903             ds[ 7 ] = 33;
3904             ds[ 8 ] = 13;
3905             ds[ 9 ] = 22;
3906             ds[ 10 ] = 21;
3907             ds[ 11 ] = 35;
3908             ds[ 12 ] = 24;
3909             ds[ 13 ] = 31;
3910             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3911             if ( bins.length != 4 ) {
3912                 return false;
3913             }
3914             if ( bins[ 0 ] != 2 ) {
3915                 return false;
3916             }
3917             if ( bins[ 1 ] != 3 ) {
3918                 return false;
3919             }
3920             if ( bins[ 2 ] != 4 ) {
3921                 return false;
3922             }
3923             if ( bins[ 3 ] != 5 ) {
3924                 return false;
3925             }
3926             final double[] ds1 = new double[ 9 ];
3927             ds1[ 0 ] = 10.0;
3928             ds1[ 1 ] = 19.0;
3929             ds1[ 2 ] = 9.999;
3930             ds1[ 3 ] = 0.0;
3931             ds1[ 4 ] = 39.9;
3932             ds1[ 5 ] = 39.999;
3933             ds1[ 6 ] = 30.0;
3934             ds1[ 7 ] = 19.999;
3935             ds1[ 8 ] = 30.1;
3936             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3937             if ( bins1.length != 4 ) {
3938                 return false;
3939             }
3940             if ( bins1[ 0 ] != 2 ) {
3941                 return false;
3942             }
3943             if ( bins1[ 1 ] != 3 ) {
3944                 return false;
3945             }
3946             if ( bins1[ 2 ] != 0 ) {
3947                 return false;
3948             }
3949             if ( bins1[ 3 ] != 4 ) {
3950                 return false;
3951             }
3952             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3953             if ( bins1_1.length != 3 ) {
3954                 return false;
3955             }
3956             if ( bins1_1[ 0 ] != 3 ) {
3957                 return false;
3958             }
3959             if ( bins1_1[ 1 ] != 2 ) {
3960                 return false;
3961             }
3962             if ( bins1_1[ 2 ] != 4 ) {
3963                 return false;
3964             }
3965             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3966             if ( bins1_2.length != 3 ) {
3967                 return false;
3968             }
3969             if ( bins1_2[ 0 ] != 2 ) {
3970                 return false;
3971             }
3972             if ( bins1_2[ 1 ] != 2 ) {
3973                 return false;
3974             }
3975             if ( bins1_2[ 2 ] != 2 ) {
3976                 return false;
3977             }
3978             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3979             dss3.addValue( 1 );
3980             dss3.addValue( 1 );
3981             dss3.addValue( 1 );
3982             dss3.addValue( 2 );
3983             dss3.addValue( 3 );
3984             dss3.addValue( 4 );
3985             dss3.addValue( 5 );
3986             dss3.addValue( 5 );
3987             dss3.addValue( 5 );
3988             dss3.addValue( 6 );
3989             dss3.addValue( 7 );
3990             dss3.addValue( 8 );
3991             dss3.addValue( 9 );
3992             dss3.addValue( 10 );
3993             dss3.addValue( 10 );
3994             dss3.addValue( 10 );
3995             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3996             histo.toStringBuffer( 10, '=', 40, 5 );
3997             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3998         }
3999         catch ( final Exception e ) {
4000             e.printStackTrace( System.out );
4001             return false;
4002         }
4003         return true;
4004     }
4005
4006     private static boolean testDir( final String file ) {
4007         try {
4008             final File f = new File( file );
4009             if ( !f.exists() ) {
4010                 return false;
4011             }
4012             if ( !f.isDirectory() ) {
4013                 return false;
4014             }
4015             if ( !f.canRead() ) {
4016                 return false;
4017             }
4018         }
4019         catch ( final Exception e ) {
4020             return false;
4021         }
4022         return true;
4023     }
4024
4025     private static boolean testEbiEntryRetrieval() {
4026         try {
4027             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
4028             if ( !entry.getAccession().equals( "AAK41263" ) ) {
4029                 System.out.println( entry.getAccession() );
4030                 return false;
4031             }
4032             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
4033                 System.out.println( entry.getTaxonomyScientificName() );
4034                 return false;
4035             }
4036             if ( !entry.getSequenceName()
4037                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
4038                 System.out.println( entry.getSequenceName() );
4039                 return false;
4040             }
4041             if ( !entry.getGeneName().equals( "treX-like" ) ) {
4042                 System.out.println( entry.getGeneName() );
4043                 return false;
4044             }
4045             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
4046                 System.out.println( entry.getTaxonomyIdentifier() );
4047                 return false;
4048             }
4049             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
4050                 System.out.println( entry.getAnnotations().first().getRefValue() );
4051                 return false;
4052             }
4053             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
4054                 System.out.println( entry.getAnnotations().first().getRefSource() );
4055                 return false;
4056             }
4057             if ( entry.getCrossReferences().size() < 1 ) {
4058                 return false;
4059             }
4060             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
4061             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
4062                 return false;
4063             }
4064             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
4065                 System.out.println( entry1.getTaxonomyScientificName() );
4066                 return false;
4067             }
4068             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
4069                 System.out.println( entry1.getSequenceName() );
4070                 return false;
4071             }
4072             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
4073                 System.out.println( entry1.getTaxonomyIdentifier() );
4074                 return false;
4075             }
4076             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
4077                 System.out.println( entry1.getGeneName() );
4078                 return false;
4079             }
4080             if ( entry1.getCrossReferences().size() < 1 ) {
4081                 return false;
4082             }
4083             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
4084             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
4085                 return false;
4086             }
4087             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4088                 System.out.println( entry2.getTaxonomyScientificName() );
4089                 return false;
4090             }
4091             if ( !entry2.getSequenceName()
4092                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
4093                 System.out.println( entry2.getSequenceName() );
4094                 return false;
4095             }
4096             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
4097                 System.out.println( entry2.getTaxonomyIdentifier() );
4098                 return false;
4099             }
4100             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
4101                 System.out.println( entry2.getGeneName() );
4102                 return false;
4103             }
4104             if ( entry2.getCrossReferences().size() < 1 ) {
4105                 return false;
4106             }
4107             if ( !entry2.getChromosome().equals( "20" ) ) {
4108                 return false;
4109             }
4110             if ( !entry2.getMap().equals( "20q11.22" ) ) {
4111                 return false;
4112             }
4113             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
4114             if ( !entry3.getAccession().equals( "HM043801" ) ) {
4115                 return false;
4116             }
4117             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
4118                 System.out.println( entry3.getTaxonomyScientificName() );
4119                 return false;
4120             }
4121             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
4122                 System.out.println( entry3.getSequenceName() );
4123                 return false;
4124             }
4125             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
4126                 System.out.println( entry3.getTaxonomyIdentifier() );
4127                 return false;
4128             }
4129             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
4130                 System.out.println( entry3.getSequenceSymbol() );
4131                 return false;
4132             }
4133             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
4134                 return false;
4135             }
4136             if ( entry3.getCrossReferences().size() < 1 ) {
4137                 return false;
4138             }
4139             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
4140             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
4141                 return false;
4142             }
4143             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4144                 System.out.println( entry4.getTaxonomyScientificName() );
4145                 return false;
4146             }
4147             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4148                 System.out.println( entry4.getSequenceName() );
4149                 return false;
4150             }
4151             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4152                 System.out.println( entry4.getTaxonomyIdentifier() );
4153                 return false;
4154             }
4155             if ( !entry4.getGeneName().equals( "ras" ) ) {
4156                 System.out.println( entry4.getGeneName() );
4157                 return false;
4158             }
4159             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4160             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4161                 return false;
4162             }
4163             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4164                 System.out.println( entry5.getTaxonomyScientificName() );
4165                 return false;
4166             }
4167             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4168                 System.out.println( entry5.getSequenceName() );
4169                 return false;
4170             }
4171             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4172                 System.out.println( entry5.getTaxonomyIdentifier() );
4173                 return false;
4174             }
4175             final SequenceDatabaseEntry entry6 = SequenceDbWsTools.obtainEntry( "M30539" );
4176             if ( !entry6.getAccession().equals( "M30539" ) ) {
4177                 return false;
4178             }
4179             if ( !entry6.getGeneName().equals( "ras" ) ) {
4180                 return false;
4181             }
4182             if ( !entry6.getSequenceName().equals( "Human SK2 c-Ha-ras-1 oncogene-encoded protein gene, exon 1" ) ) {
4183                 return false;
4184             }
4185             if ( !entry6.getTaxonomyIdentifier().equals( "9606" ) ) {
4186                 return false;
4187             }
4188             if ( !entry6.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4189                 return false;
4190             }
4191             if ( entry6.getCrossReferences().size() < 1 ) {
4192                 return false;
4193             }
4194         }
4195         catch ( final IOException e ) {
4196             System.out.println();
4197             System.out.println( "the following might be due to absence internet connection:" );
4198             e.printStackTrace( System.out );
4199             return true;
4200         }
4201         catch ( final Exception e ) {
4202             e.printStackTrace();
4203             return false;
4204         }
4205         return true;
4206     }
4207
4208     private static boolean testExternalNodeRelatedMethods() {
4209         try {
4210             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4211             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4212             PhylogenyNode n = t1.getNode( "A" );
4213             n = n.getNextExternalNode();
4214             if ( !n.getName().equals( "B" ) ) {
4215                 return false;
4216             }
4217             n = n.getNextExternalNode();
4218             if ( !n.getName().equals( "C" ) ) {
4219                 return false;
4220             }
4221             n = n.getNextExternalNode();
4222             if ( !n.getName().equals( "D" ) ) {
4223                 return false;
4224             }
4225             n = t1.getNode( "B" );
4226             while ( !n.isLastExternalNode() ) {
4227                 n = n.getNextExternalNode();
4228             }
4229             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4230             n = t2.getNode( "A" );
4231             n = n.getNextExternalNode();
4232             if ( !n.getName().equals( "B" ) ) {
4233                 return false;
4234             }
4235             n = n.getNextExternalNode();
4236             if ( !n.getName().equals( "C" ) ) {
4237                 return false;
4238             }
4239             n = n.getNextExternalNode();
4240             if ( !n.getName().equals( "D" ) ) {
4241                 return false;
4242             }
4243             n = t2.getNode( "B" );
4244             while ( !n.isLastExternalNode() ) {
4245                 n = n.getNextExternalNode();
4246             }
4247             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4248             n = t3.getNode( "A" );
4249             n = n.getNextExternalNode();
4250             if ( !n.getName().equals( "B" ) ) {
4251                 return false;
4252             }
4253             n = n.getNextExternalNode();
4254             if ( !n.getName().equals( "C" ) ) {
4255                 return false;
4256             }
4257             n = n.getNextExternalNode();
4258             if ( !n.getName().equals( "D" ) ) {
4259                 return false;
4260             }
4261             n = n.getNextExternalNode();
4262             if ( !n.getName().equals( "E" ) ) {
4263                 return false;
4264             }
4265             n = n.getNextExternalNode();
4266             if ( !n.getName().equals( "F" ) ) {
4267                 return false;
4268             }
4269             n = n.getNextExternalNode();
4270             if ( !n.getName().equals( "G" ) ) {
4271                 return false;
4272             }
4273             n = n.getNextExternalNode();
4274             if ( !n.getName().equals( "H" ) ) {
4275                 return false;
4276             }
4277             n = t3.getNode( "B" );
4278             while ( !n.isLastExternalNode() ) {
4279                 n = n.getNextExternalNode();
4280             }
4281             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4282             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4283                 final PhylogenyNode node = iter.next();
4284             }
4285             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4286             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4287                 final PhylogenyNode node = iter.next();
4288             }
4289             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4290             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4291             if ( !iter.next().getName().equals( "A" ) ) {
4292                 return false;
4293             }
4294             if ( !iter.next().getName().equals( "B" ) ) {
4295                 return false;
4296             }
4297             if ( !iter.next().getName().equals( "C" ) ) {
4298                 return false;
4299             }
4300             if ( !iter.next().getName().equals( "D" ) ) {
4301                 return false;
4302             }
4303             if ( !iter.next().getName().equals( "E" ) ) {
4304                 return false;
4305             }
4306             if ( !iter.next().getName().equals( "F" ) ) {
4307                 return false;
4308             }
4309             if ( iter.hasNext() ) {
4310                 return false;
4311             }
4312         }
4313         catch ( final Exception e ) {
4314             e.printStackTrace( System.out );
4315             return false;
4316         }
4317         return true;
4318     }
4319
4320     private static boolean testExtractSNFromNodeName() {
4321         try {
4322             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4323                 return false;
4324             }
4325             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4326                 return false;
4327             }
4328             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4329                 return false;
4330             }
4331             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4332                     .equals( "Mus musculus musculus" ) ) {
4333                 return false;
4334             }
4335             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4336                     .equals( "Mus musculus musculus" ) ) {
4337                 return false;
4338             }
4339             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4340                     .equals( "Mus musculus musculus" ) ) {
4341                 return false;
4342             }
4343             if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4344                     .equals( "Mus musculus musculus" ) ) {
4345                 return false;
4346             }
4347             if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4348                 return false;
4349             }
4350             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4351                     .equals( "Mus musculus musculus" ) ) {
4352                 return false;
4353             }
4354             if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4355                     .equals( "Mus musculus musculus" ) ) {
4356                 return false;
4357             }
4358             if ( ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
4359                 return false;
4360             }
4361             if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
4362                 return false;
4363             }
4364             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
4365                 return false;
4366             }
4367             if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
4368                 return false;
4369             }
4370             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
4371                     .equals( "Mus musculus musculus" ) ) {
4372                 return false;
4373             }
4374             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
4375                 return false;
4376             }
4377             if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
4378                 return false;
4379             }
4380             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
4381                 return false;
4382             }
4383             if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
4384                 return false;
4385             }
4386             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
4387                 return false;
4388             }
4389             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
4390                 return false;
4391             }
4392             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
4393                 return false;
4394             }
4395             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
4396                 return false;
4397             }
4398             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
4399                     .equals( "Mus musculus" ) ) {
4400                 return false;
4401             }
4402             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
4403                     .equals( "Mus musculus" ) ) {
4404                 return false;
4405             }
4406             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4407                 return false;
4408             }
4409             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4410                     .equals( "Mus musculus musculus" ) ) {
4411                 return false;
4412             }
4413             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4414                     .equals( "Mus musculus musculus" ) ) {
4415                 return false;
4416             }
4417             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
4418                     .equals( "Mus musculus musculus" ) ) {
4419                 return false;
4420             }
4421             if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4422                 return false;
4423             }
4424             if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
4425                     .equals( "Pilostyles mexicana" ) ) {
4426                 return false;
4427             }
4428             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
4429                     .equals( "Escherichia coli strain K12/DH10B" ) ) {
4430                 return false;
4431             }
4432             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
4433                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4434                 return false;
4435             }
4436             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
4437                     .equals( "Escherichia coli str. K12/DH10B" ) ) {
4438                 return false;
4439             }
4440             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
4441                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4442                 return false;
4443             }
4444             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
4445                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4446                 return false;
4447             }
4448             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
4449                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4450                 return false;
4451             }
4452             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
4453                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4454                 return false;
4455             }
4456             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
4457                     .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4458                 return false;
4459             }
4460             if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
4461                     .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
4462                 return false;
4463             }
4464             if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
4465                     .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
4466                 return false;
4467             }
4468             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
4469                     .equals( "Escherichia coli (strain K12)" ) ) {
4470                 return false;
4471             }
4472             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
4473                     .equals( "Escherichia coli (strain K12)" ) ) {
4474                 return false;
4475             }
4476             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
4477                     .equals( "Escherichia coli (str. K12)" ) ) {
4478                 return false;
4479             }
4480             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
4481                     .equals( "Escherichia coli (str. K12)" ) ) {
4482                 return false;
4483             }
4484             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
4485                     .equals( "Escherichia coli (str. K12)" ) ) {
4486                 return false;
4487             }
4488             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
4489                     .equals( "Escherichia coli (var. K12)" ) ) {
4490                 return false;
4491             }
4492             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K-12 substr. MG1655star" )
4493                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4494                 return false;
4495             }
4496             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star" )
4497                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4498                 return false;
4499             }
4500             if ( !ParserUtils
4501                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star" )
4502                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4503                 return false;
4504             }
4505             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
4506                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4507                 return false;
4508             }
4509             if ( !ParserUtils
4510                     .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
4511                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4512                 return false;
4513             }
4514             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4515                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4516                 return false;
4517             }
4518             if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4519                     .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4520                 return false;
4521             }
4522             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
4523                 return false;
4524             }
4525             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
4526                 return false;
4527             }
4528             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
4529                 return false;
4530             }
4531             if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
4532                     .equals( "Macrocera sp." ) ) {
4533                 return false;
4534             }
4535             if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
4536                 return false;
4537             }
4538             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
4539                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4540                 return false;
4541             }
4542             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
4543                     .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4544                 return false;
4545             }
4546             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
4547                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4548                 return false;
4549             }
4550             if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
4551                     .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4552                 return false;
4553             }
4554         }
4555         catch ( final Exception e ) {
4556             e.printStackTrace( System.out );
4557             return false;
4558         }
4559         return true;
4560     }
4561
4562     private static boolean testExtractTaxonomyDataFromNodeName() {
4563         try {
4564             PhylogenyNode n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN" );
4565             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4566                 return false;
4567             }
4568             n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN~1-2" );
4569             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4570                 return false;
4571             }
4572             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN" );
4573             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4574                 return false;
4575             }
4576             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN|" );
4577             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4578                 return false;
4579             }
4580             n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN~12" );
4581             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4582                 return false;
4583             }
4584             n = new PhylogenyNode( "HNRPR_HUMAN" );
4585             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4586                 return false;
4587             }
4588             n = new PhylogenyNode( "HNRPR_HUMAN_X" );
4589             if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4590                 return false;
4591             }
4592         }
4593         catch ( final Exception e ) {
4594             e.printStackTrace( System.out );
4595             return false;
4596         }
4597         return true;
4598     }
4599
4600     private static boolean testExtractTaxonomyCodeFromNodeName() {
4601         try {
4602             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4603                 return false;
4604             }
4605             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4606                     .equals( "SOYBN" ) ) {
4607                 return false;
4608             }
4609             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4610                     .equals( "ARATH" ) ) {
4611                 return false;
4612             }
4613             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4614                     .equals( "ARATH" ) ) {
4615                 return false;
4616             }
4617             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4618                 return false;
4619             }
4620             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4621                 return false;
4622             }
4623             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4624                 return false;
4625             }
4626             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4627                     .equals( "SOYBN" ) ) {
4628                 return false;
4629             }
4630             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4631                     .equals( "SOYBN" ) ) {
4632                 return false;
4633             }
4634             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4635                     .equals( "SOYBN" ) ) {
4636                 return false;
4637             }
4638             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4639                     .equals( "SOYBN" ) ) {
4640                 return false;
4641             }
4642             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4643                     .equals( "SOYBN" ) ) {
4644                 return false;
4645             }
4646             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4647                     .equals( "SOYBN" ) ) {
4648                 return false;
4649             }
4650             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4651                     .equals( "SOYBN" ) ) {
4652                 return false;
4653             }
4654             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
4655                     .equals( "SOYBN" ) ) {
4656                 return false;
4657             }
4658             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
4659                 return false;
4660             }
4661             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
4662                     .equals( "SOYBN" ) ) {
4663                 return false;
4664             }
4665             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
4666                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
4667                 return false;
4668             }
4669             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
4670                     .equals( "9YX45" ) ) {
4671                 return false;
4672             }
4673             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
4674                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4675                                                                .equals( "MOUSE" ) ) {
4676                 return false;
4677             }
4678             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
4679                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4680                                                                .equals( "MOUSE" ) ) {
4681                 return false;
4682             }
4683             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
4684                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4685                                                                .equals( "MOUSE" ) ) {
4686                 return false;
4687             }
4688             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
4689                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4690                 return false;
4691             }
4692             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
4693                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4694                 return false;
4695             }
4696             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4697                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4698                 return false;
4699             }
4700             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4701                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4702                 return false;
4703             }
4704             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
4705                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4706                 return false;
4707             }
4708             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
4709                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4710                 return false;
4711             }
4712             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
4713                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4714                 return false;
4715             }
4716             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4717                     .equals( "RAT" ) ) {
4718                 return false;
4719             }
4720             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4721                     .equals( "PIG" ) ) {
4722                 return false;
4723             }
4724             if ( !ParserUtils
4725                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4726                     .equals( "MOUSE" ) ) {
4727                 return false;
4728             }
4729             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4730                     .equals( "MOUSE" ) ) {
4731                 return false;
4732             }
4733             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4734                 return false;
4735             }
4736         }
4737         catch ( final Exception e ) {
4738             e.printStackTrace( System.out );
4739             return false;
4740         }
4741         return true;
4742     }
4743
4744     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
4745         try {
4746             PhylogenyNode n = new PhylogenyNode();
4747             n.setName( "tr|B3RJ64" );
4748             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4749                 return false;
4750             }
4751             n.setName( "tr.B3RJ64" );
4752             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4753                 return false;
4754             }
4755             n.setName( "tr=B3RJ64" );
4756             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4757                 return false;
4758             }
4759             n.setName( "tr-B3RJ64" );
4760             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4761                 return false;
4762             }
4763             n.setName( "tr/B3RJ64" );
4764             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4765                 return false;
4766             }
4767             n.setName( "tr\\B3RJ64" );
4768             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4769                 return false;
4770             }
4771             n.setName( "tr_B3RJ64" );
4772             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4773                 return false;
4774             }
4775             n.setName( " tr|B3RJ64 " );
4776             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4777                 return false;
4778             }
4779             n.setName( "-tr|B3RJ64-" );
4780             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4781                 return false;
4782             }
4783             n.setName( "-tr=B3RJ64-" );
4784             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4785                 return false;
4786             }
4787             n.setName( "_tr=B3RJ64_" );
4788             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4789                 return false;
4790             }
4791             n.setName( " tr_tr|B3RJ64_sp|123 " );
4792             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4793                 return false;
4794             }
4795             n.setName( "B3RJ64" );
4796             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4797                 return false;
4798             }
4799             n.setName( "sp|B3RJ64" );
4800             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4801                 return false;
4802             }
4803             n.setName( "sp|B3RJ64C" );
4804             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4805                 return false;
4806             }
4807             n.setName( "sp B3RJ64" );
4808             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4809                 return false;
4810             }
4811             n.setName( "sp|B3RJ6X" );
4812             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4813                 return false;
4814             }
4815             n.setName( "sp|B3RJ6" );
4816             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4817                 return false;
4818             }
4819             n.setName( "K1PYK7_CRAGI" );
4820             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4821                 return false;
4822             }
4823             n.setName( "K1PYK7_PEA" );
4824             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
4825                 return false;
4826             }
4827             n.setName( "K1PYK7_RAT" );
4828             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
4829                 return false;
4830             }
4831             n.setName( "K1PYK7_PIG" );
4832             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4833                 return false;
4834             }
4835             n.setName( "~K1PYK7_PIG~" );
4836             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4837                 return false;
4838             }
4839             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
4840             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4841                 return false;
4842             }
4843             n.setName( "K1PYKX_CRAGI" );
4844             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4845                 return false;
4846             }
4847             n.setName( "XXXXX_CRAGI" );
4848             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
4849                 return false;
4850             }
4851             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
4852             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
4853                 return false;
4854             }
4855             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
4856             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4857                 return false;
4858             }
4859             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
4860             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
4861                 return false;
4862             }
4863             n = new PhylogenyNode();
4864             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
4865             seq.setSymbol( "K1PYK7_CRAGI" );
4866             n.getNodeData().addSequence( seq );
4867             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4868                 return false;
4869             }
4870             seq.setSymbol( "tr|B3RJ64" );
4871             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4872                 return false;
4873             }
4874             n = new PhylogenyNode();
4875             seq = new org.forester.phylogeny.data.Sequence();
4876             seq.setName( "K1PYK7_CRAGI" );
4877             n.getNodeData().addSequence( seq );
4878             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4879                 return false;
4880             }
4881             seq.setName( "tr|B3RJ64" );
4882             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4883                 return false;
4884             }
4885             n = new PhylogenyNode();
4886             seq = new org.forester.phylogeny.data.Sequence();
4887             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4888             n.getNodeData().addSequence( seq );
4889             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
4890                 return false;
4891             }
4892             n = new PhylogenyNode();
4893             seq = new org.forester.phylogeny.data.Sequence();
4894             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4895             n.getNodeData().addSequence( seq );
4896             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4897                 return false;
4898             }
4899             //
4900             n = new PhylogenyNode();
4901             n.setName( "ACP19736" );
4902             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4903                 return false;
4904             }
4905             n = new PhylogenyNode();
4906             n.setName( "|ACP19736|" );
4907             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4908                 return false;
4909             }
4910         }
4911         catch ( final Exception e ) {
4912             e.printStackTrace( System.out );
4913             return false;
4914         }
4915         return true;
4916     }
4917
4918     private static boolean testFastaParser() {
4919         try {
4920             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
4921                 return false;
4922             }
4923             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
4924                 return false;
4925             }
4926             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
4927             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
4928                 return false;
4929             }
4930             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
4931                 return false;
4932             }
4933             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
4934                 return false;
4935             }
4936             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPROWXERR" ) ) {
4937                 return false;
4938             }
4939             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
4940                 return false;
4941             }
4942             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
4943                 return false;
4944             }
4945         }
4946         catch ( final Exception e ) {
4947             e.printStackTrace();
4948             return false;
4949         }
4950         return true;
4951     }
4952
4953     private static boolean testGenbankAccessorParsing() {
4954         //The format for GenBank Accession numbers are:
4955         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
4956         //Protein:    3 letters + 5 numerals
4957         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
4958         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
4959             return false;
4960         }
4961         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
4962             return false;
4963         }
4964         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
4965             return false;
4966         }
4967         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
4968             return false;
4969         }
4970         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
4971             return false;
4972         }
4973         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
4974             return false;
4975         }
4976         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
4977             return false;
4978         }
4979         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
4980             return false;
4981         }
4982         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
4983             return false;
4984         }
4985         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
4986             return false;
4987         }
4988         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
4989             return false;
4990         }
4991         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
4992             return false;
4993         }
4994         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
4995             return false;
4996         }
4997         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
4998             return false;
4999         }
5000         return true;
5001     }
5002
5003     private static boolean testGeneralMsaParser() {
5004         try {
5005             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
5006             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
5007             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
5008             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
5009             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
5010             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
5011             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
5012             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
5013             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5014                 return false;
5015             }
5016             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5017                 return false;
5018             }
5019             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5020                 return false;
5021             }
5022             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5023                 return false;
5024             }
5025             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5026                 return false;
5027             }
5028             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5029                 return false;
5030             }
5031             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5032                 return false;
5033             }
5034             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5035                 return false;
5036             }
5037             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5038                 return false;
5039             }
5040             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5041                 return false;
5042             }
5043             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5044                 return false;
5045             }
5046             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5047                 return false;
5048             }
5049             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
5050             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5051                 return false;
5052             }
5053             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5054                 return false;
5055             }
5056             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5057                 return false;
5058             }
5059             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
5060             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
5061                 return false;
5062             }
5063             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
5064                 return false;
5065             }
5066             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
5067                 return false;
5068             }
5069             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
5070             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5071                 return false;
5072             }
5073             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5074                 return false;
5075             }
5076             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5077                 return false;
5078             }
5079         }
5080         catch ( final Exception e ) {
5081             e.printStackTrace();
5082             return false;
5083         }
5084         return true;
5085     }
5086
5087     private static boolean testGeneralTable() {
5088         try {
5089             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
5090             t0.setValue( 3, 2, "23" );
5091             t0.setValue( 10, 1, "error" );
5092             t0.setValue( 10, 1, "110" );
5093             t0.setValue( 9, 1, "19" );
5094             t0.setValue( 1, 10, "101" );
5095             t0.setValue( 10, 10, "1010" );
5096             t0.setValue( 100, 10, "10100" );
5097             t0.setValue( 0, 0, "00" );
5098             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
5099                 return false;
5100             }
5101             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
5102                 return false;
5103             }
5104             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
5105                 return false;
5106             }
5107             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
5108                 return false;
5109             }
5110             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
5111                 return false;
5112             }
5113             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
5114                 return false;
5115             }
5116             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
5117                 return false;
5118             }
5119             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
5120                 return false;
5121             }
5122             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
5123                 return false;
5124             }
5125             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
5126             t1.setValue( "3", "2", "23" );
5127             t1.setValue( "10", "1", "error" );
5128             t1.setValue( "10", "1", "110" );
5129             t1.setValue( "9", "1", "19" );
5130             t1.setValue( "1", "10", "101" );
5131             t1.setValue( "10", "10", "1010" );
5132             t1.setValue( "100", "10", "10100" );
5133             t1.setValue( "0", "0", "00" );
5134             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
5135             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
5136                 return false;
5137             }
5138             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
5139                 return false;
5140             }
5141             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
5142                 return false;
5143             }
5144             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
5145                 return false;
5146             }
5147             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
5148                 return false;
5149             }
5150             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
5151                 return false;
5152             }
5153             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
5154                 return false;
5155             }
5156             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
5157                 return false;
5158             }
5159             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
5160                 return false;
5161             }
5162             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
5163                 return false;
5164             }
5165         }
5166         catch ( final Exception e ) {
5167             e.printStackTrace( System.out );
5168             return false;
5169         }
5170         return true;
5171     }
5172
5173     private static boolean testGetDistance() {
5174         try {
5175             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5176             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",
5177                                                  new NHXParser() )[ 0 ];
5178             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
5179                 return false;
5180             }
5181             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
5182                 return false;
5183             }
5184             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5185                 return false;
5186             }
5187             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5188                 return false;
5189             }
5190             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5191                 return false;
5192             }
5193             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5194                 return false;
5195             }
5196             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5197                 return false;
5198             }
5199             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5200                 return false;
5201             }
5202             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5203                 return false;
5204             }
5205             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5206                 return false;
5207             }
5208             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5209                 return false;
5210             }
5211             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5212                 return false;
5213             }
5214             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5215                 return false;
5216             }
5217             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5218                 return false;
5219             }
5220             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5221                 return false;
5222             }
5223             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5224                 return false;
5225             }
5226             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5227                 return false;
5228             }
5229             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5230                 return false;
5231             }
5232             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5233                 return false;
5234             }
5235             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5236                 return false;
5237             }
5238             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5239                 return false;
5240             }
5241             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5242                 return false;
5243             }
5244             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5245                 return false;
5246             }
5247             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5248                 return false;
5249             }
5250             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5251                 return false;
5252             }
5253             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5254                 return false;
5255             }
5256             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5257                 return false;
5258             }
5259             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5260                 return false;
5261             }
5262             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5263                 return false;
5264             }
5265             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5266                 return false;
5267             }
5268             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5269                 return false;
5270             }
5271             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",
5272                                                  new NHXParser() )[ 0 ];
5273             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5274                 return false;
5275             }
5276             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5277                 return false;
5278             }
5279             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5280                 return false;
5281             }
5282             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5283                 return false;
5284             }
5285             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5286                 return false;
5287             }
5288             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5289                 return false;
5290             }
5291             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5292                 return false;
5293             }
5294             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5295                 return false;
5296             }
5297             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5298                 return false;
5299             }
5300             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5301                 return false;
5302             }
5303             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5304                 return false;
5305             }
5306         }
5307         catch ( final Exception e ) {
5308             e.printStackTrace( System.out );
5309             return false;
5310         }
5311         return true;
5312     }
5313
5314     private static boolean testGetLCA() {
5315         try {
5316             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5317             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5318                                                  new NHXParser() )[ 0 ];
5319             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5320             if ( !A.getName().equals( "A" ) ) {
5321                 return false;
5322             }
5323             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5324             if ( !gh.getName().equals( "gh" ) ) {
5325                 return false;
5326             }
5327             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5328             if ( !ab.getName().equals( "ab" ) ) {
5329                 return false;
5330             }
5331             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5332             if ( !ab2.getName().equals( "ab" ) ) {
5333                 return false;
5334             }
5335             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5336             if ( !gh2.getName().equals( "gh" ) ) {
5337                 return false;
5338             }
5339             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5340             if ( !gh3.getName().equals( "gh" ) ) {
5341                 return false;
5342             }
5343             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5344             if ( !abc.getName().equals( "abc" ) ) {
5345                 return false;
5346             }
5347             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5348             if ( !abc2.getName().equals( "abc" ) ) {
5349                 return false;
5350             }
5351             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5352             if ( !abcd.getName().equals( "abcd" ) ) {
5353                 return false;
5354             }
5355             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5356             if ( !abcd2.getName().equals( "abcd" ) ) {
5357                 return false;
5358             }
5359             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5360             if ( !abcdef.getName().equals( "abcdef" ) ) {
5361                 return false;
5362             }
5363             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5364             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5365                 return false;
5366             }
5367             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5368             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5369                 return false;
5370             }
5371             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5372             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5373                 return false;
5374             }
5375             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
5376             if ( !abcde.getName().equals( "abcde" ) ) {
5377                 return false;
5378             }
5379             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
5380             if ( !abcde2.getName().equals( "abcde" ) ) {
5381                 return false;
5382             }
5383             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
5384             if ( !r.getName().equals( "abcdefgh" ) ) {
5385                 return false;
5386             }
5387             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5388             if ( !r2.getName().equals( "abcdefgh" ) ) {
5389                 return false;
5390             }
5391             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5392             if ( !r3.getName().equals( "abcdefgh" ) ) {
5393                 return false;
5394             }
5395             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5396             if ( !abcde3.getName().equals( "abcde" ) ) {
5397                 return false;
5398             }
5399             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5400             if ( !abcde4.getName().equals( "abcde" ) ) {
5401                 return false;
5402             }
5403             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5404             if ( !ab3.getName().equals( "ab" ) ) {
5405                 return false;
5406             }
5407             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5408             if ( !ab4.getName().equals( "ab" ) ) {
5409                 return false;
5410             }
5411             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5412             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5413             if ( !cd.getName().equals( "cd" ) ) {
5414                 return false;
5415             }
5416             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5417             if ( !cd2.getName().equals( "cd" ) ) {
5418                 return false;
5419             }
5420             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5421             if ( !cde.getName().equals( "cde" ) ) {
5422                 return false;
5423             }
5424             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5425             if ( !cde2.getName().equals( "cde" ) ) {
5426                 return false;
5427             }
5428             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5429             if ( !cdef.getName().equals( "cdef" ) ) {
5430                 return false;
5431             }
5432             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5433             if ( !cdef2.getName().equals( "cdef" ) ) {
5434                 return false;
5435             }
5436             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5437             if ( !cdef3.getName().equals( "cdef" ) ) {
5438                 return false;
5439             }
5440             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5441             if ( !rt.getName().equals( "r" ) ) {
5442                 return false;
5443             }
5444             final Phylogeny p3 = factory
5445                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5446                              new NHXParser() )[ 0 ];
5447             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5448             if ( !bc_3.getName().equals( "bc" ) ) {
5449                 return false;
5450             }
5451             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5452             if ( !ac_3.getName().equals( "abc" ) ) {
5453                 return false;
5454             }
5455             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5456             if ( !ad_3.getName().equals( "abcde" ) ) {
5457                 return false;
5458             }
5459             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5460             if ( !af_3.getName().equals( "abcdef" ) ) {
5461                 return false;
5462             }
5463             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5464             if ( !ag_3.getName().equals( "" ) ) {
5465                 return false;
5466             }
5467             if ( !ag_3.isRoot() ) {
5468                 return false;
5469             }
5470             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5471             if ( !al_3.getName().equals( "" ) ) {
5472                 return false;
5473             }
5474             if ( !al_3.isRoot() ) {
5475                 return false;
5476             }
5477             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5478             if ( !kl_3.getName().equals( "" ) ) {
5479                 return false;
5480             }
5481             if ( !kl_3.isRoot() ) {
5482                 return false;
5483             }
5484             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5485             if ( !fl_3.getName().equals( "" ) ) {
5486                 return false;
5487             }
5488             if ( !fl_3.isRoot() ) {
5489                 return false;
5490             }
5491             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5492             if ( !gk_3.getName().equals( "ghijk" ) ) {
5493                 return false;
5494             }
5495             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5496             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5497             if ( !r_4.getName().equals( "r" ) ) {
5498                 return false;
5499             }
5500             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5501             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5502             if ( !r_5.getName().equals( "root" ) ) {
5503                 return false;
5504             }
5505             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5506             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5507             if ( !r_6.getName().equals( "rot" ) ) {
5508                 return false;
5509             }
5510             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5511             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5512             if ( !r_7.getName().equals( "rott" ) ) {
5513                 return false;
5514             }
5515         }
5516         catch ( final Exception e ) {
5517             e.printStackTrace( System.out );
5518             return false;
5519         }
5520         return true;
5521     }
5522
5523     private static boolean testGetLCA2() {
5524         try {
5525             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5526             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5527             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5528             PhylogenyMethods.preOrderReId( p_a );
5529             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5530                                                                                               p_a.getNode( "a" ) );
5531             if ( !p_a_1.getName().equals( "a" ) ) {
5532                 return false;
5533             }
5534             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5535             PhylogenyMethods.preOrderReId( p_b );
5536             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5537                                                                                               p_b.getNode( "a" ) );
5538             if ( !p_b_1.getName().equals( "b" ) ) {
5539                 return false;
5540             }
5541             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5542                                                                                               p_b.getNode( "b" ) );
5543             if ( !p_b_2.getName().equals( "b" ) ) {
5544                 return false;
5545             }
5546             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5547             PhylogenyMethods.preOrderReId( p_c );
5548             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5549                                                                                               p_c.getNode( "a" ) );
5550             if ( !p_c_1.getName().equals( "b" ) ) {
5551                 return false;
5552             }
5553             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5554                                                                                               p_c.getNode( "c" ) );
5555             if ( !p_c_2.getName().equals( "c" ) ) {
5556                 System.out.println( p_c_2.getName() );
5557                 System.exit( -1 );
5558                 return false;
5559             }
5560             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5561                                                                                               p_c.getNode( "b" ) );
5562             if ( !p_c_3.getName().equals( "b" ) ) {
5563                 return false;
5564             }
5565             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5566                                                                                               p_c.getNode( "a" ) );
5567             if ( !p_c_4.getName().equals( "c" ) ) {
5568                 return false;
5569             }
5570             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5571                                                  new NHXParser() )[ 0 ];
5572             PhylogenyMethods.preOrderReId( p1 );
5573             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5574                                                                                           p1.getNode( "A" ) );
5575             if ( !A.getName().equals( "A" ) ) {
5576                 return false;
5577             }
5578             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5579                                                                                            p1.getNode( "gh" ) );
5580             if ( !gh.getName().equals( "gh" ) ) {
5581                 return false;
5582             }
5583             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5584                                                                                            p1.getNode( "B" ) );
5585             if ( !ab.getName().equals( "ab" ) ) {
5586                 return false;
5587             }
5588             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5589                                                                                             p1.getNode( "A" ) );
5590             if ( !ab2.getName().equals( "ab" ) ) {
5591                 return false;
5592             }
5593             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5594                                                                                             p1.getNode( "G" ) );
5595             if ( !gh2.getName().equals( "gh" ) ) {
5596                 return false;
5597             }
5598             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5599                                                                                             p1.getNode( "H" ) );
5600             if ( !gh3.getName().equals( "gh" ) ) {
5601                 return false;
5602             }
5603             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5604                                                                                             p1.getNode( "A" ) );
5605             if ( !abc.getName().equals( "abc" ) ) {
5606                 return false;
5607             }
5608             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5609                                                                                              p1.getNode( "C" ) );
5610             if ( !abc2.getName().equals( "abc" ) ) {
5611                 return false;
5612             }
5613             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5614                                                                                              p1.getNode( "D" ) );
5615             if ( !abcd.getName().equals( "abcd" ) ) {
5616                 return false;
5617             }
5618             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5619                                                                                               p1.getNode( "A" ) );
5620             if ( !abcd2.getName().equals( "abcd" ) ) {
5621                 return false;
5622             }
5623             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5624                                                                                                p1.getNode( "F" ) );
5625             if ( !abcdef.getName().equals( "abcdef" ) ) {
5626                 return false;
5627             }
5628             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5629                                                                                                 p1.getNode( "A" ) );
5630             if ( !abcdef2.getName().equals( "abcdef" ) ) {
5631                 return false;
5632             }
5633             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5634                                                                                                 p1.getNode( "F" ) );
5635             if ( !abcdef3.getName().equals( "abcdef" ) ) {
5636                 return false;
5637             }
5638             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5639                                                                                                 p1.getNode( "ab" ) );
5640             if ( !abcdef4.getName().equals( "abcdef" ) ) {
5641                 return false;
5642             }
5643             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5644                                                                                               p1.getNode( "E" ) );
5645             if ( !abcde.getName().equals( "abcde" ) ) {
5646                 return false;
5647             }
5648             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5649                                                                                                p1.getNode( "A" ) );
5650             if ( !abcde2.getName().equals( "abcde" ) ) {
5651                 return false;
5652             }
5653             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
5654                                                                                           p1.getNode( "abcdefgh" ) );
5655             if ( !r.getName().equals( "abcdefgh" ) ) {
5656                 return false;
5657             }
5658             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5659                                                                                            p1.getNode( "H" ) );
5660             if ( !r2.getName().equals( "abcdefgh" ) ) {
5661                 return false;
5662             }
5663             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5664                                                                                            p1.getNode( "A" ) );
5665             if ( !r3.getName().equals( "abcdefgh" ) ) {
5666                 return false;
5667             }
5668             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5669                                                                                                p1.getNode( "abcde" ) );
5670             if ( !abcde3.getName().equals( "abcde" ) ) {
5671                 return false;
5672             }
5673             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
5674                                                                                                p1.getNode( "E" ) );
5675             if ( !abcde4.getName().equals( "abcde" ) ) {
5676                 return false;
5677             }
5678             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5679                                                                                             p1.getNode( "B" ) );
5680             if ( !ab3.getName().equals( "ab" ) ) {
5681                 return false;
5682             }
5683             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5684                                                                                             p1.getNode( "ab" ) );
5685             if ( !ab4.getName().equals( "ab" ) ) {
5686                 return false;
5687             }
5688             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5689             PhylogenyMethods.preOrderReId( p2 );
5690             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5691                                                                                            p2.getNode( "d" ) );
5692             if ( !cd.getName().equals( "cd" ) ) {
5693                 return false;
5694             }
5695             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5696                                                                                             p2.getNode( "c" ) );
5697             if ( !cd2.getName().equals( "cd" ) ) {
5698                 return false;
5699             }
5700             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5701                                                                                             p2.getNode( "e" ) );
5702             if ( !cde.getName().equals( "cde" ) ) {
5703                 return false;
5704             }
5705             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
5706                                                                                              p2.getNode( "c" ) );
5707             if ( !cde2.getName().equals( "cde" ) ) {
5708                 return false;
5709             }
5710             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5711                                                                                              p2.getNode( "f" ) );
5712             if ( !cdef.getName().equals( "cdef" ) ) {
5713                 return false;
5714             }
5715             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5716                                                                                               p2.getNode( "f" ) );
5717             if ( !cdef2.getName().equals( "cdef" ) ) {
5718                 return false;
5719             }
5720             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
5721                                                                                               p2.getNode( "d" ) );
5722             if ( !cdef3.getName().equals( "cdef" ) ) {
5723                 return false;
5724             }
5725             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5726                                                                                            p2.getNode( "a" ) );
5727             if ( !rt.getName().equals( "r" ) ) {
5728                 return false;
5729             }
5730             final Phylogeny p3 = factory
5731                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5732                              new NHXParser() )[ 0 ];
5733             PhylogenyMethods.preOrderReId( p3 );
5734             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
5735                                                                                              p3.getNode( "c" ) );
5736             if ( !bc_3.getName().equals( "bc" ) ) {
5737                 return false;
5738             }
5739             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5740                                                                                              p3.getNode( "c" ) );
5741             if ( !ac_3.getName().equals( "abc" ) ) {
5742                 return false;
5743             }
5744             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5745                                                                                              p3.getNode( "d" ) );
5746             if ( !ad_3.getName().equals( "abcde" ) ) {
5747                 return false;
5748             }
5749             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5750                                                                                              p3.getNode( "f" ) );
5751             if ( !af_3.getName().equals( "abcdef" ) ) {
5752                 return false;
5753             }
5754             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5755                                                                                              p3.getNode( "g" ) );
5756             if ( !ag_3.getName().equals( "" ) ) {
5757                 return false;
5758             }
5759             if ( !ag_3.isRoot() ) {
5760                 return false;
5761             }
5762             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5763                                                                                              p3.getNode( "l" ) );
5764             if ( !al_3.getName().equals( "" ) ) {
5765                 return false;
5766             }
5767             if ( !al_3.isRoot() ) {
5768                 return false;
5769             }
5770             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
5771                                                                                              p3.getNode( "l" ) );
5772             if ( !kl_3.getName().equals( "" ) ) {
5773                 return false;
5774             }
5775             if ( !kl_3.isRoot() ) {
5776                 return false;
5777             }
5778             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
5779                                                                                              p3.getNode( "l" ) );
5780             if ( !fl_3.getName().equals( "" ) ) {
5781                 return false;
5782             }
5783             if ( !fl_3.isRoot() ) {
5784                 return false;
5785             }
5786             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
5787                                                                                              p3.getNode( "k" ) );
5788             if ( !gk_3.getName().equals( "ghijk" ) ) {
5789                 return false;
5790             }
5791             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5792             PhylogenyMethods.preOrderReId( p4 );
5793             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
5794                                                                                             p4.getNode( "c" ) );
5795             if ( !r_4.getName().equals( "r" ) ) {
5796                 return false;
5797             }
5798             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5799             PhylogenyMethods.preOrderReId( p5 );
5800             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
5801                                                                                             p5.getNode( "c" ) );
5802             if ( !r_5.getName().equals( "root" ) ) {
5803                 return false;
5804             }
5805             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5806             PhylogenyMethods.preOrderReId( p6 );
5807             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
5808                                                                                             p6.getNode( "a" ) );
5809             if ( !r_6.getName().equals( "rot" ) ) {
5810                 return false;
5811             }
5812             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5813             PhylogenyMethods.preOrderReId( p7 );
5814             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
5815                                                                                             p7.getNode( "e" ) );
5816             if ( !r_7.getName().equals( "rott" ) ) {
5817                 return false;
5818             }
5819             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5820                                                                                              p7.getNode( "a" ) );
5821             if ( !r_71.getName().equals( "rott" ) ) {
5822                 return false;
5823             }
5824             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5825                                                                                              p7.getNode( "rott" ) );
5826             if ( !r_72.getName().equals( "rott" ) ) {
5827                 return false;
5828             }
5829             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5830                                                                                              p7.getNode( "a" ) );
5831             if ( !r_73.getName().equals( "rott" ) ) {
5832                 return false;
5833             }
5834             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5835                                                                                              p7.getNode( "rott" ) );
5836             if ( !r_74.getName().equals( "rott" ) ) {
5837                 return false;
5838             }
5839             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5840                                                                                              p7.getNode( "e" ) );
5841             if ( !r_75.getName().equals( "e" ) ) {
5842                 return false;
5843             }
5844         }
5845         catch ( final Exception e ) {
5846             e.printStackTrace( System.out );
5847             return false;
5848         }
5849         return true;
5850     }
5851
5852     private static boolean testHmmscanOutputParser() {
5853         final String test_dir = Test.PATH_TO_TEST_DATA;
5854         try {
5855             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
5856                                                                                                    + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5857             parser1.parse();
5858             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
5859                                                                                                    + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5860             final List<Protein> proteins = parser2.parse();
5861             if ( parser2.getProteinsEncountered() != 4 ) {
5862                 return false;
5863             }
5864             if ( proteins.size() != 4 ) {
5865                 return false;
5866             }
5867             if ( parser2.getDomainsEncountered() != 69 ) {
5868                 return false;
5869             }
5870             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
5871                 return false;
5872             }
5873             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
5874                 return false;
5875             }
5876             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
5877                 return false;
5878             }
5879             final Protein p1 = proteins.get( 0 );
5880             if ( p1.getNumberOfProteinDomains() != 15 ) {
5881                 return false;
5882             }
5883             if ( p1.getLength() != 850 ) {
5884                 return false;
5885             }
5886             final Protein p2 = proteins.get( 1 );
5887             if ( p2.getNumberOfProteinDomains() != 51 ) {
5888                 return false;
5889             }
5890             if ( p2.getLength() != 1291 ) {
5891                 return false;
5892             }
5893             final Protein p3 = proteins.get( 2 );
5894             if ( p3.getNumberOfProteinDomains() != 2 ) {
5895                 return false;
5896             }
5897             final Protein p4 = proteins.get( 3 );
5898             if ( p4.getNumberOfProteinDomains() != 1 ) {
5899                 return false;
5900             }
5901             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
5902                 return false;
5903             }
5904             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
5905                 return false;
5906             }
5907             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
5908                 return false;
5909             }
5910             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
5911                 return false;
5912             }
5913             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
5914                 return false;
5915             }
5916             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
5917                 return false;
5918             }
5919             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
5920                 return false;
5921             }
5922         }
5923         catch ( final Exception e ) {
5924             e.printStackTrace( System.out );
5925             return false;
5926         }
5927         return true;
5928     }
5929
5930     private static boolean testLastExternalNodeMethods() {
5931         try {
5932             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5933             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
5934             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
5935             final PhylogenyNode n1 = t0.getNode( "A" );
5936             if ( n1.isLastExternalNode() ) {
5937                 return false;
5938             }
5939             final PhylogenyNode n2 = t0.getNode( "B" );
5940             if ( n2.isLastExternalNode() ) {
5941                 return false;
5942             }
5943             final PhylogenyNode n3 = t0.getNode( "C" );
5944             if ( n3.isLastExternalNode() ) {
5945                 return false;
5946             }
5947             final PhylogenyNode n4 = t0.getNode( "D" );
5948             if ( !n4.isLastExternalNode() ) {
5949                 return false;
5950             }
5951         }
5952         catch ( final Exception e ) {
5953             e.printStackTrace( System.out );
5954             return false;
5955         }
5956         return true;
5957     }
5958
5959     private static boolean testLevelOrderIterator() {
5960         try {
5961             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5962             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5963             PhylogenyNodeIterator it0;
5964             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
5965                 it0.next();
5966             }
5967             for( it0.reset(); it0.hasNext(); ) {
5968                 it0.next();
5969             }
5970             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
5971             if ( !it.next().getName().equals( "r" ) ) {
5972                 return false;
5973             }
5974             if ( !it.next().getName().equals( "ab" ) ) {
5975                 return false;
5976             }
5977             if ( !it.next().getName().equals( "cd" ) ) {
5978                 return false;
5979             }
5980             if ( !it.next().getName().equals( "A" ) ) {
5981                 return false;
5982             }
5983             if ( !it.next().getName().equals( "B" ) ) {
5984                 return false;
5985             }
5986             if ( !it.next().getName().equals( "C" ) ) {
5987                 return false;
5988             }
5989             if ( !it.next().getName().equals( "D" ) ) {
5990                 return false;
5991             }
5992             if ( it.hasNext() ) {
5993                 return false;
5994             }
5995             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",
5996                                                  new NHXParser() )[ 0 ];
5997             PhylogenyNodeIterator it2;
5998             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
5999                 it2.next();
6000             }
6001             for( it2.reset(); it2.hasNext(); ) {
6002                 it2.next();
6003             }
6004             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
6005             if ( !it3.next().getName().equals( "r" ) ) {
6006                 return false;
6007             }
6008             if ( !it3.next().getName().equals( "abc" ) ) {
6009                 return false;
6010             }
6011             if ( !it3.next().getName().equals( "defg" ) ) {
6012                 return false;
6013             }
6014             if ( !it3.next().getName().equals( "A" ) ) {
6015                 return false;
6016             }
6017             if ( !it3.next().getName().equals( "B" ) ) {
6018                 return false;
6019             }
6020             if ( !it3.next().getName().equals( "C" ) ) {
6021                 return false;
6022             }
6023             if ( !it3.next().getName().equals( "D" ) ) {
6024                 return false;
6025             }
6026             if ( !it3.next().getName().equals( "E" ) ) {
6027                 return false;
6028             }
6029             if ( !it3.next().getName().equals( "F" ) ) {
6030                 return false;
6031             }
6032             if ( !it3.next().getName().equals( "G" ) ) {
6033                 return false;
6034             }
6035             if ( !it3.next().getName().equals( "1" ) ) {
6036                 return false;
6037             }
6038             if ( !it3.next().getName().equals( "2" ) ) {
6039                 return false;
6040             }
6041             if ( !it3.next().getName().equals( "3" ) ) {
6042                 return false;
6043             }
6044             if ( !it3.next().getName().equals( "4" ) ) {
6045                 return false;
6046             }
6047             if ( !it3.next().getName().equals( "5" ) ) {
6048                 return false;
6049             }
6050             if ( !it3.next().getName().equals( "6" ) ) {
6051                 return false;
6052             }
6053             if ( !it3.next().getName().equals( "f1" ) ) {
6054                 return false;
6055             }
6056             if ( !it3.next().getName().equals( "f2" ) ) {
6057                 return false;
6058             }
6059             if ( !it3.next().getName().equals( "f3" ) ) {
6060                 return false;
6061             }
6062             if ( !it3.next().getName().equals( "a" ) ) {
6063                 return false;
6064             }
6065             if ( !it3.next().getName().equals( "b" ) ) {
6066                 return false;
6067             }
6068             if ( !it3.next().getName().equals( "f21" ) ) {
6069                 return false;
6070             }
6071             if ( !it3.next().getName().equals( "X" ) ) {
6072                 return false;
6073             }
6074             if ( !it3.next().getName().equals( "Y" ) ) {
6075                 return false;
6076             }
6077             if ( !it3.next().getName().equals( "Z" ) ) {
6078                 return false;
6079             }
6080             if ( it3.hasNext() ) {
6081                 return false;
6082             }
6083             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
6084             PhylogenyNodeIterator it4;
6085             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
6086                 it4.next();
6087             }
6088             for( it4.reset(); it4.hasNext(); ) {
6089                 it4.next();
6090             }
6091             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
6092             if ( !it5.next().getName().equals( "r" ) ) {
6093                 return false;
6094             }
6095             if ( !it5.next().getName().equals( "A" ) ) {
6096                 return false;
6097             }
6098             if ( !it5.next().getName().equals( "B" ) ) {
6099                 return false;
6100             }
6101             if ( !it5.next().getName().equals( "C" ) ) {
6102                 return false;
6103             }
6104             if ( !it5.next().getName().equals( "D" ) ) {
6105                 return false;
6106             }
6107             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
6108             PhylogenyNodeIterator it6;
6109             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
6110                 it6.next();
6111             }
6112             for( it6.reset(); it6.hasNext(); ) {
6113                 it6.next();
6114             }
6115             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
6116             if ( !it7.next().getName().equals( "A" ) ) {
6117                 return false;
6118             }
6119             if ( it.hasNext() ) {
6120                 return false;
6121             }
6122         }
6123         catch ( final Exception e ) {
6124             e.printStackTrace( System.out );
6125             return false;
6126         }
6127         return true;
6128     }
6129
6130     private static boolean testMafft( final String path ) {
6131         try {
6132             final List<String> opts = new ArrayList<String>();
6133             opts.add( "--maxiterate" );
6134             opts.add( "1000" );
6135             opts.add( "--localpair" );
6136             opts.add( "--quiet" );
6137             Msa msa = null;
6138             final MsaInferrer mafft = Mafft.createInstance( path );
6139             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
6140             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
6141                 return false;
6142             }
6143             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
6144                 return false;
6145             }
6146         }
6147         catch ( final Exception e ) {
6148             e.printStackTrace( System.out );
6149             return false;
6150         }
6151         return true;
6152     }
6153
6154     private static boolean testMidpointrooting() {
6155         try {
6156             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6157             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
6158             PhylogenyMethods.midpointRoot( t0 );
6159             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
6160                 return false;
6161             }
6162             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
6163                 return false;
6164             }
6165             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
6166                            1 ) ) {
6167                 return false;
6168             }
6169             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",
6170                                                  new NHXParser() )[ 0 ];
6171             if ( !t1.isRooted() ) {
6172                 return false;
6173             }
6174             PhylogenyMethods.midpointRoot( t1 );
6175             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6176                 return false;
6177             }
6178             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6179                 return false;
6180             }
6181             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6182                 return false;
6183             }
6184             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6185                 return false;
6186             }
6187             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6188                 return false;
6189             }
6190             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6191                 return false;
6192             }
6193             t1.reRoot( t1.getNode( "A" ) );
6194             PhylogenyMethods.midpointRoot( t1 );
6195             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6196                 return false;
6197             }
6198             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6199                 return false;
6200             }
6201             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6202                 return false;
6203             }
6204             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6205                 return false;
6206             }
6207             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6208                 System.exit( -1 );
6209                 return false;
6210             }
6211             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6212                 return false;
6213             }
6214         }
6215         catch ( final Exception e ) {
6216             e.printStackTrace( System.out );
6217             return false;
6218         }
6219         return true;
6220     }
6221
6222     private static boolean testMsaQualityMethod() {
6223         try {
6224             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6225             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6226             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6227             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6228             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6229             l.add( s0 );
6230             l.add( s1 );
6231             l.add( s2 );
6232             l.add( s3 );
6233             final Msa msa = BasicMsa.createInstance( l );
6234             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6235                 return false;
6236             }
6237             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6238                 return false;
6239             }
6240             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6241                 return false;
6242             }
6243             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6244                 return false;
6245             }
6246             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6247                 return false;
6248             }
6249             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6250                 return false;
6251             }
6252             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6253                 return false;
6254             }
6255         }
6256         catch ( final Exception e ) {
6257             e.printStackTrace( System.out );
6258             return false;
6259         }
6260         return true;
6261     }
6262
6263     private static boolean testMsaEntropy() {
6264         try {
6265             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAAAAA" );
6266             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "AAAIACC" );
6267             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AAIIIIF" );
6268             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AIIIVVW" );
6269             final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6270             l.add( s0 );
6271             l.add( s1 );
6272             l.add( s2 );
6273             l.add( s3 );
6274             final Msa msa = BasicMsa.createInstance( l );
6275             //TODO need to DO the tests!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6276             //FIXME
6277             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 0 ) );
6278             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 1 ) );
6279             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 2 ) );
6280             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 3 ) );
6281             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 4 ) );
6282             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 5 ) );
6283             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 6 ) );
6284             //            System.out.println();
6285             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 0 ) );
6286             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 1 ) );
6287             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 2 ) );
6288             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 3 ) );
6289             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 4 ) );
6290             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 5 ) );
6291             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 6 ) );
6292             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6293             l2.add( BasicSequence.createAaSequence( "1", "AAAAAAA" ) );
6294             l2.add( BasicSequence.createAaSequence( "2", "AAAIACC" ) );
6295             l2.add( BasicSequence.createAaSequence( "3", "AAIIIIF" ) );
6296             l2.add( BasicSequence.createAaSequence( "4", "AIIIVVW" ) );
6297             l2.add( BasicSequence.createAaSequence( "5", "AAAAAAA" ) );
6298             l2.add( BasicSequence.createAaSequence( "6", "AAAIACC" ) );
6299             l2.add( BasicSequence.createAaSequence( "7", "AAIIIIF" ) );
6300             l2.add( BasicSequence.createAaSequence( "8", "AIIIVVW" ) );
6301             l2.add( BasicSequence.createAaSequence( "9", "AAAAAAA" ) );
6302             l2.add( BasicSequence.createAaSequence( "10", "AAAIACC" ) );
6303             l2.add( BasicSequence.createAaSequence( "11", "AAIIIIF" ) );
6304             l2.add( BasicSequence.createAaSequence( "12", "AIIIVVW" ) );
6305             l2.add( BasicSequence.createAaSequence( "13", "AAIIIIF" ) );
6306             l2.add( BasicSequence.createAaSequence( "14", "AIIIVVW" ) );
6307             l2.add( BasicSequence.createAaSequence( "15", "AAAAAAA" ) );
6308             l2.add( BasicSequence.createAaSequence( "16", "AAAIACC" ) );
6309             l2.add( BasicSequence.createAaSequence( "17", "AAIIIIF" ) );
6310             l2.add( BasicSequence.createAaSequence( "18", "AIIIVVW" ) );
6311             l2.add( BasicSequence.createAaSequence( "19", "AAAAAAA" ) );
6312             l2.add( BasicSequence.createAaSequence( "20", "AAAIACC" ) );
6313             l2.add( BasicSequence.createAaSequence( "21", "AAIIIIF" ) );
6314             l2.add( BasicSequence.createAaSequence( "22", "AIIIVVW" ) );
6315             final Msa msa2 = BasicMsa.createInstance( l2 );
6316             //            System.out.println();
6317             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 0 ) );
6318             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 1 ) );
6319             //            System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 2 ) );
6320         }
6321         catch ( final Exception e ) {
6322             e.printStackTrace( System.out );
6323             return false;
6324         }
6325         return true;
6326     }
6327
6328     private static boolean testDeleteableMsa() {
6329         try {
6330             final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAA" );
6331             final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "BAAA" );
6332             final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "CAAA" );
6333             final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "DAAA" );
6334             final MolecularSequence s4 = BasicSequence.createAaSequence( "e", "EAAA" );
6335             final MolecularSequence s5 = BasicSequence.createAaSequence( "f", "FAAA" );
6336             final List<MolecularSequence> l0 = new ArrayList<MolecularSequence>();
6337             l0.add( s0 );
6338             l0.add( s1 );
6339             l0.add( s2 );
6340             l0.add( s3 );
6341             l0.add( s4 );
6342             l0.add( s5 );
6343             final DeleteableMsa dmsa0 = DeleteableMsa.createInstance( l0 );
6344             dmsa0.deleteRow( "b", false );
6345             if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) {
6346                 return false;
6347             }
6348             dmsa0.deleteRow( "e", false );
6349             dmsa0.deleteRow( "a", false );
6350             dmsa0.deleteRow( "f", false );
6351             if ( dmsa0.getLength() != 4 ) {
6352                 return false;
6353             }
6354             if ( dmsa0.getNumberOfSequences() != 2 ) {
6355                 return false;
6356             }
6357             if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) {
6358                 return false;
6359             }
6360             if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) {
6361                 return false;
6362             }
6363             if ( dmsa0.getResidueAt( 0, 0 ) != 'C' ) {
6364                 return false;
6365             }
6366             if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" ) ) {
6367                 return false;
6368             }
6369             if ( dmsa0.getColumnAt( 0 ).size() != 2 ) {
6370                 return false;
6371             }
6372             dmsa0.deleteRow( "c", false );
6373             dmsa0.deleteRow( "d", false );
6374             if ( dmsa0.getNumberOfSequences() != 0 ) {
6375                 return false;
6376             }
6377             //
6378             final MolecularSequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C--X----" );
6379             final MolecularSequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C-------" );
6380             final MolecularSequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C------Z" );
6381             final MolecularSequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C-------" );
6382             final MolecularSequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C-------" );
6383             final MolecularSequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--Y---" );
6384             final List<MolecularSequence> l1 = new ArrayList<MolecularSequence>();
6385             l1.add( s_0 );
6386             l1.add( s_1 );
6387             l1.add( s_2 );
6388             l1.add( s_3 );
6389             l1.add( s_4 );
6390             l1.add( s_5 );
6391             final DeleteableMsa dmsa1 = DeleteableMsa.createInstance( l1 );
6392             dmsa1.deleteGapOnlyColumns();
6393             dmsa1.deleteRow( "a", false );
6394             dmsa1.deleteRow( "f", false );
6395             dmsa1.deleteRow( "d", false );
6396             dmsa1.deleteGapOnlyColumns();
6397             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C-" ) ) {
6398                 return false;
6399             }
6400             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "CABCZ" ) ) {
6401                 return false;
6402             }
6403             if ( !dmsa1.getSequenceAsString( 2 ).toString().equals( "EAAC-" ) ) {
6404                 return false;
6405             }
6406             dmsa1.deleteRow( "c", false );
6407             dmsa1.deleteGapOnlyColumns();
6408             final Writer w0 = new StringWriter();
6409             dmsa1.write( w0, MSA_FORMAT.FASTA );
6410             final Writer w1 = new StringWriter();
6411             dmsa1.write( w1, MSA_FORMAT.PHYLIP );
6412             if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C" ) ) {
6413                 return false;
6414             }
6415             if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "EAAC" ) ) {
6416                 return false;
6417             }
6418             final MolecularSequence s__0 = BasicSequence.createAaSequence( "a", "A------" );
6419             final MolecularSequence s__1 = BasicSequence.createAaSequence( "b", "BB-----" );
6420             final MolecularSequence s__2 = BasicSequence.createAaSequence( "c", "CCC----" );
6421             final MolecularSequence s__3 = BasicSequence.createAaSequence( "d", "DDDD---" );
6422             final MolecularSequence s__4 = BasicSequence.createAaSequence( "e", "EEEEE--" );
6423             final MolecularSequence s__5 = BasicSequence.createAaSequence( "f", "FFFFFF-" );
6424             final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6425             l2.add( s__0 );
6426             l2.add( s__1 );
6427             l2.add( s__2 );
6428             l2.add( s__3 );
6429             l2.add( s__4 );
6430             l2.add( s__5 );
6431             final DeleteableMsa dmsa2 = DeleteableMsa.createInstance( l2 );
6432             dmsa2.deleteGapColumns( 0.5 );
6433             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A---" ) ) {
6434                 return false;
6435             }
6436             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB--" ) ) {
6437                 return false;
6438             }
6439             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CCC-" ) ) {
6440                 return false;
6441             }
6442             dmsa2.deleteGapColumns( 0.2 );
6443             if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A-" ) ) {
6444                 return false;
6445             }
6446             if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB" ) ) {
6447                 return false;
6448             }
6449             if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CC" ) ) {
6450                 return false;
6451             }
6452             dmsa2.deleteGapColumns( 0 );
6453             dmsa2.deleteRow( "a", false );
6454             dmsa2.deleteRow( "b", false );
6455             dmsa2.deleteRow( "f", false );
6456             dmsa2.deleteRow( "e", false );
6457             dmsa2.setIdentifier( 0, "new_c" );
6458             dmsa2.setIdentifier( 1, "new_d" );
6459             dmsa2.setResidueAt( 0, 0, 'x' );
6460             final MolecularSequence s = dmsa2.deleteRow( "new_d", true );
6461             if ( !s.getMolecularSequenceAsString().equals( "D" ) ) {
6462                 return false;
6463             }
6464             final Writer w = new StringWriter();
6465             dmsa2.write( w, MSA_FORMAT.PHYLIP );
6466             final String phylip = w.toString();
6467             if ( !phylip.equals( "1 1" + ForesterUtil.LINE_SEPARATOR + "new_c x" + ForesterUtil.LINE_SEPARATOR ) ) {
6468                 System.out.println( phylip );
6469                 return false;
6470             }
6471             final Writer w2 = new StringWriter();
6472             dmsa2.write( w2, MSA_FORMAT.FASTA );
6473             final String fasta = w2.toString();
6474             if ( !fasta.equals( ">new_c" + ForesterUtil.LINE_SEPARATOR + "x" + ForesterUtil.LINE_SEPARATOR ) ) {
6475                 System.out.println( fasta );
6476                 return false;
6477             }
6478         }
6479         catch ( final Exception e ) {
6480             e.printStackTrace( System.out );
6481             return false;
6482         }
6483         return true;
6484     }
6485
6486     private static boolean testNextNodeWithCollapsing() {
6487         try {
6488             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6489             PhylogenyNode n;
6490             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
6491             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6492             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
6493             t0.getNode( "cd" ).setCollapse( true );
6494             t0.getNode( "cde" ).setCollapse( true );
6495             n = t0.getFirstExternalNode();
6496             while ( n != null ) {
6497                 ext.add( n );
6498                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6499             }
6500             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6501                 return false;
6502             }
6503             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6504                 return false;
6505             }
6506             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
6507                 return false;
6508             }
6509             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
6510                 return false;
6511             }
6512             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
6513                 return false;
6514             }
6515             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
6516                 return false;
6517             }
6518             ext.clear();
6519             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6520             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
6521             t1.getNode( "ab" ).setCollapse( true );
6522             t1.getNode( "cd" ).setCollapse( true );
6523             t1.getNode( "cde" ).setCollapse( true );
6524             n = t1.getNode( "ab" );
6525             ext = new ArrayList<PhylogenyNode>();
6526             while ( n != null ) {
6527                 ext.add( n );
6528                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6529             }
6530             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6531                 return false;
6532             }
6533             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6534                 return false;
6535             }
6536             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6537                 return false;
6538             }
6539             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
6540                 return false;
6541             }
6542             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
6543                 return false;
6544             }
6545             ext.clear();
6546             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6547             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
6548             t2.getNode( "ab" ).setCollapse( true );
6549             t2.getNode( "cd" ).setCollapse( true );
6550             t2.getNode( "cde" ).setCollapse( true );
6551             t2.getNode( "c" ).setCollapse( true );
6552             t2.getNode( "d" ).setCollapse( true );
6553             t2.getNode( "e" ).setCollapse( true );
6554             t2.getNode( "gh" ).setCollapse( true );
6555             n = t2.getNode( "ab" );
6556             ext = new ArrayList<PhylogenyNode>();
6557             while ( n != null ) {
6558                 ext.add( n );
6559                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6560             }
6561             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6562                 return false;
6563             }
6564             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6565                 return false;
6566             }
6567             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6568                 return false;
6569             }
6570             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
6571                 return false;
6572             }
6573             ext.clear();
6574             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6575             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
6576             t3.getNode( "ab" ).setCollapse( true );
6577             t3.getNode( "cd" ).setCollapse( true );
6578             t3.getNode( "cde" ).setCollapse( true );
6579             t3.getNode( "c" ).setCollapse( true );
6580             t3.getNode( "d" ).setCollapse( true );
6581             t3.getNode( "e" ).setCollapse( true );
6582             t3.getNode( "gh" ).setCollapse( true );
6583             t3.getNode( "fgh" ).setCollapse( true );
6584             n = t3.getNode( "ab" );
6585             ext = new ArrayList<PhylogenyNode>();
6586             while ( n != null ) {
6587                 ext.add( n );
6588                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6589             }
6590             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6591                 return false;
6592             }
6593             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6594                 return false;
6595             }
6596             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
6597                 return false;
6598             }
6599             ext.clear();
6600             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6601             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
6602             t4.getNode( "ab" ).setCollapse( true );
6603             t4.getNode( "cd" ).setCollapse( true );
6604             t4.getNode( "cde" ).setCollapse( true );
6605             t4.getNode( "c" ).setCollapse( true );
6606             t4.getNode( "d" ).setCollapse( true );
6607             t4.getNode( "e" ).setCollapse( true );
6608             t4.getNode( "gh" ).setCollapse( true );
6609             t4.getNode( "fgh" ).setCollapse( true );
6610             t4.getNode( "abcdefgh" ).setCollapse( true );
6611             n = t4.getNode( "abcdefgh" );
6612             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
6613                 return false;
6614             }
6615             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6616             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
6617             ext.clear();
6618             n = t5.getFirstExternalNode();
6619             while ( n != null ) {
6620                 ext.add( n );
6621                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6622             }
6623             if ( ext.size() != 8 ) {
6624                 return false;
6625             }
6626             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6627                 return false;
6628             }
6629             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6630                 return false;
6631             }
6632             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6633                 return false;
6634             }
6635             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6636                 return false;
6637             }
6638             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6639                 return false;
6640             }
6641             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6642                 return false;
6643             }
6644             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
6645                 return false;
6646             }
6647             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
6648                 return false;
6649             }
6650             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6651             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
6652             ext.clear();
6653             t6.getNode( "ab" ).setCollapse( true );
6654             n = t6.getNode( "ab" );
6655             while ( n != null ) {
6656                 ext.add( n );
6657                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6658             }
6659             if ( ext.size() != 7 ) {
6660                 return false;
6661             }
6662             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6663                 return false;
6664             }
6665             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6666                 return false;
6667             }
6668             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6669                 return false;
6670             }
6671             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6672                 return false;
6673             }
6674             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6675                 return false;
6676             }
6677             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6678                 return false;
6679             }
6680             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6681                 return false;
6682             }
6683             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6684             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
6685             ext.clear();
6686             t7.getNode( "cd" ).setCollapse( true );
6687             n = t7.getNode( "a" );
6688             while ( n != null ) {
6689                 ext.add( n );
6690                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6691             }
6692             if ( ext.size() != 7 ) {
6693                 return false;
6694             }
6695             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6696                 return false;
6697             }
6698             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6699                 return false;
6700             }
6701             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6702                 return false;
6703             }
6704             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6705                 return false;
6706             }
6707             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6708                 return false;
6709             }
6710             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6711                 return false;
6712             }
6713             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6714                 return false;
6715             }
6716             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6717             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
6718             ext.clear();
6719             t8.getNode( "cd" ).setCollapse( true );
6720             t8.getNode( "c" ).setCollapse( true );
6721             t8.getNode( "d" ).setCollapse( true );
6722             n = t8.getNode( "a" );
6723             while ( n != null ) {
6724                 ext.add( n );
6725                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6726             }
6727             if ( ext.size() != 7 ) {
6728                 return false;
6729             }
6730             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6731                 return false;
6732             }
6733             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6734                 return false;
6735             }
6736             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6737                 System.out.println( "2 fail" );
6738                 return false;
6739             }
6740             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6741                 return false;
6742             }
6743             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6744                 return false;
6745             }
6746             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6747                 return false;
6748             }
6749             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6750                 return false;
6751             }
6752             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6753             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
6754             ext.clear();
6755             t9.getNode( "gh" ).setCollapse( true );
6756             n = t9.getNode( "a" );
6757             while ( n != null ) {
6758                 ext.add( n );
6759                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6760             }
6761             if ( ext.size() != 7 ) {
6762                 return false;
6763             }
6764             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6765                 return false;
6766             }
6767             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6768                 return false;
6769             }
6770             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6771                 return false;
6772             }
6773             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6774                 return false;
6775             }
6776             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6777                 return false;
6778             }
6779             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6780                 return false;
6781             }
6782             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6783                 return false;
6784             }
6785             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6786             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
6787             ext.clear();
6788             t10.getNode( "gh" ).setCollapse( true );
6789             t10.getNode( "g" ).setCollapse( true );
6790             t10.getNode( "h" ).setCollapse( true );
6791             n = t10.getNode( "a" );
6792             while ( n != null ) {
6793                 ext.add( n );
6794                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6795             }
6796             if ( ext.size() != 7 ) {
6797                 return false;
6798             }
6799             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6800                 return false;
6801             }
6802             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6803                 return false;
6804             }
6805             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6806                 return false;
6807             }
6808             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6809                 return false;
6810             }
6811             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6812                 return false;
6813             }
6814             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6815                 return false;
6816             }
6817             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6818                 return false;
6819             }
6820             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6821             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
6822             ext.clear();
6823             t11.getNode( "gh" ).setCollapse( true );
6824             t11.getNode( "fgh" ).setCollapse( true );
6825             n = t11.getNode( "a" );
6826             while ( n != null ) {
6827                 ext.add( n );
6828                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6829             }
6830             if ( ext.size() != 6 ) {
6831                 return false;
6832             }
6833             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6834                 return false;
6835             }
6836             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6837                 return false;
6838             }
6839             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6840                 return false;
6841             }
6842             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6843                 return false;
6844             }
6845             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6846                 return false;
6847             }
6848             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6849                 return false;
6850             }
6851             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6852             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
6853             ext.clear();
6854             t12.getNode( "gh" ).setCollapse( true );
6855             t12.getNode( "fgh" ).setCollapse( true );
6856             t12.getNode( "g" ).setCollapse( true );
6857             t12.getNode( "h" ).setCollapse( true );
6858             t12.getNode( "f" ).setCollapse( true );
6859             n = t12.getNode( "a" );
6860             while ( n != null ) {
6861                 ext.add( n );
6862                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6863             }
6864             if ( ext.size() != 6 ) {
6865                 return false;
6866             }
6867             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6868                 return false;
6869             }
6870             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6871                 return false;
6872             }
6873             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6874                 return false;
6875             }
6876             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6877                 return false;
6878             }
6879             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6880                 return false;
6881             }
6882             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6883                 return false;
6884             }
6885             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6886             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
6887             ext.clear();
6888             t13.getNode( "ab" ).setCollapse( true );
6889             t13.getNode( "b" ).setCollapse( true );
6890             t13.getNode( "fgh" ).setCollapse( true );
6891             t13.getNode( "gh" ).setCollapse( true );
6892             n = t13.getNode( "ab" );
6893             while ( n != null ) {
6894                 ext.add( n );
6895                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6896             }
6897             if ( ext.size() != 5 ) {
6898                 return false;
6899             }
6900             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6901                 return false;
6902             }
6903             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6904                 return false;
6905             }
6906             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6907                 return false;
6908             }
6909             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6910                 return false;
6911             }
6912             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6913                 return false;
6914             }
6915             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
6916             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
6917             ext.clear();
6918             t14.getNode( "ab" ).setCollapse( true );
6919             t14.getNode( "a" ).setCollapse( true );
6920             t14.getNode( "fgh" ).setCollapse( true );
6921             t14.getNode( "gh" ).setCollapse( true );
6922             n = t14.getNode( "ab" );
6923             while ( n != null ) {
6924                 ext.add( n );
6925                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6926             }
6927             if ( ext.size() != 5 ) {
6928                 return false;
6929             }
6930             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6931                 return false;
6932             }
6933             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6934                 return false;
6935             }
6936             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6937                 return false;
6938             }
6939             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6940                 return false;
6941             }
6942             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6943                 return false;
6944             }
6945             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" );
6946             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
6947             ext.clear();
6948             t15.getNode( "ab" ).setCollapse( true );
6949             t15.getNode( "a" ).setCollapse( true );
6950             t15.getNode( "fgh" ).setCollapse( true );
6951             t15.getNode( "gh" ).setCollapse( true );
6952             n = t15.getNode( "ab" );
6953             while ( n != null ) {
6954                 ext.add( n );
6955                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6956             }
6957             if ( ext.size() != 6 ) {
6958                 return false;
6959             }
6960             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6961                 return false;
6962             }
6963             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6964                 return false;
6965             }
6966             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6967                 return false;
6968             }
6969             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6970                 return false;
6971             }
6972             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
6973                 return false;
6974             }
6975             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6976                 return false;
6977             }
6978             //
6979             //
6980             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" );
6981             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
6982             ext.clear();
6983             t16.getNode( "ab" ).setCollapse( true );
6984             t16.getNode( "a" ).setCollapse( true );
6985             t16.getNode( "fgh" ).setCollapse( true );
6986             t16.getNode( "gh" ).setCollapse( true );
6987             t16.getNode( "cd" ).setCollapse( true );
6988             t16.getNode( "cde" ).setCollapse( true );
6989             t16.getNode( "d" ).setCollapse( true );
6990             t16.getNode( "x" ).setCollapse( true );
6991             n = t16.getNode( "ab" );
6992             while ( n != null ) {
6993                 ext.add( n );
6994                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6995             }
6996             if ( ext.size() != 4 ) {
6997                 return false;
6998             }
6999             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7000                 return false;
7001             }
7002             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
7003                 return false;
7004             }
7005             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
7006                 return false;
7007             }
7008             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
7009                 return false;
7010             }
7011         }
7012         catch ( final Exception e ) {
7013             e.printStackTrace( System.out );
7014             return false;
7015         }
7016         return true;
7017     }
7018
7019     private static boolean testNexusCharactersParsing() {
7020         try {
7021             final NexusCharactersParser parser = new NexusCharactersParser();
7022             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
7023             parser.parse();
7024             String[] labels = parser.getCharStateLabels();
7025             if ( labels.length != 7 ) {
7026                 return false;
7027             }
7028             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7029                 return false;
7030             }
7031             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7032                 return false;
7033             }
7034             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7035                 return false;
7036             }
7037             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7038                 return false;
7039             }
7040             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7041                 return false;
7042             }
7043             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7044                 return false;
7045             }
7046             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7047                 return false;
7048             }
7049             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7050             parser.parse();
7051             labels = parser.getCharStateLabels();
7052             if ( labels.length != 7 ) {
7053                 return false;
7054             }
7055             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7056                 return false;
7057             }
7058             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7059                 return false;
7060             }
7061             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7062                 return false;
7063             }
7064             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7065                 return false;
7066             }
7067             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7068                 return false;
7069             }
7070             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7071                 return false;
7072             }
7073             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7074                 return false;
7075             }
7076         }
7077         catch ( final Exception e ) {
7078             e.printStackTrace( System.out );
7079             return false;
7080         }
7081         return true;
7082     }
7083
7084     private static boolean testNexusMatrixParsing() {
7085         try {
7086             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
7087             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
7088             parser.parse();
7089             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
7090             if ( m.getNumberOfCharacters() != 9 ) {
7091                 return false;
7092             }
7093             if ( m.getNumberOfIdentifiers() != 5 ) {
7094                 return false;
7095             }
7096             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
7097                 return false;
7098             }
7099             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
7100                 return false;
7101             }
7102             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
7103                 return false;
7104             }
7105             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
7106                 return false;
7107             }
7108             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
7109                 return false;
7110             }
7111             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
7112                 return false;
7113             }
7114             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
7115                 return false;
7116             }
7117             //            if ( labels.length != 7 ) {
7118             //                return false;
7119             //            }
7120             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7121             //                return false;
7122             //            }
7123             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7124             //                return false;
7125             //            }
7126             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7127             //                return false;
7128             //            }
7129             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7130             //                return false;
7131             //            }
7132             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7133             //                return false;
7134             //            }
7135             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7136             //                return false;
7137             //            }
7138             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7139             //                return false;
7140             //            }
7141             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7142             //            parser.parse();
7143             //            labels = parser.getCharStateLabels();
7144             //            if ( labels.length != 7 ) {
7145             //                return false;
7146             //            }
7147             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7148             //                return false;
7149             //            }
7150             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7151             //                return false;
7152             //            }
7153             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7154             //                return false;
7155             //            }
7156             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7157             //                return false;
7158             //            }
7159             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7160             //                return false;
7161             //            }
7162             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7163             //                return false;
7164             //            }
7165             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7166             //                return false;
7167             //            }
7168         }
7169         catch ( final Exception e ) {
7170             e.printStackTrace( System.out );
7171             return false;
7172         }
7173         return true;
7174     }
7175
7176     private static boolean testNexusTreeParsing() {
7177         try {
7178             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7179             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7180             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
7181             if ( phylogenies.length != 1 ) {
7182                 return false;
7183             }
7184             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
7185                 return false;
7186             }
7187             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7188                 return false;
7189             }
7190             phylogenies = null;
7191             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
7192             if ( phylogenies.length != 1 ) {
7193                 return false;
7194             }
7195             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7196                 return false;
7197             }
7198             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
7199                 return false;
7200             }
7201             phylogenies = null;
7202             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
7203             if ( phylogenies.length != 1 ) {
7204                 return false;
7205             }
7206             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7207                 return false;
7208             }
7209             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7210                 return false;
7211             }
7212             if ( phylogenies[ 0 ].isRooted() ) {
7213                 return false;
7214             }
7215             phylogenies = null;
7216             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
7217             if ( phylogenies.length != 18 ) {
7218                 return false;
7219             }
7220             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7221                 return false;
7222             }
7223             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
7224                 return false;
7225             }
7226             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
7227                 return false;
7228             }
7229             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
7230                 return false;
7231             }
7232             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7233                 return false;
7234             }
7235             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
7236                 return false;
7237             }
7238             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
7239                 return false;
7240             }
7241             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
7242                 return false;
7243             }
7244             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
7245                 return false;
7246             }
7247             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
7248                 return false;
7249             }
7250             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
7251                 return false;
7252             }
7253             if ( phylogenies[ 8 ].isRooted() ) {
7254                 return false;
7255             }
7256             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
7257                 return false;
7258             }
7259             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
7260                 return false;
7261             }
7262             if ( !phylogenies[ 9 ].isRooted() ) {
7263                 return false;
7264             }
7265             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
7266                 return false;
7267             }
7268             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
7269                 return false;
7270             }
7271             if ( !phylogenies[ 10 ].isRooted() ) {
7272                 return false;
7273             }
7274             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
7275                 return false;
7276             }
7277             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
7278                 return false;
7279             }
7280             if ( phylogenies[ 11 ].isRooted() ) {
7281                 return false;
7282             }
7283             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
7284                 return false;
7285             }
7286             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
7287                 return false;
7288             }
7289             if ( !phylogenies[ 12 ].isRooted() ) {
7290                 return false;
7291             }
7292             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
7293                 return false;
7294             }
7295             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
7296                 return false;
7297             }
7298             if ( !phylogenies[ 13 ].isRooted() ) {
7299                 return false;
7300             }
7301             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
7302                 return false;
7303             }
7304             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
7305                 return false;
7306             }
7307             if ( !phylogenies[ 14 ].isRooted() ) {
7308                 return false;
7309             }
7310             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
7311                 return false;
7312             }
7313             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
7314                 return false;
7315             }
7316             if ( phylogenies[ 15 ].isRooted() ) {
7317                 return false;
7318             }
7319             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
7320                 return false;
7321             }
7322             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
7323                 return false;
7324             }
7325             if ( !phylogenies[ 16 ].isRooted() ) {
7326                 return false;
7327             }
7328             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
7329                 return false;
7330             }
7331             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
7332                 return false;
7333             }
7334             if ( phylogenies[ 17 ].isRooted() ) {
7335                 return false;
7336             }
7337             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
7338                 return false;
7339             }
7340             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7341             phylogenies = null;
7342             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
7343             if ( phylogenies.length != 9 ) {
7344                 return false;
7345             }
7346             if ( !isEqual( 0.48039661496919533, phylogenies[ 0 ].getNode( "Diadocidia_spinosula" )
7347                            .getDistanceToParent() ) ) {
7348                 return false;
7349             }
7350             if ( !isEqual( 0.3959796191512233, phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" )
7351                            .getDistanceToParent() ) ) {
7352                 return false;
7353             }
7354             if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
7355                 return false;
7356             }
7357             if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7358                 return false;
7359             }
7360             if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7361                 return false;
7362             }
7363             if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7364                 return false;
7365             }
7366             if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7367                 return false;
7368             }
7369         }
7370         catch ( final Exception e ) {
7371             e.printStackTrace( System.out );
7372             return false;
7373         }
7374         return true;
7375     }
7376
7377     private static boolean testNexusTreeParsingIterating() {
7378         try {
7379             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
7380             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
7381             if ( !p.hasNext() ) {
7382                 return false;
7383             }
7384             Phylogeny phy = p.next();
7385             if ( phy == null ) {
7386                 return false;
7387             }
7388             if ( phy.getNumberOfExternalNodes() != 25 ) {
7389                 return false;
7390             }
7391             if ( !phy.getName().equals( "" ) ) {
7392                 return false;
7393             }
7394             if ( p.hasNext() ) {
7395                 return false;
7396             }
7397             phy = p.next();
7398             if ( phy != null ) {
7399                 return false;
7400             }
7401             p.reset();
7402             if ( !p.hasNext() ) {
7403                 return false;
7404             }
7405             phy = p.next();
7406             if ( phy == null ) {
7407                 return false;
7408             }
7409             if ( phy.getNumberOfExternalNodes() != 25 ) {
7410                 return false;
7411             }
7412             if ( !phy.getName().equals( "" ) ) {
7413                 return false;
7414             }
7415             if ( p.hasNext() ) {
7416                 return false;
7417             }
7418             phy = p.next();
7419             if ( phy != null ) {
7420                 return false;
7421             }
7422             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
7423             if ( !p.hasNext() ) {
7424                 return false;
7425             }
7426             phy = p.next();
7427             if ( phy == null ) {
7428                 return false;
7429             }
7430             if ( phy.getNumberOfExternalNodes() != 10 ) {
7431                 return false;
7432             }
7433             if ( !phy.getName().equals( "name" ) ) {
7434                 return false;
7435             }
7436             if ( p.hasNext() ) {
7437                 return false;
7438             }
7439             phy = p.next();
7440             if ( phy != null ) {
7441                 return false;
7442             }
7443             p.reset();
7444             if ( !p.hasNext() ) {
7445                 return false;
7446             }
7447             phy = p.next();
7448             if ( phy == null ) {
7449                 return false;
7450             }
7451             if ( phy.getNumberOfExternalNodes() != 10 ) {
7452                 return false;
7453             }
7454             if ( !phy.getName().equals( "name" ) ) {
7455                 return false;
7456             }
7457             if ( p.hasNext() ) {
7458                 return false;
7459             }
7460             phy = p.next();
7461             if ( phy != null ) {
7462                 return false;
7463             }
7464             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
7465             if ( !p.hasNext() ) {
7466                 return false;
7467             }
7468             phy = p.next();
7469             if ( phy == null ) {
7470                 return false;
7471             }
7472             if ( phy.getNumberOfExternalNodes() != 3 ) {
7473                 return false;
7474             }
7475             if ( !phy.getName().equals( "" ) ) {
7476                 return false;
7477             }
7478             if ( phy.isRooted() ) {
7479                 return false;
7480             }
7481             if ( p.hasNext() ) {
7482                 return false;
7483             }
7484             phy = p.next();
7485             if ( phy != null ) {
7486                 return false;
7487             }
7488             //
7489             p.reset();
7490             if ( !p.hasNext() ) {
7491                 return false;
7492             }
7493             phy = p.next();
7494             if ( phy == null ) {
7495                 return false;
7496             }
7497             if ( phy.getNumberOfExternalNodes() != 3 ) {
7498                 return false;
7499             }
7500             if ( !phy.getName().equals( "" ) ) {
7501                 return false;
7502             }
7503             if ( p.hasNext() ) {
7504                 return false;
7505             }
7506             phy = p.next();
7507             if ( phy != null ) {
7508                 return false;
7509             }
7510             //
7511             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
7512             if ( !p.hasNext() ) {
7513                 return false;
7514             }
7515             //0
7516             phy = p.next();
7517             if ( phy == null ) {
7518                 return false;
7519             }
7520             if ( phy.getNumberOfExternalNodes() != 10 ) {
7521                 return false;
7522             }
7523             if ( !phy.getName().equals( "tree 0" ) ) {
7524                 return false;
7525             }
7526             //1
7527             if ( !p.hasNext() ) {
7528                 return false;
7529             }
7530             phy = p.next();
7531             if ( phy == null ) {
7532                 return false;
7533             }
7534             if ( phy.getNumberOfExternalNodes() != 10 ) {
7535                 return false;
7536             }
7537             if ( !phy.getName().equals( "tree 1" ) ) {
7538                 return false;
7539             }
7540             //2
7541             if ( !p.hasNext() ) {
7542                 return false;
7543             }
7544             phy = p.next();
7545             if ( phy == null ) {
7546                 return false;
7547             }
7548             if ( phy.getNumberOfExternalNodes() != 3 ) {
7549                 System.out.println( phy.toString() );
7550                 return false;
7551             }
7552             if ( !phy.getName().equals( "" ) ) {
7553                 return false;
7554             }
7555             if ( phy.isRooted() ) {
7556                 return false;
7557             }
7558             //3
7559             if ( !p.hasNext() ) {
7560                 return false;
7561             }
7562             phy = p.next();
7563             if ( phy == null ) {
7564                 return false;
7565             }
7566             if ( phy.getNumberOfExternalNodes() != 4 ) {
7567                 return false;
7568             }
7569             if ( !phy.getName().equals( "" ) ) {
7570                 return false;
7571             }
7572             if ( !phy.isRooted() ) {
7573                 return false;
7574             }
7575             //4
7576             if ( !p.hasNext() ) {
7577                 return false;
7578             }
7579             phy = p.next();
7580             if ( phy == null ) {
7581                 return false;
7582             }
7583             if ( phy.getNumberOfExternalNodes() != 5 ) {
7584                 System.out.println( phy.getNumberOfExternalNodes() );
7585                 return false;
7586             }
7587             if ( !phy.getName().equals( "" ) ) {
7588                 return false;
7589             }
7590             if ( !phy.isRooted() ) {
7591                 return false;
7592             }
7593             //5
7594             if ( !p.hasNext() ) {
7595                 return false;
7596             }
7597             phy = p.next();
7598             if ( phy == null ) {
7599                 return false;
7600             }
7601             if ( phy.getNumberOfExternalNodes() != 3 ) {
7602                 return false;
7603             }
7604             if ( !phy.getName().equals( "" ) ) {
7605                 return false;
7606             }
7607             if ( phy.isRooted() ) {
7608                 return false;
7609             }
7610             //6
7611             if ( !p.hasNext() ) {
7612                 return false;
7613             }
7614             phy = p.next();
7615             if ( phy == null ) {
7616                 return false;
7617             }
7618             if ( phy.getNumberOfExternalNodes() != 2 ) {
7619                 return false;
7620             }
7621             if ( !phy.getName().equals( "" ) ) {
7622                 return false;
7623             }
7624             if ( !phy.isRooted() ) {
7625                 return false;
7626             }
7627             //7
7628             if ( !p.hasNext() ) {
7629                 return false;
7630             }
7631             phy = p.next();
7632             if ( phy.getNumberOfExternalNodes() != 3 ) {
7633                 return false;
7634             }
7635             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7636                 return false;
7637             }
7638             if ( !phy.isRooted() ) {
7639                 return false;
7640             }
7641             //8
7642             if ( !p.hasNext() ) {
7643                 return false;
7644             }
7645             phy = p.next();
7646             if ( phy.getNumberOfExternalNodes() != 3 ) {
7647                 return false;
7648             }
7649             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
7650                 return false;
7651             }
7652             if ( !phy.getName().equals( "tree 8" ) ) {
7653                 return false;
7654             }
7655             //9
7656             if ( !p.hasNext() ) {
7657                 return false;
7658             }
7659             phy = p.next();
7660             if ( phy.getNumberOfExternalNodes() != 3 ) {
7661                 return false;
7662             }
7663             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
7664                 return false;
7665             }
7666             if ( !phy.getName().equals( "tree 9" ) ) {
7667                 return false;
7668             }
7669             //10
7670             if ( !p.hasNext() ) {
7671                 return false;
7672             }
7673             phy = p.next();
7674             if ( phy.getNumberOfExternalNodes() != 3 ) {
7675                 return false;
7676             }
7677             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7678                 return false;
7679             }
7680             if ( !phy.getName().equals( "tree 10" ) ) {
7681                 return false;
7682             }
7683             if ( !phy.isRooted() ) {
7684                 return false;
7685             }
7686             //11
7687             if ( !p.hasNext() ) {
7688                 return false;
7689             }
7690             phy = p.next();
7691             if ( phy.getNumberOfExternalNodes() != 3 ) {
7692                 return false;
7693             }
7694             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
7695                 return false;
7696             }
7697             if ( !phy.getName().equals( "tree 11" ) ) {
7698                 return false;
7699             }
7700             if ( phy.isRooted() ) {
7701                 return false;
7702             }
7703             //12
7704             if ( !p.hasNext() ) {
7705                 return false;
7706             }
7707             phy = p.next();
7708             if ( phy.getNumberOfExternalNodes() != 3 ) {
7709                 return false;
7710             }
7711             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
7712                 return false;
7713             }
7714             if ( !phy.getName().equals( "tree 12" ) ) {
7715                 return false;
7716             }
7717             if ( !phy.isRooted() ) {
7718                 return false;
7719             }
7720             //13
7721             if ( !p.hasNext() ) {
7722                 return false;
7723             }
7724             phy = p.next();
7725             if ( phy.getNumberOfExternalNodes() != 3 ) {
7726                 return false;
7727             }
7728             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7729                 return false;
7730             }
7731             if ( !phy.getName().equals( "tree 13" ) ) {
7732                 return false;
7733             }
7734             if ( !phy.isRooted() ) {
7735                 return false;
7736             }
7737             //14
7738             if ( !p.hasNext() ) {
7739                 return false;
7740             }
7741             phy = p.next();
7742             if ( phy.getNumberOfExternalNodes() != 10 ) {
7743                 System.out.println( phy.getNumberOfExternalNodes() );
7744                 return false;
7745             }
7746             if ( !phy
7747                     .toNewHampshire()
7748                     .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;" ) ) {
7749                 System.out.println( phy.toNewHampshire() );
7750                 return false;
7751             }
7752             if ( !phy.getName().equals( "tree 14" ) ) {
7753                 return false;
7754             }
7755             if ( !phy.isRooted() ) {
7756                 return false;
7757             }
7758             //15
7759             if ( !p.hasNext() ) {
7760                 return false;
7761             }
7762             phy = p.next();
7763             if ( phy.getNumberOfExternalNodes() != 10 ) {
7764                 System.out.println( phy.getNumberOfExternalNodes() );
7765                 return false;
7766             }
7767             if ( !phy
7768                     .toNewHampshire()
7769                     .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;" ) ) {
7770                 System.out.println( phy.toNewHampshire() );
7771                 return false;
7772             }
7773             if ( !phy.getName().equals( "tree 15" ) ) {
7774                 return false;
7775             }
7776             if ( phy.isRooted() ) {
7777                 return false;
7778             }
7779             //16
7780             if ( !p.hasNext() ) {
7781                 return false;
7782             }
7783             phy = p.next();
7784             if ( phy.getNumberOfExternalNodes() != 10 ) {
7785                 System.out.println( phy.getNumberOfExternalNodes() );
7786                 return false;
7787             }
7788             if ( !phy
7789                     .toNewHampshire()
7790                     .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;" ) ) {
7791                 System.out.println( phy.toNewHampshire() );
7792                 return false;
7793             }
7794             if ( !phy.getName().equals( "tree 16" ) ) {
7795                 return false;
7796             }
7797             if ( !phy.isRooted() ) {
7798                 return false;
7799             }
7800             //17
7801             if ( !p.hasNext() ) {
7802                 return false;
7803             }
7804             phy = p.next();
7805             if ( phy.getNumberOfExternalNodes() != 10 ) {
7806                 System.out.println( phy.getNumberOfExternalNodes() );
7807                 return false;
7808             }
7809             if ( !phy
7810                     .toNewHampshire()
7811                     .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;" ) ) {
7812                 System.out.println( phy.toNewHampshire() );
7813                 return false;
7814             }
7815             if ( !phy.getName().equals( "tree 17" ) ) {
7816                 return false;
7817             }
7818             if ( phy.isRooted() ) {
7819                 return false;
7820             }
7821             //
7822             if ( p.hasNext() ) {
7823                 return false;
7824             }
7825             phy = p.next();
7826             if ( phy != null ) {
7827                 return false;
7828             }
7829             p.reset();
7830             //0
7831             if ( !p.hasNext() ) {
7832                 return false;
7833             }
7834             phy = p.next();
7835             if ( phy == null ) {
7836                 return false;
7837             }
7838             if ( phy.getNumberOfExternalNodes() != 10 ) {
7839                 return false;
7840             }
7841             if ( !phy.getName().equals( "tree 0" ) ) {
7842                 return false;
7843             }
7844             //1
7845             if ( !p.hasNext() ) {
7846                 return false;
7847             }
7848             phy = p.next();
7849             if ( phy == null ) {
7850                 return false;
7851             }
7852             if ( phy.getNumberOfExternalNodes() != 10 ) {
7853                 return false;
7854             }
7855             if ( !phy.getName().equals( "tree 1" ) ) {
7856                 return false;
7857             }
7858             //2
7859             if ( !p.hasNext() ) {
7860                 return false;
7861             }
7862             phy = p.next();
7863             if ( phy == null ) {
7864                 return false;
7865             }
7866             if ( phy.getNumberOfExternalNodes() != 3 ) {
7867                 return false;
7868             }
7869             if ( !phy.getName().equals( "" ) ) {
7870                 return false;
7871             }
7872             if ( phy.isRooted() ) {
7873                 return false;
7874             }
7875             //3
7876             if ( !p.hasNext() ) {
7877                 return false;
7878             }
7879             phy = p.next();
7880             if ( phy == null ) {
7881                 return false;
7882             }
7883             if ( phy.getNumberOfExternalNodes() != 4 ) {
7884                 return false;
7885             }
7886             if ( !phy.getName().equals( "" ) ) {
7887                 return false;
7888             }
7889             if ( !phy.isRooted() ) {
7890                 return false;
7891             }
7892             //4
7893             if ( !p.hasNext() ) {
7894                 return false;
7895             }
7896             phy = p.next();
7897             if ( phy == null ) {
7898                 return false;
7899             }
7900             if ( phy.getNumberOfExternalNodes() != 5 ) {
7901                 System.out.println( phy.getNumberOfExternalNodes() );
7902                 return false;
7903             }
7904             if ( !phy.getName().equals( "" ) ) {
7905                 return false;
7906             }
7907             if ( !phy.isRooted() ) {
7908                 return false;
7909             }
7910             //5
7911             if ( !p.hasNext() ) {
7912                 return false;
7913             }
7914             phy = p.next();
7915             if ( phy == null ) {
7916                 return false;
7917             }
7918             if ( phy.getNumberOfExternalNodes() != 3 ) {
7919                 return false;
7920             }
7921             if ( !phy.getName().equals( "" ) ) {
7922                 return false;
7923             }
7924             if ( phy.isRooted() ) {
7925                 return false;
7926             }
7927             //
7928             final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7929             p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
7930             // 0
7931             if ( !p2.hasNext() ) {
7932                 return false;
7933             }
7934             phy = p2.next();
7935             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7936                 return false;
7937             }
7938             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7939                 return false;
7940             }
7941             // 1
7942             if ( !p2.hasNext() ) {
7943                 return false;
7944             }
7945             phy = p2.next();
7946             // 2
7947             if ( !p2.hasNext() ) {
7948                 return false;
7949             }
7950             phy = p2.next();
7951             // 3
7952             if ( !p2.hasNext() ) {
7953                 return false;
7954             }
7955             phy = p2.next();
7956             // 4
7957             if ( !p2.hasNext() ) {
7958                 return false;
7959             }
7960             phy = p2.next();
7961             // 5
7962             if ( !p2.hasNext() ) {
7963                 return false;
7964             }
7965             phy = p2.next();
7966             // 6
7967             if ( !p2.hasNext() ) {
7968                 return false;
7969             }
7970             phy = p2.next();
7971             // 7
7972             if ( !p2.hasNext() ) {
7973                 return false;
7974             }
7975             phy = p2.next();
7976             // 8
7977             if ( !p2.hasNext() ) {
7978                 return false;
7979             }
7980             phy = p2.next();
7981             if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7982                 return false;
7983             }
7984             if ( p2.hasNext() ) {
7985                 return false;
7986             }
7987             phy = p2.next();
7988             if ( phy != null ) {
7989                 return false;
7990             }
7991             // 0
7992             p2.reset();
7993             if ( !p2.hasNext() ) {
7994                 return false;
7995             }
7996             phy = p2.next();
7997             if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7998                 return false;
7999             }
8000             if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
8001                 return false;
8002             }
8003         }
8004         catch ( final Exception e ) {
8005             e.printStackTrace( System.out );
8006             return false;
8007         }
8008         return true;
8009     }
8010
8011     private static boolean testNexusTreeParsingTranslating() {
8012         try {
8013             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8014             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
8015             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
8016             if ( phylogenies.length != 1 ) {
8017                 return false;
8018             }
8019             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8020                 return false;
8021             }
8022             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8023                 return false;
8024             }
8025             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8026                 return false;
8027             }
8028             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8029                 return false;
8030             }
8031             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8032                     .equals( "Aranaeus" ) ) {
8033                 return false;
8034             }
8035             phylogenies = null;
8036             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
8037             if ( phylogenies.length != 3 ) {
8038                 return false;
8039             }
8040             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8041                 return false;
8042             }
8043             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8044                 return false;
8045             }
8046             if ( phylogenies[ 0 ].isRooted() ) {
8047                 return false;
8048             }
8049             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8050                 return false;
8051             }
8052             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8053                 return false;
8054             }
8055             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8056                     .equals( "Aranaeus" ) ) {
8057                 return false;
8058             }
8059             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8060                 return false;
8061             }
8062             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8063                 return false;
8064             }
8065             if ( phylogenies[ 1 ].isRooted() ) {
8066                 return false;
8067             }
8068             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8069                 return false;
8070             }
8071             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8072                 return false;
8073             }
8074             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8075                     .equals( "Aranaeus" ) ) {
8076                 return false;
8077             }
8078             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8079                 return false;
8080             }
8081             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8082                 return false;
8083             }
8084             if ( !phylogenies[ 2 ].isRooted() ) {
8085                 return false;
8086             }
8087             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8088                 return false;
8089             }
8090             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8091                 return false;
8092             }
8093             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8094                     .equals( "Aranaeus" ) ) {
8095                 return false;
8096             }
8097             phylogenies = null;
8098             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
8099             if ( phylogenies.length != 3 ) {
8100                 return false;
8101             }
8102             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8103                 return false;
8104             }
8105             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8106                 return false;
8107             }
8108             if ( phylogenies[ 0 ].isRooted() ) {
8109                 return false;
8110             }
8111             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8112                 return false;
8113             }
8114             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8115                 return false;
8116             }
8117             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8118                     .equals( "Aranaeus" ) ) {
8119                 return false;
8120             }
8121             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8122                 return false;
8123             }
8124             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8125                 return false;
8126             }
8127             if ( phylogenies[ 1 ].isRooted() ) {
8128                 return false;
8129             }
8130             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8131                 return false;
8132             }
8133             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8134                 return false;
8135             }
8136             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8137                     .equals( "Aranaeus" ) ) {
8138                 return false;
8139             }
8140             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8141                 return false;
8142             }
8143             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8144                 return false;
8145             }
8146             if ( !phylogenies[ 2 ].isRooted() ) {
8147                 return false;
8148             }
8149             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8150                 return false;
8151             }
8152             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8153                 return false;
8154             }
8155             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8156                     .equals( "Aranaeus" ) ) {
8157                 return false;
8158             }
8159             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
8160             if ( phylogenies.length != 3 ) {
8161                 return false;
8162             }
8163             if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
8164                            0.00100049 ) ) {
8165                 return false;
8166             }
8167         }
8168         catch ( final Exception e ) {
8169             e.printStackTrace( System.out );
8170             return false;
8171         }
8172         return true;
8173     }
8174
8175     private static boolean testNHParsing() {
8176         try {
8177             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8178             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
8179             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
8180                 return false;
8181             }
8182             final NHXParser nhxp = new NHXParser();
8183             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
8184             nhxp.setReplaceUnderscores( true );
8185             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
8186             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
8187                 return false;
8188             }
8189             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
8190                 return false;
8191             }
8192             final Phylogeny p1b = factory
8193                     .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 ",
8194                              new NHXParser() )[ 0 ];
8195             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
8196                 return false;
8197             }
8198             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
8199                 return false;
8200             }
8201             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
8202             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
8203             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
8204             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
8205             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
8206             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
8207             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
8208             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
8209             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
8210             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
8211             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
8212                     + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
8213                     + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
8214                     new NHXParser() );
8215             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
8216                 return false;
8217             }
8218             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
8219                 return false;
8220             }
8221             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
8222                 return false;
8223             }
8224             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
8225                 return false;
8226             }
8227             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
8228             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
8229             final String p16_S = "((A,B),C)";
8230             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
8231             if ( p16.length != 1 ) {
8232                 return false;
8233             }
8234             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
8235                 return false;
8236             }
8237             final String p17_S = "(C,(A,B))";
8238             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
8239             if ( p17.length != 1 ) {
8240                 return false;
8241             }
8242             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
8243                 return false;
8244             }
8245             final String p18_S = "((A,B),(C,D))";
8246             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
8247             if ( p18.length != 1 ) {
8248                 return false;
8249             }
8250             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
8251                 return false;
8252             }
8253             final String p19_S = "(((A,B),C),D)";
8254             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
8255             if ( p19.length != 1 ) {
8256                 return false;
8257             }
8258             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
8259                 return false;
8260             }
8261             final String p20_S = "(A,(B,(C,D)))";
8262             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
8263             if ( p20.length != 1 ) {
8264                 return false;
8265             }
8266             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
8267                 return false;
8268             }
8269             final String p21_S = "(A,(B,(C,(D,E))))";
8270             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
8271             if ( p21.length != 1 ) {
8272                 return false;
8273             }
8274             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
8275                 return false;
8276             }
8277             final String p22_S = "((((A,B),C),D),E)";
8278             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
8279             if ( p22.length != 1 ) {
8280                 return false;
8281             }
8282             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
8283                 return false;
8284             }
8285             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8286             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
8287             if ( p23.length != 1 ) {
8288                 System.out.println( "xl=" + p23.length );
8289                 System.exit( -1 );
8290                 return false;
8291             }
8292             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
8293                 return false;
8294             }
8295             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8296             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
8297             if ( p24.length != 1 ) {
8298                 return false;
8299             }
8300             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
8301                 return false;
8302             }
8303             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8304             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8305             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
8306             if ( p241.length != 2 ) {
8307                 return false;
8308             }
8309             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
8310                 return false;
8311             }
8312             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
8313                 return false;
8314             }
8315             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
8316                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
8317                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
8318                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
8319                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
8320                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
8321                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
8322                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
8323             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
8324             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
8325                 return false;
8326             }
8327             final String p26_S = "(A,B)ab";
8328             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
8329             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
8330                 return false;
8331             }
8332             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8333             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
8334             if ( p27s.length != 1 ) {
8335                 System.out.println( "xxl=" + p27s.length );
8336                 System.exit( -1 );
8337                 return false;
8338             }
8339             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8340                 System.out.println( p27s[ 0 ].toNewHampshireX() );
8341                 System.exit( -1 );
8342                 return false;
8343             }
8344             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
8345                                                     new NHXParser() );
8346             if ( p27.length != 1 ) {
8347                 System.out.println( "yl=" + p27.length );
8348                 System.exit( -1 );
8349                 return false;
8350             }
8351             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8352                 System.out.println( p27[ 0 ].toNewHampshireX() );
8353                 System.exit( -1 );
8354                 return false;
8355             }
8356             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8357             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8358             final String p28_S3 = "(A,B)ab";
8359             final String p28_S4 = "((((A,B),C),D),;E;)";
8360             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
8361                                                     new NHXParser() );
8362             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
8363                 return false;
8364             }
8365             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
8366                 return false;
8367             }
8368             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
8369                 return false;
8370             }
8371             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
8372                 return false;
8373             }
8374             if ( p28.length != 4 ) {
8375                 return false;
8376             }
8377             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";
8378             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
8379             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
8380                 return false;
8381             }
8382             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";
8383             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
8384             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
8385                 return false;
8386             }
8387             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
8388             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
8389             if ( ( p32.length != 0 ) ) {
8390                 return false;
8391             }
8392             final String p33_S = "A";
8393             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
8394             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
8395                 return false;
8396             }
8397             final String p34_S = "B;";
8398             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
8399             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
8400                 return false;
8401             }
8402             final String p35_S = "B:0.2";
8403             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
8404             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
8405                 return false;
8406             }
8407             final String p36_S = "(A)";
8408             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
8409             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
8410                 return false;
8411             }
8412             final String p37_S = "((A))";
8413             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
8414             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
8415                 return false;
8416             }
8417             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8418             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
8419             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
8420                 return false;
8421             }
8422             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8423             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
8424             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
8425                 return false;
8426             }
8427             final String p40_S = "(A,B,C)";
8428             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
8429             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
8430                 return false;
8431             }
8432             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
8433             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
8434             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
8435                 return false;
8436             }
8437             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
8438             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
8439             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
8440                 return false;
8441             }
8442             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)";
8443             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
8444             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
8445                 return false;
8446             }
8447             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)))";
8448             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
8449             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
8450                 return false;
8451             }
8452             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
8453             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
8454             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
8455                 return false;
8456             }
8457             final String p46_S = "";
8458             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
8459             if ( p46.length != 0 ) {
8460                 return false;
8461             }
8462             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
8463             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8464                 return false;
8465             }
8466             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8467             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8468                 return false;
8469             }
8470             final Phylogeny p49 = factory
8471                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
8472                              new NHXParser() )[ 0 ];
8473             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8474                 return false;
8475             }
8476             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8477             if ( p50.getNode( "A" ) == null ) {
8478                 return false;
8479             }
8480             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8481                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
8482                 return false;
8483             }
8484             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
8485                 return false;
8486             }
8487             if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
8488                     .equals( "((A,B)88:2.0,C);" ) ) {
8489                 return false;
8490             }
8491             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8492             if ( p51.getNode( "A(A" ) == null ) {
8493                 return false;
8494             }
8495             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8496             if ( p52.getNode( "A(A" ) == null ) {
8497                 return false;
8498             }
8499             final Phylogeny p53 = factory
8500                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
8501                              new NHXParser() )[ 0 ];
8502             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
8503                 return false;
8504             }
8505             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
8506             if ( p54.getNode( "A" ) == null ) {
8507                 return false;
8508             }
8509             if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ).equals( "((A,B)[88],C);" ) ) {
8510                 return false;
8511             }
8512             final Phylogeny p55 = factory
8513                     .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);" ),
8514                              new NHXParser() )[ 0 ];
8515             if ( !p55
8516                     .toNewHampshire()
8517                     .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);" ) ) {
8518                 System.out.println( p55.toNewHampshire() );
8519                 return false;
8520             }
8521             final Phylogeny p56 = factory
8522                     .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);" ),
8523                              new NHXParser() )[ 0 ];
8524             if ( !p56
8525                     .toNewHampshire()
8526                     .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);" ) ) {
8527                 System.out.println( p56.toNewHampshire() );
8528                 return false;
8529             }
8530             final Phylogeny p57 = factory
8531                     .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);" ),
8532                              new NHXParser() )[ 0 ];
8533             if ( !p57
8534                     .toNewHampshire()
8535                     .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);" ) ) {
8536                 System.out.println( p56.toNewHampshire() );
8537                 return false;
8538             }
8539             final String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
8540             final Phylogeny p58 = factory.create( new StringBuffer( s58 ), new NHXParser() )[ 0 ];
8541             if ( !p58.toNewHampshire().equals( s58 ) ) {
8542                 System.out.println( p58.toNewHampshire() );
8543                 return false;
8544             }
8545             final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
8546             final Phylogeny p59 = factory.create( new StringBuffer( s59 ), new NHXParser() )[ 0 ];
8547             if ( !p59.toNewHampshire().equals( s59 ) ) {
8548                 System.out.println( p59.toNewHampshire() );
8549                 return false;
8550             }
8551             final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
8552             final Phylogeny p60 = factory.create( new StringBuffer( s60 ), new NHXParser() )[ 0 ];
8553             if ( !p60.toNewHampshire().equals( s60 ) ) {
8554                 System.out.println( p60.toNewHampshire() );
8555                 return false;
8556             }
8557             final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
8558             final Phylogeny p61 = factory.create( new StringBuffer( s61 ), new NHXParser() )[ 0 ];
8559             if ( !p61.toNewHampshire()
8560                     .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
8561                 System.out.println( p61.toNewHampshire() );
8562                 return false;
8563             }
8564         }
8565         catch ( final Exception e ) {
8566             e.printStackTrace( System.out );
8567             return false;
8568         }
8569         return true;
8570     }
8571
8572     private static boolean testNHParsingIter() {
8573         try {
8574             final String p0_str = "(A,B);";
8575             final NHXParser p = new NHXParser();
8576             p.setSource( p0_str );
8577             if ( !p.hasNext() ) {
8578                 return false;
8579             }
8580             final Phylogeny p0 = p.next();
8581             if ( !p0.toNewHampshire().equals( p0_str ) ) {
8582                 System.out.println( p0.toNewHampshire() );
8583                 return false;
8584             }
8585             if ( p.hasNext() ) {
8586                 return false;
8587             }
8588             if ( p.next() != null ) {
8589                 return false;
8590             }
8591             //
8592             final String p00_str = "(A,B)root;";
8593             p.setSource( p00_str );
8594             final Phylogeny p00 = p.next();
8595             if ( !p00.toNewHampshire().equals( p00_str ) ) {
8596                 System.out.println( p00.toNewHampshire() );
8597                 return false;
8598             }
8599             //
8600             final String p000_str = "A;";
8601             p.setSource( p000_str );
8602             final Phylogeny p000 = p.next();
8603             if ( !p000.toNewHampshire().equals( p000_str ) ) {
8604                 System.out.println( p000.toNewHampshire() );
8605                 return false;
8606             }
8607             //
8608             final String p0000_str = "A";
8609             p.setSource( p0000_str );
8610             final Phylogeny p0000 = p.next();
8611             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
8612                 System.out.println( p0000.toNewHampshire() );
8613                 return false;
8614             }
8615             //
8616             p.setSource( "(A)" );
8617             final Phylogeny p00000 = p.next();
8618             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
8619                 System.out.println( p00000.toNewHampshire() );
8620                 return false;
8621             }
8622             //
8623             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
8624             p.setSource( p1_str );
8625             if ( !p.hasNext() ) {
8626                 return false;
8627             }
8628             final Phylogeny p1_0 = p.next();
8629             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
8630                 System.out.println( p1_0.toNewHampshire() );
8631                 return false;
8632             }
8633             if ( !p.hasNext() ) {
8634                 return false;
8635             }
8636             final Phylogeny p1_1 = p.next();
8637             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
8638                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
8639                 return false;
8640             }
8641             if ( !p.hasNext() ) {
8642                 return false;
8643             }
8644             final Phylogeny p1_2 = p.next();
8645             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
8646                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
8647                 return false;
8648             }
8649             if ( !p.hasNext() ) {
8650                 return false;
8651             }
8652             final Phylogeny p1_3 = p.next();
8653             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
8654                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
8655                 return false;
8656             }
8657             if ( p.hasNext() ) {
8658                 return false;
8659             }
8660             if ( p.next() != null ) {
8661                 return false;
8662             }
8663             //
8664             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
8665             p.setSource( p2_str );
8666             if ( !p.hasNext() ) {
8667                 return false;
8668             }
8669             Phylogeny p2_0 = p.next();
8670             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8671                 System.out.println( p2_0.toNewHampshire() );
8672                 return false;
8673             }
8674             if ( !p.hasNext() ) {
8675                 return false;
8676             }
8677             Phylogeny p2_1 = p.next();
8678             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8679                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8680                 return false;
8681             }
8682             if ( !p.hasNext() ) {
8683                 return false;
8684             }
8685             Phylogeny p2_2 = p.next();
8686             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8687                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8688                 return false;
8689             }
8690             if ( !p.hasNext() ) {
8691                 return false;
8692             }
8693             Phylogeny p2_3 = p.next();
8694             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8695                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8696                 return false;
8697             }
8698             if ( !p.hasNext() ) {
8699                 return false;
8700             }
8701             Phylogeny p2_4 = p.next();
8702             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8703                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8704                 return false;
8705             }
8706             if ( p.hasNext() ) {
8707                 return false;
8708             }
8709             if ( p.next() != null ) {
8710                 return false;
8711             }
8712             ////
8713             p.reset();
8714             if ( !p.hasNext() ) {
8715                 return false;
8716             }
8717             p2_0 = p.next();
8718             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8719                 System.out.println( p2_0.toNewHampshire() );
8720                 return false;
8721             }
8722             if ( !p.hasNext() ) {
8723                 return false;
8724             }
8725             p2_1 = p.next();
8726             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8727                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8728                 return false;
8729             }
8730             if ( !p.hasNext() ) {
8731                 return false;
8732             }
8733             p2_2 = p.next();
8734             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8735                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8736                 return false;
8737             }
8738             if ( !p.hasNext() ) {
8739                 return false;
8740             }
8741             p2_3 = p.next();
8742             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8743                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8744                 return false;
8745             }
8746             if ( !p.hasNext() ) {
8747                 return false;
8748             }
8749             p2_4 = p.next();
8750             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8751                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8752                 return false;
8753             }
8754             if ( p.hasNext() ) {
8755                 return false;
8756             }
8757             if ( p.next() != null ) {
8758                 return false;
8759             }
8760             //
8761             final String p3_str = "((A,B),C)abc";
8762             p.setSource( p3_str );
8763             if ( !p.hasNext() ) {
8764                 return false;
8765             }
8766             final Phylogeny p3_0 = p.next();
8767             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
8768                 return false;
8769             }
8770             if ( p.hasNext() ) {
8771                 return false;
8772             }
8773             if ( p.next() != null ) {
8774                 return false;
8775             }
8776             //
8777             final String p4_str = "((A,B)ab,C)abc";
8778             p.setSource( p4_str );
8779             if ( !p.hasNext() ) {
8780                 return false;
8781             }
8782             final Phylogeny p4_0 = p.next();
8783             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
8784                 return false;
8785             }
8786             if ( p.hasNext() ) {
8787                 return false;
8788             }
8789             if ( p.next() != null ) {
8790                 return false;
8791             }
8792             //
8793             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
8794             p.setSource( p5_str );
8795             if ( !p.hasNext() ) {
8796                 return false;
8797             }
8798             final Phylogeny p5_0 = p.next();
8799             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
8800                 return false;
8801             }
8802             if ( p.hasNext() ) {
8803                 return false;
8804             }
8805             if ( p.next() != null ) {
8806                 return false;
8807             }
8808             //
8809             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8810             p.setSource( p6_str );
8811             if ( !p.hasNext() ) {
8812                 return false;
8813             }
8814             Phylogeny p6_0 = p.next();
8815             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8816                 return false;
8817             }
8818             if ( p.hasNext() ) {
8819                 return false;
8820             }
8821             if ( p.next() != null ) {
8822                 return false;
8823             }
8824             p.reset();
8825             if ( !p.hasNext() ) {
8826                 return false;
8827             }
8828             p6_0 = p.next();
8829             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8830                 return false;
8831             }
8832             if ( p.hasNext() ) {
8833                 return false;
8834             }
8835             if ( p.next() != null ) {
8836                 return false;
8837             }
8838             //
8839             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8840             p.setSource( p7_str );
8841             if ( !p.hasNext() ) {
8842                 return false;
8843             }
8844             Phylogeny p7_0 = p.next();
8845             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8846                 return false;
8847             }
8848             if ( p.hasNext() ) {
8849                 return false;
8850             }
8851             if ( p.next() != null ) {
8852                 return false;
8853             }
8854             p.reset();
8855             if ( !p.hasNext() ) {
8856                 return false;
8857             }
8858             p7_0 = p.next();
8859             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8860                 return false;
8861             }
8862             if ( p.hasNext() ) {
8863                 return false;
8864             }
8865             if ( p.next() != null ) {
8866                 return false;
8867             }
8868             //
8869             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
8870             p.setSource( p8_str );
8871             if ( !p.hasNext() ) {
8872                 return false;
8873             }
8874             Phylogeny p8_0 = p.next();
8875             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8876                 return false;
8877             }
8878             if ( !p.hasNext() ) {
8879                 return false;
8880             }
8881             if ( !p.hasNext() ) {
8882                 return false;
8883             }
8884             Phylogeny p8_1 = p.next();
8885             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8886                 return false;
8887             }
8888             if ( p.hasNext() ) {
8889                 return false;
8890             }
8891             if ( p.next() != null ) {
8892                 return false;
8893             }
8894             p.reset();
8895             if ( !p.hasNext() ) {
8896                 return false;
8897             }
8898             p8_0 = p.next();
8899             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8900                 return false;
8901             }
8902             if ( !p.hasNext() ) {
8903                 return false;
8904             }
8905             p8_1 = p.next();
8906             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8907                 return false;
8908             }
8909             if ( p.hasNext() ) {
8910                 return false;
8911             }
8912             if ( p.next() != null ) {
8913                 return false;
8914             }
8915             p.reset();
8916             //
8917             p.setSource( "" );
8918             if ( p.hasNext() ) {
8919                 return false;
8920             }
8921             //
8922             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
8923             if ( !p.hasNext() ) {
8924                 return false;
8925             }
8926             Phylogeny p_27 = p.next();
8927             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8928                 System.out.println( p_27.toNewHampshireX() );
8929                 System.exit( -1 );
8930                 return false;
8931             }
8932             if ( p.hasNext() ) {
8933                 return false;
8934             }
8935             if ( p.next() != null ) {
8936                 return false;
8937             }
8938             p.reset();
8939             if ( !p.hasNext() ) {
8940                 return false;
8941             }
8942             p_27 = p.next();
8943             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8944                 System.out.println( p_27.toNewHampshireX() );
8945                 System.exit( -1 );
8946                 return false;
8947             }
8948             if ( p.hasNext() ) {
8949                 return false;
8950             }
8951             if ( p.next() != null ) {
8952                 return false;
8953             }
8954             //
8955             final String p30_str = "(A,B);(C,D)";
8956             final NHXParser p30 = new NHXParser();
8957             p30.setSource( p30_str );
8958             if ( !p30.hasNext() ) {
8959                 return false;
8960             }
8961             Phylogeny phy30 = p30.next();
8962             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8963                 System.out.println( phy30.toNewHampshire() );
8964                 return false;
8965             }
8966             if ( !p30.hasNext() ) {
8967                 return false;
8968             }
8969             Phylogeny phy301 = p30.next();
8970             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8971                 System.out.println( phy301.toNewHampshire() );
8972                 return false;
8973             }
8974             if ( p30.hasNext() ) {
8975                 return false;
8976             }
8977             if ( p30.hasNext() ) {
8978                 return false;
8979             }
8980             if ( p30.next() != null ) {
8981                 return false;
8982             }
8983             if ( p30.next() != null ) {
8984                 return false;
8985             }
8986             p30.reset();
8987             if ( !p30.hasNext() ) {
8988                 return false;
8989             }
8990             phy30 = p30.next();
8991             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8992                 System.out.println( phy30.toNewHampshire() );
8993                 return false;
8994             }
8995             if ( !p30.hasNext() ) {
8996                 return false;
8997             }
8998             phy301 = p30.next();
8999             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
9000                 System.out.println( phy301.toNewHampshire() );
9001                 return false;
9002             }
9003             if ( p30.hasNext() ) {
9004                 return false;
9005             }
9006             if ( p30.hasNext() ) {
9007                 return false;
9008             }
9009             if ( p30.next() != null ) {
9010                 return false;
9011             }
9012             if ( p30.next() != null ) {
9013                 return false;
9014             }
9015         }
9016         catch ( final Exception e ) {
9017             e.printStackTrace( System.out );
9018             return false;
9019         }
9020         return true;
9021     }
9022
9023     private static boolean testNHXconversion() {
9024         try {
9025             final PhylogenyNode n1 = new PhylogenyNode();
9026             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9027             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9028             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9029             final PhylogenyNode n5 = PhylogenyNode
9030                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
9031             final PhylogenyNode n6 = PhylogenyNode
9032                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
9033             if ( !n1.toNewHampshireX().equals( "" ) ) {
9034                 return false;
9035             }
9036             if ( !n2.toNewHampshireX().equals( "" ) ) {
9037                 return false;
9038             }
9039             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
9040                 return false;
9041             }
9042             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
9043                 return false;
9044             }
9045             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
9046                 return false;
9047             }
9048             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
9049                 System.out.println( n6.toNewHampshireX() );
9050                 return false;
9051             }
9052             final PhylogenyNode n7 = new PhylogenyNode();
9053             n7.setName( "   gks:dr-m4 \"    '    `@:[]sadq04 " );
9054             if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
9055                     .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
9056                 System.out.println( n7
9057                                     .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
9058                 return false;
9059             }
9060         }
9061         catch ( final Exception e ) {
9062             e.printStackTrace( System.out );
9063             return false;
9064         }
9065         return true;
9066     }
9067
9068     private static boolean testNHXNodeParsing() {
9069         try {
9070             final PhylogenyNode n1 = new PhylogenyNode();
9071             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9072             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9073             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9074             final PhylogenyNode n5 = PhylogenyNode
9075                     .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]" );
9076             if ( !n3.getName().equals( "n3" ) ) {
9077                 return false;
9078             }
9079             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9080                 return false;
9081             }
9082             if ( n3.isDuplication() ) {
9083                 return false;
9084             }
9085             if ( n3.isHasAssignedEvent() ) {
9086                 return false;
9087             }
9088             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
9089                 return false;
9090             }
9091             if ( !n4.getName().equals( "n4" ) ) {
9092                 return false;
9093             }
9094             if ( n4.getDistanceToParent() != 0.01 ) {
9095                 return false;
9096             }
9097             if ( !n5.getName().equals( "n5" ) ) {
9098                 return false;
9099             }
9100             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
9101                 return false;
9102             }
9103             if ( n5.getDistanceToParent() != 0.1 ) {
9104                 return false;
9105             }
9106             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
9107                 return false;
9108             }
9109             if ( !n5.isDuplication() ) {
9110                 return false;
9111             }
9112             if ( !n5.isHasAssignedEvent() ) {
9113                 return false;
9114             }
9115             final PhylogenyNode n8 = PhylogenyNode
9116                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
9117                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9118             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9119                 return false;
9120             }
9121             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
9122                 return false;
9123             }
9124             final PhylogenyNode n9 = PhylogenyNode
9125                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
9126                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9127             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
9128                 return false;
9129             }
9130             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
9131                 return false;
9132             }
9133             final PhylogenyNode n10 = PhylogenyNode
9134                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9135             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
9136                 return false;
9137             }
9138             final PhylogenyNode n20 = PhylogenyNode
9139                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9140             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9141                 return false;
9142             }
9143             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
9144                 return false;
9145             }
9146             final PhylogenyNode n20x = PhylogenyNode
9147                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9148             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
9149                 return false;
9150             }
9151             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
9152                 return false;
9153             }
9154             final PhylogenyNode n20xx = PhylogenyNode
9155                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9156             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
9157                 return false;
9158             }
9159             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
9160                 return false;
9161             }
9162             final PhylogenyNode n20xxx = PhylogenyNode
9163                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9164             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
9165                 return false;
9166             }
9167             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
9168                 return false;
9169             }
9170             final PhylogenyNode n20xxxx = PhylogenyNode
9171                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9172             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
9173                 return false;
9174             }
9175             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
9176                 return false;
9177             }
9178             final PhylogenyNode n21 = PhylogenyNode
9179                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9180             if ( !n21.getName().equals( "N21_PIG" ) ) {
9181                 return false;
9182             }
9183             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
9184                 return false;
9185             }
9186             final PhylogenyNode n21x = PhylogenyNode
9187                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9188             if ( !n21x.getName().equals( "n21_PIG" ) ) {
9189                 return false;
9190             }
9191             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
9192                 return false;
9193             }
9194             final PhylogenyNode n22 = PhylogenyNode
9195                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9196             if ( !n22.getName().equals( "n22/PIG" ) ) {
9197                 return false;
9198             }
9199             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
9200                 return false;
9201             }
9202             final PhylogenyNode n23 = PhylogenyNode
9203                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9204             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
9205                 return false;
9206             }
9207             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
9208                 return false;
9209             }
9210             final PhylogenyNode a = PhylogenyNode
9211                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9212             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9213                 return false;
9214             }
9215             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
9216                 return false;
9217             }
9218             final PhylogenyNode c1 = PhylogenyNode
9219                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
9220                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9221             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
9222                 return false;
9223             }
9224             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
9225                 return false;
9226             }
9227             final PhylogenyNode c2 = PhylogenyNode
9228                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
9229                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9230             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
9231                 return false;
9232             }
9233             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
9234                 return false;
9235             }
9236             final PhylogenyNode e3 = PhylogenyNode
9237                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9238             if ( !e3.getName().equals( "n10_RAT~" ) ) {
9239                 return false;
9240             }
9241             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
9242                 return false;
9243             }
9244             final PhylogenyNode n11 = PhylogenyNode
9245                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
9246                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9247             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
9248                 return false;
9249             }
9250             if ( n11.getDistanceToParent() != 0.4 ) {
9251                 return false;
9252             }
9253             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
9254                 return false;
9255             }
9256             final PhylogenyNode n12 = PhylogenyNode
9257                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
9258                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9259             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
9260                 return false;
9261             }
9262             if ( n12.getDistanceToParent() != 0.4 ) {
9263                 return false;
9264             }
9265             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
9266                 return false;
9267             }
9268             final PhylogenyNode o = PhylogenyNode
9269                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9270             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
9271                 return false;
9272             }
9273             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
9274                 return false;
9275             }
9276             if ( n1.getName().compareTo( "" ) != 0 ) {
9277                 return false;
9278             }
9279             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9280                 return false;
9281             }
9282             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9283                 return false;
9284             }
9285             if ( n2.getName().compareTo( "" ) != 0 ) {
9286                 return false;
9287             }
9288             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9289                 return false;
9290             }
9291             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9292                 return false;
9293             }
9294             final PhylogenyNode n00 = PhylogenyNode
9295                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
9296             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
9297                 return false;
9298             }
9299             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
9300                 return false;
9301             }
9302             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
9303             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
9304                 return false;
9305             }
9306             final PhylogenyNode n13 = PhylogenyNode
9307                     .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9308             if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
9309                 return false;
9310             }
9311             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
9312                 return false;
9313             }
9314             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9315                 return false;
9316             }
9317             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9318                 return false;
9319             }
9320             final PhylogenyNode n14 = PhylogenyNode
9321                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9322             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
9323                 return false;
9324             }
9325             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
9326                 return false;
9327             }
9328             final PhylogenyNode n15 = PhylogenyNode
9329                     .createInstanceFromNhxString( "something_wicked[123]",
9330                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9331             if ( !n15.getName().equals( "something_wicked" ) ) {
9332                 return false;
9333             }
9334             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
9335                 return false;
9336             }
9337             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
9338                 return false;
9339             }
9340             final PhylogenyNode n16 = PhylogenyNode
9341                     .createInstanceFromNhxString( "something_wicked2[9]",
9342                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9343             if ( !n16.getName().equals( "something_wicked2" ) ) {
9344                 return false;
9345             }
9346             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
9347                 return false;
9348             }
9349             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
9350                 return false;
9351             }
9352             final PhylogenyNode n17 = PhylogenyNode
9353                     .createInstanceFromNhxString( "something_wicked3[a]",
9354                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9355             if ( !n17.getName().equals( "something_wicked3" ) ) {
9356                 return false;
9357             }
9358             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
9359                 return false;
9360             }
9361             final PhylogenyNode n18 = PhylogenyNode
9362                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9363             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
9364                 return false;
9365             }
9366             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
9367                 return false;
9368             }
9369             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
9370                 return false;
9371             }
9372             final PhylogenyNode n19 = PhylogenyNode
9373                     .createInstanceFromNhxString( "BLAH_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9374             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
9375                 return false;
9376             }
9377             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9378                 return false;
9379             }
9380             final PhylogenyNode n30 = PhylogenyNode
9381                     .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
9382                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9383             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
9384                 return false;
9385             }
9386             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9387                 return false;
9388             }
9389             final PhylogenyNode n31 = PhylogenyNode
9390                     .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
9391                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9392             if ( n31.getNodeData().isHasTaxonomy() ) {
9393                 return false;
9394             }
9395             final PhylogenyNode n32 = PhylogenyNode
9396                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9397             if ( n32.getNodeData().isHasTaxonomy() ) {
9398                 return false;
9399             }
9400             final PhylogenyNode n40 = PhylogenyNode
9401                     .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9402             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9403                 return false;
9404             }
9405             final PhylogenyNode n41 = PhylogenyNode
9406                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9407             if ( n41.getNodeData().isHasTaxonomy() ) {
9408                 return false;
9409             }
9410             final PhylogenyNode n42 = PhylogenyNode
9411                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9412             if ( n42.getNodeData().isHasTaxonomy() ) {
9413                 return false;
9414             }
9415             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
9416                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
9417             if ( n43.getNodeData().isHasTaxonomy() ) {
9418                 return false;
9419             }
9420             final PhylogenyNode n44 = PhylogenyNode
9421                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9422             if ( n44.getNodeData().isHasTaxonomy() ) {
9423                 return false;
9424             }
9425         }
9426         catch ( final Exception e ) {
9427             e.printStackTrace( System.out );
9428             return false;
9429         }
9430         return true;
9431     }
9432
9433     private static boolean testNHXParsing() {
9434         try {
9435             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9436             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
9437             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
9438                 return false;
9439             }
9440             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]";
9441             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
9442             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9443                 return false;
9444             }
9445             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]";
9446             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
9447             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
9448                 return false;
9449             }
9450             final Phylogeny[] p3 = factory
9451                     .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]",
9452                              new NHXParser() );
9453             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9454                 return false;
9455             }
9456             final Phylogeny[] p4 = factory
9457                     .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(]",
9458                              new NHXParser() );
9459             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9460                 return false;
9461             }
9462             final Phylogeny[] p5 = factory
9463                     .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(((]",
9464                              new NHXParser() );
9465             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9466                 return false;
9467             }
9468             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)";
9469             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)";
9470             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
9471             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
9472                 return false;
9473             }
9474             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)))";
9475             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)))";
9476             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
9477             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
9478                 return false;
9479             }
9480             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])   ))[,,, ])))))))";
9481             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
9482             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
9483             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
9484                 return false;
9485             }
9486             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
9487             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9488                 return false;
9489             }
9490             final Phylogeny p10 = factory
9491                     .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]",
9492                              new NHXParser() )[ 0 ];
9493             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9494                 return false;
9495             }
9496             final Phylogeny p11 = factory
9497                     .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]",
9498                              new NHXParser() )[ 0 ];
9499             if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9500                 return false;
9501             }
9502             final Phylogeny p12 = factory.create( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]",
9503                                                   new NHXParser() )[ 0 ];
9504             if ( !p12.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9505                 return false;
9506             }
9507         }
9508         catch ( final Exception e ) {
9509             e.printStackTrace( System.out );
9510             return false;
9511         }
9512         return true;
9513     }
9514
9515     private static boolean testNHXParsingMB() {
9516         try {
9517             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9518             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
9519                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9520                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9521                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9522                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9523                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9524                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9525                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9526                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
9527             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
9528                 return false;
9529             }
9530             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
9531                 return false;
9532             }
9533             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
9534                            0.1100000000000000e+00 ) ) {
9535                 return false;
9536             }
9537             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
9538                 return false;
9539             }
9540             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
9541                 return false;
9542             }
9543             final Phylogeny p2 = factory
9544                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
9545                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9546                             + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9547                             + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9548                             + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9549                             + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9550                             + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9551                             + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9552                             + "7.369400000000000e-02}])",
9553                             new NHXParser() )[ 0 ];
9554             if ( p2.getNode( "1" ) == null ) {
9555                 return false;
9556             }
9557             if ( p2.getNode( "2" ) == null ) {
9558                 return false;
9559             }
9560         }
9561         catch ( final Exception e ) {
9562             e.printStackTrace( System.out );
9563             System.exit( -1 );
9564             return false;
9565         }
9566         return true;
9567     }
9568
9569     private static boolean testNHXParsingQuotes() {
9570         try {
9571             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9572             final NHXParser p = new NHXParser();
9573             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
9574             if ( phylogenies_0.length != 5 ) {
9575                 return false;
9576             }
9577             final Phylogeny phy = phylogenies_0[ 4 ];
9578             if ( phy.getNumberOfExternalNodes() != 7 ) {
9579                 return false;
9580             }
9581             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
9582                 return false;
9583             }
9584             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
9585                 return false;
9586             }
9587             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
9588                     .getScientificName().equals( "hsapiens" ) ) {
9589                 return false;
9590             }
9591             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
9592                 return false;
9593             }
9594             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
9595                 return false;
9596             }
9597             if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
9598                 return false;
9599             }
9600             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
9601                 return false;
9602             }
9603             if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
9604                 return false;
9605             }
9606             final NHXParser p1p = new NHXParser();
9607             p1p.setIgnoreQuotes( true );
9608             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
9609             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
9610                 return false;
9611             }
9612             final NHXParser p2p = new NHXParser();
9613             p1p.setIgnoreQuotes( false );
9614             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
9615             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
9616                 return false;
9617             }
9618             final NHXParser p3p = new NHXParser();
9619             p3p.setIgnoreQuotes( false );
9620             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
9621             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
9622                 return false;
9623             }
9624             final NHXParser p4p = new NHXParser();
9625             p4p.setIgnoreQuotes( false );
9626             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
9627             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
9628                 return false;
9629             }
9630             final Phylogeny p10 = factory
9631                     .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]",
9632                              new NHXParser() )[ 0 ];
9633             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]";
9634             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
9635                 return false;
9636             }
9637             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
9638             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
9639                 return false;
9640             }
9641             final Phylogeny p12 = factory
9642                     .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]",
9643                              new NHXParser() )[ 0 ];
9644             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]";
9645             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
9646                 return false;
9647             }
9648             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
9649             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
9650                 return false;
9651             }
9652             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;";
9653             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
9654                 return false;
9655             }
9656             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
9657             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
9658                 return false;
9659             }
9660         }
9661         catch ( final Exception e ) {
9662             e.printStackTrace( System.out );
9663             return false;
9664         }
9665         return true;
9666     }
9667
9668     private static boolean testNodeRemoval() {
9669         try {
9670             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9671             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
9672             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
9673             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
9674                 return false;
9675             }
9676             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
9677             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
9678             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
9679                 return false;
9680             }
9681             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
9682             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
9683             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
9684                 return false;
9685             }
9686         }
9687         catch ( final Exception e ) {
9688             e.printStackTrace( System.out );
9689             return false;
9690         }
9691         return true;
9692     }
9693
9694     private static boolean testPhylogenyBranch() {
9695         try {
9696             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
9697             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
9698             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
9699             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
9700             if ( !a1b1.equals( a1b1 ) ) {
9701                 return false;
9702             }
9703             if ( !a1b1.equals( b1a1 ) ) {
9704                 return false;
9705             }
9706             if ( !b1a1.equals( a1b1 ) ) {
9707                 return false;
9708             }
9709             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
9710             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
9711             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
9712             if ( a1_b1.equals( b1_a1 ) ) {
9713                 return false;
9714             }
9715             if ( a1_b1.equals( a1_b1_ ) ) {
9716                 return false;
9717             }
9718             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
9719             if ( !a1_b1.equals( b1_a1_ ) ) {
9720                 return false;
9721             }
9722             if ( a1_b1_.equals( b1_a1_ ) ) {
9723                 return false;
9724             }
9725             if ( !a1_b1_.equals( b1_a1 ) ) {
9726                 return false;
9727             }
9728         }
9729         catch ( final Exception e ) {
9730             e.printStackTrace( System.out );
9731             return false;
9732         }
9733         return true;
9734     }
9735
9736     private static boolean testPhyloXMLparsingOfDistributionElement() {
9737         try {
9738             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9739             PhyloXmlParser xml_parser = null;
9740             try {
9741                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
9742             }
9743             catch ( final Exception e ) {
9744                 // Do nothing -- means were not running from jar.
9745             }
9746             if ( xml_parser == null ) {
9747                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
9748                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
9749                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
9750                 }
9751                 else {
9752                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
9753                 }
9754             }
9755             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
9756                                                               xml_parser );
9757             if ( xml_parser.getErrorCount() > 0 ) {
9758                 System.out.println( xml_parser.getErrorMessages().toString() );
9759                 return false;
9760             }
9761             if ( phylogenies_0.length != 1 ) {
9762                 return false;
9763             }
9764             final Phylogeny t1 = phylogenies_0[ 0 ];
9765             PhylogenyNode n = null;
9766             Distribution d = null;
9767             n = t1.getNode( "root node" );
9768             if ( !n.getNodeData().isHasDistribution() ) {
9769                 return false;
9770             }
9771             if ( n.getNodeData().getDistributions().size() != 1 ) {
9772                 return false;
9773             }
9774             d = n.getNodeData().getDistribution();
9775             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9776                 return false;
9777             }
9778             if ( d.getPoints().size() != 1 ) {
9779                 return false;
9780             }
9781             if ( d.getPolygons() != null ) {
9782                 return false;
9783             }
9784             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9785                 return false;
9786             }
9787             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9788                 return false;
9789             }
9790             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9791                 return false;
9792             }
9793             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9794                 return false;
9795             }
9796             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9797                 return false;
9798             }
9799             n = t1.getNode( "node a" );
9800             if ( !n.getNodeData().isHasDistribution() ) {
9801                 return false;
9802             }
9803             if ( n.getNodeData().getDistributions().size() != 2 ) {
9804                 return false;
9805             }
9806             d = n.getNodeData().getDistribution( 1 );
9807             if ( !d.getDesc().equals( "San Diego" ) ) {
9808                 return false;
9809             }
9810             if ( d.getPoints().size() != 1 ) {
9811                 return false;
9812             }
9813             if ( d.getPolygons() != null ) {
9814                 return false;
9815             }
9816             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9817                 return false;
9818             }
9819             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9820                 return false;
9821             }
9822             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9823                 return false;
9824             }
9825             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9826                 return false;
9827             }
9828             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9829                 return false;
9830             }
9831             n = t1.getNode( "node bb" );
9832             if ( !n.getNodeData().isHasDistribution() ) {
9833                 return false;
9834             }
9835             if ( n.getNodeData().getDistributions().size() != 1 ) {
9836                 return false;
9837             }
9838             d = n.getNodeData().getDistribution( 0 );
9839             if ( d.getPoints().size() != 3 ) {
9840                 return false;
9841             }
9842             if ( d.getPolygons().size() != 2 ) {
9843                 return false;
9844             }
9845             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9846                 return false;
9847             }
9848             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9849                 return false;
9850             }
9851             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9852                 return false;
9853             }
9854             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9855                 return false;
9856             }
9857             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9858                 return false;
9859             }
9860             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9861                 return false;
9862             }
9863             Polygon p = d.getPolygons().get( 0 );
9864             if ( p.getPoints().size() != 3 ) {
9865                 return false;
9866             }
9867             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9868                 return false;
9869             }
9870             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9871                 return false;
9872             }
9873             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9874                 return false;
9875             }
9876             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9877                 return false;
9878             }
9879             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9880                 return false;
9881             }
9882             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9883                 return false;
9884             }
9885             p = d.getPolygons().get( 1 );
9886             if ( p.getPoints().size() != 3 ) {
9887                 return false;
9888             }
9889             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9890                 return false;
9891             }
9892             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9893                 return false;
9894             }
9895             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9896                 return false;
9897             }
9898             // Roundtrip:
9899             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
9900             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
9901             if ( rt.length != 1 ) {
9902                 return false;
9903             }
9904             final Phylogeny t1_rt = rt[ 0 ];
9905             n = t1_rt.getNode( "root node" );
9906             if ( !n.getNodeData().isHasDistribution() ) {
9907                 return false;
9908             }
9909             if ( n.getNodeData().getDistributions().size() != 1 ) {
9910                 return false;
9911             }
9912             d = n.getNodeData().getDistribution();
9913             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9914                 return false;
9915             }
9916             if ( d.getPoints().size() != 1 ) {
9917                 return false;
9918             }
9919             if ( d.getPolygons() != null ) {
9920                 return false;
9921             }
9922             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9923                 return false;
9924             }
9925             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9926                 return false;
9927             }
9928             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9929                 return false;
9930             }
9931             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9932                 return false;
9933             }
9934             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9935                 return false;
9936             }
9937             n = t1_rt.getNode( "node a" );
9938             if ( !n.getNodeData().isHasDistribution() ) {
9939                 return false;
9940             }
9941             if ( n.getNodeData().getDistributions().size() != 2 ) {
9942                 return false;
9943             }
9944             d = n.getNodeData().getDistribution( 1 );
9945             if ( !d.getDesc().equals( "San Diego" ) ) {
9946                 return false;
9947             }
9948             if ( d.getPoints().size() != 1 ) {
9949                 return false;
9950             }
9951             if ( d.getPolygons() != null ) {
9952                 return false;
9953             }
9954             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9955                 return false;
9956             }
9957             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9958                 return false;
9959             }
9960             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9961                 return false;
9962             }
9963             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9964                 return false;
9965             }
9966             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9967                 return false;
9968             }
9969             n = t1_rt.getNode( "node bb" );
9970             if ( !n.getNodeData().isHasDistribution() ) {
9971                 return false;
9972             }
9973             if ( n.getNodeData().getDistributions().size() != 1 ) {
9974                 return false;
9975             }
9976             d = n.getNodeData().getDistribution( 0 );
9977             if ( d.getPoints().size() != 3 ) {
9978                 return false;
9979             }
9980             if ( d.getPolygons().size() != 2 ) {
9981                 return false;
9982             }
9983             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9984                 return false;
9985             }
9986             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9987                 return false;
9988             }
9989             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9990                 return false;
9991             }
9992             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9993                 return false;
9994             }
9995             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9996                 return false;
9997             }
9998             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9999                 return false;
10000             }
10001             p = d.getPolygons().get( 0 );
10002             if ( p.getPoints().size() != 3 ) {
10003                 return false;
10004             }
10005             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
10006                 return false;
10007             }
10008             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
10009                 return false;
10010             }
10011             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10012                 return false;
10013             }
10014             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
10015                 return false;
10016             }
10017             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
10018                 return false;
10019             }
10020             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
10021                 return false;
10022             }
10023             p = d.getPolygons().get( 1 );
10024             if ( p.getPoints().size() != 3 ) {
10025                 return false;
10026             }
10027             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
10028                 return false;
10029             }
10030             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
10031                 return false;
10032             }
10033             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10034                 return false;
10035             }
10036         }
10037         catch ( final Exception e ) {
10038             e.printStackTrace( System.out );
10039             return false;
10040         }
10041         return true;
10042     }
10043
10044     private static boolean testPostOrderIterator() {
10045         try {
10046             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10047             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10048             PhylogenyNodeIterator it0;
10049             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
10050                 it0.next();
10051             }
10052             for( it0.reset(); it0.hasNext(); ) {
10053                 it0.next();
10054             }
10055             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10056             final PhylogenyNodeIterator it = t1.iteratorPostorder();
10057             if ( !it.next().getName().equals( "A" ) ) {
10058                 return false;
10059             }
10060             if ( !it.next().getName().equals( "B" ) ) {
10061                 return false;
10062             }
10063             if ( !it.next().getName().equals( "ab" ) ) {
10064                 return false;
10065             }
10066             if ( !it.next().getName().equals( "C" ) ) {
10067                 return false;
10068             }
10069             if ( !it.next().getName().equals( "D" ) ) {
10070                 return false;
10071             }
10072             if ( !it.next().getName().equals( "cd" ) ) {
10073                 return false;
10074             }
10075             if ( !it.next().getName().equals( "abcd" ) ) {
10076                 return false;
10077             }
10078             if ( !it.next().getName().equals( "E" ) ) {
10079                 return false;
10080             }
10081             if ( !it.next().getName().equals( "F" ) ) {
10082                 return false;
10083             }
10084             if ( !it.next().getName().equals( "ef" ) ) {
10085                 return false;
10086             }
10087             if ( !it.next().getName().equals( "G" ) ) {
10088                 return false;
10089             }
10090             if ( !it.next().getName().equals( "H" ) ) {
10091                 return false;
10092             }
10093             if ( !it.next().getName().equals( "gh" ) ) {
10094                 return false;
10095             }
10096             if ( !it.next().getName().equals( "efgh" ) ) {
10097                 return false;
10098             }
10099             if ( !it.next().getName().equals( "r" ) ) {
10100                 return false;
10101             }
10102             if ( it.hasNext() ) {
10103                 return false;
10104             }
10105         }
10106         catch ( final Exception e ) {
10107             e.printStackTrace( System.out );
10108             return false;
10109         }
10110         return true;
10111     }
10112
10113     private static boolean testPreOrderIterator() {
10114         try {
10115             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10116             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10117             PhylogenyNodeIterator it0;
10118             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
10119                 it0.next();
10120             }
10121             for( it0.reset(); it0.hasNext(); ) {
10122                 it0.next();
10123             }
10124             PhylogenyNodeIterator it = t0.iteratorPreorder();
10125             if ( !it.next().getName().equals( "r" ) ) {
10126                 return false;
10127             }
10128             if ( !it.next().getName().equals( "ab" ) ) {
10129                 return false;
10130             }
10131             if ( !it.next().getName().equals( "A" ) ) {
10132                 return false;
10133             }
10134             if ( !it.next().getName().equals( "B" ) ) {
10135                 return false;
10136             }
10137             if ( !it.next().getName().equals( "cd" ) ) {
10138                 return false;
10139             }
10140             if ( !it.next().getName().equals( "C" ) ) {
10141                 return false;
10142             }
10143             if ( !it.next().getName().equals( "D" ) ) {
10144                 return false;
10145             }
10146             if ( it.hasNext() ) {
10147                 return false;
10148             }
10149             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10150             it = t1.iteratorPreorder();
10151             if ( !it.next().getName().equals( "r" ) ) {
10152                 return false;
10153             }
10154             if ( !it.next().getName().equals( "abcd" ) ) {
10155                 return false;
10156             }
10157             if ( !it.next().getName().equals( "ab" ) ) {
10158                 return false;
10159             }
10160             if ( !it.next().getName().equals( "A" ) ) {
10161                 return false;
10162             }
10163             if ( !it.next().getName().equals( "B" ) ) {
10164                 return false;
10165             }
10166             if ( !it.next().getName().equals( "cd" ) ) {
10167                 return false;
10168             }
10169             if ( !it.next().getName().equals( "C" ) ) {
10170                 return false;
10171             }
10172             if ( !it.next().getName().equals( "D" ) ) {
10173                 return false;
10174             }
10175             if ( !it.next().getName().equals( "efgh" ) ) {
10176                 return false;
10177             }
10178             if ( !it.next().getName().equals( "ef" ) ) {
10179                 return false;
10180             }
10181             if ( !it.next().getName().equals( "E" ) ) {
10182                 return false;
10183             }
10184             if ( !it.next().getName().equals( "F" ) ) {
10185                 return false;
10186             }
10187             if ( !it.next().getName().equals( "gh" ) ) {
10188                 return false;
10189             }
10190             if ( !it.next().getName().equals( "G" ) ) {
10191                 return false;
10192             }
10193             if ( !it.next().getName().equals( "H" ) ) {
10194                 return false;
10195             }
10196             if ( it.hasNext() ) {
10197                 return false;
10198             }
10199         }
10200         catch ( final Exception e ) {
10201             e.printStackTrace( System.out );
10202             return false;
10203         }
10204         return true;
10205     }
10206
10207     private static boolean testPropertiesMap() {
10208         try {
10209             final PropertiesMap pm = new PropertiesMap();
10210             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10211             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10212             final Property p2 = new Property( "something:else",
10213                                               "?",
10214                                               "improbable:research",
10215                                               "xsd:decimal",
10216                                               AppliesTo.NODE );
10217             pm.addProperty( p0 );
10218             pm.addProperty( p1 );
10219             pm.addProperty( p2 );
10220             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
10221                 return false;
10222             }
10223             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
10224                 return false;
10225             }
10226             if ( pm.getProperties().size() != 3 ) {
10227                 return false;
10228             }
10229             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
10230                 return false;
10231             }
10232             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10233                 return false;
10234             }
10235             if ( pm.getProperties().size() != 3 ) {
10236                 return false;
10237             }
10238             pm.removeProperty( "dimensions:diameter" );
10239             if ( pm.getProperties().size() != 2 ) {
10240                 return false;
10241             }
10242             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
10243                 return false;
10244             }
10245             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10246                 return false;
10247             }
10248         }
10249         catch ( final Exception e ) {
10250             e.printStackTrace( System.out );
10251             return false;
10252         }
10253         return true;
10254     }
10255
10256     private static boolean testProteinId() {
10257         try {
10258             final ProteinId id1 = new ProteinId( "a" );
10259             final ProteinId id2 = new ProteinId( "a" );
10260             final ProteinId id3 = new ProteinId( "A" );
10261             final ProteinId id4 = new ProteinId( "b" );
10262             if ( !id1.equals( id1 ) ) {
10263                 return false;
10264             }
10265             if ( id1.getId().equals( "x" ) ) {
10266                 return false;
10267             }
10268             if ( id1.getId().equals( null ) ) {
10269                 return false;
10270             }
10271             if ( !id1.equals( id2 ) ) {
10272                 return false;
10273             }
10274             if ( id1.equals( id3 ) ) {
10275                 return false;
10276             }
10277             if ( id1.hashCode() != id1.hashCode() ) {
10278                 return false;
10279             }
10280             if ( id1.hashCode() != id2.hashCode() ) {
10281                 return false;
10282             }
10283             if ( id1.hashCode() == id3.hashCode() ) {
10284                 return false;
10285             }
10286             if ( id1.compareTo( id1 ) != 0 ) {
10287                 return false;
10288             }
10289             if ( id1.compareTo( id2 ) != 0 ) {
10290                 return false;
10291             }
10292             if ( id1.compareTo( id3 ) != 0 ) {
10293                 return false;
10294             }
10295             if ( id1.compareTo( id4 ) >= 0 ) {
10296                 return false;
10297             }
10298             if ( id4.compareTo( id1 ) <= 0 ) {
10299                 return false;
10300             }
10301             if ( !id4.getId().equals( "b" ) ) {
10302                 return false;
10303             }
10304             final ProteinId id5 = new ProteinId( " C " );
10305             if ( !id5.getId().equals( "C" ) ) {
10306                 return false;
10307             }
10308             if ( id5.equals( id1 ) ) {
10309                 return false;
10310             }
10311         }
10312         catch ( final Exception e ) {
10313             e.printStackTrace( System.out );
10314             return false;
10315         }
10316         return true;
10317     }
10318
10319     private static boolean testReIdMethods() {
10320         try {
10321             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10322             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
10323             final long count = PhylogenyNode.getNodeCount();
10324             p.levelOrderReID();
10325             if ( p.getNode( "r" ).getId() != count ) {
10326                 return false;
10327             }
10328             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
10329                 return false;
10330             }
10331             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
10332                 return false;
10333             }
10334             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
10335                 return false;
10336             }
10337             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
10338                 return false;
10339             }
10340             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
10341                 return false;
10342             }
10343             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
10344                 return false;
10345             }
10346             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
10347                 return false;
10348             }
10349             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
10350                 return false;
10351             }
10352             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
10353                 return false;
10354             }
10355             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
10356                 return false;
10357             }
10358             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
10359                 return false;
10360             }
10361             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
10362                 return false;
10363             }
10364             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
10365                 return false;
10366             }
10367             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
10368                 return false;
10369             }
10370         }
10371         catch ( final Exception e ) {
10372             e.printStackTrace( System.out );
10373             return false;
10374         }
10375         return true;
10376     }
10377
10378     private static boolean testRerooting() {
10379         try {
10380             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10381             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",
10382                                                  new NHXParser() )[ 0 ];
10383             if ( !t1.isRooted() ) {
10384                 return false;
10385             }
10386             t1.reRoot( t1.getNode( "D" ) );
10387             t1.reRoot( t1.getNode( "CD" ) );
10388             t1.reRoot( t1.getNode( "A" ) );
10389             t1.reRoot( t1.getNode( "B" ) );
10390             t1.reRoot( t1.getNode( "AB" ) );
10391             t1.reRoot( t1.getNode( "D" ) );
10392             t1.reRoot( t1.getNode( "C" ) );
10393             t1.reRoot( t1.getNode( "CD" ) );
10394             t1.reRoot( t1.getNode( "A" ) );
10395             t1.reRoot( t1.getNode( "B" ) );
10396             t1.reRoot( t1.getNode( "AB" ) );
10397             t1.reRoot( t1.getNode( "D" ) );
10398             t1.reRoot( t1.getNode( "D" ) );
10399             t1.reRoot( t1.getNode( "C" ) );
10400             t1.reRoot( t1.getNode( "A" ) );
10401             t1.reRoot( t1.getNode( "B" ) );
10402             t1.reRoot( t1.getNode( "AB" ) );
10403             t1.reRoot( t1.getNode( "C" ) );
10404             t1.reRoot( t1.getNode( "D" ) );
10405             t1.reRoot( t1.getNode( "CD" ) );
10406             t1.reRoot( t1.getNode( "D" ) );
10407             t1.reRoot( t1.getNode( "A" ) );
10408             t1.reRoot( t1.getNode( "B" ) );
10409             t1.reRoot( t1.getNode( "AB" ) );
10410             t1.reRoot( t1.getNode( "C" ) );
10411             t1.reRoot( t1.getNode( "D" ) );
10412             t1.reRoot( t1.getNode( "CD" ) );
10413             t1.reRoot( t1.getNode( "D" ) );
10414             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
10415                 return false;
10416             }
10417             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
10418                 return false;
10419             }
10420             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
10421                 return false;
10422             }
10423             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
10424                 return false;
10425             }
10426             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
10427                 return false;
10428             }
10429             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
10430                 return false;
10431             }
10432             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",
10433                                                  new NHXParser() )[ 0 ];
10434             t2.reRoot( t2.getNode( "A" ) );
10435             t2.reRoot( t2.getNode( "D" ) );
10436             t2.reRoot( t2.getNode( "ABC" ) );
10437             t2.reRoot( t2.getNode( "A" ) );
10438             t2.reRoot( t2.getNode( "B" ) );
10439             t2.reRoot( t2.getNode( "D" ) );
10440             t2.reRoot( t2.getNode( "C" ) );
10441             t2.reRoot( t2.getNode( "ABC" ) );
10442             t2.reRoot( t2.getNode( "A" ) );
10443             t2.reRoot( t2.getNode( "B" ) );
10444             t2.reRoot( t2.getNode( "AB" ) );
10445             t2.reRoot( t2.getNode( "AB" ) );
10446             t2.reRoot( t2.getNode( "D" ) );
10447             t2.reRoot( t2.getNode( "C" ) );
10448             t2.reRoot( t2.getNode( "B" ) );
10449             t2.reRoot( t2.getNode( "AB" ) );
10450             t2.reRoot( t2.getNode( "D" ) );
10451             t2.reRoot( t2.getNode( "D" ) );
10452             t2.reRoot( t2.getNode( "ABC" ) );
10453             t2.reRoot( t2.getNode( "A" ) );
10454             t2.reRoot( t2.getNode( "B" ) );
10455             t2.reRoot( t2.getNode( "AB" ) );
10456             t2.reRoot( t2.getNode( "D" ) );
10457             t2.reRoot( t2.getNode( "C" ) );
10458             t2.reRoot( t2.getNode( "ABC" ) );
10459             t2.reRoot( t2.getNode( "A" ) );
10460             t2.reRoot( t2.getNode( "B" ) );
10461             t2.reRoot( t2.getNode( "AB" ) );
10462             t2.reRoot( t2.getNode( "D" ) );
10463             t2.reRoot( t2.getNode( "D" ) );
10464             t2.reRoot( t2.getNode( "C" ) );
10465             t2.reRoot( t2.getNode( "A" ) );
10466             t2.reRoot( t2.getNode( "B" ) );
10467             t2.reRoot( t2.getNode( "AB" ) );
10468             t2.reRoot( t2.getNode( "C" ) );
10469             t2.reRoot( t2.getNode( "D" ) );
10470             t2.reRoot( t2.getNode( "ABC" ) );
10471             t2.reRoot( t2.getNode( "D" ) );
10472             t2.reRoot( t2.getNode( "A" ) );
10473             t2.reRoot( t2.getNode( "B" ) );
10474             t2.reRoot( t2.getNode( "AB" ) );
10475             t2.reRoot( t2.getNode( "C" ) );
10476             t2.reRoot( t2.getNode( "D" ) );
10477             t2.reRoot( t2.getNode( "ABC" ) );
10478             t2.reRoot( t2.getNode( "D" ) );
10479             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10480                 return false;
10481             }
10482             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10483                 return false;
10484             }
10485             t2.reRoot( t2.getNode( "ABC" ) );
10486             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10487                 return false;
10488             }
10489             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10490                 return false;
10491             }
10492             t2.reRoot( t2.getNode( "AB" ) );
10493             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10494                 return false;
10495             }
10496             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10497                 return false;
10498             }
10499             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10500                 return false;
10501             }
10502             t2.reRoot( t2.getNode( "AB" ) );
10503             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10504                 return false;
10505             }
10506             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10507                 return false;
10508             }
10509             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10510                 return false;
10511             }
10512             t2.reRoot( t2.getNode( "D" ) );
10513             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10514                 return false;
10515             }
10516             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10517                 return false;
10518             }
10519             t2.reRoot( t2.getNode( "ABC" ) );
10520             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10521                 return false;
10522             }
10523             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10524                 return false;
10525             }
10526             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
10527                                                  new NHXParser() )[ 0 ];
10528             t3.reRoot( t3.getNode( "B" ) );
10529             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10530                 return false;
10531             }
10532             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10533                 return false;
10534             }
10535             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10536                 return false;
10537             }
10538             t3.reRoot( t3.getNode( "B" ) );
10539             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10540                 return false;
10541             }
10542             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10543                 return false;
10544             }
10545             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10546                 return false;
10547             }
10548             t3.reRoot( t3.getRoot() );
10549             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10550                 return false;
10551             }
10552             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10553                 return false;
10554             }
10555             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10556                 return false;
10557             }
10558         }
10559         catch ( final Exception e ) {
10560             e.printStackTrace( System.out );
10561             return false;
10562         }
10563         return true;
10564     }
10565
10566     private static boolean testSDIse() {
10567         try {
10568             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10569             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
10570             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
10571             gene1.setRooted( true );
10572             species1.setRooted( true );
10573             final SDI sdi = new SDI( gene1, species1 );
10574             if ( !gene1.getRoot().isDuplication() ) {
10575                 return false;
10576             }
10577             final Phylogeny species2 = factory
10578                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10579                              new NHXParser() )[ 0 ];
10580             final Phylogeny gene2 = factory
10581                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10582                              new NHXParser() )[ 0 ];
10583             species2.setRooted( true );
10584             gene2.setRooted( true );
10585             final SDI sdi2 = new SDI( gene2, species2 );
10586             if ( sdi2.getDuplicationsSum() != 0 ) {
10587                 return false;
10588             }
10589             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
10590                 return false;
10591             }
10592             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
10593                 return false;
10594             }
10595             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
10596                 return false;
10597             }
10598             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
10599                 return false;
10600             }
10601             if ( !gene2.getNode( "r" ).isSpeciation() ) {
10602                 return false;
10603             }
10604             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
10605                 return false;
10606             }
10607             final Phylogeny species3 = factory
10608                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10609                              new NHXParser() )[ 0 ];
10610             final Phylogeny gene3 = factory
10611                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10612                              new NHXParser() )[ 0 ];
10613             species3.setRooted( true );
10614             gene3.setRooted( true );
10615             final SDI sdi3 = new SDI( gene3, species3 );
10616             if ( sdi3.getDuplicationsSum() != 1 ) {
10617                 return false;
10618             }
10619             if ( !gene3.getNode( "aa" ).isDuplication() ) {
10620                 return false;
10621             }
10622             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
10623                 return false;
10624             }
10625             final Phylogeny species4 = factory
10626                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10627                              new NHXParser() )[ 0 ];
10628             final Phylogeny gene4 = factory
10629                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10630                              new NHXParser() )[ 0 ];
10631             species4.setRooted( true );
10632             gene4.setRooted( true );
10633             final SDI sdi4 = new SDI( gene4, species4 );
10634             if ( sdi4.getDuplicationsSum() != 1 ) {
10635                 return false;
10636             }
10637             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
10638                 return false;
10639             }
10640             if ( !gene4.getNode( "abc" ).isDuplication() ) {
10641                 return false;
10642             }
10643             if ( gene4.getNode( "abcd" ).isDuplication() ) {
10644                 return false;
10645             }
10646             if ( species4.getNumberOfExternalNodes() != 6 ) {
10647                 return false;
10648             }
10649             if ( gene4.getNumberOfExternalNodes() != 6 ) {
10650                 return false;
10651             }
10652             final Phylogeny species5 = factory
10653                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10654                              new NHXParser() )[ 0 ];
10655             final Phylogeny gene5 = factory
10656                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10657                              new NHXParser() )[ 0 ];
10658             species5.setRooted( true );
10659             gene5.setRooted( true );
10660             final SDI sdi5 = new SDI( gene5, species5 );
10661             if ( sdi5.getDuplicationsSum() != 2 ) {
10662                 return false;
10663             }
10664             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
10665                 return false;
10666             }
10667             if ( !gene5.getNode( "adc" ).isDuplication() ) {
10668                 return false;
10669             }
10670             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
10671                 return false;
10672             }
10673             if ( species5.getNumberOfExternalNodes() != 6 ) {
10674                 return false;
10675             }
10676             if ( gene5.getNumberOfExternalNodes() != 6 ) {
10677                 return false;
10678             }
10679             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
10680             // Conjecture for Comparing Molecular Phylogenies"
10681             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
10682             final Phylogeny species6 = factory
10683                     .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,"
10684                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10685                             new NHXParser() )[ 0 ];
10686             final Phylogeny gene6 = factory
10687                     .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,"
10688                             + "((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,"
10689                             + "(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;",
10690                             new NHXParser() )[ 0 ];
10691             species6.setRooted( true );
10692             gene6.setRooted( true );
10693             final SDI sdi6 = new SDI( gene6, species6 );
10694             if ( sdi6.getDuplicationsSum() != 3 ) {
10695                 return false;
10696             }
10697             if ( !gene6.getNode( "r" ).isDuplication() ) {
10698                 return false;
10699             }
10700             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
10701                 return false;
10702             }
10703             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
10704                 return false;
10705             }
10706             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
10707                 return false;
10708             }
10709             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
10710                 return false;
10711             }
10712             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
10713                 return false;
10714             }
10715             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
10716                 return false;
10717             }
10718             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
10719                 return false;
10720             }
10721             sdi6.computeMappingCostL();
10722             if ( sdi6.computeMappingCostL() != 17 ) {
10723                 return false;
10724             }
10725             if ( species6.getNumberOfExternalNodes() != 9 ) {
10726                 return false;
10727             }
10728             if ( gene6.getNumberOfExternalNodes() != 9 ) {
10729                 return false;
10730             }
10731             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
10732                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
10733                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
10734                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
10735                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
10736             species7.setRooted( true );
10737             final Phylogeny gene7_1 = Test
10738                     .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])" );
10739             gene7_1.setRooted( true );
10740             final SDI sdi7 = new SDI( gene7_1, species7 );
10741             if ( sdi7.getDuplicationsSum() != 0 ) {
10742                 return false;
10743             }
10744             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
10745                 return false;
10746             }
10747             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
10748                 return false;
10749             }
10750             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
10751                 return false;
10752             }
10753             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
10754                 return false;
10755             }
10756             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
10757                 return false;
10758             }
10759             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
10760                 return false;
10761             }
10762             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
10763                 return false;
10764             }
10765             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
10766                 return false;
10767             }
10768             final Phylogeny gene7_2 = Test
10769                     .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])" );
10770             gene7_2.setRooted( true );
10771             final SDI sdi7_2 = new SDI( gene7_2, species7 );
10772             if ( sdi7_2.getDuplicationsSum() != 1 ) {
10773                 return false;
10774             }
10775             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
10776                 return false;
10777             }
10778             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
10779                 return false;
10780             }
10781             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
10782                 return false;
10783             }
10784             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
10785                 return false;
10786             }
10787             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
10788                 return false;
10789             }
10790             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
10791                 return false;
10792             }
10793             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
10794                 return false;
10795             }
10796             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
10797                 return false;
10798             }
10799             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
10800                 return false;
10801             }
10802         }
10803         catch ( final Exception e ) {
10804             return false;
10805         }
10806         return true;
10807     }
10808
10809     private static boolean testSDIunrooted() {
10810         try {
10811             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10812             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
10813             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
10814             final Iterator<PhylogenyBranch> iter = l.iterator();
10815             PhylogenyBranch br = iter.next();
10816             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
10817                 return false;
10818             }
10819             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
10820                 return false;
10821             }
10822             br = iter.next();
10823             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10824                 return false;
10825             }
10826             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10827                 return false;
10828             }
10829             br = iter.next();
10830             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
10831                 return false;
10832             }
10833             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
10834                 return false;
10835             }
10836             br = iter.next();
10837             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10838                 return false;
10839             }
10840             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10841                 return false;
10842             }
10843             br = iter.next();
10844             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10845                 return false;
10846             }
10847             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10848                 return false;
10849             }
10850             br = iter.next();
10851             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10852                 return false;
10853             }
10854             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10855                 return false;
10856             }
10857             br = iter.next();
10858             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10859                 return false;
10860             }
10861             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10862                 return false;
10863             }
10864             br = iter.next();
10865             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10866                 return false;
10867             }
10868             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10869                 return false;
10870             }
10871             br = iter.next();
10872             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10873                 return false;
10874             }
10875             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10876                 return false;
10877             }
10878             br = iter.next();
10879             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10880                 return false;
10881             }
10882             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10883                 return false;
10884             }
10885             br = iter.next();
10886             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10887                 return false;
10888             }
10889             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10890                 return false;
10891             }
10892             br = iter.next();
10893             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
10894                 return false;
10895             }
10896             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
10897                 return false;
10898             }
10899             br = iter.next();
10900             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10901                 return false;
10902             }
10903             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10904                 return false;
10905             }
10906             br = iter.next();
10907             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
10908                 return false;
10909             }
10910             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
10911                 return false;
10912             }
10913             br = iter.next();
10914             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
10915                 return false;
10916             }
10917             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
10918                 return false;
10919             }
10920             if ( iter.hasNext() ) {
10921                 return false;
10922             }
10923             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
10924             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
10925             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
10926             br = iter1.next();
10927             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10928                 return false;
10929             }
10930             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10931                 return false;
10932             }
10933             br = iter1.next();
10934             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10935                 return false;
10936             }
10937             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10938                 return false;
10939             }
10940             br = iter1.next();
10941             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10942                 return false;
10943             }
10944             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10945                 return false;
10946             }
10947             if ( iter1.hasNext() ) {
10948                 return false;
10949             }
10950             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
10951             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
10952             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
10953             br = iter2.next();
10954             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10955                 return false;
10956             }
10957             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10958                 return false;
10959             }
10960             br = iter2.next();
10961             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10962                 return false;
10963             }
10964             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10965                 return false;
10966             }
10967             br = iter2.next();
10968             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10969                 return false;
10970             }
10971             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10972                 return false;
10973             }
10974             if ( iter2.hasNext() ) {
10975                 return false;
10976             }
10977             final Phylogeny species0 = factory
10978                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10979                              new NHXParser() )[ 0 ];
10980             final Phylogeny gene1 = factory
10981                     .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])",
10982                              new NHXParser() )[ 0 ];
10983             species0.setRooted( true );
10984             gene1.setRooted( true );
10985             final SDIR sdi_unrooted = new SDIR();
10986             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
10987             if ( sdi_unrooted.getCount() != 1 ) {
10988                 return false;
10989             }
10990             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
10991                 return false;
10992             }
10993             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
10994                 return false;
10995             }
10996             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
10997                 return false;
10998             }
10999             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11000                 return false;
11001             }
11002             final Phylogeny gene2 = factory
11003                     .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])",
11004                              new NHXParser() )[ 0 ];
11005             gene2.setRooted( true );
11006             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
11007             if ( sdi_unrooted.getCount() != 1 ) {
11008                 return false;
11009             }
11010             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11011                 return false;
11012             }
11013             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11014                 return false;
11015             }
11016             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
11017                 return false;
11018             }
11019             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11020                 return false;
11021             }
11022             final Phylogeny species6 = factory
11023                     .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,"
11024                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11025                             new NHXParser() )[ 0 ];
11026             final Phylogeny gene6 = factory
11027                     .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],"
11028                             + "(((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],"
11029                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11030                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11031                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11032                             new NHXParser() )[ 0 ];
11033             species6.setRooted( true );
11034             gene6.setRooted( true );
11035             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
11036             if ( sdi_unrooted.getCount() != 1 ) {
11037                 return false;
11038             }
11039             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11040                 return false;
11041             }
11042             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11043                 return false;
11044             }
11045             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11046                 return false;
11047             }
11048             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11049                 return false;
11050             }
11051             if ( !p6[ 0 ].getRoot().isDuplication() ) {
11052                 return false;
11053             }
11054             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11055                 return false;
11056             }
11057             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11058                 return false;
11059             }
11060             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
11061                 return false;
11062             }
11063             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11064                 return false;
11065             }
11066             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
11067                 return false;
11068             }
11069             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
11070                 return false;
11071             }
11072             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11073                 return false;
11074             }
11075             p6 = null;
11076             final Phylogeny species7 = factory
11077                     .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,"
11078                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11079                             new NHXParser() )[ 0 ];
11080             final Phylogeny gene7 = factory
11081                     .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],"
11082                             + "(((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],"
11083                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11084                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11085                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11086                             new NHXParser() )[ 0 ];
11087             species7.setRooted( true );
11088             gene7.setRooted( true );
11089             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
11090             if ( sdi_unrooted.getCount() != 1 ) {
11091                 return false;
11092             }
11093             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11094                 return false;
11095             }
11096             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11097                 return false;
11098             }
11099             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11100                 return false;
11101             }
11102             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
11103                 return false;
11104             }
11105             if ( !p7[ 0 ].getRoot().isDuplication() ) {
11106                 return false;
11107             }
11108             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11109                 return false;
11110             }
11111             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11112                 return false;
11113             }
11114             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
11115                 return false;
11116             }
11117             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11118                 return false;
11119             }
11120             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
11121                 return false;
11122             }
11123             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
11124                 return false;
11125             }
11126             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11127                 return false;
11128             }
11129             p7 = null;
11130             final Phylogeny species8 = factory
11131                     .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,"
11132                             + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11133                             new NHXParser() )[ 0 ];
11134             final Phylogeny gene8 = factory
11135                     .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],"
11136                             + "(((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],"
11137                             + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11138                             + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11139                             + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11140                             new NHXParser() )[ 0 ];
11141             species8.setRooted( true );
11142             gene8.setRooted( true );
11143             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
11144             if ( sdi_unrooted.getCount() != 1 ) {
11145                 return false;
11146             }
11147             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11148                 return false;
11149             }
11150             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11151                 return false;
11152             }
11153             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11154                 return false;
11155             }
11156             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11157                 return false;
11158             }
11159             if ( !p8[ 0 ].getRoot().isDuplication() ) {
11160                 return false;
11161             }
11162             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11163                 return false;
11164             }
11165             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11166                 return false;
11167             }
11168             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
11169                 return false;
11170             }
11171             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11172                 return false;
11173             }
11174             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
11175                 return false;
11176             }
11177             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
11178                 return false;
11179             }
11180             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11181                 return false;
11182             }
11183             p8 = null;
11184         }
11185         catch ( final Exception e ) {
11186             e.printStackTrace( System.out );
11187             return false;
11188         }
11189         return true;
11190     }
11191
11192     private static boolean testSequenceDbWsTools1() {
11193         try {
11194             final PhylogenyNode n = new PhylogenyNode();
11195             n.setName( "NP_001025424" );
11196             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
11197             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11198                     || !acc.getValue().equals( "NP_001025424" ) ) {
11199                 return false;
11200             }
11201             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
11202             acc = SequenceDbWsTools.obtainSeqAccession( n );
11203             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11204                     || !acc.getValue().equals( "NP_001025424" ) ) {
11205                 return false;
11206             }
11207             n.setName( "NP_001025424.1" );
11208             acc = SequenceDbWsTools.obtainSeqAccession( n );
11209             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11210                     || !acc.getValue().equals( "NP_001025424" ) ) {
11211                 return false;
11212             }
11213             n.setName( "NM_001030253" );
11214             acc = SequenceDbWsTools.obtainSeqAccession( n );
11215             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11216                     || !acc.getValue().equals( "NM_001030253" ) ) {
11217                 return false;
11218             }
11219             n.setName( "BCL2_HUMAN" );
11220             acc = SequenceDbWsTools.obtainSeqAccession( n );
11221             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11222                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
11223                 System.out.println( acc.toString() );
11224                 return false;
11225             }
11226             n.setName( "P10415" );
11227             acc = SequenceDbWsTools.obtainSeqAccession( n );
11228             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11229                     || !acc.getValue().equals( "P10415" ) ) {
11230                 System.out.println( acc.toString() );
11231                 return false;
11232             }
11233             n.setName( " P10415 " );
11234             acc = SequenceDbWsTools.obtainSeqAccession( n );
11235             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11236                     || !acc.getValue().equals( "P10415" ) ) {
11237                 System.out.println( acc.toString() );
11238                 return false;
11239             }
11240             n.setName( "_P10415|" );
11241             acc = SequenceDbWsTools.obtainSeqAccession( n );
11242             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11243                     || !acc.getValue().equals( "P10415" ) ) {
11244                 System.out.println( acc.toString() );
11245                 return false;
11246             }
11247             n.setName( "AY695820" );
11248             acc = SequenceDbWsTools.obtainSeqAccession( n );
11249             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11250                     || !acc.getValue().equals( "AY695820" ) ) {
11251                 System.out.println( acc.toString() );
11252                 return false;
11253             }
11254             n.setName( "_AY695820_" );
11255             acc = SequenceDbWsTools.obtainSeqAccession( n );
11256             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11257                     || !acc.getValue().equals( "AY695820" ) ) {
11258                 System.out.println( acc.toString() );
11259                 return false;
11260             }
11261             n.setName( "AAA59452" );
11262             acc = SequenceDbWsTools.obtainSeqAccession( n );
11263             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11264                     || !acc.getValue().equals( "AAA59452" ) ) {
11265                 System.out.println( acc.toString() );
11266                 return false;
11267             }
11268             n.setName( "_AAA59452_" );
11269             acc = SequenceDbWsTools.obtainSeqAccession( n );
11270             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11271                     || !acc.getValue().equals( "AAA59452" ) ) {
11272                 System.out.println( acc.toString() );
11273                 return false;
11274             }
11275             n.setName( "AAA59452.1" );
11276             acc = SequenceDbWsTools.obtainSeqAccession( n );
11277             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11278                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11279                 System.out.println( acc.toString() );
11280                 return false;
11281             }
11282             n.setName( "_AAA59452.1_" );
11283             acc = SequenceDbWsTools.obtainSeqAccession( n );
11284             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11285                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11286                 System.out.println( acc.toString() );
11287                 return false;
11288             }
11289             n.setName( "GI:94894583" );
11290             acc = SequenceDbWsTools.obtainSeqAccession( n );
11291             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11292                     || !acc.getValue().equals( "94894583" ) ) {
11293                 System.out.println( acc.toString() );
11294                 return false;
11295             }
11296             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11297             acc = SequenceDbWsTools.obtainSeqAccession( n );
11298             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11299                     || !acc.getValue().equals( "71845847" ) ) {
11300                 System.out.println( acc.toString() );
11301                 return false;
11302             }
11303             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11304             acc = SequenceDbWsTools.obtainSeqAccession( n );
11305             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11306                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
11307                 System.out.println( acc.toString() );
11308                 return false;
11309             }
11310         }
11311         catch ( final Exception e ) {
11312             return false;
11313         }
11314         return true;
11315     }
11316
11317     private static boolean testSequenceDbWsTools2() {
11318         try {
11319             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
11320             SequenceDbWsTools.obtainSeqInformation( n1 );
11321             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
11322                 return false;
11323             }
11324             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11325                 return false;
11326             }
11327             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11328                 return false;
11329             }
11330             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
11331                 return false;
11332             }
11333             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
11334             SequenceDbWsTools.obtainSeqInformation( n2 );
11335             if ( !n2.getNodeData().getSequence().getName().equals( "Danio rerio B-cell CLL/lymphoma 2a (bcl2a), mRNA" ) ) {
11336                 return false;
11337             }
11338             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11339                 return false;
11340             }
11341             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11342                 return false;
11343             }
11344             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
11345                 return false;
11346             }
11347             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
11348             SequenceDbWsTools.obtainSeqInformation( n3 );
11349             if ( !n3.getNodeData().getSequence().getName()
11350                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
11351                 return false;
11352             }
11353             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
11354                 return false;
11355             }
11356             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11357                 return false;
11358             }
11359             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
11360                 return false;
11361             }
11362         }
11363         catch ( final IOException e ) {
11364             System.out.println();
11365             System.out.println( "the following might be due to absence internet connection:" );
11366             e.printStackTrace( System.out );
11367             return true;
11368         }
11369         catch ( final Exception e ) {
11370             e.printStackTrace();
11371             return false;
11372         }
11373         return true;
11374     }
11375
11376     private static boolean testSequenceIdParsing() {
11377         try {
11378             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
11379             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11380                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11381                 if ( id != null ) {
11382                     System.out.println( "value   =" + id.getValue() );
11383                     System.out.println( "provider=" + id.getSource() );
11384                 }
11385                 return false;
11386             }
11387             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
11388             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11389                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11390                 if ( id != null ) {
11391                     System.out.println( "value   =" + id.getValue() );
11392                     System.out.println( "provider=" + id.getSource() );
11393                 }
11394                 return false;
11395             }
11396             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
11397             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11398                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11399                 if ( id != null ) {
11400                     System.out.println( "value   =" + id.getValue() );
11401                     System.out.println( "provider=" + id.getSource() );
11402                 }
11403                 return false;
11404             }
11405             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
11406             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11407                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
11408                 if ( id != null ) {
11409                     System.out.println( "value   =" + id.getValue() );
11410                     System.out.println( "provider=" + id.getSource() );
11411                 }
11412                 return false;
11413             }
11414             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
11415             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11416                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
11417                 if ( id != null ) {
11418                     System.out.println( "value   =" + id.getValue() );
11419                     System.out.println( "provider=" + id.getSource() );
11420                 }
11421                 return false;
11422             }
11423             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
11424             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11425                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
11426                 if ( id != null ) {
11427                     System.out.println( "value   =" + id.getValue() );
11428                     System.out.println( "provider=" + id.getSource() );
11429                 }
11430                 return false;
11431             }
11432             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
11433             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11434                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
11435                 if ( id != null ) {
11436                     System.out.println( "value   =" + id.getValue() );
11437                     System.out.println( "provider=" + id.getSource() );
11438                 }
11439                 return false;
11440             }
11441             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
11442             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11443                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11444                 if ( id != null ) {
11445                     System.out.println( "value   =" + id.getValue() );
11446                     System.out.println( "provider=" + id.getSource() );
11447                 }
11448                 return false;
11449             }
11450             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
11451             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11452                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11453                 if ( id != null ) {
11454                     System.out.println( "value   =" + id.getValue() );
11455                     System.out.println( "provider=" + id.getSource() );
11456                 }
11457                 return false;
11458             }
11459             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
11460             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11461                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
11462                 if ( id != null ) {
11463                     System.out.println( "value   =" + id.getValue() );
11464                     System.out.println( "provider=" + id.getSource() );
11465                 }
11466                 return false;
11467             }
11468             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
11469             if ( id != null ) {
11470                 System.out.println( "value   =" + id.getValue() );
11471                 System.out.println( "provider=" + id.getSource() );
11472                 return false;
11473             }
11474             id = SequenceAccessionTools.parseAccessorFromString( "N3B004Z009" );
11475             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11476                     || !id.getValue().equals( "N3B004Z009" ) || !id.getSource().equals( "uniprot" ) ) {
11477                 if ( id != null ) {
11478                     System.out.println( "value   =" + id.getValue() );
11479                     System.out.println( "provider=" + id.getSource() );
11480                 }
11481                 return false;
11482             }
11483             id = SequenceAccessionTools.parseAccessorFromString( "A4CAA4ZBB9" );
11484             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11485                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
11486                 if ( id != null ) {
11487                     System.out.println( "value   =" + id.getValue() );
11488                     System.out.println( "provider=" + id.getSource() );
11489                 }
11490                 return false;
11491             }
11492             id = SequenceAccessionTools.parseAccessorFromString( "ecoli_A4CAA4ZBB9_rt" );
11493             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11494                     || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
11495                 if ( id != null ) {
11496                     System.out.println( "value   =" + id.getValue() );
11497                     System.out.println( "provider=" + id.getSource() );
11498                 }
11499                 return false;
11500             }
11501             id = SequenceAccessionTools.parseAccessorFromString( "Q4CAA4ZBB9" );
11502             if ( id != null ) {
11503                 System.out.println( "value   =" + id.getValue() );
11504                 System.out.println( "provider=" + id.getSource() );
11505                 return false;
11506             }
11507         }
11508         catch ( final Exception e ) {
11509             e.printStackTrace( System.out );
11510             return false;
11511         }
11512         return true;
11513     }
11514
11515     private static boolean testSequenceWriter() {
11516         try {
11517             final String n = ForesterUtil.LINE_SEPARATOR;
11518             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
11519                 return false;
11520             }
11521             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
11522                 return false;
11523             }
11524             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
11525                 return false;
11526             }
11527             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
11528                 return false;
11529             }
11530             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
11531                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
11532                 return false;
11533             }
11534             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
11535                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
11536                 return false;
11537             }
11538         }
11539         catch ( final Exception e ) {
11540             e.printStackTrace();
11541             return false;
11542         }
11543         return true;
11544     }
11545
11546     private static boolean testSpecies() {
11547         try {
11548             final Species s1 = new BasicSpecies( "a" );
11549             final Species s2 = new BasicSpecies( "a" );
11550             final Species s3 = new BasicSpecies( "A" );
11551             final Species s4 = new BasicSpecies( "b" );
11552             if ( !s1.equals( s1 ) ) {
11553                 return false;
11554             }
11555             if ( s1.getSpeciesId().equals( "x" ) ) {
11556                 return false;
11557             }
11558             if ( s1.getSpeciesId().equals( null ) ) {
11559                 return false;
11560             }
11561             if ( !s1.equals( s2 ) ) {
11562                 return false;
11563             }
11564             if ( s1.equals( s3 ) ) {
11565                 return false;
11566             }
11567             if ( s1.hashCode() != s1.hashCode() ) {
11568                 return false;
11569             }
11570             if ( s1.hashCode() != s2.hashCode() ) {
11571                 return false;
11572             }
11573             if ( s1.hashCode() == s3.hashCode() ) {
11574                 return false;
11575             }
11576             if ( s1.compareTo( s1 ) != 0 ) {
11577                 return false;
11578             }
11579             if ( s1.compareTo( s2 ) != 0 ) {
11580                 return false;
11581             }
11582             if ( s1.compareTo( s3 ) != 0 ) {
11583                 return false;
11584             }
11585             if ( s1.compareTo( s4 ) >= 0 ) {
11586                 return false;
11587             }
11588             if ( s4.compareTo( s1 ) <= 0 ) {
11589                 return false;
11590             }
11591             if ( !s4.getSpeciesId().equals( "b" ) ) {
11592                 return false;
11593             }
11594             final Species s5 = new BasicSpecies( " C " );
11595             if ( !s5.getSpeciesId().equals( "C" ) ) {
11596                 return false;
11597             }
11598             if ( s5.equals( s1 ) ) {
11599                 return false;
11600             }
11601         }
11602         catch ( final Exception e ) {
11603             e.printStackTrace( System.out );
11604             return false;
11605         }
11606         return true;
11607     }
11608
11609     private static boolean testSplit() {
11610         try {
11611             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11612             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11613             //Archaeopteryx.createApplication( p0 );
11614             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11615             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11616             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11617             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11618             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11619             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11620             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11621             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11622             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11623             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11624             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
11625             // System.out.println( s0.toString() );
11626             //
11627             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11628             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11629             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11630             if ( s0.match( query_nodes ) ) {
11631                 return false;
11632             }
11633             query_nodes = new HashSet<PhylogenyNode>();
11634             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11635             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11636             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11637             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11638             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11639             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11640             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11641             if ( !s0.match( query_nodes ) ) {
11642                 return false;
11643             }
11644             //
11645             query_nodes = new HashSet<PhylogenyNode>();
11646             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11647             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11648             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11649             if ( !s0.match( query_nodes ) ) {
11650                 return false;
11651             }
11652             //
11653             query_nodes = new HashSet<PhylogenyNode>();
11654             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11655             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11656             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11657             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11658             if ( !s0.match( query_nodes ) ) {
11659                 return false;
11660             }
11661             //
11662             query_nodes = new HashSet<PhylogenyNode>();
11663             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11664             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11665             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11666             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11667             if ( !s0.match( query_nodes ) ) {
11668                 return false;
11669             }
11670             //
11671             query_nodes = new HashSet<PhylogenyNode>();
11672             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11673             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11674             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11675             if ( !s0.match( query_nodes ) ) {
11676                 return false;
11677             }
11678             query_nodes = new HashSet<PhylogenyNode>();
11679             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11680             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11681             if ( !s0.match( query_nodes ) ) {
11682                 return false;
11683             }
11684             query_nodes = new HashSet<PhylogenyNode>();
11685             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11686             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11687             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11688             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11689             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11690             if ( !s0.match( query_nodes ) ) {
11691                 return false;
11692             }
11693             query_nodes = new HashSet<PhylogenyNode>();
11694             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11695             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11696             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11697             if ( !s0.match( query_nodes ) ) {
11698                 return false;
11699             }
11700             query_nodes = new HashSet<PhylogenyNode>();
11701             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11702             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11703             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11704             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11705             if ( !s0.match( query_nodes ) ) {
11706                 return false;
11707             }
11708             query_nodes = new HashSet<PhylogenyNode>();
11709             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11710             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11711             if ( s0.match( query_nodes ) ) {
11712                 return false;
11713             }
11714             query_nodes = new HashSet<PhylogenyNode>();
11715             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11716             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11717             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11718             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11719             if ( s0.match( query_nodes ) ) {
11720                 return false;
11721             }
11722             query_nodes = new HashSet<PhylogenyNode>();
11723             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11724             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11725             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11726             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11727             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11728             if ( s0.match( query_nodes ) ) {
11729                 return false;
11730             }
11731             query_nodes = new HashSet<PhylogenyNode>();
11732             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11733             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11734             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11735             if ( s0.match( query_nodes ) ) {
11736                 return false;
11737             }
11738             query_nodes = new HashSet<PhylogenyNode>();
11739             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11740             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11741             if ( s0.match( query_nodes ) ) {
11742                 return false;
11743             }
11744             query_nodes = new HashSet<PhylogenyNode>();
11745             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11746             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11747             if ( s0.match( query_nodes ) ) {
11748                 return false;
11749             }
11750             query_nodes = new HashSet<PhylogenyNode>();
11751             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11752             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11753             if ( s0.match( query_nodes ) ) {
11754                 return false;
11755             }
11756             query_nodes = new HashSet<PhylogenyNode>();
11757             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11758             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11759             if ( s0.match( query_nodes ) ) {
11760                 return false;
11761             }
11762             query_nodes = new HashSet<PhylogenyNode>();
11763             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11764             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11765             if ( s0.match( query_nodes ) ) {
11766                 return false;
11767             }
11768             query_nodes = new HashSet<PhylogenyNode>();
11769             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11770             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11771             if ( s0.match( query_nodes ) ) {
11772                 return false;
11773             }
11774             query_nodes = new HashSet<PhylogenyNode>();
11775             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11776             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11777             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11778             if ( s0.match( query_nodes ) ) {
11779                 return false;
11780             }
11781             query_nodes = new HashSet<PhylogenyNode>();
11782             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11783             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11784             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11785             if ( s0.match( query_nodes ) ) {
11786                 return false;
11787             }
11788             query_nodes = new HashSet<PhylogenyNode>();
11789             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11790             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11791             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11792             if ( s0.match( query_nodes ) ) {
11793                 return false;
11794             }
11795             query_nodes = new HashSet<PhylogenyNode>();
11796             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11797             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11798             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11799             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11800             if ( s0.match( query_nodes ) ) {
11801                 return false;
11802             }
11803             /////////
11804             //            query_nodes = new HashSet<PhylogenyNode>();
11805             //            query_nodes.add( new PhylogenyNode( "X" ) );
11806             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11807             //            query_nodes.add( new PhylogenyNode( "A" ) );
11808             //            query_nodes.add( new PhylogenyNode( "B" ) );
11809             //            query_nodes.add( new PhylogenyNode( "C" ) );
11810             //            query_nodes.add( new PhylogenyNode( "D" ) );
11811             //            query_nodes.add( new PhylogenyNode( "E" ) );
11812             //            query_nodes.add( new PhylogenyNode( "F" ) );
11813             //            query_nodes.add( new PhylogenyNode( "G" ) );
11814             //            if ( !s0.match( query_nodes ) ) {
11815             //                return false;
11816             //            }
11817             //            query_nodes = new HashSet<PhylogenyNode>();
11818             //            query_nodes.add( new PhylogenyNode( "X" ) );
11819             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11820             //            query_nodes.add( new PhylogenyNode( "A" ) );
11821             //            query_nodes.add( new PhylogenyNode( "B" ) );
11822             //            query_nodes.add( new PhylogenyNode( "C" ) );
11823             //            if ( !s0.match( query_nodes ) ) {
11824             //                return false;
11825             //            }
11826             //            //
11827             //            query_nodes = new HashSet<PhylogenyNode>();
11828             //            query_nodes.add( new PhylogenyNode( "X" ) );
11829             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11830             //            query_nodes.add( new PhylogenyNode( "D" ) );
11831             //            query_nodes.add( new PhylogenyNode( "E" ) );
11832             //            query_nodes.add( new PhylogenyNode( "F" ) );
11833             //            query_nodes.add( new PhylogenyNode( "G" ) );
11834             //            if ( !s0.match( query_nodes ) ) {
11835             //                return false;
11836             //            }
11837             //            //
11838             //            query_nodes = new HashSet<PhylogenyNode>();
11839             //            query_nodes.add( new PhylogenyNode( "X" ) );
11840             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11841             //            query_nodes.add( new PhylogenyNode( "A" ) );
11842             //            query_nodes.add( new PhylogenyNode( "B" ) );
11843             //            query_nodes.add( new PhylogenyNode( "C" ) );
11844             //            query_nodes.add( new PhylogenyNode( "D" ) );
11845             //            if ( !s0.match( query_nodes ) ) {
11846             //                return false;
11847             //            }
11848             //            //
11849             //            query_nodes = new HashSet<PhylogenyNode>();
11850             //            query_nodes.add( new PhylogenyNode( "X" ) );
11851             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11852             //            query_nodes.add( new PhylogenyNode( "E" ) );
11853             //            query_nodes.add( new PhylogenyNode( "F" ) );
11854             //            query_nodes.add( new PhylogenyNode( "G" ) );
11855             //            if ( !s0.match( query_nodes ) ) {
11856             //                return false;
11857             //            }
11858             //            //
11859             //            query_nodes = new HashSet<PhylogenyNode>();
11860             //            query_nodes.add( new PhylogenyNode( "X" ) );
11861             //            query_nodes.add( new PhylogenyNode( "Y" ) );
11862             //            query_nodes.add( new PhylogenyNode( "F" ) );
11863             //            query_nodes.add( new PhylogenyNode( "G" ) );
11864             //            if ( !s0.match( query_nodes ) ) {
11865             //                return false;
11866             //            }
11867             //
11868             query_nodes = new HashSet<PhylogenyNode>();
11869             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11870             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11871             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11872             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11873             if ( s0.match( query_nodes ) ) {
11874                 return false;
11875             }
11876             //
11877             query_nodes = new HashSet<PhylogenyNode>();
11878             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11879             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11880             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11881             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11882             if ( s0.match( query_nodes ) ) {
11883                 return false;
11884             }
11885             ///////////////////////////
11886             //
11887             query_nodes = new HashSet<PhylogenyNode>();
11888             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11889             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11890             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11891             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11892             if ( s0.match( query_nodes ) ) {
11893                 return false;
11894             }
11895             //
11896             query_nodes = new HashSet<PhylogenyNode>();
11897             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11898             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11899             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11900             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11901             if ( s0.match( query_nodes ) ) {
11902                 return false;
11903             }
11904             //
11905             query_nodes = new HashSet<PhylogenyNode>();
11906             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11907             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11908             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11909             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11910             if ( s0.match( query_nodes ) ) {
11911                 return false;
11912             }
11913             //
11914             query_nodes = new HashSet<PhylogenyNode>();
11915             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11916             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11917             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11918             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11919             if ( s0.match( query_nodes ) ) {
11920                 return false;
11921             }
11922             //
11923             query_nodes = new HashSet<PhylogenyNode>();
11924             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11925             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11926             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11927             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11928             if ( s0.match( query_nodes ) ) {
11929                 return false;
11930             }
11931             //
11932             query_nodes = new HashSet<PhylogenyNode>();
11933             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11934             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11935             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11936             if ( s0.match( query_nodes ) ) {
11937                 return false;
11938             }
11939             //
11940             query_nodes = new HashSet<PhylogenyNode>();
11941             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11942             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11943             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11944             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11945             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11946             if ( s0.match( query_nodes ) ) {
11947                 return false;
11948             }
11949             //
11950             query_nodes = new HashSet<PhylogenyNode>();
11951             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11952             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11953             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11954             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11955             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11956             if ( s0.match( query_nodes ) ) {
11957                 return false;
11958             }
11959             //
11960             query_nodes = new HashSet<PhylogenyNode>();
11961             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11962             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11963             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11964             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11965             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11966             if ( s0.match( query_nodes ) ) {
11967                 return false;
11968             }
11969             //
11970             query_nodes = new HashSet<PhylogenyNode>();
11971             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11972             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11973             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11974             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11975             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11976             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11977             if ( s0.match( query_nodes ) ) {
11978                 return false;
11979             }
11980         }
11981         catch ( final Exception e ) {
11982             e.printStackTrace();
11983             return false;
11984         }
11985         return true;
11986     }
11987
11988     private static boolean testSplitStrict() {
11989         try {
11990             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11991             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11992             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11993             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11994             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11995             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11996             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11997             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11998             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11999             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12000             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
12001             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
12002             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12003             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12004             if ( s0.match( query_nodes ) ) {
12005                 return false;
12006             }
12007             query_nodes = new HashSet<PhylogenyNode>();
12008             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12009             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12010             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12011             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12012             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12013             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12014             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12015             if ( !s0.match( query_nodes ) ) {
12016                 return false;
12017             }
12018             //
12019             query_nodes = new HashSet<PhylogenyNode>();
12020             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12021             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12022             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12023             if ( !s0.match( query_nodes ) ) {
12024                 return false;
12025             }
12026             //
12027             query_nodes = new HashSet<PhylogenyNode>();
12028             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12029             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12030             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12031             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12032             if ( !s0.match( query_nodes ) ) {
12033                 return false;
12034             }
12035             //
12036             query_nodes = new HashSet<PhylogenyNode>();
12037             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12038             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12039             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12040             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12041             if ( !s0.match( query_nodes ) ) {
12042                 return false;
12043             }
12044             //
12045             query_nodes = new HashSet<PhylogenyNode>();
12046             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12047             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12048             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12049             if ( !s0.match( query_nodes ) ) {
12050                 return false;
12051             }
12052             //
12053             query_nodes = new HashSet<PhylogenyNode>();
12054             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12055             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12056             if ( !s0.match( query_nodes ) ) {
12057                 return false;
12058             }
12059             //
12060             query_nodes = new HashSet<PhylogenyNode>();
12061             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12062             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12063             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12064             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12065             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12066             if ( !s0.match( query_nodes ) ) {
12067                 return false;
12068             }
12069             //
12070             query_nodes = new HashSet<PhylogenyNode>();
12071             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12072             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12073             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12074             if ( !s0.match( query_nodes ) ) {
12075                 return false;
12076             }
12077             //
12078             query_nodes = new HashSet<PhylogenyNode>();
12079             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12080             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12081             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12082             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12083             if ( !s0.match( query_nodes ) ) {
12084                 return false;
12085             }
12086             //
12087             query_nodes = new HashSet<PhylogenyNode>();
12088             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12089             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12090             if ( s0.match( query_nodes ) ) {
12091                 return false;
12092             }
12093             //
12094             query_nodes = new HashSet<PhylogenyNode>();
12095             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12096             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12097             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12098             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12099             if ( s0.match( query_nodes ) ) {
12100                 return false;
12101             }
12102             //
12103             query_nodes = new HashSet<PhylogenyNode>();
12104             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12105             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12106             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12107             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12108             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12109             if ( s0.match( query_nodes ) ) {
12110                 return false;
12111             }
12112             //
12113             query_nodes = new HashSet<PhylogenyNode>();
12114             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12115             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12116             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12117             if ( s0.match( query_nodes ) ) {
12118                 return false;
12119             }
12120             //
12121             query_nodes = new HashSet<PhylogenyNode>();
12122             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12123             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12124             if ( s0.match( query_nodes ) ) {
12125                 return false;
12126             }
12127             //
12128             query_nodes = new HashSet<PhylogenyNode>();
12129             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12130             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12131             if ( s0.match( query_nodes ) ) {
12132                 return false;
12133             }
12134             //
12135             query_nodes = new HashSet<PhylogenyNode>();
12136             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12137             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12138             if ( s0.match( query_nodes ) ) {
12139                 return false;
12140             }
12141             //
12142             query_nodes = new HashSet<PhylogenyNode>();
12143             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12144             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12145             if ( s0.match( query_nodes ) ) {
12146                 return false;
12147             }
12148             //
12149             query_nodes = new HashSet<PhylogenyNode>();
12150             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12151             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12152             if ( s0.match( query_nodes ) ) {
12153                 return false;
12154             }
12155             //
12156             query_nodes = new HashSet<PhylogenyNode>();
12157             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12158             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12159             if ( s0.match( query_nodes ) ) {
12160                 return false;
12161             }
12162             //
12163             query_nodes = new HashSet<PhylogenyNode>();
12164             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12165             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12166             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12167             if ( s0.match( query_nodes ) ) {
12168                 return false;
12169             }
12170             //
12171             query_nodes = new HashSet<PhylogenyNode>();
12172             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12173             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12174             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12175             if ( s0.match( query_nodes ) ) {
12176                 return false;
12177             }
12178             //
12179             query_nodes = new HashSet<PhylogenyNode>();
12180             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12181             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12182             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12183             if ( s0.match( query_nodes ) ) {
12184                 return false;
12185             }
12186             //
12187             query_nodes = new HashSet<PhylogenyNode>();
12188             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12189             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12190             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12191             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12192             if ( s0.match( query_nodes ) ) {
12193                 return false;
12194             }
12195         }
12196         catch ( final Exception e ) {
12197             e.printStackTrace();
12198             return false;
12199         }
12200         return true;
12201     }
12202
12203     private static boolean testSubtreeDeletion() {
12204         try {
12205             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12206             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12207             t1.deleteSubtree( t1.getNode( "A" ), false );
12208             if ( t1.getNumberOfExternalNodes() != 5 ) {
12209                 return false;
12210             }
12211             t1.toNewHampshireX();
12212             t1.deleteSubtree( t1.getNode( "E" ), false );
12213             if ( t1.getNumberOfExternalNodes() != 4 ) {
12214                 return false;
12215             }
12216             t1.toNewHampshireX();
12217             t1.deleteSubtree( t1.getNode( "F" ), false );
12218             if ( t1.getNumberOfExternalNodes() != 3 ) {
12219                 return false;
12220             }
12221             t1.toNewHampshireX();
12222             t1.deleteSubtree( t1.getNode( "D" ), false );
12223             t1.toNewHampshireX();
12224             if ( t1.getNumberOfExternalNodes() != 3 ) {
12225                 return false;
12226             }
12227             t1.deleteSubtree( t1.getNode( "def" ), false );
12228             t1.toNewHampshireX();
12229             if ( t1.getNumberOfExternalNodes() != 2 ) {
12230                 return false;
12231             }
12232             t1.deleteSubtree( t1.getNode( "B" ), false );
12233             t1.toNewHampshireX();
12234             if ( t1.getNumberOfExternalNodes() != 1 ) {
12235                 return false;
12236             }
12237             t1.deleteSubtree( t1.getNode( "C" ), false );
12238             t1.toNewHampshireX();
12239             if ( t1.getNumberOfExternalNodes() != 1 ) {
12240                 return false;
12241             }
12242             t1.deleteSubtree( t1.getNode( "abc" ), false );
12243             t1.toNewHampshireX();
12244             if ( t1.getNumberOfExternalNodes() != 1 ) {
12245                 return false;
12246             }
12247             t1.deleteSubtree( t1.getNode( "r" ), false );
12248             if ( t1.getNumberOfExternalNodes() != 0 ) {
12249                 return false;
12250             }
12251             if ( !t1.isEmpty() ) {
12252                 return false;
12253             }
12254             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12255             t2.deleteSubtree( t2.getNode( "A" ), false );
12256             t2.toNewHampshireX();
12257             if ( t2.getNumberOfExternalNodes() != 5 ) {
12258                 return false;
12259             }
12260             t2.deleteSubtree( t2.getNode( "abc" ), false );
12261             t2.toNewHampshireX();
12262             if ( t2.getNumberOfExternalNodes() != 3 ) {
12263                 return false;
12264             }
12265             t2.deleteSubtree( t2.getNode( "def" ), false );
12266             t2.toNewHampshireX();
12267             if ( t2.getNumberOfExternalNodes() != 1 ) {
12268                 return false;
12269             }
12270         }
12271         catch ( final Exception e ) {
12272             e.printStackTrace( System.out );
12273             return false;
12274         }
12275         return true;
12276     }
12277
12278     private static boolean testSupportCount() {
12279         try {
12280             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12281             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
12282             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
12283                     + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
12284                     + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
12285                     + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
12286                     + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
12287                     new NHXParser() );
12288             SupportCount.count( t0_1, phylogenies_1, true, false );
12289             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
12290             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
12291                     + "(((((A,B),C),D),E),((F,G),X))"
12292                     + "(((((A,Y),B),C),D),((F,G),E))"
12293                     + "(((((A,B),C),D),E),(F,G))"
12294                     + "(((((A,B),C),D),E),(F,G))"
12295                     + "(((((A,B),C),D),E),(F,G))"
12296                     + "(((((A,B),C),D),E),(F,G),Z)"
12297                     + "(((((A,B),C),D),E),(F,G))"
12298                     + "((((((A,B),C),D),E),F),G)"
12299                     + "(((((X,Y),F,G),E),((A,B),C)),D)",
12300                     new NHXParser() );
12301             SupportCount.count( t0_2, phylogenies_2, true, false );
12302             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
12303             while ( it.hasNext() ) {
12304                 final PhylogenyNode n = it.next();
12305                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
12306                     return false;
12307                 }
12308             }
12309             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
12310             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
12311                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
12312             SupportCount.count( t0_3, phylogenies_3, true, false );
12313             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
12314             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
12315                 return false;
12316             }
12317             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
12318                 return false;
12319             }
12320             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
12321                 return false;
12322             }
12323             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
12324                 return false;
12325             }
12326             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
12327                 return false;
12328             }
12329             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
12330                 return false;
12331             }
12332             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
12333                 return false;
12334             }
12335             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
12336                 return false;
12337             }
12338             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
12339                 return false;
12340             }
12341             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
12342                 return false;
12343             }
12344             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12345             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
12346                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
12347             SupportCount.count( t0_4, phylogenies_4, true, false );
12348             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
12349             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
12350                 return false;
12351             }
12352             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
12353                 return false;
12354             }
12355             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
12356                 return false;
12357             }
12358             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
12359                 return false;
12360             }
12361             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
12362                 return false;
12363             }
12364             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
12365                 return false;
12366             }
12367             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
12368                 return false;
12369             }
12370             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
12371                 return false;
12372             }
12373             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
12374                 return false;
12375             }
12376             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
12377                 return false;
12378             }
12379             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12380             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12381             double d = SupportCount.compare( b1, a, true, true, true );
12382             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
12383                 return false;
12384             }
12385             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12386             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12387             d = SupportCount.compare( b2, a, true, true, true );
12388             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
12389                 return false;
12390             }
12391             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12392             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
12393             d = SupportCount.compare( b3, a, true, true, true );
12394             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
12395                 return false;
12396             }
12397             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
12398             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
12399             d = SupportCount.compare( b4, a, true, true, false );
12400             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
12401                 return false;
12402             }
12403         }
12404         catch ( final Exception e ) {
12405             e.printStackTrace( System.out );
12406             return false;
12407         }
12408         return true;
12409     }
12410
12411     private static boolean testSupportTransfer() {
12412         try {
12413             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12414             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)",
12415                                                  new NHXParser() )[ 0 ];
12416             final Phylogeny p2 = factory
12417                     .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 ];
12418             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
12419                 return false;
12420             }
12421             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
12422                 return false;
12423             }
12424             support_transfer.moveBranchLengthsToBootstrap( p1 );
12425             support_transfer.transferSupportValues( p1, p2 );
12426             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
12427                 return false;
12428             }
12429             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
12430                 return false;
12431             }
12432             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
12433                 return false;
12434             }
12435             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
12436                 return false;
12437             }
12438             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
12439                 return false;
12440             }
12441             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
12442                 return false;
12443             }
12444             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
12445                 return false;
12446             }
12447             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
12448                 return false;
12449             }
12450         }
12451         catch ( final Exception e ) {
12452             e.printStackTrace( System.out );
12453             return false;
12454         }
12455         return true;
12456     }
12457
12458     private static boolean testTaxonomyExtraction() {
12459         try {
12460             final PhylogenyNode n0 = PhylogenyNode
12461                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12462             if ( n0.getNodeData().isHasTaxonomy() ) {
12463                 return false;
12464             }
12465             final PhylogenyNode n1 = PhylogenyNode
12466                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12467             if ( n1.getNodeData().isHasTaxonomy() ) {
12468                 System.out.println( n1.toString() );
12469                 return false;
12470             }
12471             final PhylogenyNode n2x = PhylogenyNode
12472                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12473             if ( n2x.getNodeData().isHasTaxonomy() ) {
12474                 return false;
12475             }
12476             final PhylogenyNode n3 = PhylogenyNode
12477                     .createInstanceFromNhxString( "BLAG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12478             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12479                 System.out.println( n3.toString() );
12480                 return false;
12481             }
12482             final PhylogenyNode n4 = PhylogenyNode
12483                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12484             if ( n4.getNodeData().isHasTaxonomy() ) {
12485                 System.out.println( n4.toString() );
12486                 return false;
12487             }
12488             final PhylogenyNode n5 = PhylogenyNode
12489                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12490             if ( n5.getNodeData().isHasTaxonomy() ) {
12491                 System.out.println( n5.toString() );
12492                 return false;
12493             }
12494             final PhylogenyNode n6 = PhylogenyNode
12495                     .createInstanceFromNhxString( "BLAG-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12496             if ( n6.getNodeData().isHasTaxonomy() ) {
12497                 System.out.println( n6.toString() );
12498                 return false;
12499             }
12500             final PhylogenyNode n7 = PhylogenyNode
12501                     .createInstanceFromNhxString( "BLAG-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12502             if ( n7.getNodeData().isHasTaxonomy() ) {
12503                 System.out.println( n7.toString() );
12504                 return false;
12505             }
12506             final PhylogenyNode n8 = PhylogenyNode
12507                     .createInstanceFromNhxString( "BLAG_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12508             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12509                 System.out.println( n8.toString() );
12510                 return false;
12511             }
12512             final PhylogenyNode n9 = PhylogenyNode
12513                     .createInstanceFromNhxString( "BLAG_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12514             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12515                 System.out.println( n9.toString() );
12516                 return false;
12517             }
12518             final PhylogenyNode n10x = PhylogenyNode
12519                     .createInstanceFromNhxString( "BLAG_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12520             if ( n10x.getNodeData().isHasTaxonomy() ) {
12521                 System.out.println( n10x.toString() );
12522                 return false;
12523             }
12524             final PhylogenyNode n10xx = PhylogenyNode
12525                     .createInstanceFromNhxString( "BLAG_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12526             if ( n10xx.getNodeData().isHasTaxonomy() ) {
12527                 System.out.println( n10xx.toString() );
12528                 return false;
12529             }
12530             final PhylogenyNode n10 = PhylogenyNode
12531                     .createInstanceFromNhxString( "BLAG_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12532             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
12533                 System.out.println( n10.toString() );
12534                 return false;
12535             }
12536             final PhylogenyNode n11 = PhylogenyNode
12537                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12538             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12539                 System.out.println( n11.toString() );
12540                 return false;
12541             }
12542             final PhylogenyNode n12 = PhylogenyNode
12543                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
12544                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12545             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12546                 System.out.println( n12.toString() );
12547                 return false;
12548             }
12549             final PhylogenyNode n13 = PhylogenyNode
12550                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12551             if ( n13.getNodeData().isHasTaxonomy() ) {
12552                 System.out.println( n13.toString() );
12553                 return false;
12554             }
12555             final PhylogenyNode n14 = PhylogenyNode
12556                     .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12557             if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12558                 System.out.println( n14.toString() );
12559                 return false;
12560             }
12561             final PhylogenyNode n15 = PhylogenyNode
12562                     .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12563             if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12564                 System.out.println( n15.toString() );
12565                 return false;
12566             }
12567             final PhylogenyNode n16 = PhylogenyNode
12568                     .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12569             if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12570                 System.out.println( n16.toString() );
12571                 return false;
12572             }
12573             final PhylogenyNode n17 = PhylogenyNode
12574                     .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12575             if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12576                 System.out.println( n17.toString() );
12577                 return false;
12578             }
12579             final PhylogenyNode n18 = PhylogenyNode
12580                     .createInstanceFromNhxString( "Mus_musculus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12581             if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12582                 System.out.println( n18.toString() );
12583                 return false;
12584             }
12585             final PhylogenyNode n19 = PhylogenyNode
12586                     .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
12587                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12588             if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12589                 System.out.println( n19.toString() );
12590                 return false;
12591             }
12592             final PhylogenyNode n20 = PhylogenyNode
12593                     .createInstanceFromNhxString( "Mus musculus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12594             if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12595                 System.out.println( n20.toString() );
12596                 return false;
12597             }
12598             final PhylogenyNode n21 = PhylogenyNode
12599                     .createInstanceFromNhxString( "Mus musculus musculus K392",
12600                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12601             if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12602                 System.out.println( n21.toString() );
12603                 return false;
12604             }
12605             final PhylogenyNode n23 = PhylogenyNode
12606                     .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
12607                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12608             if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12609                 System.out.println( n23.toString() );
12610                 return false;
12611             }
12612             final PhylogenyNode n24 = PhylogenyNode
12613                     .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12614             if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12615                 System.out.println( n24.toString() );
12616                 return false;
12617             }
12618             //
12619             final PhylogenyNode n25 = PhylogenyNode
12620                     .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
12621                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12622             if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12623                 System.out.println( n25.toString() );
12624                 return false;
12625             }
12626             final PhylogenyNode n26 = PhylogenyNode
12627                     .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
12628                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12629             if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12630                 System.out.println( n26.toString() );
12631                 return false;
12632             }
12633             final PhylogenyNode n27 = PhylogenyNode
12634                     .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12635             if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12636                 System.out.println( n27.toString() );
12637                 return false;
12638             }
12639         }
12640         catch ( final Exception e ) {
12641             e.printStackTrace( System.out );
12642             return false;
12643         }
12644         return true;
12645     }
12646
12647     private static boolean testTreeCopy() {
12648         try {
12649             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
12650             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
12651             final Phylogeny t1 = t0.copy();
12652             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
12653                 return false;
12654             }
12655             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12656                 return false;
12657             }
12658             t0.deleteSubtree( t0.getNode( "c" ), true );
12659             t0.deleteSubtree( t0.getNode( "a" ), true );
12660             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
12661             t0.getNode( "b" ).setName( "Bee" );
12662             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
12663                 return false;
12664             }
12665             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12666                 return false;
12667             }
12668             t0.deleteSubtree( t0.getNode( "e" ), true );
12669             t0.deleteSubtree( t0.getNode( "Bee" ), true );
12670             t0.deleteSubtree( t0.getNode( "d" ), true );
12671             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12672                 return false;
12673             }
12674         }
12675         catch ( final Exception e ) {
12676             e.printStackTrace();
12677             return false;
12678         }
12679         return true;
12680     }
12681
12682     private static boolean testTreeMethods() {
12683         try {
12684             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12685             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
12686             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
12687             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
12688                 System.out.println( t0.toNewHampshireX() );
12689                 return false;
12690             }
12691             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
12692             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
12693             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
12694                 return false;
12695             }
12696             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
12697                 return false;
12698             }
12699             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
12700                 return false;
12701             }
12702         }
12703         catch ( final Exception e ) {
12704             e.printStackTrace( System.out );
12705             return false;
12706         }
12707         return true;
12708     }
12709
12710     private static boolean testUniprotEntryRetrieval() {
12711         try {
12712             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 5000 );
12713             if ( !entry.getAccession().equals( "P12345" ) ) {
12714                 return false;
12715             }
12716             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
12717                 return false;
12718             }
12719             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
12720                 return false;
12721             }
12722             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
12723                 return false;
12724             }
12725             if ( !entry.getGeneName().equals( "GOT2" ) ) {
12726                 return false;
12727             }
12728             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
12729                 return false;
12730             }
12731             if ( entry.getMolecularSequence() == null ) {
12732                 return false;
12733             }
12734             if ( !entry
12735                     .getMolecularSequence()
12736                     .getMolecularSequenceAsString()
12737                     .startsWith( "MALLHSARVLSGVASAFHPGLAAAASARASSWWAHVEMGPPDPILGVTEAYKRDTNSKKMNLGVGAYRDDNGKPYVLPSVRKAEAQIAAKGLDKEYLPIGGLAEFCRASAELALGENSEV" )
12738                     || !entry.getMolecularSequence().getMolecularSequenceAsString().endsWith( "LAHAIHQVTK" ) ) {
12739                 System.out.println( "got: " + entry.getMolecularSequence().getMolecularSequenceAsString() );
12740                 System.out.println( "expected something else." );
12741                 return false;
12742             }
12743         }
12744         catch ( final IOException e ) {
12745             System.out.println();
12746             System.out.println( "the following might be due to absence internet connection:" );
12747             e.printStackTrace( System.out );
12748             return true;
12749         }
12750         catch ( final NullPointerException f ) {
12751             f.printStackTrace( System.out );
12752             return false;
12753         }
12754         catch ( final Exception e ) {
12755             return false;
12756         }
12757         return true;
12758     }
12759
12760     private static boolean testUniprotTaxonomySearch() {
12761         try {
12762             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
12763                                                                                                  10 );
12764             if ( results.size() != 1 ) {
12765                 return false;
12766             }
12767             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12768                 return false;
12769             }
12770             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12771                 return false;
12772             }
12773             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12774                 return false;
12775             }
12776             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12777                 return false;
12778             }
12779             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12780                 return false;
12781             }
12782             results = null;
12783             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
12784             if ( results.size() != 1 ) {
12785                 return false;
12786             }
12787             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12788                 return false;
12789             }
12790             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12791                 return false;
12792             }
12793             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12794                 return false;
12795             }
12796             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12797                 return false;
12798             }
12799             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12800                 return false;
12801             }
12802             results = null;
12803             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
12804             if ( results.size() != 1 ) {
12805                 return false;
12806             }
12807             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12808                 return false;
12809             }
12810             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12811                 return false;
12812             }
12813             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12814                 return false;
12815             }
12816             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12817                 return false;
12818             }
12819             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12820                 return false;
12821             }
12822             results = null;
12823             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
12824             if ( results.size() != 1 ) {
12825                 return false;
12826             }
12827             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12828                 return false;
12829             }
12830             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12831                 return false;
12832             }
12833             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12834                 return false;
12835             }
12836             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12837                 return false;
12838             }
12839             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12840                 return false;
12841             }
12842             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
12843                 return false;
12844             }
12845             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
12846                 return false;
12847             }
12848             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12849                     .equals( "Nematostella vectensis" ) ) {
12850                 System.out.println( results.get( 0 ).getLineage() );
12851                 return false;
12852             }
12853             //
12854             results = null;
12855             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
12856             if ( results.size() != 1 ) {
12857                 return false;
12858             }
12859             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12860                 return false;
12861             }
12862             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12863                 return false;
12864             }
12865             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12866                 return false;
12867             }
12868             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12869                 return false;
12870             }
12871             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12872                 return false;
12873             }
12874             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12875                     .equals( "Xenopus tropicalis" ) ) {
12876                 System.out.println( results.get( 0 ).getLineage() );
12877                 return false;
12878             }
12879             //
12880             results = null;
12881             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
12882             if ( results.size() != 1 ) {
12883                 return false;
12884             }
12885             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12886                 return false;
12887             }
12888             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12889                 return false;
12890             }
12891             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12892                 return false;
12893             }
12894             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12895                 return false;
12896             }
12897             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12898                 return false;
12899             }
12900             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12901                     .equals( "Xenopus tropicalis" ) ) {
12902                 System.out.println( results.get( 0 ).getLineage() );
12903                 return false;
12904             }
12905             //
12906             results = null;
12907             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
12908             if ( results.size() != 1 ) {
12909                 return false;
12910             }
12911             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12912                 return false;
12913             }
12914             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12915                 return false;
12916             }
12917             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12918                 return false;
12919             }
12920             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12921                 return false;
12922             }
12923             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12924                 return false;
12925             }
12926             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12927                     .equals( "Xenopus tropicalis" ) ) {
12928                 System.out.println( results.get( 0 ).getLineage() );
12929                 return false;
12930             }
12931         }
12932         catch ( final IOException e ) {
12933             System.out.println();
12934             System.out.println( "the following might be due to absence internet connection:" );
12935             e.printStackTrace( System.out );
12936             return true;
12937         }
12938         catch ( final Exception e ) {
12939             return false;
12940         }
12941         return true;
12942     }
12943     
12944     
12945 }