629eb44fab7577f74df5cfc3d0b55a5e5d0a66ae
[jalview.git] / forester / java / src / org / forester / test / Test.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // All rights reserved
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 //
23 // Contact: phylosoft @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
25
26 package org.forester.test;
27
28 import java.io.ByteArrayInputStream;
29 import java.io.File;
30 import java.io.FileInputStream;
31 import java.io.IOException;
32 import java.net.URL;
33 import java.util.ArrayList;
34 import java.util.Date;
35 import java.util.HashSet;
36 import java.util.Iterator;
37 import java.util.List;
38 import java.util.Locale;
39 import java.util.Set;
40 import java.util.SortedSet;
41
42 import org.forester.application.support_transfer;
43 import org.forester.archaeopteryx.TreePanelUtil;
44 import org.forester.development.DevelopmentTools;
45 import org.forester.evoinference.TestPhylogenyReconstruction;
46 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
47 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
48 import org.forester.go.TestGo;
49 import org.forester.io.parsers.FastaParser;
50 import org.forester.io.parsers.GeneralMsaParser;
51 import org.forester.io.parsers.HmmscanPerDomainTableParser;
52 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
53 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
54 import org.forester.io.parsers.nexus.NexusCharactersParser;
55 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
56 import org.forester.io.parsers.nhx.NHXParser;
57 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
58 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
59 import org.forester.io.parsers.tol.TolParser;
60 import org.forester.io.parsers.util.ParserUtils;
61 import org.forester.io.writers.PhylogenyWriter;
62 import org.forester.io.writers.SequenceWriter;
63 import org.forester.msa.BasicMsa;
64 import org.forester.msa.Mafft;
65 import org.forester.msa.Msa;
66 import org.forester.msa.MsaInferrer;
67 import org.forester.msa.MsaMethods;
68 import org.forester.pccx.TestPccx;
69 import org.forester.phylogeny.Phylogeny;
70 import org.forester.phylogeny.PhylogenyBranch;
71 import org.forester.phylogeny.PhylogenyMethods;
72 import org.forester.phylogeny.PhylogenyNode;
73 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
74 import org.forester.phylogeny.data.Accession;
75 import org.forester.phylogeny.data.Accession.Source;
76 import org.forester.phylogeny.data.BinaryCharacters;
77 import org.forester.phylogeny.data.BranchWidth;
78 import org.forester.phylogeny.data.Confidence;
79 import org.forester.phylogeny.data.Distribution;
80 import org.forester.phylogeny.data.DomainArchitecture;
81 import org.forester.phylogeny.data.Event;
82 import org.forester.phylogeny.data.Identifier;
83 import org.forester.phylogeny.data.PhylogenyData;
84 import org.forester.phylogeny.data.PhylogenyDataUtil;
85 import org.forester.phylogeny.data.Polygon;
86 import org.forester.phylogeny.data.PropertiesMap;
87 import org.forester.phylogeny.data.Property;
88 import org.forester.phylogeny.data.Property.AppliesTo;
89 import org.forester.phylogeny.data.ProteinDomain;
90 import org.forester.phylogeny.data.Taxonomy;
91 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
92 import org.forester.phylogeny.factories.PhylogenyFactory;
93 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
94 import org.forester.protein.BasicDomain;
95 import org.forester.protein.BasicProtein;
96 import org.forester.protein.Domain;
97 import org.forester.protein.Protein;
98 import org.forester.protein.ProteinId;
99 import org.forester.rio.TestRIO;
100 import org.forester.sdi.SDI;
101 import org.forester.sdi.SDIR;
102 import org.forester.sdi.TestGSDI;
103 import org.forester.sequence.BasicSequence;
104 import org.forester.sequence.Sequence;
105 import org.forester.species.BasicSpecies;
106 import org.forester.species.Species;
107 import org.forester.surfacing.TestSurfacing;
108 import org.forester.tools.ConfidenceAssessor;
109 import org.forester.tools.SupportCount;
110 import org.forester.tools.TreeSplitMatrix;
111 import org.forester.util.AsciiHistogram;
112 import org.forester.util.BasicDescriptiveStatistics;
113 import org.forester.util.BasicTable;
114 import org.forester.util.BasicTableParser;
115 import org.forester.util.DescriptiveStatistics;
116 import org.forester.util.ForesterConstants;
117 import org.forester.util.ForesterUtil;
118 import org.forester.util.GeneralTable;
119 import org.forester.util.SequenceAccessionTools;
120 import org.forester.ws.seqdb.SequenceDatabaseEntry;
121 import org.forester.ws.seqdb.SequenceDbWsTools;
122 import org.forester.ws.seqdb.UniProtTaxonomy;
123 import org.forester.ws.wabi.TxSearch;
124 import org.forester.ws.wabi.TxSearch.RANKS;
125 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
126 import org.forester.ws.wabi.TxSearch.TAX_RANK;
127
128 @SuppressWarnings( "unused")
129 public final class Test {
130
131     private final static boolean PERFORM_DB_TESTS          = false;
132     private final static double  ZERO_DIFF                 = 1.0E-9;
133     private final static String  PATH_TO_TEST_DATA         = System.getProperty( "user.dir" )
134                                                                    + ForesterUtil.getFileSeparator() + "test_data"
135                                                                    + ForesterUtil.getFileSeparator();
136     private final static String  PATH_TO_RESOURCES         = System.getProperty( "user.dir" )
137                                                                    + ForesterUtil.getFileSeparator() + "resources"
138                                                                    + ForesterUtil.getFileSeparator();
139     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
140     private static final String  PHYLOXML_REMOTE_XSD       = ForesterConstants.PHYLO_XML_LOCATION + "/"
141                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
142                                                                    + ForesterConstants.PHYLO_XML_XSD;
143     private static final String  PHYLOXML_LOCAL_XSD        = PATH_TO_RESOURCES + "phyloxml_schema/"
144                                                                    + ForesterConstants.PHYLO_XML_VERSION + "/"
145                                                                    + ForesterConstants.PHYLO_XML_XSD;
146
147     public static boolean testOverlapRemoval() {
148         try {
149             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
150             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
151             final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
152             final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
153             final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
154             final List<Boolean> covered = new ArrayList<Boolean>();
155             covered.add( true ); // 0
156             covered.add( false ); // 1
157             covered.add( true ); // 2
158             covered.add( false ); // 3
159             covered.add( true ); // 4
160             covered.add( true ); // 5
161             covered.add( false ); // 6
162             covered.add( true ); // 7
163             covered.add( true ); // 8
164             if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
165                 return false;
166             }
167             if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
168                 return false;
169             }
170             if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
171                 return false;
172             }
173             if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
174                 return false;
175             }
176             if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
177                 return false;
178             }
179             final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
180             final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
181             final Protein ab = new BasicProtein( "ab", "varanus", 0 );
182             ab.addProteinDomain( a );
183             ab.addProteinDomain( b );
184             final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
185             if ( ab.getNumberOfProteinDomains() != 2 ) {
186                 return false;
187             }
188             if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
189                 return false;
190             }
191             if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
192                 return false;
193             }
194             final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
195             if ( ab.getNumberOfProteinDomains() != 2 ) {
196                 return false;
197             }
198             if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
199                 return false;
200             }
201             final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
202             final Domain d = new BasicDomain( "d",
203                                               ( short ) 10000,
204                                               ( short ) 10500,
205                                               ( short ) 1,
206                                               ( short ) 1,
207                                               0.0000001,
208                                               1 );
209             final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
210             final Protein cde = new BasicProtein( "cde", "varanus", 0 );
211             cde.addProteinDomain( c );
212             cde.addProteinDomain( d );
213             cde.addProteinDomain( e );
214             final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
215             if ( cde.getNumberOfProteinDomains() != 3 ) {
216                 return false;
217             }
218             if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
219                 return false;
220             }
221             final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
222             final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
223             final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
224             final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
225             final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
226             final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
227             fghi.addProteinDomain( f );
228             fghi.addProteinDomain( g );
229             fghi.addProteinDomain( h );
230             fghi.addProteinDomain( i );
231             fghi.addProteinDomain( i );
232             fghi.addProteinDomain( i );
233             fghi.addProteinDomain( i2 );
234             final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
235             if ( fghi.getNumberOfProteinDomains() != 7 ) {
236                 return false;
237             }
238             if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
239                 return false;
240             }
241             if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
242                 return false;
243             }
244             final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
245             if ( fghi.getNumberOfProteinDomains() != 7 ) {
246                 return false;
247             }
248             if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
249                 return false;
250             }
251             final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
252             final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
253             final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
254             final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
255             final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
256             final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
257             final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
258             final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
259             jklm.addProteinDomain( j );
260             jklm.addProteinDomain( k );
261             jklm.addProteinDomain( l );
262             jklm.addProteinDomain( m );
263             jklm.addProteinDomain( m0 );
264             jklm.addProteinDomain( m1 );
265             jklm.addProteinDomain( m2 );
266             final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
267             if ( jklm.getNumberOfProteinDomains() != 7 ) {
268                 return false;
269             }
270             if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
271                 return false;
272             }
273             if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
274                 return false;
275             }
276             final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
277             if ( jklm.getNumberOfProteinDomains() != 7 ) {
278                 return false;
279             }
280             if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
281                 return false;
282             }
283             final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
284             final Protein od = new BasicProtein( "od", "varanus", 0 );
285             od.addProteinDomain( only );
286             final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
287             if ( od.getNumberOfProteinDomains() != 1 ) {
288                 return false;
289             }
290             if ( od_s0.getNumberOfProteinDomains() != 1 ) {
291                 return false;
292             }
293         }
294         catch ( final Exception e ) {
295             e.printStackTrace( System.out );
296             return false;
297         }
298         return true;
299     }
300
301     public static boolean testEngulfingOverlapRemoval() {
302         try {
303             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
304             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
305             final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
306             final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
307             final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
308             final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
309             final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
310             final List<Boolean> covered = new ArrayList<Boolean>();
311             covered.add( true ); // 0
312             covered.add( false ); // 1
313             covered.add( true ); // 2
314             covered.add( false ); // 3
315             covered.add( true ); // 4
316             covered.add( true ); // 5
317             covered.add( false ); // 6
318             covered.add( true ); // 7
319             covered.add( true ); // 8
320             if ( ForesterUtil.isEngulfed( d0, covered ) ) {
321                 return false;
322             }
323             if ( ForesterUtil.isEngulfed( d1, covered ) ) {
324                 return false;
325             }
326             if ( ForesterUtil.isEngulfed( d2, covered ) ) {
327                 return false;
328             }
329             if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
330                 return false;
331             }
332             if ( ForesterUtil.isEngulfed( d4, covered ) ) {
333                 return false;
334             }
335             if ( ForesterUtil.isEngulfed( d5, covered ) ) {
336                 return false;
337             }
338             if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
339                 return false;
340             }
341             final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
342             final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
343             final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
344             final Protein abc = new BasicProtein( "abc", "nemve", 0 );
345             abc.addProteinDomain( a );
346             abc.addProteinDomain( b );
347             abc.addProteinDomain( c );
348             final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
349             final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
350             if ( abc.getNumberOfProteinDomains() != 3 ) {
351                 return false;
352             }
353             if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
354                 return false;
355             }
356             if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
357                 return false;
358             }
359             if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
360                 return false;
361             }
362             if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
363                 return false;
364             }
365             final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
366             final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
367             final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
368             final Protein def = new BasicProtein( "def", "nemve", 0 );
369             def.addProteinDomain( d );
370             def.addProteinDomain( e );
371             def.addProteinDomain( f );
372             final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
373             final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
374             if ( def.getNumberOfProteinDomains() != 3 ) {
375                 return false;
376             }
377             if ( def_r1.getNumberOfProteinDomains() != 3 ) {
378                 return false;
379             }
380             if ( def_r2.getNumberOfProteinDomains() != 3 ) {
381                 return false;
382             }
383             if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
384                 return false;
385             }
386             if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
387                 return false;
388             }
389             if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
390                 return false;
391             }
392         }
393         catch ( final Exception e ) {
394             e.printStackTrace( System.out );
395             return false;
396         }
397         return true;
398     }
399
400     public static boolean isEqual( final double a, final double b ) {
401         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
402     }
403
404     public static final boolean testNHXparsingFromURL() {
405         try {
406             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
407             final URL u = new URL( s );
408             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
409             final Phylogeny[] phys = factory.create( u.openStream(), new NHXParser() );
410             if ( ( phys == null ) || ( phys.length != 1 ) ) {
411                 return false;
412             }
413             if ( !phys[ 0 ].toNewHampshire().equals( "((a,b),c);" ) ) {
414                 System.out.println( phys[ 0 ].toNewHampshire() );
415                 return false;
416             }
417             final Phylogeny[] phys2 = factory.create( u.openStream(), new NHXParser() );
418             if ( ( phys2 == null ) || ( phys2.length != 1 ) ) {
419                 return false;
420             }
421             if ( !phys2[ 0 ].toNewHampshire().equals( "((a,b),c);" ) ) {
422                 System.out.println( phys2[ 0 ].toNewHampshire() );
423                 return false;
424             }
425         }
426         catch ( final Exception e ) {
427             e.printStackTrace();
428         }
429         return true;
430     }
431
432     public static void main( final String[] args ) {
433         System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
434         System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
435                 + "]" );
436         Locale.setDefault( Locale.US );
437         System.out.println( "[Locale: " + Locale.getDefault() + "]" );
438         int failed = 0;
439         int succeeded = 0;
440         System.out.print( "[Test if directory with files for testing exists/is readable: " );
441         if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
442             System.out.println( "OK.]" );
443         }
444         else {
445             System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
446             System.out.println( "Testing aborted." );
447             System.exit( -1 );
448         }
449         System.out.print( "[Test if resources directory exists/is readable: " );
450         if ( testDir( PATH_TO_RESOURCES ) ) {
451             System.out.println( "OK.]" );
452         }
453         else {
454             System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
455             System.out.println( "Testing aborted." );
456             System.exit( -1 );
457         }
458         final long start_time = new Date().getTime();
459         System.out.print( "Basic node methods: " );
460         if ( Test.testBasicNodeMethods() ) {
461             System.out.println( "OK." );
462             succeeded++;
463         }
464         else {
465             System.out.println( "failed." );
466             failed++;
467         }
468         System.out.print( "Protein id: " );
469         if ( !testProteinId() ) {
470             System.out.println( "failed." );
471             failed++;
472         }
473         else {
474             succeeded++;
475         }
476         System.out.println( "OK." );
477         System.out.print( "Species: " );
478         if ( !testSpecies() ) {
479             System.out.println( "failed." );
480             failed++;
481         }
482         else {
483             succeeded++;
484         }
485         System.out.println( "OK." );
486         System.out.print( "Basic domain: " );
487         if ( !testBasicDomain() ) {
488             System.out.println( "failed." );
489             failed++;
490         }
491         else {
492             succeeded++;
493         }
494         System.out.println( "OK." );
495         System.out.print( "Basic protein: " );
496         if ( !testBasicProtein() ) {
497             System.out.println( "failed." );
498             failed++;
499         }
500         else {
501             succeeded++;
502         }
503         System.out.println( "OK." );
504         System.out.print( "Sequence writer: " );
505         if ( testSequenceWriter() ) {
506             System.out.println( "OK." );
507             succeeded++;
508         }
509         else {
510             System.out.println( "failed." );
511             failed++;
512         }
513         System.out.print( "Sequence id parsing: " );
514         if ( testSequenceIdParsing() ) {
515             System.out.println( "OK." );
516             succeeded++;
517         }
518         else {
519             System.out.println( "failed." );
520             failed++;
521         }
522         System.out.print( "UniProtKB id extraction: " );
523         if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
524             System.out.println( "OK." );
525             succeeded++;
526         }
527         else {
528             System.out.println( "failed." );
529             failed++;
530         }
531         System.out.print( "Sequence DB tools 1: " );
532         if ( testSequenceDbWsTools1() ) {
533             System.out.println( "OK." );
534             succeeded++;
535         }
536         else {
537             System.out.println( "failed." );
538             failed++;
539         }
540         if ( PERFORM_DB_TESTS ) {
541             System.out.print( "Ebi Entry Retrieval: " );
542             if ( Test.testEbiEntryRetrieval() ) {
543                 System.out.println( "OK." );
544                 succeeded++;
545             }
546             else {
547                 System.out.println( "failed." );
548                 failed++;
549             }
550         }
551         // System.exit( 0 );
552         if ( PERFORM_DB_TESTS ) {
553             System.out.print( "Sequence DB tools 2: " );
554             if ( testSequenceDbWsTools2() ) {
555                 System.out.println( "OK." );
556                 succeeded++;
557             }
558             else {
559                 System.out.println( "failed." );
560                 failed++;
561                 System.exit( -1 );
562             }
563         }
564         // System.exit( 0 );
565         System.out.print( "Hmmscan output parser: " );
566         if ( testHmmscanOutputParser() ) {
567             System.out.println( "OK." );
568             succeeded++;
569         }
570         else {
571             System.out.println( "failed." );
572             failed++;
573         }
574         //
575         System.out.print( "Overlap removal: " );
576         if ( !org.forester.test.Test.testOverlapRemoval() ) {
577             System.out.println( "failed." );
578             failed++;
579         }
580         else {
581             succeeded++;
582         }
583         System.out.println( "OK." );
584         System.out.print( "Engulfing overlap removal: " );
585         if ( !Test.testEngulfingOverlapRemoval() ) {
586             System.out.println( "failed." );
587             failed++;
588         }
589         else {
590             succeeded++;
591         }
592         System.out.println( "OK." );
593         //
594         System.out.print( "Taxonomy code extraction: " );
595         if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
596             System.out.println( "OK." );
597             succeeded++;
598         }
599         else {
600             System.out.println( "failed." );
601             failed++;
602         }
603         System.out.print( "SN extraction: " );
604         if ( Test.testExtractSNFromNodeName() ) {
605             System.out.println( "OK." );
606             succeeded++;
607         }
608         else {
609             System.out.println( "failed." );
610             failed++;
611         }
612         System.out.print( "Taxonomy extraction (general): " );
613         if ( Test.testTaxonomyExtraction() ) {
614             System.out.println( "OK." );
615             succeeded++;
616         }
617         else {
618             System.out.println( "failed." );
619             failed++;
620         }
621         System.out.print( "Uri for Aptx web sequence accession: " );
622         if ( Test.testCreateUriForSeqWeb() ) {
623             System.out.println( "OK." );
624             succeeded++;
625         }
626         else {
627             System.out.println( "failed." );
628             failed++;
629         }
630         System.out.print( "Basic node construction and parsing of NHX (node level): " );
631         if ( Test.testNHXNodeParsing() ) {
632             System.out.println( "OK." );
633             succeeded++;
634         }
635         else {
636             System.out.println( "failed." );
637             failed++;
638         }
639         System.out.print( "NHX parsing iterating: " );
640         if ( Test.testNHParsingIter() ) {
641             System.out.println( "OK." );
642             succeeded++;
643         }
644         else {
645             System.out.println( "failed." );
646             failed++;
647         }
648         System.out.print( "NH parsing: " );
649         if ( Test.testNHParsing() ) {
650             System.out.println( "OK." );
651             succeeded++;
652         }
653         else {
654             System.out.println( "failed." );
655             failed++;
656         }
657         System.out.print( "Conversion to NHX (node level): " );
658         if ( Test.testNHXconversion() ) {
659             System.out.println( "OK." );
660             succeeded++;
661         }
662         else {
663             System.out.println( "failed." );
664             failed++;
665         }
666         System.out.print( "NHX parsing: " );
667         if ( Test.testNHXParsing() ) {
668             System.out.println( "OK." );
669             succeeded++;
670         }
671         else {
672             System.out.println( "failed." );
673             failed++;
674         }
675         System.out.print( "NHX parsing with quotes: " );
676         if ( Test.testNHXParsingQuotes() ) {
677             System.out.println( "OK." );
678             succeeded++;
679         }
680         else {
681             System.out.println( "failed." );
682             failed++;
683         }
684         System.out.print( "NHX parsing (MrBayes): " );
685         if ( Test.testNHXParsingMB() ) {
686             System.out.println( "OK." );
687             succeeded++;
688         }
689         else {
690             System.out.println( "failed." );
691             failed++;
692         }
693         System.out.print( "Nexus characters parsing: " );
694         if ( Test.testNexusCharactersParsing() ) {
695             System.out.println( "OK." );
696             succeeded++;
697         }
698         else {
699             System.out.println( "failed." );
700             failed++;
701         }
702         System.out.print( "Nexus tree parsing iterating: " );
703         if ( Test.testNexusTreeParsingIterating() ) {
704             System.out.println( "OK." );
705             succeeded++;
706         }
707         else {
708             System.out.println( "failed." );
709             failed++;
710         }
711         System.out.print( "Nexus tree parsing: " );
712         if ( Test.testNexusTreeParsing() ) {
713             System.out.println( "OK." );
714             succeeded++;
715         }
716         else {
717             System.out.println( "failed." );
718             failed++;
719         }
720         System.out.print( "Nexus tree parsing (translating): " );
721         if ( Test.testNexusTreeParsingTranslating() ) {
722             System.out.println( "OK." );
723             succeeded++;
724         }
725         else {
726             System.out.println( "failed." );
727             failed++;
728         }
729         System.out.print( "Nexus matrix parsing: " );
730         if ( Test.testNexusMatrixParsing() ) {
731             System.out.println( "OK." );
732             succeeded++;
733         }
734         else {
735             System.out.println( "failed." );
736             failed++;
737         }
738         System.out.print( "Basic phyloXML parsing: " );
739         if ( Test.testBasicPhyloXMLparsing() ) {
740             System.out.println( "OK." );
741             succeeded++;
742         }
743         else {
744             System.out.println( "failed." );
745             failed++;
746         }
747         System.out.print( "Basic phyloXML parsing (validating against schema): " );
748         if ( testBasicPhyloXMLparsingValidating() ) {
749             System.out.println( "OK." );
750             succeeded++;
751         }
752         else {
753             System.out.println( "failed." );
754             failed++;
755         }
756         System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
757         if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
758             System.out.println( "OK." );
759             succeeded++;
760         }
761         else {
762             System.out.println( "failed." );
763             failed++;
764         }
765         System.out.print( "phyloXML Distribution Element: " );
766         if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
767             System.out.println( "OK." );
768             succeeded++;
769         }
770         else {
771             System.out.println( "failed." );
772             failed++;
773         }
774         System.out.print( "Tol XML parsing: " );
775         if ( Test.testBasicTolXMLparsing() ) {
776             System.out.println( "OK." );
777             succeeded++;
778         }
779         else {
780             System.out.println( "failed." );
781             failed++;
782         }
783         System.out.print( "Copying of node data: " );
784         if ( Test.testCopyOfNodeData() ) {
785             System.out.println( "OK." );
786             succeeded++;
787         }
788         else {
789             System.out.println( "failed." );
790             failed++;
791         }
792         System.out.print( "Tree copy: " );
793         if ( Test.testTreeCopy() ) {
794             System.out.println( "OK." );
795             succeeded++;
796         }
797         else {
798             System.out.println( "failed." );
799             failed++;
800         }
801         System.out.print( "Basic tree methods: " );
802         if ( Test.testBasicTreeMethods() ) {
803             System.out.println( "OK." );
804             succeeded++;
805         }
806         else {
807             System.out.println( "failed." );
808             failed++;
809         }
810         System.out.print( "Tree methods: " );
811         if ( Test.testTreeMethods() ) {
812             System.out.println( "OK." );
813             succeeded++;
814         }
815         else {
816             System.out.println( "failed." );
817             failed++;
818         }
819         System.out.print( "Postorder Iterator: " );
820         if ( Test.testPostOrderIterator() ) {
821             System.out.println( "OK." );
822             succeeded++;
823         }
824         else {
825             System.out.println( "failed." );
826             failed++;
827         }
828         System.out.print( "Preorder Iterator: " );
829         if ( Test.testPreOrderIterator() ) {
830             System.out.println( "OK." );
831             succeeded++;
832         }
833         else {
834             System.out.println( "failed." );
835             failed++;
836         }
837         System.out.print( "Levelorder Iterator: " );
838         if ( Test.testLevelOrderIterator() ) {
839             System.out.println( "OK." );
840             succeeded++;
841         }
842         else {
843             System.out.println( "failed." );
844             failed++;
845         }
846         System.out.print( "Re-id methods: " );
847         if ( Test.testReIdMethods() ) {
848             System.out.println( "OK." );
849             succeeded++;
850         }
851         else {
852             System.out.println( "failed." );
853             failed++;
854         }
855         System.out.print( "Methods on last external nodes: " );
856         if ( Test.testLastExternalNodeMethods() ) {
857             System.out.println( "OK." );
858             succeeded++;
859         }
860         else {
861             System.out.println( "failed." );
862             failed++;
863         }
864         System.out.print( "Methods on external nodes: " );
865         if ( Test.testExternalNodeRelatedMethods() ) {
866             System.out.println( "OK." );
867             succeeded++;
868         }
869         else {
870             System.out.println( "failed." );
871             failed++;
872         }
873         System.out.print( "Deletion of external nodes: " );
874         if ( Test.testDeletionOfExternalNodes() ) {
875             System.out.println( "OK." );
876             succeeded++;
877         }
878         else {
879             System.out.println( "failed." );
880             failed++;
881         }
882         System.out.print( "Subtree deletion: " );
883         if ( Test.testSubtreeDeletion() ) {
884             System.out.println( "OK." );
885             succeeded++;
886         }
887         else {
888             System.out.println( "failed." );
889             failed++;
890         }
891         System.out.print( "Phylogeny branch: " );
892         if ( Test.testPhylogenyBranch() ) {
893             System.out.println( "OK." );
894             succeeded++;
895         }
896         else {
897             System.out.println( "failed." );
898             failed++;
899         }
900         System.out.print( "Rerooting: " );
901         if ( Test.testRerooting() ) {
902             System.out.println( "OK." );
903             succeeded++;
904         }
905         else {
906             System.out.println( "failed." );
907             failed++;
908         }
909         System.out.print( "Mipoint rooting: " );
910         if ( Test.testMidpointrooting() ) {
911             System.out.println( "OK." );
912             succeeded++;
913         }
914         else {
915             System.out.println( "failed." );
916             failed++;
917         }
918         System.out.print( "Node removal: " );
919         if ( Test.testNodeRemoval() ) {
920             System.out.println( "OK." );
921             succeeded++;
922         }
923         else {
924             System.out.println( "failed." );
925             failed++;
926         }
927         System.out.print( "Support count: " );
928         if ( Test.testSupportCount() ) {
929             System.out.println( "OK." );
930             succeeded++;
931         }
932         else {
933             System.out.println( "failed." );
934             failed++;
935         }
936         System.out.print( "Support transfer: " );
937         if ( Test.testSupportTransfer() ) {
938             System.out.println( "OK." );
939             succeeded++;
940         }
941         else {
942             System.out.println( "failed." );
943             failed++;
944         }
945         System.out.print( "Finding of LCA: " );
946         if ( Test.testGetLCA() ) {
947             System.out.println( "OK." );
948             succeeded++;
949         }
950         else {
951             System.out.println( "failed." );
952             failed++;
953         }
954         System.out.print( "Finding of LCA 2: " );
955         if ( Test.testGetLCA2() ) {
956             System.out.println( "OK." );
957             succeeded++;
958         }
959         else {
960             System.out.println( "failed." );
961             failed++;
962         }
963         System.out.print( "Calculation of distance between nodes: " );
964         if ( Test.testGetDistance() ) {
965             System.out.println( "OK." );
966             succeeded++;
967         }
968         else {
969             System.out.println( "failed." );
970             failed++;
971         }
972         System.out.print( "Descriptive statistics: " );
973         if ( Test.testDescriptiveStatistics() ) {
974             System.out.println( "OK." );
975             succeeded++;
976         }
977         else {
978             System.out.println( "failed." );
979             failed++;
980         }
981         System.out.print( "Data objects and methods: " );
982         if ( Test.testDataObjects() ) {
983             System.out.println( "OK." );
984             succeeded++;
985         }
986         else {
987             System.out.println( "failed." );
988             failed++;
989         }
990         System.out.print( "Properties map: " );
991         if ( Test.testPropertiesMap() ) {
992             System.out.println( "OK." );
993             succeeded++;
994         }
995         else {
996             System.out.println( "failed." );
997             failed++;
998         }
999         System.out.print( "SDIse: " );
1000         if ( Test.testSDIse() ) {
1001             System.out.println( "OK." );
1002             succeeded++;
1003         }
1004         else {
1005             System.out.println( "failed." );
1006             failed++;
1007         }
1008         System.out.print( "SDIunrooted: " );
1009         if ( Test.testSDIunrooted() ) {
1010             System.out.println( "OK." );
1011             succeeded++;
1012         }
1013         else {
1014             System.out.println( "failed." );
1015             failed++;
1016         }
1017         System.out.print( "GSDI: " );
1018         if ( TestGSDI.test() ) {
1019             System.out.println( "OK." );
1020             succeeded++;
1021         }
1022         else {
1023             System.out.println( "failed." );
1024             failed++;
1025         }
1026         System.out.print( "RIO: " );
1027         if ( TestRIO.test() ) {
1028             System.out.println( "OK." );
1029             succeeded++;
1030         }
1031         else {
1032             System.out.println( "failed." );
1033             failed++;
1034         }
1035         System.out.print( "Phylogeny reconstruction:" );
1036         System.out.println();
1037         if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
1038             System.out.println( "OK." );
1039             succeeded++;
1040         }
1041         else {
1042             System.out.println( "failed." );
1043             failed++;
1044         }
1045         System.out.print( "Analysis of domain architectures: " );
1046         System.out.println();
1047         if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
1048             System.out.println( "OK." );
1049             succeeded++;
1050         }
1051         else {
1052             System.out.println( "failed." );
1053             failed++;
1054         }
1055         System.out.print( "GO: " );
1056         System.out.println();
1057         if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
1058             System.out.println( "OK." );
1059             succeeded++;
1060         }
1061         else {
1062             System.out.println( "failed." );
1063             failed++;
1064         }
1065         System.out.print( "Modeling tools: " );
1066         if ( TestPccx.test() ) {
1067             System.out.println( "OK." );
1068             succeeded++;
1069         }
1070         else {
1071             System.out.println( "failed." );
1072             failed++;
1073         }
1074         System.out.print( "Split Matrix strict: " );
1075         if ( Test.testSplitStrict() ) {
1076             System.out.println( "OK." );
1077             succeeded++;
1078         }
1079         else {
1080             System.out.println( "failed." );
1081             failed++;
1082         }
1083         System.out.print( "Split Matrix: " );
1084         if ( Test.testSplit() ) {
1085             System.out.println( "OK." );
1086             succeeded++;
1087         }
1088         else {
1089             System.out.println( "failed." );
1090             failed++;
1091         }
1092         System.out.print( "Confidence Assessor: " );
1093         if ( Test.testConfidenceAssessor() ) {
1094             System.out.println( "OK." );
1095             succeeded++;
1096         }
1097         else {
1098             System.out.println( "failed." );
1099             failed++;
1100         }
1101         System.out.print( "Basic table: " );
1102         if ( Test.testBasicTable() ) {
1103             System.out.println( "OK." );
1104             succeeded++;
1105         }
1106         else {
1107             System.out.println( "failed." );
1108             failed++;
1109         }
1110         System.out.print( "General table: " );
1111         if ( Test.testGeneralTable() ) {
1112             System.out.println( "OK." );
1113             succeeded++;
1114         }
1115         else {
1116             System.out.println( "failed." );
1117             failed++;
1118         }
1119         System.out.print( "Amino acid sequence: " );
1120         if ( Test.testAminoAcidSequence() ) {
1121             System.out.println( "OK." );
1122             succeeded++;
1123         }
1124         else {
1125             System.out.println( "failed." );
1126             failed++;
1127         }
1128         System.out.print( "General MSA parser: " );
1129         if ( Test.testGeneralMsaParser() ) {
1130             System.out.println( "OK." );
1131             succeeded++;
1132         }
1133         else {
1134             System.out.println( "failed." );
1135             failed++;
1136         }
1137         System.out.print( "Fasta parser for msa: " );
1138         if ( Test.testFastaParser() ) {
1139             System.out.println( "OK." );
1140             succeeded++;
1141         }
1142         else {
1143             System.out.println( "failed." );
1144             failed++;
1145         }
1146         System.out.print( "Creation of balanced phylogeny: " );
1147         if ( Test.testCreateBalancedPhylogeny() ) {
1148             System.out.println( "OK." );
1149             succeeded++;
1150         }
1151         else {
1152             System.out.println( "failed." );
1153             failed++;
1154         }
1155         System.out.print( "Genbank accessor parsing: " );
1156         if ( Test.testGenbankAccessorParsing() ) {
1157             System.out.println( "OK." );
1158             succeeded++;
1159         }
1160         else {
1161             System.out.println( "failed." );
1162             failed++;
1163         }
1164         if ( PERFORM_DB_TESTS ) {
1165             System.out.print( "Uniprot Entry Retrieval: " );
1166             if ( Test.testUniprotEntryRetrieval() ) {
1167                 System.out.println( "OK." );
1168                 succeeded++;
1169             }
1170             else {
1171                 System.out.println( "failed." );
1172                 failed++;
1173             }
1174         }
1175         if ( PERFORM_DB_TESTS ) {
1176             System.out.print( "Uniprot Taxonomy Search: " );
1177             if ( Test.testUniprotTaxonomySearch() ) {
1178                 System.out.println( "OK." );
1179                 succeeded++;
1180             }
1181             else {
1182                 System.out.println( "failed." );
1183                 failed++;
1184             }
1185         }
1186         //----
1187         String path = "";
1188         final String os = ForesterUtil.OS_NAME.toLowerCase();
1189         if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
1190             path = "/usr/local/bin/mafft";
1191         }
1192         else if ( os.indexOf( "win" ) >= 0 ) {
1193             path = "C:\\Program Files\\mafft-win\\mafft.bat";
1194         }
1195         else {
1196             path = "/home/czmasek/bin/mafft";
1197         }
1198         if ( !MsaInferrer.isInstalled( path ) ) {
1199             path = "mafft";
1200         }
1201         if ( !MsaInferrer.isInstalled( path ) ) {
1202             path = "/usr/local/bin/mafft";
1203         }
1204         if ( MsaInferrer.isInstalled( path ) ) {
1205             System.out.print( "MAFFT (external program): " );
1206             if ( Test.testMafft( path ) ) {
1207                 System.out.println( "OK." );
1208                 succeeded++;
1209             }
1210             else {
1211                 System.out.println( "failed [will not count towards failed tests]" );
1212             }
1213         }
1214         //----
1215         System.out.print( "Next nodes with collapsed: " );
1216         if ( Test.testNextNodeWithCollapsing() ) {
1217             System.out.println( "OK." );
1218             succeeded++;
1219         }
1220         else {
1221             System.out.println( "failed." );
1222             failed++;
1223         }
1224         System.out.print( "Simple MSA quality: " );
1225         if ( Test.testMsaQualityMethod() ) {
1226             System.out.println( "OK." );
1227             succeeded++;
1228         }
1229         else {
1230             System.out.println( "failed." );
1231             failed++;
1232         }
1233         System.out.print( "NHX parsing from URL: " );
1234         if ( Test.testNHXparsingFromURL() ) {
1235             System.out.println( "OK." );
1236             succeeded++;
1237         }
1238         else {
1239             System.out.println( "failed." );
1240             failed++;
1241         }
1242         System.out.println();
1243         final Runtime rt = java.lang.Runtime.getRuntime();
1244         final long free_memory = rt.freeMemory() / 1000000;
1245         final long total_memory = rt.totalMemory() / 1000000;
1246         System.out.println( "Running time    : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1247                 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1248         System.out.println();
1249         System.out.println( "Successful tests: " + succeeded );
1250         System.out.println( "Failed     tests: " + failed );
1251         System.out.println();
1252         if ( failed < 1 ) {
1253             System.out.println( "OK." );
1254         }
1255         else {
1256             System.out.println( "Not OK." );
1257         }
1258     }
1259
1260     private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1261         final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1262         return p;
1263     }
1264
1265     private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1266         return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1267     }
1268
1269     private static boolean testAminoAcidSequence() {
1270         try {
1271             final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1272             if ( aa1.getLength() != 13 ) {
1273                 return false;
1274             }
1275             if ( aa1.getResidueAt( 0 ) != 'A' ) {
1276                 return false;
1277             }
1278             if ( aa1.getResidueAt( 2 ) != 'K' ) {
1279                 return false;
1280             }
1281             if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1282                 return false;
1283             }
1284             final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1285             if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
1286                 return false;
1287             }
1288             final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1289             if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1290                 return false;
1291             }
1292             final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1293             if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1294                 return false;
1295             }
1296         }
1297         catch ( final Exception e ) {
1298             e.printStackTrace();
1299             return false;
1300         }
1301         return true;
1302     }
1303
1304     private static boolean testBasicDomain() {
1305         try {
1306             final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1307             if ( !pd.getDomainId().equals( "id" ) ) {
1308                 return false;
1309             }
1310             if ( pd.getNumber() != 1 ) {
1311                 return false;
1312             }
1313             if ( pd.getTotalCount() != 4 ) {
1314                 return false;
1315             }
1316             if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1317                 return false;
1318             }
1319             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1320             final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1321             final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1322             final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1323             final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1324             if ( !a1.equals( a1 ) ) {
1325                 return false;
1326             }
1327             if ( !a1.equals( a1_copy ) ) {
1328                 return false;
1329             }
1330             if ( !a1.equals( a1_equal ) ) {
1331                 return false;
1332             }
1333             if ( !a1.equals( a2 ) ) {
1334                 return false;
1335             }
1336             if ( a1.equals( a3 ) ) {
1337                 return false;
1338             }
1339             if ( a1.compareTo( a1 ) != 0 ) {
1340                 return false;
1341             }
1342             if ( a1.compareTo( a1_copy ) != 0 ) {
1343                 return false;
1344             }
1345             if ( a1.compareTo( a1_equal ) != 0 ) {
1346                 return false;
1347             }
1348             if ( a1.compareTo( a2 ) != 0 ) {
1349                 return false;
1350             }
1351             if ( a1.compareTo( a3 ) == 0 ) {
1352                 return false;
1353             }
1354         }
1355         catch ( final Exception e ) {
1356             e.printStackTrace( System.out );
1357             return false;
1358         }
1359         return true;
1360     }
1361
1362     private static boolean testBasicNodeMethods() {
1363         try {
1364             if ( PhylogenyNode.getNodeCount() != 0 ) {
1365                 return false;
1366             }
1367             final PhylogenyNode n1 = new PhylogenyNode();
1368             final PhylogenyNode n2 = PhylogenyNode
1369                     .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1370             final PhylogenyNode n3 = PhylogenyNode
1371                     .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1372             final PhylogenyNode n4 = PhylogenyNode
1373                     .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1374             if ( n1.isHasAssignedEvent() ) {
1375                 return false;
1376             }
1377             if ( PhylogenyNode.getNodeCount() != 4 ) {
1378                 return false;
1379             }
1380             if ( n3.getIndicator() != 0 ) {
1381                 return false;
1382             }
1383             if ( n3.getNumberOfExternalNodes() != 1 ) {
1384                 return false;
1385             }
1386             if ( !n3.isExternal() ) {
1387                 return false;
1388             }
1389             if ( !n3.isRoot() ) {
1390                 return false;
1391             }
1392             if ( !n4.getName().equals( "n4" ) ) {
1393                 return false;
1394             }
1395         }
1396         catch ( final Exception e ) {
1397             e.printStackTrace( System.out );
1398             return false;
1399         }
1400         return true;
1401     }
1402
1403     private static boolean testBasicPhyloXMLparsing() {
1404         try {
1405             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1406             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1407             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1408                                                               xml_parser );
1409             if ( xml_parser.getErrorCount() > 0 ) {
1410                 System.out.println( xml_parser.getErrorMessages().toString() );
1411                 return false;
1412             }
1413             if ( phylogenies_0.length != 4 ) {
1414                 return false;
1415             }
1416             final Phylogeny t1 = phylogenies_0[ 0 ];
1417             final Phylogeny t2 = phylogenies_0[ 1 ];
1418             final Phylogeny t3 = phylogenies_0[ 2 ];
1419             final Phylogeny t4 = phylogenies_0[ 3 ];
1420             if ( t1.getNumberOfExternalNodes() != 1 ) {
1421                 return false;
1422             }
1423             if ( !t1.isRooted() ) {
1424                 return false;
1425             }
1426             if ( t1.isRerootable() ) {
1427                 return false;
1428             }
1429             if ( !t1.getType().equals( "gene_tree" ) ) {
1430                 return false;
1431             }
1432             if ( t2.getNumberOfExternalNodes() != 2 ) {
1433                 return false;
1434             }
1435             if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1436                 return false;
1437             }
1438             if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1439                 return false;
1440             }
1441             if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1442                 return false;
1443             }
1444             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1445                 return false;
1446             }
1447             if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1448                 return false;
1449             }
1450             if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1451                 return false;
1452             }
1453             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1454                     .startsWith( "actgtgggggt" ) ) {
1455                 return false;
1456             }
1457             if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1458                     .startsWith( "ctgtgatgcat" ) ) {
1459                 return false;
1460             }
1461             if ( t3.getNumberOfExternalNodes() != 4 ) {
1462                 return false;
1463             }
1464             if ( !t1.getName().equals( "t1" ) ) {
1465                 return false;
1466             }
1467             if ( !t2.getName().equals( "t2" ) ) {
1468                 return false;
1469             }
1470             if ( !t3.getName().equals( "t3" ) ) {
1471                 return false;
1472             }
1473             if ( !t4.getName().equals( "t4" ) ) {
1474                 return false;
1475             }
1476             if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1477                 return false;
1478             }
1479             if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1480                 return false;
1481             }
1482             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1483                 return false;
1484             }
1485             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1486                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1487                 return false;
1488             }
1489             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1490                 return false;
1491             }
1492             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1493                 return false;
1494             }
1495             if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1496                 return false;
1497             }
1498             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1499                     .equals( "apoptosis" ) ) {
1500                 return false;
1501             }
1502             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1503                     .equals( "GO:0006915" ) ) {
1504                 return false;
1505             }
1506             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1507                     .equals( "UniProtKB" ) ) {
1508                 return false;
1509             }
1510             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1511                     .equals( "experimental" ) ) {
1512                 return false;
1513             }
1514             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1515                     .equals( "function" ) ) {
1516                 return false;
1517             }
1518             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1519                     .getValue() != 1 ) {
1520                 return false;
1521             }
1522             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1523                     .getType().equals( "ml" ) ) {
1524                 return false;
1525             }
1526             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1527                     .equals( "apoptosis" ) ) {
1528                 return false;
1529             }
1530             if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1531                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1532                 return false;
1533             }
1534             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1535                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1536                 return false;
1537             }
1538             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1539                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1540                 return false;
1541             }
1542             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1543                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1544                 return false;
1545             }
1546             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1547                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1548                 return false;
1549             }
1550             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1551                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1552                 return false;
1553             }
1554             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1555                     .equals( "GO:0005829" ) ) {
1556                 return false;
1557             }
1558             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1559                     .equals( "intracellular organelle" ) ) {
1560                 return false;
1561             }
1562             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1563                 return false;
1564             }
1565             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1566                     .equals( "UniProt link" ) ) ) {
1567                 return false;
1568             }
1569             if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1570                 return false;
1571             }
1572             final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1573             if ( x.size() != 4 ) {
1574                 return false;
1575             }
1576             int c = 0;
1577             for( final Accession acc : x ) {
1578                 if ( c == 0 ) {
1579                     if ( !acc.getSource().equals( "KEGG" ) ) {
1580                         return false;
1581                     }
1582                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1583                         return false;
1584                     }
1585                 }
1586                 c++;
1587             }
1588         }
1589         catch ( final Exception e ) {
1590             e.printStackTrace( System.out );
1591             return false;
1592         }
1593         return true;
1594     }
1595
1596     private static boolean testBasicPhyloXMLparsingRoundtrip() {
1597         try {
1598             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1599             final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1600             if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1601                 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1602             }
1603             else {
1604                 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1605             }
1606             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1607                                                               xml_parser );
1608             if ( xml_parser.getErrorCount() > 0 ) {
1609                 System.out.println( xml_parser.getErrorMessages().toString() );
1610                 return false;
1611             }
1612             if ( phylogenies_0.length != 4 ) {
1613                 return false;
1614             }
1615             final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1616             final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1617             if ( phylogenies_t1.length != 1 ) {
1618                 return false;
1619             }
1620             final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1621             if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1622                 return false;
1623             }
1624             if ( !t1_rt.isRooted() ) {
1625                 return false;
1626             }
1627             if ( t1_rt.isRerootable() ) {
1628                 return false;
1629             }
1630             if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1631                 return false;
1632             }
1633             final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1634             final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1635             final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1636             if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1637                 return false;
1638             }
1639             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1640                 return false;
1641             }
1642             if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1643                 return false;
1644             }
1645             if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1646                 return false;
1647             }
1648             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1649                     .startsWith( "actgtgggggt" ) ) {
1650                 return false;
1651             }
1652             if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1653                     .startsWith( "ctgtgatgcat" ) ) {
1654                 return false;
1655             }
1656             final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1657             final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1658             final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1659             final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1660             if ( phylogenies_1.length != 1 ) {
1661                 return false;
1662             }
1663             final Phylogeny t3_rt = phylogenies_1[ 0 ];
1664             if ( !t3_rt.getName().equals( "t3" ) ) {
1665                 return false;
1666             }
1667             if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1668                 return false;
1669             }
1670             if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1671                 return false;
1672             }
1673             if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1674                 return false;
1675             }
1676             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1677                 return false;
1678             }
1679             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1680                     .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1681                 return false;
1682             }
1683             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1684                 return false;
1685             }
1686             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1687                 return false;
1688             }
1689             if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1690                     .equals( "UniProtKB" ) ) {
1691                 return false;
1692             }
1693             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1694                     .equals( "apoptosis" ) ) {
1695                 return false;
1696             }
1697             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1698                     .equals( "GO:0006915" ) ) {
1699                 return false;
1700             }
1701             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1702                     .equals( "UniProtKB" ) ) {
1703                 return false;
1704             }
1705             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1706                     .equals( "experimental" ) ) {
1707                 return false;
1708             }
1709             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1710                     .equals( "function" ) ) {
1711                 return false;
1712             }
1713             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1714                     .getValue() != 1 ) {
1715                 return false;
1716             }
1717             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1718                     .getType().equals( "ml" ) ) {
1719                 return false;
1720             }
1721             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1722                     .equals( "apoptosis" ) ) {
1723                 return false;
1724             }
1725             if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1726                     .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1727                 return false;
1728             }
1729             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1730                     .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1731                 return false;
1732             }
1733             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1734                     .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1735                 return false;
1736             }
1737             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1738                     .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1739                 return false;
1740             }
1741             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1742                     .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1743                 return false;
1744             }
1745             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1746                     .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1747                 return false;
1748             }
1749             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1750                     .equals( "GO:0005829" ) ) {
1751                 return false;
1752             }
1753             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1754                     .equals( "intracellular organelle" ) ) {
1755                 return false;
1756             }
1757             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1758                 return false;
1759             }
1760             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1761                     .equals( "UniProt link" ) ) ) {
1762                 return false;
1763             }
1764             if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1765                 return false;
1766             }
1767             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1768                 return false;
1769             }
1770             if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1771                     .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." ) ) ) {
1772                 return false;
1773             }
1774             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1775                 return false;
1776             }
1777             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1778                 return false;
1779             }
1780             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1781                 return false;
1782             }
1783             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1784                 return false;
1785             }
1786             if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1787                     .equals( "ncbi" ) ) {
1788                 return false;
1789             }
1790             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1791                 return false;
1792             }
1793             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1794                     .getName().equals( "B" ) ) {
1795                 return false;
1796             }
1797             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1798                     .getFrom() != 21 ) {
1799                 return false;
1800             }
1801             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1802                 return false;
1803             }
1804             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1805                     .getLength() != 24 ) {
1806                 return false;
1807             }
1808             if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1809                     .getConfidence() != 2144 ) {
1810                 return false;
1811             }
1812             if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1813                     .equals( "pfam" ) ) {
1814                 return false;
1815             }
1816             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1817                 return false;
1818             }
1819             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1820                 return false;
1821             }
1822             if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1823                 return false;
1824             }
1825             if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1826                 return false;
1827             }
1828             final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1829             if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1830                 return false;
1831             }
1832             if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1833                 return false;
1834             }
1835             if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1836                 return false;
1837             }
1838             if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1839                 return false;
1840             }
1841             if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1842                 return false;
1843             }
1844             if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1845                 return false;
1846             }
1847             if ( taxbb.getSynonyms().size() != 2 ) {
1848                 return false;
1849             }
1850             if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1851                 return false;
1852             }
1853             if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1854                 return false;
1855             }
1856             if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1857                 return false;
1858             }
1859             if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1860                 return false;
1861             }
1862             if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1863                 return false;
1864             }
1865             if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1866                     .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1867                 return false;
1868             }
1869             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1870                 return false;
1871             }
1872             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1873                 return false;
1874             }
1875             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1876                 return false;
1877             }
1878             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1879                 return false;
1880             }
1881             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1882                 return false;
1883             }
1884             if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1885                 return false;
1886             }
1887             if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1888                 return false;
1889             }
1890             //
1891             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1892                 return false;
1893             }
1894             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1895                     .equalsIgnoreCase( "435" ) ) {
1896                 return false;
1897             }
1898             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1899                 return false;
1900             }
1901             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1902                     .equalsIgnoreCase( "443.7" ) ) {
1903                 return false;
1904             }
1905             if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1906                 return false;
1907             }
1908             if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1909                 return false;
1910             }
1911             if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1912                     .equalsIgnoreCase( "433" ) ) {
1913                 return false;
1914             }
1915             final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
1916                     .getCrossReferences();
1917             if ( x.size() != 4 ) {
1918                 return false;
1919             }
1920             int c = 0;
1921             for( final Accession acc : x ) {
1922                 if ( c == 0 ) {
1923                     if ( !acc.getSource().equals( "KEGG" ) ) {
1924                         return false;
1925                     }
1926                     if ( !acc.getValue().equals( "hsa:596" ) ) {
1927                         return false;
1928                     }
1929                 }
1930                 c++;
1931             }
1932         }
1933         catch ( final Exception e ) {
1934             e.printStackTrace( System.out );
1935             return false;
1936         }
1937         return true;
1938     }
1939
1940     private static boolean testBasicPhyloXMLparsingValidating() {
1941         try {
1942             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1943             PhyloXmlParser xml_parser = null;
1944             try {
1945                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1946             }
1947             catch ( final Exception e ) {
1948                 // Do nothing -- means were not running from jar.
1949             }
1950             if ( xml_parser == null ) {
1951                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
1952                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1953                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1954                 }
1955                 else {
1956                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1957                 }
1958             }
1959             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1960                                                               xml_parser );
1961             if ( xml_parser.getErrorCount() > 0 ) {
1962                 System.out.println( xml_parser.getErrorMessages().toString() );
1963                 return false;
1964             }
1965             if ( phylogenies_0.length != 4 ) {
1966                 return false;
1967             }
1968             final Phylogeny t1 = phylogenies_0[ 0 ];
1969             final Phylogeny t2 = phylogenies_0[ 1 ];
1970             final Phylogeny t3 = phylogenies_0[ 2 ];
1971             final Phylogeny t4 = phylogenies_0[ 3 ];
1972             if ( !t1.getName().equals( "t1" ) ) {
1973                 return false;
1974             }
1975             if ( !t2.getName().equals( "t2" ) ) {
1976                 return false;
1977             }
1978             if ( !t3.getName().equals( "t3" ) ) {
1979                 return false;
1980             }
1981             if ( !t4.getName().equals( "t4" ) ) {
1982                 return false;
1983             }
1984             if ( t1.getNumberOfExternalNodes() != 1 ) {
1985                 return false;
1986             }
1987             if ( t2.getNumberOfExternalNodes() != 2 ) {
1988                 return false;
1989             }
1990             if ( t3.getNumberOfExternalNodes() != 4 ) {
1991                 return false;
1992             }
1993             final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
1994             final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
1995             if ( xml_parser.getErrorCount() > 0 ) {
1996                 System.out.println( "errors:" );
1997                 System.out.println( xml_parser.getErrorMessages().toString() );
1998                 return false;
1999             }
2000             if ( phylogenies_1.length != 4 ) {
2001                 return false;
2002             }
2003             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
2004                                                               xml_parser );
2005             if ( xml_parser.getErrorCount() > 0 ) {
2006                 System.out.println( "errors:" );
2007                 System.out.println( xml_parser.getErrorMessages().toString() );
2008                 return false;
2009             }
2010             if ( phylogenies_2.length != 1 ) {
2011                 return false;
2012             }
2013             if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2014                 return false;
2015             }
2016             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
2017                                                               xml_parser );
2018             if ( xml_parser.getErrorCount() > 0 ) {
2019                 System.out.println( xml_parser.getErrorMessages().toString() );
2020                 return false;
2021             }
2022             if ( phylogenies_3.length != 2 ) {
2023                 return false;
2024             }
2025             final Phylogeny a = phylogenies_3[ 0 ];
2026             if ( !a.getName().equals( "tree 4" ) ) {
2027                 return false;
2028             }
2029             if ( a.getNumberOfExternalNodes() != 3 ) {
2030                 return false;
2031             }
2032             if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2033                 return false;
2034             }
2035             if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2036                 return false;
2037             }
2038             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
2039                                                               xml_parser );
2040             if ( xml_parser.getErrorCount() > 0 ) {
2041                 System.out.println( xml_parser.getErrorMessages().toString() );
2042                 return false;
2043             }
2044             if ( phylogenies_4.length != 1 ) {
2045                 return false;
2046             }
2047             final Phylogeny s = phylogenies_4[ 0 ];
2048             if ( s.getNumberOfExternalNodes() != 6 ) {
2049                 return false;
2050             }
2051             s.getNode( "first" );
2052             s.getNode( "<>" );
2053             s.getNode( "\"<a'b&c'd\">\"" );
2054             s.getNode( "'''\"" );
2055             s.getNode( "\"\"\"" );
2056             s.getNode( "dick & doof" );
2057         }
2058         catch ( final Exception e ) {
2059             e.printStackTrace( System.out );
2060             return false;
2061         }
2062         return true;
2063     }
2064
2065     private static boolean testBasicProtein() {
2066         try {
2067             final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2068             final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2069             final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2070             final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2071             final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2072             final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2073             final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2074             final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2075             p0.addProteinDomain( y );
2076             p0.addProteinDomain( e );
2077             p0.addProteinDomain( b );
2078             p0.addProteinDomain( c );
2079             p0.addProteinDomain( d );
2080             p0.addProteinDomain( a );
2081             p0.addProteinDomain( x );
2082             if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2083                 return false;
2084             }
2085             if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2086                 return false;
2087             }
2088             //
2089             final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2090             final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2091             aa0.addProteinDomain( a1 );
2092             if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2093                 return false;
2094             }
2095             if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2096                 return false;
2097             }
2098             //
2099             final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2100             final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2101             final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2102             aa1.addProteinDomain( a11 );
2103             aa1.addProteinDomain( a12 );
2104             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2105                 return false;
2106             }
2107             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2108                 return false;
2109             }
2110             aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2111             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2112                 return false;
2113             }
2114             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2115                 return false;
2116             }
2117             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2118                 return false;
2119             }
2120             aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2121             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2122                 return false;
2123             }
2124             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2125                 return false;
2126             }
2127             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2128                 return false;
2129             }
2130             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2131                 return false;
2132             }
2133             aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2134             if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2135                 return false;
2136             }
2137             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2138                 return false;
2139             }
2140             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2141                 return false;
2142             }
2143             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2144                 return false;
2145             }
2146             aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2147             if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2148                 return false;
2149             }
2150             if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2151                 return false;
2152             }
2153             if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2154                 return false;
2155             }
2156             if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2157                 return false;
2158             }
2159             //
2160             final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2161             final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2162             final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2163             final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2164             final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2165             final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2166             final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2167             final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2168             final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2169             final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2170             final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2171             final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2172             final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2173             final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2174             final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2175             final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2176             final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2177             final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2178             final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2179             final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2180             final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2181             p00.addProteinDomain( y0 );
2182             p00.addProteinDomain( e0 );
2183             p00.addProteinDomain( b0 );
2184             p00.addProteinDomain( c0 );
2185             p00.addProteinDomain( d0 );
2186             p00.addProteinDomain( a0 );
2187             p00.addProteinDomain( x0 );
2188             p00.addProteinDomain( y1 );
2189             p00.addProteinDomain( y2 );
2190             p00.addProteinDomain( y3 );
2191             p00.addProteinDomain( e1 );
2192             p00.addProteinDomain( e2 );
2193             p00.addProteinDomain( e3 );
2194             p00.addProteinDomain( e4 );
2195             p00.addProteinDomain( e5 );
2196             p00.addProteinDomain( z0 );
2197             p00.addProteinDomain( z1 );
2198             p00.addProteinDomain( z2 );
2199             p00.addProteinDomain( zz0 );
2200             p00.addProteinDomain( zz1 );
2201             if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2202                 return false;
2203             }
2204             if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2205                 return false;
2206             }
2207             if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2208                 return false;
2209             }
2210             if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2211                 return false;
2212             }
2213             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" ) ) {
2214                 return false;
2215             }
2216             // A0  A10  B15  A20  B25  A30  B35  B40  C50  A60  C70  D80
2217             final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2218             final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2219             final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2220             final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2221             final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2222             final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2223             final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2224             final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2225             final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2226             final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2227             final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2228             final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2229             final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2230             p.addProteinDomain( B15 );
2231             p.addProteinDomain( C50 );
2232             p.addProteinDomain( A60 );
2233             p.addProteinDomain( A30 );
2234             p.addProteinDomain( C70 );
2235             p.addProteinDomain( B35 );
2236             p.addProteinDomain( B40 );
2237             p.addProteinDomain( A0 );
2238             p.addProteinDomain( A10 );
2239             p.addProteinDomain( A20 );
2240             p.addProteinDomain( B25 );
2241             p.addProteinDomain( D80 );
2242             List<String> domains_ids = new ArrayList<String>();
2243             domains_ids.add( "A" );
2244             domains_ids.add( "B" );
2245             domains_ids.add( "C" );
2246             if ( !p.contains( domains_ids, false ) ) {
2247                 return false;
2248             }
2249             if ( !p.contains( domains_ids, true ) ) {
2250                 return false;
2251             }
2252             domains_ids.add( "X" );
2253             if ( p.contains( domains_ids, false ) ) {
2254                 return false;
2255             }
2256             if ( p.contains( domains_ids, true ) ) {
2257                 return false;
2258             }
2259             domains_ids = new ArrayList<String>();
2260             domains_ids.add( "A" );
2261             domains_ids.add( "C" );
2262             domains_ids.add( "D" );
2263             if ( !p.contains( domains_ids, false ) ) {
2264                 return false;
2265             }
2266             if ( !p.contains( domains_ids, true ) ) {
2267                 return false;
2268             }
2269             domains_ids = new ArrayList<String>();
2270             domains_ids.add( "A" );
2271             domains_ids.add( "D" );
2272             domains_ids.add( "C" );
2273             if ( !p.contains( domains_ids, false ) ) {
2274                 return false;
2275             }
2276             if ( p.contains( domains_ids, true ) ) {
2277                 return false;
2278             }
2279             domains_ids = new ArrayList<String>();
2280             domains_ids.add( "A" );
2281             domains_ids.add( "A" );
2282             domains_ids.add( "B" );
2283             if ( !p.contains( domains_ids, false ) ) {
2284                 return false;
2285             }
2286             if ( !p.contains( domains_ids, true ) ) {
2287                 return false;
2288             }
2289             domains_ids = new ArrayList<String>();
2290             domains_ids.add( "A" );
2291             domains_ids.add( "A" );
2292             domains_ids.add( "A" );
2293             domains_ids.add( "B" );
2294             domains_ids.add( "B" );
2295             if ( !p.contains( domains_ids, false ) ) {
2296                 return false;
2297             }
2298             if ( !p.contains( domains_ids, true ) ) {
2299                 return false;
2300             }
2301             domains_ids = new ArrayList<String>();
2302             domains_ids.add( "A" );
2303             domains_ids.add( "A" );
2304             domains_ids.add( "B" );
2305             domains_ids.add( "A" );
2306             domains_ids.add( "B" );
2307             domains_ids.add( "B" );
2308             domains_ids.add( "A" );
2309             domains_ids.add( "B" );
2310             domains_ids.add( "C" );
2311             domains_ids.add( "A" );
2312             domains_ids.add( "C" );
2313             domains_ids.add( "D" );
2314             if ( !p.contains( domains_ids, false ) ) {
2315                 return false;
2316             }
2317             if ( p.contains( domains_ids, true ) ) {
2318                 return false;
2319             }
2320         }
2321         catch ( final Exception e ) {
2322             e.printStackTrace( System.out );
2323             return false;
2324         }
2325         return true;
2326     }
2327
2328     private static boolean testBasicTable() {
2329         try {
2330             final BasicTable<String> t0 = new BasicTable<String>();
2331             if ( t0.getNumberOfColumns() != 0 ) {
2332                 return false;
2333             }
2334             if ( t0.getNumberOfRows() != 0 ) {
2335                 return false;
2336             }
2337             t0.setValue( 3, 2, "23" );
2338             t0.setValue( 10, 1, "error" );
2339             t0.setValue( 10, 1, "110" );
2340             t0.setValue( 9, 1, "19" );
2341             t0.setValue( 1, 10, "101" );
2342             t0.setValue( 10, 10, "1010" );
2343             t0.setValue( 100, 10, "10100" );
2344             t0.setValue( 0, 0, "00" );
2345             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2346                 return false;
2347             }
2348             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2349                 return false;
2350             }
2351             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2352                 return false;
2353             }
2354             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2355                 return false;
2356             }
2357             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2358                 return false;
2359             }
2360             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2361                 return false;
2362             }
2363             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2364                 return false;
2365             }
2366             if ( t0.getNumberOfColumns() != 101 ) {
2367                 return false;
2368             }
2369             if ( t0.getNumberOfRows() != 11 ) {
2370                 return false;
2371             }
2372             if ( t0.getValueAsString( 49, 4 ) != null ) {
2373                 return false;
2374             }
2375             final String l = ForesterUtil.getLineSeparator();
2376             final StringBuffer source = new StringBuffer();
2377             source.append( "" + l );
2378             source.append( "# 1 1 1 1 1 1 1 1" + l );
2379             source.append( " 00 01 02 03" + l );
2380             source.append( "   10 11 12 13  " + l );
2381             source.append( "20 21 22 23 " + l );
2382             source.append( "    30  31    32 33" + l );
2383             source.append( "40 41 42 43" + l );
2384             source.append( "  # 1 1 1 1 1 " + l );
2385             source.append( "50 51 52 53 54" + l );
2386             final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2387             if ( t1.getNumberOfColumns() != 5 ) {
2388                 return false;
2389             }
2390             if ( t1.getNumberOfRows() != 6 ) {
2391                 return false;
2392             }
2393             if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2394                 return false;
2395             }
2396             if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2397                 return false;
2398             }
2399             if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2400                 return false;
2401             }
2402             if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2403                 return false;
2404             }
2405             final StringBuffer source1 = new StringBuffer();
2406             source1.append( "" + l );
2407             source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2408             source1.append( " 00; 01 ;02;03" + l );
2409             source1.append( "   10; 11; 12; 13  " + l );
2410             source1.append( "20; 21; 22; 23 " + l );
2411             source1.append( "    30;  31;    32; 33" + l );
2412             source1.append( "40;41;42;43" + l );
2413             source1.append( "  # 1 1 1 1 1 " + l );
2414             source1.append( ";;;50  ;  ;52; 53;;54   " + l );
2415             final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2416             if ( t2.getNumberOfColumns() != 5 ) {
2417                 return false;
2418             }
2419             if ( t2.getNumberOfRows() != 6 ) {
2420                 return false;
2421             }
2422             if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2423                 return false;
2424             }
2425             if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2426                 return false;
2427             }
2428             if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2429                 return false;
2430             }
2431             if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2432                 return false;
2433             }
2434             if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2435                 return false;
2436             }
2437             if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2438                 return false;
2439             }
2440             final StringBuffer source2 = new StringBuffer();
2441             source2.append( "" + l );
2442             source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2443             source2.append( " 00; 01 ;02;03" + l );
2444             source2.append( "   10; 11; 12; 13  " + l );
2445             source2.append( "20; 21; 22; 23 " + l );
2446             source2.append( "                     " + l );
2447             source2.append( "    30;  31;    32; 33" + l );
2448             source2.append( "40;41;42;43" + l );
2449             source2.append( "  comment: 1 1 1 1 1 " + l );
2450             source2.append( ";;;50  ;   52; 53;;54   " + l );
2451             final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2452                                                                         ';',
2453                                                                         false,
2454                                                                         false,
2455                                                                         "comment:",
2456                                                                         false );
2457             if ( tl.size() != 2 ) {
2458                 return false;
2459             }
2460             final BasicTable<String> t3 = tl.get( 0 );
2461             final BasicTable<String> t4 = tl.get( 1 );
2462             if ( t3.getNumberOfColumns() != 4 ) {
2463                 return false;
2464             }
2465             if ( t3.getNumberOfRows() != 3 ) {
2466                 return false;
2467             }
2468             if ( t4.getNumberOfColumns() != 4 ) {
2469                 return false;
2470             }
2471             if ( t4.getNumberOfRows() != 3 ) {
2472                 return false;
2473             }
2474             if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2475                 return false;
2476             }
2477             if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2478                 return false;
2479             }
2480         }
2481         catch ( final Exception e ) {
2482             e.printStackTrace( System.out );
2483             return false;
2484         }
2485         return true;
2486     }
2487
2488     private static boolean testBasicTolXMLparsing() {
2489         try {
2490             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2491             final TolParser parser = new TolParser();
2492             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2493             if ( parser.getErrorCount() > 0 ) {
2494                 System.out.println( parser.getErrorMessages().toString() );
2495                 return false;
2496             }
2497             if ( phylogenies_0.length != 1 ) {
2498                 return false;
2499             }
2500             final Phylogeny t1 = phylogenies_0[ 0 ];
2501             if ( t1.getNumberOfExternalNodes() != 5 ) {
2502                 return false;
2503             }
2504             if ( !t1.isRooted() ) {
2505                 return false;
2506             }
2507             if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2508                 return false;
2509             }
2510             if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2511                 return false;
2512             }
2513             if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2514                 return false;
2515             }
2516             if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2517                 return false;
2518             }
2519             final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2520             if ( parser.getErrorCount() > 0 ) {
2521                 System.out.println( parser.getErrorMessages().toString() );
2522                 return false;
2523             }
2524             if ( phylogenies_1.length != 1 ) {
2525                 return false;
2526             }
2527             final Phylogeny t2 = phylogenies_1[ 0 ];
2528             if ( t2.getNumberOfExternalNodes() != 664 ) {
2529                 return false;
2530             }
2531             if ( !t2.isRooted() ) {
2532                 return false;
2533             }
2534             if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2535                 return false;
2536             }
2537             if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2538                 return false;
2539             }
2540             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2541                 return false;
2542             }
2543             if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2544                 return false;
2545             }
2546             if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2547                 return false;
2548             }
2549             if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2550                     .equals( "Aquifex" ) ) {
2551                 return false;
2552             }
2553             final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2554             if ( parser.getErrorCount() > 0 ) {
2555                 System.out.println( parser.getErrorMessages().toString() );
2556                 return false;
2557             }
2558             if ( phylogenies_2.length != 1 ) {
2559                 return false;
2560             }
2561             final Phylogeny t3 = phylogenies_2[ 0 ];
2562             if ( t3.getNumberOfExternalNodes() != 184 ) {
2563                 return false;
2564             }
2565             if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2566                 return false;
2567             }
2568             if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2569                 return false;
2570             }
2571             if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2572                 return false;
2573             }
2574             final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2575             if ( parser.getErrorCount() > 0 ) {
2576                 System.out.println( parser.getErrorMessages().toString() );
2577                 return false;
2578             }
2579             if ( phylogenies_3.length != 1 ) {
2580                 return false;
2581             }
2582             final Phylogeny t4 = phylogenies_3[ 0 ];
2583             if ( t4.getNumberOfExternalNodes() != 1 ) {
2584                 return false;
2585             }
2586             if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2587                 return false;
2588             }
2589             if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2590                 return false;
2591             }
2592             if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2593                 return false;
2594             }
2595             final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2596             if ( parser.getErrorCount() > 0 ) {
2597                 System.out.println( parser.getErrorMessages().toString() );
2598                 return false;
2599             }
2600             if ( phylogenies_4.length != 1 ) {
2601                 return false;
2602             }
2603             final Phylogeny t5 = phylogenies_4[ 0 ];
2604             if ( t5.getNumberOfExternalNodes() != 13 ) {
2605                 return false;
2606             }
2607             if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2608                 return false;
2609             }
2610             if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2611                 return false;
2612             }
2613             if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2614                 return false;
2615             }
2616         }
2617         catch ( final Exception e ) {
2618             e.printStackTrace( System.out );
2619             return false;
2620         }
2621         return true;
2622     }
2623
2624     private static boolean testBasicTreeMethods() {
2625         try {
2626             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2627             final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2628             if ( t2.getNumberOfExternalNodes() != 4 ) {
2629                 return false;
2630             }
2631             if ( t2.getHeight() != 8.5 ) {
2632                 return false;
2633             }
2634             if ( !t2.isCompletelyBinary() ) {
2635                 return false;
2636             }
2637             if ( t2.isEmpty() ) {
2638                 return false;
2639             }
2640             final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2641             if ( t3.getNumberOfExternalNodes() != 5 ) {
2642                 return false;
2643             }
2644             if ( t3.getHeight() != 11 ) {
2645                 return false;
2646             }
2647             if ( t3.isCompletelyBinary() ) {
2648                 return false;
2649             }
2650             final PhylogenyNode n = t3.getNode( "ABC" );
2651             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 ];
2652             if ( t4.getNumberOfExternalNodes() != 9 ) {
2653                 return false;
2654             }
2655             if ( t4.getHeight() != 11 ) {
2656                 return false;
2657             }
2658             if ( t4.isCompletelyBinary() ) {
2659                 return false;
2660             }
2661             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)" );
2662             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2663             if ( t5.getNumberOfExternalNodes() != 8 ) {
2664                 return false;
2665             }
2666             if ( t5.getHeight() != 15 ) {
2667                 return false;
2668             }
2669             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)" );
2670             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2671             if ( t6.getHeight() != 15 ) {
2672                 return false;
2673             }
2674             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)" );
2675             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2676             if ( t7.getHeight() != 15 ) {
2677                 return false;
2678             }
2679             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)" );
2680             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2681             if ( t8.getNumberOfExternalNodes() != 10 ) {
2682                 return false;
2683             }
2684             if ( t8.getHeight() != 15 ) {
2685                 return false;
2686             }
2687             final char[] a9 = new char[] { 'a' };
2688             final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2689             if ( t9.getHeight() != 0 ) {
2690                 return false;
2691             }
2692             final char[] a10 = new char[] { 'a', ':', '6' };
2693             final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2694             if ( t10.getHeight() != 6 ) {
2695                 return false;
2696             }
2697         }
2698         catch ( final Exception e ) {
2699             e.printStackTrace( System.out );
2700             return false;
2701         }
2702         return true;
2703     }
2704
2705     private static boolean testConfidenceAssessor() {
2706         try {
2707             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2708             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2709             final Phylogeny[] ev0 = factory
2710                     .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2711                              new NHXParser() );
2712             ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2713             if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2714                 return false;
2715             }
2716             if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2717                 return false;
2718             }
2719             final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2720             final Phylogeny[] ev1 = factory
2721                     .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)));",
2722                              new NHXParser() );
2723             ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2724             if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2725                 return false;
2726             }
2727             if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2728                 return false;
2729             }
2730             final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2731             final Phylogeny[] ev_b = factory
2732                     .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",
2733                              new NHXParser() );
2734             ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2735             if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2736                 return false;
2737             }
2738             if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2739                 return false;
2740             }
2741             //
2742             final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2743             final Phylogeny[] ev1x = factory
2744                     .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)));",
2745                              new NHXParser() );
2746             ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2747             if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2748                 return false;
2749             }
2750             if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2751                 return false;
2752             }
2753             final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2754             final Phylogeny[] ev_bx = factory
2755                     .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",
2756                              new NHXParser() );
2757             ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2758             if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2759                 return false;
2760             }
2761             if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2762                 return false;
2763             }
2764             //
2765             final Phylogeny[] t2 = factory
2766                     .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);",
2767                              new NHXParser() );
2768             final Phylogeny[] ev2 = factory
2769                     .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);",
2770                              new NHXParser() );
2771             for( final Phylogeny target : t2 ) {
2772                 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2773             }
2774             //
2775             final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2776                                                  new NHXParser() )[ 0 ];
2777             final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2778             ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2779             if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2780                 return false;
2781             }
2782             if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2783                 return false;
2784             }
2785             if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2786                 return false;
2787             }
2788         }
2789         catch ( final Exception e ) {
2790             e.printStackTrace();
2791             return false;
2792         }
2793         return true;
2794     }
2795
2796     private static boolean testCopyOfNodeData() {
2797         try {
2798             final PhylogenyNode n1 = PhylogenyNode
2799                     .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]" );
2800             final PhylogenyNode n2 = n1.copyNodeData();
2801             if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2802                 return false;
2803             }
2804         }
2805         catch ( final Exception e ) {
2806             e.printStackTrace();
2807             return false;
2808         }
2809         return true;
2810     }
2811
2812     private static boolean testTreeCopy() {
2813         try {
2814             final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
2815             final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
2816             final Phylogeny t1 = t0.copy();
2817             if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
2818                 return false;
2819             }
2820             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
2821                 return false;
2822             }
2823             t0.deleteSubtree( t0.getNode( "c" ), true );
2824             t0.deleteSubtree( t0.getNode( "a" ), true );
2825             t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
2826             t0.getNode( "b" ).setName( "Bee" );
2827             if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
2828                 return false;
2829             }
2830             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
2831                 return false;
2832             }
2833             t0.deleteSubtree( t0.getNode( "e" ), true );
2834             t0.deleteSubtree( t0.getNode( "Bee" ), true );
2835             t0.deleteSubtree( t0.getNode( "d" ), true );
2836             if ( !t1.toNewHampshireX().equals( str_0 ) ) {
2837                 return false;
2838             }
2839         }
2840         catch ( final Exception e ) {
2841             e.printStackTrace();
2842             return false;
2843         }
2844         return true;
2845     }
2846
2847     private static boolean testCreateBalancedPhylogeny() {
2848         try {
2849             final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
2850             if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
2851                 return false;
2852             }
2853             if ( p0.getNumberOfExternalNodes() != 15625 ) {
2854                 return false;
2855             }
2856             final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
2857             if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
2858                 return false;
2859             }
2860             if ( p1.getNumberOfExternalNodes() != 100 ) {
2861                 return false;
2862             }
2863         }
2864         catch ( final Exception e ) {
2865             e.printStackTrace();
2866             return false;
2867         }
2868         return true;
2869     }
2870
2871     private static boolean testCreateUriForSeqWeb() {
2872         try {
2873             final PhylogenyNode n = new PhylogenyNode();
2874             n.setName( "tr|B3RJ64" );
2875             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
2876                 return false;
2877             }
2878             n.setName( "B0LM41_HUMAN" );
2879             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
2880                 return false;
2881             }
2882             n.setName( "NP_001025424" );
2883             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
2884                 return false;
2885             }
2886             n.setName( "_NM_001030253-" );
2887             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
2888                 return false;
2889             }
2890             n.setName( "XM_002122186" );
2891             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
2892                 return false;
2893             }
2894             n.setName( "dgh_AAA34956_gdg" );
2895             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
2896                 return false;
2897             }
2898             n.setName( "AAA34956" );
2899             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
2900                 return false;
2901             }
2902             n.setName( "GI:394892" );
2903             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2904                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2905                 return false;
2906             }
2907             n.setName( "gi_394892" );
2908             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2909                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2910                 return false;
2911             }
2912             n.setName( "gi6335_gi_394892_56635_Gi_43" );
2913             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2914                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2915                 return false;
2916             }
2917             n.setName( "P12345" );
2918             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
2919                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2920                 return false;
2921             }
2922             n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
2923             if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
2924                 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
2925                 return false;
2926             }
2927         }
2928         catch ( final Exception e ) {
2929             e.printStackTrace( System.out );
2930             return false;
2931         }
2932         return true;
2933     }
2934
2935     private static boolean testDataObjects() {
2936         try {
2937             final Confidence s0 = new Confidence();
2938             final Confidence s1 = new Confidence();
2939             if ( !s0.isEqual( s1 ) ) {
2940                 return false;
2941             }
2942             final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2943             final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2944             if ( s2.isEqual( s1 ) ) {
2945                 return false;
2946             }
2947             if ( !s2.isEqual( s3 ) ) {
2948                 return false;
2949             }
2950             final Confidence s4 = ( Confidence ) s3.copy();
2951             if ( !s4.isEqual( s3 ) ) {
2952                 return false;
2953             }
2954             s3.asSimpleText();
2955             s3.asText();
2956             // Taxonomy
2957             // ----------
2958             final Taxonomy t1 = new Taxonomy();
2959             final Taxonomy t2 = new Taxonomy();
2960             final Taxonomy t3 = new Taxonomy();
2961             final Taxonomy t4 = new Taxonomy();
2962             final Taxonomy t5 = new Taxonomy();
2963             t1.setIdentifier( new Identifier( "ecoli" ) );
2964             t1.setTaxonomyCode( "ECOLI" );
2965             t1.setScientificName( "E. coli" );
2966             t1.setCommonName( "coli" );
2967             final Taxonomy t0 = ( Taxonomy ) t1.copy();
2968             if ( !t1.isEqual( t0 ) ) {
2969                 return false;
2970             }
2971             t2.setIdentifier( new Identifier( "ecoli" ) );
2972             t2.setTaxonomyCode( "OTHER" );
2973             t2.setScientificName( "what" );
2974             t2.setCommonName( "something" );
2975             if ( !t1.isEqual( t2 ) ) {
2976                 return false;
2977             }
2978             t2.setIdentifier( new Identifier( "nemve" ) );
2979             if ( t1.isEqual( t2 ) ) {
2980                 return false;
2981             }
2982             t1.setIdentifier( null );
2983             t3.setTaxonomyCode( "ECOLI" );
2984             t3.setScientificName( "what" );
2985             t3.setCommonName( "something" );
2986             if ( !t1.isEqual( t3 ) ) {
2987                 return false;
2988             }
2989             t1.setIdentifier( null );
2990             t1.setTaxonomyCode( "" );
2991             t4.setScientificName( "E. ColI" );
2992             t4.setCommonName( "something" );
2993             if ( !t1.isEqual( t4 ) ) {
2994                 return false;
2995             }
2996             t4.setScientificName( "B. subtilis" );
2997             t4.setCommonName( "something" );
2998             if ( t1.isEqual( t4 ) ) {
2999                 return false;
3000             }
3001             t1.setIdentifier( null );
3002             t1.setTaxonomyCode( "" );
3003             t1.setScientificName( "" );
3004             t5.setCommonName( "COLI" );
3005             if ( !t1.isEqual( t5 ) ) {
3006                 return false;
3007             }
3008             t5.setCommonName( "vibrio" );
3009             if ( t1.isEqual( t5 ) ) {
3010                 return false;
3011             }
3012             // Identifier
3013             // ----------
3014             final Identifier id0 = new Identifier( "123", "pfam" );
3015             final Identifier id1 = ( Identifier ) id0.copy();
3016             if ( !id1.isEqual( id1 ) ) {
3017                 return false;
3018             }
3019             if ( !id1.isEqual( id0 ) ) {
3020                 return false;
3021             }
3022             if ( !id0.isEqual( id1 ) ) {
3023                 return false;
3024             }
3025             id1.asSimpleText();
3026             id1.asText();
3027             // ProteinDomain
3028             // ---------------
3029             final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3030             final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3031             if ( !pd1.isEqual( pd1 ) ) {
3032                 return false;
3033             }
3034             if ( !pd1.isEqual( pd0 ) ) {
3035                 return false;
3036             }
3037             pd1.asSimpleText();
3038             pd1.asText();
3039             final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3040             final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3041             if ( !pd3.isEqual( pd3 ) ) {
3042                 return false;
3043             }
3044             if ( !pd2.isEqual( pd3 ) ) {
3045                 return false;
3046             }
3047             if ( !pd0.isEqual( pd3 ) ) {
3048                 return false;
3049             }
3050             pd3.asSimpleText();
3051             pd3.asText();
3052             // DomainArchitecture
3053             // ------------------
3054             final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3055             final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3056             final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3057             final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3058             final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3059             final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3060             domains0.add( d2 );
3061             domains0.add( d0 );
3062             domains0.add( d3 );
3063             domains0.add( d1 );
3064             final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3065             if ( ds0.getNumberOfDomains() != 4 ) {
3066                 return false;
3067             }
3068             final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3069             if ( !ds0.isEqual( ds0 ) ) {
3070                 return false;
3071             }
3072             if ( !ds0.isEqual( ds1 ) ) {
3073                 return false;
3074             }
3075             if ( ds1.getNumberOfDomains() != 4 ) {
3076                 return false;
3077             }
3078             final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3079             domains1.add( d1 );
3080             domains1.add( d2 );
3081             domains1.add( d4 );
3082             domains1.add( d0 );
3083             final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3084             if ( ds0.isEqual( ds2 ) ) {
3085                 return false;
3086             }
3087             ds1.asSimpleText();
3088             ds1.asText();
3089             ds1.toNHX();
3090             final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3091             if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3092                 System.out.println( ds3.toNHX() );
3093                 return false;
3094             }
3095             if ( ds3.getNumberOfDomains() != 3 ) {
3096                 return false;
3097             }
3098             // Event
3099             // -----
3100             final Event e1 = new Event( Event.EventType.fusion );
3101             if ( e1.isDuplication() ) {
3102                 return false;
3103             }
3104             if ( !e1.isFusion() ) {
3105                 return false;
3106             }
3107             if ( !e1.asText().toString().equals( "fusion" ) ) {
3108                 return false;
3109             }
3110             if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3111                 return false;
3112             }
3113             final Event e11 = new Event( Event.EventType.fusion );
3114             if ( !e11.isEqual( e1 ) ) {
3115                 return false;
3116             }
3117             if ( !e11.toNHX().toString().equals( "" ) ) {
3118                 return false;
3119             }
3120             final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3121             if ( e2.isDuplication() ) {
3122                 return false;
3123             }
3124             if ( !e2.isSpeciationOrDuplication() ) {
3125                 return false;
3126             }
3127             if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3128                 return false;
3129             }
3130             if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3131                 return false;
3132             }
3133             if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3134                 return false;
3135             }
3136             if ( e11.isEqual( e2 ) ) {
3137                 return false;
3138             }
3139             final Event e2c = ( Event ) e2.copy();
3140             if ( !e2c.isEqual( e2 ) ) {
3141                 return false;
3142             }
3143             Event e3 = new Event( 1, 2, 3 );
3144             if ( e3.isDuplication() ) {
3145                 return false;
3146             }
3147             if ( e3.isSpeciation() ) {
3148                 return false;
3149             }
3150             if ( e3.isGeneLoss() ) {
3151                 return false;
3152             }
3153             if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3154                 return false;
3155             }
3156             final Event e3c = ( Event ) e3.copy();
3157             final Event e3cc = ( Event ) e3c.copy();
3158             if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3159                 return false;
3160             }
3161             e3 = null;
3162             if ( !e3c.isEqual( e3cc ) ) {
3163                 return false;
3164             }
3165             Event e4 = new Event( 1, 2, 3 );
3166             if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3167                 return false;
3168             }
3169             if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3170                 return false;
3171             }
3172             final Event e4c = ( Event ) e4.copy();
3173             e4 = null;
3174             final Event e4cc = ( Event ) e4c.copy();
3175             if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3176                 return false;
3177             }
3178             if ( !e4c.isEqual( e4cc ) ) {
3179                 return false;
3180             }
3181             final Event e5 = new Event();
3182             if ( !e5.isUnassigned() ) {
3183                 return false;
3184             }
3185             if ( !e5.asText().toString().equals( "unassigned" ) ) {
3186                 return false;
3187             }
3188             if ( !e5.asSimpleText().toString().equals( "" ) ) {
3189                 return false;
3190             }
3191             final Event e6 = new Event( 1, 0, 0 );
3192             if ( !e6.asText().toString().equals( "duplication" ) ) {
3193                 return false;
3194             }
3195             if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3196                 return false;
3197             }
3198             final Event e7 = new Event( 0, 1, 0 );
3199             if ( !e7.asText().toString().equals( "speciation" ) ) {
3200                 return false;
3201             }
3202             if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3203                 return false;
3204             }
3205             final Event e8 = new Event( 0, 0, 1 );
3206             if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3207                 return false;
3208             }
3209             if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3210                 return false;
3211             }
3212         }
3213         catch ( final Exception e ) {
3214             e.printStackTrace( System.out );
3215             return false;
3216         }
3217         return true;
3218     }
3219
3220     private static boolean testDeletionOfExternalNodes() {
3221         try {
3222             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3223             final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3224             final PhylogenyWriter w = new PhylogenyWriter();
3225             if ( t0.isEmpty() ) {
3226                 return false;
3227             }
3228             if ( t0.getNumberOfExternalNodes() != 1 ) {
3229                 return false;
3230             }
3231             t0.deleteSubtree( t0.getNode( "A" ), false );
3232             if ( t0.getNumberOfExternalNodes() != 0 ) {
3233                 return false;
3234             }
3235             if ( !t0.isEmpty() ) {
3236                 return false;
3237             }
3238             final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3239             if ( t1.getNumberOfExternalNodes() != 2 ) {
3240                 return false;
3241             }
3242             t1.deleteSubtree( t1.getNode( "A" ), false );
3243             if ( t1.getNumberOfExternalNodes() != 1 ) {
3244                 return false;
3245             }
3246             if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3247                 return false;
3248             }
3249             t1.deleteSubtree( t1.getNode( "B" ), false );
3250             if ( t1.getNumberOfExternalNodes() != 1 ) {
3251                 return false;
3252             }
3253             t1.deleteSubtree( t1.getNode( "r" ), false );
3254             if ( !t1.isEmpty() ) {
3255                 return false;
3256             }
3257             final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3258             if ( t2.getNumberOfExternalNodes() != 3 ) {
3259                 return false;
3260             }
3261             t2.deleteSubtree( t2.getNode( "B" ), false );
3262             if ( t2.getNumberOfExternalNodes() != 2 ) {
3263                 return false;
3264             }
3265             t2.toNewHampshireX();
3266             PhylogenyNode n = t2.getNode( "A" );
3267             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3268                 return false;
3269             }
3270             t2.deleteSubtree( t2.getNode( "A" ), false );
3271             if ( t2.getNumberOfExternalNodes() != 2 ) {
3272                 return false;
3273             }
3274             t2.deleteSubtree( t2.getNode( "C" ), true );
3275             if ( t2.getNumberOfExternalNodes() != 1 ) {
3276                 return false;
3277             }
3278             final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3279             if ( t3.getNumberOfExternalNodes() != 4 ) {
3280                 return false;
3281             }
3282             t3.deleteSubtree( t3.getNode( "B" ), true );
3283             if ( t3.getNumberOfExternalNodes() != 3 ) {
3284                 return false;
3285             }
3286             n = t3.getNode( "A" );
3287             if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3288                 return false;
3289             }
3290             n = n.getNextExternalNode();
3291             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3292                 return false;
3293             }
3294             t3.deleteSubtree( t3.getNode( "A" ), true );
3295             if ( t3.getNumberOfExternalNodes() != 2 ) {
3296                 return false;
3297             }
3298             n = t3.getNode( "C" );
3299             if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3300                 return false;
3301             }
3302             t3.deleteSubtree( t3.getNode( "C" ), true );
3303             if ( t3.getNumberOfExternalNodes() != 1 ) {
3304                 return false;
3305             }
3306             t3.deleteSubtree( t3.getNode( "D" ), true );
3307             if ( t3.getNumberOfExternalNodes() != 0 ) {
3308                 return false;
3309             }
3310             final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3311             if ( t4.getNumberOfExternalNodes() != 6 ) {
3312                 return false;
3313             }
3314             t4.deleteSubtree( t4.getNode( "B2" ), true );
3315             if ( t4.getNumberOfExternalNodes() != 5 ) {
3316                 return false;
3317             }
3318             String s = w.toNewHampshire( t4, false, true ).toString();
3319             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3320                 return false;
3321             }
3322             t4.deleteSubtree( t4.getNode( "B11" ), true );
3323             if ( t4.getNumberOfExternalNodes() != 4 ) {
3324                 return false;
3325             }
3326             t4.deleteSubtree( t4.getNode( "C" ), true );
3327             if ( t4.getNumberOfExternalNodes() != 3 ) {
3328                 return false;
3329             }
3330             n = t4.getNode( "A" );
3331             n = n.getNextExternalNode();
3332             if ( !n.getName().equals( "B12" ) ) {
3333                 return false;
3334             }
3335             n = n.getNextExternalNode();
3336             if ( !n.getName().equals( "D" ) ) {
3337                 return false;
3338             }
3339             s = w.toNewHampshire( t4, false, true ).toString();
3340             if ( !s.equals( "((A,B12),D);" ) ) {
3341                 return false;
3342             }
3343             final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3344             t5.deleteSubtree( t5.getNode( "A" ), true );
3345             if ( t5.getNumberOfExternalNodes() != 5 ) {
3346                 return false;
3347             }
3348             s = w.toNewHampshire( t5, false, true ).toString();
3349             if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3350                 return false;
3351             }
3352             final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3353             t6.deleteSubtree( t6.getNode( "B11" ), true );
3354             if ( t6.getNumberOfExternalNodes() != 5 ) {
3355                 return false;
3356             }
3357             s = w.toNewHampshire( t6, false, false ).toString();
3358             if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3359                 return false;
3360             }
3361             final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3362             t7.deleteSubtree( t7.getNode( "B12" ), true );
3363             if ( t7.getNumberOfExternalNodes() != 5 ) {
3364                 return false;
3365             }
3366             s = w.toNewHampshire( t7, false, true ).toString();
3367             if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3368                 return false;
3369             }
3370             final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3371             t8.deleteSubtree( t8.getNode( "B2" ), true );
3372             if ( t8.getNumberOfExternalNodes() != 5 ) {
3373                 return false;
3374             }
3375             s = w.toNewHampshire( t8, false, false ).toString();
3376             if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3377                 return false;
3378             }
3379             final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3380             t9.deleteSubtree( t9.getNode( "C" ), true );
3381             if ( t9.getNumberOfExternalNodes() != 5 ) {
3382                 return false;
3383             }
3384             s = w.toNewHampshire( t9, false, true ).toString();
3385             if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3386                 return false;
3387             }
3388             final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3389             t10.deleteSubtree( t10.getNode( "D" ), true );
3390             if ( t10.getNumberOfExternalNodes() != 5 ) {
3391                 return false;
3392             }
3393             s = w.toNewHampshire( t10, false, true ).toString();
3394             if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3395                 return false;
3396             }
3397             final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3398             t11.deleteSubtree( t11.getNode( "A" ), true );
3399             if ( t11.getNumberOfExternalNodes() != 2 ) {
3400                 return false;
3401             }
3402             s = w.toNewHampshire( t11, false, true ).toString();
3403             if ( !s.equals( "(B,C);" ) ) {
3404                 return false;
3405             }
3406             t11.deleteSubtree( t11.getNode( "C" ), true );
3407             if ( t11.getNumberOfExternalNodes() != 1 ) {
3408                 return false;
3409             }
3410             s = w.toNewHampshire( t11, false, false ).toString();
3411             if ( !s.equals( "B;" ) ) {
3412                 return false;
3413             }
3414             final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3415             t12.deleteSubtree( t12.getNode( "B2" ), true );
3416             if ( t12.getNumberOfExternalNodes() != 8 ) {
3417                 return false;
3418             }
3419             s = w.toNewHampshire( t12, false, true ).toString();
3420             if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3421                 return false;
3422             }
3423             t12.deleteSubtree( t12.getNode( "B3" ), true );
3424             if ( t12.getNumberOfExternalNodes() != 7 ) {
3425                 return false;
3426             }
3427             s = w.toNewHampshire( t12, false, true ).toString();
3428             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3429                 return false;
3430             }
3431             t12.deleteSubtree( t12.getNode( "C3" ), true );
3432             if ( t12.getNumberOfExternalNodes() != 6 ) {
3433                 return false;
3434             }
3435             s = w.toNewHampshire( t12, false, true ).toString();
3436             if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3437                 return false;
3438             }
3439             t12.deleteSubtree( t12.getNode( "A1" ), true );
3440             if ( t12.getNumberOfExternalNodes() != 5 ) {
3441                 return false;
3442             }
3443             s = w.toNewHampshire( t12, false, true ).toString();
3444             if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3445                 return false;
3446             }
3447             t12.deleteSubtree( t12.getNode( "B1" ), true );
3448             if ( t12.getNumberOfExternalNodes() != 4 ) {
3449                 return false;
3450             }
3451             s = w.toNewHampshire( t12, false, true ).toString();
3452             if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3453                 return false;
3454             }
3455             t12.deleteSubtree( t12.getNode( "A3" ), true );
3456             if ( t12.getNumberOfExternalNodes() != 3 ) {
3457                 return false;
3458             }
3459             s = w.toNewHampshire( t12, false, true ).toString();
3460             if ( !s.equals( "(A2,(C1,C2));" ) ) {
3461                 return false;
3462             }
3463             t12.deleteSubtree( t12.getNode( "A2" ), true );
3464             if ( t12.getNumberOfExternalNodes() != 2 ) {
3465                 return false;
3466             }
3467             s = w.toNewHampshire( t12, false, true ).toString();
3468             if ( !s.equals( "(C1,C2);" ) ) {
3469                 return false;
3470             }
3471             final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3472             t13.deleteSubtree( t13.getNode( "D" ), true );
3473             if ( t13.getNumberOfExternalNodes() != 4 ) {
3474                 return false;
3475             }
3476             s = w.toNewHampshire( t13, false, true ).toString();
3477             if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3478                 return false;
3479             }
3480             final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3481             t14.deleteSubtree( t14.getNode( "E" ), true );
3482             if ( t14.getNumberOfExternalNodes() != 5 ) {
3483                 return false;
3484             }
3485             s = w.toNewHampshire( t14, false, true ).toString();
3486             if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3487                 return false;
3488             }
3489             final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3490             t15.deleteSubtree( t15.getNode( "B2" ), true );
3491             if ( t15.getNumberOfExternalNodes() != 11 ) {
3492                 return false;
3493             }
3494             t15.deleteSubtree( t15.getNode( "B1" ), true );
3495             if ( t15.getNumberOfExternalNodes() != 10 ) {
3496                 return false;
3497             }
3498             t15.deleteSubtree( t15.getNode( "B3" ), true );
3499             if ( t15.getNumberOfExternalNodes() != 9 ) {
3500                 return false;
3501             }
3502             t15.deleteSubtree( t15.getNode( "B4" ), true );
3503             if ( t15.getNumberOfExternalNodes() != 8 ) {
3504                 return false;
3505             }
3506             t15.deleteSubtree( t15.getNode( "A1" ), true );
3507             if ( t15.getNumberOfExternalNodes() != 7 ) {
3508                 return false;
3509             }
3510             t15.deleteSubtree( t15.getNode( "C4" ), true );
3511             if ( t15.getNumberOfExternalNodes() != 6 ) {
3512                 return false;
3513             }
3514         }
3515         catch ( final Exception e ) {
3516             e.printStackTrace( System.out );
3517             return false;
3518         }
3519         return true;
3520     }
3521
3522     private static boolean testDescriptiveStatistics() {
3523         try {
3524             final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3525             dss1.addValue( 82 );
3526             dss1.addValue( 78 );
3527             dss1.addValue( 70 );
3528             dss1.addValue( 58 );
3529             dss1.addValue( 42 );
3530             if ( dss1.getN() != 5 ) {
3531                 return false;
3532             }
3533             if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3534                 return false;
3535             }
3536             if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3537                 return false;
3538             }
3539             if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3540                 return false;
3541             }
3542             if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3543                 return false;
3544             }
3545             if ( !Test.isEqual( dss1.median(), 70 ) ) {
3546                 return false;
3547             }
3548             if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3549                 return false;
3550             }
3551             if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3552                 return false;
3553             }
3554             if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3555                 return false;
3556             }
3557             if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3558                 return false;
3559             }
3560             if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3561                 return false;
3562             }
3563             if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3564                 return false;
3565             }
3566             dss1.addValue( 123 );
3567             if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3568                 return false;
3569             }
3570             if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3571                 return false;
3572             }
3573             if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3574                 return false;
3575             }
3576             final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3577             dss2.addValue( -1.85 );
3578             dss2.addValue( 57.5 );
3579             dss2.addValue( 92.78 );
3580             dss2.addValue( 57.78 );
3581             if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3582                 return false;
3583             }
3584             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3585                 return false;
3586             }
3587             final double[] a = dss2.getDataAsDoubleArray();
3588             if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3589                 return false;
3590             }
3591             dss2.addValue( -100 );
3592             if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3593                 return false;
3594             }
3595             if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3596                 return false;
3597             }
3598             final double[] ds = new double[ 14 ];
3599             ds[ 0 ] = 34;
3600             ds[ 1 ] = 23;
3601             ds[ 2 ] = 1;
3602             ds[ 3 ] = 32;
3603             ds[ 4 ] = 11;
3604             ds[ 5 ] = 2;
3605             ds[ 6 ] = 12;
3606             ds[ 7 ] = 33;
3607             ds[ 8 ] = 13;
3608             ds[ 9 ] = 22;
3609             ds[ 10 ] = 21;
3610             ds[ 11 ] = 35;
3611             ds[ 12 ] = 24;
3612             ds[ 13 ] = 31;
3613             final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3614             if ( bins.length != 4 ) {
3615                 return false;
3616             }
3617             if ( bins[ 0 ] != 2 ) {
3618                 return false;
3619             }
3620             if ( bins[ 1 ] != 3 ) {
3621                 return false;
3622             }
3623             if ( bins[ 2 ] != 4 ) {
3624                 return false;
3625             }
3626             if ( bins[ 3 ] != 5 ) {
3627                 return false;
3628             }
3629             final double[] ds1 = new double[ 9 ];
3630             ds1[ 0 ] = 10.0;
3631             ds1[ 1 ] = 19.0;
3632             ds1[ 2 ] = 9.999;
3633             ds1[ 3 ] = 0.0;
3634             ds1[ 4 ] = 39.9;
3635             ds1[ 5 ] = 39.999;
3636             ds1[ 6 ] = 30.0;
3637             ds1[ 7 ] = 19.999;
3638             ds1[ 8 ] = 30.1;
3639             final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3640             if ( bins1.length != 4 ) {
3641                 return false;
3642             }
3643             if ( bins1[ 0 ] != 2 ) {
3644                 return false;
3645             }
3646             if ( bins1[ 1 ] != 3 ) {
3647                 return false;
3648             }
3649             if ( bins1[ 2 ] != 0 ) {
3650                 return false;
3651             }
3652             if ( bins1[ 3 ] != 4 ) {
3653                 return false;
3654             }
3655             final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3656             if ( bins1_1.length != 3 ) {
3657                 return false;
3658             }
3659             if ( bins1_1[ 0 ] != 3 ) {
3660                 return false;
3661             }
3662             if ( bins1_1[ 1 ] != 2 ) {
3663                 return false;
3664             }
3665             if ( bins1_1[ 2 ] != 4 ) {
3666                 return false;
3667             }
3668             final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3669             if ( bins1_2.length != 3 ) {
3670                 return false;
3671             }
3672             if ( bins1_2[ 0 ] != 2 ) {
3673                 return false;
3674             }
3675             if ( bins1_2[ 1 ] != 2 ) {
3676                 return false;
3677             }
3678             if ( bins1_2[ 2 ] != 2 ) {
3679                 return false;
3680             }
3681             final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3682             dss3.addValue( 1 );
3683             dss3.addValue( 1 );
3684             dss3.addValue( 1 );
3685             dss3.addValue( 2 );
3686             dss3.addValue( 3 );
3687             dss3.addValue( 4 );
3688             dss3.addValue( 5 );
3689             dss3.addValue( 5 );
3690             dss3.addValue( 5 );
3691             dss3.addValue( 6 );
3692             dss3.addValue( 7 );
3693             dss3.addValue( 8 );
3694             dss3.addValue( 9 );
3695             dss3.addValue( 10 );
3696             dss3.addValue( 10 );
3697             dss3.addValue( 10 );
3698             final AsciiHistogram histo = new AsciiHistogram( dss3 );
3699             histo.toStringBuffer( 10, '=', 40, 5 );
3700             histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3701         }
3702         catch ( final Exception e ) {
3703             e.printStackTrace( System.out );
3704             return false;
3705         }
3706         return true;
3707     }
3708
3709     private static boolean testDir( final String file ) {
3710         try {
3711             final File f = new File( file );
3712             if ( !f.exists() ) {
3713                 return false;
3714             }
3715             if ( !f.isDirectory() ) {
3716                 return false;
3717             }
3718             if ( !f.canRead() ) {
3719                 return false;
3720             }
3721         }
3722         catch ( final Exception e ) {
3723             return false;
3724         }
3725         return true;
3726     }
3727
3728     private static boolean testGenbankAccessorParsing() {
3729         //The format for GenBank Accession numbers are:
3730         //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
3731         //Protein:    3 letters + 5 numerals
3732         //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
3733         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
3734             return false;
3735         }
3736         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
3737             return false;
3738         }
3739         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
3740             return false;
3741         }
3742         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
3743             return false;
3744         }
3745         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
3746             return false;
3747         }
3748         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
3749             return false;
3750         }
3751         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
3752             return false;
3753         }
3754         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
3755             return false;
3756         }
3757         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
3758             return false;
3759         }
3760         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
3761             return false;
3762         }
3763         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
3764             return false;
3765         }
3766         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
3767             return false;
3768         }
3769         if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
3770             return false;
3771         }
3772         if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
3773             return false;
3774         }
3775         return true;
3776     }
3777
3778     private static boolean testExternalNodeRelatedMethods() {
3779         try {
3780             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3781             final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3782             PhylogenyNode n = t1.getNode( "A" );
3783             n = n.getNextExternalNode();
3784             if ( !n.getName().equals( "B" ) ) {
3785                 return false;
3786             }
3787             n = n.getNextExternalNode();
3788             if ( !n.getName().equals( "C" ) ) {
3789                 return false;
3790             }
3791             n = n.getNextExternalNode();
3792             if ( !n.getName().equals( "D" ) ) {
3793                 return false;
3794             }
3795             n = t1.getNode( "B" );
3796             while ( !n.isLastExternalNode() ) {
3797                 n = n.getNextExternalNode();
3798             }
3799             final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
3800             n = t2.getNode( "A" );
3801             n = n.getNextExternalNode();
3802             if ( !n.getName().equals( "B" ) ) {
3803                 return false;
3804             }
3805             n = n.getNextExternalNode();
3806             if ( !n.getName().equals( "C" ) ) {
3807                 return false;
3808             }
3809             n = n.getNextExternalNode();
3810             if ( !n.getName().equals( "D" ) ) {
3811                 return false;
3812             }
3813             n = t2.getNode( "B" );
3814             while ( !n.isLastExternalNode() ) {
3815                 n = n.getNextExternalNode();
3816             }
3817             final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3818             n = t3.getNode( "A" );
3819             n = n.getNextExternalNode();
3820             if ( !n.getName().equals( "B" ) ) {
3821                 return false;
3822             }
3823             n = n.getNextExternalNode();
3824             if ( !n.getName().equals( "C" ) ) {
3825                 return false;
3826             }
3827             n = n.getNextExternalNode();
3828             if ( !n.getName().equals( "D" ) ) {
3829                 return false;
3830             }
3831             n = n.getNextExternalNode();
3832             if ( !n.getName().equals( "E" ) ) {
3833                 return false;
3834             }
3835             n = n.getNextExternalNode();
3836             if ( !n.getName().equals( "F" ) ) {
3837                 return false;
3838             }
3839             n = n.getNextExternalNode();
3840             if ( !n.getName().equals( "G" ) ) {
3841                 return false;
3842             }
3843             n = n.getNextExternalNode();
3844             if ( !n.getName().equals( "H" ) ) {
3845                 return false;
3846             }
3847             n = t3.getNode( "B" );
3848             while ( !n.isLastExternalNode() ) {
3849                 n = n.getNextExternalNode();
3850             }
3851             final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3852             for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
3853                 final PhylogenyNode node = iter.next();
3854             }
3855             final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3856             for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
3857                 final PhylogenyNode node = iter.next();
3858             }
3859             final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
3860             final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
3861             if ( !iter.next().getName().equals( "A" ) ) {
3862                 return false;
3863             }
3864             if ( !iter.next().getName().equals( "B" ) ) {
3865                 return false;
3866             }
3867             if ( !iter.next().getName().equals( "C" ) ) {
3868                 return false;
3869             }
3870             if ( !iter.next().getName().equals( "D" ) ) {
3871                 return false;
3872             }
3873             if ( !iter.next().getName().equals( "E" ) ) {
3874                 return false;
3875             }
3876             if ( !iter.next().getName().equals( "F" ) ) {
3877                 return false;
3878             }
3879             if ( iter.hasNext() ) {
3880                 return false;
3881             }
3882         }
3883         catch ( final Exception e ) {
3884             e.printStackTrace( System.out );
3885             return false;
3886         }
3887         return true;
3888     }
3889
3890     private static boolean testExtractSNFromNodeName() {
3891         try {
3892             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
3893                 return false;
3894             }
3895             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus" )
3896                     .equals( "Mus musculus musculus" ) ) {
3897                 return false;
3898             }
3899             if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus-12" )
3900                     .equals( "Mus musculus musculus" ) ) {
3901                 return false;
3902             }
3903             if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus-12" ).equals( "Mus musculus" ) ) {
3904                 return false;
3905             }
3906             if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus-12 affrre e" )
3907                     .equals( "Mus musculus" ) ) {
3908                 return false;
3909             }
3910         }
3911         catch ( final Exception e ) {
3912             e.printStackTrace( System.out );
3913             return false;
3914         }
3915         return true;
3916     }
3917
3918     private static boolean testExtractTaxonomyCodeFromNodeName() {
3919         try {
3920             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3921                 return false;
3922             }
3923             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3924                     .equals( "SOYBN" ) ) {
3925                 return false;
3926             }
3927             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
3928                     .equals( "ARATH" ) ) {
3929                 return false;
3930             }
3931             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
3932                     .equals( "ARATH" ) ) {
3933                 return false;
3934             }
3935             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
3936                 return false;
3937             }
3938             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
3939                 return false;
3940             }
3941             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3942                 return false;
3943             }
3944             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3945                     .equals( "SOYBN" ) ) {
3946                 return false;
3947             }
3948             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3949                     .equals( "SOYBN" ) ) {
3950                 return false;
3951             }
3952             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3953                     .equals( "SOYBN" ) ) {
3954                 return false;
3955             }
3956             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3957                     .equals( "SOYBN" ) ) {
3958                 return false;
3959             }
3960             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3961                     .equals( "SOYBN" ) ) {
3962                 return false;
3963             }
3964             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3965                     .equals( "SOYBN" ) ) {
3966                 return false;
3967             }
3968             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
3969                     .equals( "SOYBN" ) ) {
3970                 return false;
3971             }
3972             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
3973                     .equals( "SOYBN" ) ) {
3974                 return false;
3975             }
3976             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
3977                 return false;
3978             }
3979             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
3980                     .equals( "SOYBN" ) ) {
3981                 return false;
3982             }
3983             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
3984                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
3985                 return false;
3986             }
3987             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
3988                     .equals( "9YX45" ) ) {
3989                 return false;
3990             }
3991             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
3992                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3993                     .equals( "MOUSE" ) ) {
3994                 return false;
3995             }
3996             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
3997                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3998                     .equals( "MOUSE" ) ) {
3999                 return false;
4000             }
4001             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
4002                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4003                     .equals( "MOUSE" ) ) {
4004                 return false;
4005             }
4006             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
4007                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4008                 return false;
4009             }
4010             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
4011                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4012                 return false;
4013             }
4014             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4015                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4016                 return false;
4017             }
4018             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4019                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4020                 return false;
4021             }
4022             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
4023                                                                TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4024                 return false;
4025             }
4026             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
4027                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4028                 return false;
4029             }
4030             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
4031                                                               TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4032                 return false;
4033             }
4034             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4035                     .equals( "RAT" ) ) {
4036                 return false;
4037             }
4038             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4039                     .equals( "PIG" ) ) {
4040                 return false;
4041             }
4042             if ( !ParserUtils
4043                     .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4044                     .equals( "MOUSE" ) ) {
4045                 return false;
4046             }
4047             if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4048                     .equals( "MOUSE" ) ) {
4049                 return false;
4050             }
4051             if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4052                 return false;
4053             }
4054         }
4055         catch ( final Exception e ) {
4056             e.printStackTrace( System.out );
4057             return false;
4058         }
4059         return true;
4060     }
4061
4062     private static boolean testExtractUniProtKbProteinSeqIdentifier() {
4063         try {
4064             PhylogenyNode n = new PhylogenyNode();
4065             n.setName( "tr|B3RJ64" );
4066             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4067                 return false;
4068             }
4069             n.setName( "tr.B3RJ64" );
4070             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4071                 return false;
4072             }
4073             n.setName( "tr=B3RJ64" );
4074             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4075                 return false;
4076             }
4077             n.setName( "tr-B3RJ64" );
4078             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4079                 return false;
4080             }
4081             n.setName( "tr/B3RJ64" );
4082             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4083                 return false;
4084             }
4085             n.setName( "tr\\B3RJ64" );
4086             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4087                 return false;
4088             }
4089             n.setName( "tr_B3RJ64" );
4090             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4091                 return false;
4092             }
4093             n.setName( " tr|B3RJ64 " );
4094             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4095                 return false;
4096             }
4097             n.setName( "-tr|B3RJ64-" );
4098             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4099                 return false;
4100             }
4101             n.setName( "-tr=B3RJ64-" );
4102             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4103                 return false;
4104             }
4105             n.setName( "_tr=B3RJ64_" );
4106             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4107                 return false;
4108             }
4109             n.setName( " tr_tr|B3RJ64_sp|123 " );
4110             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4111                 return false;
4112             }
4113             n.setName( "B3RJ64" );
4114             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4115                 return false;
4116             }
4117             n.setName( "sp|B3RJ64" );
4118             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4119                 return false;
4120             }
4121             n.setName( "sp|B3RJ64C" );
4122             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4123                 return false;
4124             }
4125             n.setName( "sp B3RJ64" );
4126             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4127                 return false;
4128             }
4129             n.setName( "sp|B3RJ6X" );
4130             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4131                 return false;
4132             }
4133             n.setName( "sp|B3RJ6" );
4134             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4135                 return false;
4136             }
4137             n.setName( "K1PYK7_CRAGI" );
4138             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4139                 return false;
4140             }
4141             n.setName( "K1PYK7_PEA" );
4142             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
4143                 return false;
4144             }
4145             n.setName( "K1PYK7_RAT" );
4146             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
4147                 return false;
4148             }
4149             n.setName( "K1PYK7_PIG" );
4150             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4151                 return false;
4152             }
4153             n.setName( "~K1PYK7_PIG~" );
4154             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4155                 return false;
4156             }
4157             n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
4158             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4159                 return false;
4160             }
4161             n.setName( "K1PYKX_CRAGI" );
4162             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4163                 return false;
4164             }
4165             n.setName( "XXXXX_CRAGI" );
4166             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
4167                 return false;
4168             }
4169             n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
4170             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
4171                 return false;
4172             }
4173             n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
4174             if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4175                 return false;
4176             }
4177             n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
4178             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
4179                 return false;
4180             }
4181             n = new PhylogenyNode();
4182             org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
4183             seq.setSymbol( "K1PYK7_CRAGI" );
4184             n.getNodeData().addSequence( seq );
4185             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4186                 return false;
4187             }
4188             seq.setSymbol( "tr|B3RJ64" );
4189             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4190                 return false;
4191             }
4192             n = new PhylogenyNode();
4193             seq = new org.forester.phylogeny.data.Sequence();
4194             seq.setName( "K1PYK7_CRAGI" );
4195             n.getNodeData().addSequence( seq );
4196             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4197                 return false;
4198             }
4199             seq.setName( "tr|B3RJ64" );
4200             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4201                 return false;
4202             }
4203             n = new PhylogenyNode();
4204             seq = new org.forester.phylogeny.data.Sequence();
4205             seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4206             n.getNodeData().addSequence( seq );
4207             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
4208                 return false;
4209             }
4210             n = new PhylogenyNode();
4211             seq = new org.forester.phylogeny.data.Sequence();
4212             seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4213             n.getNodeData().addSequence( seq );
4214             if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4215                 return false;
4216             }
4217             //
4218             n = new PhylogenyNode();
4219             n.setName( "ACP19736" );
4220             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4221                 return false;
4222             }
4223             n = new PhylogenyNode();
4224             n.setName( "|ACP19736|" );
4225             if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4226                 return false;
4227             }
4228         }
4229         catch ( final Exception e ) {
4230             e.printStackTrace( System.out );
4231             return false;
4232         }
4233         return true;
4234     }
4235
4236     private static boolean testFastaParser() {
4237         try {
4238             if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
4239                 return false;
4240             }
4241             if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
4242                 return false;
4243             }
4244             final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
4245             if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
4246                 return false;
4247             }
4248             if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
4249                 return false;
4250             }
4251             if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
4252                 return false;
4253             }
4254             if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
4255                 return false;
4256             }
4257             if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
4258                 return false;
4259             }
4260             if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
4261                 return false;
4262             }
4263         }
4264         catch ( final Exception e ) {
4265             e.printStackTrace();
4266             return false;
4267         }
4268         return true;
4269     }
4270
4271     private static boolean testGeneralMsaParser() {
4272         try {
4273             final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
4274             final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
4275             final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
4276             final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
4277             final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
4278             final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
4279             final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
4280             final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
4281             if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4282                 return false;
4283             }
4284             if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4285                 return false;
4286             }
4287             if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4288                 return false;
4289             }
4290             if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4291                 return false;
4292             }
4293             if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4294                 return false;
4295             }
4296             if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4297                 return false;
4298             }
4299             if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4300                 return false;
4301             }
4302             if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4303                 return false;
4304             }
4305             if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4306                 return false;
4307             }
4308             if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4309                 return false;
4310             }
4311             if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4312                 return false;
4313             }
4314             if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4315                 return false;
4316             }
4317             final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
4318             if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4319                 return false;
4320             }
4321             if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4322                 return false;
4323             }
4324             if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4325                 return false;
4326             }
4327             final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
4328             if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
4329                 return false;
4330             }
4331             if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
4332                 return false;
4333             }
4334             if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
4335                 return false;
4336             }
4337             final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
4338             if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4339                 return false;
4340             }
4341             if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4342                 return false;
4343             }
4344             if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4345                 return false;
4346             }
4347         }
4348         catch ( final Exception e ) {
4349             e.printStackTrace();
4350             return false;
4351         }
4352         return true;
4353     }
4354
4355     private static boolean testGeneralTable() {
4356         try {
4357             final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
4358             t0.setValue( 3, 2, "23" );
4359             t0.setValue( 10, 1, "error" );
4360             t0.setValue( 10, 1, "110" );
4361             t0.setValue( 9, 1, "19" );
4362             t0.setValue( 1, 10, "101" );
4363             t0.setValue( 10, 10, "1010" );
4364             t0.setValue( 100, 10, "10100" );
4365             t0.setValue( 0, 0, "00" );
4366             if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
4367                 return false;
4368             }
4369             if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
4370                 return false;
4371             }
4372             if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
4373                 return false;
4374             }
4375             if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
4376                 return false;
4377             }
4378             if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
4379                 return false;
4380             }
4381             if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
4382                 return false;
4383             }
4384             if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
4385                 return false;
4386             }
4387             if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
4388                 return false;
4389             }
4390             if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
4391                 return false;
4392             }
4393             final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
4394             t1.setValue( "3", "2", "23" );
4395             t1.setValue( "10", "1", "error" );
4396             t1.setValue( "10", "1", "110" );
4397             t1.setValue( "9", "1", "19" );
4398             t1.setValue( "1", "10", "101" );
4399             t1.setValue( "10", "10", "1010" );
4400             t1.setValue( "100", "10", "10100" );
4401             t1.setValue( "0", "0", "00" );
4402             t1.setValue( "qwerty", "zxcvbnm", "asdef" );
4403             if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
4404                 return false;
4405             }
4406             if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
4407                 return false;
4408             }
4409             if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
4410                 return false;
4411             }
4412             if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
4413                 return false;
4414             }
4415             if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
4416                 return false;
4417             }
4418             if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
4419                 return false;
4420             }
4421             if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
4422                 return false;
4423             }
4424             if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
4425                 return false;
4426             }
4427             if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
4428                 return false;
4429             }
4430             if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
4431                 return false;
4432             }
4433         }
4434         catch ( final Exception e ) {
4435             e.printStackTrace( System.out );
4436             return false;
4437         }
4438         return true;
4439     }
4440
4441     private static boolean testGetDistance() {
4442         try {
4443             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4444             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",
4445                                                  new NHXParser() )[ 0 ];
4446             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
4447                 return false;
4448             }
4449             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
4450                 return false;
4451             }
4452             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
4453                 return false;
4454             }
4455             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
4456                 return false;
4457             }
4458             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
4459                 return false;
4460             }
4461             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
4462                 return false;
4463             }
4464             if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
4465                 return false;
4466             }
4467             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
4468                 return false;
4469             }
4470             if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
4471                 return false;
4472             }
4473             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
4474                 return false;
4475             }
4476             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
4477                 return false;
4478             }
4479             if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
4480                 return false;
4481             }
4482             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
4483                 return false;
4484             }
4485             if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
4486                 return false;
4487             }
4488             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
4489                 return false;
4490             }
4491             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
4492                 return false;
4493             }
4494             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
4495                 return false;
4496             }
4497             if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
4498                 return false;
4499             }
4500             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
4501                 return false;
4502             }
4503             if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
4504                 return false;
4505             }
4506             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
4507                 return false;
4508             }
4509             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
4510                 return false;
4511             }
4512             if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
4513                 return false;
4514             }
4515             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
4516                 return false;
4517             }
4518             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
4519                 return false;
4520             }
4521             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
4522                 return false;
4523             }
4524             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
4525                 return false;
4526             }
4527             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
4528                 return false;
4529             }
4530             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
4531                 return false;
4532             }
4533             if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
4534                 return false;
4535             }
4536             if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
4537                 return false;
4538             }
4539             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",
4540                                                  new NHXParser() )[ 0 ];
4541             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
4542                 return false;
4543             }
4544             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
4545                 return false;
4546             }
4547             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
4548                 return false;
4549             }
4550             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
4551                 return false;
4552             }
4553             if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
4554                 return false;
4555             }
4556             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
4557                 return false;
4558             }
4559             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
4560                 return false;
4561             }
4562             if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
4563                 return false;
4564             }
4565             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
4566                 return false;
4567             }
4568             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
4569                 return false;
4570             }
4571             if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
4572                 return false;
4573             }
4574         }
4575         catch ( final Exception e ) {
4576             e.printStackTrace( System.out );
4577             return false;
4578         }
4579         return true;
4580     }
4581
4582     private static boolean testGetLCA() {
4583         try {
4584             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4585             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
4586                                                  new NHXParser() )[ 0 ];
4587             final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
4588             if ( !A.getName().equals( "A" ) ) {
4589                 return false;
4590             }
4591             final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
4592             if ( !gh.getName().equals( "gh" ) ) {
4593                 return false;
4594             }
4595             final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
4596             if ( !ab.getName().equals( "ab" ) ) {
4597                 return false;
4598             }
4599             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
4600             if ( !ab2.getName().equals( "ab" ) ) {
4601                 return false;
4602             }
4603             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
4604             if ( !gh2.getName().equals( "gh" ) ) {
4605                 return false;
4606             }
4607             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
4608             if ( !gh3.getName().equals( "gh" ) ) {
4609                 return false;
4610             }
4611             final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
4612             if ( !abc.getName().equals( "abc" ) ) {
4613                 return false;
4614             }
4615             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
4616             if ( !abc2.getName().equals( "abc" ) ) {
4617                 return false;
4618             }
4619             final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
4620             if ( !abcd.getName().equals( "abcd" ) ) {
4621                 return false;
4622             }
4623             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
4624             if ( !abcd2.getName().equals( "abcd" ) ) {
4625                 return false;
4626             }
4627             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
4628             if ( !abcdef.getName().equals( "abcdef" ) ) {
4629                 return false;
4630             }
4631             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
4632             if ( !abcdef2.getName().equals( "abcdef" ) ) {
4633                 return false;
4634             }
4635             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
4636             if ( !abcdef3.getName().equals( "abcdef" ) ) {
4637                 return false;
4638             }
4639             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
4640             if ( !abcdef4.getName().equals( "abcdef" ) ) {
4641                 return false;
4642             }
4643             final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
4644             if ( !abcde.getName().equals( "abcde" ) ) {
4645                 return false;
4646             }
4647             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
4648             if ( !abcde2.getName().equals( "abcde" ) ) {
4649                 return false;
4650             }
4651             final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
4652             if ( !r.getName().equals( "abcdefgh" ) ) {
4653                 return false;
4654             }
4655             final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
4656             if ( !r2.getName().equals( "abcdefgh" ) ) {
4657                 return false;
4658             }
4659             final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
4660             if ( !r3.getName().equals( "abcdefgh" ) ) {
4661                 return false;
4662             }
4663             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
4664             if ( !abcde3.getName().equals( "abcde" ) ) {
4665                 return false;
4666             }
4667             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
4668             if ( !abcde4.getName().equals( "abcde" ) ) {
4669                 return false;
4670             }
4671             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
4672             if ( !ab3.getName().equals( "ab" ) ) {
4673                 return false;
4674             }
4675             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
4676             if ( !ab4.getName().equals( "ab" ) ) {
4677                 return false;
4678             }
4679             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
4680             final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
4681             if ( !cd.getName().equals( "cd" ) ) {
4682                 return false;
4683             }
4684             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
4685             if ( !cd2.getName().equals( "cd" ) ) {
4686                 return false;
4687             }
4688             final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
4689             if ( !cde.getName().equals( "cde" ) ) {
4690                 return false;
4691             }
4692             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
4693             if ( !cde2.getName().equals( "cde" ) ) {
4694                 return false;
4695             }
4696             final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
4697             if ( !cdef.getName().equals( "cdef" ) ) {
4698                 return false;
4699             }
4700             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
4701             if ( !cdef2.getName().equals( "cdef" ) ) {
4702                 return false;
4703             }
4704             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
4705             if ( !cdef3.getName().equals( "cdef" ) ) {
4706                 return false;
4707             }
4708             final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
4709             if ( !rt.getName().equals( "r" ) ) {
4710                 return false;
4711             }
4712             final Phylogeny p3 = factory
4713                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
4714                              new NHXParser() )[ 0 ];
4715             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
4716             if ( !bc_3.getName().equals( "bc" ) ) {
4717                 return false;
4718             }
4719             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
4720             if ( !ac_3.getName().equals( "abc" ) ) {
4721                 return false;
4722             }
4723             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
4724             if ( !ad_3.getName().equals( "abcde" ) ) {
4725                 return false;
4726             }
4727             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
4728             if ( !af_3.getName().equals( "abcdef" ) ) {
4729                 return false;
4730             }
4731             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
4732             if ( !ag_3.getName().equals( "" ) ) {
4733                 return false;
4734             }
4735             if ( !ag_3.isRoot() ) {
4736                 return false;
4737             }
4738             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
4739             if ( !al_3.getName().equals( "" ) ) {
4740                 return false;
4741             }
4742             if ( !al_3.isRoot() ) {
4743                 return false;
4744             }
4745             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
4746             if ( !kl_3.getName().equals( "" ) ) {
4747                 return false;
4748             }
4749             if ( !kl_3.isRoot() ) {
4750                 return false;
4751             }
4752             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
4753             if ( !fl_3.getName().equals( "" ) ) {
4754                 return false;
4755             }
4756             if ( !fl_3.isRoot() ) {
4757                 return false;
4758             }
4759             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
4760             if ( !gk_3.getName().equals( "ghijk" ) ) {
4761                 return false;
4762             }
4763             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
4764             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
4765             if ( !r_4.getName().equals( "r" ) ) {
4766                 return false;
4767             }
4768             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
4769             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
4770             if ( !r_5.getName().equals( "root" ) ) {
4771                 return false;
4772             }
4773             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
4774             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
4775             if ( !r_6.getName().equals( "rot" ) ) {
4776                 return false;
4777             }
4778             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
4779             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
4780             if ( !r_7.getName().equals( "rott" ) ) {
4781                 return false;
4782             }
4783         }
4784         catch ( final Exception e ) {
4785             e.printStackTrace( System.out );
4786             return false;
4787         }
4788         return true;
4789     }
4790
4791     private static boolean testGetLCA2() {
4792         try {
4793             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4794             // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
4795             final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
4796             PhylogenyMethods.preOrderReId( p_a );
4797             final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
4798                                                                                               p_a.getNode( "a" ) );
4799             if ( !p_a_1.getName().equals( "a" ) ) {
4800                 return false;
4801             }
4802             final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
4803             PhylogenyMethods.preOrderReId( p_b );
4804             final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
4805                                                                                               p_b.getNode( "a" ) );
4806             if ( !p_b_1.getName().equals( "b" ) ) {
4807                 return false;
4808             }
4809             final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
4810                                                                                               p_b.getNode( "b" ) );
4811             if ( !p_b_2.getName().equals( "b" ) ) {
4812                 return false;
4813             }
4814             final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
4815             PhylogenyMethods.preOrderReId( p_c );
4816             final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
4817                                                                                               p_c.getNode( "a" ) );
4818             if ( !p_c_1.getName().equals( "b" ) ) {
4819                 return false;
4820             }
4821             final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
4822                                                                                               p_c.getNode( "c" ) );
4823             if ( !p_c_2.getName().equals( "c" ) ) {
4824                 System.out.println( p_c_2.getName() );
4825                 System.exit( -1 );
4826                 return false;
4827             }
4828             final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
4829                                                                                               p_c.getNode( "b" ) );
4830             if ( !p_c_3.getName().equals( "b" ) ) {
4831                 return false;
4832             }
4833             final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
4834                                                                                               p_c.getNode( "a" ) );
4835             if ( !p_c_4.getName().equals( "c" ) ) {
4836                 return false;
4837             }
4838             final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
4839                                                  new NHXParser() )[ 0 ];
4840             PhylogenyMethods.preOrderReId( p1 );
4841             final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4842                                                                                           p1.getNode( "A" ) );
4843             if ( !A.getName().equals( "A" ) ) {
4844                 return false;
4845             }
4846             final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
4847                                                                                            p1.getNode( "gh" ) );
4848             if ( !gh.getName().equals( "gh" ) ) {
4849                 return false;
4850             }
4851             final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4852                                                                                            p1.getNode( "B" ) );
4853             if ( !ab.getName().equals( "ab" ) ) {
4854                 return false;
4855             }
4856             final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
4857                                                                                             p1.getNode( "A" ) );
4858             if ( !ab2.getName().equals( "ab" ) ) {
4859                 return false;
4860             }
4861             final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
4862                                                                                             p1.getNode( "G" ) );
4863             if ( !gh2.getName().equals( "gh" ) ) {
4864                 return false;
4865             }
4866             final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
4867                                                                                             p1.getNode( "H" ) );
4868             if ( !gh3.getName().equals( "gh" ) ) {
4869                 return false;
4870             }
4871             final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
4872                                                                                             p1.getNode( "A" ) );
4873             if ( !abc.getName().equals( "abc" ) ) {
4874                 return false;
4875             }
4876             final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4877                                                                                              p1.getNode( "C" ) );
4878             if ( !abc2.getName().equals( "abc" ) ) {
4879                 return false;
4880             }
4881             final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4882                                                                                              p1.getNode( "D" ) );
4883             if ( !abcd.getName().equals( "abcd" ) ) {
4884                 return false;
4885             }
4886             final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
4887                                                                                               p1.getNode( "A" ) );
4888             if ( !abcd2.getName().equals( "abcd" ) ) {
4889                 return false;
4890             }
4891             final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4892                                                                                                p1.getNode( "F" ) );
4893             if ( !abcdef.getName().equals( "abcdef" ) ) {
4894                 return false;
4895             }
4896             final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
4897                                                                                                 p1.getNode( "A" ) );
4898             if ( !abcdef2.getName().equals( "abcdef" ) ) {
4899                 return false;
4900             }
4901             final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
4902                                                                                                 p1.getNode( "F" ) );
4903             if ( !abcdef3.getName().equals( "abcdef" ) ) {
4904                 return false;
4905             }
4906             final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
4907                                                                                                 p1.getNode( "ab" ) );
4908             if ( !abcdef4.getName().equals( "abcdef" ) ) {
4909                 return false;
4910             }
4911             final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4912                                                                                               p1.getNode( "E" ) );
4913             if ( !abcde.getName().equals( "abcde" ) ) {
4914                 return false;
4915             }
4916             final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
4917                                                                                                p1.getNode( "A" ) );
4918             if ( !abcde2.getName().equals( "abcde" ) ) {
4919                 return false;
4920             }
4921             final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
4922                                                                                           p1.getNode( "abcdefgh" ) );
4923             if ( !r.getName().equals( "abcdefgh" ) ) {
4924                 return false;
4925             }
4926             final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4927                                                                                            p1.getNode( "H" ) );
4928             if ( !r2.getName().equals( "abcdefgh" ) ) {
4929                 return false;
4930             }
4931             final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
4932                                                                                            p1.getNode( "A" ) );
4933             if ( !r3.getName().equals( "abcdefgh" ) ) {
4934                 return false;
4935             }
4936             final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
4937                                                                                                p1.getNode( "abcde" ) );
4938             if ( !abcde3.getName().equals( "abcde" ) ) {
4939                 return false;
4940             }
4941             final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
4942                                                                                                p1.getNode( "E" ) );
4943             if ( !abcde4.getName().equals( "abcde" ) ) {
4944                 return false;
4945             }
4946             final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
4947                                                                                             p1.getNode( "B" ) );
4948             if ( !ab3.getName().equals( "ab" ) ) {
4949                 return false;
4950             }
4951             final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
4952                                                                                             p1.getNode( "ab" ) );
4953             if ( !ab4.getName().equals( "ab" ) ) {
4954                 return false;
4955             }
4956             final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
4957             PhylogenyMethods.preOrderReId( p2 );
4958             final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4959                                                                                            p2.getNode( "d" ) );
4960             if ( !cd.getName().equals( "cd" ) ) {
4961                 return false;
4962             }
4963             final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
4964                                                                                             p2.getNode( "c" ) );
4965             if ( !cd2.getName().equals( "cd" ) ) {
4966                 return false;
4967             }
4968             final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4969                                                                                             p2.getNode( "e" ) );
4970             if ( !cde.getName().equals( "cde" ) ) {
4971                 return false;
4972             }
4973             final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
4974                                                                                              p2.getNode( "c" ) );
4975             if ( !cde2.getName().equals( "cde" ) ) {
4976                 return false;
4977             }
4978             final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4979                                                                                              p2.getNode( "f" ) );
4980             if ( !cdef.getName().equals( "cdef" ) ) {
4981                 return false;
4982             }
4983             final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
4984                                                                                               p2.getNode( "f" ) );
4985             if ( !cdef2.getName().equals( "cdef" ) ) {
4986                 return false;
4987             }
4988             final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
4989                                                                                               p2.getNode( "d" ) );
4990             if ( !cdef3.getName().equals( "cdef" ) ) {
4991                 return false;
4992             }
4993             final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4994                                                                                            p2.getNode( "a" ) );
4995             if ( !rt.getName().equals( "r" ) ) {
4996                 return false;
4997             }
4998             final Phylogeny p3 = factory
4999                     .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5000                              new NHXParser() )[ 0 ];
5001             PhylogenyMethods.preOrderReId( p3 );
5002             final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
5003                                                                                              p3.getNode( "c" ) );
5004             if ( !bc_3.getName().equals( "bc" ) ) {
5005                 return false;
5006             }
5007             final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5008                                                                                              p3.getNode( "c" ) );
5009             if ( !ac_3.getName().equals( "abc" ) ) {
5010                 return false;
5011             }
5012             final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5013                                                                                              p3.getNode( "d" ) );
5014             if ( !ad_3.getName().equals( "abcde" ) ) {
5015                 return false;
5016             }
5017             final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5018                                                                                              p3.getNode( "f" ) );
5019             if ( !af_3.getName().equals( "abcdef" ) ) {
5020                 return false;
5021             }
5022             final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5023                                                                                              p3.getNode( "g" ) );
5024             if ( !ag_3.getName().equals( "" ) ) {
5025                 return false;
5026             }
5027             if ( !ag_3.isRoot() ) {
5028                 return false;
5029             }
5030             final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5031                                                                                              p3.getNode( "l" ) );
5032             if ( !al_3.getName().equals( "" ) ) {
5033                 return false;
5034             }
5035             if ( !al_3.isRoot() ) {
5036                 return false;
5037             }
5038             final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
5039                                                                                              p3.getNode( "l" ) );
5040             if ( !kl_3.getName().equals( "" ) ) {
5041                 return false;
5042             }
5043             if ( !kl_3.isRoot() ) {
5044                 return false;
5045             }
5046             final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
5047                                                                                              p3.getNode( "l" ) );
5048             if ( !fl_3.getName().equals( "" ) ) {
5049                 return false;
5050             }
5051             if ( !fl_3.isRoot() ) {
5052                 return false;
5053             }
5054             final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
5055                                                                                              p3.getNode( "k" ) );
5056             if ( !gk_3.getName().equals( "ghijk" ) ) {
5057                 return false;
5058             }
5059             final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5060             PhylogenyMethods.preOrderReId( p4 );
5061             final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
5062                                                                                             p4.getNode( "c" ) );
5063             if ( !r_4.getName().equals( "r" ) ) {
5064                 return false;
5065             }
5066             final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5067             PhylogenyMethods.preOrderReId( p5 );
5068             final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
5069                                                                                             p5.getNode( "c" ) );
5070             if ( !r_5.getName().equals( "root" ) ) {
5071                 return false;
5072             }
5073             final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5074             PhylogenyMethods.preOrderReId( p6 );
5075             final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
5076                                                                                             p6.getNode( "a" ) );
5077             if ( !r_6.getName().equals( "rot" ) ) {
5078                 return false;
5079             }
5080             final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5081             PhylogenyMethods.preOrderReId( p7 );
5082             final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
5083                                                                                             p7.getNode( "e" ) );
5084             if ( !r_7.getName().equals( "rott" ) ) {
5085                 return false;
5086             }
5087             final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5088                                                                                              p7.getNode( "a" ) );
5089             if ( !r_71.getName().equals( "rott" ) ) {
5090                 return false;
5091             }
5092             final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5093                                                                                              p7.getNode( "rott" ) );
5094             if ( !r_72.getName().equals( "rott" ) ) {
5095                 return false;
5096             }
5097             final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5098                                                                                              p7.getNode( "a" ) );
5099             if ( !r_73.getName().equals( "rott" ) ) {
5100                 return false;
5101             }
5102             final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5103                                                                                              p7.getNode( "rott" ) );
5104             if ( !r_74.getName().equals( "rott" ) ) {
5105                 return false;
5106             }
5107             final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5108                                                                                              p7.getNode( "e" ) );
5109             if ( !r_75.getName().equals( "e" ) ) {
5110                 return false;
5111             }
5112         }
5113         catch ( final Exception e ) {
5114             e.printStackTrace( System.out );
5115             return false;
5116         }
5117         return true;
5118     }
5119
5120     private static boolean testHmmscanOutputParser() {
5121         final String test_dir = Test.PATH_TO_TEST_DATA;
5122         try {
5123             final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
5124                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5125             parser1.parse();
5126             final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
5127                     + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5128             final List<Protein> proteins = parser2.parse();
5129             if ( parser2.getProteinsEncountered() != 4 ) {
5130                 return false;
5131             }
5132             if ( proteins.size() != 4 ) {
5133                 return false;
5134             }
5135             if ( parser2.getDomainsEncountered() != 69 ) {
5136                 return false;
5137             }
5138             if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
5139                 return false;
5140             }
5141             if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
5142                 return false;
5143             }
5144             if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
5145                 return false;
5146             }
5147             final Protein p1 = proteins.get( 0 );
5148             if ( p1.getNumberOfProteinDomains() != 15 ) {
5149                 return false;
5150             }
5151             if ( p1.getLength() != 850 ) {
5152                 return false;
5153             }
5154             final Protein p2 = proteins.get( 1 );
5155             if ( p2.getNumberOfProteinDomains() != 51 ) {
5156                 return false;
5157             }
5158             if ( p2.getLength() != 1291 ) {
5159                 return false;
5160             }
5161             final Protein p3 = proteins.get( 2 );
5162             if ( p3.getNumberOfProteinDomains() != 2 ) {
5163                 return false;
5164             }
5165             final Protein p4 = proteins.get( 3 );
5166             if ( p4.getNumberOfProteinDomains() != 1 ) {
5167                 return false;
5168             }
5169             if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
5170                 return false;
5171             }
5172             if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
5173                 return false;
5174             }
5175             if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
5176                 return false;
5177             }
5178             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
5179                 return false;
5180             }
5181             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
5182                 return false;
5183             }
5184             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
5185                 return false;
5186             }
5187             if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
5188                 return false;
5189             }
5190         }
5191         catch ( final Exception e ) {
5192             e.printStackTrace( System.out );
5193             return false;
5194         }
5195         return true;
5196     }
5197
5198     private static boolean testLastExternalNodeMethods() {
5199         try {
5200             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5201             final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
5202             final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
5203             final PhylogenyNode n1 = t0.getNode( "A" );
5204             if ( n1.isLastExternalNode() ) {
5205                 return false;
5206             }
5207             final PhylogenyNode n2 = t0.getNode( "B" );
5208             if ( n2.isLastExternalNode() ) {
5209                 return false;
5210             }
5211             final PhylogenyNode n3 = t0.getNode( "C" );
5212             if ( n3.isLastExternalNode() ) {
5213                 return false;
5214             }
5215             final PhylogenyNode n4 = t0.getNode( "D" );
5216             if ( !n4.isLastExternalNode() ) {
5217                 return false;
5218             }
5219         }
5220         catch ( final Exception e ) {
5221             e.printStackTrace( System.out );
5222             return false;
5223         }
5224         return true;
5225     }
5226
5227     private static boolean testLevelOrderIterator() {
5228         try {
5229             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5230             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5231             PhylogenyNodeIterator it0;
5232             for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
5233                 it0.next();
5234             }
5235             for( it0.reset(); it0.hasNext(); ) {
5236                 it0.next();
5237             }
5238             final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
5239             if ( !it.next().getName().equals( "r" ) ) {
5240                 return false;
5241             }
5242             if ( !it.next().getName().equals( "ab" ) ) {
5243                 return false;
5244             }
5245             if ( !it.next().getName().equals( "cd" ) ) {
5246                 return false;
5247             }
5248             if ( !it.next().getName().equals( "A" ) ) {
5249                 return false;
5250             }
5251             if ( !it.next().getName().equals( "B" ) ) {
5252                 return false;
5253             }
5254             if ( !it.next().getName().equals( "C" ) ) {
5255                 return false;
5256             }
5257             if ( !it.next().getName().equals( "D" ) ) {
5258                 return false;
5259             }
5260             if ( it.hasNext() ) {
5261                 return false;
5262             }
5263             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",
5264                                                  new NHXParser() )[ 0 ];
5265             PhylogenyNodeIterator it2;
5266             for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
5267                 it2.next();
5268             }
5269             for( it2.reset(); it2.hasNext(); ) {
5270                 it2.next();
5271             }
5272             final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
5273             if ( !it3.next().getName().equals( "r" ) ) {
5274                 return false;
5275             }
5276             if ( !it3.next().getName().equals( "abc" ) ) {
5277                 return false;
5278             }
5279             if ( !it3.next().getName().equals( "defg" ) ) {
5280                 return false;
5281             }
5282             if ( !it3.next().getName().equals( "A" ) ) {
5283                 return false;
5284             }
5285             if ( !it3.next().getName().equals( "B" ) ) {
5286                 return false;
5287             }
5288             if ( !it3.next().getName().equals( "C" ) ) {
5289                 return false;
5290             }
5291             if ( !it3.next().getName().equals( "D" ) ) {
5292                 return false;
5293             }
5294             if ( !it3.next().getName().equals( "E" ) ) {
5295                 return false;
5296             }
5297             if ( !it3.next().getName().equals( "F" ) ) {
5298                 return false;
5299             }
5300             if ( !it3.next().getName().equals( "G" ) ) {
5301                 return false;
5302             }
5303             if ( !it3.next().getName().equals( "1" ) ) {
5304                 return false;
5305             }
5306             if ( !it3.next().getName().equals( "2" ) ) {
5307                 return false;
5308             }
5309             if ( !it3.next().getName().equals( "3" ) ) {
5310                 return false;
5311             }
5312             if ( !it3.next().getName().equals( "4" ) ) {
5313                 return false;
5314             }
5315             if ( !it3.next().getName().equals( "5" ) ) {
5316                 return false;
5317             }
5318             if ( !it3.next().getName().equals( "6" ) ) {
5319                 return false;
5320             }
5321             if ( !it3.next().getName().equals( "f1" ) ) {
5322                 return false;
5323             }
5324             if ( !it3.next().getName().equals( "f2" ) ) {
5325                 return false;
5326             }
5327             if ( !it3.next().getName().equals( "f3" ) ) {
5328                 return false;
5329             }
5330             if ( !it3.next().getName().equals( "a" ) ) {
5331                 return false;
5332             }
5333             if ( !it3.next().getName().equals( "b" ) ) {
5334                 return false;
5335             }
5336             if ( !it3.next().getName().equals( "f21" ) ) {
5337                 return false;
5338             }
5339             if ( !it3.next().getName().equals( "X" ) ) {
5340                 return false;
5341             }
5342             if ( !it3.next().getName().equals( "Y" ) ) {
5343                 return false;
5344             }
5345             if ( !it3.next().getName().equals( "Z" ) ) {
5346                 return false;
5347             }
5348             if ( it3.hasNext() ) {
5349                 return false;
5350             }
5351             final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
5352             PhylogenyNodeIterator it4;
5353             for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
5354                 it4.next();
5355             }
5356             for( it4.reset(); it4.hasNext(); ) {
5357                 it4.next();
5358             }
5359             final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
5360             if ( !it5.next().getName().equals( "r" ) ) {
5361                 return false;
5362             }
5363             if ( !it5.next().getName().equals( "A" ) ) {
5364                 return false;
5365             }
5366             if ( !it5.next().getName().equals( "B" ) ) {
5367                 return false;
5368             }
5369             if ( !it5.next().getName().equals( "C" ) ) {
5370                 return false;
5371             }
5372             if ( !it5.next().getName().equals( "D" ) ) {
5373                 return false;
5374             }
5375             final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
5376             PhylogenyNodeIterator it6;
5377             for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
5378                 it6.next();
5379             }
5380             for( it6.reset(); it6.hasNext(); ) {
5381                 it6.next();
5382             }
5383             final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
5384             if ( !it7.next().getName().equals( "A" ) ) {
5385                 return false;
5386             }
5387             if ( it.hasNext() ) {
5388                 return false;
5389             }
5390         }
5391         catch ( final Exception e ) {
5392             e.printStackTrace( System.out );
5393             return false;
5394         }
5395         return true;
5396     }
5397
5398     private static boolean testMafft( final String path ) {
5399         try {
5400             final List<String> opts = new ArrayList<String>();
5401             opts.add( "--maxiterate" );
5402             opts.add( "1000" );
5403             opts.add( "--localpair" );
5404             opts.add( "--quiet" );
5405             Msa msa = null;
5406             final MsaInferrer mafft = Mafft.createInstance( path );
5407             msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
5408             if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
5409                 return false;
5410             }
5411             if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
5412                 return false;
5413             }
5414         }
5415         catch ( final Exception e ) {
5416             e.printStackTrace( System.out );
5417             return false;
5418         }
5419         return true;
5420     }
5421
5422     private static boolean testMidpointrooting() {
5423         try {
5424             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5425             final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
5426             PhylogenyMethods.midpointRoot( t0 );
5427             if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
5428                 return false;
5429             }
5430             if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
5431                 return false;
5432             }
5433             if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
5434                            1 ) ) {
5435                 return false;
5436             }
5437             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",
5438                                                  new NHXParser() )[ 0 ];
5439             if ( !t1.isRooted() ) {
5440                 return false;
5441             }
5442             PhylogenyMethods.midpointRoot( t1 );
5443             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5444                 return false;
5445             }
5446             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5447                 return false;
5448             }
5449             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5450                 return false;
5451             }
5452             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5453                 return false;
5454             }
5455             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5456                 return false;
5457             }
5458             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5459                 return false;
5460             }
5461             t1.reRoot( t1.getNode( "A" ) );
5462             PhylogenyMethods.midpointRoot( t1 );
5463             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5464                 return false;
5465             }
5466             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5467                 return false;
5468             }
5469             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5470                 return false;
5471             }
5472             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5473                 return false;
5474             }
5475             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5476                 System.exit( -1 );
5477                 return false;
5478             }
5479             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5480                 return false;
5481             }
5482         }
5483         catch ( final Exception e ) {
5484             e.printStackTrace( System.out );
5485             return false;
5486         }
5487         return true;
5488     }
5489
5490     private static boolean testMsaQualityMethod() {
5491         try {
5492             final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
5493             final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
5494             final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
5495             final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
5496             final List<Sequence> l = new ArrayList<Sequence>();
5497             l.add( s0 );
5498             l.add( s1 );
5499             l.add( s2 );
5500             l.add( s3 );
5501             final Msa msa = BasicMsa.createInstance( l );
5502             if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
5503                 return false;
5504             }
5505             if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
5506                 return false;
5507             }
5508             if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
5509                 return false;
5510             }
5511             if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
5512                 return false;
5513             }
5514         }
5515         catch ( final Exception e ) {
5516             e.printStackTrace( System.out );
5517             return false;
5518         }
5519         return true;
5520     }
5521
5522     private static boolean testNextNodeWithCollapsing() {
5523         try {
5524             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5525             PhylogenyNode n;
5526             List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
5527             final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5528             final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
5529             t0.getNode( "cd" ).setCollapse( true );
5530             t0.getNode( "cde" ).setCollapse( true );
5531             n = t0.getFirstExternalNode();
5532             while ( n != null ) {
5533                 ext.add( n );
5534                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5535             }
5536             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5537                 return false;
5538             }
5539             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5540                 return false;
5541             }
5542             if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
5543                 return false;
5544             }
5545             if ( !ext.get( 3 ).getName().equals( "f" ) ) {
5546                 return false;
5547             }
5548             if ( !ext.get( 4 ).getName().equals( "g" ) ) {
5549                 return false;
5550             }
5551             if ( !ext.get( 5 ).getName().equals( "h" ) ) {
5552                 return false;
5553             }
5554             ext.clear();
5555             final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5556             final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
5557             t1.getNode( "ab" ).setCollapse( true );
5558             t1.getNode( "cd" ).setCollapse( true );
5559             t1.getNode( "cde" ).setCollapse( true );
5560             n = t1.getNode( "ab" );
5561             ext = new ArrayList<PhylogenyNode>();
5562             while ( n != null ) {
5563                 ext.add( n );
5564                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5565             }
5566             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5567                 return false;
5568             }
5569             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5570                 return false;
5571             }
5572             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5573                 return false;
5574             }
5575             if ( !ext.get( 3 ).getName().equals( "g" ) ) {
5576                 return false;
5577             }
5578             if ( !ext.get( 4 ).getName().equals( "h" ) ) {
5579                 return false;
5580             }
5581             //
5582             //
5583             ext.clear();
5584             final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5585             final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
5586             t2.getNode( "ab" ).setCollapse( true );
5587             t2.getNode( "cd" ).setCollapse( true );
5588             t2.getNode( "cde" ).setCollapse( true );
5589             t2.getNode( "c" ).setCollapse( true );
5590             t2.getNode( "d" ).setCollapse( true );
5591             t2.getNode( "e" ).setCollapse( true );
5592             t2.getNode( "gh" ).setCollapse( true );
5593             n = t2.getNode( "ab" );
5594             ext = new ArrayList<PhylogenyNode>();
5595             while ( n != null ) {
5596                 ext.add( n );
5597                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5598             }
5599             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5600                 return false;
5601             }
5602             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5603                 return false;
5604             }
5605             if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5606                 return false;
5607             }
5608             if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
5609                 return false;
5610             }
5611             //
5612             //
5613             ext.clear();
5614             final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5615             final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
5616             t3.getNode( "ab" ).setCollapse( true );
5617             t3.getNode( "cd" ).setCollapse( true );
5618             t3.getNode( "cde" ).setCollapse( true );
5619             t3.getNode( "c" ).setCollapse( true );
5620             t3.getNode( "d" ).setCollapse( true );
5621             t3.getNode( "e" ).setCollapse( true );
5622             t3.getNode( "gh" ).setCollapse( true );
5623             t3.getNode( "fgh" ).setCollapse( true );
5624             n = t3.getNode( "ab" );
5625             ext = new ArrayList<PhylogenyNode>();
5626             while ( n != null ) {
5627                 ext.add( n );
5628                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5629             }
5630             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5631                 return false;
5632             }
5633             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5634                 return false;
5635             }
5636             if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
5637                 return false;
5638             }
5639             //
5640             //
5641             ext.clear();
5642             final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5643             final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
5644             t4.getNode( "ab" ).setCollapse( true );
5645             t4.getNode( "cd" ).setCollapse( true );
5646             t4.getNode( "cde" ).setCollapse( true );
5647             t4.getNode( "c" ).setCollapse( true );
5648             t4.getNode( "d" ).setCollapse( true );
5649             t4.getNode( "e" ).setCollapse( true );
5650             t4.getNode( "gh" ).setCollapse( true );
5651             t4.getNode( "fgh" ).setCollapse( true );
5652             t4.getNode( "abcdefgh" ).setCollapse( true );
5653             n = t4.getNode( "abcdefgh" );
5654             if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
5655                 return false;
5656             }
5657             //
5658             //
5659             final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5660             final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
5661             ext.clear();
5662             n = t5.getFirstExternalNode();
5663             while ( n != null ) {
5664                 ext.add( n );
5665                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5666             }
5667             if ( ext.size() != 8 ) {
5668                 return false;
5669             }
5670             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5671                 return false;
5672             }
5673             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5674                 return false;
5675             }
5676             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5677                 return false;
5678             }
5679             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5680                 return false;
5681             }
5682             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5683                 return false;
5684             }
5685             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5686                 return false;
5687             }
5688             if ( !ext.get( 6 ).getName().equals( "g" ) ) {
5689                 return false;
5690             }
5691             if ( !ext.get( 7 ).getName().equals( "h" ) ) {
5692                 return false;
5693             }
5694             //
5695             //
5696             final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5697             final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
5698             ext.clear();
5699             t6.getNode( "ab" ).setCollapse( true );
5700             n = t6.getNode( "ab" );
5701             while ( n != null ) {
5702                 ext.add( n );
5703                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5704             }
5705             if ( ext.size() != 7 ) {
5706                 return false;
5707             }
5708             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5709                 return false;
5710             }
5711             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5712                 return false;
5713             }
5714             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5715                 return false;
5716             }
5717             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5718                 return false;
5719             }
5720             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5721                 return false;
5722             }
5723             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5724                 return false;
5725             }
5726             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5727                 return false;
5728             }
5729             //
5730             //
5731             final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5732             final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
5733             ext.clear();
5734             t7.getNode( "cd" ).setCollapse( true );
5735             n = t7.getNode( "a" );
5736             while ( n != null ) {
5737                 ext.add( n );
5738                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5739             }
5740             if ( ext.size() != 7 ) {
5741                 return false;
5742             }
5743             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5744                 return false;
5745             }
5746             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5747                 return false;
5748             }
5749             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
5750                 return false;
5751             }
5752             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5753                 return false;
5754             }
5755             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5756                 return false;
5757             }
5758             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5759                 return false;
5760             }
5761             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5762                 return false;
5763             }
5764             //
5765             //
5766             final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5767             final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
5768             ext.clear();
5769             t8.getNode( "cd" ).setCollapse( true );
5770             t8.getNode( "c" ).setCollapse( true );
5771             t8.getNode( "d" ).setCollapse( true );
5772             n = t8.getNode( "a" );
5773             while ( n != null ) {
5774                 ext.add( n );
5775                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5776             }
5777             if ( ext.size() != 7 ) {
5778                 return false;
5779             }
5780             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5781                 return false;
5782             }
5783             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5784                 return false;
5785             }
5786             if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
5787                 System.out.println( "2 fail" );
5788                 return false;
5789             }
5790             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5791                 return false;
5792             }
5793             if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5794                 return false;
5795             }
5796             if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5797                 return false;
5798             }
5799             if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5800                 return false;
5801             }
5802             //
5803             //
5804             final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5805             final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
5806             ext.clear();
5807             t9.getNode( "gh" ).setCollapse( true );
5808             n = t9.getNode( "a" );
5809             while ( n != null ) {
5810                 ext.add( n );
5811                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5812             }
5813             if ( ext.size() != 7 ) {
5814                 return false;
5815             }
5816             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5817                 return false;
5818             }
5819             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5820                 return false;
5821             }
5822             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5823                 return false;
5824             }
5825             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5826                 return false;
5827             }
5828             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5829                 return false;
5830             }
5831             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5832                 return false;
5833             }
5834             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
5835                 return false;
5836             }
5837             //
5838             //
5839             final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5840             final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
5841             ext.clear();
5842             t10.getNode( "gh" ).setCollapse( true );
5843             t10.getNode( "g" ).setCollapse( true );
5844             t10.getNode( "h" ).setCollapse( true );
5845             n = t10.getNode( "a" );
5846             while ( n != null ) {
5847                 ext.add( n );
5848                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5849             }
5850             if ( ext.size() != 7 ) {
5851                 return false;
5852             }
5853             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5854                 return false;
5855             }
5856             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5857                 return false;
5858             }
5859             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5860                 return false;
5861             }
5862             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5863                 return false;
5864             }
5865             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5866                 return false;
5867             }
5868             if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5869                 return false;
5870             }
5871             if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
5872                 return false;
5873             }
5874             //
5875             //
5876             final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5877             final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
5878             ext.clear();
5879             t11.getNode( "gh" ).setCollapse( true );
5880             t11.getNode( "fgh" ).setCollapse( true );
5881             n = t11.getNode( "a" );
5882             while ( n != null ) {
5883                 ext.add( n );
5884                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5885             }
5886             if ( ext.size() != 6 ) {
5887                 return false;
5888             }
5889             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5890                 return false;
5891             }
5892             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5893                 return false;
5894             }
5895             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5896                 return false;
5897             }
5898             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5899                 return false;
5900             }
5901             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5902                 return false;
5903             }
5904             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
5905                 return false;
5906             }
5907             //
5908             //
5909             final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5910             final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
5911             ext.clear();
5912             t12.getNode( "gh" ).setCollapse( true );
5913             t12.getNode( "fgh" ).setCollapse( true );
5914             t12.getNode( "g" ).setCollapse( true );
5915             t12.getNode( "h" ).setCollapse( true );
5916             t12.getNode( "f" ).setCollapse( true );
5917             n = t12.getNode( "a" );
5918             while ( n != null ) {
5919                 ext.add( n );
5920                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5921             }
5922             if ( ext.size() != 6 ) {
5923                 return false;
5924             }
5925             if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5926                 return false;
5927             }
5928             if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5929                 return false;
5930             }
5931             if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5932                 return false;
5933             }
5934             if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5935                 return false;
5936             }
5937             if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5938                 return false;
5939             }
5940             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
5941                 return false;
5942             }
5943             //
5944             //
5945             final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5946             final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
5947             ext.clear();
5948             t13.getNode( "ab" ).setCollapse( true );
5949             t13.getNode( "b" ).setCollapse( true );
5950             t13.getNode( "fgh" ).setCollapse( true );
5951             t13.getNode( "gh" ).setCollapse( true );
5952             n = t13.getNode( "ab" );
5953             while ( n != null ) {
5954                 ext.add( n );
5955                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5956             }
5957             if ( ext.size() != 5 ) {
5958                 return false;
5959             }
5960             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5961                 return false;
5962             }
5963             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5964                 return false;
5965             }
5966             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5967                 return false;
5968             }
5969             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5970                 return false;
5971             }
5972             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
5973                 return false;
5974             }
5975             //
5976             //
5977             final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
5978             final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
5979             ext.clear();
5980             t14.getNode( "ab" ).setCollapse( true );
5981             t14.getNode( "a" ).setCollapse( true );
5982             t14.getNode( "fgh" ).setCollapse( true );
5983             t14.getNode( "gh" ).setCollapse( true );
5984             n = t14.getNode( "ab" );
5985             while ( n != null ) {
5986                 ext.add( n );
5987                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5988             }
5989             if ( ext.size() != 5 ) {
5990                 return false;
5991             }
5992             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5993                 return false;
5994             }
5995             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5996                 return false;
5997             }
5998             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5999                 return false;
6000             }
6001             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6002                 return false;
6003             }
6004             if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6005                 return false;
6006             }
6007             //
6008             //
6009             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" );
6010             final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
6011             ext.clear();
6012             t15.getNode( "ab" ).setCollapse( true );
6013             t15.getNode( "a" ).setCollapse( true );
6014             t15.getNode( "fgh" ).setCollapse( true );
6015             t15.getNode( "gh" ).setCollapse( true );
6016             n = t15.getNode( "ab" );
6017             while ( n != null ) {
6018                 ext.add( n );
6019                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6020             }
6021             if ( ext.size() != 6 ) {
6022                 return false;
6023             }
6024             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6025                 return false;
6026             }
6027             if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6028                 return false;
6029             }
6030             if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6031                 return false;
6032             }
6033             if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6034                 return false;
6035             }
6036             if ( !ext.get( 4 ).getName().equals( "x" ) ) {
6037                 return false;
6038             }
6039             if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6040                 return false;
6041             }
6042             //
6043             //
6044             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" );
6045             final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
6046             ext.clear();
6047             t16.getNode( "ab" ).setCollapse( true );
6048             t16.getNode( "a" ).setCollapse( true );
6049             t16.getNode( "fgh" ).setCollapse( true );
6050             t16.getNode( "gh" ).setCollapse( true );
6051             t16.getNode( "cd" ).setCollapse( true );
6052             t16.getNode( "cde" ).setCollapse( true );
6053             t16.getNode( "d" ).setCollapse( true );
6054             t16.getNode( "x" ).setCollapse( true );
6055             n = t16.getNode( "ab" );
6056             while ( n != null ) {
6057                 ext.add( n );
6058                 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6059             }
6060             if ( ext.size() != 4 ) {
6061                 return false;
6062             }
6063             if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6064                 return false;
6065             }
6066             if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6067                 return false;
6068             }
6069             if ( !ext.get( 2 ).getName().equals( "x" ) ) {
6070                 return false;
6071             }
6072             if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
6073                 return false;
6074             }
6075         }
6076         catch ( final Exception e ) {
6077             e.printStackTrace( System.out );
6078             return false;
6079         }
6080         return true;
6081     }
6082
6083     private static boolean testNexusCharactersParsing() {
6084         try {
6085             final NexusCharactersParser parser = new NexusCharactersParser();
6086             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
6087             parser.parse();
6088             String[] labels = parser.getCharStateLabels();
6089             if ( labels.length != 7 ) {
6090                 return false;
6091             }
6092             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6093                 return false;
6094             }
6095             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6096                 return false;
6097             }
6098             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6099                 return false;
6100             }
6101             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6102                 return false;
6103             }
6104             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6105                 return false;
6106             }
6107             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6108                 return false;
6109             }
6110             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6111                 return false;
6112             }
6113             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6114             parser.parse();
6115             labels = parser.getCharStateLabels();
6116             if ( labels.length != 7 ) {
6117                 return false;
6118             }
6119             if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6120                 return false;
6121             }
6122             if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6123                 return false;
6124             }
6125             if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6126                 return false;
6127             }
6128             if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6129                 return false;
6130             }
6131             if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6132                 return false;
6133             }
6134             if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6135                 return false;
6136             }
6137             if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6138                 return false;
6139             }
6140         }
6141         catch ( final Exception e ) {
6142             e.printStackTrace( System.out );
6143             return false;
6144         }
6145         return true;
6146     }
6147
6148     private static boolean testNexusMatrixParsing() {
6149         try {
6150             final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
6151             parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
6152             parser.parse();
6153             final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
6154             if ( m.getNumberOfCharacters() != 9 ) {
6155                 return false;
6156             }
6157             if ( m.getNumberOfIdentifiers() != 5 ) {
6158                 return false;
6159             }
6160             if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
6161                 return false;
6162             }
6163             if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
6164                 return false;
6165             }
6166             if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
6167                 return false;
6168             }
6169             if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
6170                 return false;
6171             }
6172             if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
6173                 return false;
6174             }
6175             if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
6176                 return false;
6177             }
6178             if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
6179                 return false;
6180             }
6181             //            if ( labels.length != 7 ) {
6182             //                return false;
6183             //            }
6184             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6185             //                return false;
6186             //            }
6187             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6188             //                return false;
6189             //            }
6190             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6191             //                return false;
6192             //            }
6193             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6194             //                return false;
6195             //            }
6196             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6197             //                return false;
6198             //            }
6199             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6200             //                return false;
6201             //            }
6202             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6203             //                return false;
6204             //            }
6205             //            parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6206             //            parser.parse();
6207             //            labels = parser.getCharStateLabels();
6208             //            if ( labels.length != 7 ) {
6209             //                return false;
6210             //            }
6211             //            if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6212             //                return false;
6213             //            }
6214             //            if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6215             //                return false;
6216             //            }
6217             //            if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6218             //                return false;
6219             //            }
6220             //            if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6221             //                return false;
6222             //            }
6223             //            if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6224             //                return false;
6225             //            }
6226             //            if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6227             //                return false;
6228             //            }
6229             //            if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6230             //                return false;
6231             //            }
6232         }
6233         catch ( final Exception e ) {
6234             e.printStackTrace( System.out );
6235             return false;
6236         }
6237         return true;
6238     }
6239
6240     private static boolean testNexusTreeParsing() {
6241         try {
6242             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6243             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
6244             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
6245             if ( phylogenies.length != 1 ) {
6246                 return false;
6247             }
6248             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
6249                 return false;
6250             }
6251             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6252                 return false;
6253             }
6254             phylogenies = null;
6255             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
6256             if ( phylogenies.length != 1 ) {
6257                 return false;
6258             }
6259             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6260                 return false;
6261             }
6262             if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
6263                 return false;
6264             }
6265             phylogenies = null;
6266             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
6267             if ( phylogenies.length != 1 ) {
6268                 return false;
6269             }
6270             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6271                 return false;
6272             }
6273             if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6274                 return false;
6275             }
6276             if ( phylogenies[ 0 ].isRooted() ) {
6277                 return false;
6278             }
6279             phylogenies = null;
6280             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
6281             if ( phylogenies.length != 18 ) {
6282                 return false;
6283             }
6284             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6285                 return false;
6286             }
6287             if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
6288                 return false;
6289             }
6290             if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
6291                 return false;
6292             }
6293             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
6294                 return false;
6295             }
6296             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6297                 return false;
6298             }
6299             if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
6300                 return false;
6301             }
6302             if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
6303                 return false;
6304             }
6305             if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
6306                 return false;
6307             }
6308             if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
6309                 return false;
6310             }
6311             if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
6312                 return false;
6313             }
6314             if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
6315                 return false;
6316             }
6317             if ( phylogenies[ 8 ].isRooted() ) {
6318                 return false;
6319             }
6320             if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
6321                 return false;
6322             }
6323             if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
6324                 return false;
6325             }
6326             if ( !phylogenies[ 9 ].isRooted() ) {
6327                 return false;
6328             }
6329             if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
6330                 return false;
6331             }
6332             if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
6333                 return false;
6334             }
6335             if ( !phylogenies[ 10 ].isRooted() ) {
6336                 return false;
6337             }
6338             if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
6339                 return false;
6340             }
6341             if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
6342                 return false;
6343             }
6344             if ( phylogenies[ 11 ].isRooted() ) {
6345                 return false;
6346             }
6347             if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
6348                 return false;
6349             }
6350             if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
6351                 return false;
6352             }
6353             if ( !phylogenies[ 12 ].isRooted() ) {
6354                 return false;
6355             }
6356             if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
6357                 return false;
6358             }
6359             if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
6360                 return false;
6361             }
6362             if ( !phylogenies[ 13 ].isRooted() ) {
6363                 return false;
6364             }
6365             if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
6366                 return false;
6367             }
6368             if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
6369                 return false;
6370             }
6371             if ( !phylogenies[ 14 ].isRooted() ) {
6372                 return false;
6373             }
6374             if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
6375                 return false;
6376             }
6377             if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
6378                 return false;
6379             }
6380             if ( phylogenies[ 15 ].isRooted() ) {
6381                 return false;
6382             }
6383             if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
6384                 return false;
6385             }
6386             if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
6387                 return false;
6388             }
6389             if ( !phylogenies[ 16 ].isRooted() ) {
6390                 return false;
6391             }
6392             if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
6393                 return false;
6394             }
6395             if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
6396                 return false;
6397             }
6398             if ( phylogenies[ 17 ].isRooted() ) {
6399                 return false;
6400             }
6401             if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
6402                 return false;
6403             }
6404         }
6405         catch ( final Exception e ) {
6406             e.printStackTrace( System.out );
6407             return false;
6408         }
6409         return true;
6410     }
6411
6412     private static boolean testNexusTreeParsingIterating() {
6413         try {
6414             final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
6415             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
6416             if ( !p.hasNext() ) {
6417                 return false;
6418             }
6419             Phylogeny phy = p.next();
6420             if ( phy == null ) {
6421                 return false;
6422             }
6423             if ( phy.getNumberOfExternalNodes() != 25 ) {
6424                 return false;
6425             }
6426             if ( !phy.getName().equals( "" ) ) {
6427                 return false;
6428             }
6429             if ( p.hasNext() ) {
6430                 return false;
6431             }
6432             phy = p.next();
6433             if ( phy != null ) {
6434                 return false;
6435             }
6436             //
6437             p.reset();
6438             if ( !p.hasNext() ) {
6439                 return false;
6440             }
6441             phy = p.next();
6442             if ( phy == null ) {
6443                 return false;
6444             }
6445             if ( phy.getNumberOfExternalNodes() != 25 ) {
6446                 return false;
6447             }
6448             if ( !phy.getName().equals( "" ) ) {
6449                 return false;
6450             }
6451             if ( p.hasNext() ) {
6452                 return false;
6453             }
6454             phy = p.next();
6455             if ( phy != null ) {
6456                 return false;
6457             }
6458             ////
6459             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
6460             if ( !p.hasNext() ) {
6461                 return false;
6462             }
6463             phy = p.next();
6464             if ( phy == null ) {
6465                 return false;
6466             }
6467             if ( phy.getNumberOfExternalNodes() != 10 ) {
6468                 return false;
6469             }
6470             if ( !phy.getName().equals( "name" ) ) {
6471                 return false;
6472             }
6473             if ( p.hasNext() ) {
6474                 return false;
6475             }
6476             phy = p.next();
6477             if ( phy != null ) {
6478                 return false;
6479             }
6480             //
6481             p.reset();
6482             if ( !p.hasNext() ) {
6483                 return false;
6484             }
6485             phy = p.next();
6486             if ( phy == null ) {
6487                 return false;
6488             }
6489             if ( phy.getNumberOfExternalNodes() != 10 ) {
6490                 return false;
6491             }
6492             if ( !phy.getName().equals( "name" ) ) {
6493                 return false;
6494             }
6495             if ( p.hasNext() ) {
6496                 return false;
6497             }
6498             phy = p.next();
6499             if ( phy != null ) {
6500                 return false;
6501             }
6502             ////
6503             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
6504             if ( !p.hasNext() ) {
6505                 return false;
6506             }
6507             phy = p.next();
6508             if ( phy == null ) {
6509                 return false;
6510             }
6511             if ( phy.getNumberOfExternalNodes() != 3 ) {
6512                 return false;
6513             }
6514             if ( !phy.getName().equals( "" ) ) {
6515                 return false;
6516             }
6517             if ( phy.isRooted() ) {
6518                 return false;
6519             }
6520             if ( p.hasNext() ) {
6521                 return false;
6522             }
6523             phy = p.next();
6524             if ( phy != null ) {
6525                 return false;
6526             }
6527             //
6528             p.reset();
6529             if ( !p.hasNext() ) {
6530                 return false;
6531             }
6532             phy = p.next();
6533             if ( phy == null ) {
6534                 return false;
6535             }
6536             if ( phy.getNumberOfExternalNodes() != 3 ) {
6537                 return false;
6538             }
6539             if ( !phy.getName().equals( "" ) ) {
6540                 return false;
6541             }
6542             if ( p.hasNext() ) {
6543                 return false;
6544             }
6545             phy = p.next();
6546             if ( phy != null ) {
6547                 return false;
6548             }
6549             ////
6550             p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
6551             //            if ( phylogenies.length != 18 ) {
6552             //                return false;
6553             //            }
6554             //0
6555             if ( !p.hasNext() ) {
6556                 return false;
6557             }
6558             phy = p.next();
6559             if ( phy == null ) {
6560                 return false;
6561             }
6562             if ( phy.getNumberOfExternalNodes() != 10 ) {
6563                 return false;
6564             }
6565             if ( !phy.getName().equals( "tree 0" ) ) {
6566                 return false;
6567             }
6568             //1
6569             if ( !p.hasNext() ) {
6570                 return false;
6571             }
6572             phy = p.next();
6573             if ( phy == null ) {
6574                 return false;
6575             }
6576             if ( phy.getNumberOfExternalNodes() != 10 ) {
6577                 return false;
6578             }
6579             if ( !phy.getName().equals( "tree 1" ) ) {
6580                 return false;
6581             }
6582             //2
6583             if ( !p.hasNext() ) {
6584                 return false;
6585             }
6586             phy = p.next();
6587             if ( phy == null ) {
6588                 return false;
6589             }
6590             if ( phy.getNumberOfExternalNodes() != 3 ) {
6591                 return false;
6592             }
6593             if ( !phy.getName().equals( "" ) ) {
6594                 return false;
6595             }
6596             if ( phy.isRooted() ) {
6597                 return false;
6598             }
6599             //3
6600             if ( !p.hasNext() ) {
6601                 return false;
6602             }
6603             phy = p.next();
6604             if ( phy == null ) {
6605                 return false;
6606             }
6607             if ( phy.getNumberOfExternalNodes() != 4 ) {
6608                 return false;
6609             }
6610             if ( !phy.getName().equals( "" ) ) {
6611                 return false;
6612             }
6613             if ( !phy.isRooted() ) {
6614                 return false;
6615             }
6616             //4
6617             if ( !p.hasNext() ) {
6618                 return false;
6619             }
6620             phy = p.next();
6621             if ( phy == null ) {
6622                 return false;
6623             }
6624             if ( phy.getNumberOfExternalNodes() != 5 ) {
6625                 System.out.println( phy.getNumberOfExternalNodes() );
6626                 return false;
6627             }
6628             if ( !phy.getName().equals( "" ) ) {
6629                 return false;
6630             }
6631             if ( !phy.isRooted() ) {
6632                 return false;
6633             }
6634             //5
6635             if ( !p.hasNext() ) {
6636                 return false;
6637             }
6638             phy = p.next();
6639             if ( phy == null ) {
6640                 return false;
6641             }
6642             if ( phy.getNumberOfExternalNodes() != 3 ) {
6643                 return false;
6644             }
6645             if ( !phy.getName().equals( "" ) ) {
6646                 return false;
6647             }
6648             if ( phy.isRooted() ) {
6649                 return false;
6650             }
6651             //6
6652             if ( !p.hasNext() ) {
6653                 return false;
6654             }
6655             phy = p.next();
6656             if ( phy == null ) {
6657                 return false;
6658             }
6659             if ( phy.getNumberOfExternalNodes() != 2 ) {
6660                 return false;
6661             }
6662             if ( !phy.getName().equals( "" ) ) {
6663                 return false;
6664             }
6665             if ( !phy.isRooted() ) {
6666                 return false;
6667             }
6668             //7
6669             if ( !p.hasNext() ) {
6670                 return false;
6671             }
6672             phy = p.next();
6673             if ( phy.getNumberOfExternalNodes() != 3 ) {
6674                 return false;
6675             }
6676             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6677                 return false;
6678             }
6679             if ( !phy.isRooted() ) {
6680                 return false;
6681             }
6682             //8
6683             if ( !p.hasNext() ) {
6684                 return false;
6685             }
6686             phy = p.next();
6687             if ( phy.getNumberOfExternalNodes() != 3 ) {
6688                 return false;
6689             }
6690             if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
6691                 return false;
6692             }
6693             if ( !phy.getName().equals( "tree 8" ) ) {
6694                 return false;
6695             }
6696             //9
6697             if ( !p.hasNext() ) {
6698                 return false;
6699             }
6700             phy = p.next();
6701             if ( phy.getNumberOfExternalNodes() != 3 ) {
6702                 return false;
6703             }
6704             if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
6705                 return false;
6706             }
6707             if ( !phy.getName().equals( "tree 9" ) ) {
6708                 return false;
6709             }
6710             //10
6711             if ( !p.hasNext() ) {
6712                 return false;
6713             }
6714             phy = p.next();
6715             if ( phy.getNumberOfExternalNodes() != 3 ) {
6716                 return false;
6717             }
6718             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6719                 return false;
6720             }
6721             if ( !phy.getName().equals( "tree 10" ) ) {
6722                 return false;
6723             }
6724             if ( !phy.isRooted() ) {
6725                 return false;
6726             }
6727             //11
6728             if ( !p.hasNext() ) {
6729                 return false;
6730             }
6731             phy = p.next();
6732             if ( phy.getNumberOfExternalNodes() != 3 ) {
6733                 return false;
6734             }
6735             if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
6736                 return false;
6737             }
6738             if ( !phy.getName().equals( "tree 11" ) ) {
6739                 return false;
6740             }
6741             if ( phy.isRooted() ) {
6742                 return false;
6743             }
6744             //12
6745             if ( !p.hasNext() ) {
6746                 return false;
6747             }
6748             phy = p.next();
6749             if ( phy.getNumberOfExternalNodes() != 3 ) {
6750                 return false;
6751             }
6752             if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
6753                 return false;
6754             }
6755             if ( !phy.getName().equals( "tree 12" ) ) {
6756                 return false;
6757             }
6758             if ( !phy.isRooted() ) {
6759                 return false;
6760             }
6761             //13
6762             if ( !p.hasNext() ) {
6763                 return false;
6764             }
6765             phy = p.next();
6766             if ( phy.getNumberOfExternalNodes() != 3 ) {
6767                 return false;
6768             }
6769             if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6770                 return false;
6771             }
6772             if ( !phy.getName().equals( "tree 13" ) ) {
6773                 return false;
6774             }
6775             if ( !phy.isRooted() ) {
6776                 return false;
6777             }
6778             //14
6779             if ( !p.hasNext() ) {
6780                 return false;
6781             }
6782             phy = p.next();
6783             if ( phy.getNumberOfExternalNodes() != 10 ) {
6784                 System.out.println( phy.getNumberOfExternalNodes() );
6785                 return false;
6786             }
6787             if ( !phy
6788                     .toNewHampshire()
6789                     .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;" ) ) {
6790                 System.out.println( phy.toNewHampshire() );
6791                 return false;
6792             }
6793             if ( !phy.getName().equals( "tree 14" ) ) {
6794                 return false;
6795             }
6796             if ( !phy.isRooted() ) {
6797                 return false;
6798             }
6799             //15
6800             if ( !p.hasNext() ) {
6801                 return false;
6802             }
6803             phy = p.next();
6804             if ( phy.getNumberOfExternalNodes() != 10 ) {
6805                 System.out.println( phy.getNumberOfExternalNodes() );
6806                 return false;
6807             }
6808             if ( !phy
6809                     .toNewHampshire()
6810                     .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;" ) ) {
6811                 System.out.println( phy.toNewHampshire() );
6812                 return false;
6813             }
6814             if ( !phy.getName().equals( "tree 15" ) ) {
6815                 return false;
6816             }
6817             if ( phy.isRooted() ) {
6818                 return false;
6819             }
6820             //16
6821             if ( !p.hasNext() ) {
6822                 return false;
6823             }
6824             phy = p.next();
6825             if ( phy.getNumberOfExternalNodes() != 10 ) {
6826                 System.out.println( phy.getNumberOfExternalNodes() );
6827                 return false;
6828             }
6829             if ( !phy
6830                     .toNewHampshire()
6831                     .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;" ) ) {
6832                 System.out.println( phy.toNewHampshire() );
6833                 return false;
6834             }
6835             if ( !phy.getName().equals( "tree 16" ) ) {
6836                 return false;
6837             }
6838             if ( !phy.isRooted() ) {
6839                 return false;
6840             }
6841             //17
6842             if ( !p.hasNext() ) {
6843                 return false;
6844             }
6845             phy = p.next();
6846             if ( phy.getNumberOfExternalNodes() != 10 ) {
6847                 System.out.println( phy.getNumberOfExternalNodes() );
6848                 return false;
6849             }
6850             if ( !phy
6851                     .toNewHampshire()
6852                     .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;" ) ) {
6853                 System.out.println( phy.toNewHampshire() );
6854                 return false;
6855             }
6856             if ( !phy.getName().equals( "tree 17" ) ) {
6857                 return false;
6858             }
6859             if ( phy.isRooted() ) {
6860                 return false;
6861             }
6862             //
6863             if ( p.hasNext() ) {
6864                 return false;
6865             }
6866             phy = p.next();
6867             if ( phy != null ) {
6868                 return false;
6869             }
6870             p.reset();
6871             //0
6872             if ( !p.hasNext() ) {
6873                 return false;
6874             }
6875             phy = p.next();
6876             if ( phy == null ) {
6877                 return false;
6878             }
6879             if ( phy.getNumberOfExternalNodes() != 10 ) {
6880                 return false;
6881             }
6882             if ( !phy.getName().equals( "tree 0" ) ) {
6883                 return false;
6884             }
6885             //1
6886             if ( !p.hasNext() ) {
6887                 return false;
6888             }
6889             phy = p.next();
6890             if ( phy == null ) {
6891                 return false;
6892             }
6893             if ( phy.getNumberOfExternalNodes() != 10 ) {
6894                 return false;
6895             }
6896             if ( !phy.getName().equals( "tree 1" ) ) {
6897                 return false;
6898             }
6899             //2
6900             if ( !p.hasNext() ) {
6901                 return false;
6902             }
6903             phy = p.next();
6904             if ( phy == null ) {
6905                 return false;
6906             }
6907             if ( phy.getNumberOfExternalNodes() != 3 ) {
6908                 return false;
6909             }
6910             if ( !phy.getName().equals( "" ) ) {
6911                 return false;
6912             }
6913             if ( phy.isRooted() ) {
6914                 return false;
6915             }
6916             //3
6917             if ( !p.hasNext() ) {
6918                 return false;
6919             }
6920             phy = p.next();
6921             if ( phy == null ) {
6922                 return false;
6923             }
6924             if ( phy.getNumberOfExternalNodes() != 4 ) {
6925                 return false;
6926             }
6927             if ( !phy.getName().equals( "" ) ) {
6928                 return false;
6929             }
6930             if ( !phy.isRooted() ) {
6931                 return false;
6932             }
6933             //4
6934             if ( !p.hasNext() ) {
6935                 return false;
6936             }
6937             phy = p.next();
6938             if ( phy == null ) {
6939                 return false;
6940             }
6941             if ( phy.getNumberOfExternalNodes() != 5 ) {
6942                 System.out.println( phy.getNumberOfExternalNodes() );
6943                 return false;
6944             }
6945             if ( !phy.getName().equals( "" ) ) {
6946                 return false;
6947             }
6948             if ( !phy.isRooted() ) {
6949                 return false;
6950             }
6951             //5
6952             if ( !p.hasNext() ) {
6953                 return false;
6954             }
6955             phy = p.next();
6956             if ( phy == null ) {
6957                 return false;
6958             }
6959             if ( phy.getNumberOfExternalNodes() != 3 ) {
6960                 return false;
6961             }
6962             if ( !phy.getName().equals( "" ) ) {
6963                 return false;
6964             }
6965             if ( phy.isRooted() ) {
6966                 return false;
6967             }
6968         }
6969         catch ( final Exception e ) {
6970             e.printStackTrace( System.out );
6971             return false;
6972         }
6973         return true;
6974     }
6975
6976     private static boolean testNexusTreeParsingTranslating() {
6977         try {
6978             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6979             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
6980             Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
6981             if ( phylogenies.length != 1 ) {
6982                 return false;
6983             }
6984             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6985                 return false;
6986             }
6987             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
6988                 return false;
6989             }
6990             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6991                 return false;
6992             }
6993             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6994                 return false;
6995             }
6996             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6997                     .equals( "Aranaeus" ) ) {
6998                 return false;
6999             }
7000             phylogenies = null;
7001             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
7002             if ( phylogenies.length != 3 ) {
7003                 return false;
7004             }
7005             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7006                 return false;
7007             }
7008             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7009                 return false;
7010             }
7011             if ( phylogenies[ 0 ].isRooted() ) {
7012                 return false;
7013             }
7014             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7015                 return false;
7016             }
7017             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7018                 return false;
7019             }
7020             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7021                     .equals( "Aranaeus" ) ) {
7022                 return false;
7023             }
7024             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7025                 return false;
7026             }
7027             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7028                 return false;
7029             }
7030             if ( phylogenies[ 1 ].isRooted() ) {
7031                 return false;
7032             }
7033             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7034                 return false;
7035             }
7036             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7037                 return false;
7038             }
7039             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7040                     .equals( "Aranaeus" ) ) {
7041                 return false;
7042             }
7043             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7044                 return false;
7045             }
7046             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7047                 return false;
7048             }
7049             if ( !phylogenies[ 2 ].isRooted() ) {
7050                 return false;
7051             }
7052             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7053                 return false;
7054             }
7055             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7056                 return false;
7057             }
7058             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7059                     .equals( "Aranaeus" ) ) {
7060                 return false;
7061             }
7062             phylogenies = null;
7063             phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
7064             if ( phylogenies.length != 3 ) {
7065                 return false;
7066             }
7067             if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7068                 return false;
7069             }
7070             if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
7071                 return false;
7072             }
7073             if ( phylogenies[ 0 ].isRooted() ) {
7074                 return false;
7075             }
7076             if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7077                 return false;
7078             }
7079             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7080                 return false;
7081             }
7082             if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7083                     .equals( "Aranaeus" ) ) {
7084                 return false;
7085             }
7086             if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
7087                 return false;
7088             }
7089             if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
7090                 return false;
7091             }
7092             if ( phylogenies[ 1 ].isRooted() ) {
7093                 return false;
7094             }
7095             if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7096                 return false;
7097             }
7098             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7099                 return false;
7100             }
7101             if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7102                     .equals( "Aranaeus" ) ) {
7103                 return false;
7104             }
7105             if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7106                 return false;
7107             }
7108             if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
7109                 return false;
7110             }
7111             if ( !phylogenies[ 2 ].isRooted() ) {
7112                 return false;
7113             }
7114             if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
7115                 return false;
7116             }
7117             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
7118                 return false;
7119             }
7120             if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
7121                     .equals( "Aranaeus" ) ) {
7122                 return false;
7123             }
7124         }
7125         catch ( final Exception e ) {
7126             e.printStackTrace( System.out );
7127             return false;
7128         }
7129         return true;
7130     }
7131
7132     private static boolean testNHParsing() {
7133         try {
7134             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7135             final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
7136             if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
7137                 return false;
7138             }
7139             final NHXParser nhxp = new NHXParser();
7140             nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
7141             nhxp.setReplaceUnderscores( true );
7142             final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
7143             if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
7144                 return false;
7145             }
7146             if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
7147                 return false;
7148             }
7149             final Phylogeny p1b = factory
7150                     .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 ",
7151                              new NHXParser() )[ 0 ];
7152             if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
7153                 return false;
7154             }
7155             if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
7156                 return false;
7157             }
7158             final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
7159             final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
7160             final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
7161             final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
7162             final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
7163             final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
7164             final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
7165             final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
7166             final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
7167             final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
7168             final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1  3 ; \n)\t ( \n ;"
7169                                                             + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
7170                                                             + "; ; ( \t\n\r\b; G ;, ;H ;1 3; )  ;  ;   ;",
7171                                                     new NHXParser() );
7172             if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
7173                 return false;
7174             }
7175             if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
7176                 return false;
7177             }
7178             if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
7179                 return false;
7180             }
7181             if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
7182                 return false;
7183             }
7184             final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
7185             final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
7186             final String p16_S = "((A,B),C)";
7187             final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
7188             if ( p16.length != 1 ) {
7189                 return false;
7190             }
7191             if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
7192                 return false;
7193             }
7194             final String p17_S = "(C,(A,B))";
7195             final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
7196             if ( p17.length != 1 ) {
7197                 return false;
7198             }
7199             if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
7200                 return false;
7201             }
7202             final String p18_S = "((A,B),(C,D))";
7203             final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
7204             if ( p18.length != 1 ) {
7205                 return false;
7206             }
7207             if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
7208                 return false;
7209             }
7210             final String p19_S = "(((A,B),C),D)";
7211             final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
7212             if ( p19.length != 1 ) {
7213                 return false;
7214             }
7215             if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
7216                 return false;
7217             }
7218             final String p20_S = "(A,(B,(C,D)))";
7219             final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
7220             if ( p20.length != 1 ) {
7221                 return false;
7222             }
7223             if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
7224                 return false;
7225             }
7226             final String p21_S = "(A,(B,(C,(D,E))))";
7227             final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
7228             if ( p21.length != 1 ) {
7229                 return false;
7230             }
7231             if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
7232                 return false;
7233             }
7234             final String p22_S = "((((A,B),C),D),E)";
7235             final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
7236             if ( p22.length != 1 ) {
7237                 return false;
7238             }
7239             if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
7240                 return false;
7241             }
7242             final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7243             final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
7244             if ( p23.length != 1 ) {
7245                 System.out.println( "xl=" + p23.length );
7246                 System.exit( -1 );
7247                 return false;
7248             }
7249             if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
7250                 return false;
7251             }
7252             final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7253             final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
7254             if ( p24.length != 1 ) {
7255                 return false;
7256             }
7257             if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
7258                 return false;
7259             }
7260             final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7261             final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7262             final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
7263             if ( p241.length != 2 ) {
7264                 return false;
7265             }
7266             if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
7267                 return false;
7268             }
7269             if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
7270                 return false;
7271             }
7272             final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
7273                     + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
7274                     + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
7275                     + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
7276                     + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
7277                     + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
7278                     + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
7279                     + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
7280             final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
7281             if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
7282                 return false;
7283             }
7284             final String p26_S = "(A,B)ab";
7285             final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
7286             if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
7287                 return false;
7288             }
7289             final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7290             final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
7291             if ( p27s.length != 1 ) {
7292                 System.out.println( "xxl=" + p27s.length );
7293                 System.exit( -1 );
7294                 return false;
7295             }
7296             if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
7297                 System.out.println( p27s[ 0 ].toNewHampshireX() );
7298                 System.exit( -1 );
7299                 return false;
7300             }
7301             final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
7302                                                     new NHXParser() );
7303             if ( p27.length != 1 ) {
7304                 System.out.println( "yl=" + p27.length );
7305                 System.exit( -1 );
7306                 return false;
7307             }
7308             if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
7309                 System.out.println( p27[ 0 ].toNewHampshireX() );
7310                 System.exit( -1 );
7311                 return false;
7312             }
7313             final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7314             final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7315             final String p28_S3 = "(A,B)ab";
7316             final String p28_S4 = "((((A,B),C),D),;E;)";
7317             final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
7318                                                     new NHXParser() );
7319             if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
7320                 return false;
7321             }
7322             if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
7323                 return false;
7324             }
7325             if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
7326                 return false;
7327             }
7328             if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
7329                 return false;
7330             }
7331             if ( p28.length != 4 ) {
7332                 return false;
7333             }
7334             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";
7335             final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
7336             if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
7337                 return false;
7338             }
7339             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";
7340             final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
7341             if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
7342                 return false;
7343             }
7344             final String p32_S = " ;   ;        \n  \t  \b   \f  \r  ;;;;;; ";
7345             final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
7346             if ( ( p32.length != 0 ) ) {
7347                 return false;
7348             }
7349             final String p33_S = "A";
7350             final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
7351             if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
7352                 return false;
7353             }
7354             final String p34_S = "B;";
7355             final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
7356             if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
7357                 return false;
7358             }
7359             final String p35_S = "B:0.2";
7360             final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
7361             if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
7362                 return false;
7363             }
7364             final String p36_S = "(A)";
7365             final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
7366             if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
7367                 return false;
7368             }
7369             final String p37_S = "((A))";
7370             final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
7371             if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
7372                 return false;
7373             }
7374             final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
7375             final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
7376             if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
7377                 return false;
7378             }
7379             final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
7380             final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
7381             if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
7382                 return false;
7383             }
7384             final String p40_S = "(A,B,C)";
7385             final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
7386             if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
7387                 return false;
7388             }
7389             final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
7390             final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
7391             if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
7392                 return false;
7393             }
7394             final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
7395             final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
7396             if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
7397                 return false;
7398             }
7399             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)";
7400             final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
7401             if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
7402                 return false;
7403             }
7404             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)))";
7405             final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
7406             if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
7407                 return false;
7408             }
7409             final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
7410             final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
7411             if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
7412                 return false;
7413             }
7414             final String p46_S = "";
7415             final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
7416             if ( p46.length != 0 ) {
7417                 return false;
7418             }
7419             final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
7420             if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7421                 return false;
7422             }
7423             final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7424             if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7425                 return false;
7426             }
7427             final Phylogeny p49 = factory
7428                     .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
7429                              new NHXParser() )[ 0 ];
7430             if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7431                 return false;
7432             }
7433             final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7434             if ( p50.getNode( "A" ) == null ) {
7435                 return false;
7436             }
7437             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7438                     .equals( "((A,B)ab:2.0[88],C);" ) ) {
7439                 return false;
7440             }
7441             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
7442                 return false;
7443             }
7444             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
7445                     .equals( "((A,B)88:2.0,C);" ) ) {
7446                 return false;
7447             }
7448             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7449             if ( p51.getNode( "A(A" ) == null ) {
7450                 return false;
7451             }
7452             final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7453             if ( p52.getNode( "A(A" ) == null ) {
7454                 return false;
7455             }
7456             final Phylogeny p53 = factory
7457                     .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
7458                              new NHXParser() )[ 0 ];
7459             if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
7460                 return false;
7461             }
7462             // 
7463             final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
7464             if ( p54.getNode( "A" ) == null ) {
7465                 return false;
7466             }
7467             if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7468                     .equals( "((A,B)[88],C);" ) ) {
7469                 return false;
7470             }
7471         }
7472         catch ( final Exception e ) {
7473             e.printStackTrace( System.out );
7474             return false;
7475         }
7476         return true;
7477     }
7478
7479     private static boolean testNHParsingIter() {
7480         try {
7481             final String p0_str = "(A,B);";
7482             final NHXParser p = new NHXParser();
7483             p.setSource( p0_str );
7484             if ( !p.hasNext() ) {
7485                 return false;
7486             }
7487             final Phylogeny p0 = p.next();
7488             if ( !p0.toNewHampshire().equals( p0_str ) ) {
7489                 System.out.println( p0.toNewHampshire() );
7490                 return false;
7491             }
7492             if ( p.hasNext() ) {
7493                 return false;
7494             }
7495             if ( p.next() != null ) {
7496                 return false;
7497             }
7498             //
7499             final String p00_str = "(A,B)root;";
7500             p.setSource( p00_str );
7501             final Phylogeny p00 = p.next();
7502             if ( !p00.toNewHampshire().equals( p00_str ) ) {
7503                 System.out.println( p00.toNewHampshire() );
7504                 return false;
7505             }
7506             //
7507             final String p000_str = "A;";
7508             p.setSource( p000_str );
7509             final Phylogeny p000 = p.next();
7510             if ( !p000.toNewHampshire().equals( p000_str ) ) {
7511                 System.out.println( p000.toNewHampshire() );
7512                 return false;
7513             }
7514             //
7515             final String p0000_str = "A";
7516             p.setSource( p0000_str );
7517             final Phylogeny p0000 = p.next();
7518             if ( !p0000.toNewHampshire().equals( "A;" ) ) {
7519                 System.out.println( p0000.toNewHampshire() );
7520                 return false;
7521             }
7522             //
7523             p.setSource( "(A)" );
7524             final Phylogeny p00000 = p.next();
7525             if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
7526                 System.out.println( p00000.toNewHampshire() );
7527                 return false;
7528             }
7529             //
7530             final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
7531             p.setSource( p1_str );
7532             if ( !p.hasNext() ) {
7533                 return false;
7534             }
7535             final Phylogeny p1_0 = p.next();
7536             if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
7537                 System.out.println( p1_0.toNewHampshire() );
7538                 return false;
7539             }
7540             if ( !p.hasNext() ) {
7541                 return false;
7542             }
7543             final Phylogeny p1_1 = p.next();
7544             if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
7545                 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
7546                 return false;
7547             }
7548             if ( !p.hasNext() ) {
7549                 return false;
7550             }
7551             final Phylogeny p1_2 = p.next();
7552             if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
7553                 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
7554                 return false;
7555             }
7556             if ( !p.hasNext() ) {
7557                 return false;
7558             }
7559             final Phylogeny p1_3 = p.next();
7560             if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
7561                 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
7562                 return false;
7563             }
7564             if ( p.hasNext() ) {
7565                 return false;
7566             }
7567             if ( p.next() != null ) {
7568                 return false;
7569             }
7570             //
7571             final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
7572             p.setSource( p2_str );
7573             if ( !p.hasNext() ) {
7574                 return false;
7575             }
7576             Phylogeny p2_0 = p.next();
7577             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
7578                 System.out.println( p2_0.toNewHampshire() );
7579                 return false;
7580             }
7581             if ( !p.hasNext() ) {
7582                 return false;
7583             }
7584             Phylogeny p2_1 = p.next();
7585             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
7586                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
7587                 return false;
7588             }
7589             if ( !p.hasNext() ) {
7590                 return false;
7591             }
7592             Phylogeny p2_2 = p.next();
7593             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
7594                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
7595                 return false;
7596             }
7597             if ( !p.hasNext() ) {
7598                 return false;
7599             }
7600             Phylogeny p2_3 = p.next();
7601             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
7602                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
7603                 return false;
7604             }
7605             if ( !p.hasNext() ) {
7606                 return false;
7607             }
7608             Phylogeny p2_4 = p.next();
7609             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
7610                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
7611                 return false;
7612             }
7613             if ( p.hasNext() ) {
7614                 return false;
7615             }
7616             if ( p.next() != null ) {
7617                 return false;
7618             }
7619             ////
7620             p.reset();
7621             if ( !p.hasNext() ) {
7622                 return false;
7623             }
7624             p2_0 = p.next();
7625             if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
7626                 System.out.println( p2_0.toNewHampshire() );
7627                 return false;
7628             }
7629             if ( !p.hasNext() ) {
7630                 return false;
7631             }
7632             p2_1 = p.next();
7633             if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
7634                 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
7635                 return false;
7636             }
7637             if ( !p.hasNext() ) {
7638                 return false;
7639             }
7640             p2_2 = p.next();
7641             if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
7642                 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
7643                 return false;
7644             }
7645             if ( !p.hasNext() ) {
7646                 return false;
7647             }
7648             p2_3 = p.next();
7649             if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
7650                 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
7651                 return false;
7652             }
7653             if ( !p.hasNext() ) {
7654                 return false;
7655             }
7656             p2_4 = p.next();
7657             if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
7658                 System.out.println( "(X) != " + p2_4.toNewHampshire() );
7659                 return false;
7660             }
7661             if ( p.hasNext() ) {
7662                 return false;
7663             }
7664             if ( p.next() != null ) {
7665                 return false;
7666             }
7667             //
7668             final String p3_str = "((A,B),C)abc";
7669             p.setSource( p3_str );
7670             if ( !p.hasNext() ) {
7671                 return false;
7672             }
7673             final Phylogeny p3_0 = p.next();
7674             if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
7675                 return false;
7676             }
7677             if ( p.hasNext() ) {
7678                 return false;
7679             }
7680             if ( p.next() != null ) {
7681                 return false;
7682             }
7683             //
7684             final String p4_str = "((A,B)ab,C)abc";
7685             p.setSource( p4_str );
7686             if ( !p.hasNext() ) {
7687                 return false;
7688             }
7689             final Phylogeny p4_0 = p.next();
7690             if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
7691                 return false;
7692             }
7693             if ( p.hasNext() ) {
7694                 return false;
7695             }
7696             if ( p.next() != null ) {
7697                 return false;
7698             }
7699             //
7700             final String p5_str = "(((A,B)ab,C)abc,D)abcd";
7701             p.setSource( p5_str );
7702             if ( !p.hasNext() ) {
7703                 return false;
7704             }
7705             final Phylogeny p5_0 = p.next();
7706             if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
7707                 return false;
7708             }
7709             if ( p.hasNext() ) {
7710                 return false;
7711             }
7712             if ( p.next() != null ) {
7713                 return false;
7714             }
7715             //
7716             final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7717             p.setSource( p6_str );
7718             if ( !p.hasNext() ) {
7719                 return false;
7720             }
7721             Phylogeny p6_0 = p.next();
7722             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
7723                 return false;
7724             }
7725             if ( p.hasNext() ) {
7726                 return false;
7727             }
7728             if ( p.next() != null ) {
7729                 return false;
7730             }
7731             p.reset();
7732             if ( !p.hasNext() ) {
7733                 return false;
7734             }
7735             p6_0 = p.next();
7736             if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
7737                 return false;
7738             }
7739             if ( p.hasNext() ) {
7740                 return false;
7741             }
7742             if ( p.next() != null ) {
7743                 return false;
7744             }
7745             //
7746             final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7747             p.setSource( p7_str );
7748             if ( !p.hasNext() ) {
7749                 return false;
7750             }
7751             Phylogeny p7_0 = p.next();
7752             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7753                 return false;
7754             }
7755             if ( p.hasNext() ) {
7756                 return false;
7757             }
7758             if ( p.next() != null ) {
7759                 return false;
7760             }
7761             p.reset();
7762             if ( !p.hasNext() ) {
7763                 return false;
7764             }
7765             p7_0 = p.next();
7766             if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7767                 return false;
7768             }
7769             if ( p.hasNext() ) {
7770                 return false;
7771             }
7772             if ( p.next() != null ) {
7773                 return false;
7774             }
7775             //
7776             final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
7777             p.setSource( p8_str );
7778             if ( !p.hasNext() ) {
7779                 return false;
7780             }
7781             Phylogeny p8_0 = p.next();
7782             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7783                 return false;
7784             }
7785             if ( !p.hasNext() ) {
7786                 return false;
7787             }
7788             if ( !p.hasNext() ) {
7789                 return false;
7790             }
7791             Phylogeny p8_1 = p.next();
7792             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
7793                 return false;
7794             }
7795             if ( p.hasNext() ) {
7796                 return false;
7797             }
7798             if ( p.next() != null ) {
7799                 return false;
7800             }
7801             p.reset();
7802             if ( !p.hasNext() ) {
7803                 return false;
7804             }
7805             p8_0 = p.next();
7806             if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7807                 return false;
7808             }
7809             if ( !p.hasNext() ) {
7810                 return false;
7811             }
7812             p8_1 = p.next();
7813             if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
7814                 return false;
7815             }
7816             if ( p.hasNext() ) {
7817                 return false;
7818             }
7819             if ( p.next() != null ) {
7820                 return false;
7821             }
7822             p.reset();
7823             //
7824             p.setSource( "" );
7825             if ( p.hasNext() ) {
7826                 return false;
7827             }
7828             //
7829             p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
7830             if ( !p.hasNext() ) {
7831                 return false;
7832             }
7833             Phylogeny p_27 = p.next();
7834             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
7835                 System.out.println( p_27.toNewHampshireX() );
7836                 System.exit( -1 );
7837                 return false;
7838             }
7839             if ( p.hasNext() ) {
7840                 return false;
7841             }
7842             if ( p.next() != null ) {
7843                 return false;
7844             }
7845             p.reset();
7846             if ( !p.hasNext() ) {
7847                 return false;
7848             }
7849             p_27 = p.next();
7850             if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
7851                 System.out.println( p_27.toNewHampshireX() );
7852                 System.exit( -1 );
7853                 return false;
7854             }
7855             if ( p.hasNext() ) {
7856                 return false;
7857             }
7858             if ( p.next() != null ) {
7859                 return false;
7860             }
7861             //
7862             final String p30_str = "(A,B);(C,D)";
7863             final NHXParser p30 = new NHXParser();
7864             p30.setSource( p30_str );
7865             if ( !p30.hasNext() ) {
7866                 return false;
7867             }
7868             Phylogeny phy30 = p30.next();
7869             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
7870                 System.out.println( phy30.toNewHampshire() );
7871                 return false;
7872             }
7873             if ( !p30.hasNext() ) {
7874                 return false;
7875             }
7876             Phylogeny phy301 = p30.next();
7877             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
7878                 System.out.println( phy301.toNewHampshire() );
7879                 return false;
7880             }
7881             if ( p30.hasNext() ) {
7882                 return false;
7883             }
7884             if ( p30.hasNext() ) {
7885                 return false;
7886             }
7887             if ( p30.next() != null ) {
7888                 return false;
7889             }
7890             if ( p30.next() != null ) {
7891                 return false;
7892             }
7893             p30.reset();
7894             if ( !p30.hasNext() ) {
7895                 return false;
7896             }
7897             phy30 = p30.next();
7898             if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
7899                 System.out.println( phy30.toNewHampshire() );
7900                 return false;
7901             }
7902             if ( !p30.hasNext() ) {
7903                 return false;
7904             }
7905             phy301 = p30.next();
7906             if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
7907                 System.out.println( phy301.toNewHampshire() );
7908                 return false;
7909             }
7910             if ( p30.hasNext() ) {
7911                 return false;
7912             }
7913             if ( p30.hasNext() ) {
7914                 return false;
7915             }
7916             if ( p30.next() != null ) {
7917                 return false;
7918             }
7919             if ( p30.next() != null ) {
7920                 return false;
7921             }
7922         }
7923         catch ( final Exception e ) {
7924             e.printStackTrace( System.out );
7925             return false;
7926         }
7927         return true;
7928     }
7929
7930     private static boolean testNHXconversion() {
7931         try {
7932             final PhylogenyNode n1 = new PhylogenyNode();
7933             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
7934             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
7935             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
7936             final PhylogenyNode n5 = PhylogenyNode
7937                     .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
7938             final PhylogenyNode n6 = PhylogenyNode
7939                     .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
7940             if ( !n1.toNewHampshireX().equals( "" ) ) {
7941                 return false;
7942             }
7943             if ( !n2.toNewHampshireX().equals( "" ) ) {
7944                 return false;
7945             }
7946             if ( !n3.toNewHampshireX().equals( "n3" ) ) {
7947                 return false;
7948             }
7949             if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
7950                 return false;
7951             }
7952             if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
7953                 return false;
7954             }
7955             if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
7956                 System.out.println( n6.toNewHampshireX() );
7957                 return false;
7958             }
7959         }
7960         catch ( final Exception e ) {
7961             e.printStackTrace( System.out );
7962             return false;
7963         }
7964         return true;
7965     }
7966
7967     private static boolean testNHXNodeParsing() {
7968         try {
7969             final PhylogenyNode n1 = new PhylogenyNode();
7970             final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
7971             final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
7972             final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
7973             final PhylogenyNode n5 = PhylogenyNode
7974                     .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]" );
7975             if ( !n3.getName().equals( "n3" ) ) {
7976                 return false;
7977             }
7978             if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
7979                 return false;
7980             }
7981             if ( n3.isDuplication() ) {
7982                 return false;
7983             }
7984             if ( n3.isHasAssignedEvent() ) {
7985                 return false;
7986             }
7987             if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
7988                 return false;
7989             }
7990             if ( !n4.getName().equals( "n4" ) ) {
7991                 return false;
7992             }
7993             if ( n4.getDistanceToParent() != 0.01 ) {
7994                 return false;
7995             }
7996             if ( !n5.getName().equals( "n5" ) ) {
7997                 return false;
7998             }
7999             if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
8000                 return false;
8001             }
8002             if ( n5.getDistanceToParent() != 0.1 ) {
8003                 return false;
8004             }
8005             if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
8006                 return false;
8007             }
8008             if ( !n5.isDuplication() ) {
8009                 return false;
8010             }
8011             if ( !n5.isHasAssignedEvent() ) {
8012                 return false;
8013             }
8014             final PhylogenyNode n8 = PhylogenyNode
8015                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
8016                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8017             if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8018                 return false;
8019             }
8020             if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
8021                 return false;
8022             }
8023             final PhylogenyNode n9 = PhylogenyNode
8024                     .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
8025                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8026             if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
8027                 return false;
8028             }
8029             if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
8030                 return false;
8031             }
8032             final PhylogenyNode n10 = PhylogenyNode
8033                     .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8034             if ( !n10.getName().equals( "n10.ECOLI" ) ) {
8035                 return false;
8036             }
8037             final PhylogenyNode n20 = PhylogenyNode
8038                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8039             if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8040                 return false;
8041             }
8042             if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
8043                 return false;
8044             }
8045             final PhylogenyNode n20x = PhylogenyNode
8046                     .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8047             if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
8048                 return false;
8049             }
8050             if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
8051                 return false;
8052             }
8053             final PhylogenyNode n20xx = PhylogenyNode
8054                     .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8055             if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
8056                 return false;
8057             }
8058             if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
8059                 return false;
8060             }
8061             final PhylogenyNode n20xxx = PhylogenyNode
8062                     .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8063             if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
8064                 return false;
8065             }
8066             if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
8067                 return false;
8068             }
8069             final PhylogenyNode n20xxxx = PhylogenyNode
8070                     .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8071             if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
8072                 return false;
8073             }
8074             if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
8075                 return false;
8076             }
8077             final PhylogenyNode n21 = PhylogenyNode
8078                     .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8079             if ( !n21.getName().equals( "N21_PIG" ) ) {
8080                 return false;
8081             }
8082             if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
8083                 return false;
8084             }
8085             final PhylogenyNode n21x = PhylogenyNode
8086                     .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8087             if ( !n21x.getName().equals( "n21_PIG" ) ) {
8088                 return false;
8089             }
8090             if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
8091                 return false;
8092             }
8093             final PhylogenyNode n22 = PhylogenyNode
8094                     .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8095             if ( !n22.getName().equals( "n22/PIG" ) ) {
8096                 return false;
8097             }
8098             if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
8099                 return false;
8100             }
8101             final PhylogenyNode n23 = PhylogenyNode
8102                     .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8103             if ( !n23.getName().equals( "n23/PIG_1" ) ) {
8104                 return false;
8105             }
8106             if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
8107                 return false;
8108             }
8109             final PhylogenyNode a = PhylogenyNode
8110                     .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8111             if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
8112                 return false;
8113             }
8114             if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
8115                 return false;
8116             }
8117             final PhylogenyNode c1 = PhylogenyNode
8118                     .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
8119                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8120             if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
8121                 return false;
8122             }
8123             if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
8124                 return false;
8125             }
8126             final PhylogenyNode c2 = PhylogenyNode
8127                     .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
8128                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8129             if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
8130                 return false;
8131             }
8132             if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
8133                 return false;
8134             }
8135             final PhylogenyNode e3 = PhylogenyNode
8136                     .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8137             if ( !e3.getName().equals( "n10_RAT~" ) ) {
8138                 return false;
8139             }
8140             if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
8141                 return false;
8142             }
8143             final PhylogenyNode n11 = PhylogenyNode
8144                     .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
8145                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8146             if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
8147                 return false;
8148             }
8149             if ( n11.getDistanceToParent() != 0.4 ) {
8150                 return false;
8151             }
8152             if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
8153                 return false;
8154             }
8155             final PhylogenyNode n12 = PhylogenyNode
8156                     .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
8157                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8158             if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
8159                 return false;
8160             }
8161             if ( n12.getDistanceToParent() != 0.4 ) {
8162                 return false;
8163             }
8164             if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
8165                 return false;
8166             }
8167             final PhylogenyNode o = PhylogenyNode
8168                     .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8169             if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
8170                 return false;
8171             }
8172             if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
8173                 return false;
8174             }
8175             if ( n1.getName().compareTo( "" ) != 0 ) {
8176                 return false;
8177             }
8178             if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
8179                 return false;
8180             }
8181             if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8182                 return false;
8183             }
8184             if ( n2.getName().compareTo( "" ) != 0 ) {
8185                 return false;
8186             }
8187             if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
8188                 return false;
8189             }
8190             if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
8191                 return false;
8192             }
8193             final PhylogenyNode n00 = PhylogenyNode
8194                     .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
8195             if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
8196                 return false;
8197             }
8198             if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
8199                 return false;
8200             }
8201             final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
8202             if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
8203                 return false;
8204             }
8205             final PhylogenyNode n13 = PhylogenyNode
8206                     .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8207             if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
8208                 return false;
8209             }
8210             if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
8211                 return false;
8212             }
8213             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
8214                 return false;
8215             }
8216             if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8217                 return false;
8218             }
8219             final PhylogenyNode n14 = PhylogenyNode
8220                     .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8221             if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
8222                 return false;
8223             }
8224             if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
8225                 return false;
8226             }
8227             final PhylogenyNode n15 = PhylogenyNode
8228                     .createInstanceFromNhxString( "something_wicked[123]",
8229                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8230             if ( !n15.getName().equals( "something_wicked" ) ) {
8231                 return false;
8232             }
8233             if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
8234                 return false;
8235             }
8236             if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
8237                 return false;
8238             }
8239             final PhylogenyNode n16 = PhylogenyNode
8240                     .createInstanceFromNhxString( "something_wicked2[9]",
8241                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8242             if ( !n16.getName().equals( "something_wicked2" ) ) {
8243                 return false;
8244             }
8245             if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
8246                 return false;
8247             }
8248             if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
8249                 return false;
8250             }
8251             final PhylogenyNode n17 = PhylogenyNode
8252                     .createInstanceFromNhxString( "something_wicked3[a]",
8253                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8254             if ( !n17.getName().equals( "something_wicked3" ) ) {
8255                 return false;
8256             }
8257             if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
8258                 return false;
8259             }
8260             final PhylogenyNode n18 = PhylogenyNode
8261                     .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8262             if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
8263                 return false;
8264             }
8265             if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
8266                 return false;
8267             }
8268             if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
8269                 return false;
8270             }
8271             final PhylogenyNode n19 = PhylogenyNode
8272                     .createInstanceFromNhxString( "blah_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8273             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
8274                 return false;
8275             }
8276             if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8277                 return false;
8278             }
8279             final PhylogenyNode n30 = PhylogenyNode
8280                     .createInstanceFromNhxString( "blah_1234567-roejojoej",
8281                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8282             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
8283                 return false;
8284             }
8285             if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8286                 return false;
8287             }
8288             final PhylogenyNode n31 = PhylogenyNode
8289                     .createInstanceFromNhxString( "blah_12345678-roejojoej",
8290                                                   NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8291             if ( n31.getNodeData().isHasTaxonomy() ) {
8292                 return false;
8293             }
8294             final PhylogenyNode n32 = PhylogenyNode
8295                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8296             if ( n32.getNodeData().isHasTaxonomy() ) {
8297                 return false;
8298             }
8299             final PhylogenyNode n40 = PhylogenyNode
8300                     .createInstanceFromNhxString( "bcl2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8301             if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
8302                 return false;
8303             }
8304             final PhylogenyNode n41 = PhylogenyNode
8305                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8306             if ( n41.getNodeData().isHasTaxonomy() ) {
8307                 return false;
8308             }
8309             final PhylogenyNode n42 = PhylogenyNode
8310                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8311             if ( n42.getNodeData().isHasTaxonomy() ) {
8312                 return false;
8313             }
8314             final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
8315                                                                                  NHXParser.TAXONOMY_EXTRACTION.NO );
8316             if ( n43.getNodeData().isHasTaxonomy() ) {
8317                 return false;
8318             }
8319             final PhylogenyNode n44 = PhylogenyNode
8320                     .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8321             if ( n44.getNodeData().isHasTaxonomy() ) {
8322                 return false;
8323             }
8324         }
8325         catch ( final Exception e ) {
8326             e.printStackTrace( System.out );
8327             return false;
8328         }
8329         return true;
8330     }
8331
8332     private static boolean testNHXParsing() {
8333         try {
8334             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8335             final Phylogeny p1 = factory.create( "(A     [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
8336             if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
8337                 return false;
8338             }
8339             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]";
8340             final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
8341             if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8342                 return false;
8343             }
8344             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]";
8345             final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
8346             if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
8347                 return false;
8348             }
8349             final Phylogeny[] p3 = factory
8350                     .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]",
8351                              new NHXParser() );
8352             if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8353                 return false;
8354             }
8355             final Phylogeny[] p4 = factory
8356                     .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(]",
8357                              new NHXParser() );
8358             if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8359                 return false;
8360             }
8361             final Phylogeny[] p5 = factory
8362                     .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(((]",
8363                              new NHXParser() );
8364             if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8365                 return false;
8366             }
8367             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)";
8368             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)";
8369             final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
8370             if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
8371                 return false;
8372             }
8373             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)))";
8374             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)))";
8375             final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
8376             if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
8377                 return false;
8378             }
8379             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])   ))[,,, ])))))))";
8380             final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
8381             final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
8382             if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
8383                 return false;
8384             }
8385             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
8386             if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
8387                 return false;
8388             }
8389             final Phylogeny p10 = factory
8390                     .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]",
8391                              new NHXParser() )[ 0 ];
8392             if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
8393                 return false;
8394             }
8395         }
8396         catch ( final Exception e ) {
8397             e.printStackTrace( System.out );
8398             return false;
8399         }
8400         return true;
8401     }
8402
8403     private static boolean testNHXParsingMB() {
8404         try {
8405             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8406             final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
8407                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8408                     + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
8409                     + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
8410                     + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
8411                     + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8412                     + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
8413                     + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
8414                     + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
8415             if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
8416                 return false;
8417             }
8418             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
8419                 return false;
8420             }
8421             if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
8422                            0.1100000000000000e+00 ) ) {
8423                 return false;
8424             }
8425             if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
8426                 return false;
8427             }
8428             if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
8429                 return false;
8430             }
8431             final Phylogeny p2 = factory
8432                     .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
8433                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8434                                      + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
8435                                      + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
8436                                      + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
8437                                      + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8438                                      + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
8439                                      + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
8440                                      + "7.369400000000000e-02}])",
8441                              new NHXParser() )[ 0 ];
8442             if ( p2.getNode( "1" ) == null ) {
8443                 return false;
8444             }
8445             if ( p2.getNode( "2" ) == null ) {
8446                 return false;
8447             }
8448         }
8449         catch ( final Exception e ) {
8450             e.printStackTrace( System.out );
8451             System.exit( -1 );
8452             return false;
8453         }
8454         return true;
8455     }
8456
8457     private static boolean testNHXParsingQuotes() {
8458         try {
8459             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8460             final NHXParser p = new NHXParser();
8461             final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
8462             if ( phylogenies_0.length != 5 ) {
8463                 return false;
8464             }
8465             final Phylogeny phy = phylogenies_0[ 4 ];
8466             if ( phy.getNumberOfExternalNodes() != 7 ) {
8467                 return false;
8468             }
8469             if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
8470                 return false;
8471             }
8472             if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
8473                 return false;
8474             }
8475             if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
8476                     .getScientificName().equals( "hsapiens" ) ) {
8477                 return false;
8478             }
8479             if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
8480                 return false;
8481             }
8482             if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
8483                 return false;
8484             }
8485             if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
8486                 return false;
8487             }
8488             if ( phy.getNodes( "noquotes" ).size() != 1 ) {
8489                 return false;
8490             }
8491             if ( phy.getNodes( "A   (  B    C '" ).size() != 1 ) {
8492                 return false;
8493             }
8494             final NHXParser p1p = new NHXParser();
8495             p1p.setIgnoreQuotes( true );
8496             final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
8497             if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
8498                 return false;
8499             }
8500             final NHXParser p2p = new NHXParser();
8501             p1p.setIgnoreQuotes( false );
8502             final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
8503             if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
8504                 return false;
8505             }
8506             final NHXParser p3p = new NHXParser();
8507             p3p.setIgnoreQuotes( false );
8508             final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
8509             if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
8510                 return false;
8511             }
8512             final NHXParser p4p = new NHXParser();
8513             p4p.setIgnoreQuotes( false );
8514             final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
8515             if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
8516                 return false;
8517             }
8518             final Phylogeny p10 = factory
8519                     .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]",
8520                              new NHXParser() )[ 0 ];
8521             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]";
8522             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
8523                 return false;
8524             }
8525             final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
8526             if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
8527                 return false;
8528             }
8529             //
8530             final Phylogeny p12 = factory
8531                     .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]",
8532                              new NHXParser() )[ 0 ];
8533             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]";
8534             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
8535                 return false;
8536             }
8537             final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
8538             if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
8539                 return false;
8540             }
8541             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;";
8542             if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
8543                 return false;
8544             }
8545             final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
8546             if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
8547                 return false;
8548             }
8549         }
8550         catch ( final Exception e ) {
8551             e.printStackTrace( System.out );
8552             return false;
8553         }
8554         return true;
8555     }
8556
8557     private static boolean testNodeRemoval() {
8558         try {
8559             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8560             final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
8561             PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
8562             if ( !t0.toNewHampshire().equals( "(a);" ) ) {
8563                 return false;
8564             }
8565             final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
8566             PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
8567             if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
8568                 return false;
8569             }
8570             final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
8571             PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
8572             if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
8573                 return false;
8574             }
8575         }
8576         catch ( final Exception e ) {
8577             e.printStackTrace( System.out );
8578             return false;
8579         }
8580         return true;
8581     }
8582
8583     private static boolean testPhylogenyBranch() {
8584         try {
8585             final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
8586             final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
8587             final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
8588             final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
8589             if ( !a1b1.equals( a1b1 ) ) {
8590                 return false;
8591             }
8592             if ( !a1b1.equals( b1a1 ) ) {
8593                 return false;
8594             }
8595             if ( !b1a1.equals( a1b1 ) ) {
8596                 return false;
8597             }
8598             final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
8599             final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
8600             final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
8601             if ( a1_b1.equals( b1_a1 ) ) {
8602                 return false;
8603             }
8604             if ( a1_b1.equals( a1_b1_ ) ) {
8605                 return false;
8606             }
8607             final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
8608             if ( !a1_b1.equals( b1_a1_ ) ) {
8609                 return false;
8610             }
8611             if ( a1_b1_.equals( b1_a1_ ) ) {
8612                 return false;
8613             }
8614             if ( !a1_b1_.equals( b1_a1 ) ) {
8615                 return false;
8616             }
8617         }
8618         catch ( final Exception e ) {
8619             e.printStackTrace( System.out );
8620             return false;
8621         }
8622         return true;
8623     }
8624
8625     private static boolean testPhyloXMLparsingOfDistributionElement() {
8626         try {
8627             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8628             PhyloXmlParser xml_parser = null;
8629             try {
8630                 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
8631             }
8632             catch ( final Exception e ) {
8633                 // Do nothing -- means were not running from jar.
8634             }
8635             if ( xml_parser == null ) {
8636                 xml_parser = PhyloXmlParser.createPhyloXmlParser();
8637                 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
8638                     xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
8639                 }
8640                 else {
8641                     xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
8642                 }
8643             }
8644             final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
8645                                                               xml_parser );
8646             if ( xml_parser.getErrorCount() > 0 ) {
8647                 System.out.println( xml_parser.getErrorMessages().toString() );
8648                 return false;
8649             }
8650             if ( phylogenies_0.length != 1 ) {
8651                 return false;
8652             }
8653             final Phylogeny t1 = phylogenies_0[ 0 ];
8654             PhylogenyNode n = null;
8655             Distribution d = null;
8656             n = t1.getNode( "root node" );
8657             if ( !n.getNodeData().isHasDistribution() ) {
8658                 return false;
8659             }
8660             if ( n.getNodeData().getDistributions().size() != 1 ) {
8661                 return false;
8662             }
8663             d = n.getNodeData().getDistribution();
8664             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
8665                 return false;
8666             }
8667             if ( d.getPoints().size() != 1 ) {
8668                 return false;
8669             }
8670             if ( d.getPolygons() != null ) {
8671                 return false;
8672             }
8673             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
8674                 return false;
8675             }
8676             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8677                 return false;
8678             }
8679             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8680                 return false;
8681             }
8682             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
8683                 return false;
8684             }
8685             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
8686                 return false;
8687             }
8688             n = t1.getNode( "node a" );
8689             if ( !n.getNodeData().isHasDistribution() ) {
8690                 return false;
8691             }
8692             if ( n.getNodeData().getDistributions().size() != 2 ) {
8693                 return false;
8694             }
8695             d = n.getNodeData().getDistribution( 1 );
8696             if ( !d.getDesc().equals( "San Diego" ) ) {
8697                 return false;
8698             }
8699             if ( d.getPoints().size() != 1 ) {
8700                 return false;
8701             }
8702             if ( d.getPolygons() != null ) {
8703                 return false;
8704             }
8705             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
8706                 return false;
8707             }
8708             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8709                 return false;
8710             }
8711             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8712                 return false;
8713             }
8714             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
8715                 return false;
8716             }
8717             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
8718                 return false;
8719             }
8720             n = t1.getNode( "node bb" );
8721             if ( !n.getNodeData().isHasDistribution() ) {
8722                 return false;
8723             }
8724             if ( n.getNodeData().getDistributions().size() != 1 ) {
8725                 return false;
8726             }
8727             d = n.getNodeData().getDistribution( 0 );
8728             if ( d.getPoints().size() != 3 ) {
8729                 return false;
8730             }
8731             if ( d.getPolygons().size() != 2 ) {
8732                 return false;
8733             }
8734             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
8735                 return false;
8736             }
8737             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
8738                 return false;
8739             }
8740             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
8741                 return false;
8742             }
8743             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
8744                 return false;
8745             }
8746             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
8747                 return false;
8748             }
8749             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
8750                 return false;
8751             }
8752             Polygon p = d.getPolygons().get( 0 );
8753             if ( p.getPoints().size() != 3 ) {
8754                 return false;
8755             }
8756             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
8757                 return false;
8758             }
8759             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
8760                 return false;
8761             }
8762             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8763                 return false;
8764             }
8765             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
8766                 return false;
8767             }
8768             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
8769                 return false;
8770             }
8771             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
8772                 return false;
8773             }
8774             p = d.getPolygons().get( 1 );
8775             if ( p.getPoints().size() != 3 ) {
8776                 return false;
8777             }
8778             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
8779                 return false;
8780             }
8781             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
8782                 return false;
8783             }
8784             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8785                 return false;
8786             }
8787             // Roundtrip:
8788             final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
8789             final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
8790             if ( rt.length != 1 ) {
8791                 return false;
8792             }
8793             final Phylogeny t1_rt = rt[ 0 ];
8794             n = t1_rt.getNode( "root node" );
8795             if ( !n.getNodeData().isHasDistribution() ) {
8796                 return false;
8797             }
8798             if ( n.getNodeData().getDistributions().size() != 1 ) {
8799                 return false;
8800             }
8801             d = n.getNodeData().getDistribution();
8802             if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
8803                 return false;
8804             }
8805             if ( d.getPoints().size() != 1 ) {
8806                 return false;
8807             }
8808             if ( d.getPolygons() != null ) {
8809                 return false;
8810             }
8811             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
8812                 return false;
8813             }
8814             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8815                 return false;
8816             }
8817             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8818                 return false;
8819             }
8820             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
8821                 return false;
8822             }
8823             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
8824                 return false;
8825             }
8826             n = t1_rt.getNode( "node a" );
8827             if ( !n.getNodeData().isHasDistribution() ) {
8828                 return false;
8829             }
8830             if ( n.getNodeData().getDistributions().size() != 2 ) {
8831                 return false;
8832             }
8833             d = n.getNodeData().getDistribution( 1 );
8834             if ( !d.getDesc().equals( "San Diego" ) ) {
8835                 return false;
8836             }
8837             if ( d.getPoints().size() != 1 ) {
8838                 return false;
8839             }
8840             if ( d.getPolygons() != null ) {
8841                 return false;
8842             }
8843             if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
8844                 return false;
8845             }
8846             if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8847                 return false;
8848             }
8849             if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8850                 return false;
8851             }
8852             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
8853                 return false;
8854             }
8855             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
8856                 return false;
8857             }
8858             n = t1_rt.getNode( "node bb" );
8859             if ( !n.getNodeData().isHasDistribution() ) {
8860                 return false;
8861             }
8862             if ( n.getNodeData().getDistributions().size() != 1 ) {
8863                 return false;
8864             }
8865             d = n.getNodeData().getDistribution( 0 );
8866             if ( d.getPoints().size() != 3 ) {
8867                 return false;
8868             }
8869             if ( d.getPolygons().size() != 2 ) {
8870                 return false;
8871             }
8872             if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
8873                 return false;
8874             }
8875             if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
8876                 return false;
8877             }
8878             if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
8879                 return false;
8880             }
8881             if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
8882                 return false;
8883             }
8884             if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
8885                 return false;
8886             }
8887             if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
8888                 return false;
8889             }
8890             p = d.getPolygons().get( 0 );
8891             if ( p.getPoints().size() != 3 ) {
8892                 return false;
8893             }
8894             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
8895                 return false;
8896             }
8897             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
8898                 return false;
8899             }
8900             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8901                 return false;
8902             }
8903             if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
8904                 return false;
8905             }
8906             if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
8907                 return false;
8908             }
8909             if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
8910                 return false;
8911             }
8912             p = d.getPolygons().get( 1 );
8913             if ( p.getPoints().size() != 3 ) {
8914                 return false;
8915             }
8916             if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
8917                 return false;
8918             }
8919             if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
8920                 return false;
8921             }
8922             if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8923                 return false;
8924             }
8925         }
8926         catch ( final Exception e ) {
8927             e.printStackTrace( System.out );
8928             return false;
8929         }
8930         return true;
8931     }
8932
8933     private static boolean testPostOrderIterator() {
8934         try {
8935             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8936             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
8937             PhylogenyNodeIterator it0;
8938             for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
8939                 it0.next();
8940             }
8941             for( it0.reset(); it0.hasNext(); ) {
8942                 it0.next();
8943             }
8944             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
8945             final PhylogenyNodeIterator it = t1.iteratorPostorder();
8946             if ( !it.next().getName().equals( "A" ) ) {
8947                 return false;
8948             }
8949             if ( !it.next().getName().equals( "B" ) ) {
8950                 return false;
8951             }
8952             if ( !it.next().getName().equals( "ab" ) ) {
8953                 return false;
8954             }
8955             if ( !it.next().getName().equals( "C" ) ) {
8956                 return false;
8957             }
8958             if ( !it.next().getName().equals( "D" ) ) {
8959                 return false;
8960             }
8961             if ( !it.next().getName().equals( "cd" ) ) {
8962                 return false;
8963             }
8964             if ( !it.next().getName().equals( "abcd" ) ) {
8965                 return false;
8966             }
8967             if ( !it.next().getName().equals( "E" ) ) {
8968                 return false;
8969             }
8970             if ( !it.next().getName().equals( "F" ) ) {
8971                 return false;
8972             }
8973             if ( !it.next().getName().equals( "ef" ) ) {
8974                 return false;
8975             }
8976             if ( !it.next().getName().equals( "G" ) ) {
8977                 return false;
8978             }
8979             if ( !it.next().getName().equals( "H" ) ) {
8980                 return false;
8981             }
8982             if ( !it.next().getName().equals( "gh" ) ) {
8983                 return false;
8984             }
8985             if ( !it.next().getName().equals( "efgh" ) ) {
8986                 return false;
8987             }
8988             if ( !it.next().getName().equals( "r" ) ) {
8989                 return false;
8990             }
8991             if ( it.hasNext() ) {
8992                 return false;
8993             }
8994         }
8995         catch ( final Exception e ) {
8996             e.printStackTrace( System.out );
8997             return false;
8998         }
8999         return true;
9000     }
9001
9002     private static boolean testPreOrderIterator() {
9003         try {
9004             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9005             final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
9006             PhylogenyNodeIterator it0;
9007             for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
9008                 it0.next();
9009             }
9010             for( it0.reset(); it0.hasNext(); ) {
9011                 it0.next();
9012             }
9013             PhylogenyNodeIterator it = t0.iteratorPreorder();
9014             if ( !it.next().getName().equals( "r" ) ) {
9015                 return false;
9016             }
9017             if ( !it.next().getName().equals( "ab" ) ) {
9018                 return false;
9019             }
9020             if ( !it.next().getName().equals( "A" ) ) {
9021                 return false;
9022             }
9023             if ( !it.next().getName().equals( "B" ) ) {
9024                 return false;
9025             }
9026             if ( !it.next().getName().equals( "cd" ) ) {
9027                 return false;
9028             }
9029             if ( !it.next().getName().equals( "C" ) ) {
9030                 return false;
9031             }
9032             if ( !it.next().getName().equals( "D" ) ) {
9033                 return false;
9034             }
9035             if ( it.hasNext() ) {
9036                 return false;
9037             }
9038             final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
9039             it = t1.iteratorPreorder();
9040             if ( !it.next().getName().equals( "r" ) ) {
9041                 return false;
9042             }
9043             if ( !it.next().getName().equals( "abcd" ) ) {
9044                 return false;
9045             }
9046             if ( !it.next().getName().equals( "ab" ) ) {
9047                 return false;
9048             }
9049             if ( !it.next().getName().equals( "A" ) ) {
9050                 return false;
9051             }
9052             if ( !it.next().getName().equals( "B" ) ) {
9053                 return false;
9054             }
9055             if ( !it.next().getName().equals( "cd" ) ) {
9056                 return false;
9057             }
9058             if ( !it.next().getName().equals( "C" ) ) {
9059                 return false;
9060             }
9061             if ( !it.next().getName().equals( "D" ) ) {
9062                 return false;
9063             }
9064             if ( !it.next().getName().equals( "efgh" ) ) {
9065                 return false;
9066             }
9067             if ( !it.next().getName().equals( "ef" ) ) {
9068                 return false;
9069             }
9070             if ( !it.next().getName().equals( "E" ) ) {
9071                 return false;
9072             }
9073             if ( !it.next().getName().equals( "F" ) ) {
9074                 return false;
9075             }
9076             if ( !it.next().getName().equals( "gh" ) ) {
9077                 return false;
9078             }
9079             if ( !it.next().getName().equals( "G" ) ) {
9080                 return false;
9081             }
9082             if ( !it.next().getName().equals( "H" ) ) {
9083                 return false;
9084             }
9085             if ( it.hasNext() ) {
9086                 return false;
9087             }
9088         }
9089         catch ( final Exception e ) {
9090             e.printStackTrace( System.out );
9091             return false;
9092         }
9093         return true;
9094     }
9095
9096     private static boolean testPropertiesMap() {
9097         try {
9098             final PropertiesMap pm = new PropertiesMap();
9099             final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
9100             final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
9101             final Property p2 = new Property( "something:else",
9102                                               "?",
9103                                               "improbable:research",
9104                                               "xsd:decimal",
9105                                               AppliesTo.NODE );
9106             pm.addProperty( p0 );
9107             pm.addProperty( p1 );
9108             pm.addProperty( p2 );
9109             if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
9110                 return false;
9111             }
9112             if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
9113                 return false;
9114             }
9115             if ( pm.getProperties().size() != 3 ) {
9116                 return false;
9117             }
9118             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
9119                 return false;
9120             }
9121             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
9122                 return false;
9123             }
9124             if ( pm.getProperties().size() != 3 ) {
9125                 return false;
9126             }
9127             pm.removeProperty( "dimensions:diameter" );
9128             if ( pm.getProperties().size() != 2 ) {
9129                 return false;
9130             }
9131             if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
9132                 return false;
9133             }
9134             if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
9135                 return false;
9136             }
9137         }
9138         catch ( final Exception e ) {
9139             e.printStackTrace( System.out );
9140             return false;
9141         }
9142         return true;
9143     }
9144
9145     private static boolean testProteinId() {
9146         try {
9147             final ProteinId id1 = new ProteinId( "a" );
9148             final ProteinId id2 = new ProteinId( "a" );
9149             final ProteinId id3 = new ProteinId( "A" );
9150             final ProteinId id4 = new ProteinId( "b" );
9151             if ( !id1.equals( id1 ) ) {
9152                 return false;
9153             }
9154             if ( id1.getId().equals( "x" ) ) {
9155                 return false;
9156             }
9157             if ( id1.getId().equals( null ) ) {
9158                 return false;
9159             }
9160             if ( !id1.equals( id2 ) ) {
9161                 return false;
9162             }
9163             if ( id1.equals( id3 ) ) {
9164                 return false;
9165             }
9166             if ( id1.hashCode() != id1.hashCode() ) {
9167                 return false;
9168             }
9169             if ( id1.hashCode() != id2.hashCode() ) {
9170                 return false;
9171             }
9172             if ( id1.hashCode() == id3.hashCode() ) {
9173                 return false;
9174             }
9175             if ( id1.compareTo( id1 ) != 0 ) {
9176                 return false;
9177             }
9178             if ( id1.compareTo( id2 ) != 0 ) {
9179                 return false;
9180             }
9181             if ( id1.compareTo( id3 ) != 0 ) {
9182                 return false;
9183             }
9184             if ( id1.compareTo( id4 ) >= 0 ) {
9185                 return false;
9186             }
9187             if ( id4.compareTo( id1 ) <= 0 ) {
9188                 return false;
9189             }
9190             if ( !id4.getId().equals( "b" ) ) {
9191                 return false;
9192             }
9193             final ProteinId id5 = new ProteinId( " C " );
9194             if ( !id5.getId().equals( "C" ) ) {
9195                 return false;
9196             }
9197             if ( id5.equals( id1 ) ) {
9198                 return false;
9199             }
9200         }
9201         catch ( final Exception e ) {
9202             e.printStackTrace( System.out );
9203             return false;
9204         }
9205         return true;
9206     }
9207
9208     private static boolean testReIdMethods() {
9209         try {
9210             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9211             final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
9212             final long count = PhylogenyNode.getNodeCount();
9213             p.levelOrderReID();
9214             if ( p.getNode( "r" ).getId() != count ) {
9215                 return false;
9216             }
9217             if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
9218                 return false;
9219             }
9220             if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
9221                 return false;
9222             }
9223             if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
9224                 return false;
9225             }
9226             if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
9227                 return false;
9228             }
9229             if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
9230                 return false;
9231             }
9232             if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
9233                 return false;
9234             }
9235             if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
9236                 return false;
9237             }
9238             if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
9239                 return false;
9240             }
9241             if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
9242                 return false;
9243             }
9244             if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
9245                 return false;
9246             }
9247             if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
9248                 return false;
9249             }
9250             if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
9251                 return false;
9252             }
9253             if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
9254                 return false;
9255             }
9256             if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
9257                 return false;
9258             }
9259         }
9260         catch ( final Exception e ) {
9261             e.printStackTrace( System.out );
9262             return false;
9263         }
9264         return true;
9265     }
9266
9267     private static boolean testRerooting() {
9268         try {
9269             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9270             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",
9271                                                  new NHXParser() )[ 0 ];
9272             if ( !t1.isRooted() ) {
9273                 return false;
9274             }
9275             t1.reRoot( t1.getNode( "D" ) );
9276             t1.reRoot( t1.getNode( "CD" ) );
9277             t1.reRoot( t1.getNode( "A" ) );
9278             t1.reRoot( t1.getNode( "B" ) );
9279             t1.reRoot( t1.getNode( "AB" ) );
9280             t1.reRoot( t1.getNode( "D" ) );
9281             t1.reRoot( t1.getNode( "C" ) );
9282             t1.reRoot( t1.getNode( "CD" ) );
9283             t1.reRoot( t1.getNode( "A" ) );
9284             t1.reRoot( t1.getNode( "B" ) );
9285             t1.reRoot( t1.getNode( "AB" ) );
9286             t1.reRoot( t1.getNode( "D" ) );
9287             t1.reRoot( t1.getNode( "D" ) );
9288             t1.reRoot( t1.getNode( "C" ) );
9289             t1.reRoot( t1.getNode( "A" ) );
9290             t1.reRoot( t1.getNode( "B" ) );
9291             t1.reRoot( t1.getNode( "AB" ) );
9292             t1.reRoot( t1.getNode( "C" ) );
9293             t1.reRoot( t1.getNode( "D" ) );
9294             t1.reRoot( t1.getNode( "CD" ) );
9295             t1.reRoot( t1.getNode( "D" ) );
9296             t1.reRoot( t1.getNode( "A" ) );
9297             t1.reRoot( t1.getNode( "B" ) );
9298             t1.reRoot( t1.getNode( "AB" ) );
9299             t1.reRoot( t1.getNode( "C" ) );
9300             t1.reRoot( t1.getNode( "D" ) );
9301             t1.reRoot( t1.getNode( "CD" ) );
9302             t1.reRoot( t1.getNode( "D" ) );
9303             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
9304                 return false;
9305             }
9306             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
9307                 return false;
9308             }
9309             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
9310                 return false;
9311             }
9312             if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
9313                 return false;
9314             }
9315             if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
9316                 return false;
9317             }
9318             if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
9319                 return false;
9320             }
9321             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",
9322                                                  new NHXParser() )[ 0 ];
9323             t2.reRoot( t2.getNode( "A" ) );
9324             t2.reRoot( t2.getNode( "D" ) );
9325             t2.reRoot( t2.getNode( "ABC" ) );
9326             t2.reRoot( t2.getNode( "A" ) );
9327             t2.reRoot( t2.getNode( "B" ) );
9328             t2.reRoot( t2.getNode( "D" ) );
9329             t2.reRoot( t2.getNode( "C" ) );
9330             t2.reRoot( t2.getNode( "ABC" ) );
9331             t2.reRoot( t2.getNode( "A" ) );
9332             t2.reRoot( t2.getNode( "B" ) );
9333             t2.reRoot( t2.getNode( "AB" ) );
9334             t2.reRoot( t2.getNode( "AB" ) );
9335             t2.reRoot( t2.getNode( "D" ) );
9336             t2.reRoot( t2.getNode( "C" ) );
9337             t2.reRoot( t2.getNode( "B" ) );
9338             t2.reRoot( t2.getNode( "AB" ) );
9339             t2.reRoot( t2.getNode( "D" ) );
9340             t2.reRoot( t2.getNode( "D" ) );
9341             t2.reRoot( t2.getNode( "ABC" ) );
9342             t2.reRoot( t2.getNode( "A" ) );
9343             t2.reRoot( t2.getNode( "B" ) );
9344             t2.reRoot( t2.getNode( "AB" ) );
9345             t2.reRoot( t2.getNode( "D" ) );
9346             t2.reRoot( t2.getNode( "C" ) );
9347             t2.reRoot( t2.getNode( "ABC" ) );
9348             t2.reRoot( t2.getNode( "A" ) );
9349             t2.reRoot( t2.getNode( "B" ) );
9350             t2.reRoot( t2.getNode( "AB" ) );
9351             t2.reRoot( t2.getNode( "D" ) );
9352             t2.reRoot( t2.getNode( "D" ) );
9353             t2.reRoot( t2.getNode( "C" ) );
9354             t2.reRoot( t2.getNode( "A" ) );
9355             t2.reRoot( t2.getNode( "B" ) );
9356             t2.reRoot( t2.getNode( "AB" ) );
9357             t2.reRoot( t2.getNode( "C" ) );
9358             t2.reRoot( t2.getNode( "D" ) );
9359             t2.reRoot( t2.getNode( "ABC" ) );
9360             t2.reRoot( t2.getNode( "D" ) );
9361             t2.reRoot( t2.getNode( "A" ) );
9362             t2.reRoot( t2.getNode( "B" ) );
9363             t2.reRoot( t2.getNode( "AB" ) );
9364             t2.reRoot( t2.getNode( "C" ) );
9365             t2.reRoot( t2.getNode( "D" ) );
9366             t2.reRoot( t2.getNode( "ABC" ) );
9367             t2.reRoot( t2.getNode( "D" ) );
9368             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9369                 return false;
9370             }
9371             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9372                 return false;
9373             }
9374             t2.reRoot( t2.getNode( "ABC" ) );
9375             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9376                 return false;
9377             }
9378             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9379                 return false;
9380             }
9381             t2.reRoot( t2.getNode( "AB" ) );
9382             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9383                 return false;
9384             }
9385             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9386                 return false;
9387             }
9388             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9389                 return false;
9390             }
9391             t2.reRoot( t2.getNode( "AB" ) );
9392             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9393                 return false;
9394             }
9395             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9396                 return false;
9397             }
9398             if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9399                 return false;
9400             }
9401             t2.reRoot( t2.getNode( "D" ) );
9402             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9403                 return false;
9404             }
9405             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9406                 return false;
9407             }
9408             t2.reRoot( t2.getNode( "ABC" ) );
9409             if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9410                 return false;
9411             }
9412             if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9413                 return false;
9414             }
9415             final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
9416                                                  new NHXParser() )[ 0 ];
9417             t3.reRoot( t3.getNode( "B" ) );
9418             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9419                 return false;
9420             }
9421             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9422                 return false;
9423             }
9424             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9425                 return false;
9426             }
9427             t3.reRoot( t3.getNode( "B" ) );
9428             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9429                 return false;
9430             }
9431             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9432                 return false;
9433             }
9434             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9435                 return false;
9436             }
9437             t3.reRoot( t3.getRoot() );
9438             if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9439                 return false;
9440             }
9441             if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9442                 return false;
9443             }
9444             if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9445                 return false;
9446             }
9447         }
9448         catch ( final Exception e ) {
9449             e.printStackTrace( System.out );
9450             return false;
9451         }
9452         return true;
9453     }
9454
9455     private static boolean testSDIse() {
9456         try {
9457             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9458             final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
9459             final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
9460             gene1.setRooted( true );
9461             species1.setRooted( true );
9462             final SDI sdi = new SDI( gene1, species1 );
9463             if ( !gene1.getRoot().isDuplication() ) {
9464                 return false;
9465             }
9466             final Phylogeny species2 = factory
9467                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9468                              new NHXParser() )[ 0 ];
9469             final Phylogeny gene2 = factory
9470                     .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9471                              new NHXParser() )[ 0 ];
9472             species2.setRooted( true );
9473             gene2.setRooted( true );
9474             final SDI sdi2 = new SDI( gene2, species2 );
9475             if ( sdi2.getDuplicationsSum() != 0 ) {
9476                 return false;
9477             }
9478             if ( !gene2.getNode( "ab" ).isSpeciation() ) {
9479                 return false;
9480             }
9481             if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
9482                 return false;
9483             }
9484             if ( !gene2.getNode( "abc" ).isSpeciation() ) {
9485                 return false;
9486             }
9487             if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
9488                 return false;
9489             }
9490             if ( !gene2.getNode( "r" ).isSpeciation() ) {
9491                 return false;
9492             }
9493             if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
9494                 return false;
9495             }
9496             final Phylogeny species3 = factory
9497                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9498                              new NHXParser() )[ 0 ];
9499             final Phylogeny gene3 = factory
9500                     .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9501                              new NHXParser() )[ 0 ];
9502             species3.setRooted( true );
9503             gene3.setRooted( true );
9504             final SDI sdi3 = new SDI( gene3, species3 );
9505             if ( sdi3.getDuplicationsSum() != 1 ) {
9506                 return false;
9507             }
9508             if ( !gene3.getNode( "aa" ).isDuplication() ) {
9509                 return false;
9510             }
9511             if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
9512                 return false;
9513             }
9514             final Phylogeny species4 = factory
9515                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9516                              new NHXParser() )[ 0 ];
9517             final Phylogeny gene4 = factory
9518                     .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9519                              new NHXParser() )[ 0 ];
9520             species4.setRooted( true );
9521             gene4.setRooted( true );
9522             final SDI sdi4 = new SDI( gene4, species4 );
9523             if ( sdi4.getDuplicationsSum() != 1 ) {
9524                 return false;
9525             }
9526             if ( !gene4.getNode( "ac" ).isSpeciation() ) {
9527                 return false;
9528             }
9529             if ( !gene4.getNode( "abc" ).isDuplication() ) {
9530                 return false;
9531             }
9532             if ( gene4.getNode( "abcd" ).isDuplication() ) {
9533                 return false;
9534             }
9535             if ( species4.getNumberOfExternalNodes() != 6 ) {
9536                 return false;
9537             }
9538             if ( gene4.getNumberOfExternalNodes() != 6 ) {
9539                 return false;
9540             }
9541             final Phylogeny species5 = factory
9542                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9543                              new NHXParser() )[ 0 ];
9544             final Phylogeny gene5 = factory
9545                     .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9546                              new NHXParser() )[ 0 ];
9547             species5.setRooted( true );
9548             gene5.setRooted( true );
9549             final SDI sdi5 = new SDI( gene5, species5 );
9550             if ( sdi5.getDuplicationsSum() != 2 ) {
9551                 return false;
9552             }
9553             if ( !gene5.getNode( "ad" ).isSpeciation() ) {
9554                 return false;
9555             }
9556             if ( !gene5.getNode( "adc" ).isDuplication() ) {
9557                 return false;
9558             }
9559             if ( !gene5.getNode( "abcd" ).isDuplication() ) {
9560                 return false;
9561             }
9562             if ( species5.getNumberOfExternalNodes() != 6 ) {
9563                 return false;
9564             }
9565             if ( gene5.getNumberOfExternalNodes() != 6 ) {
9566                 return false;
9567             }
9568             // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
9569             // Conjecture for Comparing Molecular Phylogenies"
9570             // J. of Comput Bio. Vol. 4, No 2, pp.177-187
9571             final Phylogeny species6 = factory
9572                     .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,"
9573                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9574                              new NHXParser() )[ 0 ];
9575             final Phylogeny gene6 = factory
9576                     .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,"
9577                                      + "((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,"
9578                                      + "(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;",
9579                              new NHXParser() )[ 0 ];
9580             species6.setRooted( true );
9581             gene6.setRooted( true );
9582             final SDI sdi6 = new SDI( gene6, species6 );
9583             if ( sdi6.getDuplicationsSum() != 3 ) {
9584                 return false;
9585             }
9586             if ( !gene6.getNode( "r" ).isDuplication() ) {
9587                 return false;
9588             }
9589             if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
9590                 return false;
9591             }
9592             if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
9593                 return false;
9594             }
9595             if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
9596                 return false;
9597             }
9598             if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
9599                 return false;
9600             }
9601             if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
9602                 return false;
9603             }
9604             if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
9605                 return false;
9606             }
9607             if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
9608                 return false;
9609             }
9610             sdi6.computeMappingCostL();
9611             if ( sdi6.computeMappingCostL() != 17 ) {
9612                 return false;
9613             }
9614             if ( species6.getNumberOfExternalNodes() != 9 ) {
9615                 return false;
9616             }
9617             if ( gene6.getNumberOfExternalNodes() != 9 ) {
9618                 return false;
9619             }
9620             final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
9621                     + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
9622                     + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
9623                     + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
9624                     + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
9625             species7.setRooted( true );
9626             final Phylogeny gene7_1 = Test
9627                     .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])" );
9628             gene7_1.setRooted( true );
9629             final SDI sdi7 = new SDI( gene7_1, species7 );
9630             if ( sdi7.getDuplicationsSum() != 0 ) {
9631                 return false;
9632             }
9633             if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
9634                 return false;
9635             }
9636             if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
9637                 return false;
9638             }
9639             if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
9640                 return false;
9641             }
9642             if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
9643                 return false;
9644             }
9645             if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
9646                 return false;
9647             }
9648             if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
9649                 return false;
9650             }
9651             if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
9652                 return false;
9653             }
9654             if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
9655                 return false;
9656             }
9657             final Phylogeny gene7_2 = Test
9658                     .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])" );
9659             gene7_2.setRooted( true );
9660             final SDI sdi7_2 = new SDI( gene7_2, species7 );
9661             if ( sdi7_2.getDuplicationsSum() != 1 ) {
9662                 return false;
9663             }
9664             if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
9665                 return false;
9666             }
9667             if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
9668                 return false;
9669             }
9670             if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
9671                 return false;
9672             }
9673             if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
9674                 return false;
9675             }
9676             if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
9677                 return false;
9678             }
9679             if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
9680                 return false;
9681             }
9682             if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
9683                 return false;
9684             }
9685             if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
9686                 return false;
9687             }
9688             if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
9689                 return false;
9690             }
9691         }
9692         catch ( final Exception e ) {
9693             return false;
9694         }
9695         return true;
9696     }
9697
9698     private static boolean testSDIunrooted() {
9699         try {
9700             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9701             final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
9702             final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
9703             final Iterator<PhylogenyBranch> iter = l.iterator();
9704             PhylogenyBranch br = iter.next();
9705             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
9706                 return false;
9707             }
9708             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
9709                 return false;
9710             }
9711             br = iter.next();
9712             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
9713                 return false;
9714             }
9715             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
9716                 return false;
9717             }
9718             br = iter.next();
9719             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
9720                 return false;
9721             }
9722             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
9723                 return false;
9724             }
9725             br = iter.next();
9726             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9727                 return false;
9728             }
9729             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9730                 return false;
9731             }
9732             br = iter.next();
9733             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9734                 return false;
9735             }
9736             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9737                 return false;
9738             }
9739             br = iter.next();
9740             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
9741                 return false;
9742             }
9743             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
9744                 return false;
9745             }
9746             br = iter.next();
9747             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9748                 return false;
9749             }
9750             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9751                 return false;
9752             }
9753             br = iter.next();
9754             if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9755                 return false;
9756             }
9757             if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9758                 return false;
9759             }
9760             br = iter.next();
9761             if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9762                 return false;
9763             }
9764             if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9765                 return false;
9766             }
9767             br = iter.next();
9768             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9769                 return false;
9770             }
9771             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9772                 return false;
9773             }
9774             br = iter.next();
9775             if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
9776                 return false;
9777             }
9778             if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
9779                 return false;
9780             }
9781             br = iter.next();
9782             if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
9783                 return false;
9784             }
9785             if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
9786                 return false;
9787             }
9788             br = iter.next();
9789             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
9790                 return false;
9791             }
9792             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
9793                 return false;
9794             }
9795             br = iter.next();
9796             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
9797                 return false;
9798             }
9799             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
9800                 return false;
9801             }
9802             br = iter.next();
9803             if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
9804                 return false;
9805             }
9806             if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
9807                 return false;
9808             }
9809             if ( iter.hasNext() ) {
9810                 return false;
9811             }
9812             final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
9813             final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
9814             final Iterator<PhylogenyBranch> iter1 = l1.iterator();
9815             br = iter1.next();
9816             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
9817                 return false;
9818             }
9819             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
9820                 return false;
9821             }
9822             br = iter1.next();
9823             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9824                 return false;
9825             }
9826             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9827                 return false;
9828             }
9829             br = iter1.next();
9830             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9831                 return false;
9832             }
9833             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9834                 return false;
9835             }
9836             if ( iter1.hasNext() ) {
9837                 return false;
9838             }
9839             final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
9840             final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
9841             final Iterator<PhylogenyBranch> iter2 = l2.iterator();
9842             br = iter2.next();
9843             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
9844                 return false;
9845             }
9846             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
9847                 return false;
9848             }
9849             br = iter2.next();
9850             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9851                 return false;
9852             }
9853             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9854                 return false;
9855             }
9856             br = iter2.next();
9857             if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9858                 return false;
9859             }
9860             if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9861                 return false;
9862             }
9863             if ( iter2.hasNext() ) {
9864                 return false;
9865             }
9866             final Phylogeny species0 = factory
9867                     .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9868                              new NHXParser() )[ 0 ];
9869             final Phylogeny gene1 = factory
9870                     .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])",
9871                              new NHXParser() )[ 0 ];
9872             species0.setRooted( true );
9873             gene1.setRooted( true );
9874             final SDIR sdi_unrooted = new SDIR();
9875             sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
9876             if ( sdi_unrooted.getCount() != 1 ) {
9877                 return false;
9878             }
9879             if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
9880                 return false;
9881             }
9882             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
9883                 return false;
9884             }
9885             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
9886                 return false;
9887             }
9888             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9889                 return false;
9890             }
9891             final Phylogeny gene2 = factory
9892                     .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])",
9893                              new NHXParser() )[ 0 ];
9894             gene2.setRooted( true );
9895             sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
9896             if ( sdi_unrooted.getCount() != 1 ) {
9897                 return false;
9898             }
9899             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9900                 return false;
9901             }
9902             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9903                 return false;
9904             }
9905             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
9906                 return false;
9907             }
9908             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9909                 return false;
9910             }
9911             final Phylogeny species6 = factory
9912                     .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,"
9913                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9914                              new NHXParser() )[ 0 ];
9915             final Phylogeny gene6 = factory
9916                     .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],"
9917                                      + "(((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],"
9918                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
9919                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
9920                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
9921                              new NHXParser() )[ 0 ];
9922             species6.setRooted( true );
9923             gene6.setRooted( true );
9924             Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
9925             if ( sdi_unrooted.getCount() != 1 ) {
9926                 return false;
9927             }
9928             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9929                 return false;
9930             }
9931             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
9932                 return false;
9933             }
9934             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9935                 return false;
9936             }
9937             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9938                 return false;
9939             }
9940             if ( !p6[ 0 ].getRoot().isDuplication() ) {
9941                 return false;
9942             }
9943             if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
9944                 return false;
9945             }
9946             if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
9947                 return false;
9948             }
9949             if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
9950                 return false;
9951             }
9952             if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
9953                 return false;
9954             }
9955             if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
9956                 return false;
9957             }
9958             if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
9959                 return false;
9960             }
9961             if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
9962                 return false;
9963             }
9964             p6 = null;
9965             final Phylogeny species7 = factory
9966                     .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,"
9967                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9968                              new NHXParser() )[ 0 ];
9969             final Phylogeny gene7 = factory
9970                     .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],"
9971                                      + "(((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],"
9972                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
9973                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
9974                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
9975                              new NHXParser() )[ 0 ];
9976             species7.setRooted( true );
9977             gene7.setRooted( true );
9978             Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
9979             if ( sdi_unrooted.getCount() != 1 ) {
9980                 return false;
9981             }
9982             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9983                 return false;
9984             }
9985             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
9986                 return false;
9987             }
9988             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9989                 return false;
9990             }
9991             if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
9992                 return false;
9993             }
9994             if ( !p7[ 0 ].getRoot().isDuplication() ) {
9995                 return false;
9996             }
9997             if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
9998                 return false;
9999             }
10000             if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10001                 return false;
10002             }
10003             if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
10004                 return false;
10005             }
10006             if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10007                 return false;
10008             }
10009             if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
10010                 return false;
10011             }
10012             if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
10013                 return false;
10014             }
10015             if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10016                 return false;
10017             }
10018             p7 = null;
10019             final Phylogeny species8 = factory
10020                     .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,"
10021                                      + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10022                              new NHXParser() )[ 0 ];
10023             final Phylogeny gene8 = factory
10024                     .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],"
10025                                      + "(((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],"
10026                                      + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
10027                                      + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
10028                                      + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
10029                              new NHXParser() )[ 0 ];
10030             species8.setRooted( true );
10031             gene8.setRooted( true );
10032             Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
10033             if ( sdi_unrooted.getCount() != 1 ) {
10034                 return false;
10035             }
10036             if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
10037                 return false;
10038             }
10039             if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
10040                 return false;
10041             }
10042             if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
10043                 return false;
10044             }
10045             if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
10046                 return false;
10047             }
10048             if ( !p8[ 0 ].getRoot().isDuplication() ) {
10049                 return false;
10050             }
10051             if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
10052                 return false;
10053             }
10054             if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
10055                 return false;
10056             }
10057             if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
10058                 return false;
10059             }
10060             if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
10061                 return false;
10062             }
10063             if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
10064                 return false;
10065             }
10066             if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
10067                 return false;
10068             }
10069             if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
10070                 return false;
10071             }
10072             p8 = null;
10073         }
10074         catch ( final Exception e ) {
10075             e.printStackTrace( System.out );
10076             return false;
10077         }
10078         return true;
10079     }
10080
10081     private static boolean testSequenceIdParsing() {
10082         try {
10083             Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
10084             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10085                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
10086                 if ( id != null ) {
10087                     System.out.println( "value   =" + id.getValue() );
10088                     System.out.println( "provider=" + id.getSource() );
10089                 }
10090                 return false;
10091             }
10092             //
10093             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
10094             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10095                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
10096                 if ( id != null ) {
10097                     System.out.println( "value   =" + id.getValue() );
10098                     System.out.println( "provider=" + id.getSource() );
10099                 }
10100                 return false;
10101             }
10102             //
10103             id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
10104             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10105                     || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
10106                 if ( id != null ) {
10107                     System.out.println( "value   =" + id.getValue() );
10108                     System.out.println( "provider=" + id.getSource() );
10109                 }
10110                 return false;
10111             }
10112             // 
10113             id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
10114             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10115                     || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
10116                 if ( id != null ) {
10117                     System.out.println( "value   =" + id.getValue() );
10118                     System.out.println( "provider=" + id.getSource() );
10119                 }
10120                 return false;
10121             }
10122             // 
10123             id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
10124             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10125                     || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
10126                 if ( id != null ) {
10127                     System.out.println( "value   =" + id.getValue() );
10128                     System.out.println( "provider=" + id.getSource() );
10129                 }
10130                 return false;
10131             }
10132             // 
10133             id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
10134             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10135                     || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
10136                 if ( id != null ) {
10137                     System.out.println( "value   =" + id.getValue() );
10138                     System.out.println( "provider=" + id.getSource() );
10139                 }
10140                 return false;
10141             }
10142             // 
10143             id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
10144             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10145                     || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
10146                 if ( id != null ) {
10147                     System.out.println( "value   =" + id.getValue() );
10148                     System.out.println( "provider=" + id.getSource() );
10149                 }
10150                 return false;
10151             }
10152             // 
10153             id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
10154             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10155                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
10156                 if ( id != null ) {
10157                     System.out.println( "value   =" + id.getValue() );
10158                     System.out.println( "provider=" + id.getSource() );
10159                 }
10160                 return false;
10161             }
10162             // 
10163             id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
10164             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10165                     || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
10166                 if ( id != null ) {
10167                     System.out.println( "value   =" + id.getValue() );
10168                     System.out.println( "provider=" + id.getSource() );
10169                 }
10170                 return false;
10171             }
10172             // 
10173             id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
10174             if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
10175                     || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
10176                 if ( id != null ) {
10177                     System.out.println( "value   =" + id.getValue() );
10178                     System.out.println( "provider=" + id.getSource() );
10179                 }
10180                 return false;
10181             }
10182             id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
10183             if ( id != null ) {
10184                 System.out.println( "value   =" + id.getValue() );
10185                 System.out.println( "provider=" + id.getSource() );
10186                 return false;
10187             }
10188         }
10189         catch ( final Exception e ) {
10190             e.printStackTrace( System.out );
10191             return false;
10192         }
10193         return true;
10194     }
10195
10196     private static boolean testSequenceWriter() {
10197         try {
10198             final String n = ForesterUtil.LINE_SEPARATOR;
10199             if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
10200                 return false;
10201             }
10202             if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
10203                 return false;
10204             }
10205             if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
10206                 return false;
10207             }
10208             if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
10209                 return false;
10210             }
10211             if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
10212                     .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
10213                 return false;
10214             }
10215             if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
10216                     .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
10217                 return false;
10218             }
10219         }
10220         catch ( final Exception e ) {
10221             e.printStackTrace();
10222             return false;
10223         }
10224         return true;
10225     }
10226
10227     private static boolean testSpecies() {
10228         try {
10229             final Species s1 = new BasicSpecies( "a" );
10230             final Species s2 = new BasicSpecies( "a" );
10231             final Species s3 = new BasicSpecies( "A" );
10232             final Species s4 = new BasicSpecies( "b" );
10233             if ( !s1.equals( s1 ) ) {
10234                 return false;
10235             }
10236             if ( s1.getSpeciesId().equals( "x" ) ) {
10237                 return false;
10238             }
10239             if ( s1.getSpeciesId().equals( null ) ) {
10240                 return false;
10241             }
10242             if ( !s1.equals( s2 ) ) {
10243                 return false;
10244             }
10245             if ( s1.equals( s3 ) ) {
10246                 return false;
10247             }
10248             if ( s1.hashCode() != s1.hashCode() ) {
10249                 return false;
10250             }
10251             if ( s1.hashCode() != s2.hashCode() ) {
10252                 return false;
10253             }
10254             if ( s1.hashCode() == s3.hashCode() ) {
10255                 return false;
10256             }
10257             if ( s1.compareTo( s1 ) != 0 ) {
10258                 return false;
10259             }
10260             if ( s1.compareTo( s2 ) != 0 ) {
10261                 return false;
10262             }
10263             if ( s1.compareTo( s3 ) != 0 ) {
10264                 return false;
10265             }
10266             if ( s1.compareTo( s4 ) >= 0 ) {
10267                 return false;
10268             }
10269             if ( s4.compareTo( s1 ) <= 0 ) {
10270                 return false;
10271             }
10272             if ( !s4.getSpeciesId().equals( "b" ) ) {
10273                 return false;
10274             }
10275             final Species s5 = new BasicSpecies( " C " );
10276             if ( !s5.getSpeciesId().equals( "C" ) ) {
10277                 return false;
10278             }
10279             if ( s5.equals( s1 ) ) {
10280                 return false;
10281             }
10282         }
10283         catch ( final Exception e ) {
10284             e.printStackTrace( System.out );
10285             return false;
10286         }
10287         return true;
10288     }
10289
10290     private static boolean testSplit() {
10291         try {
10292             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10293             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
10294             //Archaeopteryx.createApplication( p0 );
10295             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
10296             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10297             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10298             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10299             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10300             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10301             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10302             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10303             ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10304             ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10305             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
10306             // System.out.println( s0.toString() );
10307             //
10308             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
10309             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10310             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10311             if ( s0.match( query_nodes ) ) {
10312                 return false;
10313             }
10314             query_nodes = new HashSet<PhylogenyNode>();
10315             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10316             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10317             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10318             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10319             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10320             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10321             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10322             if ( !s0.match( query_nodes ) ) {
10323                 return false;
10324             }
10325             //
10326             query_nodes = new HashSet<PhylogenyNode>();
10327             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10328             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10329             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10330             if ( !s0.match( query_nodes ) ) {
10331                 return false;
10332             }
10333             //
10334             query_nodes = new HashSet<PhylogenyNode>();
10335             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10336             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10337             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10338             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10339             if ( !s0.match( query_nodes ) ) {
10340                 return false;
10341             }
10342             //
10343             query_nodes = new HashSet<PhylogenyNode>();
10344             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10345             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10346             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10347             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10348             if ( !s0.match( query_nodes ) ) {
10349                 return false;
10350             }
10351             //
10352             query_nodes = new HashSet<PhylogenyNode>();
10353             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10354             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10355             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10356             if ( !s0.match( query_nodes ) ) {
10357                 return false;
10358             }
10359             //
10360             query_nodes = new HashSet<PhylogenyNode>();
10361             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10362             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10363             if ( !s0.match( query_nodes ) ) {
10364                 return false;
10365             }
10366             //
10367             query_nodes = new HashSet<PhylogenyNode>();
10368             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10369             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10370             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10371             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10372             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10373             if ( !s0.match( query_nodes ) ) {
10374                 return false;
10375             }
10376             //
10377             query_nodes = new HashSet<PhylogenyNode>();
10378             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10379             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10380             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10381             if ( !s0.match( query_nodes ) ) {
10382                 return false;
10383             }
10384             //
10385             query_nodes = new HashSet<PhylogenyNode>();
10386             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10387             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10388             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10389             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10390             if ( !s0.match( query_nodes ) ) {
10391                 return false;
10392             }
10393             //
10394             query_nodes = new HashSet<PhylogenyNode>();
10395             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10396             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10397             if ( s0.match( query_nodes ) ) {
10398                 return false;
10399             }
10400             //
10401             query_nodes = new HashSet<PhylogenyNode>();
10402             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10403             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10404             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10405             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10406             if ( s0.match( query_nodes ) ) {
10407                 return false;
10408             }
10409             //
10410             query_nodes = new HashSet<PhylogenyNode>();
10411             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10412             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10413             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10414             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10415             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10416             if ( s0.match( query_nodes ) ) {
10417                 return false;
10418             }
10419             //
10420             query_nodes = new HashSet<PhylogenyNode>();
10421             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10422             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10423             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10424             if ( s0.match( query_nodes ) ) {
10425                 return false;
10426             }
10427             //
10428             query_nodes = new HashSet<PhylogenyNode>();
10429             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10430             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10431             if ( s0.match( query_nodes ) ) {
10432                 return false;
10433             }
10434             //
10435             query_nodes = new HashSet<PhylogenyNode>();
10436             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10437             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10438             if ( s0.match( query_nodes ) ) {
10439                 return false;
10440             }
10441             //
10442             query_nodes = new HashSet<PhylogenyNode>();
10443             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10444             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10445             if ( s0.match( query_nodes ) ) {
10446                 return false;
10447             }
10448             //
10449             query_nodes = new HashSet<PhylogenyNode>();
10450             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10451             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10452             if ( s0.match( query_nodes ) ) {
10453                 return false;
10454             }
10455             //
10456             query_nodes = new HashSet<PhylogenyNode>();
10457             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10458             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10459             if ( s0.match( query_nodes ) ) {
10460                 return false;
10461             }
10462             //
10463             query_nodes = new HashSet<PhylogenyNode>();
10464             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10465             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10466             if ( s0.match( query_nodes ) ) {
10467                 return false;
10468             }
10469             //
10470             query_nodes = new HashSet<PhylogenyNode>();
10471             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10472             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10473             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10474             if ( s0.match( query_nodes ) ) {
10475                 return false;
10476             }
10477             //
10478             query_nodes = new HashSet<PhylogenyNode>();
10479             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10480             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10481             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10482             if ( s0.match( query_nodes ) ) {
10483                 return false;
10484             }
10485             //
10486             query_nodes = new HashSet<PhylogenyNode>();
10487             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10488             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10489             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10490             if ( s0.match( query_nodes ) ) {
10491                 return false;
10492             }
10493             //
10494             query_nodes = new HashSet<PhylogenyNode>();
10495             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10496             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10497             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10498             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10499             if ( s0.match( query_nodes ) ) {
10500                 return false;
10501             }
10502             /////////
10503             //            query_nodes = new HashSet<PhylogenyNode>();
10504             //            query_nodes.add( new PhylogenyNode( "X" ) );
10505             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10506             //            query_nodes.add( new PhylogenyNode( "A" ) );
10507             //            query_nodes.add( new PhylogenyNode( "B" ) );
10508             //            query_nodes.add( new PhylogenyNode( "C" ) );
10509             //            query_nodes.add( new PhylogenyNode( "D" ) );
10510             //            query_nodes.add( new PhylogenyNode( "E" ) );
10511             //            query_nodes.add( new PhylogenyNode( "F" ) );
10512             //            query_nodes.add( new PhylogenyNode( "G" ) );
10513             //            if ( !s0.match( query_nodes ) ) {
10514             //                return false;
10515             //            }
10516             //            query_nodes = new HashSet<PhylogenyNode>();
10517             //            query_nodes.add( new PhylogenyNode( "X" ) );
10518             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10519             //            query_nodes.add( new PhylogenyNode( "A" ) );
10520             //            query_nodes.add( new PhylogenyNode( "B" ) );
10521             //            query_nodes.add( new PhylogenyNode( "C" ) );
10522             //            if ( !s0.match( query_nodes ) ) {
10523             //                return false;
10524             //            }
10525             //            //
10526             //            query_nodes = new HashSet<PhylogenyNode>();
10527             //            query_nodes.add( new PhylogenyNode( "X" ) );
10528             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10529             //            query_nodes.add( new PhylogenyNode( "D" ) );
10530             //            query_nodes.add( new PhylogenyNode( "E" ) );
10531             //            query_nodes.add( new PhylogenyNode( "F" ) );
10532             //            query_nodes.add( new PhylogenyNode( "G" ) );
10533             //            if ( !s0.match( query_nodes ) ) {
10534             //                return false;
10535             //            }
10536             //            //
10537             //            query_nodes = new HashSet<PhylogenyNode>();
10538             //            query_nodes.add( new PhylogenyNode( "X" ) );
10539             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10540             //            query_nodes.add( new PhylogenyNode( "A" ) );
10541             //            query_nodes.add( new PhylogenyNode( "B" ) );
10542             //            query_nodes.add( new PhylogenyNode( "C" ) );
10543             //            query_nodes.add( new PhylogenyNode( "D" ) );
10544             //            if ( !s0.match( query_nodes ) ) {
10545             //                return false;
10546             //            }
10547             //            //
10548             //            query_nodes = new HashSet<PhylogenyNode>();
10549             //            query_nodes.add( new PhylogenyNode( "X" ) );
10550             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10551             //            query_nodes.add( new PhylogenyNode( "E" ) );
10552             //            query_nodes.add( new PhylogenyNode( "F" ) );
10553             //            query_nodes.add( new PhylogenyNode( "G" ) );
10554             //            if ( !s0.match( query_nodes ) ) {
10555             //                return false;
10556             //            }
10557             //            //
10558             //            query_nodes = new HashSet<PhylogenyNode>();
10559             //            query_nodes.add( new PhylogenyNode( "X" ) );
10560             //            query_nodes.add( new PhylogenyNode( "Y" ) );
10561             //            query_nodes.add( new PhylogenyNode( "F" ) );
10562             //            query_nodes.add( new PhylogenyNode( "G" ) );
10563             //            if ( !s0.match( query_nodes ) ) {
10564             //                return false;
10565             //            }
10566             //
10567             query_nodes = new HashSet<PhylogenyNode>();
10568             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10569             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10570             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10571             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10572             if ( s0.match( query_nodes ) ) {
10573                 return false;
10574             }
10575             //
10576             query_nodes = new HashSet<PhylogenyNode>();
10577             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10578             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10579             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10580             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10581             if ( s0.match( query_nodes ) ) {
10582                 return false;
10583             }
10584             ///////////////////////////
10585             //
10586             query_nodes = new HashSet<PhylogenyNode>();
10587             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10588             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10589             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10590             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10591             if ( s0.match( query_nodes ) ) {
10592                 return false;
10593             }
10594             //
10595             query_nodes = new HashSet<PhylogenyNode>();
10596             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10597             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10598             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10599             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10600             if ( s0.match( query_nodes ) ) {
10601                 return false;
10602             }
10603             //
10604             query_nodes = new HashSet<PhylogenyNode>();
10605             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10606             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10607             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10608             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10609             if ( s0.match( query_nodes ) ) {
10610                 return false;
10611             }
10612             //
10613             query_nodes = new HashSet<PhylogenyNode>();
10614             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10615             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10616             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10617             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10618             if ( s0.match( query_nodes ) ) {
10619                 return false;
10620             }
10621             //
10622             query_nodes = new HashSet<PhylogenyNode>();
10623             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10624             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10625             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10626             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10627             if ( s0.match( query_nodes ) ) {
10628                 return false;
10629             }
10630             //
10631             query_nodes = new HashSet<PhylogenyNode>();
10632             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10633             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10634             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10635             if ( s0.match( query_nodes ) ) {
10636                 return false;
10637             }
10638             //
10639             query_nodes = new HashSet<PhylogenyNode>();
10640             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10641             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10642             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10643             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10644             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10645             if ( s0.match( query_nodes ) ) {
10646                 return false;
10647             }
10648             //
10649             query_nodes = new HashSet<PhylogenyNode>();
10650             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10651             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10652             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10653             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10654             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10655             if ( s0.match( query_nodes ) ) {
10656                 return false;
10657             }
10658             //
10659             query_nodes = new HashSet<PhylogenyNode>();
10660             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10661             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10662             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10663             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10664             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10665             if ( s0.match( query_nodes ) ) {
10666                 return false;
10667             }
10668             //
10669             query_nodes = new HashSet<PhylogenyNode>();
10670             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10671             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10672             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10673             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10674             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10675             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10676             if ( s0.match( query_nodes ) ) {
10677                 return false;
10678             }
10679         }
10680         catch ( final Exception e ) {
10681             e.printStackTrace();
10682             return false;
10683         }
10684         return true;
10685     }
10686
10687     private static boolean testSplitStrict() {
10688         try {
10689             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10690             final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
10691             final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
10692             ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10693             ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10694             ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10695             ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10696             ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10697             ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10698             ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10699             final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
10700             Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
10701             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10702             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10703             if ( s0.match( query_nodes ) ) {
10704                 return false;
10705             }
10706             query_nodes = new HashSet<PhylogenyNode>();
10707             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10708             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10709             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10710             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10711             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10712             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10713             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10714             if ( !s0.match( query_nodes ) ) {
10715                 return false;
10716             }
10717             //
10718             query_nodes = new HashSet<PhylogenyNode>();
10719             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10720             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10721             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10722             if ( !s0.match( query_nodes ) ) {
10723                 return false;
10724             }
10725             //
10726             query_nodes = new HashSet<PhylogenyNode>();
10727             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10728             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10729             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10730             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10731             if ( !s0.match( query_nodes ) ) {
10732                 return false;
10733             }
10734             //
10735             query_nodes = new HashSet<PhylogenyNode>();
10736             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10737             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10738             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10739             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10740             if ( !s0.match( query_nodes ) ) {
10741                 return false;
10742             }
10743             //
10744             query_nodes = new HashSet<PhylogenyNode>();
10745             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10746             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10747             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10748             if ( !s0.match( query_nodes ) ) {
10749                 return false;
10750             }
10751             //
10752             query_nodes = new HashSet<PhylogenyNode>();
10753             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10754             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10755             if ( !s0.match( query_nodes ) ) {
10756                 return false;
10757             }
10758             //
10759             query_nodes = new HashSet<PhylogenyNode>();
10760             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10761             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10762             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10763             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10764             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10765             if ( !s0.match( query_nodes ) ) {
10766                 return false;
10767             }
10768             //
10769             query_nodes = new HashSet<PhylogenyNode>();
10770             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10771             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10772             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10773             if ( !s0.match( query_nodes ) ) {
10774                 return false;
10775             }
10776             //
10777             query_nodes = new HashSet<PhylogenyNode>();
10778             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10779             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10780             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10781             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10782             if ( !s0.match( query_nodes ) ) {
10783                 return false;
10784             }
10785             //
10786             query_nodes = new HashSet<PhylogenyNode>();
10787             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10788             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10789             if ( s0.match( query_nodes ) ) {
10790                 return false;
10791             }
10792             //
10793             query_nodes = new HashSet<PhylogenyNode>();
10794             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10795             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10796             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10797             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10798             if ( s0.match( query_nodes ) ) {
10799                 return false;
10800             }
10801             //
10802             query_nodes = new HashSet<PhylogenyNode>();
10803             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10804             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10805             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10806             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10807             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10808             if ( s0.match( query_nodes ) ) {
10809                 return false;
10810             }
10811             //
10812             query_nodes = new HashSet<PhylogenyNode>();
10813             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10814             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10815             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10816             if ( s0.match( query_nodes ) ) {
10817                 return false;
10818             }
10819             //
10820             query_nodes = new HashSet<PhylogenyNode>();
10821             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10822             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10823             if ( s0.match( query_nodes ) ) {
10824                 return false;
10825             }
10826             //
10827             query_nodes = new HashSet<PhylogenyNode>();
10828             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10829             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10830             if ( s0.match( query_nodes ) ) {
10831                 return false;
10832             }
10833             //
10834             query_nodes = new HashSet<PhylogenyNode>();
10835             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10836             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10837             if ( s0.match( query_nodes ) ) {
10838                 return false;
10839             }
10840             //
10841             query_nodes = new HashSet<PhylogenyNode>();
10842             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10843             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10844             if ( s0.match( query_nodes ) ) {
10845                 return false;
10846             }
10847             //
10848             query_nodes = new HashSet<PhylogenyNode>();
10849             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10850             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10851             if ( s0.match( query_nodes ) ) {
10852                 return false;
10853             }
10854             //
10855             query_nodes = new HashSet<PhylogenyNode>();
10856             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10857             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10858             if ( s0.match( query_nodes ) ) {
10859                 return false;
10860             }
10861             //
10862             query_nodes = new HashSet<PhylogenyNode>();
10863             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10864             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10865             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10866             if ( s0.match( query_nodes ) ) {
10867                 return false;
10868             }
10869             //
10870             query_nodes = new HashSet<PhylogenyNode>();
10871             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10872             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10873             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10874             if ( s0.match( query_nodes ) ) {
10875                 return false;
10876             }
10877             //
10878             query_nodes = new HashSet<PhylogenyNode>();
10879             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10880             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10881             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10882             if ( s0.match( query_nodes ) ) {
10883                 return false;
10884             }
10885             //
10886             query_nodes = new HashSet<PhylogenyNode>();
10887             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10888             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10889             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10890             query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10891             if ( s0.match( query_nodes ) ) {
10892                 return false;
10893             }
10894         }
10895         catch ( final Exception e ) {
10896             e.printStackTrace();
10897             return false;
10898         }
10899         return true;
10900     }
10901
10902     private static boolean testSubtreeDeletion() {
10903         try {
10904             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10905             final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
10906             t1.deleteSubtree( t1.getNode( "A" ), false );
10907             if ( t1.getNumberOfExternalNodes() != 5 ) {
10908                 return false;
10909             }
10910             t1.toNewHampshireX();
10911             t1.deleteSubtree( t1.getNode( "E" ), false );
10912             if ( t1.getNumberOfExternalNodes() != 4 ) {
10913                 return false;
10914             }
10915             t1.toNewHampshireX();
10916             t1.deleteSubtree( t1.getNode( "F" ), false );
10917             if ( t1.getNumberOfExternalNodes() != 3 ) {
10918                 return false;
10919             }
10920             t1.toNewHampshireX();
10921             t1.deleteSubtree( t1.getNode( "D" ), false );
10922             t1.toNewHampshireX();
10923             if ( t1.getNumberOfExternalNodes() != 3 ) {
10924                 return false;
10925             }
10926             t1.deleteSubtree( t1.getNode( "def" ), false );
10927             t1.toNewHampshireX();
10928             if ( t1.getNumberOfExternalNodes() != 2 ) {
10929                 return false;
10930             }
10931             t1.deleteSubtree( t1.getNode( "B" ), false );
10932             t1.toNewHampshireX();
10933             if ( t1.getNumberOfExternalNodes() != 1 ) {
10934                 return false;
10935             }
10936             t1.deleteSubtree( t1.getNode( "C" ), false );
10937             t1.toNewHampshireX();
10938             if ( t1.getNumberOfExternalNodes() != 1 ) {
10939                 return false;
10940             }
10941             t1.deleteSubtree( t1.getNode( "abc" ), false );
10942             t1.toNewHampshireX();
10943             if ( t1.getNumberOfExternalNodes() != 1 ) {
10944                 return false;
10945             }
10946             t1.deleteSubtree( t1.getNode( "r" ), false );
10947             if ( t1.getNumberOfExternalNodes() != 0 ) {
10948                 return false;
10949             }
10950             if ( !t1.isEmpty() ) {
10951                 return false;
10952             }
10953             final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
10954             t2.deleteSubtree( t2.getNode( "A" ), false );
10955             t2.toNewHampshireX();
10956             if ( t2.getNumberOfExternalNodes() != 5 ) {
10957                 return false;
10958             }
10959             t2.deleteSubtree( t2.getNode( "abc" ), false );
10960             t2.toNewHampshireX();
10961             if ( t2.getNumberOfExternalNodes() != 3 ) {
10962                 return false;
10963             }
10964             t2.deleteSubtree( t2.getNode( "def" ), false );
10965             t2.toNewHampshireX();
10966             if ( t2.getNumberOfExternalNodes() != 1 ) {
10967                 return false;
10968             }
10969         }
10970         catch ( final Exception e ) {
10971             e.printStackTrace( System.out );
10972             return false;
10973         }
10974         return true;
10975     }
10976
10977     private static boolean testSupportCount() {
10978         try {
10979             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10980             final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
10981             final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
10982                                                                       + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
10983                                                                       + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
10984                                                                       + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
10985                                                                       + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
10986                                                               new NHXParser() );
10987             SupportCount.count( t0_1, phylogenies_1, true, false );
10988             final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
10989             final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
10990                                                                       + "(((((A,B),C),D),E),((F,G),X))"
10991                                                                       + "(((((A,Y),B),C),D),((F,G),E))"
10992                                                                       + "(((((A,B),C),D),E),(F,G))"
10993                                                                       + "(((((A,B),C),D),E),(F,G))"
10994                                                                       + "(((((A,B),C),D),E),(F,G))"
10995                                                                       + "(((((A,B),C),D),E),(F,G),Z)"
10996                                                                       + "(((((A,B),C),D),E),(F,G))"
10997                                                                       + "((((((A,B),C),D),E),F),G)"
10998                                                                       + "(((((X,Y),F,G),E),((A,B),C)),D)",
10999                                                               new NHXParser() );
11000             SupportCount.count( t0_2, phylogenies_2, true, false );
11001             final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
11002             while ( it.hasNext() ) {
11003                 final PhylogenyNode n = it.next();
11004                 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
11005                     return false;
11006                 }
11007             }
11008             final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
11009             final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
11010                     + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
11011             SupportCount.count( t0_3, phylogenies_3, true, false );
11012             t0_3.reRoot( t0_3.getNode( "def" ).getId() );
11013             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
11014                 return false;
11015             }
11016             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
11017                 return false;
11018             }
11019             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
11020                 return false;
11021             }
11022             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
11023                 return false;
11024             }
11025             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
11026                 return false;
11027             }
11028             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
11029                 return false;
11030             }
11031             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
11032                 return false;
11033             }
11034             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
11035                 return false;
11036             }
11037             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
11038                 return false;
11039             }
11040             if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
11041                 return false;
11042             }
11043             final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11044             final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
11045                     + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
11046             SupportCount.count( t0_4, phylogenies_4, true, false );
11047             t0_4.reRoot( t0_4.getNode( "F" ).getId() );
11048             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
11049                 return false;
11050             }
11051             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
11052                 return false;
11053             }
11054             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
11055                 return false;
11056             }
11057             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
11058                 return false;
11059             }
11060             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
11061                 return false;
11062             }
11063             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
11064                 return false;
11065             }
11066             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
11067                 return false;
11068             }
11069             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
11070                 return false;
11071             }
11072             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
11073                 return false;
11074             }
11075             if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
11076                 return false;
11077             }
11078             Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11079             final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11080             double d = SupportCount.compare( b1, a, true, true, true );
11081             if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
11082                 return false;
11083             }
11084             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11085             final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11086             d = SupportCount.compare( b2, a, true, true, true );
11087             if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
11088                 return false;
11089             }
11090             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
11091             final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
11092             d = SupportCount.compare( b3, a, true, true, true );
11093             if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
11094                 return false;
11095             }
11096             a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
11097             final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
11098             d = SupportCount.compare( b4, a, true, true, false );
11099             if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
11100                 return false;
11101             }
11102         }
11103         catch ( final Exception e ) {
11104             e.printStackTrace( System.out );
11105             return false;
11106         }
11107         return true;
11108     }
11109
11110     private static boolean testSupportTransfer() {
11111         try {
11112             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11113             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)",
11114                                                  new NHXParser() )[ 0 ];
11115             final Phylogeny p2 = factory
11116                     .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 ];
11117             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
11118                 return false;
11119             }
11120             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
11121                 return false;
11122             }
11123             support_transfer.moveBranchLengthsToBootstrap( p1 );
11124             support_transfer.transferSupportValues( p1, p2 );
11125             if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
11126                 return false;
11127             }
11128             if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
11129                 return false;
11130             }
11131             if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
11132                 return false;
11133             }
11134             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
11135                 return false;
11136             }
11137             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
11138                 return false;
11139             }
11140             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
11141                 return false;
11142             }
11143             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
11144                 return false;
11145             }
11146             if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
11147                 return false;
11148             }
11149         }
11150         catch ( final Exception e ) {
11151             e.printStackTrace( System.out );
11152             return false;
11153         }
11154         return true;
11155     }
11156
11157     private static boolean testTaxonomyExtraction() {
11158         try {
11159             final PhylogenyNode n0 = PhylogenyNode
11160                     .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11161             if ( n0.getNodeData().isHasTaxonomy() ) {
11162                 return false;
11163             }
11164             final PhylogenyNode n1 = PhylogenyNode
11165                     .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11166             if ( n1.getNodeData().isHasTaxonomy() ) {
11167                 System.out.println( n1.toString() );
11168                 return false;
11169             }
11170             final PhylogenyNode n2x = PhylogenyNode
11171                     .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11172             if ( n2x.getNodeData().isHasTaxonomy() ) {
11173                 return false;
11174             }
11175             final PhylogenyNode n3 = PhylogenyNode
11176                     .createInstanceFromNhxString( "blag_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11177             if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
11178                 System.out.println( n3.toString() );
11179                 return false;
11180             }
11181             final PhylogenyNode n4 = PhylogenyNode
11182                     .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11183             if ( n4.getNodeData().isHasTaxonomy() ) {
11184                 System.out.println( n4.toString() );
11185                 return false;
11186             }
11187             final PhylogenyNode n5 = PhylogenyNode
11188                     .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11189             if ( n5.getNodeData().isHasTaxonomy() ) {
11190                 System.out.println( n5.toString() );
11191                 return false;
11192             }
11193             final PhylogenyNode n6 = PhylogenyNode
11194                     .createInstanceFromNhxString( "blag-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11195             if ( n6.getNodeData().isHasTaxonomy() ) {
11196                 System.out.println( n6.toString() );
11197                 return false;
11198             }
11199             final PhylogenyNode n7 = PhylogenyNode
11200                     .createInstanceFromNhxString( "blag-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11201             if ( n7.getNodeData().isHasTaxonomy() ) {
11202                 System.out.println( n7.toString() );
11203                 return false;
11204             }
11205             final PhylogenyNode n8 = PhylogenyNode
11206                     .createInstanceFromNhxString( "blag_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11207             if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
11208                 System.out.println( n8.toString() );
11209                 return false;
11210             }
11211             final PhylogenyNode n9 = PhylogenyNode
11212                     .createInstanceFromNhxString( "blag_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11213             if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
11214                 System.out.println( n9.toString() );
11215                 return false;
11216             }
11217             final PhylogenyNode n10x = PhylogenyNode
11218                     .createInstanceFromNhxString( "blag_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11219             if ( n10x.getNodeData().isHasTaxonomy() ) {
11220                 System.out.println( n10x.toString() );
11221                 return false;
11222             }
11223             final PhylogenyNode n10xx = PhylogenyNode
11224                     .createInstanceFromNhxString( "blag_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11225             if ( n10xx.getNodeData().isHasTaxonomy() ) {
11226                 System.out.println( n10xx.toString() );
11227                 return false;
11228             }
11229             final PhylogenyNode n10 = PhylogenyNode
11230                     .createInstanceFromNhxString( "blag_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
11231             if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
11232                 System.out.println( n10.toString() );
11233                 return false;
11234             }
11235             final PhylogenyNode n11 = PhylogenyNode
11236                     .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11237             if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
11238                 System.out.println( n11.toString() );
11239                 return false;
11240             }
11241             final PhylogenyNode n12 = PhylogenyNode
11242                     .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
11243                                                   NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11244             if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
11245                 System.out.println( n12.toString() );
11246                 return false;
11247             }
11248             final PhylogenyNode n13 = PhylogenyNode
11249                     .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11250             if ( n13.getNodeData().isHasTaxonomy() ) {
11251                 System.out.println( n13.toString() );
11252                 return false;
11253             }
11254         }
11255         catch ( final Exception e ) {
11256             e.printStackTrace( System.out );
11257             return false;
11258         }
11259         return true;
11260     }
11261
11262     private static boolean testTreeMethods() {
11263         try {
11264             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11265             final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
11266             PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
11267             if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
11268                 System.out.println( t0.toNewHampshireX() );
11269                 return false;
11270             }
11271             final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
11272             PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
11273             if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
11274                 return false;
11275             }
11276             if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
11277                 return false;
11278             }
11279             if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
11280                 return false;
11281             }
11282         }
11283         catch ( final Exception e ) {
11284             e.printStackTrace( System.out );
11285             return false;
11286         }
11287         return true;
11288     }
11289
11290     private static boolean testSequenceDbWsTools1() {
11291         try {
11292             final PhylogenyNode n = new PhylogenyNode();
11293             n.setName( "NP_001025424" );
11294             Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
11295             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11296                     || !acc.getValue().equals( "NP_001025424" ) ) {
11297                 return false;
11298             }
11299             n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
11300             acc = SequenceDbWsTools.obtainSeqAccession( n );
11301             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11302                     || !acc.getValue().equals( "NP_001025424" ) ) {
11303                 return false;
11304             }
11305             n.setName( "NP_001025424.1" );
11306             acc = SequenceDbWsTools.obtainSeqAccession( n );
11307             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11308                     || !acc.getValue().equals( "NP_001025424" ) ) {
11309                 return false;
11310             }
11311             n.setName( "NM_001030253" );
11312             acc = SequenceDbWsTools.obtainSeqAccession( n );
11313             if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11314                     || !acc.getValue().equals( "NM_001030253" ) ) {
11315                 return false;
11316             }
11317             n.setName( "BCL2_HUMAN" );
11318             acc = SequenceDbWsTools.obtainSeqAccession( n );
11319             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11320                     || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
11321                 System.out.println( acc.toString() );
11322                 return false;
11323             }
11324             n.setName( "P10415" );
11325             acc = SequenceDbWsTools.obtainSeqAccession( n );
11326             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11327                     || !acc.getValue().equals( "P10415" ) ) {
11328                 System.out.println( acc.toString() );
11329                 return false;
11330             }
11331             n.setName( " P10415 " );
11332             acc = SequenceDbWsTools.obtainSeqAccession( n );
11333             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11334                     || !acc.getValue().equals( "P10415" ) ) {
11335                 System.out.println( acc.toString() );
11336                 return false;
11337             }
11338             n.setName( "_P10415|" );
11339             acc = SequenceDbWsTools.obtainSeqAccession( n );
11340             if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11341                     || !acc.getValue().equals( "P10415" ) ) {
11342                 System.out.println( acc.toString() );
11343                 return false;
11344             }
11345             n.setName( "AY695820" );
11346             acc = SequenceDbWsTools.obtainSeqAccession( n );
11347             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11348                     || !acc.getValue().equals( "AY695820" ) ) {
11349                 System.out.println( acc.toString() );
11350                 return false;
11351             }
11352             n.setName( "_AY695820_" );
11353             acc = SequenceDbWsTools.obtainSeqAccession( n );
11354             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11355                     || !acc.getValue().equals( "AY695820" ) ) {
11356                 System.out.println( acc.toString() );
11357                 return false;
11358             }
11359             n.setName( "AAA59452" );
11360             acc = SequenceDbWsTools.obtainSeqAccession( n );
11361             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11362                     || !acc.getValue().equals( "AAA59452" ) ) {
11363                 System.out.println( acc.toString() );
11364                 return false;
11365             }
11366             n.setName( "_AAA59452_" );
11367             acc = SequenceDbWsTools.obtainSeqAccession( n );
11368             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11369                     || !acc.getValue().equals( "AAA59452" ) ) {
11370                 System.out.println( acc.toString() );
11371                 return false;
11372             }
11373             n.setName( "AAA59452.1" );
11374             acc = SequenceDbWsTools.obtainSeqAccession( n );
11375             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11376                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11377                 System.out.println( acc.toString() );
11378                 return false;
11379             }
11380             n.setName( "_AAA59452.1_" );
11381             acc = SequenceDbWsTools.obtainSeqAccession( n );
11382             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11383                     || !acc.getValue().equals( "AAA59452.1" ) ) {
11384                 System.out.println( acc.toString() );
11385                 return false;
11386             }
11387             n.setName( "GI:94894583" );
11388             acc = SequenceDbWsTools.obtainSeqAccession( n );
11389             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11390                     || !acc.getValue().equals( "94894583" ) ) {
11391                 System.out.println( acc.toString() );
11392                 return false;
11393             }
11394             n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11395             acc = SequenceDbWsTools.obtainSeqAccession( n );
11396             if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11397                     || !acc.getValue().equals( "71845847" ) ) {
11398                 System.out.println( acc.toString() );
11399                 return false;
11400             }
11401             n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11402             acc = SequenceDbWsTools.obtainSeqAccession( n );
11403             if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11404                     || !acc.getValue().equals( "AAZ45343.1" ) ) {
11405                 System.out.println( acc.toString() );
11406                 return false;
11407             }
11408         }
11409         catch ( final Exception e ) {
11410             return false;
11411         }
11412         return true;
11413     }
11414
11415     private static boolean testSequenceDbWsTools2() {
11416         try {
11417             final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
11418             SequenceDbWsTools.obtainSeqInformation( n1 );
11419             if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
11420                 return false;
11421             }
11422             if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11423                 return false;
11424             }
11425             if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11426                 return false;
11427             }
11428             if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
11429                 return false;
11430             }
11431             final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
11432             SequenceDbWsTools.obtainSeqInformation( n2 );
11433             if ( !n2.getNodeData().getSequence().getName()
11434                     .equals( "Danio rerio B-cell leukemia/lymphoma 2 (bcl2), mRNA" ) ) {
11435                 return false;
11436             }
11437             if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11438                 return false;
11439             }
11440             if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11441                 return false;
11442             }
11443             if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
11444                 return false;
11445             }
11446             final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
11447             SequenceDbWsTools.obtainSeqInformation( n3 );
11448             if ( !n3.getNodeData().getSequence().getName()
11449                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
11450                 return false;
11451             }
11452             if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
11453                 return false;
11454             }
11455             if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11456                 return false;
11457             }
11458             if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
11459                 return false;
11460             }
11461         }
11462         catch ( final IOException e ) {
11463             System.out.println();
11464             System.out.println( "the following might be due to absence internet connection:" );
11465             e.printStackTrace( System.out );
11466             return true;
11467         }
11468         catch ( final Exception e ) {
11469             e.printStackTrace();
11470             return false;
11471         }
11472         return true;
11473     }
11474
11475     private static boolean testEbiEntryRetrieval() {
11476         try {
11477             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
11478             if ( !entry.getAccession().equals( "AAK41263" ) ) {
11479                 System.out.println( entry.getAccession() );
11480                 return false;
11481             }
11482             if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
11483                 System.out.println( entry.getTaxonomyScientificName() );
11484                 return false;
11485             }
11486             if ( !entry.getSequenceName()
11487                     .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
11488                 System.out.println( entry.getSequenceName() );
11489                 return false;
11490             }
11491             // if ( !entry.getSequenceSymbol().equals( "" ) ) {
11492             //     System.out.println( entry.getSequenceSymbol() );
11493             //     return false;
11494             // }
11495             if ( !entry.getGeneName().equals( "treX-like" ) ) {
11496                 System.out.println( entry.getGeneName() );
11497                 return false;
11498             }
11499             if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
11500                 System.out.println( entry.getTaxonomyIdentifier() );
11501                 return false;
11502             }
11503             if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
11504                 System.out.println( entry.getAnnotations().first().getRefValue() );
11505                 return false;
11506             }
11507             if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
11508                 System.out.println( entry.getAnnotations().first().getRefSource() );
11509                 return false;
11510             }
11511             if ( entry.getCrossReferences().size() != 5 ) {
11512                 return false;
11513             }
11514             //
11515             final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
11516             if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
11517                 return false;
11518             }
11519             if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
11520                 System.out.println( entry1.getTaxonomyScientificName() );
11521                 return false;
11522             }
11523             if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
11524                 System.out.println( entry1.getSequenceName() );
11525                 return false;
11526             }
11527             if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
11528                 System.out.println( entry1.getTaxonomyIdentifier() );
11529                 return false;
11530             }
11531             if ( !entry1.getGeneName().equals( "BCL2" ) ) {
11532                 System.out.println( entry1.getGeneName() );
11533                 return false;
11534             }
11535             if ( entry1.getCrossReferences().size() != 6 ) {
11536                 return false;
11537             }
11538             //
11539             final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
11540             if ( !entry2.getAccession().equals( "NM_184234" ) ) {
11541                 return false;
11542             }
11543             if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
11544                 System.out.println( entry2.getTaxonomyScientificName() );
11545                 return false;
11546             }
11547             if ( !entry2.getSequenceName()
11548                     .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
11549                 System.out.println( entry2.getSequenceName() );
11550                 return false;
11551             }
11552             if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
11553                 System.out.println( entry2.getTaxonomyIdentifier() );
11554                 return false;
11555             }
11556             if ( !entry2.getGeneName().equals( "RBM39" ) ) {
11557                 System.out.println( entry2.getGeneName() );
11558                 return false;
11559             }
11560             if ( entry2.getCrossReferences().size() != 3 ) {
11561                 return false;
11562             }
11563             //
11564             final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
11565             if ( !entry3.getAccession().equals( "HM043801" ) ) {
11566                 return false;
11567             }
11568             if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
11569                 System.out.println( entry3.getTaxonomyScientificName() );
11570                 return false;
11571             }
11572             if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
11573                 System.out.println( entry3.getSequenceName() );
11574                 return false;
11575             }
11576             if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
11577                 System.out.println( entry3.getTaxonomyIdentifier() );
11578                 return false;
11579             }
11580             if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
11581                 System.out.println( entry3.getSequenceSymbol() );
11582                 return false;
11583             }
11584             if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
11585                 return false;
11586             }
11587             if ( entry3.getCrossReferences().size() != 8 ) {
11588                 return false;
11589             }
11590             //
11591             //
11592             final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
11593             if ( !entry4.getAccession().equals( "AAA36557" ) ) {
11594                 return false;
11595             }
11596             if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
11597                 System.out.println( entry4.getTaxonomyScientificName() );
11598                 return false;
11599             }
11600             if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
11601                 System.out.println( entry4.getSequenceName() );
11602                 return false;
11603             }
11604             if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
11605                 System.out.println( entry4.getTaxonomyIdentifier() );
11606                 return false;
11607             }
11608             if ( !entry4.getGeneName().equals( "ras" ) ) {
11609                 System.out.println( entry4.getGeneName() );
11610                 return false;
11611             }
11612             //   if ( !entry4.getChromosome().equals( "ras" ) ) {
11613             //     System.out.println( entry4.getChromosome() );
11614             //     return false;
11615             // }
11616             // if ( !entry4.getMap().equals( "ras" ) ) {
11617             //     System.out.println( entry4.getMap() );
11618             //     return false;
11619             // }
11620             //TODO FIXME gi...
11621             //
11622             //TODO fails:
11623             //            final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "M30539" );
11624             //            if ( !entry5.getAccession().equals( "HM043801" ) ) {
11625             //                return false;
11626             //            }
11627             final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
11628             if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
11629                 return false;
11630             }
11631             if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
11632                 System.out.println( entry5.getTaxonomyScientificName() );
11633                 return false;
11634             }
11635             if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
11636                 System.out.println( entry5.getSequenceName() );
11637                 return false;
11638             }
11639             if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
11640                 System.out.println( entry5.getTaxonomyIdentifier() );
11641                 return false;
11642             }
11643         }
11644         catch ( final IOException e ) {
11645             System.out.println();
11646             System.out.println( "the following might be due to absence internet connection:" );
11647             e.printStackTrace( System.out );
11648             return true;
11649         }
11650         catch ( final Exception e ) {
11651             e.printStackTrace();
11652             return false;
11653         }
11654         return true;
11655     }
11656
11657     private static boolean testUniprotEntryRetrieval() {
11658         try {
11659             final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
11660             if ( !entry.getAccession().equals( "P12345" ) ) {
11661                 return false;
11662             }
11663             if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
11664                 return false;
11665             }
11666             if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
11667                 return false;
11668             }
11669             if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
11670                 return false;
11671             }
11672             if ( !entry.getGeneName().equals( "GOT2" ) ) {
11673                 return false;
11674             }
11675             if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
11676                 return false;
11677             }
11678         }
11679         catch ( final IOException e ) {
11680             System.out.println();
11681             System.out.println( "the following might be due to absence internet connection:" );
11682             e.printStackTrace( System.out );
11683             return true;
11684         }
11685         catch ( final Exception e ) {
11686             return false;
11687         }
11688         return true;
11689     }
11690
11691     private static boolean testUniprotTaxonomySearch() {
11692         try {
11693             List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
11694                                                                                                  10 );
11695             if ( results.size() != 1 ) {
11696                 return false;
11697             }
11698             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11699                 return false;
11700             }
11701             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11702                 return false;
11703             }
11704             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11705                 return false;
11706             }
11707             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11708                 return false;
11709             }
11710             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11711                 return false;
11712             }
11713             results = null;
11714             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
11715             if ( results.size() != 1 ) {
11716                 return false;
11717             }
11718             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11719                 return false;
11720             }
11721             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11722                 return false;
11723             }
11724             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11725                 return false;
11726             }
11727             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11728                 return false;
11729             }
11730             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11731                 return false;
11732             }
11733             results = null;
11734             results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
11735             if ( results.size() != 1 ) {
11736                 return false;
11737             }
11738             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11739                 return false;
11740             }
11741             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11742                 return false;
11743             }
11744             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11745                 return false;
11746             }
11747             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11748                 return false;
11749             }
11750             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11751                 return false;
11752             }
11753             results = null;
11754             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
11755             if ( results.size() != 1 ) {
11756                 return false;
11757             }
11758             if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11759                 return false;
11760             }
11761             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11762                 return false;
11763             }
11764             if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11765                 return false;
11766             }
11767             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11768                 return false;
11769             }
11770             if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11771                 return false;
11772             }
11773             if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
11774                 return false;
11775             }
11776             if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
11777                 return false;
11778             }
11779             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11780                     .equals( "Nematostella vectensis" ) ) {
11781                 System.out.println( results.get( 0 ).getLineage() );
11782                 return false;
11783             }
11784             //
11785             results = null;
11786             results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
11787             if ( results.size() != 1 ) {
11788                 return false;
11789             }
11790             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11791                 return false;
11792             }
11793             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11794                 return false;
11795             }
11796             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11797                 return false;
11798             }
11799             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11800                 return false;
11801             }
11802             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11803                 return false;
11804             }
11805             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11806                     .equals( "Xenopus tropicalis" ) ) {
11807                 System.out.println( results.get( 0 ).getLineage() );
11808                 return false;
11809             }
11810             //
11811             results = null;
11812             results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
11813             if ( results.size() != 1 ) {
11814                 return false;
11815             }
11816             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11817                 return false;
11818             }
11819             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11820                 return false;
11821             }
11822             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11823                 return false;
11824             }
11825             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11826                 return false;
11827             }
11828             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11829                 return false;
11830             }
11831             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11832                     .equals( "Xenopus tropicalis" ) ) {
11833                 System.out.println( results.get( 0 ).getLineage() );
11834                 return false;
11835             }
11836             //
11837             results = null;
11838             results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
11839             if ( results.size() != 1 ) {
11840                 return false;
11841             }
11842             if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
11843                 return false;
11844             }
11845             if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
11846                 return false;
11847             }
11848             if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
11849                 return false;
11850             }
11851             if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11852                 return false;
11853             }
11854             if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
11855                 return false;
11856             }
11857             if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11858                     .equals( "Xenopus tropicalis" ) ) {
11859                 System.out.println( results.get( 0 ).getLineage() );
11860                 return false;
11861             }
11862         }
11863         catch ( final IOException e ) {
11864             System.out.println();
11865             System.out.println( "the following might be due to absence internet connection:" );
11866             e.printStackTrace( System.out );
11867             return true;
11868         }
11869         catch ( final Exception e ) {
11870             return false;
11871         }
11872         return true;
11873     }
11874
11875     private static boolean testWabiTxSearch() {
11876         try {
11877             String result = "";
11878             result = TxSearch.searchSimple( "nematostella" );
11879             result = TxSearch.getTxId( "nematostella" );
11880             if ( !result.equals( "45350" ) ) {
11881                 return false;
11882             }
11883             result = TxSearch.getTxName( "45350" );
11884             if ( !result.equals( "Nematostella" ) ) {
11885                 return false;
11886             }
11887             result = TxSearch.getTxId( "nematostella vectensis" );
11888             if ( !result.equals( "45351" ) ) {
11889                 return false;
11890             }
11891             result = TxSearch.getTxName( "45351" );
11892             if ( !result.equals( "Nematostella vectensis" ) ) {
11893                 return false;
11894             }
11895             result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
11896             if ( !result.equals( "536089" ) ) {
11897                 return false;
11898             }
11899             result = TxSearch.getTxName( "536089" );
11900             if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
11901                 return false;
11902             }
11903             final List<String> queries = new ArrayList<String>();
11904             queries.add( "Campylobacter coli" );
11905             queries.add( "Escherichia coli" );
11906             queries.add( "Arabidopsis" );
11907             queries.add( "Trichoplax" );
11908             queries.add( "Samanea saman" );
11909             queries.add( "Kluyveromyces marxianus" );
11910             queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
11911             queries.add( "Bornavirus parrot/PDD/2008" );
11912             final List<RANKS> ranks = new ArrayList<RANKS>();
11913             ranks.add( RANKS.SUPERKINGDOM );
11914             ranks.add( RANKS.KINGDOM );
11915             ranks.add( RANKS.FAMILY );
11916             ranks.add( RANKS.GENUS );
11917             ranks.add( RANKS.TRIBE );
11918             result = TxSearch.searchLineage( queries, ranks );
11919             result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
11920             result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
11921         }
11922         catch ( final Exception e ) {
11923             System.out.println();
11924             System.out.println( "the following might be due to absence internet connection:" );
11925             e.printStackTrace( System.out );
11926             return false;
11927         }
11928         return true;
11929     }
11930 }