2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
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.
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.
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
23 // Contact: phylosoft @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
26 package org.forester.test;
28 import java.io.ByteArrayInputStream;
30 import java.io.FileInputStream;
31 import java.io.IOException;
32 import java.util.ArrayList;
33 import java.util.Date;
34 import java.util.HashSet;
35 import java.util.Iterator;
36 import java.util.List;
37 import java.util.Locale;
40 import org.forester.application.support_transfer;
41 import org.forester.archaeopteryx.AptxUtil;
42 import org.forester.development.DevelopmentTools;
43 import org.forester.evoinference.TestPhylogenyReconstruction;
44 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
45 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
46 import org.forester.go.TestGo;
47 import org.forester.io.parsers.FastaParser;
48 import org.forester.io.parsers.GeneralMsaParser;
49 import org.forester.io.parsers.HmmscanPerDomainTableParser;
50 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
51 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
52 import org.forester.io.parsers.nexus.NexusCharactersParser;
53 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
54 import org.forester.io.parsers.nhx.NHXParser;
55 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
56 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
57 import org.forester.io.parsers.tol.TolParser;
58 import org.forester.io.parsers.util.ParserUtils;
59 import org.forester.io.writers.PhylogenyWriter;
60 import org.forester.msa.BasicMsa;
61 import org.forester.msa.Mafft;
62 import org.forester.msa.Msa;
63 import org.forester.msa.MsaInferrer;
64 import org.forester.msa.MsaMethods;
65 import org.forester.pccx.TestPccx;
66 import org.forester.phylogeny.Phylogeny;
67 import org.forester.phylogeny.PhylogenyBranch;
68 import org.forester.phylogeny.PhylogenyMethods;
69 import org.forester.phylogeny.PhylogenyNode;
70 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
71 import org.forester.phylogeny.data.Accession;
72 import org.forester.phylogeny.data.BinaryCharacters;
73 import org.forester.phylogeny.data.BranchWidth;
74 import org.forester.phylogeny.data.Confidence;
75 import org.forester.phylogeny.data.Distribution;
76 import org.forester.phylogeny.data.DomainArchitecture;
77 import org.forester.phylogeny.data.Event;
78 import org.forester.phylogeny.data.Identifier;
79 import org.forester.phylogeny.data.PhylogenyData;
80 import org.forester.phylogeny.data.PhylogenyDataUtil;
81 import org.forester.phylogeny.data.Polygon;
82 import org.forester.phylogeny.data.PropertiesMap;
83 import org.forester.phylogeny.data.Property;
84 import org.forester.phylogeny.data.Property.AppliesTo;
85 import org.forester.phylogeny.data.ProteinDomain;
86 import org.forester.phylogeny.data.Taxonomy;
87 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
88 import org.forester.phylogeny.factories.PhylogenyFactory;
89 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
90 import org.forester.protein.Protein;
91 import org.forester.rio.TestRIO;
92 import org.forester.sdi.SDI;
93 import org.forester.sdi.SDIR;
94 import org.forester.sdi.TestGSDI;
95 import org.forester.sequence.BasicSequence;
96 import org.forester.sequence.Sequence;
97 import org.forester.surfacing.TestSurfacing;
98 import org.forester.tools.ConfidenceAssessor;
99 import org.forester.tools.SupportCount;
100 import org.forester.tools.TreeSplitMatrix;
101 import org.forester.util.AsciiHistogram;
102 import org.forester.util.BasicDescriptiveStatistics;
103 import org.forester.util.BasicTable;
104 import org.forester.util.BasicTableParser;
105 import org.forester.util.DescriptiveStatistics;
106 import org.forester.util.ForesterConstants;
107 import org.forester.util.ForesterUtil;
108 import org.forester.util.GeneralTable;
109 import org.forester.util.SequenceIdParser;
110 import org.forester.ws.seqdb.SequenceDatabaseEntry;
111 import org.forester.ws.seqdb.SequenceDbWsTools;
112 import org.forester.ws.seqdb.UniProtTaxonomy;
113 import org.forester.ws.wabi.TxSearch;
114 import org.forester.ws.wabi.TxSearch.RANKS;
115 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
116 import org.forester.ws.wabi.TxSearch.TAX_RANK;
118 @SuppressWarnings( "unused")
119 public final class Test {
121 private final static double ZERO_DIFF = 1.0E-9;
122 private final static String PATH_TO_TEST_DATA = System.getProperty( "user.dir" )
123 + ForesterUtil.getFileSeparator() + "test_data"
124 + ForesterUtil.getFileSeparator();
125 private final static String PATH_TO_RESOURCES = System.getProperty( "user.dir" )
126 + ForesterUtil.getFileSeparator() + "resources"
127 + ForesterUtil.getFileSeparator();
128 private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
129 private static final String PHYLOXML_REMOTE_XSD = ForesterConstants.PHYLO_XML_LOCATION + "/"
130 + ForesterConstants.PHYLO_XML_VERSION + "/"
131 + ForesterConstants.PHYLO_XML_XSD;
132 private static final String PHYLOXML_LOCAL_XSD = PATH_TO_RESOURCES + "phyloxml_schema/"
133 + ForesterConstants.PHYLO_XML_VERSION + "/"
134 + ForesterConstants.PHYLO_XML_XSD;
136 private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
137 final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
141 private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
142 return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
145 public static boolean isEqual( final double a, final double b ) {
146 return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
149 public static void main( final String[] args ) {
150 System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
151 System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
153 Locale.setDefault( Locale.US );
154 System.out.println( "[Locale: " + Locale.getDefault() + "]" );
157 System.out.print( "[Test if directory with files for testing exists/is readable: " );
158 if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
159 System.out.println( "OK.]" );
162 System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
163 System.out.println( "Testing aborted." );
166 System.out.print( "[Test if resources directory exists/is readable: " );
167 if ( testDir( PATH_TO_RESOURCES ) ) {
168 System.out.println( "OK.]" );
171 System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
172 System.out.println( "Testing aborted." );
175 final long start_time = new Date().getTime();
176 System.out.print( "Sequence id parsing: " );
177 if ( testSequenceIdParsing() ) {
178 System.out.println( "OK." );
182 System.out.println( "failed." );
185 System.out.print( "Hmmscan output parser: " );
186 if ( testHmmscanOutputParser() ) {
187 System.out.println( "OK." );
191 System.out.println( "failed." );
194 System.out.print( "Basic node methods: " );
195 if ( Test.testBasicNodeMethods() ) {
196 System.out.println( "OK." );
200 System.out.println( "failed." );
203 System.out.print( "Taxonomy code extraction: " );
204 if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
205 System.out.println( "OK." );
209 System.out.println( "failed." );
212 System.out.print( "Taxonomy extraction (general): " );
213 if ( Test.testTaxonomyExtraction() ) {
214 System.out.println( "OK." );
218 System.out.println( "failed." );
221 System.out.print( "UniProtKB id extraction: " );
222 if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
223 System.out.println( "OK." );
227 System.out.println( "failed." );
230 System.out.print( "Uri for Aptx web sequence accession: " );
231 if ( Test.testCreateUriForSeqWeb() ) {
232 System.out.println( "OK." );
236 System.out.println( "failed." );
239 System.out.print( "Basic node construction and parsing of NHX (node level): " );
240 if ( Test.testNHXNodeParsing() ) {
241 System.out.println( "OK." );
245 System.out.println( "failed." );
248 System.out.print( "NHX parsing iterating: " );
249 if ( Test.testNHParsingIter() ) {
250 System.out.println( "OK." );
254 System.out.println( "failed." );
257 System.out.print( "NH parsing: " );
258 if ( Test.testNHParsing() ) {
259 System.out.println( "OK." );
263 System.out.println( "failed." );
266 System.out.print( "Conversion to NHX (node level): " );
267 if ( Test.testNHXconversion() ) {
268 System.out.println( "OK." );
272 System.out.println( "failed." );
275 System.out.print( "NHX parsing: " );
276 if ( Test.testNHXParsing() ) {
277 System.out.println( "OK." );
281 System.out.println( "failed." );
284 System.out.print( "NHX parsing with quotes: " );
285 if ( Test.testNHXParsingQuotes() ) {
286 System.out.println( "OK." );
290 System.out.println( "failed." );
293 System.out.print( "NHX parsing (MrBayes): " );
294 if ( Test.testNHXParsingMB() ) {
295 System.out.println( "OK." );
299 System.out.println( "failed." );
302 System.out.print( "Nexus characters parsing: " );
303 if ( Test.testNexusCharactersParsing() ) {
304 System.out.println( "OK." );
308 System.out.println( "failed." );
311 System.out.print( "Nexus tree parsing iterating: " );
312 if ( Test.testNexusTreeParsingIterating() ) {
313 System.out.println( "OK." );
317 System.out.println( "failed." );
320 System.out.print( "Nexus tree parsing: " );
321 if ( Test.testNexusTreeParsing() ) {
322 System.out.println( "OK." );
326 System.out.println( "failed." );
329 System.out.print( "Nexus tree parsing (translating): " );
330 if ( Test.testNexusTreeParsingTranslating() ) {
331 System.out.println( "OK." );
335 System.out.println( "failed." );
338 System.out.print( "Nexus matrix parsing: " );
339 if ( Test.testNexusMatrixParsing() ) {
340 System.out.println( "OK." );
344 System.out.println( "failed." );
347 System.out.print( "Basic phyloXML parsing: " );
348 if ( Test.testBasicPhyloXMLparsing() ) {
349 System.out.println( "OK." );
353 System.out.println( "failed." );
356 System.out.print( "Basic phyloXML parsing (validating against schema): " );
357 if ( testBasicPhyloXMLparsingValidating() ) {
358 System.out.println( "OK." );
362 System.out.println( "failed." );
365 System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
366 if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
367 System.out.println( "OK." );
371 System.out.println( "failed." );
374 System.out.print( "phyloXML Distribution Element: " );
375 if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
376 System.out.println( "OK." );
380 System.out.println( "failed." );
383 System.out.print( "Tol XML parsing: " );
384 if ( Test.testBasicTolXMLparsing() ) {
385 System.out.println( "OK." );
389 System.out.println( "failed." );
392 System.out.print( "Copying of node data: " );
393 if ( Test.testCopyOfNodeData() ) {
394 System.out.println( "OK." );
398 System.out.println( "failed." );
401 System.out.print( "Basic tree methods: " );
402 if ( Test.testBasicTreeMethods() ) {
403 System.out.println( "OK." );
407 System.out.println( "failed." );
410 System.out.print( "Tree methods: " );
411 if ( Test.testTreeMethods() ) {
412 System.out.println( "OK." );
416 System.out.println( "failed." );
419 System.out.print( "Postorder Iterator: " );
420 if ( Test.testPostOrderIterator() ) {
421 System.out.println( "OK." );
425 System.out.println( "failed." );
428 System.out.print( "Preorder Iterator: " );
429 if ( Test.testPreOrderIterator() ) {
430 System.out.println( "OK." );
434 System.out.println( "failed." );
437 System.out.print( "Levelorder Iterator: " );
438 if ( Test.testLevelOrderIterator() ) {
439 System.out.println( "OK." );
443 System.out.println( "failed." );
446 System.out.print( "Re-id methods: " );
447 if ( Test.testReIdMethods() ) {
448 System.out.println( "OK." );
452 System.out.println( "failed." );
455 System.out.print( "Methods on last external nodes: " );
456 if ( Test.testLastExternalNodeMethods() ) {
457 System.out.println( "OK." );
461 System.out.println( "failed." );
464 System.out.print( "Methods on external nodes: " );
465 if ( Test.testExternalNodeRelatedMethods() ) {
466 System.out.println( "OK." );
470 System.out.println( "failed." );
473 System.out.print( "Deletion of external nodes: " );
474 if ( Test.testDeletionOfExternalNodes() ) {
475 System.out.println( "OK." );
479 System.out.println( "failed." );
482 System.out.print( "Subtree deletion: " );
483 if ( Test.testSubtreeDeletion() ) {
484 System.out.println( "OK." );
488 System.out.println( "failed." );
491 System.out.print( "Phylogeny branch: " );
492 if ( Test.testPhylogenyBranch() ) {
493 System.out.println( "OK." );
497 System.out.println( "failed." );
500 System.out.print( "Rerooting: " );
501 if ( Test.testRerooting() ) {
502 System.out.println( "OK." );
506 System.out.println( "failed." );
509 System.out.print( "Mipoint rooting: " );
510 if ( Test.testMidpointrooting() ) {
511 System.out.println( "OK." );
515 System.out.println( "failed." );
518 System.out.print( "Node removal: " );
519 if ( Test.testNodeRemoval() ) {
520 System.out.println( "OK." );
524 System.out.println( "failed." );
527 System.out.print( "Support count: " );
528 if ( Test.testSupportCount() ) {
529 System.out.println( "OK." );
533 System.out.println( "failed." );
536 System.out.print( "Support transfer: " );
537 if ( Test.testSupportTransfer() ) {
538 System.out.println( "OK." );
542 System.out.println( "failed." );
545 System.out.print( "Finding of LCA: " );
546 if ( Test.testGetLCA() ) {
547 System.out.println( "OK." );
551 System.out.println( "failed." );
554 System.out.print( "Finding of LCA 2: " );
555 if ( Test.testGetLCA2() ) {
556 System.out.println( "OK." );
560 System.out.println( "failed." );
563 System.out.print( "Calculation of distance between nodes: " );
564 if ( Test.testGetDistance() ) {
565 System.out.println( "OK." );
569 System.out.println( "failed." );
572 System.out.print( "Descriptive statistics: " );
573 if ( Test.testDescriptiveStatistics() ) {
574 System.out.println( "OK." );
578 System.out.println( "failed." );
581 System.out.print( "Data objects and methods: " );
582 if ( Test.testDataObjects() ) {
583 System.out.println( "OK." );
587 System.out.println( "failed." );
590 System.out.print( "Properties map: " );
591 if ( Test.testPropertiesMap() ) {
592 System.out.println( "OK." );
596 System.out.println( "failed." );
599 System.out.print( "SDIse: " );
600 if ( Test.testSDIse() ) {
601 System.out.println( "OK." );
605 System.out.println( "failed." );
608 System.out.print( "SDIunrooted: " );
609 if ( Test.testSDIunrooted() ) {
610 System.out.println( "OK." );
614 System.out.println( "failed." );
617 System.out.print( "GSDI: " );
618 if ( TestGSDI.test() ) {
619 System.out.println( "OK." );
623 System.out.println( "failed." );
626 System.out.print( "RIO: " );
627 if ( TestRIO.test() ) {
628 System.out.println( "OK." );
632 System.out.println( "failed." );
635 System.out.print( "Phylogeny reconstruction:" );
636 System.out.println();
637 if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
638 System.out.println( "OK." );
642 System.out.println( "failed." );
645 System.out.print( "Analysis of domain architectures: " );
646 System.out.println();
647 if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
648 System.out.println( "OK." );
652 System.out.println( "failed." );
655 System.out.print( "GO: " );
656 System.out.println();
657 if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
658 System.out.println( "OK." );
662 System.out.println( "failed." );
665 System.out.print( "Modeling tools: " );
666 if ( TestPccx.test() ) {
667 System.out.println( "OK." );
671 System.out.println( "failed." );
674 System.out.print( "Split Matrix strict: " );
675 if ( Test.testSplitStrict() ) {
676 System.out.println( "OK." );
680 System.out.println( "failed." );
683 System.out.print( "Split Matrix: " );
684 if ( Test.testSplit() ) {
685 System.out.println( "OK." );
689 System.out.println( "failed." );
692 System.out.print( "Confidence Assessor: " );
693 if ( Test.testConfidenceAssessor() ) {
694 System.out.println( "OK." );
698 System.out.println( "failed." );
701 System.out.print( "Basic table: " );
702 if ( Test.testBasicTable() ) {
703 System.out.println( "OK." );
707 System.out.println( "failed." );
710 System.out.print( "General table: " );
711 if ( Test.testGeneralTable() ) {
712 System.out.println( "OK." );
716 System.out.println( "failed." );
719 System.out.print( "Amino acid sequence: " );
720 if ( Test.testAminoAcidSequence() ) {
721 System.out.println( "OK." );
725 System.out.println( "failed." );
728 System.out.print( "General MSA parser: " );
729 if ( Test.testGeneralMsaParser() ) {
730 System.out.println( "OK." );
734 System.out.println( "failed." );
737 System.out.print( "Fasta parser for msa: " );
738 if ( Test.testFastaParser() ) {
739 System.out.println( "OK." );
743 System.out.println( "failed." );
746 System.out.print( "Creation of balanced phylogeny: " );
747 if ( Test.testCreateBalancedPhylogeny() ) {
748 System.out.println( "OK." );
752 System.out.println( "failed." );
755 System.out.print( "EMBL Entry Retrieval: " );
756 if ( Test.testEmblEntryRetrieval() ) {
757 System.out.println( "OK." );
761 System.out.println( "failed." );
764 System.out.print( "Uniprot Entry Retrieval: " );
765 if ( Test.testUniprotEntryRetrieval() ) {
766 System.out.println( "OK." );
770 System.out.println( "failed." );
773 System.out.print( "Uniprot Taxonomy Search: " );
774 if ( Test.testUniprotTaxonomySearch() ) {
775 System.out.println( "OK." );
779 System.out.println( "failed." );
784 final String os = ForesterUtil.OS_NAME.toLowerCase();
785 if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
786 path = "/usr/local/bin/mafft";
788 else if ( os.indexOf( "win" ) >= 0 ) {
789 path = "C:\\Program Files\\mafft-win\\mafft.bat";
792 path = "/home/czmasek/bin/mafft";
794 if ( !MsaInferrer.isInstalled( path ) ) {
797 if ( !MsaInferrer.isInstalled( path ) ) {
798 path = "/usr/local/bin/mafft";
800 if ( MsaInferrer.isInstalled( path ) ) {
801 System.out.print( "MAFFT (external program): " );
802 if ( Test.testMafft( path ) ) {
803 System.out.println( "OK." );
807 System.out.println( "failed [will not count towards failed tests]" );
811 System.out.print( "Next nodes with collapsed: " );
812 if ( Test.testNextNodeWithCollapsing() ) {
813 System.out.println( "OK." );
817 System.out.println( "failed." );
820 System.out.print( "Simple MSA quality: " );
821 if ( Test.testMsaQualityMethod() ) {
822 System.out.println( "OK." );
826 System.out.println( "failed." );
829 System.out.println();
830 final Runtime rt = java.lang.Runtime.getRuntime();
831 final long free_memory = rt.freeMemory() / 1000000;
832 final long total_memory = rt.totalMemory() / 1000000;
833 System.out.println( "Running time : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
834 + free_memory + "MB, total memory: " + total_memory + "MB)" );
835 System.out.println();
836 System.out.println( "Successful tests: " + succeeded );
837 System.out.println( "Failed tests: " + failed );
838 System.out.println();
840 System.out.println( "OK." );
843 System.out.println( "Not OK." );
847 private static boolean testExtractUniProtKbProteinSeqIdentifier() {
849 PhylogenyNode n = new PhylogenyNode();
850 n.setName( "tr|B3RJ64" );
851 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
854 n.setName( "tr.B3RJ64" );
855 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
858 n.setName( "tr=B3RJ64" );
859 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
862 n.setName( "tr-B3RJ64" );
863 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
866 n.setName( "tr/B3RJ64" );
867 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
870 n.setName( "tr\\B3RJ64" );
871 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
874 n.setName( "tr_B3RJ64" );
875 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
878 n.setName( " tr|B3RJ64 " );
879 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
882 n.setName( "-tr|B3RJ64-" );
883 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
886 n.setName( "-tr=B3RJ64-" );
887 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
890 n.setName( "_tr=B3RJ64_" );
891 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
894 n.setName( " tr_tr|B3RJ64_sp|123 " );
895 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
898 n.setName( "sp|B3RJ64" );
899 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
902 n.setName( "ssp|B3RJ64" );
903 if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
906 n.setName( "sp|B3RJ64C" );
907 if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
910 n.setName( "sp B3RJ64" );
911 if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
914 n.setName( "sp|B3RJ6X" );
915 if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
918 n.setName( "sp|B3RJ6" );
919 if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
922 n.setName( "K1PYK7_CRAGI" );
923 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
926 n.setName( "K1PYK7_PEA" );
927 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PEA" ) ) {
930 n.setName( "K1PYK7_RAT" );
931 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_RAT" ) ) {
934 n.setName( "K1PYK7_PIG" );
935 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PIG" ) ) {
938 n.setName( "~K1PYK7_PIG~" );
939 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PIG" ) ) {
942 n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
943 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
946 n.setName( "K1PYKX_CRAGI" );
947 if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
950 n.setName( "XXXXX_CRAGI" );
951 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "XXXXX_CRAGI" ) ) {
954 n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
955 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "H3IB65" ) ) {
958 n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
959 if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
962 n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
963 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "Q86U06" ) ) {
966 n = new PhylogenyNode();
967 org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
968 seq.setSymbol( "K1PYK7_CRAGI" );
969 n.getNodeData().addSequence( seq );
970 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
973 seq.setSymbol( "tr|B3RJ64" );
974 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
977 n = new PhylogenyNode();
978 seq = new org.forester.phylogeny.data.Sequence();
979 seq.setName( "K1PYK7_CRAGI" );
980 n.getNodeData().addSequence( seq );
981 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
984 seq.setName( "tr|B3RJ64" );
985 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
988 n = new PhylogenyNode();
989 seq = new org.forester.phylogeny.data.Sequence();
990 seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
991 n.getNodeData().addSequence( seq );
992 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK8_CRAGI" ) ) {
995 n = new PhylogenyNode();
996 seq = new org.forester.phylogeny.data.Sequence();
997 seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
998 n.getNodeData().addSequence( seq );
999 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
1003 n = new PhylogenyNode();
1004 n.setName( "ACP19736" );
1005 if ( !ForesterUtil.extractGenbankAccessor( n ).equals( "ACP19736" ) ) {
1008 n = new PhylogenyNode();
1009 n.setName( "_ACP19736_" );
1010 if ( !ForesterUtil.extractGenbankAccessor( n ).equals( "ACP19736" ) ) {
1014 catch ( final Exception e ) {
1015 e.printStackTrace( System.out );
1021 private static boolean testCreateUriForSeqWeb() {
1023 final PhylogenyNode n = new PhylogenyNode();
1024 n.setName( "tr|B3RJ64" );
1025 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
1028 n.setName( "B0LM41_HUMAN" );
1029 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
1032 n.setName( "NP_001025424" );
1033 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
1036 n.setName( "_NM_001030253-" );
1037 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
1040 n.setName( "XM_002122186" );
1041 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
1044 n.setName( "dgh_AAA34956_gdg" );
1045 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
1048 n.setName( "j40f4_Q06891.1_fndn2 fnr3" );
1049 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "Q06891.1" ) ) {
1052 n.setName( "GI:394892" );
1053 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
1054 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
1057 n.setName( "gi_394892" );
1058 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
1059 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
1062 n.setName( "gi6335_gi_394892_56635_Gi_43" );
1063 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
1064 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
1068 catch ( final Exception e ) {
1069 e.printStackTrace( System.out );
1075 private static boolean testExtractTaxonomyCodeFromNodeName() {
1077 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1078 .equals( "MOUSE" ) ) {
1081 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1082 .equals( "RAT" ) ) {
1085 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1088 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
1089 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1090 .equals( "MOUSE" ) ) {
1093 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE_function = 23445",
1094 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1095 .equals( "MOUSE" ) ) {
1098 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
1099 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1100 .equals( "MOUSE" ) ) {
1103 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
1104 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1107 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
1108 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1111 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
1112 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1115 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT_function = 23445",
1116 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1119 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
1120 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1123 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
1124 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1127 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
1128 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1131 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1132 .equals( "RAT" ) ) {
1135 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
1136 .equals( "PIG" ) ) {
1140 .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1141 .equals( "MOUSE" ) ) {
1144 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
1145 .equals( "MOUSE" ) ) {
1148 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE_", TAXONOMY_EXTRACTION.AGRESSIVE )
1149 .equals( "MOUSE" ) ) {
1152 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE_", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1153 .equals( "MOUSE" ) ) {
1156 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE_", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ) != null ) {
1159 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "x_MOUSE_x", TAXONOMY_EXTRACTION.AGRESSIVE )
1160 .equals( "MOUSE" ) ) {
1164 catch ( final Exception e ) {
1165 e.printStackTrace( System.out );
1171 private static boolean testBasicNodeMethods() {
1173 if ( PhylogenyNode.getNodeCount() != 0 ) {
1176 final PhylogenyNode n1 = new PhylogenyNode();
1177 final PhylogenyNode n2 = PhylogenyNode
1178 .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1179 final PhylogenyNode n3 = PhylogenyNode
1180 .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1181 final PhylogenyNode n4 = PhylogenyNode
1182 .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1183 if ( n1.isHasAssignedEvent() ) {
1186 if ( PhylogenyNode.getNodeCount() != 4 ) {
1189 if ( n3.getIndicator() != 0 ) {
1192 if ( n3.getNumberOfExternalNodes() != 1 ) {
1195 if ( !n3.isExternal() ) {
1198 if ( !n3.isRoot() ) {
1201 if ( !n4.getName().equals( "n4" ) ) {
1205 catch ( final Exception e ) {
1206 e.printStackTrace( System.out );
1212 private static boolean testBasicPhyloXMLparsing() {
1214 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1215 final PhyloXmlParser xml_parser = new PhyloXmlParser();
1216 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1218 if ( xml_parser.getErrorCount() > 0 ) {
1219 System.out.println( xml_parser.getErrorMessages().toString() );
1222 if ( phylogenies_0.length != 4 ) {
1225 final Phylogeny t1 = phylogenies_0[ 0 ];
1226 final Phylogeny t2 = phylogenies_0[ 1 ];
1227 final Phylogeny t3 = phylogenies_0[ 2 ];
1228 final Phylogeny t4 = phylogenies_0[ 3 ];
1229 if ( t1.getNumberOfExternalNodes() != 1 ) {
1232 if ( !t1.isRooted() ) {
1235 if ( t1.isRerootable() ) {
1238 if ( !t1.getType().equals( "gene_tree" ) ) {
1241 if ( t2.getNumberOfExternalNodes() != 2 ) {
1244 if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1247 if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1250 if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1253 if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1256 if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1259 if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1262 if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1263 .startsWith( "actgtgggggt" ) ) {
1266 if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1267 .startsWith( "ctgtgatgcat" ) ) {
1270 if ( t3.getNumberOfExternalNodes() != 4 ) {
1273 if ( !t1.getName().equals( "t1" ) ) {
1276 if ( !t2.getName().equals( "t2" ) ) {
1279 if ( !t3.getName().equals( "t3" ) ) {
1282 if ( !t4.getName().equals( "t4" ) ) {
1285 if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1288 if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1291 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1294 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1295 .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1298 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1301 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1304 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1307 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1308 .equals( "apoptosis" ) ) {
1311 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1312 .equals( "GO:0006915" ) ) {
1315 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1316 .equals( "UniProtKB" ) ) {
1319 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1320 .equals( "experimental" ) ) {
1323 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1324 .equals( "function" ) ) {
1327 if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1328 .getValue() != 1 ) {
1331 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1332 .getType().equals( "ml" ) ) {
1335 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1336 .equals( "apoptosis" ) ) {
1339 if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1340 .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1343 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1344 .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1347 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1348 .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1351 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1352 .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1355 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1356 .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1359 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1360 .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1363 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1364 .equals( "GO:0005829" ) ) {
1367 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1368 .equals( "intracellular organelle" ) ) {
1371 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1374 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1375 .equals( "UniProt link" ) ) ) {
1378 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1382 catch ( final Exception e ) {
1383 e.printStackTrace( System.out );
1389 private static boolean testBasicPhyloXMLparsingRoundtrip() {
1391 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1392 final PhyloXmlParser xml_parser = new PhyloXmlParser();
1393 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1394 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1397 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1399 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1401 if ( xml_parser.getErrorCount() > 0 ) {
1402 System.out.println( xml_parser.getErrorMessages().toString() );
1405 if ( phylogenies_0.length != 4 ) {
1408 final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1409 final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1410 if ( phylogenies_t1.length != 1 ) {
1413 final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1414 if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1417 if ( !t1_rt.isRooted() ) {
1420 if ( t1_rt.isRerootable() ) {
1423 if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1426 final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1427 final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1428 final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1429 if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1432 if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1435 if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1438 if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1441 if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1442 .startsWith( "actgtgggggt" ) ) {
1445 if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1446 .startsWith( "ctgtgatgcat" ) ) {
1449 final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1450 final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1451 final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1452 final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1453 if ( phylogenies_1.length != 1 ) {
1456 final Phylogeny t3_rt = phylogenies_1[ 0 ];
1457 if ( !t3_rt.getName().equals( "t3" ) ) {
1460 if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1463 if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1466 if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1469 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1472 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1473 .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1476 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1479 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1482 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1483 .equals( "UniProtKB" ) ) {
1486 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1487 .equals( "apoptosis" ) ) {
1490 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1491 .equals( "GO:0006915" ) ) {
1494 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1495 .equals( "UniProtKB" ) ) {
1498 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1499 .equals( "experimental" ) ) {
1502 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1503 .equals( "function" ) ) {
1506 if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1507 .getValue() != 1 ) {
1510 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1511 .getType().equals( "ml" ) ) {
1514 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1515 .equals( "apoptosis" ) ) {
1518 if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1519 .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1522 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1523 .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1526 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1527 .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1530 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1531 .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1534 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1535 .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1538 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1539 .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1542 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1543 .equals( "GO:0005829" ) ) {
1546 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1547 .equals( "intracellular organelle" ) ) {
1550 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1553 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1554 .equals( "UniProt link" ) ) ) {
1557 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1560 if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1563 if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1564 .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." ) ) ) {
1567 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1570 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1573 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1576 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1579 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1580 .equals( "ncbi" ) ) {
1583 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1586 if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1587 .getName().equals( "B" ) ) {
1590 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1591 .getFrom() != 21 ) {
1594 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1597 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1598 .getLength() != 24 ) {
1601 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1602 .getConfidence() != 2144 ) {
1605 if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1606 .equals( "pfam" ) ) {
1609 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1612 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1615 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1618 if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1621 final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1622 if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1625 if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1628 if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1631 if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1634 if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1637 if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1640 if ( taxbb.getSynonyms().size() != 2 ) {
1643 if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1646 if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1649 if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1652 if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1655 if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1658 if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1659 .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1663 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1666 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1669 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1672 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1675 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1678 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1681 if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1685 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1688 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1689 .equalsIgnoreCase( "435" ) ) {
1692 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1695 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1696 .equalsIgnoreCase( "443.7" ) ) {
1699 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1702 if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1705 if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1706 .equalsIgnoreCase( "433" ) ) {
1710 catch ( final Exception e ) {
1711 e.printStackTrace( System.out );
1717 private static boolean testBasicPhyloXMLparsingValidating() {
1719 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1720 PhyloXmlParser xml_parser = null;
1722 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1724 catch ( final Exception e ) {
1725 // Do nothing -- means were not running from jar.
1727 if ( xml_parser == null ) {
1728 xml_parser = new PhyloXmlParser();
1729 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1730 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1733 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1736 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1738 if ( xml_parser.getErrorCount() > 0 ) {
1739 System.out.println( xml_parser.getErrorMessages().toString() );
1742 if ( phylogenies_0.length != 4 ) {
1745 final Phylogeny t1 = phylogenies_0[ 0 ];
1746 final Phylogeny t2 = phylogenies_0[ 1 ];
1747 final Phylogeny t3 = phylogenies_0[ 2 ];
1748 final Phylogeny t4 = phylogenies_0[ 3 ];
1749 if ( !t1.getName().equals( "t1" ) ) {
1752 if ( !t2.getName().equals( "t2" ) ) {
1755 if ( !t3.getName().equals( "t3" ) ) {
1758 if ( !t4.getName().equals( "t4" ) ) {
1761 if ( t1.getNumberOfExternalNodes() != 1 ) {
1764 if ( t2.getNumberOfExternalNodes() != 2 ) {
1767 if ( t3.getNumberOfExternalNodes() != 4 ) {
1770 final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
1771 final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
1772 if ( xml_parser.getErrorCount() > 0 ) {
1773 System.out.println( "errors:" );
1774 System.out.println( xml_parser.getErrorMessages().toString() );
1777 if ( phylogenies_1.length != 4 ) {
1780 final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
1782 if ( xml_parser.getErrorCount() > 0 ) {
1783 System.out.println( "errors:" );
1784 System.out.println( xml_parser.getErrorMessages().toString() );
1787 if ( phylogenies_2.length != 1 ) {
1790 if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
1793 final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
1795 if ( xml_parser.getErrorCount() > 0 ) {
1796 System.out.println( xml_parser.getErrorMessages().toString() );
1799 if ( phylogenies_3.length != 2 ) {
1802 final Phylogeny a = phylogenies_3[ 0 ];
1803 if ( !a.getName().equals( "tree 4" ) ) {
1806 if ( a.getNumberOfExternalNodes() != 3 ) {
1809 if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
1812 if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
1815 final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
1817 if ( xml_parser.getErrorCount() > 0 ) {
1818 System.out.println( xml_parser.getErrorMessages().toString() );
1821 if ( phylogenies_4.length != 1 ) {
1824 final Phylogeny s = phylogenies_4[ 0 ];
1825 if ( s.getNumberOfExternalNodes() != 6 ) {
1828 s.getNode( "first" );
1830 s.getNode( "\"<a'b&c'd\">\"" );
1831 s.getNode( "'''\"" );
1832 s.getNode( "\"\"\"" );
1833 s.getNode( "dick & doof" );
1835 catch ( final Exception e ) {
1836 e.printStackTrace( System.out );
1842 private static boolean testBasicTable() {
1844 final BasicTable<String> t0 = new BasicTable<String>();
1845 if ( t0.getNumberOfColumns() != 0 ) {
1848 if ( t0.getNumberOfRows() != 0 ) {
1851 t0.setValue( 3, 2, "23" );
1852 t0.setValue( 10, 1, "error" );
1853 t0.setValue( 10, 1, "110" );
1854 t0.setValue( 9, 1, "19" );
1855 t0.setValue( 1, 10, "101" );
1856 t0.setValue( 10, 10, "1010" );
1857 t0.setValue( 100, 10, "10100" );
1858 t0.setValue( 0, 0, "00" );
1859 if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
1862 if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
1865 if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
1868 if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
1871 if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
1874 if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
1877 if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
1880 if ( t0.getNumberOfColumns() != 101 ) {
1883 if ( t0.getNumberOfRows() != 11 ) {
1886 if ( t0.getValueAsString( 49, 4 ) != null ) {
1889 final String l = ForesterUtil.getLineSeparator();
1890 final StringBuffer source = new StringBuffer();
1891 source.append( "" + l );
1892 source.append( "# 1 1 1 1 1 1 1 1" + l );
1893 source.append( " 00 01 02 03" + l );
1894 source.append( " 10 11 12 13 " + l );
1895 source.append( "20 21 22 23 " + l );
1896 source.append( " 30 31 32 33" + l );
1897 source.append( "40 41 42 43" + l );
1898 source.append( " # 1 1 1 1 1 " + l );
1899 source.append( "50 51 52 53 54" + l );
1900 final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
1901 if ( t1.getNumberOfColumns() != 5 ) {
1904 if ( t1.getNumberOfRows() != 6 ) {
1907 if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
1910 if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
1913 if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
1916 if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
1919 final StringBuffer source1 = new StringBuffer();
1920 source1.append( "" + l );
1921 source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
1922 source1.append( " 00; 01 ;02;03" + l );
1923 source1.append( " 10; 11; 12; 13 " + l );
1924 source1.append( "20; 21; 22; 23 " + l );
1925 source1.append( " 30; 31; 32; 33" + l );
1926 source1.append( "40;41;42;43" + l );
1927 source1.append( " # 1 1 1 1 1 " + l );
1928 source1.append( ";;;50 ; ;52; 53;;54 " + l );
1929 final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
1930 if ( t2.getNumberOfColumns() != 5 ) {
1933 if ( t2.getNumberOfRows() != 6 ) {
1936 if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
1939 if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
1942 if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
1945 if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
1948 if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
1951 if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
1954 final StringBuffer source2 = new StringBuffer();
1955 source2.append( "" + l );
1956 source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
1957 source2.append( " 00; 01 ;02;03" + l );
1958 source2.append( " 10; 11; 12; 13 " + l );
1959 source2.append( "20; 21; 22; 23 " + l );
1960 source2.append( " " + l );
1961 source2.append( " 30; 31; 32; 33" + l );
1962 source2.append( "40;41;42;43" + l );
1963 source2.append( " comment: 1 1 1 1 1 " + l );
1964 source2.append( ";;;50 ; 52; 53;;54 " + l );
1965 final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
1971 if ( tl.size() != 2 ) {
1974 final BasicTable<String> t3 = tl.get( 0 );
1975 final BasicTable<String> t4 = tl.get( 1 );
1976 if ( t3.getNumberOfColumns() != 4 ) {
1979 if ( t3.getNumberOfRows() != 3 ) {
1982 if ( t4.getNumberOfColumns() != 4 ) {
1985 if ( t4.getNumberOfRows() != 3 ) {
1988 if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
1991 if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
1995 catch ( final Exception e ) {
1996 e.printStackTrace( System.out );
2002 private static boolean testBasicTolXMLparsing() {
2004 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2005 final TolParser parser = new TolParser();
2006 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2007 if ( parser.getErrorCount() > 0 ) {
2008 System.out.println( parser.getErrorMessages().toString() );
2011 if ( phylogenies_0.length != 1 ) {
2014 final Phylogeny t1 = phylogenies_0[ 0 ];
2015 if ( t1.getNumberOfExternalNodes() != 5 ) {
2018 if ( !t1.isRooted() ) {
2021 if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2024 if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2027 if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2030 if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2033 final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2034 if ( parser.getErrorCount() > 0 ) {
2035 System.out.println( parser.getErrorMessages().toString() );
2038 if ( phylogenies_1.length != 1 ) {
2041 final Phylogeny t2 = phylogenies_1[ 0 ];
2042 if ( t2.getNumberOfExternalNodes() != 664 ) {
2045 if ( !t2.isRooted() ) {
2048 if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2051 if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2054 if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2057 if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2060 if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2063 if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2064 .equals( "Aquifex" ) ) {
2067 final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2068 if ( parser.getErrorCount() > 0 ) {
2069 System.out.println( parser.getErrorMessages().toString() );
2072 if ( phylogenies_2.length != 1 ) {
2075 final Phylogeny t3 = phylogenies_2[ 0 ];
2076 if ( t3.getNumberOfExternalNodes() != 184 ) {
2079 if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2082 if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2085 if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2088 final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2089 if ( parser.getErrorCount() > 0 ) {
2090 System.out.println( parser.getErrorMessages().toString() );
2093 if ( phylogenies_3.length != 1 ) {
2096 final Phylogeny t4 = phylogenies_3[ 0 ];
2097 if ( t4.getNumberOfExternalNodes() != 1 ) {
2100 if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2103 if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2106 if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2109 final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2110 if ( parser.getErrorCount() > 0 ) {
2111 System.out.println( parser.getErrorMessages().toString() );
2114 if ( phylogenies_4.length != 1 ) {
2117 final Phylogeny t5 = phylogenies_4[ 0 ];
2118 if ( t5.getNumberOfExternalNodes() != 13 ) {
2121 if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2124 if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2127 if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2131 catch ( final Exception e ) {
2132 e.printStackTrace( System.out );
2138 private static boolean testBasicTreeMethods() {
2140 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2141 final Phylogeny t1 = factory.create();
2142 if ( !t1.isEmpty() ) {
2145 final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2146 if ( t2.getNumberOfExternalNodes() != 4 ) {
2149 if ( t2.getHeight() != 8.5 ) {
2152 if ( !t2.isCompletelyBinary() ) {
2155 if ( t2.isEmpty() ) {
2158 final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2159 if ( t3.getNumberOfExternalNodes() != 5 ) {
2162 if ( t3.getHeight() != 11 ) {
2165 if ( t3.isCompletelyBinary() ) {
2168 final PhylogenyNode n = t3.getNode( "ABC" );
2169 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 ];
2170 if ( t4.getNumberOfExternalNodes() != 9 ) {
2173 if ( t4.getHeight() != 11 ) {
2176 if ( t4.isCompletelyBinary() ) {
2179 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)" );
2180 final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2181 if ( t5.getNumberOfExternalNodes() != 8 ) {
2184 if ( t5.getHeight() != 15 ) {
2187 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)" );
2188 final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2189 if ( t6.getHeight() != 15 ) {
2192 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)" );
2193 final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2194 if ( t7.getHeight() != 15 ) {
2197 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)" );
2198 final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2199 if ( t8.getNumberOfExternalNodes() != 10 ) {
2202 if ( t8.getHeight() != 15 ) {
2205 final char[] a9 = new char[] { 'a' };
2206 final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2207 if ( t9.getHeight() != 0 ) {
2210 final char[] a10 = new char[] { 'a', ':', '6' };
2211 final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2212 if ( t10.getHeight() != 6 ) {
2216 catch ( final Exception e ) {
2217 e.printStackTrace( System.out );
2223 private static boolean testTreeMethods() {
2225 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2226 final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
2227 PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
2228 if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
2229 System.out.println( t0.toNewHampshireX() );
2232 final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
2233 PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
2234 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
2237 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
2240 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
2244 catch ( final Exception e ) {
2245 e.printStackTrace( System.out );
2251 private static boolean testConfidenceAssessor() {
2253 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2254 final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2255 final Phylogeny[] ev0 = factory
2256 .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2258 ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2259 if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2262 if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2265 final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2266 final Phylogeny[] ev1 = factory
2267 .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)));",
2269 ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2270 if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2273 if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2276 final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2277 final Phylogeny[] ev_b = factory
2278 .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",
2280 ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2281 if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2284 if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2288 final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2289 final Phylogeny[] ev1x = factory
2290 .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)));",
2292 ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2293 if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2296 if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2299 final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2300 final Phylogeny[] ev_bx = factory
2301 .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",
2303 ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2304 if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2307 if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2311 final Phylogeny[] t2 = factory
2312 .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);",
2314 final Phylogeny[] ev2 = factory
2315 .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);",
2317 for( final Phylogeny target : t2 ) {
2318 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2321 final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2322 new NHXParser() )[ 0 ];
2323 final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2324 ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2325 if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2328 if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2331 if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2335 catch ( final Exception e ) {
2336 e.printStackTrace();
2342 private static boolean testCopyOfNodeData() {
2344 final PhylogenyNode n1 = PhylogenyNode
2345 .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]" );
2346 final PhylogenyNode n2 = n1.copyNodeData();
2347 if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2351 catch ( final Exception e ) {
2352 e.printStackTrace();
2358 private static boolean testDataObjects() {
2360 final Confidence s0 = new Confidence();
2361 final Confidence s1 = new Confidence();
2362 if ( !s0.isEqual( s1 ) ) {
2365 final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2366 final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2367 if ( s2.isEqual( s1 ) ) {
2370 if ( !s2.isEqual( s3 ) ) {
2373 final Confidence s4 = ( Confidence ) s3.copy();
2374 if ( !s4.isEqual( s3 ) ) {
2381 final Taxonomy t1 = new Taxonomy();
2382 final Taxonomy t2 = new Taxonomy();
2383 final Taxonomy t3 = new Taxonomy();
2384 final Taxonomy t4 = new Taxonomy();
2385 final Taxonomy t5 = new Taxonomy();
2386 t1.setIdentifier( new Identifier( "ecoli" ) );
2387 t1.setTaxonomyCode( "ECOLI" );
2388 t1.setScientificName( "E. coli" );
2389 t1.setCommonName( "coli" );
2390 final Taxonomy t0 = ( Taxonomy ) t1.copy();
2391 if ( !t1.isEqual( t0 ) ) {
2394 t2.setIdentifier( new Identifier( "ecoli" ) );
2395 t2.setTaxonomyCode( "OTHER" );
2396 t2.setScientificName( "what" );
2397 t2.setCommonName( "something" );
2398 if ( !t1.isEqual( t2 ) ) {
2401 t2.setIdentifier( new Identifier( "nemve" ) );
2402 if ( t1.isEqual( t2 ) ) {
2405 t1.setIdentifier( null );
2406 t3.setTaxonomyCode( "ECOLI" );
2407 t3.setScientificName( "what" );
2408 t3.setCommonName( "something" );
2409 if ( !t1.isEqual( t3 ) ) {
2412 t1.setIdentifier( null );
2413 t1.setTaxonomyCode( "" );
2414 t4.setScientificName( "E. ColI" );
2415 t4.setCommonName( "something" );
2416 if ( !t1.isEqual( t4 ) ) {
2419 t4.setScientificName( "B. subtilis" );
2420 t4.setCommonName( "something" );
2421 if ( t1.isEqual( t4 ) ) {
2424 t1.setIdentifier( null );
2425 t1.setTaxonomyCode( "" );
2426 t1.setScientificName( "" );
2427 t5.setCommonName( "COLI" );
2428 if ( !t1.isEqual( t5 ) ) {
2431 t5.setCommonName( "vibrio" );
2432 if ( t1.isEqual( t5 ) ) {
2437 final Identifier id0 = new Identifier( "123", "pfam" );
2438 final Identifier id1 = ( Identifier ) id0.copy();
2439 if ( !id1.isEqual( id1 ) ) {
2442 if ( !id1.isEqual( id0 ) ) {
2445 if ( !id0.isEqual( id1 ) ) {
2452 final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
2453 final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
2454 if ( !pd1.isEqual( pd1 ) ) {
2457 if ( !pd1.isEqual( pd0 ) ) {
2462 final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
2463 final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
2464 if ( !pd3.isEqual( pd3 ) ) {
2467 if ( !pd2.isEqual( pd3 ) ) {
2470 if ( !pd0.isEqual( pd3 ) ) {
2475 // DomainArchitecture
2476 // ------------------
2477 final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
2478 final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
2479 final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
2480 final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
2481 final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
2482 final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
2487 final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
2488 if ( ds0.getNumberOfDomains() != 4 ) {
2491 final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
2492 if ( !ds0.isEqual( ds0 ) ) {
2495 if ( !ds0.isEqual( ds1 ) ) {
2498 if ( ds1.getNumberOfDomains() != 4 ) {
2501 final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
2506 final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
2507 if ( ds0.isEqual( ds2 ) ) {
2513 final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
2514 if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
2515 System.out.println( ds3.toNHX() );
2518 if ( ds3.getNumberOfDomains() != 3 ) {
2523 final Event e1 = new Event( Event.EventType.fusion );
2524 if ( e1.isDuplication() ) {
2527 if ( !e1.isFusion() ) {
2530 if ( !e1.asText().toString().equals( "fusion" ) ) {
2533 if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
2536 final Event e11 = new Event( Event.EventType.fusion );
2537 if ( !e11.isEqual( e1 ) ) {
2540 if ( !e11.toNHX().toString().equals( "" ) ) {
2543 final Event e2 = new Event( Event.EventType.speciation_or_duplication );
2544 if ( e2.isDuplication() ) {
2547 if ( !e2.isSpeciationOrDuplication() ) {
2550 if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
2553 if ( !e2.asSimpleText().toString().equals( "?" ) ) {
2556 if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
2559 if ( e11.isEqual( e2 ) ) {
2562 final Event e2c = ( Event ) e2.copy();
2563 if ( !e2c.isEqual( e2 ) ) {
2566 Event e3 = new Event( 1, 2, 3 );
2567 if ( e3.isDuplication() ) {
2570 if ( e3.isSpeciation() ) {
2573 if ( e3.isGeneLoss() ) {
2576 if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2579 final Event e3c = ( Event ) e3.copy();
2580 final Event e3cc = ( Event ) e3c.copy();
2581 if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
2585 if ( !e3c.isEqual( e3cc ) ) {
2588 Event e4 = new Event( 1, 2, 3 );
2589 if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2592 if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
2595 final Event e4c = ( Event ) e4.copy();
2597 final Event e4cc = ( Event ) e4c.copy();
2598 if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2601 if ( !e4c.isEqual( e4cc ) ) {
2604 final Event e5 = new Event();
2605 if ( !e5.isUnassigned() ) {
2608 if ( !e5.asText().toString().equals( "unassigned" ) ) {
2611 if ( !e5.asSimpleText().toString().equals( "" ) ) {
2614 final Event e6 = new Event( 1, 0, 0 );
2615 if ( !e6.asText().toString().equals( "duplication" ) ) {
2618 if ( !e6.asSimpleText().toString().equals( "D" ) ) {
2621 final Event e7 = new Event( 0, 1, 0 );
2622 if ( !e7.asText().toString().equals( "speciation" ) ) {
2625 if ( !e7.asSimpleText().toString().equals( "S" ) ) {
2628 final Event e8 = new Event( 0, 0, 1 );
2629 if ( !e8.asText().toString().equals( "gene-loss" ) ) {
2632 if ( !e8.asSimpleText().toString().equals( "L" ) ) {
2636 catch ( final Exception e ) {
2637 e.printStackTrace( System.out );
2643 private static boolean testDeletionOfExternalNodes() {
2645 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2646 final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
2647 final PhylogenyWriter w = new PhylogenyWriter();
2648 if ( t0.isEmpty() ) {
2651 if ( t0.getNumberOfExternalNodes() != 1 ) {
2654 t0.deleteSubtree( t0.getNode( "A" ), false );
2655 if ( t0.getNumberOfExternalNodes() != 0 ) {
2658 if ( !t0.isEmpty() ) {
2661 final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
2662 if ( t1.getNumberOfExternalNodes() != 2 ) {
2665 t1.deleteSubtree( t1.getNode( "A" ), false );
2666 if ( t1.getNumberOfExternalNodes() != 1 ) {
2669 if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
2672 t1.deleteSubtree( t1.getNode( "B" ), false );
2673 if ( t1.getNumberOfExternalNodes() != 1 ) {
2676 t1.deleteSubtree( t1.getNode( "r" ), false );
2677 if ( !t1.isEmpty() ) {
2680 final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
2681 if ( t2.getNumberOfExternalNodes() != 3 ) {
2684 t2.deleteSubtree( t2.getNode( "B" ), false );
2685 if ( t2.getNumberOfExternalNodes() != 2 ) {
2688 t2.toNewHampshireX();
2689 PhylogenyNode n = t2.getNode( "A" );
2690 if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2693 t2.deleteSubtree( t2.getNode( "A" ), false );
2694 if ( t2.getNumberOfExternalNodes() != 2 ) {
2697 t2.deleteSubtree( t2.getNode( "C" ), true );
2698 if ( t2.getNumberOfExternalNodes() != 1 ) {
2701 final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2702 if ( t3.getNumberOfExternalNodes() != 4 ) {
2705 t3.deleteSubtree( t3.getNode( "B" ), true );
2706 if ( t3.getNumberOfExternalNodes() != 3 ) {
2709 n = t3.getNode( "A" );
2710 if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2713 n = n.getNextExternalNode();
2714 if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2717 t3.deleteSubtree( t3.getNode( "A" ), true );
2718 if ( t3.getNumberOfExternalNodes() != 2 ) {
2721 n = t3.getNode( "C" );
2722 if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2725 t3.deleteSubtree( t3.getNode( "C" ), true );
2726 if ( t3.getNumberOfExternalNodes() != 1 ) {
2729 t3.deleteSubtree( t3.getNode( "D" ), true );
2730 if ( t3.getNumberOfExternalNodes() != 0 ) {
2733 final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2734 if ( t4.getNumberOfExternalNodes() != 6 ) {
2737 t4.deleteSubtree( t4.getNode( "B2" ), true );
2738 if ( t4.getNumberOfExternalNodes() != 5 ) {
2741 String s = w.toNewHampshire( t4, false, true ).toString();
2742 if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2745 t4.deleteSubtree( t4.getNode( "B11" ), true );
2746 if ( t4.getNumberOfExternalNodes() != 4 ) {
2749 t4.deleteSubtree( t4.getNode( "C" ), true );
2750 if ( t4.getNumberOfExternalNodes() != 3 ) {
2753 n = t4.getNode( "A" );
2754 n = n.getNextExternalNode();
2755 if ( !n.getName().equals( "B12" ) ) {
2758 n = n.getNextExternalNode();
2759 if ( !n.getName().equals( "D" ) ) {
2762 s = w.toNewHampshire( t4, false, true ).toString();
2763 if ( !s.equals( "((A,B12),D);" ) ) {
2766 final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2767 t5.deleteSubtree( t5.getNode( "A" ), true );
2768 if ( t5.getNumberOfExternalNodes() != 5 ) {
2771 s = w.toNewHampshire( t5, false, true ).toString();
2772 if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
2775 final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2776 t6.deleteSubtree( t6.getNode( "B11" ), true );
2777 if ( t6.getNumberOfExternalNodes() != 5 ) {
2780 s = w.toNewHampshire( t6, false, false ).toString();
2781 if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
2784 final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2785 t7.deleteSubtree( t7.getNode( "B12" ), true );
2786 if ( t7.getNumberOfExternalNodes() != 5 ) {
2789 s = w.toNewHampshire( t7, false, true ).toString();
2790 if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
2793 final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2794 t8.deleteSubtree( t8.getNode( "B2" ), true );
2795 if ( t8.getNumberOfExternalNodes() != 5 ) {
2798 s = w.toNewHampshire( t8, false, false ).toString();
2799 if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2802 final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2803 t9.deleteSubtree( t9.getNode( "C" ), true );
2804 if ( t9.getNumberOfExternalNodes() != 5 ) {
2807 s = w.toNewHampshire( t9, false, true ).toString();
2808 if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
2811 final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2812 t10.deleteSubtree( t10.getNode( "D" ), true );
2813 if ( t10.getNumberOfExternalNodes() != 5 ) {
2816 s = w.toNewHampshire( t10, false, true ).toString();
2817 if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
2820 final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
2821 t11.deleteSubtree( t11.getNode( "A" ), true );
2822 if ( t11.getNumberOfExternalNodes() != 2 ) {
2825 s = w.toNewHampshire( t11, false, true ).toString();
2826 if ( !s.equals( "(B,C);" ) ) {
2829 t11.deleteSubtree( t11.getNode( "C" ), true );
2830 if ( t11.getNumberOfExternalNodes() != 1 ) {
2833 s = w.toNewHampshire( t11, false, false ).toString();
2834 if ( !s.equals( "B;" ) ) {
2837 final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
2838 t12.deleteSubtree( t12.getNode( "B2" ), true );
2839 if ( t12.getNumberOfExternalNodes() != 8 ) {
2842 s = w.toNewHampshire( t12, false, true ).toString();
2843 if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
2846 t12.deleteSubtree( t12.getNode( "B3" ), true );
2847 if ( t12.getNumberOfExternalNodes() != 7 ) {
2850 s = w.toNewHampshire( t12, false, true ).toString();
2851 if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
2854 t12.deleteSubtree( t12.getNode( "C3" ), true );
2855 if ( t12.getNumberOfExternalNodes() != 6 ) {
2858 s = w.toNewHampshire( t12, false, true ).toString();
2859 if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
2862 t12.deleteSubtree( t12.getNode( "A1" ), true );
2863 if ( t12.getNumberOfExternalNodes() != 5 ) {
2866 s = w.toNewHampshire( t12, false, true ).toString();
2867 if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
2870 t12.deleteSubtree( t12.getNode( "B1" ), true );
2871 if ( t12.getNumberOfExternalNodes() != 4 ) {
2874 s = w.toNewHampshire( t12, false, true ).toString();
2875 if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
2878 t12.deleteSubtree( t12.getNode( "A3" ), true );
2879 if ( t12.getNumberOfExternalNodes() != 3 ) {
2882 s = w.toNewHampshire( t12, false, true ).toString();
2883 if ( !s.equals( "(A2,(C1,C2));" ) ) {
2886 t12.deleteSubtree( t12.getNode( "A2" ), true );
2887 if ( t12.getNumberOfExternalNodes() != 2 ) {
2890 s = w.toNewHampshire( t12, false, true ).toString();
2891 if ( !s.equals( "(C1,C2);" ) ) {
2894 final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
2895 t13.deleteSubtree( t13.getNode( "D" ), true );
2896 if ( t13.getNumberOfExternalNodes() != 4 ) {
2899 s = w.toNewHampshire( t13, false, true ).toString();
2900 if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
2903 final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
2904 t14.deleteSubtree( t14.getNode( "E" ), true );
2905 if ( t14.getNumberOfExternalNodes() != 5 ) {
2908 s = w.toNewHampshire( t14, false, true ).toString();
2909 if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
2912 final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
2913 t15.deleteSubtree( t15.getNode( "B2" ), true );
2914 if ( t15.getNumberOfExternalNodes() != 11 ) {
2917 t15.deleteSubtree( t15.getNode( "B1" ), true );
2918 if ( t15.getNumberOfExternalNodes() != 10 ) {
2921 t15.deleteSubtree( t15.getNode( "B3" ), true );
2922 if ( t15.getNumberOfExternalNodes() != 9 ) {
2925 t15.deleteSubtree( t15.getNode( "B4" ), true );
2926 if ( t15.getNumberOfExternalNodes() != 8 ) {
2929 t15.deleteSubtree( t15.getNode( "A1" ), true );
2930 if ( t15.getNumberOfExternalNodes() != 7 ) {
2933 t15.deleteSubtree( t15.getNode( "C4" ), true );
2934 if ( t15.getNumberOfExternalNodes() != 6 ) {
2938 catch ( final Exception e ) {
2939 e.printStackTrace( System.out );
2945 private static boolean testDescriptiveStatistics() {
2947 final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
2948 dss1.addValue( 82 );
2949 dss1.addValue( 78 );
2950 dss1.addValue( 70 );
2951 dss1.addValue( 58 );
2952 dss1.addValue( 42 );
2953 if ( dss1.getN() != 5 ) {
2956 if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
2959 if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
2962 if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
2965 if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
2968 if ( !Test.isEqual( dss1.median(), 70 ) ) {
2971 if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
2974 if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
2977 if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
2980 if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
2983 if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
2986 if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
2989 dss1.addValue( 123 );
2990 if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
2993 if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
2996 if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
2999 final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3000 dss2.addValue( -1.85 );
3001 dss2.addValue( 57.5 );
3002 dss2.addValue( 92.78 );
3003 dss2.addValue( 57.78 );
3004 if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3007 if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3010 final double[] a = dss2.getDataAsDoubleArray();
3011 if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3014 dss2.addValue( -100 );
3015 if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3018 if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3021 final double[] ds = new double[ 14 ];
3036 final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3037 if ( bins.length != 4 ) {
3040 if ( bins[ 0 ] != 2 ) {
3043 if ( bins[ 1 ] != 3 ) {
3046 if ( bins[ 2 ] != 4 ) {
3049 if ( bins[ 3 ] != 5 ) {
3052 final double[] ds1 = new double[ 9 ];
3062 final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3063 if ( bins1.length != 4 ) {
3066 if ( bins1[ 0 ] != 2 ) {
3069 if ( bins1[ 1 ] != 3 ) {
3072 if ( bins1[ 2 ] != 0 ) {
3075 if ( bins1[ 3 ] != 4 ) {
3078 final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3079 if ( bins1_1.length != 3 ) {
3082 if ( bins1_1[ 0 ] != 3 ) {
3085 if ( bins1_1[ 1 ] != 2 ) {
3088 if ( bins1_1[ 2 ] != 4 ) {
3091 final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3092 if ( bins1_2.length != 3 ) {
3095 if ( bins1_2[ 0 ] != 2 ) {
3098 if ( bins1_2[ 1 ] != 2 ) {
3101 if ( bins1_2[ 2 ] != 2 ) {
3104 final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3118 dss3.addValue( 10 );
3119 dss3.addValue( 10 );
3120 dss3.addValue( 10 );
3121 final AsciiHistogram histo = new AsciiHistogram( dss3 );
3122 histo.toStringBuffer( 10, '=', 40, 5 );
3123 histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3125 catch ( final Exception e ) {
3126 e.printStackTrace( System.out );
3132 private static boolean testDir( final String file ) {
3134 final File f = new File( file );
3135 if ( !f.exists() ) {
3138 if ( !f.isDirectory() ) {
3141 if ( !f.canRead() ) {
3145 catch ( final Exception e ) {
3151 private static boolean testExternalNodeRelatedMethods() {
3153 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3154 final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3155 PhylogenyNode n = t1.getNode( "A" );
3156 n = n.getNextExternalNode();
3157 if ( !n.getName().equals( "B" ) ) {
3160 n = n.getNextExternalNode();
3161 if ( !n.getName().equals( "C" ) ) {
3164 n = n.getNextExternalNode();
3165 if ( !n.getName().equals( "D" ) ) {
3168 n = t1.getNode( "B" );
3169 while ( !n.isLastExternalNode() ) {
3170 n = n.getNextExternalNode();
3172 final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
3173 n = t2.getNode( "A" );
3174 n = n.getNextExternalNode();
3175 if ( !n.getName().equals( "B" ) ) {
3178 n = n.getNextExternalNode();
3179 if ( !n.getName().equals( "C" ) ) {
3182 n = n.getNextExternalNode();
3183 if ( !n.getName().equals( "D" ) ) {
3186 n = t2.getNode( "B" );
3187 while ( !n.isLastExternalNode() ) {
3188 n = n.getNextExternalNode();
3190 final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3191 n = t3.getNode( "A" );
3192 n = n.getNextExternalNode();
3193 if ( !n.getName().equals( "B" ) ) {
3196 n = n.getNextExternalNode();
3197 if ( !n.getName().equals( "C" ) ) {
3200 n = n.getNextExternalNode();
3201 if ( !n.getName().equals( "D" ) ) {
3204 n = n.getNextExternalNode();
3205 if ( !n.getName().equals( "E" ) ) {
3208 n = n.getNextExternalNode();
3209 if ( !n.getName().equals( "F" ) ) {
3212 n = n.getNextExternalNode();
3213 if ( !n.getName().equals( "G" ) ) {
3216 n = n.getNextExternalNode();
3217 if ( !n.getName().equals( "H" ) ) {
3220 n = t3.getNode( "B" );
3221 while ( !n.isLastExternalNode() ) {
3222 n = n.getNextExternalNode();
3224 final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3225 for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
3226 final PhylogenyNode node = iter.next();
3228 final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3229 for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
3230 final PhylogenyNode node = iter.next();
3232 final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
3233 final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
3234 if ( !iter.next().getName().equals( "A" ) ) {
3237 if ( !iter.next().getName().equals( "B" ) ) {
3240 if ( !iter.next().getName().equals( "C" ) ) {
3243 if ( !iter.next().getName().equals( "D" ) ) {
3246 if ( !iter.next().getName().equals( "E" ) ) {
3249 if ( !iter.next().getName().equals( "F" ) ) {
3252 if ( iter.hasNext() ) {
3256 catch ( final Exception e ) {
3257 e.printStackTrace( System.out );
3263 private static boolean testGeneralTable() {
3265 final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
3266 t0.setValue( 3, 2, "23" );
3267 t0.setValue( 10, 1, "error" );
3268 t0.setValue( 10, 1, "110" );
3269 t0.setValue( 9, 1, "19" );
3270 t0.setValue( 1, 10, "101" );
3271 t0.setValue( 10, 10, "1010" );
3272 t0.setValue( 100, 10, "10100" );
3273 t0.setValue( 0, 0, "00" );
3274 if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
3277 if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
3280 if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
3283 if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
3286 if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
3289 if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
3292 if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
3295 if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
3298 if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
3301 final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
3302 t1.setValue( "3", "2", "23" );
3303 t1.setValue( "10", "1", "error" );
3304 t1.setValue( "10", "1", "110" );
3305 t1.setValue( "9", "1", "19" );
3306 t1.setValue( "1", "10", "101" );
3307 t1.setValue( "10", "10", "1010" );
3308 t1.setValue( "100", "10", "10100" );
3309 t1.setValue( "0", "0", "00" );
3310 t1.setValue( "qwerty", "zxcvbnm", "asdef" );
3311 if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
3314 if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
3317 if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
3320 if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
3323 if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
3326 if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
3329 if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
3332 if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
3335 if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
3338 if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
3342 catch ( final Exception e ) {
3343 e.printStackTrace( System.out );
3349 private static boolean testGetDistance() {
3351 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3352 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",
3353 new NHXParser() )[ 0 ];
3354 if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
3357 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
3360 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
3363 if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
3366 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
3369 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
3372 if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
3375 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
3378 if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
3381 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
3384 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
3387 if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
3390 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
3393 if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
3396 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
3399 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
3402 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
3405 if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
3408 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
3411 if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
3414 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
3417 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
3420 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
3423 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
3426 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
3429 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
3432 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
3435 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
3438 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
3441 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
3444 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
3447 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",
3448 new NHXParser() )[ 0 ];
3449 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
3452 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
3455 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
3458 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
3461 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
3464 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
3467 if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
3470 if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
3473 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
3476 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
3479 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
3483 catch ( final Exception e ) {
3484 e.printStackTrace( System.out );
3490 private static boolean testGetLCA() {
3492 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3493 final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3494 new NHXParser() )[ 0 ];
3495 final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
3496 if ( !A.getName().equals( "A" ) ) {
3499 final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
3500 if ( !gh.getName().equals( "gh" ) ) {
3503 final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
3504 if ( !ab.getName().equals( "ab" ) ) {
3507 final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
3508 if ( !ab2.getName().equals( "ab" ) ) {
3511 final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
3512 if ( !gh2.getName().equals( "gh" ) ) {
3515 final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
3516 if ( !gh3.getName().equals( "gh" ) ) {
3519 final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
3520 if ( !abc.getName().equals( "abc" ) ) {
3523 final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
3524 if ( !abc2.getName().equals( "abc" ) ) {
3527 final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
3528 if ( !abcd.getName().equals( "abcd" ) ) {
3531 final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
3532 if ( !abcd2.getName().equals( "abcd" ) ) {
3535 final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
3536 if ( !abcdef.getName().equals( "abcdef" ) ) {
3539 final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
3540 if ( !abcdef2.getName().equals( "abcdef" ) ) {
3543 final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
3544 if ( !abcdef3.getName().equals( "abcdef" ) ) {
3547 final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
3548 if ( !abcdef4.getName().equals( "abcdef" ) ) {
3551 final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
3552 if ( !abcde.getName().equals( "abcde" ) ) {
3555 final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
3556 if ( !abcde2.getName().equals( "abcde" ) ) {
3559 final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
3560 if ( !r.getName().equals( "abcdefgh" ) ) {
3563 final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
3564 if ( !r2.getName().equals( "abcdefgh" ) ) {
3567 final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
3568 if ( !r3.getName().equals( "abcdefgh" ) ) {
3571 final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
3572 if ( !abcde3.getName().equals( "abcde" ) ) {
3575 final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
3576 if ( !abcde4.getName().equals( "abcde" ) ) {
3579 final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
3580 if ( !ab3.getName().equals( "ab" ) ) {
3583 final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
3584 if ( !ab4.getName().equals( "ab" ) ) {
3587 final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3588 final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
3589 if ( !cd.getName().equals( "cd" ) ) {
3592 final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
3593 if ( !cd2.getName().equals( "cd" ) ) {
3596 final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
3597 if ( !cde.getName().equals( "cde" ) ) {
3600 final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
3601 if ( !cde2.getName().equals( "cde" ) ) {
3604 final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
3605 if ( !cdef.getName().equals( "cdef" ) ) {
3608 final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
3609 if ( !cdef2.getName().equals( "cdef" ) ) {
3612 final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
3613 if ( !cdef3.getName().equals( "cdef" ) ) {
3616 final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
3617 if ( !rt.getName().equals( "r" ) ) {
3620 final Phylogeny p3 = factory
3621 .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
3622 new NHXParser() )[ 0 ];
3623 final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
3624 if ( !bc_3.getName().equals( "bc" ) ) {
3627 final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
3628 if ( !ac_3.getName().equals( "abc" ) ) {
3631 final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
3632 if ( !ad_3.getName().equals( "abcde" ) ) {
3635 final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
3636 if ( !af_3.getName().equals( "abcdef" ) ) {
3639 final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
3640 if ( !ag_3.getName().equals( "" ) ) {
3643 if ( !ag_3.isRoot() ) {
3646 final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
3647 if ( !al_3.getName().equals( "" ) ) {
3650 if ( !al_3.isRoot() ) {
3653 final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
3654 if ( !kl_3.getName().equals( "" ) ) {
3657 if ( !kl_3.isRoot() ) {
3660 final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
3661 if ( !fl_3.getName().equals( "" ) ) {
3664 if ( !fl_3.isRoot() ) {
3667 final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
3668 if ( !gk_3.getName().equals( "ghijk" ) ) {
3671 final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
3672 final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
3673 if ( !r_4.getName().equals( "r" ) ) {
3676 final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
3677 final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
3678 if ( !r_5.getName().equals( "root" ) ) {
3681 final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
3682 final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
3683 if ( !r_6.getName().equals( "rot" ) ) {
3686 final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
3687 final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
3688 if ( !r_7.getName().equals( "rott" ) ) {
3692 catch ( final Exception e ) {
3693 e.printStackTrace( System.out );
3699 private static boolean testGetLCA2() {
3701 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3702 final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
3703 PhylogenyMethods.preOrderReId( p_a );
3704 final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
3705 p_a.getNode( "a" ) );
3706 if ( !p_a_1.getName().equals( "a" ) ) {
3709 final Phylogeny p_b = factory.create( "((a)b)", new NHXParser() )[ 0 ];
3710 PhylogenyMethods.preOrderReId( p_b );
3711 final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
3712 p_b.getNode( "a" ) );
3713 if ( !p_b_1.getName().equals( "b" ) ) {
3716 final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
3717 p_b.getNode( "b" ) );
3718 if ( !p_b_2.getName().equals( "b" ) ) {
3721 final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
3722 PhylogenyMethods.preOrderReId( p_c );
3723 final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
3724 p_c.getNode( "a" ) );
3725 if ( !p_c_1.getName().equals( "b" ) ) {
3728 final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3729 p_c.getNode( "c" ) );
3730 if ( !p_c_2.getName().equals( "c" ) ) {
3731 System.out.println( p_c_2.getName() );
3735 final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3736 p_c.getNode( "b" ) );
3737 if ( !p_c_3.getName().equals( "b" ) ) {
3740 final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
3741 p_c.getNode( "a" ) );
3742 if ( !p_c_4.getName().equals( "c" ) ) {
3745 final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3746 new NHXParser() )[ 0 ];
3747 PhylogenyMethods.preOrderReId( p1 );
3748 final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3749 p1.getNode( "A" ) );
3750 if ( !A.getName().equals( "A" ) ) {
3753 final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
3754 p1.getNode( "gh" ) );
3755 if ( !gh.getName().equals( "gh" ) ) {
3758 final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3759 p1.getNode( "B" ) );
3760 if ( !ab.getName().equals( "ab" ) ) {
3763 final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3764 p1.getNode( "A" ) );
3765 if ( !ab2.getName().equals( "ab" ) ) {
3768 final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3769 p1.getNode( "G" ) );
3770 if ( !gh2.getName().equals( "gh" ) ) {
3773 final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
3774 p1.getNode( "H" ) );
3775 if ( !gh3.getName().equals( "gh" ) ) {
3778 final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
3779 p1.getNode( "A" ) );
3780 if ( !abc.getName().equals( "abc" ) ) {
3783 final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3784 p1.getNode( "C" ) );
3785 if ( !abc2.getName().equals( "abc" ) ) {
3788 final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3789 p1.getNode( "D" ) );
3790 if ( !abcd.getName().equals( "abcd" ) ) {
3793 final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
3794 p1.getNode( "A" ) );
3795 if ( !abcd2.getName().equals( "abcd" ) ) {
3798 final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3799 p1.getNode( "F" ) );
3800 if ( !abcdef.getName().equals( "abcdef" ) ) {
3803 final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3804 p1.getNode( "A" ) );
3805 if ( !abcdef2.getName().equals( "abcdef" ) ) {
3808 final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3809 p1.getNode( "F" ) );
3810 if ( !abcdef3.getName().equals( "abcdef" ) ) {
3813 final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3814 p1.getNode( "ab" ) );
3815 if ( !abcdef4.getName().equals( "abcdef" ) ) {
3818 final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3819 p1.getNode( "E" ) );
3820 if ( !abcde.getName().equals( "abcde" ) ) {
3823 final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3824 p1.getNode( "A" ) );
3825 if ( !abcde2.getName().equals( "abcde" ) ) {
3828 final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
3829 p1.getNode( "abcdefgh" ) );
3830 if ( !r.getName().equals( "abcdefgh" ) ) {
3833 final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3834 p1.getNode( "H" ) );
3835 if ( !r2.getName().equals( "abcdefgh" ) ) {
3838 final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3839 p1.getNode( "A" ) );
3840 if ( !r3.getName().equals( "abcdefgh" ) ) {
3843 final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3844 p1.getNode( "abcde" ) );
3845 if ( !abcde3.getName().equals( "abcde" ) ) {
3848 final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
3849 p1.getNode( "E" ) );
3850 if ( !abcde4.getName().equals( "abcde" ) ) {
3853 final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3854 p1.getNode( "B" ) );
3855 if ( !ab3.getName().equals( "ab" ) ) {
3858 final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3859 p1.getNode( "ab" ) );
3860 if ( !ab4.getName().equals( "ab" ) ) {
3863 final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3864 PhylogenyMethods.preOrderReId( p2 );
3865 final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3866 p2.getNode( "d" ) );
3867 if ( !cd.getName().equals( "cd" ) ) {
3870 final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3871 p2.getNode( "c" ) );
3872 if ( !cd2.getName().equals( "cd" ) ) {
3875 final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3876 p2.getNode( "e" ) );
3877 if ( !cde.getName().equals( "cde" ) ) {
3880 final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
3881 p2.getNode( "c" ) );
3882 if ( !cde2.getName().equals( "cde" ) ) {
3885 final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3886 p2.getNode( "f" ) );
3887 if ( !cdef.getName().equals( "cdef" ) ) {
3890 final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3891 p2.getNode( "f" ) );
3892 if ( !cdef2.getName().equals( "cdef" ) ) {
3895 final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
3896 p2.getNode( "d" ) );
3897 if ( !cdef3.getName().equals( "cdef" ) ) {
3900 final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3901 p2.getNode( "a" ) );
3902 if ( !rt.getName().equals( "r" ) ) {
3905 final Phylogeny p3 = factory
3906 .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
3907 new NHXParser() )[ 0 ];
3908 PhylogenyMethods.preOrderReId( p3 );
3909 final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
3910 p3.getNode( "c" ) );
3911 if ( !bc_3.getName().equals( "bc" ) ) {
3914 final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3915 p3.getNode( "c" ) );
3916 if ( !ac_3.getName().equals( "abc" ) ) {
3919 final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3920 p3.getNode( "d" ) );
3921 if ( !ad_3.getName().equals( "abcde" ) ) {
3924 final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3925 p3.getNode( "f" ) );
3926 if ( !af_3.getName().equals( "abcdef" ) ) {
3929 final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3930 p3.getNode( "g" ) );
3931 if ( !ag_3.getName().equals( "" ) ) {
3934 if ( !ag_3.isRoot() ) {
3937 final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3938 p3.getNode( "l" ) );
3939 if ( !al_3.getName().equals( "" ) ) {
3942 if ( !al_3.isRoot() ) {
3945 final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
3946 p3.getNode( "l" ) );
3947 if ( !kl_3.getName().equals( "" ) ) {
3950 if ( !kl_3.isRoot() ) {
3953 final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
3954 p3.getNode( "l" ) );
3955 if ( !fl_3.getName().equals( "" ) ) {
3958 if ( !fl_3.isRoot() ) {
3961 final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
3962 p3.getNode( "k" ) );
3963 if ( !gk_3.getName().equals( "ghijk" ) ) {
3966 final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
3967 PhylogenyMethods.preOrderReId( p4 );
3968 final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
3969 p4.getNode( "c" ) );
3970 if ( !r_4.getName().equals( "r" ) ) {
3973 final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
3974 PhylogenyMethods.preOrderReId( p5 );
3975 final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
3976 p5.getNode( "c" ) );
3977 if ( !r_5.getName().equals( "root" ) ) {
3980 final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
3981 PhylogenyMethods.preOrderReId( p6 );
3982 final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
3983 p6.getNode( "a" ) );
3984 if ( !r_6.getName().equals( "rot" ) ) {
3987 final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
3988 PhylogenyMethods.preOrderReId( p7 );
3989 final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
3990 p7.getNode( "e" ) );
3991 if ( !r_7.getName().equals( "rott" ) ) {
3994 final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
3995 p7.getNode( "a" ) );
3996 if ( !r_71.getName().equals( "rott" ) ) {
3999 final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4000 p7.getNode( "rott" ) );
4001 if ( !r_72.getName().equals( "rott" ) ) {
4004 final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
4005 p7.getNode( "a" ) );
4006 if ( !r_73.getName().equals( "rott" ) ) {
4009 final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
4010 p7.getNode( "rott" ) );
4011 if ( !r_74.getName().equals( "rott" ) ) {
4014 final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4015 p7.getNode( "e" ) );
4016 if ( !r_75.getName().equals( "e" ) ) {
4020 catch ( final Exception e ) {
4021 e.printStackTrace( System.out );
4027 private static boolean testHmmscanOutputParser() {
4028 final String test_dir = Test.PATH_TO_TEST_DATA;
4030 final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
4031 + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4033 final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
4034 + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4035 final List<Protein> proteins = parser2.parse();
4036 if ( parser2.getProteinsEncountered() != 4 ) {
4039 if ( proteins.size() != 4 ) {
4042 if ( parser2.getDomainsEncountered() != 69 ) {
4045 if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
4048 if ( parser2.getDomainsIgnoredDueToEval() != 0 ) {
4051 final Protein p1 = proteins.get( 0 );
4052 if ( p1.getNumberOfProteinDomains() != 15 ) {
4055 if ( p1.getLength() != 850 ) {
4058 final Protein p2 = proteins.get( 1 );
4059 if ( p2.getNumberOfProteinDomains() != 51 ) {
4062 if ( p2.getLength() != 1291 ) {
4065 final Protein p3 = proteins.get( 2 );
4066 if ( p3.getNumberOfProteinDomains() != 2 ) {
4069 final Protein p4 = proteins.get( 3 );
4070 if ( p4.getNumberOfProteinDomains() != 1 ) {
4073 if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
4076 if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
4079 if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
4082 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
4085 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
4088 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) {
4091 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) {
4094 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
4097 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
4101 catch ( final Exception e ) {
4102 e.printStackTrace( System.out );
4108 private static boolean testLastExternalNodeMethods() {
4110 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4111 final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
4112 final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
4113 final PhylogenyNode n1 = t0.getNode( "A" );
4114 if ( n1.isLastExternalNode() ) {
4117 final PhylogenyNode n2 = t0.getNode( "B" );
4118 if ( n2.isLastExternalNode() ) {
4121 final PhylogenyNode n3 = t0.getNode( "C" );
4122 if ( n3.isLastExternalNode() ) {
4125 final PhylogenyNode n4 = t0.getNode( "D" );
4126 if ( !n4.isLastExternalNode() ) {
4130 catch ( final Exception e ) {
4131 e.printStackTrace( System.out );
4137 private static boolean testLevelOrderIterator() {
4139 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4140 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
4141 PhylogenyNodeIterator it0;
4142 for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
4145 for( it0.reset(); it0.hasNext(); ) {
4148 final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
4149 if ( !it.next().getName().equals( "r" ) ) {
4152 if ( !it.next().getName().equals( "ab" ) ) {
4155 if ( !it.next().getName().equals( "cd" ) ) {
4158 if ( !it.next().getName().equals( "A" ) ) {
4161 if ( !it.next().getName().equals( "B" ) ) {
4164 if ( !it.next().getName().equals( "C" ) ) {
4167 if ( !it.next().getName().equals( "D" ) ) {
4170 if ( it.hasNext() ) {
4173 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",
4174 new NHXParser() )[ 0 ];
4175 PhylogenyNodeIterator it2;
4176 for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
4179 for( it2.reset(); it2.hasNext(); ) {
4182 final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
4183 if ( !it3.next().getName().equals( "r" ) ) {
4186 if ( !it3.next().getName().equals( "abc" ) ) {
4189 if ( !it3.next().getName().equals( "defg" ) ) {
4192 if ( !it3.next().getName().equals( "A" ) ) {
4195 if ( !it3.next().getName().equals( "B" ) ) {
4198 if ( !it3.next().getName().equals( "C" ) ) {
4201 if ( !it3.next().getName().equals( "D" ) ) {
4204 if ( !it3.next().getName().equals( "E" ) ) {
4207 if ( !it3.next().getName().equals( "F" ) ) {
4210 if ( !it3.next().getName().equals( "G" ) ) {
4213 if ( !it3.next().getName().equals( "1" ) ) {
4216 if ( !it3.next().getName().equals( "2" ) ) {
4219 if ( !it3.next().getName().equals( "3" ) ) {
4222 if ( !it3.next().getName().equals( "4" ) ) {
4225 if ( !it3.next().getName().equals( "5" ) ) {
4228 if ( !it3.next().getName().equals( "6" ) ) {
4231 if ( !it3.next().getName().equals( "f1" ) ) {
4234 if ( !it3.next().getName().equals( "f2" ) ) {
4237 if ( !it3.next().getName().equals( "f3" ) ) {
4240 if ( !it3.next().getName().equals( "a" ) ) {
4243 if ( !it3.next().getName().equals( "b" ) ) {
4246 if ( !it3.next().getName().equals( "f21" ) ) {
4249 if ( !it3.next().getName().equals( "X" ) ) {
4252 if ( !it3.next().getName().equals( "Y" ) ) {
4255 if ( !it3.next().getName().equals( "Z" ) ) {
4258 if ( it3.hasNext() ) {
4261 final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
4262 PhylogenyNodeIterator it4;
4263 for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
4266 for( it4.reset(); it4.hasNext(); ) {
4269 final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
4270 if ( !it5.next().getName().equals( "r" ) ) {
4273 if ( !it5.next().getName().equals( "A" ) ) {
4276 if ( !it5.next().getName().equals( "B" ) ) {
4279 if ( !it5.next().getName().equals( "C" ) ) {
4282 if ( !it5.next().getName().equals( "D" ) ) {
4285 final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
4286 PhylogenyNodeIterator it6;
4287 for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
4290 for( it6.reset(); it6.hasNext(); ) {
4293 final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
4294 if ( !it7.next().getName().equals( "A" ) ) {
4297 if ( it.hasNext() ) {
4301 catch ( final Exception e ) {
4302 e.printStackTrace( System.out );
4308 private static boolean testNodeRemoval() {
4310 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4311 final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
4312 PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
4313 if ( !t0.toNewHampshire().equals( "(a);" ) ) {
4316 final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
4317 PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
4318 if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
4321 final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
4322 PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
4323 if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
4327 catch ( final Exception e ) {
4328 e.printStackTrace( System.out );
4334 private static boolean testMidpointrooting() {
4336 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4337 final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
4338 PhylogenyMethods.midpointRoot( t0 );
4339 if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
4342 if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
4345 if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
4349 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",
4350 new NHXParser() )[ 0 ];
4351 if ( !t1.isRooted() ) {
4354 PhylogenyMethods.midpointRoot( t1 );
4355 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4358 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4361 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4364 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4367 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4370 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4373 t1.reRoot( t1.getNode( "A" ) );
4374 PhylogenyMethods.midpointRoot( t1 );
4375 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4378 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4381 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4384 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4387 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4391 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4395 catch ( final Exception e ) {
4396 e.printStackTrace( System.out );
4402 private static boolean testNexusCharactersParsing() {
4404 final NexusCharactersParser parser = new NexusCharactersParser();
4405 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
4407 String[] labels = parser.getCharStateLabels();
4408 if ( labels.length != 7 ) {
4411 if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4414 if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4417 if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4420 if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4423 if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4426 if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4429 if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4432 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4434 labels = parser.getCharStateLabels();
4435 if ( labels.length != 7 ) {
4438 if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4441 if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4444 if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4447 if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4450 if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4453 if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4456 if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4460 catch ( final Exception e ) {
4461 e.printStackTrace( System.out );
4467 private static boolean testNexusMatrixParsing() {
4469 final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
4470 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
4472 final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
4473 if ( m.getNumberOfCharacters() != 9 ) {
4476 if ( m.getNumberOfIdentifiers() != 5 ) {
4479 if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
4482 if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
4485 if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
4488 if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
4491 if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
4494 if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
4497 if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
4500 // if ( labels.length != 7 ) {
4503 // if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4506 // if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4509 // if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4512 // if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4515 // if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4518 // if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4521 // if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4524 // parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4526 // labels = parser.getCharStateLabels();
4527 // if ( labels.length != 7 ) {
4530 // if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4533 // if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4536 // if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4539 // if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4542 // if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4545 // if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4548 // if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4552 catch ( final Exception e ) {
4553 e.printStackTrace( System.out );
4559 private static boolean testNexusTreeParsing() {
4561 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4562 final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
4563 Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
4564 if ( phylogenies.length != 1 ) {
4567 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
4570 if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4574 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
4575 if ( phylogenies.length != 1 ) {
4578 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4581 if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
4585 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
4586 if ( phylogenies.length != 1 ) {
4589 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4592 if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4595 if ( phylogenies[ 0 ].isRooted() ) {
4599 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
4600 if ( phylogenies.length != 18 ) {
4603 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4606 if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
4609 if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
4612 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
4615 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
4618 if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
4621 if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
4624 if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
4627 if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
4630 if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
4633 if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
4636 if ( phylogenies[ 8 ].isRooted() ) {
4639 if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
4642 if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
4645 if ( !phylogenies[ 9 ].isRooted() ) {
4648 if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
4651 if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
4654 if ( !phylogenies[ 10 ].isRooted() ) {
4657 if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
4660 if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
4663 if ( phylogenies[ 11 ].isRooted() ) {
4666 if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
4669 if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
4672 if ( !phylogenies[ 12 ].isRooted() ) {
4675 if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
4678 if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
4681 if ( !phylogenies[ 13 ].isRooted() ) {
4684 if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
4687 if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
4690 if ( !phylogenies[ 14 ].isRooted() ) {
4693 if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
4696 if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
4699 if ( phylogenies[ 15 ].isRooted() ) {
4702 if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
4705 if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
4708 if ( !phylogenies[ 16 ].isRooted() ) {
4711 if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
4714 if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
4717 if ( phylogenies[ 17 ].isRooted() ) {
4720 if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
4724 catch ( final Exception e ) {
4725 e.printStackTrace( System.out );
4731 private static boolean testNexusTreeParsingIterating() {
4733 final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
4734 p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
4735 if ( !p.hasNext() ) {
4738 Phylogeny phy = p.next();
4739 if ( phy == null ) {
4742 if ( phy.getNumberOfExternalNodes() != 25 ) {
4745 if ( !phy.getName().equals( "" ) ) {
4748 if ( p.hasNext() ) {
4752 if ( phy != null ) {
4757 if ( !p.hasNext() ) {
4761 if ( phy == null ) {
4764 if ( phy.getNumberOfExternalNodes() != 25 ) {
4767 if ( !phy.getName().equals( "" ) ) {
4770 if ( p.hasNext() ) {
4774 if ( phy != null ) {
4778 p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
4779 if ( !p.hasNext() ) {
4783 if ( phy == null ) {
4786 if ( phy.getNumberOfExternalNodes() != 10 ) {
4789 if ( !phy.getName().equals( "name" ) ) {
4792 if ( p.hasNext() ) {
4796 if ( phy != null ) {
4801 if ( !p.hasNext() ) {
4805 if ( phy == null ) {
4808 if ( phy.getNumberOfExternalNodes() != 10 ) {
4811 if ( !phy.getName().equals( "name" ) ) {
4814 if ( p.hasNext() ) {
4818 if ( phy != null ) {
4822 p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
4823 if ( !p.hasNext() ) {
4827 if ( phy == null ) {
4830 if ( phy.getNumberOfExternalNodes() != 3 ) {
4833 if ( !phy.getName().equals( "" ) ) {
4836 if ( phy.isRooted() ) {
4839 if ( p.hasNext() ) {
4843 if ( phy != null ) {
4848 if ( !p.hasNext() ) {
4852 if ( phy == null ) {
4855 if ( phy.getNumberOfExternalNodes() != 3 ) {
4858 if ( !phy.getName().equals( "" ) ) {
4861 if ( p.hasNext() ) {
4865 if ( phy != null ) {
4869 p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
4870 // if ( phylogenies.length != 18 ) {
4874 if ( !p.hasNext() ) {
4878 if ( phy == null ) {
4881 if ( phy.getNumberOfExternalNodes() != 10 ) {
4884 if ( !phy.getName().equals( "tree 0" ) ) {
4888 if ( !p.hasNext() ) {
4892 if ( phy == null ) {
4895 if ( phy.getNumberOfExternalNodes() != 10 ) {
4898 if ( !phy.getName().equals( "tree 1" ) ) {
4902 if ( !p.hasNext() ) {
4906 if ( phy == null ) {
4909 if ( phy.getNumberOfExternalNodes() != 3 ) {
4912 if ( !phy.getName().equals( "" ) ) {
4915 if ( phy.isRooted() ) {
4919 if ( !p.hasNext() ) {
4923 if ( phy == null ) {
4926 if ( phy.getNumberOfExternalNodes() != 4 ) {
4929 if ( !phy.getName().equals( "" ) ) {
4932 if ( !phy.isRooted() ) {
4936 if ( !p.hasNext() ) {
4940 if ( phy == null ) {
4943 if ( phy.getNumberOfExternalNodes() != 5 ) {
4944 System.out.println( phy.getNumberOfExternalNodes() );
4947 if ( !phy.getName().equals( "" ) ) {
4950 if ( !phy.isRooted() ) {
4954 if ( !p.hasNext() ) {
4958 if ( phy == null ) {
4961 if ( phy.getNumberOfExternalNodes() != 3 ) {
4964 if ( !phy.getName().equals( "" ) ) {
4967 if ( phy.isRooted() ) {
4971 if ( !p.hasNext() ) {
4975 if ( phy == null ) {
4978 if ( phy.getNumberOfExternalNodes() != 2 ) {
4981 if ( !phy.getName().equals( "" ) ) {
4984 if ( !phy.isRooted() ) {
4988 if ( !p.hasNext() ) {
4992 if ( phy.getNumberOfExternalNodes() != 3 ) {
4995 if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
4998 if ( !phy.isRooted() ) {
5002 if ( !p.hasNext() ) {
5006 if ( phy.getNumberOfExternalNodes() != 3 ) {
5009 if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
5012 if ( !phy.getName().equals( "tree 8" ) ) {
5016 if ( !p.hasNext() ) {
5020 if ( phy.getNumberOfExternalNodes() != 3 ) {
5023 if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
5026 if ( !phy.getName().equals( "tree 9" ) ) {
5030 if ( !p.hasNext() ) {
5034 if ( phy.getNumberOfExternalNodes() != 3 ) {
5037 if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
5040 if ( !phy.getName().equals( "tree 10" ) ) {
5043 if ( !phy.isRooted() ) {
5047 if ( !p.hasNext() ) {
5051 if ( phy.getNumberOfExternalNodes() != 3 ) {
5054 if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
5057 if ( !phy.getName().equals( "tree 11" ) ) {
5060 if ( phy.isRooted() ) {
5064 if ( !p.hasNext() ) {
5068 if ( phy.getNumberOfExternalNodes() != 3 ) {
5071 if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
5074 if ( !phy.getName().equals( "tree 12" ) ) {
5077 if ( !phy.isRooted() ) {
5081 if ( !p.hasNext() ) {
5085 if ( phy.getNumberOfExternalNodes() != 3 ) {
5088 if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
5091 if ( !phy.getName().equals( "tree 13" ) ) {
5094 if ( !phy.isRooted() ) {
5098 if ( !p.hasNext() ) {
5102 if ( phy.getNumberOfExternalNodes() != 10 ) {
5103 System.out.println( phy.getNumberOfExternalNodes() );
5108 .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;" ) ) {
5109 System.out.println( phy.toNewHampshire() );
5112 if ( !phy.getName().equals( "tree 14" ) ) {
5115 if ( !phy.isRooted() ) {
5119 if ( !p.hasNext() ) {
5123 if ( phy.getNumberOfExternalNodes() != 10 ) {
5124 System.out.println( phy.getNumberOfExternalNodes() );
5129 .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;" ) ) {
5130 System.out.println( phy.toNewHampshire() );
5133 if ( !phy.getName().equals( "tree 15" ) ) {
5136 if ( phy.isRooted() ) {
5140 if ( !p.hasNext() ) {
5144 if ( phy.getNumberOfExternalNodes() != 10 ) {
5145 System.out.println( phy.getNumberOfExternalNodes() );
5150 .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;" ) ) {
5151 System.out.println( phy.toNewHampshire() );
5154 if ( !phy.getName().equals( "tree 16" ) ) {
5157 if ( !phy.isRooted() ) {
5161 if ( !p.hasNext() ) {
5165 if ( phy.getNumberOfExternalNodes() != 10 ) {
5166 System.out.println( phy.getNumberOfExternalNodes() );
5171 .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;" ) ) {
5172 System.out.println( phy.toNewHampshire() );
5175 if ( !phy.getName().equals( "tree 17" ) ) {
5178 if ( phy.isRooted() ) {
5182 if ( p.hasNext() ) {
5186 if ( phy != null ) {
5191 if ( !p.hasNext() ) {
5195 if ( phy == null ) {
5198 if ( phy.getNumberOfExternalNodes() != 10 ) {
5201 if ( !phy.getName().equals( "tree 0" ) ) {
5205 if ( !p.hasNext() ) {
5209 if ( phy == null ) {
5212 if ( phy.getNumberOfExternalNodes() != 10 ) {
5215 if ( !phy.getName().equals( "tree 1" ) ) {
5219 if ( !p.hasNext() ) {
5223 if ( phy == null ) {
5226 if ( phy.getNumberOfExternalNodes() != 3 ) {
5229 if ( !phy.getName().equals( "" ) ) {
5232 if ( phy.isRooted() ) {
5236 if ( !p.hasNext() ) {
5240 if ( phy == null ) {
5243 if ( phy.getNumberOfExternalNodes() != 4 ) {
5246 if ( !phy.getName().equals( "" ) ) {
5249 if ( !phy.isRooted() ) {
5253 if ( !p.hasNext() ) {
5257 if ( phy == null ) {
5260 if ( phy.getNumberOfExternalNodes() != 5 ) {
5261 System.out.println( phy.getNumberOfExternalNodes() );
5264 if ( !phy.getName().equals( "" ) ) {
5267 if ( !phy.isRooted() ) {
5271 if ( !p.hasNext() ) {
5275 if ( phy == null ) {
5278 if ( phy.getNumberOfExternalNodes() != 3 ) {
5281 if ( !phy.getName().equals( "" ) ) {
5284 if ( phy.isRooted() ) {
5288 catch ( final Exception e ) {
5289 e.printStackTrace( System.out );
5295 private static boolean testNexusTreeParsingTranslating() {
5297 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5298 final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
5299 Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
5300 if ( phylogenies.length != 1 ) {
5303 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5306 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5309 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5312 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5315 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5316 .equals( "Aranaeus" ) ) {
5320 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
5321 if ( phylogenies.length != 3 ) {
5324 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5327 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5330 if ( phylogenies[ 0 ].isRooted() ) {
5333 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5336 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5339 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5340 .equals( "Aranaeus" ) ) {
5343 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
5346 if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
5349 if ( phylogenies[ 1 ].isRooted() ) {
5352 if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5355 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5358 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5359 .equals( "Aranaeus" ) ) {
5362 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
5365 if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
5368 if ( !phylogenies[ 2 ].isRooted() ) {
5371 if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5374 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5377 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5378 .equals( "Aranaeus" ) ) {
5382 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
5383 if ( phylogenies.length != 3 ) {
5386 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5389 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5392 if ( phylogenies[ 0 ].isRooted() ) {
5395 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5398 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5401 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5402 .equals( "Aranaeus" ) ) {
5405 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
5408 if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
5411 if ( phylogenies[ 1 ].isRooted() ) {
5414 if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5417 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5420 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5421 .equals( "Aranaeus" ) ) {
5424 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
5427 if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
5430 if ( !phylogenies[ 2 ].isRooted() ) {
5433 if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5436 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5439 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5440 .equals( "Aranaeus" ) ) {
5444 catch ( final Exception e ) {
5445 e.printStackTrace( System.out );
5451 private static boolean testNHParsing() {
5453 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5454 final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
5455 if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
5458 final NHXParser nhxp = new NHXParser();
5459 nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
5460 nhxp.setReplaceUnderscores( true );
5461 final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
5462 if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
5465 if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
5468 final Phylogeny p1b = factory
5469 .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 ",
5470 new NHXParser() )[ 0 ];
5471 if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
5474 if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
5477 final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
5478 final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
5479 final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
5480 final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
5481 final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
5482 final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
5483 final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
5484 final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
5485 final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
5486 final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
5487 final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1 3 ; \n)\t ( \n ;"
5488 + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
5489 + "; ; ( \t\n\r\b; G ;, ;H ;1 3; ) ; ; ;",
5491 if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
5494 if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
5497 if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
5500 if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
5503 final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
5504 final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
5505 final String p16_S = "((A,B),C)";
5506 final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
5507 if ( p16.length != 1 ) {
5510 if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
5513 final String p17_S = "(C,(A,B))";
5514 final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
5515 if ( p17.length != 1 ) {
5518 if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
5521 final String p18_S = "((A,B),(C,D))";
5522 final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
5523 if ( p18.length != 1 ) {
5526 if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
5529 final String p19_S = "(((A,B),C),D)";
5530 final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
5531 if ( p19.length != 1 ) {
5534 if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
5537 final String p20_S = "(A,(B,(C,D)))";
5538 final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
5539 if ( p20.length != 1 ) {
5542 if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
5545 final String p21_S = "(A,(B,(C,(D,E))))";
5546 final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
5547 if ( p21.length != 1 ) {
5550 if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
5553 final String p22_S = "((((A,B),C),D),E)";
5554 final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
5555 if ( p22.length != 1 ) {
5558 if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
5561 final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5562 final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
5563 if ( p23.length != 1 ) {
5564 System.out.println( "xl=" + p23.length );
5568 if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
5571 final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5572 final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
5573 if ( p24.length != 1 ) {
5576 if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
5579 final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5580 final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5581 final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
5582 if ( p241.length != 2 ) {
5585 if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
5588 if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
5591 final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
5592 + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
5593 + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
5594 + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
5595 + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
5596 + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
5597 + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
5598 + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
5599 final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
5600 if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
5603 final String p26_S = "(A,B)ab";
5604 final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
5605 if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
5608 final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5609 final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
5610 if ( p27s.length != 1 ) {
5611 System.out.println( "xxl=" + p27s.length );
5615 if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
5616 System.out.println( p27s[ 0 ].toNewHampshireX() );
5620 final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
5622 if ( p27.length != 1 ) {
5623 System.out.println( "yl=" + p27.length );
5627 if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
5628 System.out.println( p27[ 0 ].toNewHampshireX() );
5632 final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5633 final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5634 final String p28_S3 = "(A,B)ab";
5635 final String p28_S4 = "((((A,B),C),D),;E;)";
5636 final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
5638 if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
5641 if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
5644 if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
5647 if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
5650 if ( p28.length != 4 ) {
5653 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";
5654 final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
5655 if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
5658 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";
5659 final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
5660 if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
5663 final String p32_S = " ; ; \n \t \b \f \r ;;;;;; ";
5664 final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
5665 if ( ( p32.length != 0 ) ) {
5668 final String p33_S = "A";
5669 final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
5670 if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
5673 final String p34_S = "B;";
5674 final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
5675 if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
5678 final String p35_S = "B:0.2";
5679 final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
5680 if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
5683 final String p36_S = "(A)";
5684 final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
5685 if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
5688 final String p37_S = "((A))";
5689 final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
5690 if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
5693 final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
5694 final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
5695 if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
5698 final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
5699 final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
5700 if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
5703 final String p40_S = "(A,B,C)";
5704 final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
5705 if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
5708 final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
5709 final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
5710 if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
5713 final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
5714 final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
5715 if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
5718 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)";
5719 final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
5720 if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
5723 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)))";
5724 final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
5725 if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
5728 final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
5729 final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
5730 if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
5733 final String p46_S = "";
5734 final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
5735 if ( p46.length != 0 ) {
5738 final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
5739 if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5742 final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5743 if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5746 final Phylogeny p49 = factory
5747 .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
5748 new NHXParser() )[ 0 ];
5749 if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5752 final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5753 if ( p50.getNode( "A" ) == null ) {
5756 if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
5757 .equals( "((A,B)ab:2.0[88],C);" ) ) {
5760 if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
5763 if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
5764 .equals( "((A,B)88:2.0,C);" ) ) {
5767 final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5768 if ( p51.getNode( "A(A" ) == null ) {
5771 final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5772 if ( p52.getNode( "A(A" ) == null ) {
5775 final Phylogeny p53 = factory
5776 .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
5777 new NHXParser() )[ 0 ];
5778 if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
5782 final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
5783 if ( p54.getNode( "A" ) == null ) {
5786 if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
5787 .equals( "((A,B)[88],C);" ) ) {
5791 catch ( final Exception e ) {
5792 e.printStackTrace( System.out );
5798 private static boolean testNHParsingIter() {
5800 final String p0_str = "(A,B);";
5801 final NHXParser p = new NHXParser();
5802 p.setSource( p0_str );
5803 if ( !p.hasNext() ) {
5806 final Phylogeny p0 = p.next();
5807 if ( !p0.toNewHampshire().equals( p0_str ) ) {
5808 System.out.println( p0.toNewHampshire() );
5811 if ( p.hasNext() ) {
5814 if ( p.next() != null ) {
5818 final String p00_str = "(A,B)root;";
5819 p.setSource( p00_str );
5820 final Phylogeny p00 = p.next();
5821 if ( !p00.toNewHampshire().equals( p00_str ) ) {
5822 System.out.println( p00.toNewHampshire() );
5826 final String p000_str = "A;";
5827 p.setSource( p000_str );
5828 final Phylogeny p000 = p.next();
5829 if ( !p000.toNewHampshire().equals( p000_str ) ) {
5830 System.out.println( p000.toNewHampshire() );
5834 final String p0000_str = "A";
5835 p.setSource( p0000_str );
5836 final Phylogeny p0000 = p.next();
5837 if ( !p0000.toNewHampshire().equals( "A;" ) ) {
5838 System.out.println( p0000.toNewHampshire() );
5842 p.setSource( "(A)" );
5843 final Phylogeny p00000 = p.next();
5844 if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
5845 System.out.println( p00000.toNewHampshire() );
5849 final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
5850 p.setSource( p1_str );
5851 if ( !p.hasNext() ) {
5854 final Phylogeny p1_0 = p.next();
5855 if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
5856 System.out.println( p1_0.toNewHampshire() );
5859 if ( !p.hasNext() ) {
5862 final Phylogeny p1_1 = p.next();
5863 if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
5864 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
5867 if ( !p.hasNext() ) {
5870 final Phylogeny p1_2 = p.next();
5871 if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
5872 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
5875 if ( !p.hasNext() ) {
5878 final Phylogeny p1_3 = p.next();
5879 if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
5880 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
5883 if ( p.hasNext() ) {
5886 if ( p.next() != null ) {
5890 final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
5891 p.setSource( p2_str );
5892 if ( !p.hasNext() ) {
5895 Phylogeny p2_0 = p.next();
5896 if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
5897 System.out.println( p2_0.toNewHampshire() );
5900 if ( !p.hasNext() ) {
5903 Phylogeny p2_1 = p.next();
5904 if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
5905 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
5908 if ( !p.hasNext() ) {
5911 Phylogeny p2_2 = p.next();
5912 if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
5913 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
5916 if ( !p.hasNext() ) {
5919 Phylogeny p2_3 = p.next();
5920 if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
5921 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
5924 if ( !p.hasNext() ) {
5927 Phylogeny p2_4 = p.next();
5928 if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
5929 System.out.println( "(X) != " + p2_4.toNewHampshire() );
5932 if ( p.hasNext() ) {
5935 if ( p.next() != null ) {
5940 if ( !p.hasNext() ) {
5944 if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
5945 System.out.println( p2_0.toNewHampshire() );
5948 if ( !p.hasNext() ) {
5952 if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
5953 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
5956 if ( !p.hasNext() ) {
5960 if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
5961 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
5964 if ( !p.hasNext() ) {
5968 if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
5969 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
5972 if ( !p.hasNext() ) {
5976 if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
5977 System.out.println( "(X) != " + p2_4.toNewHampshire() );
5980 if ( p.hasNext() ) {
5983 if ( p.next() != null ) {
5987 final String p3_str = "((A,B),C)abc";
5988 p.setSource( p3_str );
5989 if ( !p.hasNext() ) {
5992 final Phylogeny p3_0 = p.next();
5993 if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
5996 if ( p.hasNext() ) {
5999 if ( p.next() != null ) {
6003 final String p4_str = "((A,B)ab,C)abc";
6004 p.setSource( p4_str );
6005 if ( !p.hasNext() ) {
6008 final Phylogeny p4_0 = p.next();
6009 if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
6012 if ( p.hasNext() ) {
6015 if ( p.next() != null ) {
6019 final String p5_str = "(((A,B)ab,C)abc,D)abcd";
6020 p.setSource( p5_str );
6021 if ( !p.hasNext() ) {
6024 final Phylogeny p5_0 = p.next();
6025 if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
6028 if ( p.hasNext() ) {
6031 if ( p.next() != null ) {
6035 final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
6036 p.setSource( p6_str );
6037 if ( !p.hasNext() ) {
6040 Phylogeny p6_0 = p.next();
6041 if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
6044 if ( p.hasNext() ) {
6047 if ( p.next() != null ) {
6051 if ( !p.hasNext() ) {
6055 if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
6058 if ( p.hasNext() ) {
6061 if ( p.next() != null ) {
6065 final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6066 p.setSource( p7_str );
6067 if ( !p.hasNext() ) {
6070 Phylogeny p7_0 = p.next();
6071 if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6074 if ( p.hasNext() ) {
6077 if ( p.next() != null ) {
6081 if ( !p.hasNext() ) {
6085 if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6088 if ( p.hasNext() ) {
6091 if ( p.next() != null ) {
6095 final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
6096 p.setSource( p8_str );
6097 if ( !p.hasNext() ) {
6100 Phylogeny p8_0 = p.next();
6101 if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6104 if ( !p.hasNext() ) {
6107 if ( !p.hasNext() ) {
6110 Phylogeny p8_1 = p.next();
6111 if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
6114 if ( p.hasNext() ) {
6117 if ( p.next() != null ) {
6121 if ( !p.hasNext() ) {
6125 if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6128 if ( !p.hasNext() ) {
6132 if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
6135 if ( p.hasNext() ) {
6138 if ( p.next() != null ) {
6144 if ( p.hasNext() ) {
6148 p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
6149 if ( !p.hasNext() ) {
6152 Phylogeny p_27 = p.next();
6153 if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
6154 System.out.println( p_27.toNewHampshireX() );
6158 if ( p.hasNext() ) {
6161 if ( p.next() != null ) {
6165 if ( !p.hasNext() ) {
6169 if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
6170 System.out.println( p_27.toNewHampshireX() );
6174 if ( p.hasNext() ) {
6177 if ( p.next() != null ) {
6181 catch ( final Exception e ) {
6182 e.printStackTrace( System.out );
6188 private static boolean testNHXconversion() {
6190 final PhylogenyNode n1 = new PhylogenyNode();
6191 final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
6192 final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
6193 final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
6194 final PhylogenyNode n5 = PhylogenyNode
6195 .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
6196 final PhylogenyNode n6 = PhylogenyNode
6197 .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
6198 if ( !n1.toNewHampshireX().equals( "" ) ) {
6201 if ( !n2.toNewHampshireX().equals( "" ) ) {
6204 if ( !n3.toNewHampshireX().equals( "n3" ) ) {
6207 if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
6210 if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
6213 if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
6214 System.out.println( n6.toNewHampshireX() );
6218 catch ( final Exception e ) {
6219 e.printStackTrace( System.out );
6225 private static boolean testTaxonomyExtraction() {
6227 final PhylogenyNode n0 = PhylogenyNode
6228 .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6229 if ( n0.getNodeData().isHasTaxonomy() ) {
6232 final PhylogenyNode n1 = PhylogenyNode
6233 .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6234 if ( n1.getNodeData().isHasTaxonomy() ) {
6235 System.out.println( n1.toString() );
6238 final PhylogenyNode n2 = PhylogenyNode
6239 .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.AGRESSIVE );
6240 if ( !n2.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6241 System.out.println( n2.toString() );
6244 final PhylogenyNode n2x = PhylogenyNode
6245 .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6246 if ( n2x.getNodeData().isHasTaxonomy() ) {
6249 final PhylogenyNode n3 = PhylogenyNode
6250 .createInstanceFromNhxString( "blag_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6251 if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6252 System.out.println( n3.toString() );
6255 final PhylogenyNode n4 = PhylogenyNode
6256 .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6257 if ( n4.getNodeData().isHasTaxonomy() ) {
6258 System.out.println( n4.toString() );
6261 final PhylogenyNode n5 = PhylogenyNode
6262 .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6263 if ( n5.getNodeData().isHasTaxonomy() ) {
6264 System.out.println( n5.toString() );
6267 final PhylogenyNode n6 = PhylogenyNode
6268 .createInstanceFromNhxString( "blag-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6269 if ( n6.getNodeData().isHasTaxonomy() ) {
6270 System.out.println( n6.toString() );
6273 final PhylogenyNode n7 = PhylogenyNode
6274 .createInstanceFromNhxString( "blag-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6275 if ( n7.getNodeData().isHasTaxonomy() ) {
6276 System.out.println( n7.toString() );
6279 final PhylogenyNode n8 = PhylogenyNode
6280 .createInstanceFromNhxString( "blag_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6281 if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6282 System.out.println( n8.toString() );
6285 final PhylogenyNode n9 = PhylogenyNode
6286 .createInstanceFromNhxString( "blag_12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6287 if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6288 System.out.println( n9.toString() );
6291 final PhylogenyNode n10x = PhylogenyNode
6292 .createInstanceFromNhxString( "blag_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6293 if ( n10x.getNodeData().isHasTaxonomy() ) {
6294 System.out.println( n10x.toString() );
6297 final PhylogenyNode n10xx = PhylogenyNode
6298 .createInstanceFromNhxString( "blag_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6299 if ( n10xx.getNodeData().isHasTaxonomy() ) {
6300 System.out.println( n10xx.toString() );
6303 final PhylogenyNode n10 = PhylogenyNode
6304 .createInstanceFromNhxString( "blag_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6305 if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
6306 System.out.println( n10.toString() );
6309 final PhylogenyNode n11 = PhylogenyNode
6310 .createInstanceFromNhxString( "blag_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6311 if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
6312 System.out.println( n11.toString() );
6315 final PhylogenyNode n12 = PhylogenyNode
6316 .createInstanceFromNhxString( "blag_Mus_musculus_musculus",
6317 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6318 if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
6319 System.out.println( n12.toString() );
6322 final PhylogenyNode n13 = PhylogenyNode
6323 .createInstanceFromNhxString( "blag_Mus_musculus1",
6324 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6325 if ( n13.getNodeData().isHasTaxonomy() ) {
6326 System.out.println( n13.toString() );
6329 final PhylogenyNode n14 = PhylogenyNode
6330 .createInstanceFromNhxString( "blag_Mus_musculus_11",
6331 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6332 if ( n14.getNodeData().isHasTaxonomy() ) {
6333 System.out.println( n14.toString() );
6336 final PhylogenyNode n15 = PhylogenyNode
6337 .createInstanceFromNhxString( "blag_Mus_musculus_v11",
6338 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6339 if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus v11" ) ) {
6340 System.out.println( n15.toString() );
6343 final PhylogenyNode n16 = PhylogenyNode
6344 .createInstanceFromNhxString( "blag_Mus_musculus_/11",
6345 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6346 if ( n16.getNodeData().isHasTaxonomy() ) {
6347 System.out.println( n16.toString() );
6350 final PhylogenyNode n17 = PhylogenyNode
6351 .createInstanceFromNhxString( "blag_Mus_musculus_v",
6352 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6353 if ( n17.getNodeData().isHasTaxonomy() ) {
6354 System.out.println( n17.toString() );
6358 catch ( final Exception e ) {
6359 e.printStackTrace( System.out );
6365 private static boolean testNHXNodeParsing() {
6367 final PhylogenyNode n1 = new PhylogenyNode();
6368 final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
6369 final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
6370 final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
6371 final PhylogenyNode n5 = PhylogenyNode
6372 .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]" );
6373 if ( !n3.getName().equals( "n3" ) ) {
6376 if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6379 if ( n3.isDuplication() ) {
6382 if ( n3.isHasAssignedEvent() ) {
6385 if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
6388 if ( !n4.getName().equals( "n4" ) ) {
6391 if ( n4.getDistanceToParent() != 0.01 ) {
6394 if ( !n5.getName().equals( "n5" ) ) {
6397 if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
6400 if ( n5.getDistanceToParent() != 0.1 ) {
6403 if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
6406 if ( !n5.isDuplication() ) {
6409 if ( !n5.isHasAssignedEvent() ) {
6412 final PhylogenyNode n8 = PhylogenyNode
6413 .createInstanceFromNhxString( "n8_ECOLI/12:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6414 if ( !n8.getName().equals( "n8_ECOLI/12" ) ) {
6417 if ( PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
6420 final PhylogenyNode n9 = PhylogenyNode
6421 .createInstanceFromNhxString( "n9_ECOLI/12=12:0.01",
6422 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6423 if ( !n9.getName().equals( "n9_ECOLI/12=12" ) ) {
6426 if ( PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
6429 final PhylogenyNode n10 = PhylogenyNode
6430 .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6431 if ( !n10.getName().equals( "n10.ECOLI" ) ) {
6434 final PhylogenyNode n20 = PhylogenyNode
6435 .createInstanceFromNhxString( "n20_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6436 if ( !n20.getName().equals( "n20_ECOLI/1-2" ) ) {
6439 if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
6442 final PhylogenyNode n20x = PhylogenyNode
6443 .createInstanceFromNhxString( "n20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6444 if ( !n20x.getName().equals( "n20_ECOL1/1-2" ) ) {
6447 if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
6450 final PhylogenyNode n20xx = PhylogenyNode
6451 .createInstanceFromNhxString( "n20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6452 if ( !n20xx.getName().equals( "n20_eCOL1/1-2" ) ) {
6455 if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
6458 final PhylogenyNode n20xxx = PhylogenyNode
6459 .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6460 if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
6463 if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
6466 final PhylogenyNode n20xxxx = PhylogenyNode
6467 .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6468 if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
6471 if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
6474 final PhylogenyNode n21 = PhylogenyNode
6475 .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6476 if ( !n21.getName().equals( "n21_PIG" ) ) {
6479 if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
6482 final PhylogenyNode n21x = PhylogenyNode
6483 .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6484 if ( !n21x.getName().equals( "n21_PIG" ) ) {
6487 if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
6490 final PhylogenyNode n22 = PhylogenyNode
6491 .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6492 if ( !n22.getName().equals( "n22/PIG" ) ) {
6495 if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
6498 final PhylogenyNode n23 = PhylogenyNode
6499 .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6500 if ( !n23.getName().equals( "n23/PIG_1" ) ) {
6503 if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
6506 final PhylogenyNode a = PhylogenyNode
6507 .createInstanceFromNhxString( "n10_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6508 if ( !a.getName().equals( "n10_ECOLI/1-2" ) ) {
6511 if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
6514 final PhylogenyNode b = PhylogenyNode
6515 .createInstanceFromNhxString( "n10_ECOLI1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6516 if ( !b.getName().equals( "n10_ECOLI1/1-2" ) ) {
6519 if ( PhylogenyMethods.getSpecies( b ).equals( "ECOLI" ) ) {
6522 final PhylogenyNode c = PhylogenyNode
6523 .createInstanceFromNhxString( "n10_RATAF12/1000-2000",
6524 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6525 if ( !c.getName().equals( "n10_RATAF12/1000-2000" ) ) {
6528 if ( PhylogenyMethods.getSpecies( c ).equals( "RATAF" ) ) {
6531 final PhylogenyNode c1 = PhylogenyNode
6532 .createInstanceFromNhxString( "n10_BOVIN_1/1000-2000",
6533 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6534 if ( !c1.getName().equals( "n10_BOVIN_1/1000-2000" ) ) {
6537 if ( PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
6540 final PhylogenyNode c2 = PhylogenyNode
6541 .createInstanceFromNhxString( "n10_Bovin_1/1000-2000",
6542 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6543 if ( !c2.getName().equals( "n10_Bovin_1/1000-2000" ) ) {
6546 if ( !PhylogenyMethods.getSpecies( c2 ).equals( "" ) ) {
6549 final PhylogenyNode d = PhylogenyNode
6550 .createInstanceFromNhxString( "n10_RAT1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6551 if ( !d.getName().equals( "n10_RAT1/1-2" ) ) {
6554 if ( PhylogenyMethods.getSpecies( d ).equals( "RAT" ) ) {
6557 final PhylogenyNode e = PhylogenyNode
6558 .createInstanceFromNhxString( "n10_RAT1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6559 if ( !e.getName().equals( "n10_RAT1" ) ) {
6562 if ( !ForesterUtil.isEmpty( PhylogenyMethods.getSpecies( e ) ) ) {
6565 final PhylogenyNode e2 = PhylogenyNode
6566 .createInstanceFromNhxString( "n10_RAT1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6567 if ( !e2.getName().equals( "n10_RAT1" ) ) {
6570 if ( PhylogenyMethods.getSpecies( e2 ).equals( "RAT" ) ) {
6573 final PhylogenyNode e3 = PhylogenyNode
6574 .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6575 if ( !e3.getName().equals( "n10_RAT~" ) ) {
6578 if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
6581 final PhylogenyNode n11 = PhylogenyNode
6582 .createInstanceFromNhxString( "n111111_ECOLI/jdj:0.4",
6583 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6584 if ( !n11.getName().equals( "n111111_ECOLI/jdj" ) ) {
6587 if ( n11.getDistanceToParent() != 0.4 ) {
6590 if ( PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
6593 final PhylogenyNode n12 = PhylogenyNode
6594 .createInstanceFromNhxString( "n111111-ECOLI---/jdj:0.4",
6595 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6596 if ( !n12.getName().equals( "n111111-ECOLI---/jdj" ) ) {
6599 if ( n12.getDistanceToParent() != 0.4 ) {
6602 if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
6605 final PhylogenyNode m = PhylogenyNode
6606 .createInstanceFromNhxString( "n10_MOUSEa", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6607 if ( !m.getName().equals( "n10_MOUSEa" ) ) {
6610 if ( PhylogenyMethods.getSpecies( m ).equals( "MOUSE" ) ) {
6613 final PhylogenyNode o = PhylogenyNode
6614 .createInstanceFromNhxString( "n10_MOUSE_", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6615 if ( !o.getName().equals( "n10_MOUSE_" ) ) {
6618 if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
6621 if ( n1.getName().compareTo( "" ) != 0 ) {
6624 if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
6627 if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6630 if ( n2.getName().compareTo( "" ) != 0 ) {
6633 if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
6636 if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6639 final PhylogenyNode n00 = PhylogenyNode
6640 .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
6641 if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
6644 if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
6647 final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
6648 if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
6651 final PhylogenyNode n13 = PhylogenyNode
6652 .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.AGRESSIVE );
6653 if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
6656 if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
6659 if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6662 if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6665 final PhylogenyNode n14 = PhylogenyNode
6666 .createInstanceFromNhxString( "blah_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6667 if ( !n14.getName().equals( "blah_9QX45/1-2" ) ) {
6670 if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
6673 final PhylogenyNode n15 = PhylogenyNode
6674 .createInstanceFromNhxString( "something_wicked[123]",
6675 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6676 if ( !n15.getName().equals( "something_wicked" ) ) {
6679 if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
6682 if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
6685 final PhylogenyNode n16 = PhylogenyNode
6686 .createInstanceFromNhxString( "something_wicked2[9]",
6687 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6688 if ( !n16.getName().equals( "something_wicked2" ) ) {
6691 if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
6694 if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
6697 final PhylogenyNode n17 = PhylogenyNode
6698 .createInstanceFromNhxString( "something_wicked3[a]",
6699 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6700 if ( !n17.getName().equals( "something_wicked3" ) ) {
6703 if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
6706 final PhylogenyNode n18 = PhylogenyNode
6707 .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6708 if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
6711 if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
6714 if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
6717 final PhylogenyNode n19 = PhylogenyNode
6718 .createInstanceFromNhxString( "blah_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6719 if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
6722 if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6725 final PhylogenyNode n30 = PhylogenyNode
6726 .createInstanceFromNhxString( "blah_1234567-roejojoej",
6727 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6728 if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
6731 if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6734 final PhylogenyNode n31 = PhylogenyNode
6735 .createInstanceFromNhxString( "blah_12345678-roejojoej",
6736 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6737 if ( n31.getNodeData().isHasTaxonomy() ) {
6740 final PhylogenyNode n32 = PhylogenyNode
6741 .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6742 if ( n32.getNodeData().isHasTaxonomy() ) {
6746 catch ( final Exception e ) {
6747 e.printStackTrace( System.out );
6753 private static boolean testNHXParsing() {
6755 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6756 final Phylogeny p1 = factory.create( "(A [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
6757 if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
6760 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]";
6761 final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
6762 if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6765 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]";
6766 final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
6767 if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
6770 final Phylogeny[] p3 = factory
6771 .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]",
6773 if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6776 final Phylogeny[] p4 = factory
6777 .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(]",
6779 if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6782 final Phylogeny[] p5 = factory
6783 .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(((]",
6785 if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6788 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)";
6789 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)";
6790 final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
6791 if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
6794 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)))";
6795 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)))";
6796 final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
6797 if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
6800 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]) ))[,,, ])))))))";
6801 final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
6802 final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
6803 if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
6806 final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
6807 if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
6810 final Phylogeny p10 = factory
6811 .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]",
6812 new NHXParser() )[ 0 ];
6813 if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
6817 catch ( final Exception e ) {
6818 e.printStackTrace( System.out );
6824 private static boolean testNHXParsingQuotes() {
6826 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6827 final NHXParser p = new NHXParser();
6828 final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
6829 if ( phylogenies_0.length != 5 ) {
6832 final Phylogeny phy = phylogenies_0[ 4 ];
6833 if ( phy.getNumberOfExternalNodes() != 7 ) {
6836 if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
6839 if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
6842 if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
6843 .getScientificName().equals( "hsapiens" ) ) {
6846 if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
6849 if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
6852 if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
6855 if ( phy.getNodes( "noquotes" ).size() != 1 ) {
6858 if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
6861 final NHXParser p1p = new NHXParser();
6862 p1p.setIgnoreQuotes( true );
6863 final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
6864 if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
6867 final NHXParser p2p = new NHXParser();
6868 p1p.setIgnoreQuotes( false );
6869 final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
6870 if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
6873 final NHXParser p3p = new NHXParser();
6874 p3p.setIgnoreQuotes( false );
6875 final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
6876 if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
6879 final NHXParser p4p = new NHXParser();
6880 p4p.setIgnoreQuotes( false );
6881 final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
6882 if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
6885 final Phylogeny p10 = factory
6886 .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]",
6887 new NHXParser() )[ 0 ];
6888 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]";
6889 if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
6892 final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
6893 if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
6897 final Phylogeny p12 = factory
6898 .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]",
6899 new NHXParser() )[ 0 ];
6900 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]";
6901 if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
6904 final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
6905 if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
6908 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;";
6909 if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
6912 final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
6913 if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
6917 catch ( final Exception e ) {
6918 e.printStackTrace( System.out );
6924 private static boolean testNHXParsingMB() {
6926 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6927 final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
6928 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6929 + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
6930 + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
6931 + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
6932 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6933 + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
6934 + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
6935 + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
6936 if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
6939 if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
6942 if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
6943 0.1100000000000000e+00 ) ) {
6946 if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
6949 if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
6952 final Phylogeny p2 = factory
6953 .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
6954 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6955 + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
6956 + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
6957 + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
6958 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6959 + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
6960 + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
6961 + "7.369400000000000e-02}])",
6962 new NHXParser() )[ 0 ];
6963 if ( p2.getNode( "1" ) == null ) {
6966 if ( p2.getNode( "2" ) == null ) {
6970 catch ( final Exception e ) {
6971 e.printStackTrace( System.out );
6978 private static boolean testPhylogenyBranch() {
6980 final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
6981 final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
6982 final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
6983 final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
6984 if ( !a1b1.equals( a1b1 ) ) {
6987 if ( !a1b1.equals( b1a1 ) ) {
6990 if ( !b1a1.equals( a1b1 ) ) {
6993 final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
6994 final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
6995 final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
6996 if ( a1_b1.equals( b1_a1 ) ) {
6999 if ( a1_b1.equals( a1_b1_ ) ) {
7002 final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
7003 if ( !a1_b1.equals( b1_a1_ ) ) {
7006 if ( a1_b1_.equals( b1_a1_ ) ) {
7009 if ( !a1_b1_.equals( b1_a1 ) ) {
7013 catch ( final Exception e ) {
7014 e.printStackTrace( System.out );
7020 private static boolean testPhyloXMLparsingOfDistributionElement() {
7022 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7023 PhyloXmlParser xml_parser = null;
7025 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
7027 catch ( final Exception e ) {
7028 // Do nothing -- means were not running from jar.
7030 if ( xml_parser == null ) {
7031 xml_parser = new PhyloXmlParser();
7032 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
7033 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
7036 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
7039 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
7041 if ( xml_parser.getErrorCount() > 0 ) {
7042 System.out.println( xml_parser.getErrorMessages().toString() );
7045 if ( phylogenies_0.length != 1 ) {
7048 final Phylogeny t1 = phylogenies_0[ 0 ];
7049 PhylogenyNode n = null;
7050 Distribution d = null;
7051 n = t1.getNode( "root node" );
7052 if ( !n.getNodeData().isHasDistribution() ) {
7055 if ( n.getNodeData().getDistributions().size() != 1 ) {
7058 d = n.getNodeData().getDistribution();
7059 if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
7062 if ( d.getPoints().size() != 1 ) {
7065 if ( d.getPolygons() != null ) {
7068 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
7071 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7074 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7077 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
7080 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
7083 n = t1.getNode( "node a" );
7084 if ( !n.getNodeData().isHasDistribution() ) {
7087 if ( n.getNodeData().getDistributions().size() != 2 ) {
7090 d = n.getNodeData().getDistribution( 1 );
7091 if ( !d.getDesc().equals( "San Diego" ) ) {
7094 if ( d.getPoints().size() != 1 ) {
7097 if ( d.getPolygons() != null ) {
7100 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
7103 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7106 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7109 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
7112 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
7115 n = t1.getNode( "node bb" );
7116 if ( !n.getNodeData().isHasDistribution() ) {
7119 if ( n.getNodeData().getDistributions().size() != 1 ) {
7122 d = n.getNodeData().getDistribution( 0 );
7123 if ( d.getPoints().size() != 3 ) {
7126 if ( d.getPolygons().size() != 2 ) {
7129 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
7132 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
7135 if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
7138 if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
7141 if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
7144 if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
7147 Polygon p = d.getPolygons().get( 0 );
7148 if ( p.getPoints().size() != 3 ) {
7151 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
7154 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
7157 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7160 if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
7163 if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
7166 if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
7169 p = d.getPolygons().get( 1 );
7170 if ( p.getPoints().size() != 3 ) {
7173 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
7176 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
7179 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7183 final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
7184 final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
7185 if ( rt.length != 1 ) {
7188 final Phylogeny t1_rt = rt[ 0 ];
7189 n = t1_rt.getNode( "root node" );
7190 if ( !n.getNodeData().isHasDistribution() ) {
7193 if ( n.getNodeData().getDistributions().size() != 1 ) {
7196 d = n.getNodeData().getDistribution();
7197 if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
7200 if ( d.getPoints().size() != 1 ) {
7203 if ( d.getPolygons() != null ) {
7206 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
7209 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7212 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7215 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
7218 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
7221 n = t1_rt.getNode( "node a" );
7222 if ( !n.getNodeData().isHasDistribution() ) {
7225 if ( n.getNodeData().getDistributions().size() != 2 ) {
7228 d = n.getNodeData().getDistribution( 1 );
7229 if ( !d.getDesc().equals( "San Diego" ) ) {
7232 if ( d.getPoints().size() != 1 ) {
7235 if ( d.getPolygons() != null ) {
7238 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
7241 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7244 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7247 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
7250 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
7253 n = t1_rt.getNode( "node bb" );
7254 if ( !n.getNodeData().isHasDistribution() ) {
7257 if ( n.getNodeData().getDistributions().size() != 1 ) {
7260 d = n.getNodeData().getDistribution( 0 );
7261 if ( d.getPoints().size() != 3 ) {
7264 if ( d.getPolygons().size() != 2 ) {
7267 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
7270 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
7273 if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
7276 if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
7279 if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
7282 if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
7285 p = d.getPolygons().get( 0 );
7286 if ( p.getPoints().size() != 3 ) {
7289 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
7292 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
7295 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7298 if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
7301 if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
7304 if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
7307 p = d.getPolygons().get( 1 );
7308 if ( p.getPoints().size() != 3 ) {
7311 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
7314 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
7317 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7321 catch ( final Exception e ) {
7322 e.printStackTrace( System.out );
7328 private static boolean testPostOrderIterator() {
7330 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7331 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
7332 PhylogenyNodeIterator it0;
7333 for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
7336 for( it0.reset(); it0.hasNext(); ) {
7339 final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
7340 final PhylogenyNodeIterator it = t1.iteratorPostorder();
7341 if ( !it.next().getName().equals( "A" ) ) {
7344 if ( !it.next().getName().equals( "B" ) ) {
7347 if ( !it.next().getName().equals( "ab" ) ) {
7350 if ( !it.next().getName().equals( "C" ) ) {
7353 if ( !it.next().getName().equals( "D" ) ) {
7356 if ( !it.next().getName().equals( "cd" ) ) {
7359 if ( !it.next().getName().equals( "abcd" ) ) {
7362 if ( !it.next().getName().equals( "E" ) ) {
7365 if ( !it.next().getName().equals( "F" ) ) {
7368 if ( !it.next().getName().equals( "ef" ) ) {
7371 if ( !it.next().getName().equals( "G" ) ) {
7374 if ( !it.next().getName().equals( "H" ) ) {
7377 if ( !it.next().getName().equals( "gh" ) ) {
7380 if ( !it.next().getName().equals( "efgh" ) ) {
7383 if ( !it.next().getName().equals( "r" ) ) {
7386 if ( it.hasNext() ) {
7390 catch ( final Exception e ) {
7391 e.printStackTrace( System.out );
7397 private static boolean testPreOrderIterator() {
7399 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7400 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
7401 PhylogenyNodeIterator it0;
7402 for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
7405 for( it0.reset(); it0.hasNext(); ) {
7408 PhylogenyNodeIterator it = t0.iteratorPreorder();
7409 if ( !it.next().getName().equals( "r" ) ) {
7412 if ( !it.next().getName().equals( "ab" ) ) {
7415 if ( !it.next().getName().equals( "A" ) ) {
7418 if ( !it.next().getName().equals( "B" ) ) {
7421 if ( !it.next().getName().equals( "cd" ) ) {
7424 if ( !it.next().getName().equals( "C" ) ) {
7427 if ( !it.next().getName().equals( "D" ) ) {
7430 if ( it.hasNext() ) {
7433 final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
7434 it = t1.iteratorPreorder();
7435 if ( !it.next().getName().equals( "r" ) ) {
7438 if ( !it.next().getName().equals( "abcd" ) ) {
7441 if ( !it.next().getName().equals( "ab" ) ) {
7444 if ( !it.next().getName().equals( "A" ) ) {
7447 if ( !it.next().getName().equals( "B" ) ) {
7450 if ( !it.next().getName().equals( "cd" ) ) {
7453 if ( !it.next().getName().equals( "C" ) ) {
7456 if ( !it.next().getName().equals( "D" ) ) {
7459 if ( !it.next().getName().equals( "efgh" ) ) {
7462 if ( !it.next().getName().equals( "ef" ) ) {
7465 if ( !it.next().getName().equals( "E" ) ) {
7468 if ( !it.next().getName().equals( "F" ) ) {
7471 if ( !it.next().getName().equals( "gh" ) ) {
7474 if ( !it.next().getName().equals( "G" ) ) {
7477 if ( !it.next().getName().equals( "H" ) ) {
7480 if ( it.hasNext() ) {
7484 catch ( final Exception e ) {
7485 e.printStackTrace( System.out );
7491 private static boolean testPropertiesMap() {
7493 final PropertiesMap pm = new PropertiesMap();
7494 final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
7495 final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
7496 final Property p2 = new Property( "something:else",
7498 "improbable:research",
7501 pm.addProperty( p0 );
7502 pm.addProperty( p1 );
7503 pm.addProperty( p2 );
7504 if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
7507 if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
7510 if ( pm.getProperties().size() != 3 ) {
7513 if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
7516 if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
7519 if ( pm.getProperties().size() != 3 ) {
7522 pm.removeProperty( "dimensions:diameter" );
7523 if ( pm.getProperties().size() != 2 ) {
7526 if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
7529 if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
7533 catch ( final Exception e ) {
7534 e.printStackTrace( System.out );
7540 private static boolean testReIdMethods() {
7542 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7543 final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
7544 final long count = PhylogenyNode.getNodeCount();
7546 if ( p.getNode( "r" ).getId() != count ) {
7549 if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
7552 if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
7555 if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
7558 if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
7561 if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
7564 if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
7567 if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
7570 if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
7573 if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
7576 if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
7579 if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
7582 if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
7585 if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
7588 if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
7592 catch ( final Exception e ) {
7593 e.printStackTrace( System.out );
7599 private static boolean testRerooting() {
7601 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7602 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",
7603 new NHXParser() )[ 0 ];
7604 if ( !t1.isRooted() ) {
7607 t1.reRoot( t1.getNode( "D" ) );
7608 t1.reRoot( t1.getNode( "CD" ) );
7609 t1.reRoot( t1.getNode( "A" ) );
7610 t1.reRoot( t1.getNode( "B" ) );
7611 t1.reRoot( t1.getNode( "AB" ) );
7612 t1.reRoot( t1.getNode( "D" ) );
7613 t1.reRoot( t1.getNode( "C" ) );
7614 t1.reRoot( t1.getNode( "CD" ) );
7615 t1.reRoot( t1.getNode( "A" ) );
7616 t1.reRoot( t1.getNode( "B" ) );
7617 t1.reRoot( t1.getNode( "AB" ) );
7618 t1.reRoot( t1.getNode( "D" ) );
7619 t1.reRoot( t1.getNode( "D" ) );
7620 t1.reRoot( t1.getNode( "C" ) );
7621 t1.reRoot( t1.getNode( "A" ) );
7622 t1.reRoot( t1.getNode( "B" ) );
7623 t1.reRoot( t1.getNode( "AB" ) );
7624 t1.reRoot( t1.getNode( "C" ) );
7625 t1.reRoot( t1.getNode( "D" ) );
7626 t1.reRoot( t1.getNode( "CD" ) );
7627 t1.reRoot( t1.getNode( "D" ) );
7628 t1.reRoot( t1.getNode( "A" ) );
7629 t1.reRoot( t1.getNode( "B" ) );
7630 t1.reRoot( t1.getNode( "AB" ) );
7631 t1.reRoot( t1.getNode( "C" ) );
7632 t1.reRoot( t1.getNode( "D" ) );
7633 t1.reRoot( t1.getNode( "CD" ) );
7634 t1.reRoot( t1.getNode( "D" ) );
7635 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
7638 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
7641 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
7644 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
7647 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
7650 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
7653 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",
7654 new NHXParser() )[ 0 ];
7655 t2.reRoot( t2.getNode( "A" ) );
7656 t2.reRoot( t2.getNode( "D" ) );
7657 t2.reRoot( t2.getNode( "ABC" ) );
7658 t2.reRoot( t2.getNode( "A" ) );
7659 t2.reRoot( t2.getNode( "B" ) );
7660 t2.reRoot( t2.getNode( "D" ) );
7661 t2.reRoot( t2.getNode( "C" ) );
7662 t2.reRoot( t2.getNode( "ABC" ) );
7663 t2.reRoot( t2.getNode( "A" ) );
7664 t2.reRoot( t2.getNode( "B" ) );
7665 t2.reRoot( t2.getNode( "AB" ) );
7666 t2.reRoot( t2.getNode( "AB" ) );
7667 t2.reRoot( t2.getNode( "D" ) );
7668 t2.reRoot( t2.getNode( "C" ) );
7669 t2.reRoot( t2.getNode( "B" ) );
7670 t2.reRoot( t2.getNode( "AB" ) );
7671 t2.reRoot( t2.getNode( "D" ) );
7672 t2.reRoot( t2.getNode( "D" ) );
7673 t2.reRoot( t2.getNode( "ABC" ) );
7674 t2.reRoot( t2.getNode( "A" ) );
7675 t2.reRoot( t2.getNode( "B" ) );
7676 t2.reRoot( t2.getNode( "AB" ) );
7677 t2.reRoot( t2.getNode( "D" ) );
7678 t2.reRoot( t2.getNode( "C" ) );
7679 t2.reRoot( t2.getNode( "ABC" ) );
7680 t2.reRoot( t2.getNode( "A" ) );
7681 t2.reRoot( t2.getNode( "B" ) );
7682 t2.reRoot( t2.getNode( "AB" ) );
7683 t2.reRoot( t2.getNode( "D" ) );
7684 t2.reRoot( t2.getNode( "D" ) );
7685 t2.reRoot( t2.getNode( "C" ) );
7686 t2.reRoot( t2.getNode( "A" ) );
7687 t2.reRoot( t2.getNode( "B" ) );
7688 t2.reRoot( t2.getNode( "AB" ) );
7689 t2.reRoot( t2.getNode( "C" ) );
7690 t2.reRoot( t2.getNode( "D" ) );
7691 t2.reRoot( t2.getNode( "ABC" ) );
7692 t2.reRoot( t2.getNode( "D" ) );
7693 t2.reRoot( t2.getNode( "A" ) );
7694 t2.reRoot( t2.getNode( "B" ) );
7695 t2.reRoot( t2.getNode( "AB" ) );
7696 t2.reRoot( t2.getNode( "C" ) );
7697 t2.reRoot( t2.getNode( "D" ) );
7698 t2.reRoot( t2.getNode( "ABC" ) );
7699 t2.reRoot( t2.getNode( "D" ) );
7700 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7703 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7706 t2.reRoot( t2.getNode( "ABC" ) );
7707 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7710 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7713 t2.reRoot( t2.getNode( "AB" ) );
7714 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7717 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7720 if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7723 t2.reRoot( t2.getNode( "AB" ) );
7724 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7727 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7730 if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7733 t2.reRoot( t2.getNode( "D" ) );
7734 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7737 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7740 t2.reRoot( t2.getNode( "ABC" ) );
7741 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7744 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7747 final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
7748 new NHXParser() )[ 0 ];
7749 t3.reRoot( t3.getNode( "B" ) );
7750 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7753 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7756 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7759 t3.reRoot( t3.getNode( "B" ) );
7760 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7763 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7766 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7769 t3.reRoot( t3.getRoot() );
7770 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7773 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7776 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7780 catch ( final Exception e ) {
7781 e.printStackTrace( System.out );
7787 private static boolean testSDIse() {
7789 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7790 final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
7791 final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
7792 gene1.setRooted( true );
7793 species1.setRooted( true );
7794 final SDI sdi = new SDI( gene1, species1 );
7795 if ( !gene1.getRoot().isDuplication() ) {
7798 final Phylogeny species2 = factory
7799 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7800 new NHXParser() )[ 0 ];
7801 final Phylogeny gene2 = factory
7802 .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7803 new NHXParser() )[ 0 ];
7804 species2.setRooted( true );
7805 gene2.setRooted( true );
7806 final SDI sdi2 = new SDI( gene2, species2 );
7807 if ( sdi2.getDuplicationsSum() != 0 ) {
7810 if ( !gene2.getNode( "ab" ).isSpeciation() ) {
7813 if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
7816 if ( !gene2.getNode( "abc" ).isSpeciation() ) {
7819 if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
7822 if ( !gene2.getNode( "r" ).isSpeciation() ) {
7825 if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
7828 final Phylogeny species3 = factory
7829 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7830 new NHXParser() )[ 0 ];
7831 final Phylogeny gene3 = factory
7832 .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7833 new NHXParser() )[ 0 ];
7834 species3.setRooted( true );
7835 gene3.setRooted( true );
7836 final SDI sdi3 = new SDI( gene3, species3 );
7837 if ( sdi3.getDuplicationsSum() != 1 ) {
7840 if ( !gene3.getNode( "aa" ).isDuplication() ) {
7843 if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
7846 final Phylogeny species4 = factory
7847 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7848 new NHXParser() )[ 0 ];
7849 final Phylogeny gene4 = factory
7850 .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7851 new NHXParser() )[ 0 ];
7852 species4.setRooted( true );
7853 gene4.setRooted( true );
7854 final SDI sdi4 = new SDI( gene4, species4 );
7855 if ( sdi4.getDuplicationsSum() != 1 ) {
7858 if ( !gene4.getNode( "ac" ).isSpeciation() ) {
7861 if ( !gene4.getNode( "abc" ).isDuplication() ) {
7864 if ( gene4.getNode( "abcd" ).isDuplication() ) {
7867 if ( species4.getNumberOfExternalNodes() != 6 ) {
7870 if ( gene4.getNumberOfExternalNodes() != 6 ) {
7873 final Phylogeny species5 = factory
7874 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7875 new NHXParser() )[ 0 ];
7876 final Phylogeny gene5 = factory
7877 .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7878 new NHXParser() )[ 0 ];
7879 species5.setRooted( true );
7880 gene5.setRooted( true );
7881 final SDI sdi5 = new SDI( gene5, species5 );
7882 if ( sdi5.getDuplicationsSum() != 2 ) {
7885 if ( !gene5.getNode( "ad" ).isSpeciation() ) {
7888 if ( !gene5.getNode( "adc" ).isDuplication() ) {
7891 if ( !gene5.getNode( "abcd" ).isDuplication() ) {
7894 if ( species5.getNumberOfExternalNodes() != 6 ) {
7897 if ( gene5.getNumberOfExternalNodes() != 6 ) {
7900 // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
7901 // Conjecture for Comparing Molecular Phylogenies"
7902 // J. of Comput Bio. Vol. 4, No 2, pp.177-187
7903 final Phylogeny species6 = factory
7904 .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,"
7905 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
7906 new NHXParser() )[ 0 ];
7907 final Phylogeny gene6 = factory
7908 .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,"
7909 + "((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,"
7910 + "(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;",
7911 new NHXParser() )[ 0 ];
7912 species6.setRooted( true );
7913 gene6.setRooted( true );
7914 final SDI sdi6 = new SDI( gene6, species6 );
7915 if ( sdi6.getDuplicationsSum() != 3 ) {
7918 if ( !gene6.getNode( "r" ).isDuplication() ) {
7921 if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
7924 if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
7927 if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
7930 if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
7933 if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
7936 if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
7939 if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
7942 sdi6.computeMappingCostL();
7943 if ( sdi6.computeMappingCostL() != 17 ) {
7946 if ( species6.getNumberOfExternalNodes() != 9 ) {
7949 if ( gene6.getNumberOfExternalNodes() != 9 ) {
7952 final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
7953 + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
7954 + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
7955 + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
7956 + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
7957 species7.setRooted( true );
7958 final Phylogeny gene7_1 = Test
7959 .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])" );
7960 gene7_1.setRooted( true );
7961 final SDI sdi7 = new SDI( gene7_1, species7 );
7962 if ( sdi7.getDuplicationsSum() != 0 ) {
7965 if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
7968 if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
7971 if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
7974 if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
7977 if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
7980 if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
7983 if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
7986 if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
7989 final Phylogeny gene7_2 = Test
7990 .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])" );
7991 gene7_2.setRooted( true );
7992 final SDI sdi7_2 = new SDI( gene7_2, species7 );
7993 if ( sdi7_2.getDuplicationsSum() != 1 ) {
7996 if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
7999 if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
8002 if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
8005 if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
8008 if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
8011 if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
8014 if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
8017 if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
8020 if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
8024 catch ( final Exception e ) {
8030 private static boolean testSDIunrooted() {
8032 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8033 final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
8034 final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
8035 final Iterator<PhylogenyBranch> iter = l.iterator();
8036 PhylogenyBranch br = iter.next();
8037 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
8040 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
8044 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
8047 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
8051 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
8054 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
8058 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8061 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8065 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8068 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8072 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
8075 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
8079 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8082 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8086 if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8089 if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8093 if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8096 if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8100 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8103 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8107 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
8110 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
8114 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
8117 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
8121 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
8124 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
8128 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
8131 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
8135 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
8138 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
8141 if ( iter.hasNext() ) {
8144 final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
8145 final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
8146 final Iterator<PhylogenyBranch> iter1 = l1.iterator();
8148 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
8151 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
8155 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8158 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8162 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8165 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8168 if ( iter1.hasNext() ) {
8171 final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
8172 final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
8173 final Iterator<PhylogenyBranch> iter2 = l2.iterator();
8175 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
8178 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
8182 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8185 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8189 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8192 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8195 if ( iter2.hasNext() ) {
8198 final Phylogeny species0 = factory
8199 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
8200 new NHXParser() )[ 0 ];
8201 final Phylogeny gene1 = factory
8202 .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])",
8203 new NHXParser() )[ 0 ];
8204 species0.setRooted( true );
8205 gene1.setRooted( true );
8206 final SDIR sdi_unrooted = new SDIR();
8207 sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
8208 if ( sdi_unrooted.getCount() != 1 ) {
8211 if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
8214 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
8217 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
8220 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8223 final Phylogeny gene2 = factory
8224 .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])",
8225 new NHXParser() )[ 0 ];
8226 gene2.setRooted( true );
8227 sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
8228 if ( sdi_unrooted.getCount() != 1 ) {
8231 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8234 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8237 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
8240 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8243 final Phylogeny species6 = factory
8244 .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,"
8245 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8246 new NHXParser() )[ 0 ];
8247 final Phylogeny gene6 = factory
8248 .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],"
8249 + "(((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],"
8250 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8251 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8252 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8253 new NHXParser() )[ 0 ];
8254 species6.setRooted( true );
8255 gene6.setRooted( true );
8256 Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
8257 if ( sdi_unrooted.getCount() != 1 ) {
8260 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8263 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8266 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8269 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8272 if ( !p6[ 0 ].getRoot().isDuplication() ) {
8275 if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8278 if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8281 if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
8284 if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8287 if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
8290 if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
8293 if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8297 final Phylogeny species7 = factory
8298 .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,"
8299 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8300 new NHXParser() )[ 0 ];
8301 final Phylogeny gene7 = factory
8302 .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],"
8303 + "(((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],"
8304 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8305 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8306 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8307 new NHXParser() )[ 0 ];
8308 species7.setRooted( true );
8309 gene7.setRooted( true );
8310 Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
8311 if ( sdi_unrooted.getCount() != 1 ) {
8314 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8317 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8320 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8323 if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
8326 if ( !p7[ 0 ].getRoot().isDuplication() ) {
8329 if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8332 if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8335 if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
8338 if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8341 if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
8344 if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
8347 if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8351 final Phylogeny species8 = factory
8352 .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,"
8353 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8354 new NHXParser() )[ 0 ];
8355 final Phylogeny gene8 = factory
8356 .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],"
8357 + "(((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],"
8358 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8359 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8360 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8361 new NHXParser() )[ 0 ];
8362 species8.setRooted( true );
8363 gene8.setRooted( true );
8364 Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
8365 if ( sdi_unrooted.getCount() != 1 ) {
8368 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8371 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8374 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8377 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8380 if ( !p8[ 0 ].getRoot().isDuplication() ) {
8383 if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8386 if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8389 if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
8392 if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8395 if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
8398 if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
8401 if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8406 catch ( final Exception e ) {
8407 e.printStackTrace( System.out );
8413 private static boolean testSplit() {
8415 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8416 final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
8417 //Archaeopteryx.createApplication( p0 );
8418 final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
8419 ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8420 ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8421 ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8422 ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8423 ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8424 ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8425 ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8426 ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8427 ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8428 final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
8429 // System.out.println( s0.toString() );
8431 Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
8432 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8433 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8434 if ( s0.match( query_nodes ) ) {
8437 query_nodes = new HashSet<PhylogenyNode>();
8438 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8439 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8440 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8441 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8442 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8443 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8444 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8445 if ( !s0.match( query_nodes ) ) {
8449 query_nodes = new HashSet<PhylogenyNode>();
8450 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8451 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8452 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8453 if ( !s0.match( query_nodes ) ) {
8457 query_nodes = new HashSet<PhylogenyNode>();
8458 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8459 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8460 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8461 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8462 if ( !s0.match( query_nodes ) ) {
8466 query_nodes = new HashSet<PhylogenyNode>();
8467 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8468 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8469 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8470 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8471 if ( !s0.match( query_nodes ) ) {
8475 query_nodes = new HashSet<PhylogenyNode>();
8476 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8477 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8478 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8479 if ( !s0.match( query_nodes ) ) {
8483 query_nodes = new HashSet<PhylogenyNode>();
8484 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8485 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8486 if ( !s0.match( query_nodes ) ) {
8490 query_nodes = new HashSet<PhylogenyNode>();
8491 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8492 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8493 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8494 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8495 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8496 if ( !s0.match( query_nodes ) ) {
8500 query_nodes = new HashSet<PhylogenyNode>();
8501 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8502 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8503 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8504 if ( !s0.match( query_nodes ) ) {
8508 query_nodes = new HashSet<PhylogenyNode>();
8509 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8510 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8511 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8512 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8513 if ( !s0.match( query_nodes ) ) {
8517 query_nodes = new HashSet<PhylogenyNode>();
8518 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8519 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8520 if ( s0.match( query_nodes ) ) {
8524 query_nodes = new HashSet<PhylogenyNode>();
8525 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8526 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8527 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8528 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8529 if ( s0.match( query_nodes ) ) {
8533 query_nodes = new HashSet<PhylogenyNode>();
8534 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8535 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8536 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8537 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8538 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8539 if ( s0.match( query_nodes ) ) {
8543 query_nodes = new HashSet<PhylogenyNode>();
8544 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8545 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8546 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8547 if ( s0.match( query_nodes ) ) {
8551 query_nodes = new HashSet<PhylogenyNode>();
8552 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8553 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8554 if ( s0.match( query_nodes ) ) {
8558 query_nodes = new HashSet<PhylogenyNode>();
8559 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8560 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8561 if ( s0.match( query_nodes ) ) {
8565 query_nodes = new HashSet<PhylogenyNode>();
8566 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8567 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8568 if ( s0.match( query_nodes ) ) {
8572 query_nodes = new HashSet<PhylogenyNode>();
8573 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8574 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8575 if ( s0.match( query_nodes ) ) {
8579 query_nodes = new HashSet<PhylogenyNode>();
8580 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8581 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8582 if ( s0.match( query_nodes ) ) {
8586 query_nodes = new HashSet<PhylogenyNode>();
8587 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8588 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8589 if ( s0.match( query_nodes ) ) {
8593 query_nodes = new HashSet<PhylogenyNode>();
8594 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8595 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8596 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8597 if ( s0.match( query_nodes ) ) {
8601 query_nodes = new HashSet<PhylogenyNode>();
8602 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8603 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8604 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8605 if ( s0.match( query_nodes ) ) {
8609 query_nodes = new HashSet<PhylogenyNode>();
8610 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8611 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8612 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8613 if ( s0.match( query_nodes ) ) {
8617 query_nodes = new HashSet<PhylogenyNode>();
8618 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8619 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8620 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8621 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8622 if ( s0.match( query_nodes ) ) {
8626 // query_nodes = new HashSet<PhylogenyNode>();
8627 // query_nodes.add( new PhylogenyNode( "X" ) );
8628 // query_nodes.add( new PhylogenyNode( "Y" ) );
8629 // query_nodes.add( new PhylogenyNode( "A" ) );
8630 // query_nodes.add( new PhylogenyNode( "B" ) );
8631 // query_nodes.add( new PhylogenyNode( "C" ) );
8632 // query_nodes.add( new PhylogenyNode( "D" ) );
8633 // query_nodes.add( new PhylogenyNode( "E" ) );
8634 // query_nodes.add( new PhylogenyNode( "F" ) );
8635 // query_nodes.add( new PhylogenyNode( "G" ) );
8636 // if ( !s0.match( query_nodes ) ) {
8639 // query_nodes = new HashSet<PhylogenyNode>();
8640 // query_nodes.add( new PhylogenyNode( "X" ) );
8641 // query_nodes.add( new PhylogenyNode( "Y" ) );
8642 // query_nodes.add( new PhylogenyNode( "A" ) );
8643 // query_nodes.add( new PhylogenyNode( "B" ) );
8644 // query_nodes.add( new PhylogenyNode( "C" ) );
8645 // if ( !s0.match( query_nodes ) ) {
8649 // query_nodes = new HashSet<PhylogenyNode>();
8650 // query_nodes.add( new PhylogenyNode( "X" ) );
8651 // query_nodes.add( new PhylogenyNode( "Y" ) );
8652 // query_nodes.add( new PhylogenyNode( "D" ) );
8653 // query_nodes.add( new PhylogenyNode( "E" ) );
8654 // query_nodes.add( new PhylogenyNode( "F" ) );
8655 // query_nodes.add( new PhylogenyNode( "G" ) );
8656 // if ( !s0.match( query_nodes ) ) {
8660 // query_nodes = new HashSet<PhylogenyNode>();
8661 // query_nodes.add( new PhylogenyNode( "X" ) );
8662 // query_nodes.add( new PhylogenyNode( "Y" ) );
8663 // query_nodes.add( new PhylogenyNode( "A" ) );
8664 // query_nodes.add( new PhylogenyNode( "B" ) );
8665 // query_nodes.add( new PhylogenyNode( "C" ) );
8666 // query_nodes.add( new PhylogenyNode( "D" ) );
8667 // if ( !s0.match( query_nodes ) ) {
8671 // query_nodes = new HashSet<PhylogenyNode>();
8672 // query_nodes.add( new PhylogenyNode( "X" ) );
8673 // query_nodes.add( new PhylogenyNode( "Y" ) );
8674 // query_nodes.add( new PhylogenyNode( "E" ) );
8675 // query_nodes.add( new PhylogenyNode( "F" ) );
8676 // query_nodes.add( new PhylogenyNode( "G" ) );
8677 // if ( !s0.match( query_nodes ) ) {
8681 // query_nodes = new HashSet<PhylogenyNode>();
8682 // query_nodes.add( new PhylogenyNode( "X" ) );
8683 // query_nodes.add( new PhylogenyNode( "Y" ) );
8684 // query_nodes.add( new PhylogenyNode( "F" ) );
8685 // query_nodes.add( new PhylogenyNode( "G" ) );
8686 // if ( !s0.match( query_nodes ) ) {
8690 query_nodes = new HashSet<PhylogenyNode>();
8691 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8692 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8693 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8694 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8695 if ( s0.match( query_nodes ) ) {
8699 query_nodes = new HashSet<PhylogenyNode>();
8700 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8701 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8702 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8703 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8704 if ( s0.match( query_nodes ) ) {
8707 ///////////////////////////
8709 query_nodes = new HashSet<PhylogenyNode>();
8710 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8711 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8712 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8713 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8714 if ( s0.match( query_nodes ) ) {
8718 query_nodes = new HashSet<PhylogenyNode>();
8719 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8720 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8721 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8722 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8723 if ( s0.match( query_nodes ) ) {
8727 query_nodes = new HashSet<PhylogenyNode>();
8728 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8729 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8730 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8731 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8732 if ( s0.match( query_nodes ) ) {
8736 query_nodes = new HashSet<PhylogenyNode>();
8737 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8738 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8739 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8740 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8741 if ( s0.match( query_nodes ) ) {
8745 query_nodes = new HashSet<PhylogenyNode>();
8746 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8747 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8748 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8749 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8750 if ( s0.match( query_nodes ) ) {
8754 query_nodes = new HashSet<PhylogenyNode>();
8755 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8756 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8757 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8758 if ( s0.match( query_nodes ) ) {
8762 query_nodes = new HashSet<PhylogenyNode>();
8763 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8764 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8765 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8766 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8767 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8768 if ( s0.match( query_nodes ) ) {
8772 query_nodes = new HashSet<PhylogenyNode>();
8773 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8774 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8775 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8776 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8777 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8778 if ( s0.match( query_nodes ) ) {
8782 query_nodes = new HashSet<PhylogenyNode>();
8783 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8784 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8785 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8786 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8787 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8788 if ( s0.match( query_nodes ) ) {
8792 query_nodes = new HashSet<PhylogenyNode>();
8793 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8794 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8795 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8796 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8797 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8798 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8799 if ( s0.match( query_nodes ) ) {
8803 catch ( final Exception e ) {
8804 e.printStackTrace();
8810 private static boolean testSplitStrict() {
8812 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8813 final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
8814 final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
8815 ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8816 ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8817 ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8818 ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8819 ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8820 ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8821 ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8822 final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
8823 Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
8824 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8825 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8826 if ( s0.match( query_nodes ) ) {
8829 query_nodes = new HashSet<PhylogenyNode>();
8830 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8831 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8832 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8833 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8834 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8835 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8836 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8837 if ( !s0.match( query_nodes ) ) {
8841 query_nodes = new HashSet<PhylogenyNode>();
8842 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8843 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8844 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8845 if ( !s0.match( query_nodes ) ) {
8849 query_nodes = new HashSet<PhylogenyNode>();
8850 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8851 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8852 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8853 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8854 if ( !s0.match( query_nodes ) ) {
8858 query_nodes = new HashSet<PhylogenyNode>();
8859 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8860 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8861 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8862 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8863 if ( !s0.match( query_nodes ) ) {
8867 query_nodes = new HashSet<PhylogenyNode>();
8868 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8869 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8870 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8871 if ( !s0.match( query_nodes ) ) {
8875 query_nodes = new HashSet<PhylogenyNode>();
8876 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8877 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8878 if ( !s0.match( query_nodes ) ) {
8882 query_nodes = new HashSet<PhylogenyNode>();
8883 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8884 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8885 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8886 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8887 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8888 if ( !s0.match( query_nodes ) ) {
8892 query_nodes = new HashSet<PhylogenyNode>();
8893 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8894 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8895 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8896 if ( !s0.match( query_nodes ) ) {
8900 query_nodes = new HashSet<PhylogenyNode>();
8901 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8902 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8903 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8904 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8905 if ( !s0.match( query_nodes ) ) {
8909 query_nodes = new HashSet<PhylogenyNode>();
8910 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8911 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8912 if ( s0.match( query_nodes ) ) {
8916 query_nodes = new HashSet<PhylogenyNode>();
8917 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8918 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8919 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8920 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8921 if ( s0.match( query_nodes ) ) {
8925 query_nodes = new HashSet<PhylogenyNode>();
8926 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8927 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8928 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8929 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8930 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8931 if ( s0.match( query_nodes ) ) {
8935 query_nodes = new HashSet<PhylogenyNode>();
8936 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8937 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8938 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8939 if ( s0.match( query_nodes ) ) {
8943 query_nodes = new HashSet<PhylogenyNode>();
8944 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8945 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8946 if ( s0.match( query_nodes ) ) {
8950 query_nodes = new HashSet<PhylogenyNode>();
8951 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8952 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8953 if ( s0.match( query_nodes ) ) {
8957 query_nodes = new HashSet<PhylogenyNode>();
8958 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8959 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8960 if ( s0.match( query_nodes ) ) {
8964 query_nodes = new HashSet<PhylogenyNode>();
8965 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8966 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8967 if ( s0.match( query_nodes ) ) {
8971 query_nodes = new HashSet<PhylogenyNode>();
8972 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8973 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8974 if ( s0.match( query_nodes ) ) {
8978 query_nodes = new HashSet<PhylogenyNode>();
8979 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8980 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8981 if ( s0.match( query_nodes ) ) {
8985 query_nodes = new HashSet<PhylogenyNode>();
8986 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8987 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8988 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8989 if ( s0.match( query_nodes ) ) {
8993 query_nodes = new HashSet<PhylogenyNode>();
8994 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8995 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8996 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8997 if ( s0.match( query_nodes ) ) {
9001 query_nodes = new HashSet<PhylogenyNode>();
9002 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9003 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9004 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9005 if ( s0.match( query_nodes ) ) {
9009 query_nodes = new HashSet<PhylogenyNode>();
9010 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9011 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9012 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9013 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9014 if ( s0.match( query_nodes ) ) {
9018 catch ( final Exception e ) {
9019 e.printStackTrace();
9025 private static boolean testSubtreeDeletion() {
9027 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9028 final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
9029 t1.deleteSubtree( t1.getNode( "A" ), false );
9030 if ( t1.getNumberOfExternalNodes() != 5 ) {
9033 t1.toNewHampshireX();
9034 t1.deleteSubtree( t1.getNode( "E" ), false );
9035 if ( t1.getNumberOfExternalNodes() != 4 ) {
9038 t1.toNewHampshireX();
9039 t1.deleteSubtree( t1.getNode( "F" ), false );
9040 if ( t1.getNumberOfExternalNodes() != 3 ) {
9043 t1.toNewHampshireX();
9044 t1.deleteSubtree( t1.getNode( "D" ), false );
9045 t1.toNewHampshireX();
9046 if ( t1.getNumberOfExternalNodes() != 3 ) {
9049 t1.deleteSubtree( t1.getNode( "def" ), false );
9050 t1.toNewHampshireX();
9051 if ( t1.getNumberOfExternalNodes() != 2 ) {
9054 t1.deleteSubtree( t1.getNode( "B" ), false );
9055 t1.toNewHampshireX();
9056 if ( t1.getNumberOfExternalNodes() != 1 ) {
9059 t1.deleteSubtree( t1.getNode( "C" ), false );
9060 t1.toNewHampshireX();
9061 if ( t1.getNumberOfExternalNodes() != 1 ) {
9064 t1.deleteSubtree( t1.getNode( "abc" ), false );
9065 t1.toNewHampshireX();
9066 if ( t1.getNumberOfExternalNodes() != 1 ) {
9069 t1.deleteSubtree( t1.getNode( "r" ), false );
9070 if ( t1.getNumberOfExternalNodes() != 0 ) {
9073 if ( !t1.isEmpty() ) {
9076 final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
9077 t2.deleteSubtree( t2.getNode( "A" ), false );
9078 t2.toNewHampshireX();
9079 if ( t2.getNumberOfExternalNodes() != 5 ) {
9082 t2.deleteSubtree( t2.getNode( "abc" ), false );
9083 t2.toNewHampshireX();
9084 if ( t2.getNumberOfExternalNodes() != 3 ) {
9087 t2.deleteSubtree( t2.getNode( "def" ), false );
9088 t2.toNewHampshireX();
9089 if ( t2.getNumberOfExternalNodes() != 1 ) {
9093 catch ( final Exception e ) {
9094 e.printStackTrace( System.out );
9100 private static boolean testSupportCount() {
9102 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9103 final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
9104 final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
9105 + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
9106 + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
9107 + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
9108 + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
9110 SupportCount.count( t0_1, phylogenies_1, true, false );
9111 final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
9112 final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
9113 + "(((((A,B),C),D),E),((F,G),X))"
9114 + "(((((A,Y),B),C),D),((F,G),E))"
9115 + "(((((A,B),C),D),E),(F,G))"
9116 + "(((((A,B),C),D),E),(F,G))"
9117 + "(((((A,B),C),D),E),(F,G))"
9118 + "(((((A,B),C),D),E),(F,G),Z)"
9119 + "(((((A,B),C),D),E),(F,G))"
9120 + "((((((A,B),C),D),E),F),G)"
9121 + "(((((X,Y),F,G),E),((A,B),C)),D)",
9123 SupportCount.count( t0_2, phylogenies_2, true, false );
9124 final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
9125 while ( it.hasNext() ) {
9126 final PhylogenyNode n = it.next();
9127 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
9131 final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
9132 final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
9133 + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
9134 SupportCount.count( t0_3, phylogenies_3, true, false );
9135 t0_3.reRoot( t0_3.getNode( "def" ).getId() );
9136 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
9139 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
9142 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
9145 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
9148 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
9151 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
9154 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
9157 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
9160 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
9163 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
9166 final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9167 final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
9168 + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
9169 SupportCount.count( t0_4, phylogenies_4, true, false );
9170 t0_4.reRoot( t0_4.getNode( "F" ).getId() );
9171 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
9174 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
9177 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
9180 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
9183 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
9186 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
9189 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
9192 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
9195 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
9198 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
9201 Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9202 final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9203 double d = SupportCount.compare( b1, a, true, true, true );
9204 if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
9207 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9208 final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9209 d = SupportCount.compare( b2, a, true, true, true );
9210 if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
9213 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9214 final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
9215 d = SupportCount.compare( b3, a, true, true, true );
9216 if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
9219 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
9220 final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
9221 d = SupportCount.compare( b4, a, true, true, false );
9222 if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
9226 catch ( final Exception e ) {
9227 e.printStackTrace( System.out );
9233 private static boolean testSupportTransfer() {
9235 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9236 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)",
9237 new NHXParser() )[ 0 ];
9238 final Phylogeny p2 = factory
9239 .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 ];
9240 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
9243 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
9246 support_transfer.moveBranchLengthsToBootstrap( p1 );
9247 support_transfer.transferSupportValues( p1, p2 );
9248 if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
9251 if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
9254 if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
9257 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
9260 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
9263 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
9266 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
9269 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
9273 catch ( final Exception e ) {
9274 e.printStackTrace( System.out );
9280 private static boolean testUniprotTaxonomySearch() {
9282 List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
9284 if ( results.size() != 1 ) {
9287 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9290 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9293 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9296 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9299 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9303 results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
9304 if ( results.size() != 1 ) {
9307 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9310 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9313 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9316 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9319 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9323 results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
9324 if ( results.size() != 1 ) {
9327 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9330 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9333 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9336 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9339 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9343 results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
9344 if ( results.size() != 1 ) {
9347 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9350 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9353 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9356 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9359 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9362 if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
9365 if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
9368 if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
9369 .equals( "Nematostella vectensis" ) ) {
9370 System.out.println( results.get( 0 ).getLineage() );
9374 catch ( final IOException e ) {
9375 System.out.println();
9376 System.out.println( "the following might be due to absence internet connection:" );
9377 e.printStackTrace( System.out );
9380 catch ( final Exception e ) {
9386 private static boolean testEmblEntryRetrieval() {
9387 //The format for GenBank Accession numbers are:
9388 //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
9389 //Protein: 3 letters + 5 numerals
9390 //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
9391 if ( !SequenceIdParser.parseGenbankAccessor( "AY423861" ).equals( "AY423861" ) ) {
9394 if ( !SequenceIdParser.parseGenbankAccessor( ".AY423861.2" ).equals( "AY423861.2" ) ) {
9397 if ( !SequenceIdParser.parseGenbankAccessor( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
9400 if ( SequenceIdParser.parseGenbankAccessor( "AAY423861" ) != null ) {
9403 if ( SequenceIdParser.parseGenbankAccessor( "AY4238612" ) != null ) {
9406 if ( SequenceIdParser.parseGenbankAccessor( "AAY4238612" ) != null ) {
9409 if ( SequenceIdParser.parseGenbankAccessor( "Y423861" ) != null ) {
9412 if ( !SequenceIdParser.parseGenbankAccessor( "S12345" ).equals( "S12345" ) ) {
9415 if ( !SequenceIdParser.parseGenbankAccessor( "|S12345|" ).equals( "S12345" ) ) {
9418 if ( SequenceIdParser.parseGenbankAccessor( "|S123456" ) != null ) {
9421 if ( SequenceIdParser.parseGenbankAccessor( "ABC123456" ) != null ) {
9424 if ( !SequenceIdParser.parseGenbankAccessor( "ABC12345" ).equals( "ABC12345" ) ) {
9427 if ( !SequenceIdParser.parseGenbankAccessor( "&ABC12345&" ).equals( "ABC12345" ) ) {
9430 if ( SequenceIdParser.parseGenbankAccessor( "ABCD12345" ) != null ) {
9436 private static boolean testUniprotEntryRetrieval() {
9438 final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
9439 if ( !entry.getAccession().equals( "P12345" ) ) {
9442 if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
9445 if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
9448 if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
9452 catch ( final IOException e ) {
9453 System.out.println();
9454 System.out.println( "the following might be due to absence internet connection:" );
9455 e.printStackTrace( System.out );
9458 catch ( final Exception e ) {
9464 private static boolean testWabiTxSearch() {
9467 result = TxSearch.searchSimple( "nematostella" );
9468 result = TxSearch.getTxId( "nematostella" );
9469 if ( !result.equals( "45350" ) ) {
9472 result = TxSearch.getTxName( "45350" );
9473 if ( !result.equals( "Nematostella" ) ) {
9476 result = TxSearch.getTxId( "nematostella vectensis" );
9477 if ( !result.equals( "45351" ) ) {
9480 result = TxSearch.getTxName( "45351" );
9481 if ( !result.equals( "Nematostella vectensis" ) ) {
9484 result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
9485 if ( !result.equals( "536089" ) ) {
9488 result = TxSearch.getTxName( "536089" );
9489 if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
9492 final List<String> queries = new ArrayList<String>();
9493 queries.add( "Campylobacter coli" );
9494 queries.add( "Escherichia coli" );
9495 queries.add( "Arabidopsis" );
9496 queries.add( "Trichoplax" );
9497 queries.add( "Samanea saman" );
9498 queries.add( "Kluyveromyces marxianus" );
9499 queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
9500 queries.add( "Bornavirus parrot/PDD/2008" );
9501 final List<RANKS> ranks = new ArrayList<RANKS>();
9502 ranks.add( RANKS.SUPERKINGDOM );
9503 ranks.add( RANKS.KINGDOM );
9504 ranks.add( RANKS.FAMILY );
9505 ranks.add( RANKS.GENUS );
9506 ranks.add( RANKS.TRIBE );
9507 result = TxSearch.searchLineage( queries, ranks );
9508 result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
9509 result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
9511 catch ( final Exception e ) {
9512 System.out.println();
9513 System.out.println( "the following might be due to absence internet connection:" );
9514 e.printStackTrace( System.out );
9520 private static boolean testAminoAcidSequence() {
9522 final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
9523 if ( aa1.getLength() != 13 ) {
9526 if ( aa1.getResidueAt( 0 ) != 'A' ) {
9529 if ( aa1.getResidueAt( 2 ) != 'K' ) {
9532 if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
9535 final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
9536 if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
9539 final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
9540 if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
9543 final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
9544 if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
9548 catch ( final Exception e ) {
9549 e.printStackTrace();
9555 private static boolean testCreateBalancedPhylogeny() {
9557 final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
9558 if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
9561 if ( p0.getNumberOfExternalNodes() != 15625 ) {
9564 final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
9565 if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
9568 if ( p1.getNumberOfExternalNodes() != 100 ) {
9572 catch ( final Exception e ) {
9573 e.printStackTrace();
9579 private static boolean testFastaParser() {
9581 if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
9584 if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
9587 final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
9588 if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
9591 if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
9594 if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
9597 if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
9600 if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
9603 if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
9607 catch ( final Exception e ) {
9608 e.printStackTrace();
9614 private static boolean testGeneralMsaParser() {
9616 final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
9617 final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
9618 final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
9619 final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
9620 final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
9621 final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
9622 final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
9623 final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
9624 if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9627 if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9630 if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9633 if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9636 if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9639 if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9642 if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9645 if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9648 if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9651 if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9654 if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9657 if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9660 final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
9661 if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
9664 if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
9667 if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
9670 final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
9671 if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
9674 if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
9677 if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
9680 final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
9681 if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
9684 if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
9687 if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
9691 catch ( final Exception e ) {
9692 e.printStackTrace();
9698 private static boolean testMafft( final String path ) {
9700 final List<String> opts = new ArrayList<String>();
9701 opts.add( "--maxiterate" );
9703 opts.add( "--localpair" );
9704 opts.add( "--quiet" );
9706 final MsaInferrer mafft = Mafft.createInstance( path );
9707 msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
9708 if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
9711 if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
9715 catch ( final Exception e ) {
9716 e.printStackTrace( System.out );
9722 private static boolean testNextNodeWithCollapsing() {
9724 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9726 List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
9727 final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9728 final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
9729 t0.getNode( "cd" ).setCollapse( true );
9730 t0.getNode( "cde" ).setCollapse( true );
9731 n = t0.getFirstExternalNode();
9732 while ( n != null ) {
9734 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9736 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
9739 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
9742 if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
9745 if ( !ext.get( 3 ).getName().equals( "f" ) ) {
9748 if ( !ext.get( 4 ).getName().equals( "g" ) ) {
9751 if ( !ext.get( 5 ).getName().equals( "h" ) ) {
9755 final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9756 final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
9757 t1.getNode( "ab" ).setCollapse( true );
9758 t1.getNode( "cd" ).setCollapse( true );
9759 t1.getNode( "cde" ).setCollapse( true );
9760 n = t1.getNode( "ab" );
9761 ext = new ArrayList<PhylogenyNode>();
9762 while ( n != null ) {
9764 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9766 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9769 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9772 if ( !ext.get( 2 ).getName().equals( "f" ) ) {
9775 if ( !ext.get( 3 ).getName().equals( "g" ) ) {
9778 if ( !ext.get( 4 ).getName().equals( "h" ) ) {
9784 final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9785 final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
9786 t2.getNode( "ab" ).setCollapse( true );
9787 t2.getNode( "cd" ).setCollapse( true );
9788 t2.getNode( "cde" ).setCollapse( true );
9789 t2.getNode( "c" ).setCollapse( true );
9790 t2.getNode( "d" ).setCollapse( true );
9791 t2.getNode( "e" ).setCollapse( true );
9792 t2.getNode( "gh" ).setCollapse( true );
9793 n = t2.getNode( "ab" );
9794 ext = new ArrayList<PhylogenyNode>();
9795 while ( n != null ) {
9797 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9799 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9802 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9805 if ( !ext.get( 2 ).getName().equals( "f" ) ) {
9808 if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
9814 final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9815 final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
9816 t3.getNode( "ab" ).setCollapse( true );
9817 t3.getNode( "cd" ).setCollapse( true );
9818 t3.getNode( "cde" ).setCollapse( true );
9819 t3.getNode( "c" ).setCollapse( true );
9820 t3.getNode( "d" ).setCollapse( true );
9821 t3.getNode( "e" ).setCollapse( true );
9822 t3.getNode( "gh" ).setCollapse( true );
9823 t3.getNode( "fgh" ).setCollapse( true );
9824 n = t3.getNode( "ab" );
9825 ext = new ArrayList<PhylogenyNode>();
9826 while ( n != null ) {
9828 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9830 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9833 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9836 if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
9842 final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9843 final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
9844 t4.getNode( "ab" ).setCollapse( true );
9845 t4.getNode( "cd" ).setCollapse( true );
9846 t4.getNode( "cde" ).setCollapse( true );
9847 t4.getNode( "c" ).setCollapse( true );
9848 t4.getNode( "d" ).setCollapse( true );
9849 t4.getNode( "e" ).setCollapse( true );
9850 t4.getNode( "gh" ).setCollapse( true );
9851 t4.getNode( "fgh" ).setCollapse( true );
9852 t4.getNode( "abcdefgh" ).setCollapse( true );
9853 n = t4.getNode( "abcdefgh" );
9854 if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
9859 final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9860 final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
9862 n = t5.getFirstExternalNode();
9863 while ( n != null ) {
9865 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9867 if ( ext.size() != 8 ) {
9870 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
9873 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
9876 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
9879 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
9882 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
9885 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
9888 if ( !ext.get( 6 ).getName().equals( "g" ) ) {
9891 if ( !ext.get( 7 ).getName().equals( "h" ) ) {
9896 final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9897 final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
9899 t6.getNode( "ab" ).setCollapse( true );
9900 n = t6.getNode( "ab" );
9901 while ( n != null ) {
9903 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9905 if ( ext.size() != 7 ) {
9908 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9911 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
9914 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
9917 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
9920 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
9923 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
9926 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
9931 final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9932 final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
9934 t7.getNode( "cd" ).setCollapse( true );
9935 n = t7.getNode( "a" );
9936 while ( n != null ) {
9938 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9940 if ( ext.size() != 7 ) {
9943 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
9946 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
9949 if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
9952 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
9955 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
9958 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
9961 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
9966 final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9967 final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
9969 t8.getNode( "cd" ).setCollapse( true );
9970 t8.getNode( "c" ).setCollapse( true );
9971 t8.getNode( "d" ).setCollapse( true );
9972 n = t8.getNode( "a" );
9973 while ( n != null ) {
9975 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9977 if ( ext.size() != 7 ) {
9980 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
9983 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
9986 if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
9987 System.out.println( "2 fail" );
9990 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
9993 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
9996 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
9999 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
10004 final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10005 final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
10007 t9.getNode( "gh" ).setCollapse( true );
10008 n = t9.getNode( "a" );
10009 while ( n != null ) {
10011 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10013 if ( ext.size() != 7 ) {
10016 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10019 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10022 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10025 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10028 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10031 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
10034 if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
10039 final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10040 final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
10042 t10.getNode( "gh" ).setCollapse( true );
10043 t10.getNode( "g" ).setCollapse( true );
10044 t10.getNode( "h" ).setCollapse( true );
10045 n = t10.getNode( "a" );
10046 while ( n != null ) {
10048 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10050 if ( ext.size() != 7 ) {
10053 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10056 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10059 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10062 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10065 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10068 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
10071 if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
10076 final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10077 final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
10079 t11.getNode( "gh" ).setCollapse( true );
10080 t11.getNode( "fgh" ).setCollapse( true );
10081 n = t11.getNode( "a" );
10082 while ( n != null ) {
10084 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10086 if ( ext.size() != 6 ) {
10089 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10092 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10095 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10098 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10101 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10104 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10109 final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10110 final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
10112 t12.getNode( "gh" ).setCollapse( true );
10113 t12.getNode( "fgh" ).setCollapse( true );
10114 t12.getNode( "g" ).setCollapse( true );
10115 t12.getNode( "h" ).setCollapse( true );
10116 t12.getNode( "f" ).setCollapse( true );
10117 n = t12.getNode( "a" );
10118 while ( n != null ) {
10120 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10122 if ( ext.size() != 6 ) {
10125 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10128 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10131 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10134 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10137 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10140 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10145 final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10146 final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
10148 t13.getNode( "ab" ).setCollapse( true );
10149 t13.getNode( "b" ).setCollapse( true );
10150 t13.getNode( "fgh" ).setCollapse( true );
10151 t13.getNode( "gh" ).setCollapse( true );
10152 n = t13.getNode( "ab" );
10153 while ( n != null ) {
10155 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10157 if ( ext.size() != 5 ) {
10160 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10163 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10166 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10169 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10172 if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
10177 final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
10178 final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
10180 t14.getNode( "ab" ).setCollapse( true );
10181 t14.getNode( "a" ).setCollapse( true );
10182 t14.getNode( "fgh" ).setCollapse( true );
10183 t14.getNode( "gh" ).setCollapse( true );
10184 n = t14.getNode( "ab" );
10185 while ( n != null ) {
10187 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10189 if ( ext.size() != 5 ) {
10192 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10195 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10198 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10201 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10204 if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
10209 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" );
10210 final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
10212 t15.getNode( "ab" ).setCollapse( true );
10213 t15.getNode( "a" ).setCollapse( true );
10214 t15.getNode( "fgh" ).setCollapse( true );
10215 t15.getNode( "gh" ).setCollapse( true );
10216 n = t15.getNode( "ab" );
10217 while ( n != null ) {
10219 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10221 if ( ext.size() != 6 ) {
10224 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10227 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10230 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10233 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10236 if ( !ext.get( 4 ).getName().equals( "x" ) ) {
10239 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10244 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" );
10245 final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
10247 t16.getNode( "ab" ).setCollapse( true );
10248 t16.getNode( "a" ).setCollapse( true );
10249 t16.getNode( "fgh" ).setCollapse( true );
10250 t16.getNode( "gh" ).setCollapse( true );
10251 t16.getNode( "cd" ).setCollapse( true );
10252 t16.getNode( "cde" ).setCollapse( true );
10253 t16.getNode( "d" ).setCollapse( true );
10254 t16.getNode( "x" ).setCollapse( true );
10255 n = t16.getNode( "ab" );
10256 while ( n != null ) {
10258 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10260 if ( ext.size() != 4 ) {
10263 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10266 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
10269 if ( !ext.get( 2 ).getName().equals( "x" ) ) {
10272 if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
10276 catch ( final Exception e ) {
10277 e.printStackTrace( System.out );
10283 private static boolean testMsaQualityMethod() {
10285 final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
10286 final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
10287 final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
10288 final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
10289 final List<Sequence> l = new ArrayList<Sequence>();
10294 final Msa msa = BasicMsa.createInstance( l );
10295 if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
10298 if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
10301 if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
10304 if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
10308 catch ( final Exception e ) {
10309 e.printStackTrace( System.out );
10315 private static boolean testSequenceIdParsing() {
10317 Identifier id = SequenceIdParser.parse( "gb_ADF31344_segmented_worms_" );
10318 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10319 || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
10320 if ( id != null ) {
10321 System.out.println( "value =" + id.getValue() );
10322 System.out.println( "provider=" + id.getProvider() );
10327 id = SequenceIdParser.parse( "segmented worms|gb_ADF31344" );
10328 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10329 || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
10330 if ( id != null ) {
10331 System.out.println( "value =" + id.getValue() );
10332 System.out.println( "provider=" + id.getProvider() );
10337 id = SequenceIdParser.parse( "segmented worms gb_ADF31344 and more" );
10338 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10339 || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
10340 if ( id != null ) {
10341 System.out.println( "value =" + id.getValue() );
10342 System.out.println( "provider=" + id.getProvider() );
10347 id = SequenceIdParser.parse( "gb_AAA96518_1" );
10348 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10349 || !id.getValue().equals( "AAA96518" ) || !id.getProvider().equals( "ncbi" ) ) {
10350 if ( id != null ) {
10351 System.out.println( "value =" + id.getValue() );
10352 System.out.println( "provider=" + id.getProvider() );
10357 id = SequenceIdParser.parse( "gb_EHB07727_1_rodents_" );
10358 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10359 || !id.getValue().equals( "EHB07727" ) || !id.getProvider().equals( "ncbi" ) ) {
10360 if ( id != null ) {
10361 System.out.println( "value =" + id.getValue() );
10362 System.out.println( "provider=" + id.getProvider() );
10367 id = SequenceIdParser.parse( "dbj_BAF37827_1_turtles_" );
10368 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10369 || !id.getValue().equals( "BAF37827" ) || !id.getProvider().equals( "ncbi" ) ) {
10370 if ( id != null ) {
10371 System.out.println( "value =" + id.getValue() );
10372 System.out.println( "provider=" + id.getProvider() );
10377 id = SequenceIdParser.parse( "emb_CAA73223_1_primates_" );
10378 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10379 || !id.getValue().equals( "CAA73223" ) || !id.getProvider().equals( "ncbi" ) ) {
10380 if ( id != null ) {
10381 System.out.println( "value =" + id.getValue() );
10382 System.out.println( "provider=" + id.getProvider() );
10387 id = SequenceIdParser.parse( "mites|ref_XP_002434188_1" );
10388 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10389 || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
10390 if ( id != null ) {
10391 System.out.println( "value =" + id.getValue() );
10392 System.out.println( "provider=" + id.getProvider() );
10397 id = SequenceIdParser.parse( "mites_ref_XP_002434188_1_bla_XP_12345" );
10398 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10399 || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
10400 if ( id != null ) {
10401 System.out.println( "value =" + id.getValue() );
10402 System.out.println( "provider=" + id.getProvider() );
10407 id = SequenceIdParser.parse( "P4A123" );
10408 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10409 || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
10410 if ( id != null ) {
10411 System.out.println( "value =" + id.getValue() );
10412 System.out.println( "provider=" + id.getProvider() );
10417 id = SequenceIdParser.parse( "pllf[pok P4A123_osdjfosnqo035-9233332904i000490 vf tmv x45" );
10418 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10419 || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
10420 if ( id != null ) {
10421 System.out.println( "value =" + id.getValue() );
10422 System.out.println( "provider=" + id.getProvider() );
10427 id = SequenceIdParser.parse( "XP_12345" );
10428 if ( id != null ) {
10429 System.out.println( "value =" + id.getValue() );
10430 System.out.println( "provider=" + id.getProvider() );
10433 // lcl_91970_unknown_
10435 catch ( final Exception e ) {
10436 e.printStackTrace( System.out );