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( "AAA34956" );
1045 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
1048 n.setName( "Q06891.1" );
1049 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "Q06891" ) ) {
1053 catch ( final Exception e ) {
1054 e.printStackTrace( System.out );
1060 private static boolean testExtractTaxonomyCodeFromNodeName() {
1062 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1063 .equals( "MOUSE" ) ) {
1066 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1067 .equals( "RAT" ) ) {
1070 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1073 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
1074 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1075 .equals( "MOUSE" ) ) {
1078 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE_function = 23445",
1079 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1080 .equals( "MOUSE" ) ) {
1083 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
1084 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1085 .equals( "MOUSE" ) ) {
1088 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
1089 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1092 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
1093 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1096 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
1097 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1100 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT_function = 23445",
1101 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1104 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
1105 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1108 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
1109 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1112 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
1113 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1116 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1117 .equals( "RAT" ) ) {
1120 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
1121 .equals( "PIG" ) ) {
1125 .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1126 .equals( "MOUSE" ) ) {
1129 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
1130 .equals( "MOUSE" ) ) {
1133 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE_", TAXONOMY_EXTRACTION.AGRESSIVE )
1134 .equals( "MOUSE" ) ) {
1137 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE_", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1138 .equals( "MOUSE" ) ) {
1141 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE_", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ) != null ) {
1144 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "x_MOUSE_x", TAXONOMY_EXTRACTION.AGRESSIVE )
1145 .equals( "MOUSE" ) ) {
1149 catch ( final Exception e ) {
1150 e.printStackTrace( System.out );
1156 private static boolean testBasicNodeMethods() {
1158 if ( PhylogenyNode.getNodeCount() != 0 ) {
1161 final PhylogenyNode n1 = new PhylogenyNode();
1162 final PhylogenyNode n2 = PhylogenyNode
1163 .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1164 final PhylogenyNode n3 = PhylogenyNode
1165 .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1166 final PhylogenyNode n4 = PhylogenyNode
1167 .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1168 if ( n1.isHasAssignedEvent() ) {
1171 if ( PhylogenyNode.getNodeCount() != 4 ) {
1174 if ( n3.getIndicator() != 0 ) {
1177 if ( n3.getNumberOfExternalNodes() != 1 ) {
1180 if ( !n3.isExternal() ) {
1183 if ( !n3.isRoot() ) {
1186 if ( !n4.getName().equals( "n4" ) ) {
1190 catch ( final Exception e ) {
1191 e.printStackTrace( System.out );
1197 private static boolean testBasicPhyloXMLparsing() {
1199 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1200 final PhyloXmlParser xml_parser = new PhyloXmlParser();
1201 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1203 if ( xml_parser.getErrorCount() > 0 ) {
1204 System.out.println( xml_parser.getErrorMessages().toString() );
1207 if ( phylogenies_0.length != 4 ) {
1210 final Phylogeny t1 = phylogenies_0[ 0 ];
1211 final Phylogeny t2 = phylogenies_0[ 1 ];
1212 final Phylogeny t3 = phylogenies_0[ 2 ];
1213 final Phylogeny t4 = phylogenies_0[ 3 ];
1214 if ( t1.getNumberOfExternalNodes() != 1 ) {
1217 if ( !t1.isRooted() ) {
1220 if ( t1.isRerootable() ) {
1223 if ( !t1.getType().equals( "gene_tree" ) ) {
1226 if ( t2.getNumberOfExternalNodes() != 2 ) {
1229 if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1232 if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1235 if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1238 if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1241 if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1244 if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1247 if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1248 .startsWith( "actgtgggggt" ) ) {
1251 if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1252 .startsWith( "ctgtgatgcat" ) ) {
1255 if ( t3.getNumberOfExternalNodes() != 4 ) {
1258 if ( !t1.getName().equals( "t1" ) ) {
1261 if ( !t2.getName().equals( "t2" ) ) {
1264 if ( !t3.getName().equals( "t3" ) ) {
1267 if ( !t4.getName().equals( "t4" ) ) {
1270 if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1273 if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1276 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1279 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1280 .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1283 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1286 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1289 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1292 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1293 .equals( "apoptosis" ) ) {
1296 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1297 .equals( "GO:0006915" ) ) {
1300 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1301 .equals( "UniProtKB" ) ) {
1304 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1305 .equals( "experimental" ) ) {
1308 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1309 .equals( "function" ) ) {
1312 if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1313 .getValue() != 1 ) {
1316 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1317 .getType().equals( "ml" ) ) {
1320 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1321 .equals( "apoptosis" ) ) {
1324 if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1325 .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1328 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1329 .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1332 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1333 .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1336 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1337 .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1340 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1341 .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1344 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1345 .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1348 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1349 .equals( "GO:0005829" ) ) {
1352 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1353 .equals( "intracellular organelle" ) ) {
1356 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1359 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1360 .equals( "UniProt link" ) ) ) {
1363 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1367 catch ( final Exception e ) {
1368 e.printStackTrace( System.out );
1374 private static boolean testBasicPhyloXMLparsingRoundtrip() {
1376 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1377 final PhyloXmlParser xml_parser = new PhyloXmlParser();
1378 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1379 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1382 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1384 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1386 if ( xml_parser.getErrorCount() > 0 ) {
1387 System.out.println( xml_parser.getErrorMessages().toString() );
1390 if ( phylogenies_0.length != 4 ) {
1393 final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1394 final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1395 if ( phylogenies_t1.length != 1 ) {
1398 final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1399 if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1402 if ( !t1_rt.isRooted() ) {
1405 if ( t1_rt.isRerootable() ) {
1408 if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1411 final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1412 final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1413 final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1414 if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1417 if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1420 if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1423 if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1426 if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1427 .startsWith( "actgtgggggt" ) ) {
1430 if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1431 .startsWith( "ctgtgatgcat" ) ) {
1434 final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1435 final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1436 final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1437 final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1438 if ( phylogenies_1.length != 1 ) {
1441 final Phylogeny t3_rt = phylogenies_1[ 0 ];
1442 if ( !t3_rt.getName().equals( "t3" ) ) {
1445 if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1448 if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1451 if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1454 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1457 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1458 .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1461 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1464 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1467 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1468 .equals( "UniProtKB" ) ) {
1471 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1472 .equals( "apoptosis" ) ) {
1475 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1476 .equals( "GO:0006915" ) ) {
1479 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1480 .equals( "UniProtKB" ) ) {
1483 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1484 .equals( "experimental" ) ) {
1487 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1488 .equals( "function" ) ) {
1491 if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1492 .getValue() != 1 ) {
1495 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1496 .getType().equals( "ml" ) ) {
1499 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1500 .equals( "apoptosis" ) ) {
1503 if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1504 .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1507 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1508 .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1511 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1512 .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1515 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1516 .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1519 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1520 .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1523 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1524 .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1527 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1528 .equals( "GO:0005829" ) ) {
1531 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1532 .equals( "intracellular organelle" ) ) {
1535 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1538 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1539 .equals( "UniProt link" ) ) ) {
1542 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1545 if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1548 if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1549 .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." ) ) ) {
1552 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1555 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1558 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1561 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1564 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1565 .equals( "ncbi" ) ) {
1568 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1571 if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1572 .getName().equals( "B" ) ) {
1575 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1576 .getFrom() != 21 ) {
1579 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1582 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1583 .getLength() != 24 ) {
1586 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1587 .getConfidence() != 2144 ) {
1590 if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1591 .equals( "pfam" ) ) {
1594 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1597 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1600 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1603 if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1606 final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1607 if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1610 if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1613 if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1616 if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1619 if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1622 if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1625 if ( taxbb.getSynonyms().size() != 2 ) {
1628 if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1631 if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1634 if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1637 if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1640 if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1643 if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1644 .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1648 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1651 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1654 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1657 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1660 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1663 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1666 if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1670 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1673 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1674 .equalsIgnoreCase( "435" ) ) {
1677 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1680 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1681 .equalsIgnoreCase( "443.7" ) ) {
1684 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1687 if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1690 if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1691 .equalsIgnoreCase( "433" ) ) {
1695 catch ( final Exception e ) {
1696 e.printStackTrace( System.out );
1702 private static boolean testBasicPhyloXMLparsingValidating() {
1704 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1705 PhyloXmlParser xml_parser = null;
1707 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1709 catch ( final Exception e ) {
1710 // Do nothing -- means were not running from jar.
1712 if ( xml_parser == null ) {
1713 xml_parser = new PhyloXmlParser();
1714 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1715 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1718 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1721 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1723 if ( xml_parser.getErrorCount() > 0 ) {
1724 System.out.println( xml_parser.getErrorMessages().toString() );
1727 if ( phylogenies_0.length != 4 ) {
1730 final Phylogeny t1 = phylogenies_0[ 0 ];
1731 final Phylogeny t2 = phylogenies_0[ 1 ];
1732 final Phylogeny t3 = phylogenies_0[ 2 ];
1733 final Phylogeny t4 = phylogenies_0[ 3 ];
1734 if ( !t1.getName().equals( "t1" ) ) {
1737 if ( !t2.getName().equals( "t2" ) ) {
1740 if ( !t3.getName().equals( "t3" ) ) {
1743 if ( !t4.getName().equals( "t4" ) ) {
1746 if ( t1.getNumberOfExternalNodes() != 1 ) {
1749 if ( t2.getNumberOfExternalNodes() != 2 ) {
1752 if ( t3.getNumberOfExternalNodes() != 4 ) {
1755 final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
1756 final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
1757 if ( xml_parser.getErrorCount() > 0 ) {
1758 System.out.println( "errors:" );
1759 System.out.println( xml_parser.getErrorMessages().toString() );
1762 if ( phylogenies_1.length != 4 ) {
1765 final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
1767 if ( xml_parser.getErrorCount() > 0 ) {
1768 System.out.println( "errors:" );
1769 System.out.println( xml_parser.getErrorMessages().toString() );
1772 if ( phylogenies_2.length != 1 ) {
1775 if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
1778 final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
1780 if ( xml_parser.getErrorCount() > 0 ) {
1781 System.out.println( xml_parser.getErrorMessages().toString() );
1784 if ( phylogenies_3.length != 2 ) {
1787 final Phylogeny a = phylogenies_3[ 0 ];
1788 if ( !a.getName().equals( "tree 4" ) ) {
1791 if ( a.getNumberOfExternalNodes() != 3 ) {
1794 if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
1797 if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
1800 final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
1802 if ( xml_parser.getErrorCount() > 0 ) {
1803 System.out.println( xml_parser.getErrorMessages().toString() );
1806 if ( phylogenies_4.length != 1 ) {
1809 final Phylogeny s = phylogenies_4[ 0 ];
1810 if ( s.getNumberOfExternalNodes() != 6 ) {
1813 s.getNode( "first" );
1815 s.getNode( "\"<a'b&c'd\">\"" );
1816 s.getNode( "'''\"" );
1817 s.getNode( "\"\"\"" );
1818 s.getNode( "dick & doof" );
1820 catch ( final Exception e ) {
1821 e.printStackTrace( System.out );
1827 private static boolean testBasicTable() {
1829 final BasicTable<String> t0 = new BasicTable<String>();
1830 if ( t0.getNumberOfColumns() != 0 ) {
1833 if ( t0.getNumberOfRows() != 0 ) {
1836 t0.setValue( 3, 2, "23" );
1837 t0.setValue( 10, 1, "error" );
1838 t0.setValue( 10, 1, "110" );
1839 t0.setValue( 9, 1, "19" );
1840 t0.setValue( 1, 10, "101" );
1841 t0.setValue( 10, 10, "1010" );
1842 t0.setValue( 100, 10, "10100" );
1843 t0.setValue( 0, 0, "00" );
1844 if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
1847 if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
1850 if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
1853 if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
1856 if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
1859 if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
1862 if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
1865 if ( t0.getNumberOfColumns() != 101 ) {
1868 if ( t0.getNumberOfRows() != 11 ) {
1871 if ( t0.getValueAsString( 49, 4 ) != null ) {
1874 final String l = ForesterUtil.getLineSeparator();
1875 final StringBuffer source = new StringBuffer();
1876 source.append( "" + l );
1877 source.append( "# 1 1 1 1 1 1 1 1" + l );
1878 source.append( " 00 01 02 03" + l );
1879 source.append( " 10 11 12 13 " + l );
1880 source.append( "20 21 22 23 " + l );
1881 source.append( " 30 31 32 33" + l );
1882 source.append( "40 41 42 43" + l );
1883 source.append( " # 1 1 1 1 1 " + l );
1884 source.append( "50 51 52 53 54" + l );
1885 final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), " " );
1886 if ( t1.getNumberOfColumns() != 5 ) {
1889 if ( t1.getNumberOfRows() != 6 ) {
1892 if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
1895 if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
1898 if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
1901 if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
1904 final StringBuffer source1 = new StringBuffer();
1905 source1.append( "" + l );
1906 source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
1907 source1.append( " 00; 01 ;02;03" + l );
1908 source1.append( " 10; 11; 12; 13 " + l );
1909 source1.append( "20; 21; 22; 23 " + l );
1910 source1.append( " 30; 31; 32; 33" + l );
1911 source1.append( "40;41;42;43" + l );
1912 source1.append( " # 1 1 1 1 1 " + l );
1913 source1.append( ";;;50 ; ;52; 53;;54 " + l );
1914 final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ";" );
1915 if ( t2.getNumberOfColumns() != 5 ) {
1918 if ( t2.getNumberOfRows() != 6 ) {
1921 if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
1924 if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
1927 if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
1930 if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
1933 if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
1936 if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
1939 final StringBuffer source2 = new StringBuffer();
1940 source2.append( "" + l );
1941 source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
1942 source2.append( " 00; 01 ;02;03" + l );
1943 source2.append( " 10; 11; 12; 13 " + l );
1944 source2.append( "20; 21; 22; 23 " + l );
1945 source2.append( " " + l );
1946 source2.append( " 30; 31; 32; 33" + l );
1947 source2.append( "40;41;42;43" + l );
1948 source2.append( " comment: 1 1 1 1 1 " + l );
1949 source2.append( ";;;50 ; 52; 53;;54 " + l );
1950 final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
1956 if ( tl.size() != 2 ) {
1959 final BasicTable<String> t3 = tl.get( 0 );
1960 final BasicTable<String> t4 = tl.get( 1 );
1961 if ( t3.getNumberOfColumns() != 4 ) {
1964 if ( t3.getNumberOfRows() != 3 ) {
1967 if ( t4.getNumberOfColumns() != 4 ) {
1970 if ( t4.getNumberOfRows() != 3 ) {
1973 if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
1976 if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
1980 catch ( final Exception e ) {
1981 e.printStackTrace( System.out );
1987 private static boolean testBasicTolXMLparsing() {
1989 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1990 final TolParser parser = new TolParser();
1991 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
1992 if ( parser.getErrorCount() > 0 ) {
1993 System.out.println( parser.getErrorMessages().toString() );
1996 if ( phylogenies_0.length != 1 ) {
1999 final Phylogeny t1 = phylogenies_0[ 0 ];
2000 if ( t1.getNumberOfExternalNodes() != 5 ) {
2003 if ( !t1.isRooted() ) {
2006 if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2009 if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2012 if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2015 if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2018 final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2019 if ( parser.getErrorCount() > 0 ) {
2020 System.out.println( parser.getErrorMessages().toString() );
2023 if ( phylogenies_1.length != 1 ) {
2026 final Phylogeny t2 = phylogenies_1[ 0 ];
2027 if ( t2.getNumberOfExternalNodes() != 664 ) {
2030 if ( !t2.isRooted() ) {
2033 if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2036 if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2039 if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2042 if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2045 if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2048 if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2049 .equals( "Aquifex" ) ) {
2052 final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2053 if ( parser.getErrorCount() > 0 ) {
2054 System.out.println( parser.getErrorMessages().toString() );
2057 if ( phylogenies_2.length != 1 ) {
2060 final Phylogeny t3 = phylogenies_2[ 0 ];
2061 if ( t3.getNumberOfExternalNodes() != 184 ) {
2064 if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2067 if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2070 if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2073 final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2074 if ( parser.getErrorCount() > 0 ) {
2075 System.out.println( parser.getErrorMessages().toString() );
2078 if ( phylogenies_3.length != 1 ) {
2081 final Phylogeny t4 = phylogenies_3[ 0 ];
2082 if ( t4.getNumberOfExternalNodes() != 1 ) {
2085 if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2088 if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2091 if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2094 final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2095 if ( parser.getErrorCount() > 0 ) {
2096 System.out.println( parser.getErrorMessages().toString() );
2099 if ( phylogenies_4.length != 1 ) {
2102 final Phylogeny t5 = phylogenies_4[ 0 ];
2103 if ( t5.getNumberOfExternalNodes() != 13 ) {
2106 if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2109 if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2112 if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2116 catch ( final Exception e ) {
2117 e.printStackTrace( System.out );
2123 private static boolean testBasicTreeMethods() {
2125 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2126 final Phylogeny t1 = factory.create();
2127 if ( !t1.isEmpty() ) {
2130 final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2131 if ( t2.getNumberOfExternalNodes() != 4 ) {
2134 if ( t2.getHeight() != 8.5 ) {
2137 if ( !t2.isCompletelyBinary() ) {
2140 if ( t2.isEmpty() ) {
2143 final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2144 if ( t3.getNumberOfExternalNodes() != 5 ) {
2147 if ( t3.getHeight() != 11 ) {
2150 if ( t3.isCompletelyBinary() ) {
2153 final PhylogenyNode n = t3.getNode( "ABC" );
2154 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 ];
2155 if ( t4.getNumberOfExternalNodes() != 9 ) {
2158 if ( t4.getHeight() != 11 ) {
2161 if ( t4.isCompletelyBinary() ) {
2164 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)" );
2165 final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2166 if ( t5.getNumberOfExternalNodes() != 8 ) {
2169 if ( t5.getHeight() != 15 ) {
2172 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)" );
2173 final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2174 if ( t6.getHeight() != 15 ) {
2177 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)" );
2178 final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2179 if ( t7.getHeight() != 15 ) {
2182 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)" );
2183 final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2184 if ( t8.getNumberOfExternalNodes() != 10 ) {
2187 if ( t8.getHeight() != 15 ) {
2190 final char[] a9 = new char[] { 'a' };
2191 final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2192 if ( t9.getHeight() != 0 ) {
2195 final char[] a10 = new char[] { 'a', ':', '6' };
2196 final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2197 if ( t10.getHeight() != 6 ) {
2201 catch ( final Exception e ) {
2202 e.printStackTrace( System.out );
2208 private static boolean testTreeMethods() {
2210 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2211 final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
2212 PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
2213 if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
2214 System.out.println( t0.toNewHampshireX() );
2217 final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
2218 PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
2219 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
2222 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
2225 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
2229 catch ( final Exception e ) {
2230 e.printStackTrace( System.out );
2236 private static boolean testConfidenceAssessor() {
2238 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2239 final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2240 final Phylogeny[] ev0 = factory
2241 .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2243 ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2244 if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2247 if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2250 final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2251 final Phylogeny[] ev1 = factory
2252 .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)));",
2254 ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2255 if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2258 if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2261 final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2262 final Phylogeny[] ev_b = factory
2263 .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",
2265 ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2266 if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2269 if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2273 final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2274 final Phylogeny[] ev1x = factory
2275 .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)));",
2277 ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2278 if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2281 if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2284 final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2285 final Phylogeny[] ev_bx = factory
2286 .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",
2288 ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2289 if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2292 if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2296 final Phylogeny[] t2 = factory
2297 .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);",
2299 final Phylogeny[] ev2 = factory
2300 .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);",
2302 for( final Phylogeny target : t2 ) {
2303 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2306 final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2307 new NHXParser() )[ 0 ];
2308 final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2309 ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2310 if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2313 if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2316 if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2320 catch ( final Exception e ) {
2321 e.printStackTrace();
2327 private static boolean testCopyOfNodeData() {
2329 final PhylogenyNode n1 = PhylogenyNode
2330 .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]" );
2331 final PhylogenyNode n2 = n1.copyNodeData();
2332 if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2336 catch ( final Exception e ) {
2337 e.printStackTrace();
2343 private static boolean testDataObjects() {
2345 final Confidence s0 = new Confidence();
2346 final Confidence s1 = new Confidence();
2347 if ( !s0.isEqual( s1 ) ) {
2350 final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2351 final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2352 if ( s2.isEqual( s1 ) ) {
2355 if ( !s2.isEqual( s3 ) ) {
2358 final Confidence s4 = ( Confidence ) s3.copy();
2359 if ( !s4.isEqual( s3 ) ) {
2366 final Taxonomy t1 = new Taxonomy();
2367 final Taxonomy t2 = new Taxonomy();
2368 final Taxonomy t3 = new Taxonomy();
2369 final Taxonomy t4 = new Taxonomy();
2370 final Taxonomy t5 = new Taxonomy();
2371 t1.setIdentifier( new Identifier( "ecoli" ) );
2372 t1.setTaxonomyCode( "ECOLI" );
2373 t1.setScientificName( "E. coli" );
2374 t1.setCommonName( "coli" );
2375 final Taxonomy t0 = ( Taxonomy ) t1.copy();
2376 if ( !t1.isEqual( t0 ) ) {
2379 t2.setIdentifier( new Identifier( "ecoli" ) );
2380 t2.setTaxonomyCode( "OTHER" );
2381 t2.setScientificName( "what" );
2382 t2.setCommonName( "something" );
2383 if ( !t1.isEqual( t2 ) ) {
2386 t2.setIdentifier( new Identifier( "nemve" ) );
2387 if ( t1.isEqual( t2 ) ) {
2390 t1.setIdentifier( null );
2391 t3.setTaxonomyCode( "ECOLI" );
2392 t3.setScientificName( "what" );
2393 t3.setCommonName( "something" );
2394 if ( !t1.isEqual( t3 ) ) {
2397 t1.setIdentifier( null );
2398 t1.setTaxonomyCode( "" );
2399 t4.setScientificName( "E. ColI" );
2400 t4.setCommonName( "something" );
2401 if ( !t1.isEqual( t4 ) ) {
2404 t4.setScientificName( "B. subtilis" );
2405 t4.setCommonName( "something" );
2406 if ( t1.isEqual( t4 ) ) {
2409 t1.setIdentifier( null );
2410 t1.setTaxonomyCode( "" );
2411 t1.setScientificName( "" );
2412 t5.setCommonName( "COLI" );
2413 if ( !t1.isEqual( t5 ) ) {
2416 t5.setCommonName( "vibrio" );
2417 if ( t1.isEqual( t5 ) ) {
2422 final Identifier id0 = new Identifier( "123", "pfam" );
2423 final Identifier id1 = ( Identifier ) id0.copy();
2424 if ( !id1.isEqual( id1 ) ) {
2427 if ( !id1.isEqual( id0 ) ) {
2430 if ( !id0.isEqual( id1 ) ) {
2437 final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
2438 final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
2439 if ( !pd1.isEqual( pd1 ) ) {
2442 if ( !pd1.isEqual( pd0 ) ) {
2447 final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
2448 final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
2449 if ( !pd3.isEqual( pd3 ) ) {
2452 if ( !pd2.isEqual( pd3 ) ) {
2455 if ( !pd0.isEqual( pd3 ) ) {
2460 // DomainArchitecture
2461 // ------------------
2462 final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
2463 final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
2464 final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
2465 final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
2466 final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
2467 final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
2472 final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
2473 if ( ds0.getNumberOfDomains() != 4 ) {
2476 final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
2477 if ( !ds0.isEqual( ds0 ) ) {
2480 if ( !ds0.isEqual( ds1 ) ) {
2483 if ( ds1.getNumberOfDomains() != 4 ) {
2486 final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
2491 final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
2492 if ( ds0.isEqual( ds2 ) ) {
2498 final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
2499 if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
2500 System.out.println( ds3.toNHX() );
2503 if ( ds3.getNumberOfDomains() != 3 ) {
2508 final Event e1 = new Event( Event.EventType.fusion );
2509 if ( e1.isDuplication() ) {
2512 if ( !e1.isFusion() ) {
2515 if ( !e1.asText().toString().equals( "fusion" ) ) {
2518 if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
2521 final Event e11 = new Event( Event.EventType.fusion );
2522 if ( !e11.isEqual( e1 ) ) {
2525 if ( !e11.toNHX().toString().equals( "" ) ) {
2528 final Event e2 = new Event( Event.EventType.speciation_or_duplication );
2529 if ( e2.isDuplication() ) {
2532 if ( !e2.isSpeciationOrDuplication() ) {
2535 if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
2538 if ( !e2.asSimpleText().toString().equals( "?" ) ) {
2541 if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
2544 if ( e11.isEqual( e2 ) ) {
2547 final Event e2c = ( Event ) e2.copy();
2548 if ( !e2c.isEqual( e2 ) ) {
2551 Event e3 = new Event( 1, 2, 3 );
2552 if ( e3.isDuplication() ) {
2555 if ( e3.isSpeciation() ) {
2558 if ( e3.isGeneLoss() ) {
2561 if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2564 final Event e3c = ( Event ) e3.copy();
2565 final Event e3cc = ( Event ) e3c.copy();
2566 if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
2570 if ( !e3c.isEqual( e3cc ) ) {
2573 Event e4 = new Event( 1, 2, 3 );
2574 if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2577 if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
2580 final Event e4c = ( Event ) e4.copy();
2582 final Event e4cc = ( Event ) e4c.copy();
2583 if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2586 if ( !e4c.isEqual( e4cc ) ) {
2589 final Event e5 = new Event();
2590 if ( !e5.isUnassigned() ) {
2593 if ( !e5.asText().toString().equals( "unassigned" ) ) {
2596 if ( !e5.asSimpleText().toString().equals( "" ) ) {
2599 final Event e6 = new Event( 1, 0, 0 );
2600 if ( !e6.asText().toString().equals( "duplication" ) ) {
2603 if ( !e6.asSimpleText().toString().equals( "D" ) ) {
2606 final Event e7 = new Event( 0, 1, 0 );
2607 if ( !e7.asText().toString().equals( "speciation" ) ) {
2610 if ( !e7.asSimpleText().toString().equals( "S" ) ) {
2613 final Event e8 = new Event( 0, 0, 1 );
2614 if ( !e8.asText().toString().equals( "gene-loss" ) ) {
2617 if ( !e8.asSimpleText().toString().equals( "L" ) ) {
2621 catch ( final Exception e ) {
2622 e.printStackTrace( System.out );
2628 private static boolean testDeletionOfExternalNodes() {
2630 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2631 final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
2632 final PhylogenyWriter w = new PhylogenyWriter();
2633 if ( t0.isEmpty() ) {
2636 if ( t0.getNumberOfExternalNodes() != 1 ) {
2639 t0.deleteSubtree( t0.getNode( "A" ), false );
2640 if ( t0.getNumberOfExternalNodes() != 0 ) {
2643 if ( !t0.isEmpty() ) {
2646 final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
2647 if ( t1.getNumberOfExternalNodes() != 2 ) {
2650 t1.deleteSubtree( t1.getNode( "A" ), false );
2651 if ( t1.getNumberOfExternalNodes() != 1 ) {
2654 if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
2657 t1.deleteSubtree( t1.getNode( "B" ), false );
2658 if ( t1.getNumberOfExternalNodes() != 1 ) {
2661 t1.deleteSubtree( t1.getNode( "r" ), false );
2662 if ( !t1.isEmpty() ) {
2665 final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
2666 if ( t2.getNumberOfExternalNodes() != 3 ) {
2669 t2.deleteSubtree( t2.getNode( "B" ), false );
2670 if ( t2.getNumberOfExternalNodes() != 2 ) {
2673 t2.toNewHampshireX();
2674 PhylogenyNode n = t2.getNode( "A" );
2675 if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2678 t2.deleteSubtree( t2.getNode( "A" ), false );
2679 if ( t2.getNumberOfExternalNodes() != 2 ) {
2682 t2.deleteSubtree( t2.getNode( "C" ), true );
2683 if ( t2.getNumberOfExternalNodes() != 1 ) {
2686 final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2687 if ( t3.getNumberOfExternalNodes() != 4 ) {
2690 t3.deleteSubtree( t3.getNode( "B" ), true );
2691 if ( t3.getNumberOfExternalNodes() != 3 ) {
2694 n = t3.getNode( "A" );
2695 if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2698 n = n.getNextExternalNode();
2699 if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2702 t3.deleteSubtree( t3.getNode( "A" ), true );
2703 if ( t3.getNumberOfExternalNodes() != 2 ) {
2706 n = t3.getNode( "C" );
2707 if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2710 t3.deleteSubtree( t3.getNode( "C" ), true );
2711 if ( t3.getNumberOfExternalNodes() != 1 ) {
2714 t3.deleteSubtree( t3.getNode( "D" ), true );
2715 if ( t3.getNumberOfExternalNodes() != 0 ) {
2718 final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2719 if ( t4.getNumberOfExternalNodes() != 6 ) {
2722 t4.deleteSubtree( t4.getNode( "B2" ), true );
2723 if ( t4.getNumberOfExternalNodes() != 5 ) {
2726 String s = w.toNewHampshire( t4, false, true ).toString();
2727 if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2730 t4.deleteSubtree( t4.getNode( "B11" ), true );
2731 if ( t4.getNumberOfExternalNodes() != 4 ) {
2734 t4.deleteSubtree( t4.getNode( "C" ), true );
2735 if ( t4.getNumberOfExternalNodes() != 3 ) {
2738 n = t4.getNode( "A" );
2739 n = n.getNextExternalNode();
2740 if ( !n.getName().equals( "B12" ) ) {
2743 n = n.getNextExternalNode();
2744 if ( !n.getName().equals( "D" ) ) {
2747 s = w.toNewHampshire( t4, false, true ).toString();
2748 if ( !s.equals( "((A,B12),D);" ) ) {
2751 final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2752 t5.deleteSubtree( t5.getNode( "A" ), true );
2753 if ( t5.getNumberOfExternalNodes() != 5 ) {
2756 s = w.toNewHampshire( t5, false, true ).toString();
2757 if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
2760 final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2761 t6.deleteSubtree( t6.getNode( "B11" ), true );
2762 if ( t6.getNumberOfExternalNodes() != 5 ) {
2765 s = w.toNewHampshire( t6, false, false ).toString();
2766 if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
2769 final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2770 t7.deleteSubtree( t7.getNode( "B12" ), true );
2771 if ( t7.getNumberOfExternalNodes() != 5 ) {
2774 s = w.toNewHampshire( t7, false, true ).toString();
2775 if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
2778 final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2779 t8.deleteSubtree( t8.getNode( "B2" ), true );
2780 if ( t8.getNumberOfExternalNodes() != 5 ) {
2783 s = w.toNewHampshire( t8, false, false ).toString();
2784 if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2787 final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2788 t9.deleteSubtree( t9.getNode( "C" ), true );
2789 if ( t9.getNumberOfExternalNodes() != 5 ) {
2792 s = w.toNewHampshire( t9, false, true ).toString();
2793 if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
2796 final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2797 t10.deleteSubtree( t10.getNode( "D" ), true );
2798 if ( t10.getNumberOfExternalNodes() != 5 ) {
2801 s = w.toNewHampshire( t10, false, true ).toString();
2802 if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
2805 final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
2806 t11.deleteSubtree( t11.getNode( "A" ), true );
2807 if ( t11.getNumberOfExternalNodes() != 2 ) {
2810 s = w.toNewHampshire( t11, false, true ).toString();
2811 if ( !s.equals( "(B,C);" ) ) {
2814 t11.deleteSubtree( t11.getNode( "C" ), true );
2815 if ( t11.getNumberOfExternalNodes() != 1 ) {
2818 s = w.toNewHampshire( t11, false, false ).toString();
2819 if ( !s.equals( "B;" ) ) {
2822 final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
2823 t12.deleteSubtree( t12.getNode( "B2" ), true );
2824 if ( t12.getNumberOfExternalNodes() != 8 ) {
2827 s = w.toNewHampshire( t12, false, true ).toString();
2828 if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
2831 t12.deleteSubtree( t12.getNode( "B3" ), true );
2832 if ( t12.getNumberOfExternalNodes() != 7 ) {
2835 s = w.toNewHampshire( t12, false, true ).toString();
2836 if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
2839 t12.deleteSubtree( t12.getNode( "C3" ), true );
2840 if ( t12.getNumberOfExternalNodes() != 6 ) {
2843 s = w.toNewHampshire( t12, false, true ).toString();
2844 if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
2847 t12.deleteSubtree( t12.getNode( "A1" ), true );
2848 if ( t12.getNumberOfExternalNodes() != 5 ) {
2851 s = w.toNewHampshire( t12, false, true ).toString();
2852 if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
2855 t12.deleteSubtree( t12.getNode( "B1" ), true );
2856 if ( t12.getNumberOfExternalNodes() != 4 ) {
2859 s = w.toNewHampshire( t12, false, true ).toString();
2860 if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
2863 t12.deleteSubtree( t12.getNode( "A3" ), true );
2864 if ( t12.getNumberOfExternalNodes() != 3 ) {
2867 s = w.toNewHampshire( t12, false, true ).toString();
2868 if ( !s.equals( "(A2,(C1,C2));" ) ) {
2871 t12.deleteSubtree( t12.getNode( "A2" ), true );
2872 if ( t12.getNumberOfExternalNodes() != 2 ) {
2875 s = w.toNewHampshire( t12, false, true ).toString();
2876 if ( !s.equals( "(C1,C2);" ) ) {
2879 final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
2880 t13.deleteSubtree( t13.getNode( "D" ), true );
2881 if ( t13.getNumberOfExternalNodes() != 4 ) {
2884 s = w.toNewHampshire( t13, false, true ).toString();
2885 if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
2888 final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
2889 t14.deleteSubtree( t14.getNode( "E" ), true );
2890 if ( t14.getNumberOfExternalNodes() != 5 ) {
2893 s = w.toNewHampshire( t14, false, true ).toString();
2894 if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
2897 final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
2898 t15.deleteSubtree( t15.getNode( "B2" ), true );
2899 if ( t15.getNumberOfExternalNodes() != 11 ) {
2902 t15.deleteSubtree( t15.getNode( "B1" ), true );
2903 if ( t15.getNumberOfExternalNodes() != 10 ) {
2906 t15.deleteSubtree( t15.getNode( "B3" ), true );
2907 if ( t15.getNumberOfExternalNodes() != 9 ) {
2910 t15.deleteSubtree( t15.getNode( "B4" ), true );
2911 if ( t15.getNumberOfExternalNodes() != 8 ) {
2914 t15.deleteSubtree( t15.getNode( "A1" ), true );
2915 if ( t15.getNumberOfExternalNodes() != 7 ) {
2918 t15.deleteSubtree( t15.getNode( "C4" ), true );
2919 if ( t15.getNumberOfExternalNodes() != 6 ) {
2923 catch ( final Exception e ) {
2924 e.printStackTrace( System.out );
2930 private static boolean testDescriptiveStatistics() {
2932 final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
2933 dss1.addValue( 82 );
2934 dss1.addValue( 78 );
2935 dss1.addValue( 70 );
2936 dss1.addValue( 58 );
2937 dss1.addValue( 42 );
2938 if ( dss1.getN() != 5 ) {
2941 if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
2944 if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
2947 if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
2950 if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
2953 if ( !Test.isEqual( dss1.median(), 70 ) ) {
2956 if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
2959 if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
2962 if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
2965 if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
2968 if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
2971 if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
2974 dss1.addValue( 123 );
2975 if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
2978 if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
2981 if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
2984 final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
2985 dss2.addValue( -1.85 );
2986 dss2.addValue( 57.5 );
2987 dss2.addValue( 92.78 );
2988 dss2.addValue( 57.78 );
2989 if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
2992 if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
2995 final double[] a = dss2.getDataAsDoubleArray();
2996 if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
2999 dss2.addValue( -100 );
3000 if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3003 if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3006 final double[] ds = new double[ 14 ];
3021 final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3022 if ( bins.length != 4 ) {
3025 if ( bins[ 0 ] != 2 ) {
3028 if ( bins[ 1 ] != 3 ) {
3031 if ( bins[ 2 ] != 4 ) {
3034 if ( bins[ 3 ] != 5 ) {
3037 final double[] ds1 = new double[ 9 ];
3047 final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3048 if ( bins1.length != 4 ) {
3051 if ( bins1[ 0 ] != 2 ) {
3054 if ( bins1[ 1 ] != 3 ) {
3057 if ( bins1[ 2 ] != 0 ) {
3060 if ( bins1[ 3 ] != 4 ) {
3063 final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3064 if ( bins1_1.length != 3 ) {
3067 if ( bins1_1[ 0 ] != 3 ) {
3070 if ( bins1_1[ 1 ] != 2 ) {
3073 if ( bins1_1[ 2 ] != 4 ) {
3076 final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3077 if ( bins1_2.length != 3 ) {
3080 if ( bins1_2[ 0 ] != 2 ) {
3083 if ( bins1_2[ 1 ] != 2 ) {
3086 if ( bins1_2[ 2 ] != 2 ) {
3089 final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3103 dss3.addValue( 10 );
3104 dss3.addValue( 10 );
3105 dss3.addValue( 10 );
3106 final AsciiHistogram histo = new AsciiHistogram( dss3 );
3107 histo.toStringBuffer( 10, '=', 40, 5 );
3108 histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3110 catch ( final Exception e ) {
3111 e.printStackTrace( System.out );
3117 private static boolean testDir( final String file ) {
3119 final File f = new File( file );
3120 if ( !f.exists() ) {
3123 if ( !f.isDirectory() ) {
3126 if ( !f.canRead() ) {
3130 catch ( final Exception e ) {
3136 private static boolean testExternalNodeRelatedMethods() {
3138 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3139 final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3140 PhylogenyNode n = t1.getNode( "A" );
3141 n = n.getNextExternalNode();
3142 if ( !n.getName().equals( "B" ) ) {
3145 n = n.getNextExternalNode();
3146 if ( !n.getName().equals( "C" ) ) {
3149 n = n.getNextExternalNode();
3150 if ( !n.getName().equals( "D" ) ) {
3153 n = t1.getNode( "B" );
3154 while ( !n.isLastExternalNode() ) {
3155 n = n.getNextExternalNode();
3157 final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
3158 n = t2.getNode( "A" );
3159 n = n.getNextExternalNode();
3160 if ( !n.getName().equals( "B" ) ) {
3163 n = n.getNextExternalNode();
3164 if ( !n.getName().equals( "C" ) ) {
3167 n = n.getNextExternalNode();
3168 if ( !n.getName().equals( "D" ) ) {
3171 n = t2.getNode( "B" );
3172 while ( !n.isLastExternalNode() ) {
3173 n = n.getNextExternalNode();
3175 final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3176 n = t3.getNode( "A" );
3177 n = n.getNextExternalNode();
3178 if ( !n.getName().equals( "B" ) ) {
3181 n = n.getNextExternalNode();
3182 if ( !n.getName().equals( "C" ) ) {
3185 n = n.getNextExternalNode();
3186 if ( !n.getName().equals( "D" ) ) {
3189 n = n.getNextExternalNode();
3190 if ( !n.getName().equals( "E" ) ) {
3193 n = n.getNextExternalNode();
3194 if ( !n.getName().equals( "F" ) ) {
3197 n = n.getNextExternalNode();
3198 if ( !n.getName().equals( "G" ) ) {
3201 n = n.getNextExternalNode();
3202 if ( !n.getName().equals( "H" ) ) {
3205 n = t3.getNode( "B" );
3206 while ( !n.isLastExternalNode() ) {
3207 n = n.getNextExternalNode();
3209 final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3210 for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
3211 final PhylogenyNode node = iter.next();
3213 final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3214 for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
3215 final PhylogenyNode node = iter.next();
3217 final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
3218 final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
3219 if ( !iter.next().getName().equals( "A" ) ) {
3222 if ( !iter.next().getName().equals( "B" ) ) {
3225 if ( !iter.next().getName().equals( "C" ) ) {
3228 if ( !iter.next().getName().equals( "D" ) ) {
3231 if ( !iter.next().getName().equals( "E" ) ) {
3234 if ( !iter.next().getName().equals( "F" ) ) {
3237 if ( iter.hasNext() ) {
3241 catch ( final Exception e ) {
3242 e.printStackTrace( System.out );
3248 private static boolean testGeneralTable() {
3250 final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
3251 t0.setValue( 3, 2, "23" );
3252 t0.setValue( 10, 1, "error" );
3253 t0.setValue( 10, 1, "110" );
3254 t0.setValue( 9, 1, "19" );
3255 t0.setValue( 1, 10, "101" );
3256 t0.setValue( 10, 10, "1010" );
3257 t0.setValue( 100, 10, "10100" );
3258 t0.setValue( 0, 0, "00" );
3259 if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
3262 if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
3265 if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
3268 if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
3271 if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
3274 if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
3277 if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
3280 if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
3283 if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
3286 final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
3287 t1.setValue( "3", "2", "23" );
3288 t1.setValue( "10", "1", "error" );
3289 t1.setValue( "10", "1", "110" );
3290 t1.setValue( "9", "1", "19" );
3291 t1.setValue( "1", "10", "101" );
3292 t1.setValue( "10", "10", "1010" );
3293 t1.setValue( "100", "10", "10100" );
3294 t1.setValue( "0", "0", "00" );
3295 t1.setValue( "qwerty", "zxcvbnm", "asdef" );
3296 if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
3299 if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
3302 if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
3305 if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
3308 if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
3311 if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
3314 if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
3317 if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
3320 if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
3323 if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
3327 catch ( final Exception e ) {
3328 e.printStackTrace( System.out );
3334 private static boolean testGetDistance() {
3336 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3337 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",
3338 new NHXParser() )[ 0 ];
3339 if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
3342 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
3345 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
3348 if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
3351 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
3354 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
3357 if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
3360 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
3363 if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
3366 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
3369 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
3372 if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
3375 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
3378 if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
3381 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
3384 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
3387 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
3390 if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
3393 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
3396 if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
3399 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
3402 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
3405 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
3408 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
3411 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
3414 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
3417 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
3420 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
3423 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
3426 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
3429 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
3432 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",
3433 new NHXParser() )[ 0 ];
3434 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
3437 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
3440 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
3443 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
3446 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
3449 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
3452 if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
3455 if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
3458 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
3461 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
3464 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
3468 catch ( final Exception e ) {
3469 e.printStackTrace( System.out );
3475 private static boolean testGetLCA() {
3477 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3478 final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3479 new NHXParser() )[ 0 ];
3480 final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
3481 if ( !A.getName().equals( "A" ) ) {
3484 final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
3485 if ( !gh.getName().equals( "gh" ) ) {
3488 final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
3489 if ( !ab.getName().equals( "ab" ) ) {
3492 final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
3493 if ( !ab2.getName().equals( "ab" ) ) {
3496 final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
3497 if ( !gh2.getName().equals( "gh" ) ) {
3500 final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
3501 if ( !gh3.getName().equals( "gh" ) ) {
3504 final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
3505 if ( !abc.getName().equals( "abc" ) ) {
3508 final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
3509 if ( !abc2.getName().equals( "abc" ) ) {
3512 final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
3513 if ( !abcd.getName().equals( "abcd" ) ) {
3516 final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
3517 if ( !abcd2.getName().equals( "abcd" ) ) {
3520 final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
3521 if ( !abcdef.getName().equals( "abcdef" ) ) {
3524 final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
3525 if ( !abcdef2.getName().equals( "abcdef" ) ) {
3528 final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
3529 if ( !abcdef3.getName().equals( "abcdef" ) ) {
3532 final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
3533 if ( !abcdef4.getName().equals( "abcdef" ) ) {
3536 final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
3537 if ( !abcde.getName().equals( "abcde" ) ) {
3540 final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
3541 if ( !abcde2.getName().equals( "abcde" ) ) {
3544 final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
3545 if ( !r.getName().equals( "abcdefgh" ) ) {
3548 final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
3549 if ( !r2.getName().equals( "abcdefgh" ) ) {
3552 final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
3553 if ( !r3.getName().equals( "abcdefgh" ) ) {
3556 final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
3557 if ( !abcde3.getName().equals( "abcde" ) ) {
3560 final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
3561 if ( !abcde4.getName().equals( "abcde" ) ) {
3564 final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
3565 if ( !ab3.getName().equals( "ab" ) ) {
3568 final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
3569 if ( !ab4.getName().equals( "ab" ) ) {
3572 final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3573 final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
3574 if ( !cd.getName().equals( "cd" ) ) {
3577 final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
3578 if ( !cd2.getName().equals( "cd" ) ) {
3581 final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
3582 if ( !cde.getName().equals( "cde" ) ) {
3585 final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
3586 if ( !cde2.getName().equals( "cde" ) ) {
3589 final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
3590 if ( !cdef.getName().equals( "cdef" ) ) {
3593 final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
3594 if ( !cdef2.getName().equals( "cdef" ) ) {
3597 final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
3598 if ( !cdef3.getName().equals( "cdef" ) ) {
3601 final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
3602 if ( !rt.getName().equals( "r" ) ) {
3605 final Phylogeny p3 = factory
3606 .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
3607 new NHXParser() )[ 0 ];
3608 final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
3609 if ( !bc_3.getName().equals( "bc" ) ) {
3612 final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
3613 if ( !ac_3.getName().equals( "abc" ) ) {
3616 final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
3617 if ( !ad_3.getName().equals( "abcde" ) ) {
3620 final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
3621 if ( !af_3.getName().equals( "abcdef" ) ) {
3624 final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
3625 if ( !ag_3.getName().equals( "" ) ) {
3628 if ( !ag_3.isRoot() ) {
3631 final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
3632 if ( !al_3.getName().equals( "" ) ) {
3635 if ( !al_3.isRoot() ) {
3638 final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
3639 if ( !kl_3.getName().equals( "" ) ) {
3642 if ( !kl_3.isRoot() ) {
3645 final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
3646 if ( !fl_3.getName().equals( "" ) ) {
3649 if ( !fl_3.isRoot() ) {
3652 final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
3653 if ( !gk_3.getName().equals( "ghijk" ) ) {
3656 final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
3657 final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
3658 if ( !r_4.getName().equals( "r" ) ) {
3661 final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
3662 final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
3663 if ( !r_5.getName().equals( "root" ) ) {
3666 final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
3667 final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
3668 if ( !r_6.getName().equals( "rot" ) ) {
3671 final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
3672 final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
3673 if ( !r_7.getName().equals( "rott" ) ) {
3677 catch ( final Exception e ) {
3678 e.printStackTrace( System.out );
3684 private static boolean testGetLCA2() {
3686 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3687 final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
3688 PhylogenyMethods.preOrderReId( p_a );
3689 final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
3690 p_a.getNode( "a" ) );
3691 if ( !p_a_1.getName().equals( "a" ) ) {
3694 final Phylogeny p_b = factory.create( "((a)b)", new NHXParser() )[ 0 ];
3695 PhylogenyMethods.preOrderReId( p_b );
3696 final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
3697 p_b.getNode( "a" ) );
3698 if ( !p_b_1.getName().equals( "b" ) ) {
3701 final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
3702 p_b.getNode( "b" ) );
3703 if ( !p_b_2.getName().equals( "b" ) ) {
3706 final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
3707 PhylogenyMethods.preOrderReId( p_c );
3708 final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
3709 p_c.getNode( "a" ) );
3710 if ( !p_c_1.getName().equals( "b" ) ) {
3713 final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3714 p_c.getNode( "c" ) );
3715 if ( !p_c_2.getName().equals( "c" ) ) {
3716 System.out.println( p_c_2.getName() );
3720 final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3721 p_c.getNode( "b" ) );
3722 if ( !p_c_3.getName().equals( "b" ) ) {
3725 final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
3726 p_c.getNode( "a" ) );
3727 if ( !p_c_4.getName().equals( "c" ) ) {
3730 final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3731 new NHXParser() )[ 0 ];
3732 PhylogenyMethods.preOrderReId( p1 );
3733 final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3734 p1.getNode( "A" ) );
3735 if ( !A.getName().equals( "A" ) ) {
3738 final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
3739 p1.getNode( "gh" ) );
3740 if ( !gh.getName().equals( "gh" ) ) {
3743 final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3744 p1.getNode( "B" ) );
3745 if ( !ab.getName().equals( "ab" ) ) {
3748 final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3749 p1.getNode( "A" ) );
3750 if ( !ab2.getName().equals( "ab" ) ) {
3753 final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3754 p1.getNode( "G" ) );
3755 if ( !gh2.getName().equals( "gh" ) ) {
3758 final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
3759 p1.getNode( "H" ) );
3760 if ( !gh3.getName().equals( "gh" ) ) {
3763 final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
3764 p1.getNode( "A" ) );
3765 if ( !abc.getName().equals( "abc" ) ) {
3768 final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3769 p1.getNode( "C" ) );
3770 if ( !abc2.getName().equals( "abc" ) ) {
3773 final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3774 p1.getNode( "D" ) );
3775 if ( !abcd.getName().equals( "abcd" ) ) {
3778 final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
3779 p1.getNode( "A" ) );
3780 if ( !abcd2.getName().equals( "abcd" ) ) {
3783 final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3784 p1.getNode( "F" ) );
3785 if ( !abcdef.getName().equals( "abcdef" ) ) {
3788 final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3789 p1.getNode( "A" ) );
3790 if ( !abcdef2.getName().equals( "abcdef" ) ) {
3793 final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3794 p1.getNode( "F" ) );
3795 if ( !abcdef3.getName().equals( "abcdef" ) ) {
3798 final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3799 p1.getNode( "ab" ) );
3800 if ( !abcdef4.getName().equals( "abcdef" ) ) {
3803 final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3804 p1.getNode( "E" ) );
3805 if ( !abcde.getName().equals( "abcde" ) ) {
3808 final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3809 p1.getNode( "A" ) );
3810 if ( !abcde2.getName().equals( "abcde" ) ) {
3813 final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
3814 p1.getNode( "abcdefgh" ) );
3815 if ( !r.getName().equals( "abcdefgh" ) ) {
3818 final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3819 p1.getNode( "H" ) );
3820 if ( !r2.getName().equals( "abcdefgh" ) ) {
3823 final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3824 p1.getNode( "A" ) );
3825 if ( !r3.getName().equals( "abcdefgh" ) ) {
3828 final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3829 p1.getNode( "abcde" ) );
3830 if ( !abcde3.getName().equals( "abcde" ) ) {
3833 final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
3834 p1.getNode( "E" ) );
3835 if ( !abcde4.getName().equals( "abcde" ) ) {
3838 final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3839 p1.getNode( "B" ) );
3840 if ( !ab3.getName().equals( "ab" ) ) {
3843 final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3844 p1.getNode( "ab" ) );
3845 if ( !ab4.getName().equals( "ab" ) ) {
3848 final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3849 PhylogenyMethods.preOrderReId( p2 );
3850 final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3851 p2.getNode( "d" ) );
3852 if ( !cd.getName().equals( "cd" ) ) {
3855 final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3856 p2.getNode( "c" ) );
3857 if ( !cd2.getName().equals( "cd" ) ) {
3860 final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3861 p2.getNode( "e" ) );
3862 if ( !cde.getName().equals( "cde" ) ) {
3865 final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
3866 p2.getNode( "c" ) );
3867 if ( !cde2.getName().equals( "cde" ) ) {
3870 final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3871 p2.getNode( "f" ) );
3872 if ( !cdef.getName().equals( "cdef" ) ) {
3875 final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3876 p2.getNode( "f" ) );
3877 if ( !cdef2.getName().equals( "cdef" ) ) {
3880 final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
3881 p2.getNode( "d" ) );
3882 if ( !cdef3.getName().equals( "cdef" ) ) {
3885 final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3886 p2.getNode( "a" ) );
3887 if ( !rt.getName().equals( "r" ) ) {
3890 final Phylogeny p3 = factory
3891 .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
3892 new NHXParser() )[ 0 ];
3893 PhylogenyMethods.preOrderReId( p3 );
3894 final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
3895 p3.getNode( "c" ) );
3896 if ( !bc_3.getName().equals( "bc" ) ) {
3899 final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3900 p3.getNode( "c" ) );
3901 if ( !ac_3.getName().equals( "abc" ) ) {
3904 final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3905 p3.getNode( "d" ) );
3906 if ( !ad_3.getName().equals( "abcde" ) ) {
3909 final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3910 p3.getNode( "f" ) );
3911 if ( !af_3.getName().equals( "abcdef" ) ) {
3914 final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3915 p3.getNode( "g" ) );
3916 if ( !ag_3.getName().equals( "" ) ) {
3919 if ( !ag_3.isRoot() ) {
3922 final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3923 p3.getNode( "l" ) );
3924 if ( !al_3.getName().equals( "" ) ) {
3927 if ( !al_3.isRoot() ) {
3930 final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
3931 p3.getNode( "l" ) );
3932 if ( !kl_3.getName().equals( "" ) ) {
3935 if ( !kl_3.isRoot() ) {
3938 final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
3939 p3.getNode( "l" ) );
3940 if ( !fl_3.getName().equals( "" ) ) {
3943 if ( !fl_3.isRoot() ) {
3946 final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
3947 p3.getNode( "k" ) );
3948 if ( !gk_3.getName().equals( "ghijk" ) ) {
3951 final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
3952 PhylogenyMethods.preOrderReId( p4 );
3953 final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
3954 p4.getNode( "c" ) );
3955 if ( !r_4.getName().equals( "r" ) ) {
3958 final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
3959 PhylogenyMethods.preOrderReId( p5 );
3960 final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
3961 p5.getNode( "c" ) );
3962 if ( !r_5.getName().equals( "root" ) ) {
3965 final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
3966 PhylogenyMethods.preOrderReId( p6 );
3967 final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
3968 p6.getNode( "a" ) );
3969 if ( !r_6.getName().equals( "rot" ) ) {
3972 final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
3973 PhylogenyMethods.preOrderReId( p7 );
3974 final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
3975 p7.getNode( "e" ) );
3976 if ( !r_7.getName().equals( "rott" ) ) {
3979 final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
3980 p7.getNode( "a" ) );
3981 if ( !r_71.getName().equals( "rott" ) ) {
3984 final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
3985 p7.getNode( "rott" ) );
3986 if ( !r_72.getName().equals( "rott" ) ) {
3989 final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
3990 p7.getNode( "a" ) );
3991 if ( !r_73.getName().equals( "rott" ) ) {
3994 final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
3995 p7.getNode( "rott" ) );
3996 if ( !r_74.getName().equals( "rott" ) ) {
3999 final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4000 p7.getNode( "e" ) );
4001 if ( !r_75.getName().equals( "e" ) ) {
4005 catch ( final Exception e ) {
4006 e.printStackTrace( System.out );
4012 private static boolean testHmmscanOutputParser() {
4013 final String test_dir = Test.PATH_TO_TEST_DATA;
4015 final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
4016 + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4018 final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
4019 + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4020 final List<Protein> proteins = parser2.parse();
4021 if ( parser2.getProteinsEncountered() != 4 ) {
4024 if ( proteins.size() != 4 ) {
4027 if ( parser2.getDomainsEncountered() != 69 ) {
4030 if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
4033 if ( parser2.getDomainsIgnoredDueToEval() != 0 ) {
4036 final Protein p1 = proteins.get( 0 );
4037 if ( p1.getNumberOfProteinDomains() != 15 ) {
4040 if ( p1.getLength() != 850 ) {
4043 final Protein p2 = proteins.get( 1 );
4044 if ( p2.getNumberOfProteinDomains() != 51 ) {
4047 if ( p2.getLength() != 1291 ) {
4050 final Protein p3 = proteins.get( 2 );
4051 if ( p3.getNumberOfProteinDomains() != 2 ) {
4054 final Protein p4 = proteins.get( 3 );
4055 if ( p4.getNumberOfProteinDomains() != 1 ) {
4058 if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
4061 if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
4064 if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
4067 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
4070 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
4073 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) {
4076 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) {
4079 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
4082 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
4086 catch ( final Exception e ) {
4087 e.printStackTrace( System.out );
4093 private static boolean testLastExternalNodeMethods() {
4095 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4096 final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
4097 final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
4098 final PhylogenyNode n1 = t0.getNode( "A" );
4099 if ( n1.isLastExternalNode() ) {
4102 final PhylogenyNode n2 = t0.getNode( "B" );
4103 if ( n2.isLastExternalNode() ) {
4106 final PhylogenyNode n3 = t0.getNode( "C" );
4107 if ( n3.isLastExternalNode() ) {
4110 final PhylogenyNode n4 = t0.getNode( "D" );
4111 if ( !n4.isLastExternalNode() ) {
4115 catch ( final Exception e ) {
4116 e.printStackTrace( System.out );
4122 private static boolean testLevelOrderIterator() {
4124 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4125 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
4126 PhylogenyNodeIterator it0;
4127 for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
4130 for( it0.reset(); it0.hasNext(); ) {
4133 final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
4134 if ( !it.next().getName().equals( "r" ) ) {
4137 if ( !it.next().getName().equals( "ab" ) ) {
4140 if ( !it.next().getName().equals( "cd" ) ) {
4143 if ( !it.next().getName().equals( "A" ) ) {
4146 if ( !it.next().getName().equals( "B" ) ) {
4149 if ( !it.next().getName().equals( "C" ) ) {
4152 if ( !it.next().getName().equals( "D" ) ) {
4155 if ( it.hasNext() ) {
4158 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",
4159 new NHXParser() )[ 0 ];
4160 PhylogenyNodeIterator it2;
4161 for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
4164 for( it2.reset(); it2.hasNext(); ) {
4167 final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
4168 if ( !it3.next().getName().equals( "r" ) ) {
4171 if ( !it3.next().getName().equals( "abc" ) ) {
4174 if ( !it3.next().getName().equals( "defg" ) ) {
4177 if ( !it3.next().getName().equals( "A" ) ) {
4180 if ( !it3.next().getName().equals( "B" ) ) {
4183 if ( !it3.next().getName().equals( "C" ) ) {
4186 if ( !it3.next().getName().equals( "D" ) ) {
4189 if ( !it3.next().getName().equals( "E" ) ) {
4192 if ( !it3.next().getName().equals( "F" ) ) {
4195 if ( !it3.next().getName().equals( "G" ) ) {
4198 if ( !it3.next().getName().equals( "1" ) ) {
4201 if ( !it3.next().getName().equals( "2" ) ) {
4204 if ( !it3.next().getName().equals( "3" ) ) {
4207 if ( !it3.next().getName().equals( "4" ) ) {
4210 if ( !it3.next().getName().equals( "5" ) ) {
4213 if ( !it3.next().getName().equals( "6" ) ) {
4216 if ( !it3.next().getName().equals( "f1" ) ) {
4219 if ( !it3.next().getName().equals( "f2" ) ) {
4222 if ( !it3.next().getName().equals( "f3" ) ) {
4225 if ( !it3.next().getName().equals( "a" ) ) {
4228 if ( !it3.next().getName().equals( "b" ) ) {
4231 if ( !it3.next().getName().equals( "f21" ) ) {
4234 if ( !it3.next().getName().equals( "X" ) ) {
4237 if ( !it3.next().getName().equals( "Y" ) ) {
4240 if ( !it3.next().getName().equals( "Z" ) ) {
4243 if ( it3.hasNext() ) {
4246 final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
4247 PhylogenyNodeIterator it4;
4248 for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
4251 for( it4.reset(); it4.hasNext(); ) {
4254 final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
4255 if ( !it5.next().getName().equals( "r" ) ) {
4258 if ( !it5.next().getName().equals( "A" ) ) {
4261 if ( !it5.next().getName().equals( "B" ) ) {
4264 if ( !it5.next().getName().equals( "C" ) ) {
4267 if ( !it5.next().getName().equals( "D" ) ) {
4270 final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
4271 PhylogenyNodeIterator it6;
4272 for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
4275 for( it6.reset(); it6.hasNext(); ) {
4278 final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
4279 if ( !it7.next().getName().equals( "A" ) ) {
4282 if ( it.hasNext() ) {
4286 catch ( final Exception e ) {
4287 e.printStackTrace( System.out );
4293 private static boolean testNodeRemoval() {
4295 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4296 final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
4297 PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
4298 if ( !t0.toNewHampshire().equals( "(a);" ) ) {
4301 final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
4302 PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
4303 if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
4306 final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
4307 PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
4308 if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
4312 catch ( final Exception e ) {
4313 e.printStackTrace( System.out );
4319 private static boolean testMidpointrooting() {
4321 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4322 final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
4323 PhylogenyMethods.midpointRoot( t0 );
4324 if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
4327 if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
4330 if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
4334 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",
4335 new NHXParser() )[ 0 ];
4336 if ( !t1.isRooted() ) {
4339 PhylogenyMethods.midpointRoot( t1 );
4340 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4343 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4346 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4349 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4352 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4355 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4358 t1.reRoot( t1.getNode( "A" ) );
4359 PhylogenyMethods.midpointRoot( t1 );
4360 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4363 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4366 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4369 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4372 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4376 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4380 catch ( final Exception e ) {
4381 e.printStackTrace( System.out );
4387 private static boolean testNexusCharactersParsing() {
4389 final NexusCharactersParser parser = new NexusCharactersParser();
4390 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
4392 String[] labels = parser.getCharStateLabels();
4393 if ( labels.length != 7 ) {
4396 if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4399 if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4402 if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4405 if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4408 if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4411 if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4414 if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4417 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4419 labels = parser.getCharStateLabels();
4420 if ( labels.length != 7 ) {
4423 if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4426 if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4429 if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4432 if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4435 if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4438 if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4441 if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4445 catch ( final Exception e ) {
4446 e.printStackTrace( System.out );
4452 private static boolean testNexusMatrixParsing() {
4454 final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
4455 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
4457 final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
4458 if ( m.getNumberOfCharacters() != 9 ) {
4461 if ( m.getNumberOfIdentifiers() != 5 ) {
4464 if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
4467 if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
4470 if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
4473 if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
4476 if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
4479 if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
4482 if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
4485 // if ( labels.length != 7 ) {
4488 // if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4491 // if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4494 // if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4497 // if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4500 // if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4503 // if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4506 // if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4509 // parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4511 // labels = parser.getCharStateLabels();
4512 // if ( labels.length != 7 ) {
4515 // if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4518 // if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4521 // if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4524 // if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4527 // if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4530 // if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4533 // if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4537 catch ( final Exception e ) {
4538 e.printStackTrace( System.out );
4544 private static boolean testNexusTreeParsing() {
4546 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4547 final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
4548 Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
4549 if ( phylogenies.length != 1 ) {
4552 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
4555 if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4559 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
4560 if ( phylogenies.length != 1 ) {
4563 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4566 if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
4570 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
4571 if ( phylogenies.length != 1 ) {
4574 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4577 if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4580 if ( phylogenies[ 0 ].isRooted() ) {
4584 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
4585 if ( phylogenies.length != 18 ) {
4588 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4591 if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
4594 if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
4597 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
4600 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
4603 if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
4606 if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
4609 if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
4612 if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
4615 if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
4618 if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
4621 if ( phylogenies[ 8 ].isRooted() ) {
4624 if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
4627 if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
4630 if ( !phylogenies[ 9 ].isRooted() ) {
4633 if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
4636 if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
4639 if ( !phylogenies[ 10 ].isRooted() ) {
4642 if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
4645 if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
4648 if ( phylogenies[ 11 ].isRooted() ) {
4651 if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
4654 if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
4657 if ( !phylogenies[ 12 ].isRooted() ) {
4660 if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
4663 if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
4666 if ( !phylogenies[ 13 ].isRooted() ) {
4669 if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
4672 if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
4675 if ( !phylogenies[ 14 ].isRooted() ) {
4678 if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
4681 if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
4684 if ( phylogenies[ 15 ].isRooted() ) {
4687 if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
4690 if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
4693 if ( !phylogenies[ 16 ].isRooted() ) {
4696 if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
4699 if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
4702 if ( phylogenies[ 17 ].isRooted() ) {
4705 if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
4709 catch ( final Exception e ) {
4710 e.printStackTrace( System.out );
4716 private static boolean testNexusTreeParsingIterating() {
4718 final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
4719 p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
4720 if ( !p.hasNext() ) {
4723 Phylogeny phy = p.next();
4724 if ( phy == null ) {
4727 if ( phy.getNumberOfExternalNodes() != 25 ) {
4730 if ( !phy.getName().equals( "" ) ) {
4733 if ( p.hasNext() ) {
4737 if ( phy != null ) {
4742 if ( !p.hasNext() ) {
4746 if ( phy == null ) {
4749 if ( phy.getNumberOfExternalNodes() != 25 ) {
4752 if ( !phy.getName().equals( "" ) ) {
4755 if ( p.hasNext() ) {
4759 if ( phy != null ) {
4763 p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
4764 if ( !p.hasNext() ) {
4768 if ( phy == null ) {
4771 if ( phy.getNumberOfExternalNodes() != 10 ) {
4774 if ( !phy.getName().equals( "name" ) ) {
4777 if ( p.hasNext() ) {
4781 if ( phy != null ) {
4786 if ( !p.hasNext() ) {
4790 if ( phy == null ) {
4793 if ( phy.getNumberOfExternalNodes() != 10 ) {
4796 if ( !phy.getName().equals( "name" ) ) {
4799 if ( p.hasNext() ) {
4803 if ( phy != null ) {
4807 p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
4808 if ( !p.hasNext() ) {
4812 if ( phy == null ) {
4815 if ( phy.getNumberOfExternalNodes() != 3 ) {
4818 if ( !phy.getName().equals( "" ) ) {
4821 if ( phy.isRooted() ) {
4824 if ( p.hasNext() ) {
4828 if ( phy != null ) {
4833 if ( !p.hasNext() ) {
4837 if ( phy == null ) {
4840 if ( phy.getNumberOfExternalNodes() != 3 ) {
4843 if ( !phy.getName().equals( "" ) ) {
4846 if ( p.hasNext() ) {
4850 if ( phy != null ) {
4854 p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
4855 // if ( phylogenies.length != 18 ) {
4859 if ( !p.hasNext() ) {
4863 if ( phy == null ) {
4866 if ( phy.getNumberOfExternalNodes() != 10 ) {
4869 if ( !phy.getName().equals( "tree 0" ) ) {
4873 if ( !p.hasNext() ) {
4877 if ( phy == null ) {
4880 if ( phy.getNumberOfExternalNodes() != 10 ) {
4883 if ( !phy.getName().equals( "tree 1" ) ) {
4887 if ( !p.hasNext() ) {
4891 if ( phy == null ) {
4894 if ( phy.getNumberOfExternalNodes() != 3 ) {
4897 if ( !phy.getName().equals( "" ) ) {
4900 if ( phy.isRooted() ) {
4904 if ( !p.hasNext() ) {
4908 if ( phy == null ) {
4911 if ( phy.getNumberOfExternalNodes() != 4 ) {
4914 if ( !phy.getName().equals( "" ) ) {
4917 if ( !phy.isRooted() ) {
4921 if ( !p.hasNext() ) {
4925 if ( phy == null ) {
4928 if ( phy.getNumberOfExternalNodes() != 5 ) {
4929 System.out.println( phy.getNumberOfExternalNodes() );
4932 if ( !phy.getName().equals( "" ) ) {
4935 if ( !phy.isRooted() ) {
4939 if ( !p.hasNext() ) {
4943 if ( phy == null ) {
4946 if ( phy.getNumberOfExternalNodes() != 3 ) {
4949 if ( !phy.getName().equals( "" ) ) {
4952 if ( phy.isRooted() ) {
4956 if ( !p.hasNext() ) {
4960 if ( phy == null ) {
4963 if ( phy.getNumberOfExternalNodes() != 2 ) {
4966 if ( !phy.getName().equals( "" ) ) {
4969 if ( !phy.isRooted() ) {
4973 if ( !p.hasNext() ) {
4977 if ( phy.getNumberOfExternalNodes() != 3 ) {
4980 if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
4983 if ( !phy.isRooted() ) {
4987 if ( !p.hasNext() ) {
4991 if ( phy.getNumberOfExternalNodes() != 3 ) {
4994 if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
4997 if ( !phy.getName().equals( "tree 8" ) ) {
5001 if ( !p.hasNext() ) {
5005 if ( phy.getNumberOfExternalNodes() != 3 ) {
5008 if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
5011 if ( !phy.getName().equals( "tree 9" ) ) {
5015 if ( !p.hasNext() ) {
5019 if ( phy.getNumberOfExternalNodes() != 3 ) {
5022 if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
5025 if ( !phy.getName().equals( "tree 10" ) ) {
5028 if ( !phy.isRooted() ) {
5032 if ( !p.hasNext() ) {
5036 if ( phy.getNumberOfExternalNodes() != 3 ) {
5039 if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
5042 if ( !phy.getName().equals( "tree 11" ) ) {
5045 if ( phy.isRooted() ) {
5049 if ( !p.hasNext() ) {
5053 if ( phy.getNumberOfExternalNodes() != 3 ) {
5056 if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
5059 if ( !phy.getName().equals( "tree 12" ) ) {
5062 if ( !phy.isRooted() ) {
5066 if ( !p.hasNext() ) {
5070 if ( phy.getNumberOfExternalNodes() != 3 ) {
5073 if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
5076 if ( !phy.getName().equals( "tree 13" ) ) {
5079 if ( !phy.isRooted() ) {
5083 if ( !p.hasNext() ) {
5087 if ( phy.getNumberOfExternalNodes() != 10 ) {
5088 System.out.println( phy.getNumberOfExternalNodes() );
5093 .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;" ) ) {
5094 System.out.println( phy.toNewHampshire() );
5097 if ( !phy.getName().equals( "tree 14" ) ) {
5100 if ( !phy.isRooted() ) {
5104 if ( !p.hasNext() ) {
5108 if ( phy.getNumberOfExternalNodes() != 10 ) {
5109 System.out.println( phy.getNumberOfExternalNodes() );
5114 .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;" ) ) {
5115 System.out.println( phy.toNewHampshire() );
5118 if ( !phy.getName().equals( "tree 15" ) ) {
5121 if ( phy.isRooted() ) {
5125 if ( !p.hasNext() ) {
5129 if ( phy.getNumberOfExternalNodes() != 10 ) {
5130 System.out.println( phy.getNumberOfExternalNodes() );
5135 .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;" ) ) {
5136 System.out.println( phy.toNewHampshire() );
5139 if ( !phy.getName().equals( "tree 16" ) ) {
5142 if ( !phy.isRooted() ) {
5146 if ( !p.hasNext() ) {
5150 if ( phy.getNumberOfExternalNodes() != 10 ) {
5151 System.out.println( phy.getNumberOfExternalNodes() );
5156 .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;" ) ) {
5157 System.out.println( phy.toNewHampshire() );
5160 if ( !phy.getName().equals( "tree 17" ) ) {
5163 if ( phy.isRooted() ) {
5167 if ( p.hasNext() ) {
5171 if ( phy != null ) {
5176 if ( !p.hasNext() ) {
5180 if ( phy == null ) {
5183 if ( phy.getNumberOfExternalNodes() != 10 ) {
5186 if ( !phy.getName().equals( "tree 0" ) ) {
5190 if ( !p.hasNext() ) {
5194 if ( phy == null ) {
5197 if ( phy.getNumberOfExternalNodes() != 10 ) {
5200 if ( !phy.getName().equals( "tree 1" ) ) {
5204 if ( !p.hasNext() ) {
5208 if ( phy == null ) {
5211 if ( phy.getNumberOfExternalNodes() != 3 ) {
5214 if ( !phy.getName().equals( "" ) ) {
5217 if ( phy.isRooted() ) {
5221 if ( !p.hasNext() ) {
5225 if ( phy == null ) {
5228 if ( phy.getNumberOfExternalNodes() != 4 ) {
5231 if ( !phy.getName().equals( "" ) ) {
5234 if ( !phy.isRooted() ) {
5238 if ( !p.hasNext() ) {
5242 if ( phy == null ) {
5245 if ( phy.getNumberOfExternalNodes() != 5 ) {
5246 System.out.println( phy.getNumberOfExternalNodes() );
5249 if ( !phy.getName().equals( "" ) ) {
5252 if ( !phy.isRooted() ) {
5256 if ( !p.hasNext() ) {
5260 if ( phy == null ) {
5263 if ( phy.getNumberOfExternalNodes() != 3 ) {
5266 if ( !phy.getName().equals( "" ) ) {
5269 if ( phy.isRooted() ) {
5273 catch ( final Exception e ) {
5274 e.printStackTrace( System.out );
5280 private static boolean testNexusTreeParsingTranslating() {
5282 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5283 final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
5284 Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
5285 if ( phylogenies.length != 1 ) {
5288 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5291 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5294 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5297 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5300 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5301 .equals( "Aranaeus" ) ) {
5305 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
5306 if ( phylogenies.length != 3 ) {
5309 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5312 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5315 if ( phylogenies[ 0 ].isRooted() ) {
5318 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5321 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5324 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5325 .equals( "Aranaeus" ) ) {
5328 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
5331 if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
5334 if ( phylogenies[ 1 ].isRooted() ) {
5337 if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5340 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5343 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5344 .equals( "Aranaeus" ) ) {
5347 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
5350 if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
5353 if ( !phylogenies[ 2 ].isRooted() ) {
5356 if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5359 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5362 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5363 .equals( "Aranaeus" ) ) {
5367 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
5368 if ( phylogenies.length != 3 ) {
5371 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5374 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5377 if ( phylogenies[ 0 ].isRooted() ) {
5380 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5383 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5386 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5387 .equals( "Aranaeus" ) ) {
5390 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
5393 if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
5396 if ( phylogenies[ 1 ].isRooted() ) {
5399 if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5402 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5405 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5406 .equals( "Aranaeus" ) ) {
5409 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
5412 if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
5415 if ( !phylogenies[ 2 ].isRooted() ) {
5418 if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5421 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5424 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5425 .equals( "Aranaeus" ) ) {
5429 catch ( final Exception e ) {
5430 e.printStackTrace( System.out );
5436 private static boolean testNHParsing() {
5438 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5439 final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
5440 if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
5443 final NHXParser nhxp = new NHXParser();
5444 nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
5445 nhxp.setReplaceUnderscores( true );
5446 final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
5447 if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
5450 if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
5453 final Phylogeny p1b = factory
5454 .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 ",
5455 new NHXParser() )[ 0 ];
5456 if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
5459 if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
5462 final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
5463 final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
5464 final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
5465 final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
5466 final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
5467 final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
5468 final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
5469 final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
5470 final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
5471 final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
5472 final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1 3 ; \n)\t ( \n ;"
5473 + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
5474 + "; ; ( \t\n\r\b; G ;, ;H ;1 3; ) ; ; ;",
5476 if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
5479 if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
5482 if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
5485 if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
5488 final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
5489 final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
5490 final String p16_S = "((A,B),C)";
5491 final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
5492 if ( p16.length != 1 ) {
5495 if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
5498 final String p17_S = "(C,(A,B))";
5499 final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
5500 if ( p17.length != 1 ) {
5503 if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
5506 final String p18_S = "((A,B),(C,D))";
5507 final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
5508 if ( p18.length != 1 ) {
5511 if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
5514 final String p19_S = "(((A,B),C),D)";
5515 final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
5516 if ( p19.length != 1 ) {
5519 if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
5522 final String p20_S = "(A,(B,(C,D)))";
5523 final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
5524 if ( p20.length != 1 ) {
5527 if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
5530 final String p21_S = "(A,(B,(C,(D,E))))";
5531 final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
5532 if ( p21.length != 1 ) {
5535 if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
5538 final String p22_S = "((((A,B),C),D),E)";
5539 final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
5540 if ( p22.length != 1 ) {
5543 if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
5546 final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5547 final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
5548 if ( p23.length != 1 ) {
5549 System.out.println( "xl=" + p23.length );
5553 if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
5556 final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5557 final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
5558 if ( p24.length != 1 ) {
5561 if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
5564 final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5565 final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5566 final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
5567 if ( p241.length != 2 ) {
5570 if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
5573 if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
5576 final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
5577 + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
5578 + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
5579 + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
5580 + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
5581 + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
5582 + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
5583 + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
5584 final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
5585 if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
5588 final String p26_S = "(A,B)ab";
5589 final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
5590 if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
5593 final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5594 final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
5595 if ( p27s.length != 1 ) {
5596 System.out.println( "xxl=" + p27s.length );
5600 if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
5601 System.out.println( p27s[ 0 ].toNewHampshireX() );
5605 final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
5607 if ( p27.length != 1 ) {
5608 System.out.println( "yl=" + p27.length );
5612 if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
5613 System.out.println( p27[ 0 ].toNewHampshireX() );
5617 final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5618 final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5619 final String p28_S3 = "(A,B)ab";
5620 final String p28_S4 = "((((A,B),C),D),;E;)";
5621 final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
5623 if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
5626 if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
5629 if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
5632 if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
5635 if ( p28.length != 4 ) {
5638 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";
5639 final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
5640 if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
5643 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";
5644 final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
5645 if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
5648 final String p32_S = " ; ; \n \t \b \f \r ;;;;;; ";
5649 final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
5650 if ( ( p32.length != 0 ) ) {
5653 final String p33_S = "A";
5654 final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
5655 if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
5658 final String p34_S = "B;";
5659 final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
5660 if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
5663 final String p35_S = "B:0.2";
5664 final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
5665 if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
5668 final String p36_S = "(A)";
5669 final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
5670 if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
5673 final String p37_S = "((A))";
5674 final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
5675 if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
5678 final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
5679 final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
5680 if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
5683 final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
5684 final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
5685 if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
5688 final String p40_S = "(A,B,C)";
5689 final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
5690 if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
5693 final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
5694 final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
5695 if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
5698 final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
5699 final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
5700 if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
5703 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)";
5704 final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
5705 if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
5708 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)))";
5709 final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
5710 if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
5713 final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
5714 final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
5715 if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
5718 final String p46_S = "";
5719 final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
5720 if ( p46.length != 0 ) {
5723 final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
5724 if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5727 final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5728 if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5731 final Phylogeny p49 = factory
5732 .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
5733 new NHXParser() )[ 0 ];
5734 if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5737 final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5738 if ( p50.getNode( "A" ) == null ) {
5741 if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
5742 .equals( "((A,B)ab:2.0[88],C);" ) ) {
5745 if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
5748 if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
5749 .equals( "((A,B)88:2.0,C);" ) ) {
5752 final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5753 if ( p51.getNode( "A(A" ) == null ) {
5756 final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5757 if ( p52.getNode( "A(A" ) == null ) {
5760 final Phylogeny p53 = factory
5761 .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
5762 new NHXParser() )[ 0 ];
5763 if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
5767 final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
5768 if ( p54.getNode( "A" ) == null ) {
5771 if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
5772 .equals( "((A,B)[88],C);" ) ) {
5776 catch ( final Exception e ) {
5777 e.printStackTrace( System.out );
5783 private static boolean testNHParsingIter() {
5785 final String p0_str = "(A,B);";
5786 final NHXParser p = new NHXParser();
5787 p.setSource( p0_str );
5788 if ( !p.hasNext() ) {
5791 final Phylogeny p0 = p.next();
5792 if ( !p0.toNewHampshire().equals( p0_str ) ) {
5793 System.out.println( p0.toNewHampshire() );
5796 if ( p.hasNext() ) {
5799 if ( p.next() != null ) {
5803 final String p00_str = "(A,B)root;";
5804 p.setSource( p00_str );
5805 final Phylogeny p00 = p.next();
5806 if ( !p00.toNewHampshire().equals( p00_str ) ) {
5807 System.out.println( p00.toNewHampshire() );
5811 final String p000_str = "A;";
5812 p.setSource( p000_str );
5813 final Phylogeny p000 = p.next();
5814 if ( !p000.toNewHampshire().equals( p000_str ) ) {
5815 System.out.println( p000.toNewHampshire() );
5819 final String p0000_str = "A";
5820 p.setSource( p0000_str );
5821 final Phylogeny p0000 = p.next();
5822 if ( !p0000.toNewHampshire().equals( "A;" ) ) {
5823 System.out.println( p0000.toNewHampshire() );
5827 p.setSource( "(A)" );
5828 final Phylogeny p00000 = p.next();
5829 if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
5830 System.out.println( p00000.toNewHampshire() );
5834 final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
5835 p.setSource( p1_str );
5836 if ( !p.hasNext() ) {
5839 final Phylogeny p1_0 = p.next();
5840 if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
5841 System.out.println( p1_0.toNewHampshire() );
5844 if ( !p.hasNext() ) {
5847 final Phylogeny p1_1 = p.next();
5848 if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
5849 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
5852 if ( !p.hasNext() ) {
5855 final Phylogeny p1_2 = p.next();
5856 if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
5857 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
5860 if ( !p.hasNext() ) {
5863 final Phylogeny p1_3 = p.next();
5864 if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
5865 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
5868 if ( p.hasNext() ) {
5871 if ( p.next() != null ) {
5875 final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
5876 p.setSource( p2_str );
5877 if ( !p.hasNext() ) {
5880 Phylogeny p2_0 = p.next();
5881 if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
5882 System.out.println( p2_0.toNewHampshire() );
5885 if ( !p.hasNext() ) {
5888 Phylogeny p2_1 = p.next();
5889 if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
5890 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
5893 if ( !p.hasNext() ) {
5896 Phylogeny p2_2 = p.next();
5897 if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
5898 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
5901 if ( !p.hasNext() ) {
5904 Phylogeny p2_3 = p.next();
5905 if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
5906 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
5909 if ( !p.hasNext() ) {
5912 Phylogeny p2_4 = p.next();
5913 if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
5914 System.out.println( "(X) != " + p2_4.toNewHampshire() );
5917 if ( p.hasNext() ) {
5920 if ( p.next() != null ) {
5925 if ( !p.hasNext() ) {
5929 if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
5930 System.out.println( p2_0.toNewHampshire() );
5933 if ( !p.hasNext() ) {
5937 if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
5938 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
5941 if ( !p.hasNext() ) {
5945 if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
5946 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
5949 if ( !p.hasNext() ) {
5953 if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
5954 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
5957 if ( !p.hasNext() ) {
5961 if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
5962 System.out.println( "(X) != " + p2_4.toNewHampshire() );
5965 if ( p.hasNext() ) {
5968 if ( p.next() != null ) {
5972 final String p3_str = "((A,B),C)abc";
5973 p.setSource( p3_str );
5974 if ( !p.hasNext() ) {
5977 final Phylogeny p3_0 = p.next();
5978 if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
5981 if ( p.hasNext() ) {
5984 if ( p.next() != null ) {
5988 final String p4_str = "((A,B)ab,C)abc";
5989 p.setSource( p4_str );
5990 if ( !p.hasNext() ) {
5993 final Phylogeny p4_0 = p.next();
5994 if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
5997 if ( p.hasNext() ) {
6000 if ( p.next() != null ) {
6004 final String p5_str = "(((A,B)ab,C)abc,D)abcd";
6005 p.setSource( p5_str );
6006 if ( !p.hasNext() ) {
6009 final Phylogeny p5_0 = p.next();
6010 if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
6013 if ( p.hasNext() ) {
6016 if ( p.next() != null ) {
6020 final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
6021 p.setSource( p6_str );
6022 if ( !p.hasNext() ) {
6025 Phylogeny p6_0 = p.next();
6026 if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
6029 if ( p.hasNext() ) {
6032 if ( p.next() != null ) {
6036 if ( !p.hasNext() ) {
6040 if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
6043 if ( p.hasNext() ) {
6046 if ( p.next() != null ) {
6050 final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6051 p.setSource( p7_str );
6052 if ( !p.hasNext() ) {
6055 Phylogeny p7_0 = p.next();
6056 if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6059 if ( p.hasNext() ) {
6062 if ( p.next() != null ) {
6066 if ( !p.hasNext() ) {
6070 if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6073 if ( p.hasNext() ) {
6076 if ( p.next() != null ) {
6080 final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
6081 p.setSource( p8_str );
6082 if ( !p.hasNext() ) {
6085 Phylogeny p8_0 = p.next();
6086 if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6089 if ( !p.hasNext() ) {
6092 if ( !p.hasNext() ) {
6095 Phylogeny p8_1 = p.next();
6096 if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
6099 if ( p.hasNext() ) {
6102 if ( p.next() != null ) {
6106 if ( !p.hasNext() ) {
6110 if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6113 if ( !p.hasNext() ) {
6117 if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
6120 if ( p.hasNext() ) {
6123 if ( p.next() != null ) {
6129 if ( p.hasNext() ) {
6133 p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
6134 if ( !p.hasNext() ) {
6137 Phylogeny p_27 = p.next();
6138 if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
6139 System.out.println( p_27.toNewHampshireX() );
6143 if ( p.hasNext() ) {
6146 if ( p.next() != null ) {
6150 if ( !p.hasNext() ) {
6154 if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
6155 System.out.println( p_27.toNewHampshireX() );
6159 if ( p.hasNext() ) {
6162 if ( p.next() != null ) {
6166 catch ( final Exception e ) {
6167 e.printStackTrace( System.out );
6173 private static boolean testNHXconversion() {
6175 final PhylogenyNode n1 = new PhylogenyNode();
6176 final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
6177 final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
6178 final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
6179 final PhylogenyNode n5 = PhylogenyNode
6180 .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
6181 final PhylogenyNode n6 = PhylogenyNode
6182 .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
6183 if ( !n1.toNewHampshireX().equals( "" ) ) {
6186 if ( !n2.toNewHampshireX().equals( "" ) ) {
6189 if ( !n3.toNewHampshireX().equals( "n3" ) ) {
6192 if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
6195 if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
6198 if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
6199 System.out.println( n6.toNewHampshireX() );
6203 catch ( final Exception e ) {
6204 e.printStackTrace( System.out );
6210 private static boolean testTaxonomyExtraction() {
6212 final PhylogenyNode n0 = PhylogenyNode
6213 .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6214 if ( n0.getNodeData().isHasTaxonomy() ) {
6217 final PhylogenyNode n1 = PhylogenyNode
6218 .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6219 if ( n1.getNodeData().isHasTaxonomy() ) {
6220 System.out.println( n1.toString() );
6223 final PhylogenyNode n2 = PhylogenyNode
6224 .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.AGRESSIVE );
6225 if ( !n2.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6226 System.out.println( n2.toString() );
6229 final PhylogenyNode n2x = PhylogenyNode
6230 .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6231 if ( n2x.getNodeData().isHasTaxonomy() ) {
6234 final PhylogenyNode n3 = PhylogenyNode
6235 .createInstanceFromNhxString( "blag_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6236 if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6237 System.out.println( n3.toString() );
6240 final PhylogenyNode n4 = PhylogenyNode
6241 .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6242 if ( n4.getNodeData().isHasTaxonomy() ) {
6243 System.out.println( n4.toString() );
6246 final PhylogenyNode n5 = PhylogenyNode
6247 .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6248 if ( n5.getNodeData().isHasTaxonomy() ) {
6249 System.out.println( n5.toString() );
6252 final PhylogenyNode n6 = PhylogenyNode
6253 .createInstanceFromNhxString( "blag-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6254 if ( n6.getNodeData().isHasTaxonomy() ) {
6255 System.out.println( n6.toString() );
6258 final PhylogenyNode n7 = PhylogenyNode
6259 .createInstanceFromNhxString( "blag-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6260 if ( n7.getNodeData().isHasTaxonomy() ) {
6261 System.out.println( n7.toString() );
6264 final PhylogenyNode n8 = PhylogenyNode
6265 .createInstanceFromNhxString( "blag_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6266 if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6267 System.out.println( n8.toString() );
6270 final PhylogenyNode n9 = PhylogenyNode
6271 .createInstanceFromNhxString( "blag_12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6272 if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6273 System.out.println( n9.toString() );
6276 final PhylogenyNode n10x = PhylogenyNode
6277 .createInstanceFromNhxString( "blag_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6278 if ( n10x.getNodeData().isHasTaxonomy() ) {
6279 System.out.println( n10x.toString() );
6282 final PhylogenyNode n10xx = PhylogenyNode
6283 .createInstanceFromNhxString( "blag_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6284 if ( n10xx.getNodeData().isHasTaxonomy() ) {
6285 System.out.println( n10xx.toString() );
6288 final PhylogenyNode n10 = PhylogenyNode
6289 .createInstanceFromNhxString( "blag_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6290 if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
6291 System.out.println( n10.toString() );
6294 final PhylogenyNode n11 = PhylogenyNode
6295 .createInstanceFromNhxString( "blag_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6296 if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
6297 System.out.println( n11.toString() );
6300 final PhylogenyNode n12 = PhylogenyNode
6301 .createInstanceFromNhxString( "blag_Mus_musculus_musculus",
6302 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6303 if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
6304 System.out.println( n12.toString() );
6307 final PhylogenyNode n13 = PhylogenyNode
6308 .createInstanceFromNhxString( "blag_Mus_musculus1",
6309 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6310 if ( n13.getNodeData().isHasTaxonomy() ) {
6311 System.out.println( n13.toString() );
6314 final PhylogenyNode n14 = PhylogenyNode
6315 .createInstanceFromNhxString( "blag_Mus_musculus_11",
6316 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6317 if ( n14.getNodeData().isHasTaxonomy() ) {
6318 System.out.println( n14.toString() );
6321 final PhylogenyNode n15 = PhylogenyNode
6322 .createInstanceFromNhxString( "blag_Mus_musculus_v11",
6323 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6324 if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus v11" ) ) {
6325 System.out.println( n15.toString() );
6328 final PhylogenyNode n16 = PhylogenyNode
6329 .createInstanceFromNhxString( "blag_Mus_musculus_/11",
6330 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6331 if ( n16.getNodeData().isHasTaxonomy() ) {
6332 System.out.println( n16.toString() );
6335 final PhylogenyNode n17 = PhylogenyNode
6336 .createInstanceFromNhxString( "blag_Mus_musculus_v",
6337 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6338 if ( n17.getNodeData().isHasTaxonomy() ) {
6339 System.out.println( n17.toString() );
6343 catch ( final Exception e ) {
6344 e.printStackTrace( System.out );
6350 private static boolean testNHXNodeParsing() {
6352 final PhylogenyNode n1 = new PhylogenyNode();
6353 final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
6354 final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
6355 final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
6356 final PhylogenyNode n5 = PhylogenyNode
6357 .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]" );
6358 if ( !n3.getName().equals( "n3" ) ) {
6361 if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6364 if ( n3.isDuplication() ) {
6367 if ( n3.isHasAssignedEvent() ) {
6370 if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
6373 if ( !n4.getName().equals( "n4" ) ) {
6376 if ( n4.getDistanceToParent() != 0.01 ) {
6379 if ( !n5.getName().equals( "n5" ) ) {
6382 if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
6385 if ( n5.getDistanceToParent() != 0.1 ) {
6388 if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
6391 if ( !n5.isDuplication() ) {
6394 if ( !n5.isHasAssignedEvent() ) {
6397 final PhylogenyNode n8 = PhylogenyNode
6398 .createInstanceFromNhxString( "n8_ECOLI/12:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6399 if ( !n8.getName().equals( "n8_ECOLI/12" ) ) {
6402 if ( PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
6405 final PhylogenyNode n9 = PhylogenyNode
6406 .createInstanceFromNhxString( "n9_ECOLI/12=12:0.01",
6407 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6408 if ( !n9.getName().equals( "n9_ECOLI/12=12" ) ) {
6411 if ( PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
6414 final PhylogenyNode n10 = PhylogenyNode
6415 .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6416 if ( !n10.getName().equals( "n10.ECOLI" ) ) {
6419 final PhylogenyNode n20 = PhylogenyNode
6420 .createInstanceFromNhxString( "n20_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6421 if ( !n20.getName().equals( "n20_ECOLI/1-2" ) ) {
6424 if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
6427 final PhylogenyNode n20x = PhylogenyNode
6428 .createInstanceFromNhxString( "n20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6429 if ( !n20x.getName().equals( "n20_ECOL1/1-2" ) ) {
6432 if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
6435 final PhylogenyNode n20xx = PhylogenyNode
6436 .createInstanceFromNhxString( "n20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6437 if ( !n20xx.getName().equals( "n20_eCOL1/1-2" ) ) {
6440 if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
6443 final PhylogenyNode n20xxx = PhylogenyNode
6444 .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6445 if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
6448 if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
6451 final PhylogenyNode n20xxxx = PhylogenyNode
6452 .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6453 if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
6456 if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
6459 final PhylogenyNode n21 = PhylogenyNode
6460 .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6461 if ( !n21.getName().equals( "n21_PIG" ) ) {
6464 if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
6467 final PhylogenyNode n21x = PhylogenyNode
6468 .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6469 if ( !n21x.getName().equals( "n21_PIG" ) ) {
6472 if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
6475 final PhylogenyNode n22 = PhylogenyNode
6476 .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6477 if ( !n22.getName().equals( "n22/PIG" ) ) {
6480 if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
6483 final PhylogenyNode n23 = PhylogenyNode
6484 .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6485 if ( !n23.getName().equals( "n23/PIG_1" ) ) {
6488 if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
6491 final PhylogenyNode a = PhylogenyNode
6492 .createInstanceFromNhxString( "n10_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6493 if ( !a.getName().equals( "n10_ECOLI/1-2" ) ) {
6496 if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
6499 final PhylogenyNode b = PhylogenyNode
6500 .createInstanceFromNhxString( "n10_ECOLI1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6501 if ( !b.getName().equals( "n10_ECOLI1/1-2" ) ) {
6504 if ( PhylogenyMethods.getSpecies( b ).equals( "ECOLI" ) ) {
6507 final PhylogenyNode c = PhylogenyNode
6508 .createInstanceFromNhxString( "n10_RATAF12/1000-2000",
6509 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6510 if ( !c.getName().equals( "n10_RATAF12/1000-2000" ) ) {
6513 if ( PhylogenyMethods.getSpecies( c ).equals( "RATAF" ) ) {
6516 final PhylogenyNode c1 = PhylogenyNode
6517 .createInstanceFromNhxString( "n10_BOVIN_1/1000-2000",
6518 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6519 if ( !c1.getName().equals( "n10_BOVIN_1/1000-2000" ) ) {
6522 if ( PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
6525 final PhylogenyNode c2 = PhylogenyNode
6526 .createInstanceFromNhxString( "n10_Bovin_1/1000-2000",
6527 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6528 if ( !c2.getName().equals( "n10_Bovin_1/1000-2000" ) ) {
6531 if ( !PhylogenyMethods.getSpecies( c2 ).equals( "" ) ) {
6534 final PhylogenyNode d = PhylogenyNode
6535 .createInstanceFromNhxString( "n10_RAT1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6536 if ( !d.getName().equals( "n10_RAT1/1-2" ) ) {
6539 if ( PhylogenyMethods.getSpecies( d ).equals( "RAT" ) ) {
6542 final PhylogenyNode e = PhylogenyNode
6543 .createInstanceFromNhxString( "n10_RAT1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6544 if ( !e.getName().equals( "n10_RAT1" ) ) {
6547 if ( !ForesterUtil.isEmpty( PhylogenyMethods.getSpecies( e ) ) ) {
6550 final PhylogenyNode e2 = PhylogenyNode
6551 .createInstanceFromNhxString( "n10_RAT1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6552 if ( !e2.getName().equals( "n10_RAT1" ) ) {
6555 if ( PhylogenyMethods.getSpecies( e2 ).equals( "RAT" ) ) {
6558 final PhylogenyNode e3 = PhylogenyNode
6559 .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6560 if ( !e3.getName().equals( "n10_RAT~" ) ) {
6563 if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
6566 final PhylogenyNode n11 = PhylogenyNode
6567 .createInstanceFromNhxString( "n111111_ECOLI/jdj:0.4",
6568 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6569 if ( !n11.getName().equals( "n111111_ECOLI/jdj" ) ) {
6572 if ( n11.getDistanceToParent() != 0.4 ) {
6575 if ( PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
6578 final PhylogenyNode n12 = PhylogenyNode
6579 .createInstanceFromNhxString( "n111111-ECOLI---/jdj:0.4",
6580 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6581 if ( !n12.getName().equals( "n111111-ECOLI---/jdj" ) ) {
6584 if ( n12.getDistanceToParent() != 0.4 ) {
6587 if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
6590 final PhylogenyNode m = PhylogenyNode
6591 .createInstanceFromNhxString( "n10_MOUSEa", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6592 if ( !m.getName().equals( "n10_MOUSEa" ) ) {
6595 if ( PhylogenyMethods.getSpecies( m ).equals( "MOUSE" ) ) {
6598 final PhylogenyNode o = PhylogenyNode
6599 .createInstanceFromNhxString( "n10_MOUSE_", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6600 if ( !o.getName().equals( "n10_MOUSE_" ) ) {
6603 if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
6606 if ( n1.getName().compareTo( "" ) != 0 ) {
6609 if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
6612 if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6615 if ( n2.getName().compareTo( "" ) != 0 ) {
6618 if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
6621 if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6624 final PhylogenyNode n00 = PhylogenyNode
6625 .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
6626 if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
6629 if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
6632 final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
6633 if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
6636 final PhylogenyNode n13 = PhylogenyNode
6637 .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.AGRESSIVE );
6638 if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
6641 if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
6644 if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6647 if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6650 final PhylogenyNode n14 = PhylogenyNode
6651 .createInstanceFromNhxString( "blah_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6652 if ( !n14.getName().equals( "blah_9QX45/1-2" ) ) {
6655 if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
6658 final PhylogenyNode n15 = PhylogenyNode
6659 .createInstanceFromNhxString( "something_wicked[123]",
6660 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6661 if ( !n15.getName().equals( "something_wicked" ) ) {
6664 if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
6667 if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
6670 final PhylogenyNode n16 = PhylogenyNode
6671 .createInstanceFromNhxString( "something_wicked2[9]",
6672 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6673 if ( !n16.getName().equals( "something_wicked2" ) ) {
6676 if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
6679 if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
6682 final PhylogenyNode n17 = PhylogenyNode
6683 .createInstanceFromNhxString( "something_wicked3[a]",
6684 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6685 if ( !n17.getName().equals( "something_wicked3" ) ) {
6688 if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
6691 final PhylogenyNode n18 = PhylogenyNode
6692 .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6693 if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
6696 if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
6699 if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
6702 final PhylogenyNode n19 = PhylogenyNode
6703 .createInstanceFromNhxString( "blah_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6704 if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
6707 if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6710 final PhylogenyNode n30 = PhylogenyNode
6711 .createInstanceFromNhxString( "blah_1234567-roejojoej",
6712 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6713 if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
6716 if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6719 final PhylogenyNode n31 = PhylogenyNode
6720 .createInstanceFromNhxString( "blah_12345678-roejojoej",
6721 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6722 if ( n31.getNodeData().isHasTaxonomy() ) {
6725 final PhylogenyNode n32 = PhylogenyNode
6726 .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6727 if ( n32.getNodeData().isHasTaxonomy() ) {
6731 catch ( final Exception e ) {
6732 e.printStackTrace( System.out );
6738 private static boolean testNHXParsing() {
6740 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6741 final Phylogeny p1 = factory.create( "(A [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
6742 if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
6745 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]";
6746 final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
6747 if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6750 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]";
6751 final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
6752 if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
6755 final Phylogeny[] p3 = factory
6756 .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]",
6758 if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6761 final Phylogeny[] p4 = factory
6762 .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(]",
6764 if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6767 final Phylogeny[] p5 = factory
6768 .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(((]",
6770 if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6773 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)";
6774 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)";
6775 final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
6776 if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
6779 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)))";
6780 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)))";
6781 final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
6782 if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
6785 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]) ))[,,, ])))))))";
6786 final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
6787 final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
6788 if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
6791 final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
6792 if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
6795 final Phylogeny p10 = factory
6796 .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]",
6797 new NHXParser() )[ 0 ];
6798 if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
6802 catch ( final Exception e ) {
6803 e.printStackTrace( System.out );
6809 private static boolean testNHXParsingQuotes() {
6811 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6812 final NHXParser p = new NHXParser();
6813 final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
6814 if ( phylogenies_0.length != 5 ) {
6817 final Phylogeny phy = phylogenies_0[ 4 ];
6818 if ( phy.getNumberOfExternalNodes() != 7 ) {
6821 if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
6824 if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
6827 if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
6828 .getScientificName().equals( "hsapiens" ) ) {
6831 if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
6834 if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
6837 if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
6840 if ( phy.getNodes( "noquotes" ).size() != 1 ) {
6843 if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
6846 final NHXParser p1p = new NHXParser();
6847 p1p.setIgnoreQuotes( true );
6848 final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
6849 if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
6852 final NHXParser p2p = new NHXParser();
6853 p1p.setIgnoreQuotes( false );
6854 final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
6855 if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
6858 final NHXParser p3p = new NHXParser();
6859 p3p.setIgnoreQuotes( false );
6860 final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
6861 if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
6864 final NHXParser p4p = new NHXParser();
6865 p4p.setIgnoreQuotes( false );
6866 final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
6867 if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
6870 final Phylogeny p10 = factory
6871 .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]",
6872 new NHXParser() )[ 0 ];
6873 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]";
6874 if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
6877 final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
6878 if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
6882 final Phylogeny p12 = factory
6883 .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]",
6884 new NHXParser() )[ 0 ];
6885 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]";
6886 if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
6889 final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
6890 if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
6893 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;";
6894 if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
6897 final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
6898 if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
6902 catch ( final Exception e ) {
6903 e.printStackTrace( System.out );
6909 private static boolean testNHXParsingMB() {
6911 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6912 final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
6913 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6914 + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
6915 + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
6916 + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
6917 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6918 + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
6919 + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
6920 + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
6921 if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
6924 if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
6927 if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
6928 0.1100000000000000e+00 ) ) {
6931 if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
6934 if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
6937 final Phylogeny p2 = factory
6938 .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
6939 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6940 + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
6941 + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
6942 + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
6943 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6944 + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
6945 + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
6946 + "7.369400000000000e-02}])",
6947 new NHXParser() )[ 0 ];
6948 if ( p2.getNode( "1" ) == null ) {
6951 if ( p2.getNode( "2" ) == null ) {
6955 catch ( final Exception e ) {
6956 e.printStackTrace( System.out );
6963 private static boolean testPhylogenyBranch() {
6965 final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
6966 final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
6967 final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
6968 final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
6969 if ( !a1b1.equals( a1b1 ) ) {
6972 if ( !a1b1.equals( b1a1 ) ) {
6975 if ( !b1a1.equals( a1b1 ) ) {
6978 final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
6979 final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
6980 final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
6981 if ( a1_b1.equals( b1_a1 ) ) {
6984 if ( a1_b1.equals( a1_b1_ ) ) {
6987 final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
6988 if ( !a1_b1.equals( b1_a1_ ) ) {
6991 if ( a1_b1_.equals( b1_a1_ ) ) {
6994 if ( !a1_b1_.equals( b1_a1 ) ) {
6998 catch ( final Exception e ) {
6999 e.printStackTrace( System.out );
7005 private static boolean testPhyloXMLparsingOfDistributionElement() {
7007 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7008 PhyloXmlParser xml_parser = null;
7010 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
7012 catch ( final Exception e ) {
7013 // Do nothing -- means were not running from jar.
7015 if ( xml_parser == null ) {
7016 xml_parser = new PhyloXmlParser();
7017 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
7018 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
7021 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
7024 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
7026 if ( xml_parser.getErrorCount() > 0 ) {
7027 System.out.println( xml_parser.getErrorMessages().toString() );
7030 if ( phylogenies_0.length != 1 ) {
7033 final Phylogeny t1 = phylogenies_0[ 0 ];
7034 PhylogenyNode n = null;
7035 Distribution d = null;
7036 n = t1.getNode( "root node" );
7037 if ( !n.getNodeData().isHasDistribution() ) {
7040 if ( n.getNodeData().getDistributions().size() != 1 ) {
7043 d = n.getNodeData().getDistribution();
7044 if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
7047 if ( d.getPoints().size() != 1 ) {
7050 if ( d.getPolygons() != null ) {
7053 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
7056 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7059 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7062 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
7065 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
7068 n = t1.getNode( "node a" );
7069 if ( !n.getNodeData().isHasDistribution() ) {
7072 if ( n.getNodeData().getDistributions().size() != 2 ) {
7075 d = n.getNodeData().getDistribution( 1 );
7076 if ( !d.getDesc().equals( "San Diego" ) ) {
7079 if ( d.getPoints().size() != 1 ) {
7082 if ( d.getPolygons() != null ) {
7085 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
7088 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7091 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7094 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
7097 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
7100 n = t1.getNode( "node bb" );
7101 if ( !n.getNodeData().isHasDistribution() ) {
7104 if ( n.getNodeData().getDistributions().size() != 1 ) {
7107 d = n.getNodeData().getDistribution( 0 );
7108 if ( d.getPoints().size() != 3 ) {
7111 if ( d.getPolygons().size() != 2 ) {
7114 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
7117 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
7120 if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
7123 if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
7126 if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
7129 if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
7132 Polygon p = d.getPolygons().get( 0 );
7133 if ( p.getPoints().size() != 3 ) {
7136 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
7139 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
7142 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7145 if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
7148 if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
7151 if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
7154 p = d.getPolygons().get( 1 );
7155 if ( p.getPoints().size() != 3 ) {
7158 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
7161 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
7164 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7168 final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
7169 final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
7170 if ( rt.length != 1 ) {
7173 final Phylogeny t1_rt = rt[ 0 ];
7174 n = t1_rt.getNode( "root node" );
7175 if ( !n.getNodeData().isHasDistribution() ) {
7178 if ( n.getNodeData().getDistributions().size() != 1 ) {
7181 d = n.getNodeData().getDistribution();
7182 if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
7185 if ( d.getPoints().size() != 1 ) {
7188 if ( d.getPolygons() != null ) {
7191 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
7194 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7197 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7200 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
7203 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
7206 n = t1_rt.getNode( "node a" );
7207 if ( !n.getNodeData().isHasDistribution() ) {
7210 if ( n.getNodeData().getDistributions().size() != 2 ) {
7213 d = n.getNodeData().getDistribution( 1 );
7214 if ( !d.getDesc().equals( "San Diego" ) ) {
7217 if ( d.getPoints().size() != 1 ) {
7220 if ( d.getPolygons() != null ) {
7223 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
7226 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7229 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7232 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
7235 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
7238 n = t1_rt.getNode( "node bb" );
7239 if ( !n.getNodeData().isHasDistribution() ) {
7242 if ( n.getNodeData().getDistributions().size() != 1 ) {
7245 d = n.getNodeData().getDistribution( 0 );
7246 if ( d.getPoints().size() != 3 ) {
7249 if ( d.getPolygons().size() != 2 ) {
7252 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
7255 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
7258 if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
7261 if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
7264 if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
7267 if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
7270 p = d.getPolygons().get( 0 );
7271 if ( p.getPoints().size() != 3 ) {
7274 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
7277 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
7280 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7283 if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
7286 if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
7289 if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
7292 p = d.getPolygons().get( 1 );
7293 if ( p.getPoints().size() != 3 ) {
7296 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
7299 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
7302 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7306 catch ( final Exception e ) {
7307 e.printStackTrace( System.out );
7313 private static boolean testPostOrderIterator() {
7315 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7316 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
7317 PhylogenyNodeIterator it0;
7318 for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
7321 for( it0.reset(); it0.hasNext(); ) {
7324 final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
7325 final PhylogenyNodeIterator it = t1.iteratorPostorder();
7326 if ( !it.next().getName().equals( "A" ) ) {
7329 if ( !it.next().getName().equals( "B" ) ) {
7332 if ( !it.next().getName().equals( "ab" ) ) {
7335 if ( !it.next().getName().equals( "C" ) ) {
7338 if ( !it.next().getName().equals( "D" ) ) {
7341 if ( !it.next().getName().equals( "cd" ) ) {
7344 if ( !it.next().getName().equals( "abcd" ) ) {
7347 if ( !it.next().getName().equals( "E" ) ) {
7350 if ( !it.next().getName().equals( "F" ) ) {
7353 if ( !it.next().getName().equals( "ef" ) ) {
7356 if ( !it.next().getName().equals( "G" ) ) {
7359 if ( !it.next().getName().equals( "H" ) ) {
7362 if ( !it.next().getName().equals( "gh" ) ) {
7365 if ( !it.next().getName().equals( "efgh" ) ) {
7368 if ( !it.next().getName().equals( "r" ) ) {
7371 if ( it.hasNext() ) {
7375 catch ( final Exception e ) {
7376 e.printStackTrace( System.out );
7382 private static boolean testPreOrderIterator() {
7384 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7385 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
7386 PhylogenyNodeIterator it0;
7387 for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
7390 for( it0.reset(); it0.hasNext(); ) {
7393 PhylogenyNodeIterator it = t0.iteratorPreorder();
7394 if ( !it.next().getName().equals( "r" ) ) {
7397 if ( !it.next().getName().equals( "ab" ) ) {
7400 if ( !it.next().getName().equals( "A" ) ) {
7403 if ( !it.next().getName().equals( "B" ) ) {
7406 if ( !it.next().getName().equals( "cd" ) ) {
7409 if ( !it.next().getName().equals( "C" ) ) {
7412 if ( !it.next().getName().equals( "D" ) ) {
7415 if ( it.hasNext() ) {
7418 final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
7419 it = t1.iteratorPreorder();
7420 if ( !it.next().getName().equals( "r" ) ) {
7423 if ( !it.next().getName().equals( "abcd" ) ) {
7426 if ( !it.next().getName().equals( "ab" ) ) {
7429 if ( !it.next().getName().equals( "A" ) ) {
7432 if ( !it.next().getName().equals( "B" ) ) {
7435 if ( !it.next().getName().equals( "cd" ) ) {
7438 if ( !it.next().getName().equals( "C" ) ) {
7441 if ( !it.next().getName().equals( "D" ) ) {
7444 if ( !it.next().getName().equals( "efgh" ) ) {
7447 if ( !it.next().getName().equals( "ef" ) ) {
7450 if ( !it.next().getName().equals( "E" ) ) {
7453 if ( !it.next().getName().equals( "F" ) ) {
7456 if ( !it.next().getName().equals( "gh" ) ) {
7459 if ( !it.next().getName().equals( "G" ) ) {
7462 if ( !it.next().getName().equals( "H" ) ) {
7465 if ( it.hasNext() ) {
7469 catch ( final Exception e ) {
7470 e.printStackTrace( System.out );
7476 private static boolean testPropertiesMap() {
7478 final PropertiesMap pm = new PropertiesMap();
7479 final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
7480 final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
7481 final Property p2 = new Property( "something:else",
7483 "improbable:research",
7486 pm.addProperty( p0 );
7487 pm.addProperty( p1 );
7488 pm.addProperty( p2 );
7489 if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
7492 if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
7495 if ( pm.getProperties().size() != 3 ) {
7498 if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
7501 if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
7504 if ( pm.getProperties().size() != 3 ) {
7507 pm.removeProperty( "dimensions:diameter" );
7508 if ( pm.getProperties().size() != 2 ) {
7511 if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
7514 if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
7518 catch ( final Exception e ) {
7519 e.printStackTrace( System.out );
7525 private static boolean testReIdMethods() {
7527 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7528 final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
7529 final long count = PhylogenyNode.getNodeCount();
7531 if ( p.getNode( "r" ).getId() != count ) {
7534 if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
7537 if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
7540 if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
7543 if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
7546 if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
7549 if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
7552 if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
7555 if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
7558 if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
7561 if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
7564 if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
7567 if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
7570 if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
7573 if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
7577 catch ( final Exception e ) {
7578 e.printStackTrace( System.out );
7584 private static boolean testRerooting() {
7586 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7587 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",
7588 new NHXParser() )[ 0 ];
7589 if ( !t1.isRooted() ) {
7592 t1.reRoot( t1.getNode( "D" ) );
7593 t1.reRoot( t1.getNode( "CD" ) );
7594 t1.reRoot( t1.getNode( "A" ) );
7595 t1.reRoot( t1.getNode( "B" ) );
7596 t1.reRoot( t1.getNode( "AB" ) );
7597 t1.reRoot( t1.getNode( "D" ) );
7598 t1.reRoot( t1.getNode( "C" ) );
7599 t1.reRoot( t1.getNode( "CD" ) );
7600 t1.reRoot( t1.getNode( "A" ) );
7601 t1.reRoot( t1.getNode( "B" ) );
7602 t1.reRoot( t1.getNode( "AB" ) );
7603 t1.reRoot( t1.getNode( "D" ) );
7604 t1.reRoot( t1.getNode( "D" ) );
7605 t1.reRoot( t1.getNode( "C" ) );
7606 t1.reRoot( t1.getNode( "A" ) );
7607 t1.reRoot( t1.getNode( "B" ) );
7608 t1.reRoot( t1.getNode( "AB" ) );
7609 t1.reRoot( t1.getNode( "C" ) );
7610 t1.reRoot( t1.getNode( "D" ) );
7611 t1.reRoot( t1.getNode( "CD" ) );
7612 t1.reRoot( t1.getNode( "D" ) );
7613 t1.reRoot( t1.getNode( "A" ) );
7614 t1.reRoot( t1.getNode( "B" ) );
7615 t1.reRoot( t1.getNode( "AB" ) );
7616 t1.reRoot( t1.getNode( "C" ) );
7617 t1.reRoot( t1.getNode( "D" ) );
7618 t1.reRoot( t1.getNode( "CD" ) );
7619 t1.reRoot( t1.getNode( "D" ) );
7620 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
7623 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
7626 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
7629 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
7632 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
7635 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
7638 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",
7639 new NHXParser() )[ 0 ];
7640 t2.reRoot( t2.getNode( "A" ) );
7641 t2.reRoot( t2.getNode( "D" ) );
7642 t2.reRoot( t2.getNode( "ABC" ) );
7643 t2.reRoot( t2.getNode( "A" ) );
7644 t2.reRoot( t2.getNode( "B" ) );
7645 t2.reRoot( t2.getNode( "D" ) );
7646 t2.reRoot( t2.getNode( "C" ) );
7647 t2.reRoot( t2.getNode( "ABC" ) );
7648 t2.reRoot( t2.getNode( "A" ) );
7649 t2.reRoot( t2.getNode( "B" ) );
7650 t2.reRoot( t2.getNode( "AB" ) );
7651 t2.reRoot( t2.getNode( "AB" ) );
7652 t2.reRoot( t2.getNode( "D" ) );
7653 t2.reRoot( t2.getNode( "C" ) );
7654 t2.reRoot( t2.getNode( "B" ) );
7655 t2.reRoot( t2.getNode( "AB" ) );
7656 t2.reRoot( t2.getNode( "D" ) );
7657 t2.reRoot( t2.getNode( "D" ) );
7658 t2.reRoot( t2.getNode( "ABC" ) );
7659 t2.reRoot( t2.getNode( "A" ) );
7660 t2.reRoot( t2.getNode( "B" ) );
7661 t2.reRoot( t2.getNode( "AB" ) );
7662 t2.reRoot( t2.getNode( "D" ) );
7663 t2.reRoot( t2.getNode( "C" ) );
7664 t2.reRoot( t2.getNode( "ABC" ) );
7665 t2.reRoot( t2.getNode( "A" ) );
7666 t2.reRoot( t2.getNode( "B" ) );
7667 t2.reRoot( t2.getNode( "AB" ) );
7668 t2.reRoot( t2.getNode( "D" ) );
7669 t2.reRoot( t2.getNode( "D" ) );
7670 t2.reRoot( t2.getNode( "C" ) );
7671 t2.reRoot( t2.getNode( "A" ) );
7672 t2.reRoot( t2.getNode( "B" ) );
7673 t2.reRoot( t2.getNode( "AB" ) );
7674 t2.reRoot( t2.getNode( "C" ) );
7675 t2.reRoot( t2.getNode( "D" ) );
7676 t2.reRoot( t2.getNode( "ABC" ) );
7677 t2.reRoot( t2.getNode( "D" ) );
7678 t2.reRoot( t2.getNode( "A" ) );
7679 t2.reRoot( t2.getNode( "B" ) );
7680 t2.reRoot( t2.getNode( "AB" ) );
7681 t2.reRoot( t2.getNode( "C" ) );
7682 t2.reRoot( t2.getNode( "D" ) );
7683 t2.reRoot( t2.getNode( "ABC" ) );
7684 t2.reRoot( t2.getNode( "D" ) );
7685 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7688 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7691 t2.reRoot( t2.getNode( "ABC" ) );
7692 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7695 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7698 t2.reRoot( t2.getNode( "AB" ) );
7699 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7702 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7705 if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7708 t2.reRoot( t2.getNode( "AB" ) );
7709 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7712 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7715 if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7718 t2.reRoot( t2.getNode( "D" ) );
7719 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7722 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7725 t2.reRoot( t2.getNode( "ABC" ) );
7726 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7729 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7732 final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
7733 new NHXParser() )[ 0 ];
7734 t3.reRoot( t3.getNode( "B" ) );
7735 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7738 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7741 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7744 t3.reRoot( t3.getNode( "B" ) );
7745 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7748 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7751 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7754 t3.reRoot( t3.getRoot() );
7755 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7758 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7761 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7765 catch ( final Exception e ) {
7766 e.printStackTrace( System.out );
7772 private static boolean testSDIse() {
7774 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7775 final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
7776 final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
7777 gene1.setRooted( true );
7778 species1.setRooted( true );
7779 final SDI sdi = new SDI( gene1, species1 );
7780 if ( !gene1.getRoot().isDuplication() ) {
7783 final Phylogeny species2 = factory
7784 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7785 new NHXParser() )[ 0 ];
7786 final Phylogeny gene2 = factory
7787 .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7788 new NHXParser() )[ 0 ];
7789 species2.setRooted( true );
7790 gene2.setRooted( true );
7791 final SDI sdi2 = new SDI( gene2, species2 );
7792 if ( sdi2.getDuplicationsSum() != 0 ) {
7795 if ( !gene2.getNode( "ab" ).isSpeciation() ) {
7798 if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
7801 if ( !gene2.getNode( "abc" ).isSpeciation() ) {
7804 if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
7807 if ( !gene2.getNode( "r" ).isSpeciation() ) {
7810 if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
7813 final Phylogeny species3 = factory
7814 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7815 new NHXParser() )[ 0 ];
7816 final Phylogeny gene3 = factory
7817 .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7818 new NHXParser() )[ 0 ];
7819 species3.setRooted( true );
7820 gene3.setRooted( true );
7821 final SDI sdi3 = new SDI( gene3, species3 );
7822 if ( sdi3.getDuplicationsSum() != 1 ) {
7825 if ( !gene3.getNode( "aa" ).isDuplication() ) {
7828 if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
7831 final Phylogeny species4 = factory
7832 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7833 new NHXParser() )[ 0 ];
7834 final Phylogeny gene4 = factory
7835 .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7836 new NHXParser() )[ 0 ];
7837 species4.setRooted( true );
7838 gene4.setRooted( true );
7839 final SDI sdi4 = new SDI( gene4, species4 );
7840 if ( sdi4.getDuplicationsSum() != 1 ) {
7843 if ( !gene4.getNode( "ac" ).isSpeciation() ) {
7846 if ( !gene4.getNode( "abc" ).isDuplication() ) {
7849 if ( gene4.getNode( "abcd" ).isDuplication() ) {
7852 if ( species4.getNumberOfExternalNodes() != 6 ) {
7855 if ( gene4.getNumberOfExternalNodes() != 6 ) {
7858 final Phylogeny species5 = factory
7859 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7860 new NHXParser() )[ 0 ];
7861 final Phylogeny gene5 = factory
7862 .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7863 new NHXParser() )[ 0 ];
7864 species5.setRooted( true );
7865 gene5.setRooted( true );
7866 final SDI sdi5 = new SDI( gene5, species5 );
7867 if ( sdi5.getDuplicationsSum() != 2 ) {
7870 if ( !gene5.getNode( "ad" ).isSpeciation() ) {
7873 if ( !gene5.getNode( "adc" ).isDuplication() ) {
7876 if ( !gene5.getNode( "abcd" ).isDuplication() ) {
7879 if ( species5.getNumberOfExternalNodes() != 6 ) {
7882 if ( gene5.getNumberOfExternalNodes() != 6 ) {
7885 // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
7886 // Conjecture for Comparing Molecular Phylogenies"
7887 // J. of Comput Bio. Vol. 4, No 2, pp.177-187
7888 final Phylogeny species6 = factory
7889 .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,"
7890 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
7891 new NHXParser() )[ 0 ];
7892 final Phylogeny gene6 = factory
7893 .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,"
7894 + "((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,"
7895 + "(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;",
7896 new NHXParser() )[ 0 ];
7897 species6.setRooted( true );
7898 gene6.setRooted( true );
7899 final SDI sdi6 = new SDI( gene6, species6 );
7900 if ( sdi6.getDuplicationsSum() != 3 ) {
7903 if ( !gene6.getNode( "r" ).isDuplication() ) {
7906 if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
7909 if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
7912 if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
7915 if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
7918 if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
7921 if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
7924 if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
7927 sdi6.computeMappingCostL();
7928 if ( sdi6.computeMappingCostL() != 17 ) {
7931 if ( species6.getNumberOfExternalNodes() != 9 ) {
7934 if ( gene6.getNumberOfExternalNodes() != 9 ) {
7937 final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
7938 + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
7939 + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
7940 + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
7941 + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
7942 species7.setRooted( true );
7943 final Phylogeny gene7_1 = Test
7944 .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])" );
7945 gene7_1.setRooted( true );
7946 final SDI sdi7 = new SDI( gene7_1, species7 );
7947 if ( sdi7.getDuplicationsSum() != 0 ) {
7950 if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
7953 if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
7956 if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
7959 if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
7962 if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
7965 if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
7968 if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
7971 if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
7974 final Phylogeny gene7_2 = Test
7975 .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])" );
7976 gene7_2.setRooted( true );
7977 final SDI sdi7_2 = new SDI( gene7_2, species7 );
7978 if ( sdi7_2.getDuplicationsSum() != 1 ) {
7981 if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
7984 if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
7987 if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
7990 if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
7993 if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
7996 if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
7999 if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
8002 if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
8005 if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
8009 catch ( final Exception e ) {
8015 private static boolean testSDIunrooted() {
8017 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8018 final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
8019 final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
8020 final Iterator<PhylogenyBranch> iter = l.iterator();
8021 PhylogenyBranch br = iter.next();
8022 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
8025 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
8029 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
8032 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
8036 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
8039 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
8043 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8046 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8050 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8053 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8057 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
8060 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
8064 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8067 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8071 if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8074 if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8078 if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8081 if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8085 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8088 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8092 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
8095 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
8099 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
8102 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
8106 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
8109 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
8113 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
8116 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
8120 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
8123 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
8126 if ( iter.hasNext() ) {
8129 final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
8130 final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
8131 final Iterator<PhylogenyBranch> iter1 = l1.iterator();
8133 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
8136 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
8140 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8143 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8147 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8150 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8153 if ( iter1.hasNext() ) {
8156 final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
8157 final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
8158 final Iterator<PhylogenyBranch> iter2 = l2.iterator();
8160 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
8163 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
8167 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8170 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8174 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8177 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8180 if ( iter2.hasNext() ) {
8183 final Phylogeny species0 = factory
8184 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
8185 new NHXParser() )[ 0 ];
8186 final Phylogeny gene1 = factory
8187 .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])",
8188 new NHXParser() )[ 0 ];
8189 species0.setRooted( true );
8190 gene1.setRooted( true );
8191 final SDIR sdi_unrooted = new SDIR();
8192 sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
8193 if ( sdi_unrooted.getCount() != 1 ) {
8196 if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
8199 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
8202 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
8205 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8208 final Phylogeny gene2 = factory
8209 .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])",
8210 new NHXParser() )[ 0 ];
8211 gene2.setRooted( true );
8212 sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
8213 if ( sdi_unrooted.getCount() != 1 ) {
8216 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8219 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8222 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
8225 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8228 final Phylogeny species6 = factory
8229 .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,"
8230 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8231 new NHXParser() )[ 0 ];
8232 final Phylogeny gene6 = factory
8233 .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],"
8234 + "(((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],"
8235 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8236 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8237 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8238 new NHXParser() )[ 0 ];
8239 species6.setRooted( true );
8240 gene6.setRooted( true );
8241 Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
8242 if ( sdi_unrooted.getCount() != 1 ) {
8245 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8248 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8251 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8254 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8257 if ( !p6[ 0 ].getRoot().isDuplication() ) {
8260 if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8263 if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8266 if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
8269 if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8272 if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
8275 if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
8278 if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8282 final Phylogeny species7 = factory
8283 .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,"
8284 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8285 new NHXParser() )[ 0 ];
8286 final Phylogeny gene7 = factory
8287 .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],"
8288 + "(((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],"
8289 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8290 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8291 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8292 new NHXParser() )[ 0 ];
8293 species7.setRooted( true );
8294 gene7.setRooted( true );
8295 Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
8296 if ( sdi_unrooted.getCount() != 1 ) {
8299 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8302 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8305 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8308 if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
8311 if ( !p7[ 0 ].getRoot().isDuplication() ) {
8314 if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8317 if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8320 if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
8323 if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8326 if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
8329 if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
8332 if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8336 final Phylogeny species8 = factory
8337 .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,"
8338 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8339 new NHXParser() )[ 0 ];
8340 final Phylogeny gene8 = factory
8341 .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],"
8342 + "(((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],"
8343 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8344 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8345 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8346 new NHXParser() )[ 0 ];
8347 species8.setRooted( true );
8348 gene8.setRooted( true );
8349 Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
8350 if ( sdi_unrooted.getCount() != 1 ) {
8353 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8356 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8359 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8362 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8365 if ( !p8[ 0 ].getRoot().isDuplication() ) {
8368 if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8371 if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8374 if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
8377 if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8380 if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
8383 if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
8386 if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8391 catch ( final Exception e ) {
8392 e.printStackTrace( System.out );
8398 private static boolean testSplit() {
8400 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8401 final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
8402 //Archaeopteryx.createApplication( p0 );
8403 final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
8404 ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8405 ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8406 ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8407 ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8408 ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8409 ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8410 ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8411 ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8412 ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8413 final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
8414 // System.out.println( s0.toString() );
8416 Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
8417 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8418 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8419 if ( s0.match( query_nodes ) ) {
8422 query_nodes = new HashSet<PhylogenyNode>();
8423 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8424 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8425 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8426 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8427 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8428 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8429 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8430 if ( !s0.match( query_nodes ) ) {
8434 query_nodes = new HashSet<PhylogenyNode>();
8435 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8436 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8437 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8438 if ( !s0.match( query_nodes ) ) {
8442 query_nodes = new HashSet<PhylogenyNode>();
8443 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8444 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8445 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8446 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8447 if ( !s0.match( query_nodes ) ) {
8451 query_nodes = new HashSet<PhylogenyNode>();
8452 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8453 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8454 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8455 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8456 if ( !s0.match( query_nodes ) ) {
8460 query_nodes = new HashSet<PhylogenyNode>();
8461 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8462 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8463 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8464 if ( !s0.match( query_nodes ) ) {
8468 query_nodes = new HashSet<PhylogenyNode>();
8469 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8470 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
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( "D" ) );
8478 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8479 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8480 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8481 if ( !s0.match( query_nodes ) ) {
8485 query_nodes = new HashSet<PhylogenyNode>();
8486 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8487 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8488 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8489 if ( !s0.match( query_nodes ) ) {
8493 query_nodes = new HashSet<PhylogenyNode>();
8494 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8495 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8496 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8497 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8498 if ( !s0.match( query_nodes ) ) {
8502 query_nodes = new HashSet<PhylogenyNode>();
8503 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8504 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8505 if ( s0.match( query_nodes ) ) {
8509 query_nodes = new HashSet<PhylogenyNode>();
8510 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8511 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8512 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8513 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8514 if ( s0.match( query_nodes ) ) {
8518 query_nodes = new HashSet<PhylogenyNode>();
8519 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8520 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8521 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8522 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8523 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8524 if ( s0.match( query_nodes ) ) {
8528 query_nodes = new HashSet<PhylogenyNode>();
8529 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8530 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8531 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8532 if ( s0.match( query_nodes ) ) {
8536 query_nodes = new HashSet<PhylogenyNode>();
8537 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8538 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
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 if ( s0.match( query_nodes ) ) {
8550 query_nodes = new HashSet<PhylogenyNode>();
8551 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8552 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8553 if ( s0.match( query_nodes ) ) {
8557 query_nodes = new HashSet<PhylogenyNode>();
8558 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8559 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8560 if ( s0.match( query_nodes ) ) {
8564 query_nodes = new HashSet<PhylogenyNode>();
8565 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8566 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8567 if ( s0.match( query_nodes ) ) {
8571 query_nodes = new HashSet<PhylogenyNode>();
8572 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8573 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8574 if ( s0.match( query_nodes ) ) {
8578 query_nodes = new HashSet<PhylogenyNode>();
8579 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8580 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8581 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
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( "B" ) );
8589 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8590 if ( s0.match( query_nodes ) ) {
8594 query_nodes = new HashSet<PhylogenyNode>();
8595 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8596 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8597 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8598 if ( s0.match( query_nodes ) ) {
8602 query_nodes = new HashSet<PhylogenyNode>();
8603 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8604 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8605 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8606 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8607 if ( s0.match( query_nodes ) ) {
8611 // query_nodes = new HashSet<PhylogenyNode>();
8612 // query_nodes.add( new PhylogenyNode( "X" ) );
8613 // query_nodes.add( new PhylogenyNode( "Y" ) );
8614 // query_nodes.add( new PhylogenyNode( "A" ) );
8615 // query_nodes.add( new PhylogenyNode( "B" ) );
8616 // query_nodes.add( new PhylogenyNode( "C" ) );
8617 // query_nodes.add( new PhylogenyNode( "D" ) );
8618 // query_nodes.add( new PhylogenyNode( "E" ) );
8619 // query_nodes.add( new PhylogenyNode( "F" ) );
8620 // query_nodes.add( new PhylogenyNode( "G" ) );
8621 // if ( !s0.match( query_nodes ) ) {
8624 // query_nodes = new HashSet<PhylogenyNode>();
8625 // query_nodes.add( new PhylogenyNode( "X" ) );
8626 // query_nodes.add( new PhylogenyNode( "Y" ) );
8627 // query_nodes.add( new PhylogenyNode( "A" ) );
8628 // query_nodes.add( new PhylogenyNode( "B" ) );
8629 // query_nodes.add( new PhylogenyNode( "C" ) );
8630 // if ( !s0.match( query_nodes ) ) {
8634 // query_nodes = new HashSet<PhylogenyNode>();
8635 // query_nodes.add( new PhylogenyNode( "X" ) );
8636 // query_nodes.add( new PhylogenyNode( "Y" ) );
8637 // query_nodes.add( new PhylogenyNode( "D" ) );
8638 // query_nodes.add( new PhylogenyNode( "E" ) );
8639 // query_nodes.add( new PhylogenyNode( "F" ) );
8640 // query_nodes.add( new PhylogenyNode( "G" ) );
8641 // if ( !s0.match( query_nodes ) ) {
8645 // query_nodes = new HashSet<PhylogenyNode>();
8646 // query_nodes.add( new PhylogenyNode( "X" ) );
8647 // query_nodes.add( new PhylogenyNode( "Y" ) );
8648 // query_nodes.add( new PhylogenyNode( "A" ) );
8649 // query_nodes.add( new PhylogenyNode( "B" ) );
8650 // query_nodes.add( new PhylogenyNode( "C" ) );
8651 // query_nodes.add( new PhylogenyNode( "D" ) );
8652 // if ( !s0.match( query_nodes ) ) {
8656 // query_nodes = new HashSet<PhylogenyNode>();
8657 // query_nodes.add( new PhylogenyNode( "X" ) );
8658 // query_nodes.add( new PhylogenyNode( "Y" ) );
8659 // query_nodes.add( new PhylogenyNode( "E" ) );
8660 // query_nodes.add( new PhylogenyNode( "F" ) );
8661 // query_nodes.add( new PhylogenyNode( "G" ) );
8662 // if ( !s0.match( query_nodes ) ) {
8666 // query_nodes = new HashSet<PhylogenyNode>();
8667 // query_nodes.add( new PhylogenyNode( "X" ) );
8668 // query_nodes.add( new PhylogenyNode( "Y" ) );
8669 // query_nodes.add( new PhylogenyNode( "F" ) );
8670 // query_nodes.add( new PhylogenyNode( "G" ) );
8671 // if ( !s0.match( query_nodes ) ) {
8675 query_nodes = new HashSet<PhylogenyNode>();
8676 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8677 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8678 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8679 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8680 if ( s0.match( query_nodes ) ) {
8684 query_nodes = new HashSet<PhylogenyNode>();
8685 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8686 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8687 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8688 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8689 if ( s0.match( query_nodes ) ) {
8692 ///////////////////////////
8694 query_nodes = new HashSet<PhylogenyNode>();
8695 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8696 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8697 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8698 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8699 if ( s0.match( query_nodes ) ) {
8703 query_nodes = new HashSet<PhylogenyNode>();
8704 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8705 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8706 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8707 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8708 if ( s0.match( query_nodes ) ) {
8712 query_nodes = new HashSet<PhylogenyNode>();
8713 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8714 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8715 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8716 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8717 if ( s0.match( query_nodes ) ) {
8721 query_nodes = new HashSet<PhylogenyNode>();
8722 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8723 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8724 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8725 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8726 if ( s0.match( query_nodes ) ) {
8730 query_nodes = new HashSet<PhylogenyNode>();
8731 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8732 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8733 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8734 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8735 if ( s0.match( query_nodes ) ) {
8739 query_nodes = new HashSet<PhylogenyNode>();
8740 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8741 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8742 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8743 if ( s0.match( query_nodes ) ) {
8747 query_nodes = new HashSet<PhylogenyNode>();
8748 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8749 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8750 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8751 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8752 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8753 if ( s0.match( query_nodes ) ) {
8757 query_nodes = new HashSet<PhylogenyNode>();
8758 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8759 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8760 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8761 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8762 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8763 if ( s0.match( query_nodes ) ) {
8767 query_nodes = new HashSet<PhylogenyNode>();
8768 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8769 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8770 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8771 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8772 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8773 if ( s0.match( query_nodes ) ) {
8777 query_nodes = new HashSet<PhylogenyNode>();
8778 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8779 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8780 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8781 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8782 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8783 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8784 if ( s0.match( query_nodes ) ) {
8788 catch ( final Exception e ) {
8789 e.printStackTrace();
8795 private static boolean testSplitStrict() {
8797 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8798 final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
8799 final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
8800 ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8801 ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8802 ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8803 ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8804 ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8805 ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8806 ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8807 final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
8808 Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
8809 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8810 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8811 if ( s0.match( query_nodes ) ) {
8814 query_nodes = new HashSet<PhylogenyNode>();
8815 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8816 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8817 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8818 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8819 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8820 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8821 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8822 if ( !s0.match( query_nodes ) ) {
8826 query_nodes = new HashSet<PhylogenyNode>();
8827 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8828 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8829 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8830 if ( !s0.match( query_nodes ) ) {
8834 query_nodes = new HashSet<PhylogenyNode>();
8835 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8836 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8837 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8838 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8839 if ( !s0.match( query_nodes ) ) {
8843 query_nodes = new HashSet<PhylogenyNode>();
8844 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8845 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8846 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8847 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8848 if ( !s0.match( query_nodes ) ) {
8852 query_nodes = new HashSet<PhylogenyNode>();
8853 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8854 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8855 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8856 if ( !s0.match( query_nodes ) ) {
8860 query_nodes = new HashSet<PhylogenyNode>();
8861 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8862 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
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( "D" ) );
8870 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8871 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8872 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8873 if ( !s0.match( query_nodes ) ) {
8877 query_nodes = new HashSet<PhylogenyNode>();
8878 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8879 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8880 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8881 if ( !s0.match( query_nodes ) ) {
8885 query_nodes = new HashSet<PhylogenyNode>();
8886 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8887 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8888 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8889 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8890 if ( !s0.match( query_nodes ) ) {
8894 query_nodes = new HashSet<PhylogenyNode>();
8895 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8896 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8897 if ( s0.match( query_nodes ) ) {
8901 query_nodes = new HashSet<PhylogenyNode>();
8902 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8903 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8904 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8905 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8906 if ( s0.match( query_nodes ) ) {
8910 query_nodes = new HashSet<PhylogenyNode>();
8911 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8912 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8913 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8914 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8915 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8916 if ( s0.match( query_nodes ) ) {
8920 query_nodes = new HashSet<PhylogenyNode>();
8921 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8922 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8923 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8924 if ( s0.match( query_nodes ) ) {
8928 query_nodes = new HashSet<PhylogenyNode>();
8929 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8930 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
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 if ( s0.match( query_nodes ) ) {
8942 query_nodes = new HashSet<PhylogenyNode>();
8943 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8944 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8945 if ( s0.match( query_nodes ) ) {
8949 query_nodes = new HashSet<PhylogenyNode>();
8950 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8951 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8952 if ( s0.match( query_nodes ) ) {
8956 query_nodes = new HashSet<PhylogenyNode>();
8957 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8958 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8959 if ( s0.match( query_nodes ) ) {
8963 query_nodes = new HashSet<PhylogenyNode>();
8964 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8965 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8966 if ( s0.match( query_nodes ) ) {
8970 query_nodes = new HashSet<PhylogenyNode>();
8971 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8972 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8973 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
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( "B" ) );
8981 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8982 if ( s0.match( query_nodes ) ) {
8986 query_nodes = new HashSet<PhylogenyNode>();
8987 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8988 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8989 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8990 if ( s0.match( query_nodes ) ) {
8994 query_nodes = new HashSet<PhylogenyNode>();
8995 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8996 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8997 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8998 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8999 if ( s0.match( query_nodes ) ) {
9003 catch ( final Exception e ) {
9004 e.printStackTrace();
9010 private static boolean testSubtreeDeletion() {
9012 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9013 final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
9014 t1.deleteSubtree( t1.getNode( "A" ), false );
9015 if ( t1.getNumberOfExternalNodes() != 5 ) {
9018 t1.toNewHampshireX();
9019 t1.deleteSubtree( t1.getNode( "E" ), false );
9020 if ( t1.getNumberOfExternalNodes() != 4 ) {
9023 t1.toNewHampshireX();
9024 t1.deleteSubtree( t1.getNode( "F" ), false );
9025 if ( t1.getNumberOfExternalNodes() != 3 ) {
9028 t1.toNewHampshireX();
9029 t1.deleteSubtree( t1.getNode( "D" ), false );
9030 t1.toNewHampshireX();
9031 if ( t1.getNumberOfExternalNodes() != 3 ) {
9034 t1.deleteSubtree( t1.getNode( "def" ), false );
9035 t1.toNewHampshireX();
9036 if ( t1.getNumberOfExternalNodes() != 2 ) {
9039 t1.deleteSubtree( t1.getNode( "B" ), false );
9040 t1.toNewHampshireX();
9041 if ( t1.getNumberOfExternalNodes() != 1 ) {
9044 t1.deleteSubtree( t1.getNode( "C" ), false );
9045 t1.toNewHampshireX();
9046 if ( t1.getNumberOfExternalNodes() != 1 ) {
9049 t1.deleteSubtree( t1.getNode( "abc" ), false );
9050 t1.toNewHampshireX();
9051 if ( t1.getNumberOfExternalNodes() != 1 ) {
9054 t1.deleteSubtree( t1.getNode( "r" ), false );
9055 if ( t1.getNumberOfExternalNodes() != 0 ) {
9058 if ( !t1.isEmpty() ) {
9061 final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
9062 t2.deleteSubtree( t2.getNode( "A" ), false );
9063 t2.toNewHampshireX();
9064 if ( t2.getNumberOfExternalNodes() != 5 ) {
9067 t2.deleteSubtree( t2.getNode( "abc" ), false );
9068 t2.toNewHampshireX();
9069 if ( t2.getNumberOfExternalNodes() != 3 ) {
9072 t2.deleteSubtree( t2.getNode( "def" ), false );
9073 t2.toNewHampshireX();
9074 if ( t2.getNumberOfExternalNodes() != 1 ) {
9078 catch ( final Exception e ) {
9079 e.printStackTrace( System.out );
9085 private static boolean testSupportCount() {
9087 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9088 final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
9089 final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
9090 + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
9091 + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
9092 + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
9093 + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
9095 SupportCount.count( t0_1, phylogenies_1, true, false );
9096 final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
9097 final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
9098 + "(((((A,B),C),D),E),((F,G),X))"
9099 + "(((((A,Y),B),C),D),((F,G),E))"
9100 + "(((((A,B),C),D),E),(F,G))"
9101 + "(((((A,B),C),D),E),(F,G))"
9102 + "(((((A,B),C),D),E),(F,G))"
9103 + "(((((A,B),C),D),E),(F,G),Z)"
9104 + "(((((A,B),C),D),E),(F,G))"
9105 + "((((((A,B),C),D),E),F),G)"
9106 + "(((((X,Y),F,G),E),((A,B),C)),D)",
9108 SupportCount.count( t0_2, phylogenies_2, true, false );
9109 final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
9110 while ( it.hasNext() ) {
9111 final PhylogenyNode n = it.next();
9112 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
9116 final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
9117 final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
9118 + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
9119 SupportCount.count( t0_3, phylogenies_3, true, false );
9120 t0_3.reRoot( t0_3.getNode( "def" ).getId() );
9121 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
9124 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
9127 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
9130 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
9133 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
9136 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
9139 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
9142 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
9145 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
9148 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
9151 final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9152 final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
9153 + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
9154 SupportCount.count( t0_4, phylogenies_4, true, false );
9155 t0_4.reRoot( t0_4.getNode( "F" ).getId() );
9156 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
9159 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
9162 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
9165 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
9168 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
9171 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
9174 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
9177 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
9180 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
9183 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
9186 Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9187 final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9188 double d = SupportCount.compare( b1, a, true, true, true );
9189 if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
9192 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9193 final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9194 d = SupportCount.compare( b2, a, true, true, true );
9195 if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
9198 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9199 final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
9200 d = SupportCount.compare( b3, a, true, true, true );
9201 if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
9204 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
9205 final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
9206 d = SupportCount.compare( b4, a, true, true, false );
9207 if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
9211 catch ( final Exception e ) {
9212 e.printStackTrace( System.out );
9218 private static boolean testSupportTransfer() {
9220 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9221 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)",
9222 new NHXParser() )[ 0 ];
9223 final Phylogeny p2 = factory
9224 .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 ];
9225 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
9228 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
9231 support_transfer.moveBranchLengthsToBootstrap( p1 );
9232 support_transfer.transferSupportValues( p1, p2 );
9233 if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
9236 if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
9239 if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
9242 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
9245 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
9248 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
9251 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
9254 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
9258 catch ( final Exception e ) {
9259 e.printStackTrace( System.out );
9265 private static boolean testUniprotTaxonomySearch() {
9267 List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
9269 if ( results.size() != 1 ) {
9272 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9275 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9278 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9281 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9284 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9288 results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
9289 if ( results.size() != 1 ) {
9292 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9295 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9298 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9301 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9304 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9308 results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
9309 if ( results.size() != 1 ) {
9312 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9315 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9318 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9321 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9324 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9328 results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
9329 if ( results.size() != 1 ) {
9332 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9335 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9338 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9341 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9344 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9347 if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
9350 if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
9353 if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
9354 .equals( "Nematostella vectensis" ) ) {
9355 System.out.println( results.get( 0 ).getLineage() );
9359 catch ( final IOException e ) {
9360 System.out.println();
9361 System.out.println( "the following might be due to absence internet connection:" );
9362 e.printStackTrace( System.out );
9365 catch ( final Exception e ) {
9371 private static boolean testEmblEntryRetrieval() {
9372 //The format for GenBank Accession numbers are:
9373 //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
9374 //Protein: 3 letters + 5 numerals
9375 //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
9376 if ( !SequenceIdParser.parseGenbankAccessor( "AY423861" ).equals( "AY423861" ) ) {
9379 if ( !SequenceIdParser.parseGenbankAccessor( ".AY423861." ).equals( "AY423861" ) ) {
9382 if ( SequenceIdParser.parseGenbankAccessor( "AAY423861" ) != null ) {
9385 if ( SequenceIdParser.parseGenbankAccessor( "AY4238612" ) != null ) {
9388 if ( SequenceIdParser.parseGenbankAccessor( "AAY4238612" ) != null ) {
9391 if ( SequenceIdParser.parseGenbankAccessor( "Y423861" ) != null ) {
9394 if ( !SequenceIdParser.parseGenbankAccessor( "S12345" ).equals( "S12345" ) ) {
9397 if ( !SequenceIdParser.parseGenbankAccessor( "|S12345|" ).equals( "S12345" ) ) {
9400 if ( SequenceIdParser.parseGenbankAccessor( "|S123456" ) != null ) {
9403 if ( SequenceIdParser.parseGenbankAccessor( "ABC123456" ) != null ) {
9406 if ( !SequenceIdParser.parseGenbankAccessor( "ABC12345" ).equals( "ABC12345" ) ) {
9409 if ( !SequenceIdParser.parseGenbankAccessor( "&ABC12345&" ).equals( "ABC12345" ) ) {
9412 if ( SequenceIdParser.parseGenbankAccessor( "ABCD12345" ) != null ) {
9418 private static boolean testUniprotEntryRetrieval() {
9419 if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345" ).equals( "P12345" ) ) {
9422 if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345" ) != null ) {
9425 if ( SequenceDbWsTools.parseUniProtAccessor( "3 4P12345" ) != null ) {
9428 if ( SequenceDbWsTools.parseUniProtAccessor( "P12345E" ) != null ) {
9431 if ( SequenceDbWsTools.parseUniProtAccessor( "P123455" ) != null ) {
9434 if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345E" ) != null ) {
9437 if ( SequenceDbWsTools.parseUniProtAccessor( "AY423861" ) != null ) {
9440 if ( !SequenceDbWsTools.parseUniProtAccessor( "P1DDD5" ).equals( "P1DDD5" ) ) {
9443 if ( SequenceDbWsTools.parseUniProtAccessor( "P1DDDD" ) != null ) {
9446 if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345/12-42" ).equals( "P12345" ) ) {
9449 if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X P12345 12-42" ).equals( "P12345" ) ) {
9452 if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345/12-42" ).equals( "P12345" ) ) {
9455 if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345" ).equals( "P12345" ) ) {
9459 final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
9460 if ( !entry.getAccession().equals( "P12345" ) ) {
9463 if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
9466 if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
9469 if ( !entry.getSequenceSymbol().equals( "GOT2" ) ) {
9472 if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
9476 catch ( final IOException e ) {
9477 System.out.println();
9478 System.out.println( "the following might be due to absence internet connection:" );
9479 e.printStackTrace( System.out );
9482 catch ( final Exception e ) {
9488 private static boolean testWabiTxSearch() {
9491 result = TxSearch.searchSimple( "nematostella" );
9492 result = TxSearch.getTxId( "nematostella" );
9493 if ( !result.equals( "45350" ) ) {
9496 result = TxSearch.getTxName( "45350" );
9497 if ( !result.equals( "Nematostella" ) ) {
9500 result = TxSearch.getTxId( "nematostella vectensis" );
9501 if ( !result.equals( "45351" ) ) {
9504 result = TxSearch.getTxName( "45351" );
9505 if ( !result.equals( "Nematostella vectensis" ) ) {
9508 result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
9509 if ( !result.equals( "536089" ) ) {
9512 result = TxSearch.getTxName( "536089" );
9513 if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
9516 final List<String> queries = new ArrayList<String>();
9517 queries.add( "Campylobacter coli" );
9518 queries.add( "Escherichia coli" );
9519 queries.add( "Arabidopsis" );
9520 queries.add( "Trichoplax" );
9521 queries.add( "Samanea saman" );
9522 queries.add( "Kluyveromyces marxianus" );
9523 queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
9524 queries.add( "Bornavirus parrot/PDD/2008" );
9525 final List<RANKS> ranks = new ArrayList<RANKS>();
9526 ranks.add( RANKS.SUPERKINGDOM );
9527 ranks.add( RANKS.KINGDOM );
9528 ranks.add( RANKS.FAMILY );
9529 ranks.add( RANKS.GENUS );
9530 ranks.add( RANKS.TRIBE );
9531 result = TxSearch.searchLineage( queries, ranks );
9532 result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
9533 result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
9535 catch ( final Exception e ) {
9536 System.out.println();
9537 System.out.println( "the following might be due to absence internet connection:" );
9538 e.printStackTrace( System.out );
9544 private static boolean testAminoAcidSequence() {
9546 final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
9547 if ( aa1.getLength() != 13 ) {
9550 if ( aa1.getResidueAt( 0 ) != 'A' ) {
9553 if ( aa1.getResidueAt( 2 ) != 'K' ) {
9556 if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
9559 final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
9560 if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
9563 final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
9564 if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
9567 final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
9568 if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
9572 catch ( final Exception e ) {
9573 e.printStackTrace();
9579 private static boolean testCreateBalancedPhylogeny() {
9581 final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
9582 if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
9585 if ( p0.getNumberOfExternalNodes() != 15625 ) {
9588 final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
9589 if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
9592 if ( p1.getNumberOfExternalNodes() != 100 ) {
9596 catch ( final Exception e ) {
9597 e.printStackTrace();
9603 private static boolean testFastaParser() {
9605 if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
9608 if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
9611 final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
9612 if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
9615 if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
9618 if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
9621 if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
9624 if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
9627 if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
9631 catch ( final Exception e ) {
9632 e.printStackTrace();
9638 private static boolean testGeneralMsaParser() {
9640 final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
9641 final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
9642 final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
9643 final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
9644 final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
9645 final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
9646 final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
9647 final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
9648 if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9651 if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9654 if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9657 if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9660 if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9663 if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9666 if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9669 if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9672 if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9675 if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9678 if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9681 if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9684 final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
9685 if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
9688 if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
9691 if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
9694 final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
9695 if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
9698 if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
9701 if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
9704 final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
9705 if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
9708 if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
9711 if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
9715 catch ( final Exception e ) {
9716 e.printStackTrace();
9722 private static boolean testMafft( final String path ) {
9724 final List<String> opts = new ArrayList<String>();
9725 opts.add( "--maxiterate" );
9727 opts.add( "--localpair" );
9728 opts.add( "--quiet" );
9730 final MsaInferrer mafft = Mafft.createInstance( path );
9731 msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
9732 if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
9735 if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
9739 catch ( final Exception e ) {
9740 e.printStackTrace( System.out );
9746 private static boolean testNextNodeWithCollapsing() {
9748 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9750 List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
9751 final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9752 final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
9753 t0.getNode( "cd" ).setCollapse( true );
9754 t0.getNode( "cde" ).setCollapse( true );
9755 n = t0.getFirstExternalNode();
9756 while ( n != null ) {
9758 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9760 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
9763 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
9766 if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
9769 if ( !ext.get( 3 ).getName().equals( "f" ) ) {
9772 if ( !ext.get( 4 ).getName().equals( "g" ) ) {
9775 if ( !ext.get( 5 ).getName().equals( "h" ) ) {
9779 final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9780 final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
9781 t1.getNode( "ab" ).setCollapse( true );
9782 t1.getNode( "cd" ).setCollapse( true );
9783 t1.getNode( "cde" ).setCollapse( true );
9784 n = t1.getNode( "ab" );
9785 ext = new ArrayList<PhylogenyNode>();
9786 while ( n != null ) {
9788 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9790 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9793 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9796 if ( !ext.get( 2 ).getName().equals( "f" ) ) {
9799 if ( !ext.get( 3 ).getName().equals( "g" ) ) {
9802 if ( !ext.get( 4 ).getName().equals( "h" ) ) {
9808 final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9809 final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
9810 t2.getNode( "ab" ).setCollapse( true );
9811 t2.getNode( "cd" ).setCollapse( true );
9812 t2.getNode( "cde" ).setCollapse( true );
9813 t2.getNode( "c" ).setCollapse( true );
9814 t2.getNode( "d" ).setCollapse( true );
9815 t2.getNode( "e" ).setCollapse( true );
9816 t2.getNode( "gh" ).setCollapse( true );
9817 n = t2.getNode( "ab" );
9818 ext = new ArrayList<PhylogenyNode>();
9819 while ( n != null ) {
9821 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9823 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9826 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9829 if ( !ext.get( 2 ).getName().equals( "f" ) ) {
9832 if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
9838 final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9839 final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
9840 t3.getNode( "ab" ).setCollapse( true );
9841 t3.getNode( "cd" ).setCollapse( true );
9842 t3.getNode( "cde" ).setCollapse( true );
9843 t3.getNode( "c" ).setCollapse( true );
9844 t3.getNode( "d" ).setCollapse( true );
9845 t3.getNode( "e" ).setCollapse( true );
9846 t3.getNode( "gh" ).setCollapse( true );
9847 t3.getNode( "fgh" ).setCollapse( true );
9848 n = t3.getNode( "ab" );
9849 ext = new ArrayList<PhylogenyNode>();
9850 while ( n != null ) {
9852 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9854 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9857 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9860 if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
9866 final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9867 final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
9868 t4.getNode( "ab" ).setCollapse( true );
9869 t4.getNode( "cd" ).setCollapse( true );
9870 t4.getNode( "cde" ).setCollapse( true );
9871 t4.getNode( "c" ).setCollapse( true );
9872 t4.getNode( "d" ).setCollapse( true );
9873 t4.getNode( "e" ).setCollapse( true );
9874 t4.getNode( "gh" ).setCollapse( true );
9875 t4.getNode( "fgh" ).setCollapse( true );
9876 t4.getNode( "abcdefgh" ).setCollapse( true );
9877 n = t4.getNode( "abcdefgh" );
9878 if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
9883 final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9884 final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
9886 n = t5.getFirstExternalNode();
9887 while ( n != null ) {
9889 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9891 if ( ext.size() != 8 ) {
9894 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
9897 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
9900 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
9903 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
9906 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
9909 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
9912 if ( !ext.get( 6 ).getName().equals( "g" ) ) {
9915 if ( !ext.get( 7 ).getName().equals( "h" ) ) {
9920 final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9921 final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
9923 t6.getNode( "ab" ).setCollapse( true );
9924 n = t6.getNode( "ab" );
9925 while ( n != null ) {
9927 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9929 if ( ext.size() != 7 ) {
9932 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9935 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
9938 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
9941 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
9944 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
9947 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
9950 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
9955 final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9956 final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
9958 t7.getNode( "cd" ).setCollapse( true );
9959 n = t7.getNode( "a" );
9960 while ( n != null ) {
9962 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9964 if ( ext.size() != 7 ) {
9967 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
9970 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
9973 if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
9976 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
9979 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
9982 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
9985 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
9990 final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9991 final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
9993 t8.getNode( "cd" ).setCollapse( true );
9994 t8.getNode( "c" ).setCollapse( true );
9995 t8.getNode( "d" ).setCollapse( true );
9996 n = t8.getNode( "a" );
9997 while ( n != null ) {
9999 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10001 if ( ext.size() != 7 ) {
10004 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10007 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10010 if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
10011 System.out.println( "2 fail" );
10014 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10017 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
10020 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
10023 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
10028 final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10029 final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
10031 t9.getNode( "gh" ).setCollapse( true );
10032 n = t9.getNode( "a" );
10033 while ( n != null ) {
10035 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10037 if ( ext.size() != 7 ) {
10040 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10043 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10046 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10049 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10052 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10055 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
10058 if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
10063 final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10064 final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
10066 t10.getNode( "gh" ).setCollapse( true );
10067 t10.getNode( "g" ).setCollapse( true );
10068 t10.getNode( "h" ).setCollapse( true );
10069 n = t10.getNode( "a" );
10070 while ( n != null ) {
10072 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10074 if ( ext.size() != 7 ) {
10077 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10080 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10083 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10086 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10089 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10092 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
10095 if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
10100 final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10101 final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
10103 t11.getNode( "gh" ).setCollapse( true );
10104 t11.getNode( "fgh" ).setCollapse( true );
10105 n = t11.getNode( "a" );
10106 while ( n != null ) {
10108 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10110 if ( ext.size() != 6 ) {
10113 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10116 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10119 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10122 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10125 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10128 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10133 final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10134 final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
10136 t12.getNode( "gh" ).setCollapse( true );
10137 t12.getNode( "fgh" ).setCollapse( true );
10138 t12.getNode( "g" ).setCollapse( true );
10139 t12.getNode( "h" ).setCollapse( true );
10140 t12.getNode( "f" ).setCollapse( true );
10141 n = t12.getNode( "a" );
10142 while ( n != null ) {
10144 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10146 if ( ext.size() != 6 ) {
10149 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10152 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10155 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10158 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10161 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10164 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10169 final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10170 final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
10172 t13.getNode( "ab" ).setCollapse( true );
10173 t13.getNode( "b" ).setCollapse( true );
10174 t13.getNode( "fgh" ).setCollapse( true );
10175 t13.getNode( "gh" ).setCollapse( true );
10176 n = t13.getNode( "ab" );
10177 while ( n != null ) {
10179 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10181 if ( ext.size() != 5 ) {
10184 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10187 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10190 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10193 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10196 if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
10201 final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
10202 final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
10204 t14.getNode( "ab" ).setCollapse( true );
10205 t14.getNode( "a" ).setCollapse( true );
10206 t14.getNode( "fgh" ).setCollapse( true );
10207 t14.getNode( "gh" ).setCollapse( true );
10208 n = t14.getNode( "ab" );
10209 while ( n != null ) {
10211 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10213 if ( ext.size() != 5 ) {
10216 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10219 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10222 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10225 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10228 if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
10233 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" );
10234 final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
10236 t15.getNode( "ab" ).setCollapse( true );
10237 t15.getNode( "a" ).setCollapse( true );
10238 t15.getNode( "fgh" ).setCollapse( true );
10239 t15.getNode( "gh" ).setCollapse( true );
10240 n = t15.getNode( "ab" );
10241 while ( n != null ) {
10243 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10245 if ( ext.size() != 6 ) {
10248 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10251 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10254 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10257 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10260 if ( !ext.get( 4 ).getName().equals( "x" ) ) {
10263 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10268 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" );
10269 final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
10271 t16.getNode( "ab" ).setCollapse( true );
10272 t16.getNode( "a" ).setCollapse( true );
10273 t16.getNode( "fgh" ).setCollapse( true );
10274 t16.getNode( "gh" ).setCollapse( true );
10275 t16.getNode( "cd" ).setCollapse( true );
10276 t16.getNode( "cde" ).setCollapse( true );
10277 t16.getNode( "d" ).setCollapse( true );
10278 t16.getNode( "x" ).setCollapse( true );
10279 n = t16.getNode( "ab" );
10280 while ( n != null ) {
10282 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10284 if ( ext.size() != 4 ) {
10287 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10290 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
10293 if ( !ext.get( 2 ).getName().equals( "x" ) ) {
10296 if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
10300 catch ( final Exception e ) {
10301 e.printStackTrace( System.out );
10307 private static boolean testMsaQualityMethod() {
10309 final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
10310 final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
10311 final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
10312 final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
10313 final List<Sequence> l = new ArrayList<Sequence>();
10318 final Msa msa = BasicMsa.createInstance( l );
10319 if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
10322 if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
10325 if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
10328 if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
10332 catch ( final Exception e ) {
10333 e.printStackTrace( System.out );
10339 private static boolean testSequenceIdParsing() {
10341 Identifier id = SequenceIdParser.parse( "gb_ADF31344_segmented_worms_" );
10342 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10343 || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
10344 if ( id != null ) {
10345 System.out.println( "value =" + id.getValue() );
10346 System.out.println( "provider=" + id.getProvider() );
10351 id = SequenceIdParser.parse( "segmented worms|gb_ADF31344" );
10352 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10353 || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
10354 if ( id != null ) {
10355 System.out.println( "value =" + id.getValue() );
10356 System.out.println( "provider=" + id.getProvider() );
10361 id = SequenceIdParser.parse( "segmented worms gb_ADF31344 and more" );
10362 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10363 || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
10364 if ( id != null ) {
10365 System.out.println( "value =" + id.getValue() );
10366 System.out.println( "provider=" + id.getProvider() );
10371 id = SequenceIdParser.parse( "gb_AAA96518_1" );
10372 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10373 || !id.getValue().equals( "AAA96518" ) || !id.getProvider().equals( "ncbi" ) ) {
10374 if ( id != null ) {
10375 System.out.println( "value =" + id.getValue() );
10376 System.out.println( "provider=" + id.getProvider() );
10381 id = SequenceIdParser.parse( "gb_EHB07727_1_rodents_" );
10382 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10383 || !id.getValue().equals( "EHB07727" ) || !id.getProvider().equals( "ncbi" ) ) {
10384 if ( id != null ) {
10385 System.out.println( "value =" + id.getValue() );
10386 System.out.println( "provider=" + id.getProvider() );
10391 id = SequenceIdParser.parse( "dbj_BAF37827_1_turtles_" );
10392 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10393 || !id.getValue().equals( "BAF37827" ) || !id.getProvider().equals( "ncbi" ) ) {
10394 if ( id != null ) {
10395 System.out.println( "value =" + id.getValue() );
10396 System.out.println( "provider=" + id.getProvider() );
10401 id = SequenceIdParser.parse( "emb_CAA73223_1_primates_" );
10402 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10403 || !id.getValue().equals( "CAA73223" ) || !id.getProvider().equals( "ncbi" ) ) {
10404 if ( id != null ) {
10405 System.out.println( "value =" + id.getValue() );
10406 System.out.println( "provider=" + id.getProvider() );
10411 id = SequenceIdParser.parse( "mites|ref_XP_002434188_1" );
10412 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10413 || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
10414 if ( id != null ) {
10415 System.out.println( "value =" + id.getValue() );
10416 System.out.println( "provider=" + id.getProvider() );
10421 id = SequenceIdParser.parse( "mites_ref_XP_002434188_1_bla_XP_12345" );
10422 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10423 || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
10424 if ( id != null ) {
10425 System.out.println( "value =" + id.getValue() );
10426 System.out.println( "provider=" + id.getProvider() );
10431 id = SequenceIdParser.parse( "P4A123" );
10432 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10433 || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
10434 if ( id != null ) {
10435 System.out.println( "value =" + id.getValue() );
10436 System.out.println( "provider=" + id.getProvider() );
10441 id = SequenceIdParser.parse( "pllf[pok P4A123_osdjfosnqo035-9233332904i000490 vf tmv x45" );
10442 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10443 || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
10444 if ( id != null ) {
10445 System.out.println( "value =" + id.getValue() );
10446 System.out.println( "provider=" + id.getProvider() );
10451 id = SequenceIdParser.parse( "XP_12345" );
10452 if ( id != null ) {
10453 System.out.println( "value =" + id.getValue() );
10454 System.out.println( "provider=" + id.getProvider() );
10457 // lcl_91970_unknown_
10459 catch ( final Exception e ) {
10460 e.printStackTrace( System.out );