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" ) ) {
1026 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
1030 n.setName( "B0LM41_HUMAN" );
1031 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
1032 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
1036 n.setName( "NP_001025424" );
1037 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
1038 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
1042 n.setName( "_NM_001030253-" );
1043 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
1044 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
1048 n.setName( "NP_001025424" );
1049 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
1050 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
1055 catch ( final Exception e ) {
1056 e.printStackTrace( System.out );
1062 private static boolean testExtractTaxonomyCodeFromNodeName() {
1064 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1065 .equals( "MOUSE" ) ) {
1068 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1069 .equals( "RAT" ) ) {
1072 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1075 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
1076 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1077 .equals( "MOUSE" ) ) {
1080 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE_function = 23445",
1081 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1082 .equals( "MOUSE" ) ) {
1085 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
1086 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1087 .equals( "MOUSE" ) ) {
1090 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
1091 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1094 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
1095 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1098 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
1099 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1102 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT_function = 23445",
1103 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1106 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
1107 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1110 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
1111 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1114 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
1115 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1118 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1119 .equals( "RAT" ) ) {
1122 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
1123 .equals( "PIG" ) ) {
1127 .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1128 .equals( "MOUSE" ) ) {
1131 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
1132 .equals( "MOUSE" ) ) {
1135 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE_", TAXONOMY_EXTRACTION.AGRESSIVE )
1136 .equals( "MOUSE" ) ) {
1139 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE_", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1140 .equals( "MOUSE" ) ) {
1143 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE_", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ) != null ) {
1146 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "x_MOUSE_x", TAXONOMY_EXTRACTION.AGRESSIVE )
1147 .equals( "MOUSE" ) ) {
1151 catch ( final Exception e ) {
1152 e.printStackTrace( System.out );
1158 private static boolean testBasicNodeMethods() {
1160 if ( PhylogenyNode.getNodeCount() != 0 ) {
1163 final PhylogenyNode n1 = new PhylogenyNode();
1164 final PhylogenyNode n2 = PhylogenyNode
1165 .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1166 final PhylogenyNode n3 = PhylogenyNode
1167 .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1168 final PhylogenyNode n4 = PhylogenyNode
1169 .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1170 if ( n1.isHasAssignedEvent() ) {
1173 if ( PhylogenyNode.getNodeCount() != 4 ) {
1176 if ( n3.getIndicator() != 0 ) {
1179 if ( n3.getNumberOfExternalNodes() != 1 ) {
1182 if ( !n3.isExternal() ) {
1185 if ( !n3.isRoot() ) {
1188 if ( !n4.getName().equals( "n4" ) ) {
1192 catch ( final Exception e ) {
1193 e.printStackTrace( System.out );
1199 private static boolean testBasicPhyloXMLparsing() {
1201 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1202 final PhyloXmlParser xml_parser = new PhyloXmlParser();
1203 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1205 if ( xml_parser.getErrorCount() > 0 ) {
1206 System.out.println( xml_parser.getErrorMessages().toString() );
1209 if ( phylogenies_0.length != 4 ) {
1212 final Phylogeny t1 = phylogenies_0[ 0 ];
1213 final Phylogeny t2 = phylogenies_0[ 1 ];
1214 final Phylogeny t3 = phylogenies_0[ 2 ];
1215 final Phylogeny t4 = phylogenies_0[ 3 ];
1216 if ( t1.getNumberOfExternalNodes() != 1 ) {
1219 if ( !t1.isRooted() ) {
1222 if ( t1.isRerootable() ) {
1225 if ( !t1.getType().equals( "gene_tree" ) ) {
1228 if ( t2.getNumberOfExternalNodes() != 2 ) {
1231 if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1234 if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1237 if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1240 if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1243 if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1246 if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1249 if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1250 .startsWith( "actgtgggggt" ) ) {
1253 if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1254 .startsWith( "ctgtgatgcat" ) ) {
1257 if ( t3.getNumberOfExternalNodes() != 4 ) {
1260 if ( !t1.getName().equals( "t1" ) ) {
1263 if ( !t2.getName().equals( "t2" ) ) {
1266 if ( !t3.getName().equals( "t3" ) ) {
1269 if ( !t4.getName().equals( "t4" ) ) {
1272 if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1275 if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1278 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1281 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1282 .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1285 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1288 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1291 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1294 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1295 .equals( "apoptosis" ) ) {
1298 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1299 .equals( "GO:0006915" ) ) {
1302 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1303 .equals( "UniProtKB" ) ) {
1306 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1307 .equals( "experimental" ) ) {
1310 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1311 .equals( "function" ) ) {
1314 if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1315 .getValue() != 1 ) {
1318 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1319 .getType().equals( "ml" ) ) {
1322 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1323 .equals( "apoptosis" ) ) {
1326 if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1327 .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1330 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1331 .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1334 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1335 .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1338 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1339 .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1342 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1343 .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1346 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1347 .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1350 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1351 .equals( "GO:0005829" ) ) {
1354 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1355 .equals( "intracellular organelle" ) ) {
1358 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1361 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1362 .equals( "UniProt link" ) ) ) {
1365 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1369 catch ( final Exception e ) {
1370 e.printStackTrace( System.out );
1376 private static boolean testBasicPhyloXMLparsingRoundtrip() {
1378 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1379 final PhyloXmlParser xml_parser = new PhyloXmlParser();
1380 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1381 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1384 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1386 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1388 if ( xml_parser.getErrorCount() > 0 ) {
1389 System.out.println( xml_parser.getErrorMessages().toString() );
1392 if ( phylogenies_0.length != 4 ) {
1395 final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1396 final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1397 if ( phylogenies_t1.length != 1 ) {
1400 final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1401 if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1404 if ( !t1_rt.isRooted() ) {
1407 if ( t1_rt.isRerootable() ) {
1410 if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1413 final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1414 final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1415 final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1416 if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1419 if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1422 if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1425 if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1428 if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1429 .startsWith( "actgtgggggt" ) ) {
1432 if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1433 .startsWith( "ctgtgatgcat" ) ) {
1436 final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1437 final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1438 final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1439 final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1440 if ( phylogenies_1.length != 1 ) {
1443 final Phylogeny t3_rt = phylogenies_1[ 0 ];
1444 if ( !t3_rt.getName().equals( "t3" ) ) {
1447 if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1450 if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1453 if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1456 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1459 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1460 .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1463 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1466 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1469 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1470 .equals( "UniProtKB" ) ) {
1473 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1474 .equals( "apoptosis" ) ) {
1477 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1478 .equals( "GO:0006915" ) ) {
1481 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1482 .equals( "UniProtKB" ) ) {
1485 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1486 .equals( "experimental" ) ) {
1489 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1490 .equals( "function" ) ) {
1493 if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1494 .getValue() != 1 ) {
1497 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1498 .getType().equals( "ml" ) ) {
1501 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1502 .equals( "apoptosis" ) ) {
1505 if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1506 .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1509 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1510 .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1513 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1514 .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1517 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1518 .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1521 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1522 .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1525 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1526 .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1529 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1530 .equals( "GO:0005829" ) ) {
1533 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1534 .equals( "intracellular organelle" ) ) {
1537 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1540 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1541 .equals( "UniProt link" ) ) ) {
1544 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1547 if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1550 if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1551 .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." ) ) ) {
1554 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1557 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1560 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1563 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1566 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1567 .equals( "ncbi" ) ) {
1570 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1573 if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1574 .getName().equals( "B" ) ) {
1577 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1578 .getFrom() != 21 ) {
1581 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1584 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1585 .getLength() != 24 ) {
1588 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1589 .getConfidence() != 2144 ) {
1592 if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1593 .equals( "pfam" ) ) {
1596 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1599 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1602 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1605 if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1608 final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1609 if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1612 if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1615 if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1618 if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1621 if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1624 if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1627 if ( taxbb.getSynonyms().size() != 2 ) {
1630 if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1633 if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1636 if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1639 if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1642 if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1645 if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1646 .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1650 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1653 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1656 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1659 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1662 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1665 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1668 if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1672 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1675 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1676 .equalsIgnoreCase( "435" ) ) {
1679 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1682 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1683 .equalsIgnoreCase( "443.7" ) ) {
1686 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1689 if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1692 if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1693 .equalsIgnoreCase( "433" ) ) {
1697 catch ( final Exception e ) {
1698 e.printStackTrace( System.out );
1704 private static boolean testBasicPhyloXMLparsingValidating() {
1706 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1707 PhyloXmlParser xml_parser = null;
1709 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1711 catch ( final Exception e ) {
1712 // Do nothing -- means were not running from jar.
1714 if ( xml_parser == null ) {
1715 xml_parser = new PhyloXmlParser();
1716 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1717 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1720 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1723 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1725 if ( xml_parser.getErrorCount() > 0 ) {
1726 System.out.println( xml_parser.getErrorMessages().toString() );
1729 if ( phylogenies_0.length != 4 ) {
1732 final Phylogeny t1 = phylogenies_0[ 0 ];
1733 final Phylogeny t2 = phylogenies_0[ 1 ];
1734 final Phylogeny t3 = phylogenies_0[ 2 ];
1735 final Phylogeny t4 = phylogenies_0[ 3 ];
1736 if ( !t1.getName().equals( "t1" ) ) {
1739 if ( !t2.getName().equals( "t2" ) ) {
1742 if ( !t3.getName().equals( "t3" ) ) {
1745 if ( !t4.getName().equals( "t4" ) ) {
1748 if ( t1.getNumberOfExternalNodes() != 1 ) {
1751 if ( t2.getNumberOfExternalNodes() != 2 ) {
1754 if ( t3.getNumberOfExternalNodes() != 4 ) {
1757 final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
1758 final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
1759 if ( xml_parser.getErrorCount() > 0 ) {
1760 System.out.println( "errors:" );
1761 System.out.println( xml_parser.getErrorMessages().toString() );
1764 if ( phylogenies_1.length != 4 ) {
1767 final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
1769 if ( xml_parser.getErrorCount() > 0 ) {
1770 System.out.println( "errors:" );
1771 System.out.println( xml_parser.getErrorMessages().toString() );
1774 if ( phylogenies_2.length != 1 ) {
1777 if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
1780 final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
1782 if ( xml_parser.getErrorCount() > 0 ) {
1783 System.out.println( xml_parser.getErrorMessages().toString() );
1786 if ( phylogenies_3.length != 2 ) {
1789 final Phylogeny a = phylogenies_3[ 0 ];
1790 if ( !a.getName().equals( "tree 4" ) ) {
1793 if ( a.getNumberOfExternalNodes() != 3 ) {
1796 if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
1799 if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
1802 final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
1804 if ( xml_parser.getErrorCount() > 0 ) {
1805 System.out.println( xml_parser.getErrorMessages().toString() );
1808 if ( phylogenies_4.length != 1 ) {
1811 final Phylogeny s = phylogenies_4[ 0 ];
1812 if ( s.getNumberOfExternalNodes() != 6 ) {
1815 s.getNode( "first" );
1817 s.getNode( "\"<a'b&c'd\">\"" );
1818 s.getNode( "'''\"" );
1819 s.getNode( "\"\"\"" );
1820 s.getNode( "dick & doof" );
1822 catch ( final Exception e ) {
1823 e.printStackTrace( System.out );
1829 private static boolean testBasicTable() {
1831 final BasicTable<String> t0 = new BasicTable<String>();
1832 if ( t0.getNumberOfColumns() != 0 ) {
1835 if ( t0.getNumberOfRows() != 0 ) {
1838 t0.setValue( 3, 2, "23" );
1839 t0.setValue( 10, 1, "error" );
1840 t0.setValue( 10, 1, "110" );
1841 t0.setValue( 9, 1, "19" );
1842 t0.setValue( 1, 10, "101" );
1843 t0.setValue( 10, 10, "1010" );
1844 t0.setValue( 100, 10, "10100" );
1845 t0.setValue( 0, 0, "00" );
1846 if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
1849 if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
1852 if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
1855 if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
1858 if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
1861 if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
1864 if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
1867 if ( t0.getNumberOfColumns() != 101 ) {
1870 if ( t0.getNumberOfRows() != 11 ) {
1873 if ( t0.getValueAsString( 49, 4 ) != null ) {
1876 final String l = ForesterUtil.getLineSeparator();
1877 final StringBuffer source = new StringBuffer();
1878 source.append( "" + l );
1879 source.append( "# 1 1 1 1 1 1 1 1" + l );
1880 source.append( " 00 01 02 03" + l );
1881 source.append( " 10 11 12 13 " + l );
1882 source.append( "20 21 22 23 " + l );
1883 source.append( " 30 31 32 33" + l );
1884 source.append( "40 41 42 43" + l );
1885 source.append( " # 1 1 1 1 1 " + l );
1886 source.append( "50 51 52 53 54" + l );
1887 final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), " " );
1888 if ( t1.getNumberOfColumns() != 5 ) {
1891 if ( t1.getNumberOfRows() != 6 ) {
1894 if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
1897 if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
1900 if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
1903 if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
1906 final StringBuffer source1 = new StringBuffer();
1907 source1.append( "" + l );
1908 source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
1909 source1.append( " 00; 01 ;02;03" + l );
1910 source1.append( " 10; 11; 12; 13 " + l );
1911 source1.append( "20; 21; 22; 23 " + l );
1912 source1.append( " 30; 31; 32; 33" + l );
1913 source1.append( "40;41;42;43" + l );
1914 source1.append( " # 1 1 1 1 1 " + l );
1915 source1.append( ";;;50 ; ;52; 53;;54 " + l );
1916 final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ";" );
1917 if ( t2.getNumberOfColumns() != 5 ) {
1920 if ( t2.getNumberOfRows() != 6 ) {
1923 if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
1926 if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
1929 if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
1932 if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
1935 if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
1938 if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
1941 final StringBuffer source2 = new StringBuffer();
1942 source2.append( "" + l );
1943 source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
1944 source2.append( " 00; 01 ;02;03" + l );
1945 source2.append( " 10; 11; 12; 13 " + l );
1946 source2.append( "20; 21; 22; 23 " + l );
1947 source2.append( " " + l );
1948 source2.append( " 30; 31; 32; 33" + l );
1949 source2.append( "40;41;42;43" + l );
1950 source2.append( " comment: 1 1 1 1 1 " + l );
1951 source2.append( ";;;50 ; 52; 53;;54 " + l );
1952 final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
1958 if ( tl.size() != 2 ) {
1961 final BasicTable<String> t3 = tl.get( 0 );
1962 final BasicTable<String> t4 = tl.get( 1 );
1963 if ( t3.getNumberOfColumns() != 4 ) {
1966 if ( t3.getNumberOfRows() != 3 ) {
1969 if ( t4.getNumberOfColumns() != 4 ) {
1972 if ( t4.getNumberOfRows() != 3 ) {
1975 if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
1978 if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
1982 catch ( final Exception e ) {
1983 e.printStackTrace( System.out );
1989 private static boolean testBasicTolXMLparsing() {
1991 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1992 final TolParser parser = new TolParser();
1993 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
1994 if ( parser.getErrorCount() > 0 ) {
1995 System.out.println( parser.getErrorMessages().toString() );
1998 if ( phylogenies_0.length != 1 ) {
2001 final Phylogeny t1 = phylogenies_0[ 0 ];
2002 if ( t1.getNumberOfExternalNodes() != 5 ) {
2005 if ( !t1.isRooted() ) {
2008 if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2011 if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2014 if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2017 if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2020 final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2021 if ( parser.getErrorCount() > 0 ) {
2022 System.out.println( parser.getErrorMessages().toString() );
2025 if ( phylogenies_1.length != 1 ) {
2028 final Phylogeny t2 = phylogenies_1[ 0 ];
2029 if ( t2.getNumberOfExternalNodes() != 664 ) {
2032 if ( !t2.isRooted() ) {
2035 if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2038 if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2041 if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2044 if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2047 if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2050 if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2051 .equals( "Aquifex" ) ) {
2054 final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2055 if ( parser.getErrorCount() > 0 ) {
2056 System.out.println( parser.getErrorMessages().toString() );
2059 if ( phylogenies_2.length != 1 ) {
2062 final Phylogeny t3 = phylogenies_2[ 0 ];
2063 if ( t3.getNumberOfExternalNodes() != 184 ) {
2066 if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2069 if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2072 if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2075 final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2076 if ( parser.getErrorCount() > 0 ) {
2077 System.out.println( parser.getErrorMessages().toString() );
2080 if ( phylogenies_3.length != 1 ) {
2083 final Phylogeny t4 = phylogenies_3[ 0 ];
2084 if ( t4.getNumberOfExternalNodes() != 1 ) {
2087 if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2090 if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2093 if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2096 final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2097 if ( parser.getErrorCount() > 0 ) {
2098 System.out.println( parser.getErrorMessages().toString() );
2101 if ( phylogenies_4.length != 1 ) {
2104 final Phylogeny t5 = phylogenies_4[ 0 ];
2105 if ( t5.getNumberOfExternalNodes() != 13 ) {
2108 if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2111 if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2114 if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2118 catch ( final Exception e ) {
2119 e.printStackTrace( System.out );
2125 private static boolean testBasicTreeMethods() {
2127 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2128 final Phylogeny t1 = factory.create();
2129 if ( !t1.isEmpty() ) {
2132 final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2133 if ( t2.getNumberOfExternalNodes() != 4 ) {
2136 if ( t2.getHeight() != 8.5 ) {
2139 if ( !t2.isCompletelyBinary() ) {
2142 if ( t2.isEmpty() ) {
2145 final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2146 if ( t3.getNumberOfExternalNodes() != 5 ) {
2149 if ( t3.getHeight() != 11 ) {
2152 if ( t3.isCompletelyBinary() ) {
2155 final PhylogenyNode n = t3.getNode( "ABC" );
2156 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 ];
2157 if ( t4.getNumberOfExternalNodes() != 9 ) {
2160 if ( t4.getHeight() != 11 ) {
2163 if ( t4.isCompletelyBinary() ) {
2166 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)" );
2167 final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2168 if ( t5.getNumberOfExternalNodes() != 8 ) {
2171 if ( t5.getHeight() != 15 ) {
2174 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)" );
2175 final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2176 if ( t6.getHeight() != 15 ) {
2179 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)" );
2180 final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2181 if ( t7.getHeight() != 15 ) {
2184 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)" );
2185 final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2186 if ( t8.getNumberOfExternalNodes() != 10 ) {
2189 if ( t8.getHeight() != 15 ) {
2192 final char[] a9 = new char[] { 'a' };
2193 final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2194 if ( t9.getHeight() != 0 ) {
2197 final char[] a10 = new char[] { 'a', ':', '6' };
2198 final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2199 if ( t10.getHeight() != 6 ) {
2203 catch ( final Exception e ) {
2204 e.printStackTrace( System.out );
2210 private static boolean testTreeMethods() {
2212 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2213 final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
2214 PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
2215 if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
2216 System.out.println( t0.toNewHampshireX() );
2219 final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
2220 PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
2221 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
2224 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
2227 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
2231 catch ( final Exception e ) {
2232 e.printStackTrace( System.out );
2238 private static boolean testConfidenceAssessor() {
2240 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2241 final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2242 final Phylogeny[] ev0 = factory
2243 .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2245 ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2246 if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2249 if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2252 final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2253 final Phylogeny[] ev1 = factory
2254 .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)));",
2256 ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2257 if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2260 if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2263 final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2264 final Phylogeny[] ev_b = factory
2265 .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",
2267 ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2268 if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2271 if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2275 final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2276 final Phylogeny[] ev1x = factory
2277 .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)));",
2279 ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2280 if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2283 if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2286 final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2287 final Phylogeny[] ev_bx = factory
2288 .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",
2290 ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2291 if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2294 if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2298 final Phylogeny[] t2 = factory
2299 .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);",
2301 final Phylogeny[] ev2 = factory
2302 .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);",
2304 for( final Phylogeny target : t2 ) {
2305 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2308 final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2309 new NHXParser() )[ 0 ];
2310 final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2311 ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2312 if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2315 if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2318 if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2322 catch ( final Exception e ) {
2323 e.printStackTrace();
2329 private static boolean testCopyOfNodeData() {
2331 final PhylogenyNode n1 = PhylogenyNode
2332 .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]" );
2333 final PhylogenyNode n2 = n1.copyNodeData();
2334 if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2338 catch ( final Exception e ) {
2339 e.printStackTrace();
2345 private static boolean testDataObjects() {
2347 final Confidence s0 = new Confidence();
2348 final Confidence s1 = new Confidence();
2349 if ( !s0.isEqual( s1 ) ) {
2352 final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2353 final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2354 if ( s2.isEqual( s1 ) ) {
2357 if ( !s2.isEqual( s3 ) ) {
2360 final Confidence s4 = ( Confidence ) s3.copy();
2361 if ( !s4.isEqual( s3 ) ) {
2368 final Taxonomy t1 = new Taxonomy();
2369 final Taxonomy t2 = new Taxonomy();
2370 final Taxonomy t3 = new Taxonomy();
2371 final Taxonomy t4 = new Taxonomy();
2372 final Taxonomy t5 = new Taxonomy();
2373 t1.setIdentifier( new Identifier( "ecoli" ) );
2374 t1.setTaxonomyCode( "ECOLI" );
2375 t1.setScientificName( "E. coli" );
2376 t1.setCommonName( "coli" );
2377 final Taxonomy t0 = ( Taxonomy ) t1.copy();
2378 if ( !t1.isEqual( t0 ) ) {
2381 t2.setIdentifier( new Identifier( "ecoli" ) );
2382 t2.setTaxonomyCode( "OTHER" );
2383 t2.setScientificName( "what" );
2384 t2.setCommonName( "something" );
2385 if ( !t1.isEqual( t2 ) ) {
2388 t2.setIdentifier( new Identifier( "nemve" ) );
2389 if ( t1.isEqual( t2 ) ) {
2392 t1.setIdentifier( null );
2393 t3.setTaxonomyCode( "ECOLI" );
2394 t3.setScientificName( "what" );
2395 t3.setCommonName( "something" );
2396 if ( !t1.isEqual( t3 ) ) {
2399 t1.setIdentifier( null );
2400 t1.setTaxonomyCode( "" );
2401 t4.setScientificName( "E. ColI" );
2402 t4.setCommonName( "something" );
2403 if ( !t1.isEqual( t4 ) ) {
2406 t4.setScientificName( "B. subtilis" );
2407 t4.setCommonName( "something" );
2408 if ( t1.isEqual( t4 ) ) {
2411 t1.setIdentifier( null );
2412 t1.setTaxonomyCode( "" );
2413 t1.setScientificName( "" );
2414 t5.setCommonName( "COLI" );
2415 if ( !t1.isEqual( t5 ) ) {
2418 t5.setCommonName( "vibrio" );
2419 if ( t1.isEqual( t5 ) ) {
2424 final Identifier id0 = new Identifier( "123", "pfam" );
2425 final Identifier id1 = ( Identifier ) id0.copy();
2426 if ( !id1.isEqual( id1 ) ) {
2429 if ( !id1.isEqual( id0 ) ) {
2432 if ( !id0.isEqual( id1 ) ) {
2439 final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
2440 final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
2441 if ( !pd1.isEqual( pd1 ) ) {
2444 if ( !pd1.isEqual( pd0 ) ) {
2449 final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
2450 final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
2451 if ( !pd3.isEqual( pd3 ) ) {
2454 if ( !pd2.isEqual( pd3 ) ) {
2457 if ( !pd0.isEqual( pd3 ) ) {
2462 // DomainArchitecture
2463 // ------------------
2464 final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
2465 final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
2466 final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
2467 final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
2468 final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
2469 final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
2474 final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
2475 if ( ds0.getNumberOfDomains() != 4 ) {
2478 final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
2479 if ( !ds0.isEqual( ds0 ) ) {
2482 if ( !ds0.isEqual( ds1 ) ) {
2485 if ( ds1.getNumberOfDomains() != 4 ) {
2488 final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
2493 final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
2494 if ( ds0.isEqual( ds2 ) ) {
2500 final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
2501 if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
2502 System.out.println( ds3.toNHX() );
2505 if ( ds3.getNumberOfDomains() != 3 ) {
2510 final Event e1 = new Event( Event.EventType.fusion );
2511 if ( e1.isDuplication() ) {
2514 if ( !e1.isFusion() ) {
2517 if ( !e1.asText().toString().equals( "fusion" ) ) {
2520 if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
2523 final Event e11 = new Event( Event.EventType.fusion );
2524 if ( !e11.isEqual( e1 ) ) {
2527 if ( !e11.toNHX().toString().equals( "" ) ) {
2530 final Event e2 = new Event( Event.EventType.speciation_or_duplication );
2531 if ( e2.isDuplication() ) {
2534 if ( !e2.isSpeciationOrDuplication() ) {
2537 if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
2540 if ( !e2.asSimpleText().toString().equals( "?" ) ) {
2543 if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
2546 if ( e11.isEqual( e2 ) ) {
2549 final Event e2c = ( Event ) e2.copy();
2550 if ( !e2c.isEqual( e2 ) ) {
2553 Event e3 = new Event( 1, 2, 3 );
2554 if ( e3.isDuplication() ) {
2557 if ( e3.isSpeciation() ) {
2560 if ( e3.isGeneLoss() ) {
2563 if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2566 final Event e3c = ( Event ) e3.copy();
2567 final Event e3cc = ( Event ) e3c.copy();
2568 if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
2572 if ( !e3c.isEqual( e3cc ) ) {
2575 Event e4 = new Event( 1, 2, 3 );
2576 if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2579 if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
2582 final Event e4c = ( Event ) e4.copy();
2584 final Event e4cc = ( Event ) e4c.copy();
2585 if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2588 if ( !e4c.isEqual( e4cc ) ) {
2591 final Event e5 = new Event();
2592 if ( !e5.isUnassigned() ) {
2595 if ( !e5.asText().toString().equals( "unassigned" ) ) {
2598 if ( !e5.asSimpleText().toString().equals( "" ) ) {
2601 final Event e6 = new Event( 1, 0, 0 );
2602 if ( !e6.asText().toString().equals( "duplication" ) ) {
2605 if ( !e6.asSimpleText().toString().equals( "D" ) ) {
2608 final Event e7 = new Event( 0, 1, 0 );
2609 if ( !e7.asText().toString().equals( "speciation" ) ) {
2612 if ( !e7.asSimpleText().toString().equals( "S" ) ) {
2615 final Event e8 = new Event( 0, 0, 1 );
2616 if ( !e8.asText().toString().equals( "gene-loss" ) ) {
2619 if ( !e8.asSimpleText().toString().equals( "L" ) ) {
2623 catch ( final Exception e ) {
2624 e.printStackTrace( System.out );
2630 private static boolean testDeletionOfExternalNodes() {
2632 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2633 final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
2634 final PhylogenyWriter w = new PhylogenyWriter();
2635 if ( t0.isEmpty() ) {
2638 if ( t0.getNumberOfExternalNodes() != 1 ) {
2641 t0.deleteSubtree( t0.getNode( "A" ), false );
2642 if ( t0.getNumberOfExternalNodes() != 0 ) {
2645 if ( !t0.isEmpty() ) {
2648 final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
2649 if ( t1.getNumberOfExternalNodes() != 2 ) {
2652 t1.deleteSubtree( t1.getNode( "A" ), false );
2653 if ( t1.getNumberOfExternalNodes() != 1 ) {
2656 if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
2659 t1.deleteSubtree( t1.getNode( "B" ), false );
2660 if ( t1.getNumberOfExternalNodes() != 1 ) {
2663 t1.deleteSubtree( t1.getNode( "r" ), false );
2664 if ( !t1.isEmpty() ) {
2667 final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
2668 if ( t2.getNumberOfExternalNodes() != 3 ) {
2671 t2.deleteSubtree( t2.getNode( "B" ), false );
2672 if ( t2.getNumberOfExternalNodes() != 2 ) {
2675 t2.toNewHampshireX();
2676 PhylogenyNode n = t2.getNode( "A" );
2677 if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2680 t2.deleteSubtree( t2.getNode( "A" ), false );
2681 if ( t2.getNumberOfExternalNodes() != 2 ) {
2684 t2.deleteSubtree( t2.getNode( "C" ), true );
2685 if ( t2.getNumberOfExternalNodes() != 1 ) {
2688 final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2689 if ( t3.getNumberOfExternalNodes() != 4 ) {
2692 t3.deleteSubtree( t3.getNode( "B" ), true );
2693 if ( t3.getNumberOfExternalNodes() != 3 ) {
2696 n = t3.getNode( "A" );
2697 if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2700 n = n.getNextExternalNode();
2701 if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2704 t3.deleteSubtree( t3.getNode( "A" ), true );
2705 if ( t3.getNumberOfExternalNodes() != 2 ) {
2708 n = t3.getNode( "C" );
2709 if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2712 t3.deleteSubtree( t3.getNode( "C" ), true );
2713 if ( t3.getNumberOfExternalNodes() != 1 ) {
2716 t3.deleteSubtree( t3.getNode( "D" ), true );
2717 if ( t3.getNumberOfExternalNodes() != 0 ) {
2720 final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2721 if ( t4.getNumberOfExternalNodes() != 6 ) {
2724 t4.deleteSubtree( t4.getNode( "B2" ), true );
2725 if ( t4.getNumberOfExternalNodes() != 5 ) {
2728 String s = w.toNewHampshire( t4, false, true ).toString();
2729 if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2732 t4.deleteSubtree( t4.getNode( "B11" ), true );
2733 if ( t4.getNumberOfExternalNodes() != 4 ) {
2736 t4.deleteSubtree( t4.getNode( "C" ), true );
2737 if ( t4.getNumberOfExternalNodes() != 3 ) {
2740 n = t4.getNode( "A" );
2741 n = n.getNextExternalNode();
2742 if ( !n.getName().equals( "B12" ) ) {
2745 n = n.getNextExternalNode();
2746 if ( !n.getName().equals( "D" ) ) {
2749 s = w.toNewHampshire( t4, false, true ).toString();
2750 if ( !s.equals( "((A,B12),D);" ) ) {
2753 final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2754 t5.deleteSubtree( t5.getNode( "A" ), true );
2755 if ( t5.getNumberOfExternalNodes() != 5 ) {
2758 s = w.toNewHampshire( t5, false, true ).toString();
2759 if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
2762 final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2763 t6.deleteSubtree( t6.getNode( "B11" ), true );
2764 if ( t6.getNumberOfExternalNodes() != 5 ) {
2767 s = w.toNewHampshire( t6, false, false ).toString();
2768 if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
2771 final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2772 t7.deleteSubtree( t7.getNode( "B12" ), true );
2773 if ( t7.getNumberOfExternalNodes() != 5 ) {
2776 s = w.toNewHampshire( t7, false, true ).toString();
2777 if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
2780 final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2781 t8.deleteSubtree( t8.getNode( "B2" ), true );
2782 if ( t8.getNumberOfExternalNodes() != 5 ) {
2785 s = w.toNewHampshire( t8, false, false ).toString();
2786 if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2789 final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2790 t9.deleteSubtree( t9.getNode( "C" ), true );
2791 if ( t9.getNumberOfExternalNodes() != 5 ) {
2794 s = w.toNewHampshire( t9, false, true ).toString();
2795 if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
2798 final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2799 t10.deleteSubtree( t10.getNode( "D" ), true );
2800 if ( t10.getNumberOfExternalNodes() != 5 ) {
2803 s = w.toNewHampshire( t10, false, true ).toString();
2804 if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
2807 final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
2808 t11.deleteSubtree( t11.getNode( "A" ), true );
2809 if ( t11.getNumberOfExternalNodes() != 2 ) {
2812 s = w.toNewHampshire( t11, false, true ).toString();
2813 if ( !s.equals( "(B,C);" ) ) {
2816 t11.deleteSubtree( t11.getNode( "C" ), true );
2817 if ( t11.getNumberOfExternalNodes() != 1 ) {
2820 s = w.toNewHampshire( t11, false, false ).toString();
2821 if ( !s.equals( "B;" ) ) {
2824 final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
2825 t12.deleteSubtree( t12.getNode( "B2" ), true );
2826 if ( t12.getNumberOfExternalNodes() != 8 ) {
2829 s = w.toNewHampshire( t12, false, true ).toString();
2830 if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
2833 t12.deleteSubtree( t12.getNode( "B3" ), true );
2834 if ( t12.getNumberOfExternalNodes() != 7 ) {
2837 s = w.toNewHampshire( t12, false, true ).toString();
2838 if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
2841 t12.deleteSubtree( t12.getNode( "C3" ), true );
2842 if ( t12.getNumberOfExternalNodes() != 6 ) {
2845 s = w.toNewHampshire( t12, false, true ).toString();
2846 if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
2849 t12.deleteSubtree( t12.getNode( "A1" ), true );
2850 if ( t12.getNumberOfExternalNodes() != 5 ) {
2853 s = w.toNewHampshire( t12, false, true ).toString();
2854 if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
2857 t12.deleteSubtree( t12.getNode( "B1" ), true );
2858 if ( t12.getNumberOfExternalNodes() != 4 ) {
2861 s = w.toNewHampshire( t12, false, true ).toString();
2862 if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
2865 t12.deleteSubtree( t12.getNode( "A3" ), true );
2866 if ( t12.getNumberOfExternalNodes() != 3 ) {
2869 s = w.toNewHampshire( t12, false, true ).toString();
2870 if ( !s.equals( "(A2,(C1,C2));" ) ) {
2873 t12.deleteSubtree( t12.getNode( "A2" ), true );
2874 if ( t12.getNumberOfExternalNodes() != 2 ) {
2877 s = w.toNewHampshire( t12, false, true ).toString();
2878 if ( !s.equals( "(C1,C2);" ) ) {
2881 final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
2882 t13.deleteSubtree( t13.getNode( "D" ), true );
2883 if ( t13.getNumberOfExternalNodes() != 4 ) {
2886 s = w.toNewHampshire( t13, false, true ).toString();
2887 if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
2890 final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
2891 t14.deleteSubtree( t14.getNode( "E" ), true );
2892 if ( t14.getNumberOfExternalNodes() != 5 ) {
2895 s = w.toNewHampshire( t14, false, true ).toString();
2896 if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
2899 final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
2900 t15.deleteSubtree( t15.getNode( "B2" ), true );
2901 if ( t15.getNumberOfExternalNodes() != 11 ) {
2904 t15.deleteSubtree( t15.getNode( "B1" ), true );
2905 if ( t15.getNumberOfExternalNodes() != 10 ) {
2908 t15.deleteSubtree( t15.getNode( "B3" ), true );
2909 if ( t15.getNumberOfExternalNodes() != 9 ) {
2912 t15.deleteSubtree( t15.getNode( "B4" ), true );
2913 if ( t15.getNumberOfExternalNodes() != 8 ) {
2916 t15.deleteSubtree( t15.getNode( "A1" ), true );
2917 if ( t15.getNumberOfExternalNodes() != 7 ) {
2920 t15.deleteSubtree( t15.getNode( "C4" ), true );
2921 if ( t15.getNumberOfExternalNodes() != 6 ) {
2925 catch ( final Exception e ) {
2926 e.printStackTrace( System.out );
2932 private static boolean testDescriptiveStatistics() {
2934 final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
2935 dss1.addValue( 82 );
2936 dss1.addValue( 78 );
2937 dss1.addValue( 70 );
2938 dss1.addValue( 58 );
2939 dss1.addValue( 42 );
2940 if ( dss1.getN() != 5 ) {
2943 if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
2946 if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
2949 if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
2952 if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
2955 if ( !Test.isEqual( dss1.median(), 70 ) ) {
2958 if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
2961 if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
2964 if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
2967 if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
2970 if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
2973 if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
2976 dss1.addValue( 123 );
2977 if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
2980 if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
2983 if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
2986 final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
2987 dss2.addValue( -1.85 );
2988 dss2.addValue( 57.5 );
2989 dss2.addValue( 92.78 );
2990 dss2.addValue( 57.78 );
2991 if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
2994 if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
2997 final double[] a = dss2.getDataAsDoubleArray();
2998 if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3001 dss2.addValue( -100 );
3002 if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3005 if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3008 final double[] ds = new double[ 14 ];
3023 final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3024 if ( bins.length != 4 ) {
3027 if ( bins[ 0 ] != 2 ) {
3030 if ( bins[ 1 ] != 3 ) {
3033 if ( bins[ 2 ] != 4 ) {
3036 if ( bins[ 3 ] != 5 ) {
3039 final double[] ds1 = new double[ 9 ];
3049 final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3050 if ( bins1.length != 4 ) {
3053 if ( bins1[ 0 ] != 2 ) {
3056 if ( bins1[ 1 ] != 3 ) {
3059 if ( bins1[ 2 ] != 0 ) {
3062 if ( bins1[ 3 ] != 4 ) {
3065 final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3066 if ( bins1_1.length != 3 ) {
3069 if ( bins1_1[ 0 ] != 3 ) {
3072 if ( bins1_1[ 1 ] != 2 ) {
3075 if ( bins1_1[ 2 ] != 4 ) {
3078 final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3079 if ( bins1_2.length != 3 ) {
3082 if ( bins1_2[ 0 ] != 2 ) {
3085 if ( bins1_2[ 1 ] != 2 ) {
3088 if ( bins1_2[ 2 ] != 2 ) {
3091 final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3105 dss3.addValue( 10 );
3106 dss3.addValue( 10 );
3107 dss3.addValue( 10 );
3108 final AsciiHistogram histo = new AsciiHistogram( dss3 );
3109 histo.toStringBuffer( 10, '=', 40, 5 );
3110 histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3112 catch ( final Exception e ) {
3113 e.printStackTrace( System.out );
3119 private static boolean testDir( final String file ) {
3121 final File f = new File( file );
3122 if ( !f.exists() ) {
3125 if ( !f.isDirectory() ) {
3128 if ( !f.canRead() ) {
3132 catch ( final Exception e ) {
3138 private static boolean testExternalNodeRelatedMethods() {
3140 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3141 final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3142 PhylogenyNode n = t1.getNode( "A" );
3143 n = n.getNextExternalNode();
3144 if ( !n.getName().equals( "B" ) ) {
3147 n = n.getNextExternalNode();
3148 if ( !n.getName().equals( "C" ) ) {
3151 n = n.getNextExternalNode();
3152 if ( !n.getName().equals( "D" ) ) {
3155 n = t1.getNode( "B" );
3156 while ( !n.isLastExternalNode() ) {
3157 n = n.getNextExternalNode();
3159 final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
3160 n = t2.getNode( "A" );
3161 n = n.getNextExternalNode();
3162 if ( !n.getName().equals( "B" ) ) {
3165 n = n.getNextExternalNode();
3166 if ( !n.getName().equals( "C" ) ) {
3169 n = n.getNextExternalNode();
3170 if ( !n.getName().equals( "D" ) ) {
3173 n = t2.getNode( "B" );
3174 while ( !n.isLastExternalNode() ) {
3175 n = n.getNextExternalNode();
3177 final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3178 n = t3.getNode( "A" );
3179 n = n.getNextExternalNode();
3180 if ( !n.getName().equals( "B" ) ) {
3183 n = n.getNextExternalNode();
3184 if ( !n.getName().equals( "C" ) ) {
3187 n = n.getNextExternalNode();
3188 if ( !n.getName().equals( "D" ) ) {
3191 n = n.getNextExternalNode();
3192 if ( !n.getName().equals( "E" ) ) {
3195 n = n.getNextExternalNode();
3196 if ( !n.getName().equals( "F" ) ) {
3199 n = n.getNextExternalNode();
3200 if ( !n.getName().equals( "G" ) ) {
3203 n = n.getNextExternalNode();
3204 if ( !n.getName().equals( "H" ) ) {
3207 n = t3.getNode( "B" );
3208 while ( !n.isLastExternalNode() ) {
3209 n = n.getNextExternalNode();
3211 final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3212 for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
3213 final PhylogenyNode node = iter.next();
3215 final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3216 for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
3217 final PhylogenyNode node = iter.next();
3219 final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
3220 final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
3221 if ( !iter.next().getName().equals( "A" ) ) {
3224 if ( !iter.next().getName().equals( "B" ) ) {
3227 if ( !iter.next().getName().equals( "C" ) ) {
3230 if ( !iter.next().getName().equals( "D" ) ) {
3233 if ( !iter.next().getName().equals( "E" ) ) {
3236 if ( !iter.next().getName().equals( "F" ) ) {
3239 if ( iter.hasNext() ) {
3243 catch ( final Exception e ) {
3244 e.printStackTrace( System.out );
3250 private static boolean testGeneralTable() {
3252 final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
3253 t0.setValue( 3, 2, "23" );
3254 t0.setValue( 10, 1, "error" );
3255 t0.setValue( 10, 1, "110" );
3256 t0.setValue( 9, 1, "19" );
3257 t0.setValue( 1, 10, "101" );
3258 t0.setValue( 10, 10, "1010" );
3259 t0.setValue( 100, 10, "10100" );
3260 t0.setValue( 0, 0, "00" );
3261 if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
3264 if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
3267 if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
3270 if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
3273 if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
3276 if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
3279 if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
3282 if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
3285 if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
3288 final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
3289 t1.setValue( "3", "2", "23" );
3290 t1.setValue( "10", "1", "error" );
3291 t1.setValue( "10", "1", "110" );
3292 t1.setValue( "9", "1", "19" );
3293 t1.setValue( "1", "10", "101" );
3294 t1.setValue( "10", "10", "1010" );
3295 t1.setValue( "100", "10", "10100" );
3296 t1.setValue( "0", "0", "00" );
3297 t1.setValue( "qwerty", "zxcvbnm", "asdef" );
3298 if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
3301 if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
3304 if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
3307 if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
3310 if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
3313 if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
3316 if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
3319 if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
3322 if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
3325 if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
3329 catch ( final Exception e ) {
3330 e.printStackTrace( System.out );
3336 private static boolean testGetDistance() {
3338 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3339 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",
3340 new NHXParser() )[ 0 ];
3341 if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
3344 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
3347 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
3350 if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
3353 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
3356 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
3359 if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
3362 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
3365 if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
3368 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
3371 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
3374 if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
3377 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
3380 if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
3383 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
3386 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
3389 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
3392 if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
3395 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
3398 if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
3401 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
3404 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
3407 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
3410 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
3413 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
3416 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
3419 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
3422 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
3425 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
3428 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
3431 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
3434 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",
3435 new NHXParser() )[ 0 ];
3436 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
3439 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
3442 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
3445 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
3448 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
3451 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
3454 if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
3457 if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
3460 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
3463 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
3466 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
3470 catch ( final Exception e ) {
3471 e.printStackTrace( System.out );
3477 private static boolean testGetLCA() {
3479 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3480 final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3481 new NHXParser() )[ 0 ];
3482 final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
3483 if ( !A.getName().equals( "A" ) ) {
3486 final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
3487 if ( !gh.getName().equals( "gh" ) ) {
3490 final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
3491 if ( !ab.getName().equals( "ab" ) ) {
3494 final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
3495 if ( !ab2.getName().equals( "ab" ) ) {
3498 final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
3499 if ( !gh2.getName().equals( "gh" ) ) {
3502 final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
3503 if ( !gh3.getName().equals( "gh" ) ) {
3506 final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
3507 if ( !abc.getName().equals( "abc" ) ) {
3510 final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
3511 if ( !abc2.getName().equals( "abc" ) ) {
3514 final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
3515 if ( !abcd.getName().equals( "abcd" ) ) {
3518 final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
3519 if ( !abcd2.getName().equals( "abcd" ) ) {
3522 final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
3523 if ( !abcdef.getName().equals( "abcdef" ) ) {
3526 final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
3527 if ( !abcdef2.getName().equals( "abcdef" ) ) {
3530 final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
3531 if ( !abcdef3.getName().equals( "abcdef" ) ) {
3534 final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
3535 if ( !abcdef4.getName().equals( "abcdef" ) ) {
3538 final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
3539 if ( !abcde.getName().equals( "abcde" ) ) {
3542 final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
3543 if ( !abcde2.getName().equals( "abcde" ) ) {
3546 final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
3547 if ( !r.getName().equals( "abcdefgh" ) ) {
3550 final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
3551 if ( !r2.getName().equals( "abcdefgh" ) ) {
3554 final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
3555 if ( !r3.getName().equals( "abcdefgh" ) ) {
3558 final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
3559 if ( !abcde3.getName().equals( "abcde" ) ) {
3562 final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
3563 if ( !abcde4.getName().equals( "abcde" ) ) {
3566 final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
3567 if ( !ab3.getName().equals( "ab" ) ) {
3570 final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
3571 if ( !ab4.getName().equals( "ab" ) ) {
3574 final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3575 final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
3576 if ( !cd.getName().equals( "cd" ) ) {
3579 final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
3580 if ( !cd2.getName().equals( "cd" ) ) {
3583 final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
3584 if ( !cde.getName().equals( "cde" ) ) {
3587 final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
3588 if ( !cde2.getName().equals( "cde" ) ) {
3591 final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
3592 if ( !cdef.getName().equals( "cdef" ) ) {
3595 final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
3596 if ( !cdef2.getName().equals( "cdef" ) ) {
3599 final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
3600 if ( !cdef3.getName().equals( "cdef" ) ) {
3603 final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
3604 if ( !rt.getName().equals( "r" ) ) {
3607 final Phylogeny p3 = factory
3608 .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
3609 new NHXParser() )[ 0 ];
3610 final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
3611 if ( !bc_3.getName().equals( "bc" ) ) {
3614 final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
3615 if ( !ac_3.getName().equals( "abc" ) ) {
3618 final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
3619 if ( !ad_3.getName().equals( "abcde" ) ) {
3622 final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
3623 if ( !af_3.getName().equals( "abcdef" ) ) {
3626 final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
3627 if ( !ag_3.getName().equals( "" ) ) {
3630 if ( !ag_3.isRoot() ) {
3633 final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
3634 if ( !al_3.getName().equals( "" ) ) {
3637 if ( !al_3.isRoot() ) {
3640 final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
3641 if ( !kl_3.getName().equals( "" ) ) {
3644 if ( !kl_3.isRoot() ) {
3647 final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
3648 if ( !fl_3.getName().equals( "" ) ) {
3651 if ( !fl_3.isRoot() ) {
3654 final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
3655 if ( !gk_3.getName().equals( "ghijk" ) ) {
3658 final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
3659 final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
3660 if ( !r_4.getName().equals( "r" ) ) {
3663 final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
3664 final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
3665 if ( !r_5.getName().equals( "root" ) ) {
3668 final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
3669 final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
3670 if ( !r_6.getName().equals( "rot" ) ) {
3673 final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
3674 final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
3675 if ( !r_7.getName().equals( "rott" ) ) {
3679 catch ( final Exception e ) {
3680 e.printStackTrace( System.out );
3686 private static boolean testGetLCA2() {
3688 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3689 final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
3690 PhylogenyMethods.preOrderReId( p_a );
3691 final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
3692 p_a.getNode( "a" ) );
3693 if ( !p_a_1.getName().equals( "a" ) ) {
3696 final Phylogeny p_b = factory.create( "((a)b)", new NHXParser() )[ 0 ];
3697 PhylogenyMethods.preOrderReId( p_b );
3698 final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
3699 p_b.getNode( "a" ) );
3700 if ( !p_b_1.getName().equals( "b" ) ) {
3703 final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
3704 p_b.getNode( "b" ) );
3705 if ( !p_b_2.getName().equals( "b" ) ) {
3708 final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
3709 PhylogenyMethods.preOrderReId( p_c );
3710 final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
3711 p_c.getNode( "a" ) );
3712 if ( !p_c_1.getName().equals( "b" ) ) {
3715 final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3716 p_c.getNode( "c" ) );
3717 if ( !p_c_2.getName().equals( "c" ) ) {
3718 System.out.println( p_c_2.getName() );
3722 final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3723 p_c.getNode( "b" ) );
3724 if ( !p_c_3.getName().equals( "b" ) ) {
3727 final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
3728 p_c.getNode( "a" ) );
3729 if ( !p_c_4.getName().equals( "c" ) ) {
3732 final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3733 new NHXParser() )[ 0 ];
3734 PhylogenyMethods.preOrderReId( p1 );
3735 final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3736 p1.getNode( "A" ) );
3737 if ( !A.getName().equals( "A" ) ) {
3740 final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
3741 p1.getNode( "gh" ) );
3742 if ( !gh.getName().equals( "gh" ) ) {
3745 final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3746 p1.getNode( "B" ) );
3747 if ( !ab.getName().equals( "ab" ) ) {
3750 final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3751 p1.getNode( "A" ) );
3752 if ( !ab2.getName().equals( "ab" ) ) {
3755 final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3756 p1.getNode( "G" ) );
3757 if ( !gh2.getName().equals( "gh" ) ) {
3760 final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
3761 p1.getNode( "H" ) );
3762 if ( !gh3.getName().equals( "gh" ) ) {
3765 final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
3766 p1.getNode( "A" ) );
3767 if ( !abc.getName().equals( "abc" ) ) {
3770 final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3771 p1.getNode( "C" ) );
3772 if ( !abc2.getName().equals( "abc" ) ) {
3775 final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3776 p1.getNode( "D" ) );
3777 if ( !abcd.getName().equals( "abcd" ) ) {
3780 final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
3781 p1.getNode( "A" ) );
3782 if ( !abcd2.getName().equals( "abcd" ) ) {
3785 final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3786 p1.getNode( "F" ) );
3787 if ( !abcdef.getName().equals( "abcdef" ) ) {
3790 final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3791 p1.getNode( "A" ) );
3792 if ( !abcdef2.getName().equals( "abcdef" ) ) {
3795 final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3796 p1.getNode( "F" ) );
3797 if ( !abcdef3.getName().equals( "abcdef" ) ) {
3800 final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3801 p1.getNode( "ab" ) );
3802 if ( !abcdef4.getName().equals( "abcdef" ) ) {
3805 final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3806 p1.getNode( "E" ) );
3807 if ( !abcde.getName().equals( "abcde" ) ) {
3810 final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3811 p1.getNode( "A" ) );
3812 if ( !abcde2.getName().equals( "abcde" ) ) {
3815 final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
3816 p1.getNode( "abcdefgh" ) );
3817 if ( !r.getName().equals( "abcdefgh" ) ) {
3820 final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3821 p1.getNode( "H" ) );
3822 if ( !r2.getName().equals( "abcdefgh" ) ) {
3825 final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3826 p1.getNode( "A" ) );
3827 if ( !r3.getName().equals( "abcdefgh" ) ) {
3830 final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3831 p1.getNode( "abcde" ) );
3832 if ( !abcde3.getName().equals( "abcde" ) ) {
3835 final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
3836 p1.getNode( "E" ) );
3837 if ( !abcde4.getName().equals( "abcde" ) ) {
3840 final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3841 p1.getNode( "B" ) );
3842 if ( !ab3.getName().equals( "ab" ) ) {
3845 final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3846 p1.getNode( "ab" ) );
3847 if ( !ab4.getName().equals( "ab" ) ) {
3850 final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3851 PhylogenyMethods.preOrderReId( p2 );
3852 final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3853 p2.getNode( "d" ) );
3854 if ( !cd.getName().equals( "cd" ) ) {
3857 final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3858 p2.getNode( "c" ) );
3859 if ( !cd2.getName().equals( "cd" ) ) {
3862 final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3863 p2.getNode( "e" ) );
3864 if ( !cde.getName().equals( "cde" ) ) {
3867 final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
3868 p2.getNode( "c" ) );
3869 if ( !cde2.getName().equals( "cde" ) ) {
3872 final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3873 p2.getNode( "f" ) );
3874 if ( !cdef.getName().equals( "cdef" ) ) {
3877 final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3878 p2.getNode( "f" ) );
3879 if ( !cdef2.getName().equals( "cdef" ) ) {
3882 final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
3883 p2.getNode( "d" ) );
3884 if ( !cdef3.getName().equals( "cdef" ) ) {
3887 final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3888 p2.getNode( "a" ) );
3889 if ( !rt.getName().equals( "r" ) ) {
3892 final Phylogeny p3 = factory
3893 .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
3894 new NHXParser() )[ 0 ];
3895 PhylogenyMethods.preOrderReId( p3 );
3896 final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
3897 p3.getNode( "c" ) );
3898 if ( !bc_3.getName().equals( "bc" ) ) {
3901 final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3902 p3.getNode( "c" ) );
3903 if ( !ac_3.getName().equals( "abc" ) ) {
3906 final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3907 p3.getNode( "d" ) );
3908 if ( !ad_3.getName().equals( "abcde" ) ) {
3911 final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3912 p3.getNode( "f" ) );
3913 if ( !af_3.getName().equals( "abcdef" ) ) {
3916 final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3917 p3.getNode( "g" ) );
3918 if ( !ag_3.getName().equals( "" ) ) {
3921 if ( !ag_3.isRoot() ) {
3924 final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3925 p3.getNode( "l" ) );
3926 if ( !al_3.getName().equals( "" ) ) {
3929 if ( !al_3.isRoot() ) {
3932 final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
3933 p3.getNode( "l" ) );
3934 if ( !kl_3.getName().equals( "" ) ) {
3937 if ( !kl_3.isRoot() ) {
3940 final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
3941 p3.getNode( "l" ) );
3942 if ( !fl_3.getName().equals( "" ) ) {
3945 if ( !fl_3.isRoot() ) {
3948 final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
3949 p3.getNode( "k" ) );
3950 if ( !gk_3.getName().equals( "ghijk" ) ) {
3953 final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
3954 PhylogenyMethods.preOrderReId( p4 );
3955 final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
3956 p4.getNode( "c" ) );
3957 if ( !r_4.getName().equals( "r" ) ) {
3960 final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
3961 PhylogenyMethods.preOrderReId( p5 );
3962 final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
3963 p5.getNode( "c" ) );
3964 if ( !r_5.getName().equals( "root" ) ) {
3967 final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
3968 PhylogenyMethods.preOrderReId( p6 );
3969 final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
3970 p6.getNode( "a" ) );
3971 if ( !r_6.getName().equals( "rot" ) ) {
3974 final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
3975 PhylogenyMethods.preOrderReId( p7 );
3976 final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
3977 p7.getNode( "e" ) );
3978 if ( !r_7.getName().equals( "rott" ) ) {
3981 final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
3982 p7.getNode( "a" ) );
3983 if ( !r_71.getName().equals( "rott" ) ) {
3986 final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
3987 p7.getNode( "rott" ) );
3988 if ( !r_72.getName().equals( "rott" ) ) {
3991 final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
3992 p7.getNode( "a" ) );
3993 if ( !r_73.getName().equals( "rott" ) ) {
3996 final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
3997 p7.getNode( "rott" ) );
3998 if ( !r_74.getName().equals( "rott" ) ) {
4001 final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4002 p7.getNode( "e" ) );
4003 if ( !r_75.getName().equals( "e" ) ) {
4007 catch ( final Exception e ) {
4008 e.printStackTrace( System.out );
4014 private static boolean testHmmscanOutputParser() {
4015 final String test_dir = Test.PATH_TO_TEST_DATA;
4017 final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
4018 + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4020 final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
4021 + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4022 final List<Protein> proteins = parser2.parse();
4023 if ( parser2.getProteinsEncountered() != 4 ) {
4026 if ( proteins.size() != 4 ) {
4029 if ( parser2.getDomainsEncountered() != 69 ) {
4032 if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
4035 if ( parser2.getDomainsIgnoredDueToEval() != 0 ) {
4038 final Protein p1 = proteins.get( 0 );
4039 if ( p1.getNumberOfProteinDomains() != 15 ) {
4042 if ( p1.getLength() != 850 ) {
4045 final Protein p2 = proteins.get( 1 );
4046 if ( p2.getNumberOfProteinDomains() != 51 ) {
4049 if ( p2.getLength() != 1291 ) {
4052 final Protein p3 = proteins.get( 2 );
4053 if ( p3.getNumberOfProteinDomains() != 2 ) {
4056 final Protein p4 = proteins.get( 3 );
4057 if ( p4.getNumberOfProteinDomains() != 1 ) {
4060 if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
4063 if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
4066 if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
4069 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
4072 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
4075 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) {
4078 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) {
4081 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
4084 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
4088 catch ( final Exception e ) {
4089 e.printStackTrace( System.out );
4095 private static boolean testLastExternalNodeMethods() {
4097 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4098 final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
4099 final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
4100 final PhylogenyNode n1 = t0.getNode( "A" );
4101 if ( n1.isLastExternalNode() ) {
4104 final PhylogenyNode n2 = t0.getNode( "B" );
4105 if ( n2.isLastExternalNode() ) {
4108 final PhylogenyNode n3 = t0.getNode( "C" );
4109 if ( n3.isLastExternalNode() ) {
4112 final PhylogenyNode n4 = t0.getNode( "D" );
4113 if ( !n4.isLastExternalNode() ) {
4117 catch ( final Exception e ) {
4118 e.printStackTrace( System.out );
4124 private static boolean testLevelOrderIterator() {
4126 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4127 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
4128 PhylogenyNodeIterator it0;
4129 for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
4132 for( it0.reset(); it0.hasNext(); ) {
4135 final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
4136 if ( !it.next().getName().equals( "r" ) ) {
4139 if ( !it.next().getName().equals( "ab" ) ) {
4142 if ( !it.next().getName().equals( "cd" ) ) {
4145 if ( !it.next().getName().equals( "A" ) ) {
4148 if ( !it.next().getName().equals( "B" ) ) {
4151 if ( !it.next().getName().equals( "C" ) ) {
4154 if ( !it.next().getName().equals( "D" ) ) {
4157 if ( it.hasNext() ) {
4160 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",
4161 new NHXParser() )[ 0 ];
4162 PhylogenyNodeIterator it2;
4163 for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
4166 for( it2.reset(); it2.hasNext(); ) {
4169 final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
4170 if ( !it3.next().getName().equals( "r" ) ) {
4173 if ( !it3.next().getName().equals( "abc" ) ) {
4176 if ( !it3.next().getName().equals( "defg" ) ) {
4179 if ( !it3.next().getName().equals( "A" ) ) {
4182 if ( !it3.next().getName().equals( "B" ) ) {
4185 if ( !it3.next().getName().equals( "C" ) ) {
4188 if ( !it3.next().getName().equals( "D" ) ) {
4191 if ( !it3.next().getName().equals( "E" ) ) {
4194 if ( !it3.next().getName().equals( "F" ) ) {
4197 if ( !it3.next().getName().equals( "G" ) ) {
4200 if ( !it3.next().getName().equals( "1" ) ) {
4203 if ( !it3.next().getName().equals( "2" ) ) {
4206 if ( !it3.next().getName().equals( "3" ) ) {
4209 if ( !it3.next().getName().equals( "4" ) ) {
4212 if ( !it3.next().getName().equals( "5" ) ) {
4215 if ( !it3.next().getName().equals( "6" ) ) {
4218 if ( !it3.next().getName().equals( "f1" ) ) {
4221 if ( !it3.next().getName().equals( "f2" ) ) {
4224 if ( !it3.next().getName().equals( "f3" ) ) {
4227 if ( !it3.next().getName().equals( "a" ) ) {
4230 if ( !it3.next().getName().equals( "b" ) ) {
4233 if ( !it3.next().getName().equals( "f21" ) ) {
4236 if ( !it3.next().getName().equals( "X" ) ) {
4239 if ( !it3.next().getName().equals( "Y" ) ) {
4242 if ( !it3.next().getName().equals( "Z" ) ) {
4245 if ( it3.hasNext() ) {
4248 final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
4249 PhylogenyNodeIterator it4;
4250 for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
4253 for( it4.reset(); it4.hasNext(); ) {
4256 final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
4257 if ( !it5.next().getName().equals( "r" ) ) {
4260 if ( !it5.next().getName().equals( "A" ) ) {
4263 if ( !it5.next().getName().equals( "B" ) ) {
4266 if ( !it5.next().getName().equals( "C" ) ) {
4269 if ( !it5.next().getName().equals( "D" ) ) {
4272 final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
4273 PhylogenyNodeIterator it6;
4274 for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
4277 for( it6.reset(); it6.hasNext(); ) {
4280 final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
4281 if ( !it7.next().getName().equals( "A" ) ) {
4284 if ( it.hasNext() ) {
4288 catch ( final Exception e ) {
4289 e.printStackTrace( System.out );
4295 private static boolean testNodeRemoval() {
4297 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4298 final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
4299 PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
4300 if ( !t0.toNewHampshire().equals( "(a);" ) ) {
4303 final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
4304 PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
4305 if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
4308 final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
4309 PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
4310 if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
4314 catch ( final Exception e ) {
4315 e.printStackTrace( System.out );
4321 private static boolean testMidpointrooting() {
4323 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4324 final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
4325 PhylogenyMethods.midpointRoot( t0 );
4326 if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
4329 if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
4332 if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
4336 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",
4337 new NHXParser() )[ 0 ];
4338 if ( !t1.isRooted() ) {
4341 PhylogenyMethods.midpointRoot( t1 );
4342 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4345 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4348 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4351 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4354 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4357 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4360 t1.reRoot( t1.getNode( "A" ) );
4361 PhylogenyMethods.midpointRoot( t1 );
4362 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4365 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4368 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4371 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4374 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4378 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4382 catch ( final Exception e ) {
4383 e.printStackTrace( System.out );
4389 private static boolean testNexusCharactersParsing() {
4391 final NexusCharactersParser parser = new NexusCharactersParser();
4392 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
4394 String[] labels = parser.getCharStateLabels();
4395 if ( labels.length != 7 ) {
4398 if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4401 if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4404 if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4407 if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4410 if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4413 if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4416 if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4419 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4421 labels = parser.getCharStateLabels();
4422 if ( labels.length != 7 ) {
4425 if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4428 if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4431 if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4434 if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4437 if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4440 if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4443 if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4447 catch ( final Exception e ) {
4448 e.printStackTrace( System.out );
4454 private static boolean testNexusMatrixParsing() {
4456 final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
4457 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
4459 final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
4460 if ( m.getNumberOfCharacters() != 9 ) {
4463 if ( m.getNumberOfIdentifiers() != 5 ) {
4466 if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
4469 if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
4472 if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
4475 if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
4478 if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
4481 if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
4484 if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
4487 // if ( labels.length != 7 ) {
4490 // if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4493 // if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4496 // if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4499 // if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4502 // if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4505 // if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4508 // if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4511 // parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4513 // labels = parser.getCharStateLabels();
4514 // if ( labels.length != 7 ) {
4517 // if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4520 // if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4523 // if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4526 // if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4529 // if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4532 // if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4535 // if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4539 catch ( final Exception e ) {
4540 e.printStackTrace( System.out );
4546 private static boolean testNexusTreeParsing() {
4548 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4549 final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
4550 Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
4551 if ( phylogenies.length != 1 ) {
4554 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
4557 if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4561 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
4562 if ( phylogenies.length != 1 ) {
4565 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4568 if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
4572 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
4573 if ( phylogenies.length != 1 ) {
4576 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4579 if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4582 if ( phylogenies[ 0 ].isRooted() ) {
4586 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
4587 if ( phylogenies.length != 18 ) {
4590 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4593 if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
4596 if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
4599 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
4602 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
4605 if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
4608 if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
4611 if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
4614 if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
4617 if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
4620 if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
4623 if ( phylogenies[ 8 ].isRooted() ) {
4626 if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
4629 if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
4632 if ( !phylogenies[ 9 ].isRooted() ) {
4635 if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
4638 if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
4641 if ( !phylogenies[ 10 ].isRooted() ) {
4644 if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
4647 if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
4650 if ( phylogenies[ 11 ].isRooted() ) {
4653 if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
4656 if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
4659 if ( !phylogenies[ 12 ].isRooted() ) {
4662 if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
4665 if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
4668 if ( !phylogenies[ 13 ].isRooted() ) {
4671 if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
4674 if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
4677 if ( !phylogenies[ 14 ].isRooted() ) {
4680 if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
4683 if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
4686 if ( phylogenies[ 15 ].isRooted() ) {
4689 if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
4692 if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
4695 if ( !phylogenies[ 16 ].isRooted() ) {
4698 if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
4701 if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
4704 if ( phylogenies[ 17 ].isRooted() ) {
4707 if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
4711 catch ( final Exception e ) {
4712 e.printStackTrace( System.out );
4718 private static boolean testNexusTreeParsingIterating() {
4720 final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
4721 p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
4722 if ( !p.hasNext() ) {
4725 Phylogeny phy = p.next();
4726 if ( phy == null ) {
4729 if ( phy.getNumberOfExternalNodes() != 25 ) {
4732 if ( !phy.getName().equals( "" ) ) {
4735 if ( p.hasNext() ) {
4739 if ( phy != null ) {
4744 if ( !p.hasNext() ) {
4748 if ( phy == null ) {
4751 if ( phy.getNumberOfExternalNodes() != 25 ) {
4754 if ( !phy.getName().equals( "" ) ) {
4757 if ( p.hasNext() ) {
4761 if ( phy != null ) {
4765 p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
4766 if ( !p.hasNext() ) {
4770 if ( phy == null ) {
4773 if ( phy.getNumberOfExternalNodes() != 10 ) {
4776 if ( !phy.getName().equals( "name" ) ) {
4779 if ( p.hasNext() ) {
4783 if ( phy != null ) {
4788 if ( !p.hasNext() ) {
4792 if ( phy == null ) {
4795 if ( phy.getNumberOfExternalNodes() != 10 ) {
4798 if ( !phy.getName().equals( "name" ) ) {
4801 if ( p.hasNext() ) {
4805 if ( phy != null ) {
4809 p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
4810 if ( !p.hasNext() ) {
4814 if ( phy == null ) {
4817 if ( phy.getNumberOfExternalNodes() != 3 ) {
4820 if ( !phy.getName().equals( "" ) ) {
4823 if ( phy.isRooted() ) {
4826 if ( p.hasNext() ) {
4830 if ( phy != null ) {
4835 if ( !p.hasNext() ) {
4839 if ( phy == null ) {
4842 if ( phy.getNumberOfExternalNodes() != 3 ) {
4845 if ( !phy.getName().equals( "" ) ) {
4848 if ( p.hasNext() ) {
4852 if ( phy != null ) {
4856 p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
4857 // if ( phylogenies.length != 18 ) {
4861 if ( !p.hasNext() ) {
4865 if ( phy == null ) {
4868 if ( phy.getNumberOfExternalNodes() != 10 ) {
4871 if ( !phy.getName().equals( "tree 0" ) ) {
4875 if ( !p.hasNext() ) {
4879 if ( phy == null ) {
4882 if ( phy.getNumberOfExternalNodes() != 10 ) {
4885 if ( !phy.getName().equals( "tree 1" ) ) {
4889 if ( !p.hasNext() ) {
4893 if ( phy == null ) {
4896 if ( phy.getNumberOfExternalNodes() != 3 ) {
4899 if ( !phy.getName().equals( "" ) ) {
4902 if ( phy.isRooted() ) {
4906 if ( !p.hasNext() ) {
4910 if ( phy == null ) {
4913 if ( phy.getNumberOfExternalNodes() != 4 ) {
4916 if ( !phy.getName().equals( "" ) ) {
4919 if ( !phy.isRooted() ) {
4923 if ( !p.hasNext() ) {
4927 if ( phy == null ) {
4930 if ( phy.getNumberOfExternalNodes() != 5 ) {
4931 System.out.println( phy.getNumberOfExternalNodes() );
4934 if ( !phy.getName().equals( "" ) ) {
4937 if ( !phy.isRooted() ) {
4941 if ( !p.hasNext() ) {
4945 if ( phy == null ) {
4948 if ( phy.getNumberOfExternalNodes() != 3 ) {
4951 if ( !phy.getName().equals( "" ) ) {
4954 if ( phy.isRooted() ) {
4958 if ( !p.hasNext() ) {
4962 if ( phy == null ) {
4965 if ( phy.getNumberOfExternalNodes() != 2 ) {
4968 if ( !phy.getName().equals( "" ) ) {
4971 if ( !phy.isRooted() ) {
4975 if ( !p.hasNext() ) {
4979 if ( phy.getNumberOfExternalNodes() != 3 ) {
4982 if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
4985 if ( !phy.isRooted() ) {
4989 if ( !p.hasNext() ) {
4993 if ( phy.getNumberOfExternalNodes() != 3 ) {
4996 if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
4999 if ( !phy.getName().equals( "tree 8" ) ) {
5003 if ( !p.hasNext() ) {
5007 if ( phy.getNumberOfExternalNodes() != 3 ) {
5010 if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
5013 if ( !phy.getName().equals( "tree 9" ) ) {
5017 if ( !p.hasNext() ) {
5021 if ( phy.getNumberOfExternalNodes() != 3 ) {
5024 if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
5027 if ( !phy.getName().equals( "tree 10" ) ) {
5030 if ( !phy.isRooted() ) {
5034 if ( !p.hasNext() ) {
5038 if ( phy.getNumberOfExternalNodes() != 3 ) {
5041 if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
5044 if ( !phy.getName().equals( "tree 11" ) ) {
5047 if ( phy.isRooted() ) {
5051 if ( !p.hasNext() ) {
5055 if ( phy.getNumberOfExternalNodes() != 3 ) {
5058 if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
5061 if ( !phy.getName().equals( "tree 12" ) ) {
5064 if ( !phy.isRooted() ) {
5068 if ( !p.hasNext() ) {
5072 if ( phy.getNumberOfExternalNodes() != 3 ) {
5075 if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
5078 if ( !phy.getName().equals( "tree 13" ) ) {
5081 if ( !phy.isRooted() ) {
5085 if ( !p.hasNext() ) {
5089 if ( phy.getNumberOfExternalNodes() != 10 ) {
5090 System.out.println( phy.getNumberOfExternalNodes() );
5095 .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;" ) ) {
5096 System.out.println( phy.toNewHampshire() );
5099 if ( !phy.getName().equals( "tree 14" ) ) {
5102 if ( !phy.isRooted() ) {
5106 if ( !p.hasNext() ) {
5110 if ( phy.getNumberOfExternalNodes() != 10 ) {
5111 System.out.println( phy.getNumberOfExternalNodes() );
5116 .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;" ) ) {
5117 System.out.println( phy.toNewHampshire() );
5120 if ( !phy.getName().equals( "tree 15" ) ) {
5123 if ( phy.isRooted() ) {
5127 if ( !p.hasNext() ) {
5131 if ( phy.getNumberOfExternalNodes() != 10 ) {
5132 System.out.println( phy.getNumberOfExternalNodes() );
5137 .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;" ) ) {
5138 System.out.println( phy.toNewHampshire() );
5141 if ( !phy.getName().equals( "tree 16" ) ) {
5144 if ( !phy.isRooted() ) {
5148 if ( !p.hasNext() ) {
5152 if ( phy.getNumberOfExternalNodes() != 10 ) {
5153 System.out.println( phy.getNumberOfExternalNodes() );
5158 .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;" ) ) {
5159 System.out.println( phy.toNewHampshire() );
5162 if ( !phy.getName().equals( "tree 17" ) ) {
5165 if ( phy.isRooted() ) {
5169 if ( p.hasNext() ) {
5173 if ( phy != null ) {
5178 if ( !p.hasNext() ) {
5182 if ( phy == null ) {
5185 if ( phy.getNumberOfExternalNodes() != 10 ) {
5188 if ( !phy.getName().equals( "tree 0" ) ) {
5192 if ( !p.hasNext() ) {
5196 if ( phy == null ) {
5199 if ( phy.getNumberOfExternalNodes() != 10 ) {
5202 if ( !phy.getName().equals( "tree 1" ) ) {
5206 if ( !p.hasNext() ) {
5210 if ( phy == null ) {
5213 if ( phy.getNumberOfExternalNodes() != 3 ) {
5216 if ( !phy.getName().equals( "" ) ) {
5219 if ( phy.isRooted() ) {
5223 if ( !p.hasNext() ) {
5227 if ( phy == null ) {
5230 if ( phy.getNumberOfExternalNodes() != 4 ) {
5233 if ( !phy.getName().equals( "" ) ) {
5236 if ( !phy.isRooted() ) {
5240 if ( !p.hasNext() ) {
5244 if ( phy == null ) {
5247 if ( phy.getNumberOfExternalNodes() != 5 ) {
5248 System.out.println( phy.getNumberOfExternalNodes() );
5251 if ( !phy.getName().equals( "" ) ) {
5254 if ( !phy.isRooted() ) {
5258 if ( !p.hasNext() ) {
5262 if ( phy == null ) {
5265 if ( phy.getNumberOfExternalNodes() != 3 ) {
5268 if ( !phy.getName().equals( "" ) ) {
5271 if ( phy.isRooted() ) {
5275 catch ( final Exception e ) {
5276 e.printStackTrace( System.out );
5282 private static boolean testNexusTreeParsingTranslating() {
5284 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5285 final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
5286 Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
5287 if ( phylogenies.length != 1 ) {
5290 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5293 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5296 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5299 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5302 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5303 .equals( "Aranaeus" ) ) {
5307 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
5308 if ( phylogenies.length != 3 ) {
5311 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5314 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5317 if ( phylogenies[ 0 ].isRooted() ) {
5320 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5323 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5326 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5327 .equals( "Aranaeus" ) ) {
5330 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
5333 if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
5336 if ( phylogenies[ 1 ].isRooted() ) {
5339 if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5342 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5345 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5346 .equals( "Aranaeus" ) ) {
5349 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
5352 if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
5355 if ( !phylogenies[ 2 ].isRooted() ) {
5358 if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5361 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5364 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5365 .equals( "Aranaeus" ) ) {
5369 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
5370 if ( phylogenies.length != 3 ) {
5373 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5376 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5379 if ( phylogenies[ 0 ].isRooted() ) {
5382 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5385 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5388 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5389 .equals( "Aranaeus" ) ) {
5392 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
5395 if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
5398 if ( phylogenies[ 1 ].isRooted() ) {
5401 if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5404 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5407 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5408 .equals( "Aranaeus" ) ) {
5411 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
5414 if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
5417 if ( !phylogenies[ 2 ].isRooted() ) {
5420 if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5423 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5426 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5427 .equals( "Aranaeus" ) ) {
5431 catch ( final Exception e ) {
5432 e.printStackTrace( System.out );
5438 private static boolean testNHParsing() {
5440 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5441 final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
5442 if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
5445 final NHXParser nhxp = new NHXParser();
5446 nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
5447 nhxp.setReplaceUnderscores( true );
5448 final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
5449 if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
5452 if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
5455 final Phylogeny p1b = factory
5456 .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 ",
5457 new NHXParser() )[ 0 ];
5458 if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
5461 if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
5464 final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
5465 final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
5466 final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
5467 final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
5468 final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
5469 final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
5470 final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
5471 final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
5472 final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
5473 final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
5474 final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1 3 ; \n)\t ( \n ;"
5475 + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
5476 + "; ; ( \t\n\r\b; G ;, ;H ;1 3; ) ; ; ;",
5478 if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
5481 if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
5484 if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
5487 if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
5490 final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
5491 final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
5492 final String p16_S = "((A,B),C)";
5493 final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
5494 if ( p16.length != 1 ) {
5497 if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
5500 final String p17_S = "(C,(A,B))";
5501 final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
5502 if ( p17.length != 1 ) {
5505 if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
5508 final String p18_S = "((A,B),(C,D))";
5509 final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
5510 if ( p18.length != 1 ) {
5513 if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
5516 final String p19_S = "(((A,B),C),D)";
5517 final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
5518 if ( p19.length != 1 ) {
5521 if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
5524 final String p20_S = "(A,(B,(C,D)))";
5525 final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
5526 if ( p20.length != 1 ) {
5529 if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
5532 final String p21_S = "(A,(B,(C,(D,E))))";
5533 final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
5534 if ( p21.length != 1 ) {
5537 if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
5540 final String p22_S = "((((A,B),C),D),E)";
5541 final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
5542 if ( p22.length != 1 ) {
5545 if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
5548 final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5549 final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
5550 if ( p23.length != 1 ) {
5551 System.out.println( "xl=" + p23.length );
5555 if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
5558 final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5559 final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
5560 if ( p24.length != 1 ) {
5563 if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
5566 final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5567 final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5568 final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
5569 if ( p241.length != 2 ) {
5572 if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
5575 if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
5578 final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
5579 + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
5580 + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
5581 + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
5582 + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
5583 + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
5584 + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
5585 + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
5586 final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
5587 if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
5590 final String p26_S = "(A,B)ab";
5591 final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
5592 if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
5595 final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5596 final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
5597 if ( p27s.length != 1 ) {
5598 System.out.println( "xxl=" + p27s.length );
5602 if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
5603 System.out.println( p27s[ 0 ].toNewHampshireX() );
5607 final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
5609 if ( p27.length != 1 ) {
5610 System.out.println( "yl=" + p27.length );
5614 if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
5615 System.out.println( p27[ 0 ].toNewHampshireX() );
5619 final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5620 final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5621 final String p28_S3 = "(A,B)ab";
5622 final String p28_S4 = "((((A,B),C),D),;E;)";
5623 final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
5625 if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
5628 if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
5631 if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
5634 if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
5637 if ( p28.length != 4 ) {
5640 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";
5641 final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
5642 if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
5645 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";
5646 final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
5647 if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
5650 final String p32_S = " ; ; \n \t \b \f \r ;;;;;; ";
5651 final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
5652 if ( ( p32.length != 0 ) ) {
5655 final String p33_S = "A";
5656 final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
5657 if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
5660 final String p34_S = "B;";
5661 final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
5662 if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
5665 final String p35_S = "B:0.2";
5666 final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
5667 if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
5670 final String p36_S = "(A)";
5671 final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
5672 if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
5675 final String p37_S = "((A))";
5676 final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
5677 if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
5680 final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
5681 final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
5682 if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
5685 final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
5686 final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
5687 if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
5690 final String p40_S = "(A,B,C)";
5691 final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
5692 if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
5695 final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
5696 final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
5697 if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
5700 final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
5701 final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
5702 if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
5705 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)";
5706 final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
5707 if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
5710 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)))";
5711 final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
5712 if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
5715 final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
5716 final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
5717 if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
5720 final String p46_S = "";
5721 final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
5722 if ( p46.length != 0 ) {
5725 final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
5726 if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5729 final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5730 if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5733 final Phylogeny p49 = factory
5734 .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
5735 new NHXParser() )[ 0 ];
5736 if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5739 final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5740 if ( p50.getNode( "A" ) == null ) {
5743 if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
5744 .equals( "((A,B)ab:2.0[88],C);" ) ) {
5747 if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
5750 if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
5751 .equals( "((A,B)88:2.0,C);" ) ) {
5754 final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5755 if ( p51.getNode( "A(A" ) == null ) {
5758 final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5759 if ( p52.getNode( "A(A" ) == null ) {
5762 final Phylogeny p53 = factory
5763 .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
5764 new NHXParser() )[ 0 ];
5765 if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
5769 final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
5770 if ( p54.getNode( "A" ) == null ) {
5773 if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
5774 .equals( "((A,B)[88],C);" ) ) {
5778 catch ( final Exception e ) {
5779 e.printStackTrace( System.out );
5785 private static boolean testNHParsingIter() {
5787 final String p0_str = "(A,B);";
5788 final NHXParser p = new NHXParser();
5789 p.setSource( p0_str );
5790 if ( !p.hasNext() ) {
5793 final Phylogeny p0 = p.next();
5794 if ( !p0.toNewHampshire().equals( p0_str ) ) {
5795 System.out.println( p0.toNewHampshire() );
5798 if ( p.hasNext() ) {
5801 if ( p.next() != null ) {
5805 final String p00_str = "(A,B)root;";
5806 p.setSource( p00_str );
5807 final Phylogeny p00 = p.next();
5808 if ( !p00.toNewHampshire().equals( p00_str ) ) {
5809 System.out.println( p00.toNewHampshire() );
5813 final String p000_str = "A;";
5814 p.setSource( p000_str );
5815 final Phylogeny p000 = p.next();
5816 if ( !p000.toNewHampshire().equals( p000_str ) ) {
5817 System.out.println( p000.toNewHampshire() );
5821 final String p0000_str = "A";
5822 p.setSource( p0000_str );
5823 final Phylogeny p0000 = p.next();
5824 if ( !p0000.toNewHampshire().equals( "A;" ) ) {
5825 System.out.println( p0000.toNewHampshire() );
5829 p.setSource( "(A)" );
5830 final Phylogeny p00000 = p.next();
5831 if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
5832 System.out.println( p00000.toNewHampshire() );
5836 final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
5837 p.setSource( p1_str );
5838 if ( !p.hasNext() ) {
5841 final Phylogeny p1_0 = p.next();
5842 if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
5843 System.out.println( p1_0.toNewHampshire() );
5846 if ( !p.hasNext() ) {
5849 final Phylogeny p1_1 = p.next();
5850 if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
5851 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
5854 if ( !p.hasNext() ) {
5857 final Phylogeny p1_2 = p.next();
5858 if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
5859 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
5862 if ( !p.hasNext() ) {
5865 final Phylogeny p1_3 = p.next();
5866 if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
5867 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
5870 if ( p.hasNext() ) {
5873 if ( p.next() != null ) {
5877 final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
5878 p.setSource( p2_str );
5879 if ( !p.hasNext() ) {
5882 Phylogeny p2_0 = p.next();
5883 if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
5884 System.out.println( p2_0.toNewHampshire() );
5887 if ( !p.hasNext() ) {
5890 Phylogeny p2_1 = p.next();
5891 if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
5892 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
5895 if ( !p.hasNext() ) {
5898 Phylogeny p2_2 = p.next();
5899 if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
5900 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
5903 if ( !p.hasNext() ) {
5906 Phylogeny p2_3 = p.next();
5907 if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
5908 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
5911 if ( !p.hasNext() ) {
5914 Phylogeny p2_4 = p.next();
5915 if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
5916 System.out.println( "(X) != " + p2_4.toNewHampshire() );
5919 if ( p.hasNext() ) {
5922 if ( p.next() != null ) {
5927 if ( !p.hasNext() ) {
5931 if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
5932 System.out.println( p2_0.toNewHampshire() );
5935 if ( !p.hasNext() ) {
5939 if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
5940 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
5943 if ( !p.hasNext() ) {
5947 if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
5948 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
5951 if ( !p.hasNext() ) {
5955 if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
5956 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
5959 if ( !p.hasNext() ) {
5963 if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
5964 System.out.println( "(X) != " + p2_4.toNewHampshire() );
5967 if ( p.hasNext() ) {
5970 if ( p.next() != null ) {
5974 final String p3_str = "((A,B),C)abc";
5975 p.setSource( p3_str );
5976 if ( !p.hasNext() ) {
5979 final Phylogeny p3_0 = p.next();
5980 if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
5983 if ( p.hasNext() ) {
5986 if ( p.next() != null ) {
5990 final String p4_str = "((A,B)ab,C)abc";
5991 p.setSource( p4_str );
5992 if ( !p.hasNext() ) {
5995 final Phylogeny p4_0 = p.next();
5996 if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
5999 if ( p.hasNext() ) {
6002 if ( p.next() != null ) {
6006 final String p5_str = "(((A,B)ab,C)abc,D)abcd";
6007 p.setSource( p5_str );
6008 if ( !p.hasNext() ) {
6011 final Phylogeny p5_0 = p.next();
6012 if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
6015 if ( p.hasNext() ) {
6018 if ( p.next() != null ) {
6022 final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
6023 p.setSource( p6_str );
6024 if ( !p.hasNext() ) {
6027 Phylogeny p6_0 = p.next();
6028 if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
6031 if ( p.hasNext() ) {
6034 if ( p.next() != null ) {
6038 if ( !p.hasNext() ) {
6042 if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
6045 if ( p.hasNext() ) {
6048 if ( p.next() != null ) {
6052 final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6053 p.setSource( p7_str );
6054 if ( !p.hasNext() ) {
6057 Phylogeny p7_0 = p.next();
6058 if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6061 if ( p.hasNext() ) {
6064 if ( p.next() != null ) {
6068 if ( !p.hasNext() ) {
6072 if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6075 if ( p.hasNext() ) {
6078 if ( p.next() != null ) {
6082 final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
6083 p.setSource( p8_str );
6084 if ( !p.hasNext() ) {
6087 Phylogeny p8_0 = p.next();
6088 if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6091 if ( !p.hasNext() ) {
6094 if ( !p.hasNext() ) {
6097 Phylogeny p8_1 = p.next();
6098 if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
6101 if ( p.hasNext() ) {
6104 if ( p.next() != null ) {
6108 if ( !p.hasNext() ) {
6112 if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6115 if ( !p.hasNext() ) {
6119 if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
6122 if ( p.hasNext() ) {
6125 if ( p.next() != null ) {
6131 if ( p.hasNext() ) {
6135 p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
6136 if ( !p.hasNext() ) {
6139 Phylogeny p_27 = p.next();
6140 if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
6141 System.out.println( p_27.toNewHampshireX() );
6145 if ( p.hasNext() ) {
6148 if ( p.next() != null ) {
6152 if ( !p.hasNext() ) {
6156 if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
6157 System.out.println( p_27.toNewHampshireX() );
6161 if ( p.hasNext() ) {
6164 if ( p.next() != null ) {
6168 catch ( final Exception e ) {
6169 e.printStackTrace( System.out );
6175 private static boolean testNHXconversion() {
6177 final PhylogenyNode n1 = new PhylogenyNode();
6178 final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
6179 final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
6180 final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
6181 final PhylogenyNode n5 = PhylogenyNode
6182 .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
6183 final PhylogenyNode n6 = PhylogenyNode
6184 .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
6185 if ( !n1.toNewHampshireX().equals( "" ) ) {
6188 if ( !n2.toNewHampshireX().equals( "" ) ) {
6191 if ( !n3.toNewHampshireX().equals( "n3" ) ) {
6194 if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
6197 if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
6200 if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
6201 System.out.println( n6.toNewHampshireX() );
6205 catch ( final Exception e ) {
6206 e.printStackTrace( System.out );
6212 private static boolean testTaxonomyExtraction() {
6214 final PhylogenyNode n0 = PhylogenyNode
6215 .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6216 if ( n0.getNodeData().isHasTaxonomy() ) {
6219 final PhylogenyNode n1 = PhylogenyNode
6220 .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6221 if ( n1.getNodeData().isHasTaxonomy() ) {
6222 System.out.println( n1.toString() );
6225 final PhylogenyNode n2 = PhylogenyNode
6226 .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.AGRESSIVE );
6227 if ( !n2.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6228 System.out.println( n2.toString() );
6231 final PhylogenyNode n2x = PhylogenyNode
6232 .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6233 if ( n2x.getNodeData().isHasTaxonomy() ) {
6236 final PhylogenyNode n3 = PhylogenyNode
6237 .createInstanceFromNhxString( "blag_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6238 if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6239 System.out.println( n3.toString() );
6242 final PhylogenyNode n4 = PhylogenyNode
6243 .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6244 if ( n4.getNodeData().isHasTaxonomy() ) {
6245 System.out.println( n4.toString() );
6248 final PhylogenyNode n5 = PhylogenyNode
6249 .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6250 if ( n5.getNodeData().isHasTaxonomy() ) {
6251 System.out.println( n5.toString() );
6254 final PhylogenyNode n6 = PhylogenyNode
6255 .createInstanceFromNhxString( "blag-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6256 if ( n6.getNodeData().isHasTaxonomy() ) {
6257 System.out.println( n6.toString() );
6260 final PhylogenyNode n7 = PhylogenyNode
6261 .createInstanceFromNhxString( "blag-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6262 if ( n7.getNodeData().isHasTaxonomy() ) {
6263 System.out.println( n7.toString() );
6266 final PhylogenyNode n8 = PhylogenyNode
6267 .createInstanceFromNhxString( "blag_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6268 if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6269 System.out.println( n8.toString() );
6272 final PhylogenyNode n9 = PhylogenyNode
6273 .createInstanceFromNhxString( "blag_12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6274 if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6275 System.out.println( n9.toString() );
6278 final PhylogenyNode n10x = PhylogenyNode
6279 .createInstanceFromNhxString( "blag_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6280 if ( n10x.getNodeData().isHasTaxonomy() ) {
6281 System.out.println( n10x.toString() );
6284 final PhylogenyNode n10xx = PhylogenyNode
6285 .createInstanceFromNhxString( "blag_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6286 if ( n10xx.getNodeData().isHasTaxonomy() ) {
6287 System.out.println( n10xx.toString() );
6290 final PhylogenyNode n10 = PhylogenyNode
6291 .createInstanceFromNhxString( "blag_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6292 if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
6293 System.out.println( n10.toString() );
6296 final PhylogenyNode n11 = PhylogenyNode
6297 .createInstanceFromNhxString( "blag_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6298 if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
6299 System.out.println( n11.toString() );
6302 final PhylogenyNode n12 = PhylogenyNode
6303 .createInstanceFromNhxString( "blag_Mus_musculus_musculus",
6304 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6305 if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
6306 System.out.println( n12.toString() );
6309 final PhylogenyNode n13 = PhylogenyNode
6310 .createInstanceFromNhxString( "blag_Mus_musculus1",
6311 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6312 if ( n13.getNodeData().isHasTaxonomy() ) {
6313 System.out.println( n13.toString() );
6316 final PhylogenyNode n14 = PhylogenyNode
6317 .createInstanceFromNhxString( "blag_Mus_musculus_11",
6318 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6319 if ( n14.getNodeData().isHasTaxonomy() ) {
6320 System.out.println( n14.toString() );
6323 final PhylogenyNode n15 = PhylogenyNode
6324 .createInstanceFromNhxString( "blag_Mus_musculus_v11",
6325 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6326 if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus v11" ) ) {
6327 System.out.println( n15.toString() );
6330 final PhylogenyNode n16 = PhylogenyNode
6331 .createInstanceFromNhxString( "blag_Mus_musculus_/11",
6332 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6333 if ( n16.getNodeData().isHasTaxonomy() ) {
6334 System.out.println( n16.toString() );
6337 final PhylogenyNode n17 = PhylogenyNode
6338 .createInstanceFromNhxString( "blag_Mus_musculus_v",
6339 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6340 if ( n17.getNodeData().isHasTaxonomy() ) {
6341 System.out.println( n17.toString() );
6345 catch ( final Exception e ) {
6346 e.printStackTrace( System.out );
6352 private static boolean testNHXNodeParsing() {
6354 final PhylogenyNode n1 = new PhylogenyNode();
6355 final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
6356 final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
6357 final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
6358 final PhylogenyNode n5 = PhylogenyNode
6359 .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]" );
6360 if ( !n3.getName().equals( "n3" ) ) {
6363 if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6366 if ( n3.isDuplication() ) {
6369 if ( n3.isHasAssignedEvent() ) {
6372 if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
6375 if ( !n4.getName().equals( "n4" ) ) {
6378 if ( n4.getDistanceToParent() != 0.01 ) {
6381 if ( !n5.getName().equals( "n5" ) ) {
6384 if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
6387 if ( n5.getDistanceToParent() != 0.1 ) {
6390 if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
6393 if ( !n5.isDuplication() ) {
6396 if ( !n5.isHasAssignedEvent() ) {
6399 final PhylogenyNode n8 = PhylogenyNode
6400 .createInstanceFromNhxString( "n8_ECOLI/12:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6401 if ( !n8.getName().equals( "n8_ECOLI/12" ) ) {
6404 if ( PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
6407 final PhylogenyNode n9 = PhylogenyNode
6408 .createInstanceFromNhxString( "n9_ECOLI/12=12:0.01",
6409 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6410 if ( !n9.getName().equals( "n9_ECOLI/12=12" ) ) {
6413 if ( PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
6416 final PhylogenyNode n10 = PhylogenyNode
6417 .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6418 if ( !n10.getName().equals( "n10.ECOLI" ) ) {
6421 final PhylogenyNode n20 = PhylogenyNode
6422 .createInstanceFromNhxString( "n20_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6423 if ( !n20.getName().equals( "n20_ECOLI/1-2" ) ) {
6426 if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
6429 final PhylogenyNode n20x = PhylogenyNode
6430 .createInstanceFromNhxString( "n20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6431 if ( !n20x.getName().equals( "n20_ECOL1/1-2" ) ) {
6434 if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
6437 final PhylogenyNode n20xx = PhylogenyNode
6438 .createInstanceFromNhxString( "n20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6439 if ( !n20xx.getName().equals( "n20_eCOL1/1-2" ) ) {
6442 if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
6445 final PhylogenyNode n20xxx = PhylogenyNode
6446 .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6447 if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
6450 if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
6453 final PhylogenyNode n20xxxx = PhylogenyNode
6454 .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6455 if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
6458 if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
6461 final PhylogenyNode n21 = PhylogenyNode
6462 .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6463 if ( !n21.getName().equals( "n21_PIG" ) ) {
6466 if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
6469 final PhylogenyNode n21x = PhylogenyNode
6470 .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6471 if ( !n21x.getName().equals( "n21_PIG" ) ) {
6474 if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
6477 final PhylogenyNode n22 = PhylogenyNode
6478 .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6479 if ( !n22.getName().equals( "n22/PIG" ) ) {
6482 if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
6485 final PhylogenyNode n23 = PhylogenyNode
6486 .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6487 if ( !n23.getName().equals( "n23/PIG_1" ) ) {
6490 if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
6493 final PhylogenyNode a = PhylogenyNode
6494 .createInstanceFromNhxString( "n10_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6495 if ( !a.getName().equals( "n10_ECOLI/1-2" ) ) {
6498 if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
6501 final PhylogenyNode b = PhylogenyNode
6502 .createInstanceFromNhxString( "n10_ECOLI1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6503 if ( !b.getName().equals( "n10_ECOLI1/1-2" ) ) {
6506 if ( PhylogenyMethods.getSpecies( b ).equals( "ECOLI" ) ) {
6509 final PhylogenyNode c = PhylogenyNode
6510 .createInstanceFromNhxString( "n10_RATAF12/1000-2000",
6511 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6512 if ( !c.getName().equals( "n10_RATAF12/1000-2000" ) ) {
6515 if ( PhylogenyMethods.getSpecies( c ).equals( "RATAF" ) ) {
6518 final PhylogenyNode c1 = PhylogenyNode
6519 .createInstanceFromNhxString( "n10_BOVIN_1/1000-2000",
6520 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6521 if ( !c1.getName().equals( "n10_BOVIN_1/1000-2000" ) ) {
6524 if ( PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
6527 final PhylogenyNode c2 = PhylogenyNode
6528 .createInstanceFromNhxString( "n10_Bovin_1/1000-2000",
6529 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6530 if ( !c2.getName().equals( "n10_Bovin_1/1000-2000" ) ) {
6533 if ( !PhylogenyMethods.getSpecies( c2 ).equals( "" ) ) {
6536 final PhylogenyNode d = PhylogenyNode
6537 .createInstanceFromNhxString( "n10_RAT1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6538 if ( !d.getName().equals( "n10_RAT1/1-2" ) ) {
6541 if ( PhylogenyMethods.getSpecies( d ).equals( "RAT" ) ) {
6544 final PhylogenyNode e = PhylogenyNode
6545 .createInstanceFromNhxString( "n10_RAT1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6546 if ( !e.getName().equals( "n10_RAT1" ) ) {
6549 if ( !ForesterUtil.isEmpty( PhylogenyMethods.getSpecies( e ) ) ) {
6552 final PhylogenyNode e2 = PhylogenyNode
6553 .createInstanceFromNhxString( "n10_RAT1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6554 if ( !e2.getName().equals( "n10_RAT1" ) ) {
6557 if ( PhylogenyMethods.getSpecies( e2 ).equals( "RAT" ) ) {
6560 final PhylogenyNode e3 = PhylogenyNode
6561 .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6562 if ( !e3.getName().equals( "n10_RAT~" ) ) {
6565 if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
6568 final PhylogenyNode n11 = PhylogenyNode
6569 .createInstanceFromNhxString( "n111111_ECOLI/jdj:0.4",
6570 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6571 if ( !n11.getName().equals( "n111111_ECOLI/jdj" ) ) {
6574 if ( n11.getDistanceToParent() != 0.4 ) {
6577 if ( PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
6580 final PhylogenyNode n12 = PhylogenyNode
6581 .createInstanceFromNhxString( "n111111-ECOLI---/jdj:0.4",
6582 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6583 if ( !n12.getName().equals( "n111111-ECOLI---/jdj" ) ) {
6586 if ( n12.getDistanceToParent() != 0.4 ) {
6589 if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
6592 final PhylogenyNode m = PhylogenyNode
6593 .createInstanceFromNhxString( "n10_MOUSEa", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6594 if ( !m.getName().equals( "n10_MOUSEa" ) ) {
6597 if ( PhylogenyMethods.getSpecies( m ).equals( "MOUSE" ) ) {
6600 final PhylogenyNode o = PhylogenyNode
6601 .createInstanceFromNhxString( "n10_MOUSE_", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6602 if ( !o.getName().equals( "n10_MOUSE_" ) ) {
6605 if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
6608 if ( n1.getName().compareTo( "" ) != 0 ) {
6611 if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
6614 if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6617 if ( n2.getName().compareTo( "" ) != 0 ) {
6620 if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
6623 if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6626 final PhylogenyNode n00 = PhylogenyNode
6627 .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
6628 if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
6631 if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
6634 final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
6635 if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
6638 final PhylogenyNode n13 = PhylogenyNode
6639 .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.AGRESSIVE );
6640 if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
6643 if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
6646 if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6649 if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6652 final PhylogenyNode n14 = PhylogenyNode
6653 .createInstanceFromNhxString( "blah_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6654 if ( !n14.getName().equals( "blah_9QX45/1-2" ) ) {
6657 if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
6660 final PhylogenyNode n15 = PhylogenyNode
6661 .createInstanceFromNhxString( "something_wicked[123]",
6662 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6663 if ( !n15.getName().equals( "something_wicked" ) ) {
6666 if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
6669 if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
6672 final PhylogenyNode n16 = PhylogenyNode
6673 .createInstanceFromNhxString( "something_wicked2[9]",
6674 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6675 if ( !n16.getName().equals( "something_wicked2" ) ) {
6678 if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
6681 if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
6684 final PhylogenyNode n17 = PhylogenyNode
6685 .createInstanceFromNhxString( "something_wicked3[a]",
6686 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6687 if ( !n17.getName().equals( "something_wicked3" ) ) {
6690 if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
6693 final PhylogenyNode n18 = PhylogenyNode
6694 .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6695 if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
6698 if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
6701 if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
6704 final PhylogenyNode n19 = PhylogenyNode
6705 .createInstanceFromNhxString( "blah_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6706 if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
6709 if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6712 final PhylogenyNode n30 = PhylogenyNode
6713 .createInstanceFromNhxString( "blah_1234567-roejojoej",
6714 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6715 if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
6718 if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6721 final PhylogenyNode n31 = PhylogenyNode
6722 .createInstanceFromNhxString( "blah_12345678-roejojoej",
6723 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6724 if ( n31.getNodeData().isHasTaxonomy() ) {
6727 final PhylogenyNode n32 = PhylogenyNode
6728 .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6729 if ( n32.getNodeData().isHasTaxonomy() ) {
6733 catch ( final Exception e ) {
6734 e.printStackTrace( System.out );
6740 private static boolean testNHXParsing() {
6742 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6743 final Phylogeny p1 = factory.create( "(A [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
6744 if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
6747 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]";
6748 final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
6749 if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6752 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]";
6753 final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
6754 if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
6757 final Phylogeny[] p3 = factory
6758 .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]",
6760 if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6763 final Phylogeny[] p4 = factory
6764 .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(]",
6766 if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6769 final Phylogeny[] p5 = factory
6770 .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(((]",
6772 if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6775 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)";
6776 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)";
6777 final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
6778 if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
6781 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)))";
6782 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)))";
6783 final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
6784 if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
6787 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]) ))[,,, ])))))))";
6788 final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
6789 final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
6790 if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
6793 final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
6794 if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
6797 final Phylogeny p10 = factory
6798 .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]",
6799 new NHXParser() )[ 0 ];
6800 if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
6804 catch ( final Exception e ) {
6805 e.printStackTrace( System.out );
6811 private static boolean testNHXParsingQuotes() {
6813 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6814 final NHXParser p = new NHXParser();
6815 final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
6816 if ( phylogenies_0.length != 5 ) {
6819 final Phylogeny phy = phylogenies_0[ 4 ];
6820 if ( phy.getNumberOfExternalNodes() != 7 ) {
6823 if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
6826 if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
6829 if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
6830 .getScientificName().equals( "hsapiens" ) ) {
6833 if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
6836 if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
6839 if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
6842 if ( phy.getNodes( "noquotes" ).size() != 1 ) {
6845 if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
6848 final NHXParser p1p = new NHXParser();
6849 p1p.setIgnoreQuotes( true );
6850 final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
6851 if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
6854 final NHXParser p2p = new NHXParser();
6855 p1p.setIgnoreQuotes( false );
6856 final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
6857 if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
6860 final NHXParser p3p = new NHXParser();
6861 p3p.setIgnoreQuotes( false );
6862 final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
6863 if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
6866 final NHXParser p4p = new NHXParser();
6867 p4p.setIgnoreQuotes( false );
6868 final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
6869 if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
6872 final Phylogeny p10 = factory
6873 .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]",
6874 new NHXParser() )[ 0 ];
6875 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]";
6876 if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
6879 final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
6880 if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
6884 final Phylogeny p12 = factory
6885 .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]",
6886 new NHXParser() )[ 0 ];
6887 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]";
6888 if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
6891 final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
6892 if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
6895 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;";
6896 if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
6899 final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
6900 if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
6904 catch ( final Exception e ) {
6905 e.printStackTrace( System.out );
6911 private static boolean testNHXParsingMB() {
6913 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6914 final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
6915 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6916 + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
6917 + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
6918 + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
6919 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6920 + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
6921 + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
6922 + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
6923 if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
6926 if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
6929 if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
6930 0.1100000000000000e+00 ) ) {
6933 if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
6936 if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
6939 final Phylogeny p2 = factory
6940 .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
6941 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6942 + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
6943 + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
6944 + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
6945 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6946 + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
6947 + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
6948 + "7.369400000000000e-02}])",
6949 new NHXParser() )[ 0 ];
6950 if ( p2.getNode( "1" ) == null ) {
6953 if ( p2.getNode( "2" ) == null ) {
6957 catch ( final Exception e ) {
6958 e.printStackTrace( System.out );
6965 private static boolean testPhylogenyBranch() {
6967 final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
6968 final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
6969 final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
6970 final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
6971 if ( !a1b1.equals( a1b1 ) ) {
6974 if ( !a1b1.equals( b1a1 ) ) {
6977 if ( !b1a1.equals( a1b1 ) ) {
6980 final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
6981 final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
6982 final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
6983 if ( a1_b1.equals( b1_a1 ) ) {
6986 if ( a1_b1.equals( a1_b1_ ) ) {
6989 final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
6990 if ( !a1_b1.equals( b1_a1_ ) ) {
6993 if ( a1_b1_.equals( b1_a1_ ) ) {
6996 if ( !a1_b1_.equals( b1_a1 ) ) {
7000 catch ( final Exception e ) {
7001 e.printStackTrace( System.out );
7007 private static boolean testPhyloXMLparsingOfDistributionElement() {
7009 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7010 PhyloXmlParser xml_parser = null;
7012 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
7014 catch ( final Exception e ) {
7015 // Do nothing -- means were not running from jar.
7017 if ( xml_parser == null ) {
7018 xml_parser = new PhyloXmlParser();
7019 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
7020 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
7023 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
7026 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
7028 if ( xml_parser.getErrorCount() > 0 ) {
7029 System.out.println( xml_parser.getErrorMessages().toString() );
7032 if ( phylogenies_0.length != 1 ) {
7035 final Phylogeny t1 = phylogenies_0[ 0 ];
7036 PhylogenyNode n = null;
7037 Distribution d = null;
7038 n = t1.getNode( "root node" );
7039 if ( !n.getNodeData().isHasDistribution() ) {
7042 if ( n.getNodeData().getDistributions().size() != 1 ) {
7045 d = n.getNodeData().getDistribution();
7046 if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
7049 if ( d.getPoints().size() != 1 ) {
7052 if ( d.getPolygons() != null ) {
7055 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
7058 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7061 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7064 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
7067 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
7070 n = t1.getNode( "node a" );
7071 if ( !n.getNodeData().isHasDistribution() ) {
7074 if ( n.getNodeData().getDistributions().size() != 2 ) {
7077 d = n.getNodeData().getDistribution( 1 );
7078 if ( !d.getDesc().equals( "San Diego" ) ) {
7081 if ( d.getPoints().size() != 1 ) {
7084 if ( d.getPolygons() != null ) {
7087 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
7090 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7093 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7096 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
7099 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
7102 n = t1.getNode( "node bb" );
7103 if ( !n.getNodeData().isHasDistribution() ) {
7106 if ( n.getNodeData().getDistributions().size() != 1 ) {
7109 d = n.getNodeData().getDistribution( 0 );
7110 if ( d.getPoints().size() != 3 ) {
7113 if ( d.getPolygons().size() != 2 ) {
7116 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
7119 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
7122 if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
7125 if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
7128 if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
7131 if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
7134 Polygon p = d.getPolygons().get( 0 );
7135 if ( p.getPoints().size() != 3 ) {
7138 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
7141 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
7144 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7147 if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
7150 if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
7153 if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
7156 p = d.getPolygons().get( 1 );
7157 if ( p.getPoints().size() != 3 ) {
7160 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
7163 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
7166 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7170 final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
7171 final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
7172 if ( rt.length != 1 ) {
7175 final Phylogeny t1_rt = rt[ 0 ];
7176 n = t1_rt.getNode( "root node" );
7177 if ( !n.getNodeData().isHasDistribution() ) {
7180 if ( n.getNodeData().getDistributions().size() != 1 ) {
7183 d = n.getNodeData().getDistribution();
7184 if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
7187 if ( d.getPoints().size() != 1 ) {
7190 if ( d.getPolygons() != null ) {
7193 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
7196 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7199 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7202 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
7205 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
7208 n = t1_rt.getNode( "node a" );
7209 if ( !n.getNodeData().isHasDistribution() ) {
7212 if ( n.getNodeData().getDistributions().size() != 2 ) {
7215 d = n.getNodeData().getDistribution( 1 );
7216 if ( !d.getDesc().equals( "San Diego" ) ) {
7219 if ( d.getPoints().size() != 1 ) {
7222 if ( d.getPolygons() != null ) {
7225 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
7228 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7231 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7234 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
7237 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
7240 n = t1_rt.getNode( "node bb" );
7241 if ( !n.getNodeData().isHasDistribution() ) {
7244 if ( n.getNodeData().getDistributions().size() != 1 ) {
7247 d = n.getNodeData().getDistribution( 0 );
7248 if ( d.getPoints().size() != 3 ) {
7251 if ( d.getPolygons().size() != 2 ) {
7254 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
7257 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
7260 if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
7263 if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
7266 if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
7269 if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
7272 p = d.getPolygons().get( 0 );
7273 if ( p.getPoints().size() != 3 ) {
7276 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
7279 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
7282 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7285 if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
7288 if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
7291 if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
7294 p = d.getPolygons().get( 1 );
7295 if ( p.getPoints().size() != 3 ) {
7298 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
7301 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
7304 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7308 catch ( final Exception e ) {
7309 e.printStackTrace( System.out );
7315 private static boolean testPostOrderIterator() {
7317 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7318 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
7319 PhylogenyNodeIterator it0;
7320 for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
7323 for( it0.reset(); it0.hasNext(); ) {
7326 final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
7327 final PhylogenyNodeIterator it = t1.iteratorPostorder();
7328 if ( !it.next().getName().equals( "A" ) ) {
7331 if ( !it.next().getName().equals( "B" ) ) {
7334 if ( !it.next().getName().equals( "ab" ) ) {
7337 if ( !it.next().getName().equals( "C" ) ) {
7340 if ( !it.next().getName().equals( "D" ) ) {
7343 if ( !it.next().getName().equals( "cd" ) ) {
7346 if ( !it.next().getName().equals( "abcd" ) ) {
7349 if ( !it.next().getName().equals( "E" ) ) {
7352 if ( !it.next().getName().equals( "F" ) ) {
7355 if ( !it.next().getName().equals( "ef" ) ) {
7358 if ( !it.next().getName().equals( "G" ) ) {
7361 if ( !it.next().getName().equals( "H" ) ) {
7364 if ( !it.next().getName().equals( "gh" ) ) {
7367 if ( !it.next().getName().equals( "efgh" ) ) {
7370 if ( !it.next().getName().equals( "r" ) ) {
7373 if ( it.hasNext() ) {
7377 catch ( final Exception e ) {
7378 e.printStackTrace( System.out );
7384 private static boolean testPreOrderIterator() {
7386 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7387 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
7388 PhylogenyNodeIterator it0;
7389 for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
7392 for( it0.reset(); it0.hasNext(); ) {
7395 PhylogenyNodeIterator it = t0.iteratorPreorder();
7396 if ( !it.next().getName().equals( "r" ) ) {
7399 if ( !it.next().getName().equals( "ab" ) ) {
7402 if ( !it.next().getName().equals( "A" ) ) {
7405 if ( !it.next().getName().equals( "B" ) ) {
7408 if ( !it.next().getName().equals( "cd" ) ) {
7411 if ( !it.next().getName().equals( "C" ) ) {
7414 if ( !it.next().getName().equals( "D" ) ) {
7417 if ( it.hasNext() ) {
7420 final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
7421 it = t1.iteratorPreorder();
7422 if ( !it.next().getName().equals( "r" ) ) {
7425 if ( !it.next().getName().equals( "abcd" ) ) {
7428 if ( !it.next().getName().equals( "ab" ) ) {
7431 if ( !it.next().getName().equals( "A" ) ) {
7434 if ( !it.next().getName().equals( "B" ) ) {
7437 if ( !it.next().getName().equals( "cd" ) ) {
7440 if ( !it.next().getName().equals( "C" ) ) {
7443 if ( !it.next().getName().equals( "D" ) ) {
7446 if ( !it.next().getName().equals( "efgh" ) ) {
7449 if ( !it.next().getName().equals( "ef" ) ) {
7452 if ( !it.next().getName().equals( "E" ) ) {
7455 if ( !it.next().getName().equals( "F" ) ) {
7458 if ( !it.next().getName().equals( "gh" ) ) {
7461 if ( !it.next().getName().equals( "G" ) ) {
7464 if ( !it.next().getName().equals( "H" ) ) {
7467 if ( it.hasNext() ) {
7471 catch ( final Exception e ) {
7472 e.printStackTrace( System.out );
7478 private static boolean testPropertiesMap() {
7480 final PropertiesMap pm = new PropertiesMap();
7481 final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
7482 final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
7483 final Property p2 = new Property( "something:else",
7485 "improbable:research",
7488 pm.addProperty( p0 );
7489 pm.addProperty( p1 );
7490 pm.addProperty( p2 );
7491 if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
7494 if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
7497 if ( pm.getProperties().size() != 3 ) {
7500 if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
7503 if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
7506 if ( pm.getProperties().size() != 3 ) {
7509 pm.removeProperty( "dimensions:diameter" );
7510 if ( pm.getProperties().size() != 2 ) {
7513 if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
7516 if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
7520 catch ( final Exception e ) {
7521 e.printStackTrace( System.out );
7527 private static boolean testReIdMethods() {
7529 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7530 final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
7531 final long count = PhylogenyNode.getNodeCount();
7533 if ( p.getNode( "r" ).getId() != count ) {
7536 if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
7539 if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
7542 if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
7545 if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
7548 if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
7551 if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
7554 if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
7557 if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
7560 if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
7563 if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
7566 if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
7569 if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
7572 if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
7575 if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
7579 catch ( final Exception e ) {
7580 e.printStackTrace( System.out );
7586 private static boolean testRerooting() {
7588 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7589 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",
7590 new NHXParser() )[ 0 ];
7591 if ( !t1.isRooted() ) {
7594 t1.reRoot( t1.getNode( "D" ) );
7595 t1.reRoot( t1.getNode( "CD" ) );
7596 t1.reRoot( t1.getNode( "A" ) );
7597 t1.reRoot( t1.getNode( "B" ) );
7598 t1.reRoot( t1.getNode( "AB" ) );
7599 t1.reRoot( t1.getNode( "D" ) );
7600 t1.reRoot( t1.getNode( "C" ) );
7601 t1.reRoot( t1.getNode( "CD" ) );
7602 t1.reRoot( t1.getNode( "A" ) );
7603 t1.reRoot( t1.getNode( "B" ) );
7604 t1.reRoot( t1.getNode( "AB" ) );
7605 t1.reRoot( t1.getNode( "D" ) );
7606 t1.reRoot( t1.getNode( "D" ) );
7607 t1.reRoot( t1.getNode( "C" ) );
7608 t1.reRoot( t1.getNode( "A" ) );
7609 t1.reRoot( t1.getNode( "B" ) );
7610 t1.reRoot( t1.getNode( "AB" ) );
7611 t1.reRoot( t1.getNode( "C" ) );
7612 t1.reRoot( t1.getNode( "D" ) );
7613 t1.reRoot( t1.getNode( "CD" ) );
7614 t1.reRoot( t1.getNode( "D" ) );
7615 t1.reRoot( t1.getNode( "A" ) );
7616 t1.reRoot( t1.getNode( "B" ) );
7617 t1.reRoot( t1.getNode( "AB" ) );
7618 t1.reRoot( t1.getNode( "C" ) );
7619 t1.reRoot( t1.getNode( "D" ) );
7620 t1.reRoot( t1.getNode( "CD" ) );
7621 t1.reRoot( t1.getNode( "D" ) );
7622 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
7625 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
7628 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
7631 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
7634 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
7637 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
7640 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",
7641 new NHXParser() )[ 0 ];
7642 t2.reRoot( t2.getNode( "A" ) );
7643 t2.reRoot( t2.getNode( "D" ) );
7644 t2.reRoot( t2.getNode( "ABC" ) );
7645 t2.reRoot( t2.getNode( "A" ) );
7646 t2.reRoot( t2.getNode( "B" ) );
7647 t2.reRoot( t2.getNode( "D" ) );
7648 t2.reRoot( t2.getNode( "C" ) );
7649 t2.reRoot( t2.getNode( "ABC" ) );
7650 t2.reRoot( t2.getNode( "A" ) );
7651 t2.reRoot( t2.getNode( "B" ) );
7652 t2.reRoot( t2.getNode( "AB" ) );
7653 t2.reRoot( t2.getNode( "AB" ) );
7654 t2.reRoot( t2.getNode( "D" ) );
7655 t2.reRoot( t2.getNode( "C" ) );
7656 t2.reRoot( t2.getNode( "B" ) );
7657 t2.reRoot( t2.getNode( "AB" ) );
7658 t2.reRoot( t2.getNode( "D" ) );
7659 t2.reRoot( t2.getNode( "D" ) );
7660 t2.reRoot( t2.getNode( "ABC" ) );
7661 t2.reRoot( t2.getNode( "A" ) );
7662 t2.reRoot( t2.getNode( "B" ) );
7663 t2.reRoot( t2.getNode( "AB" ) );
7664 t2.reRoot( t2.getNode( "D" ) );
7665 t2.reRoot( t2.getNode( "C" ) );
7666 t2.reRoot( t2.getNode( "ABC" ) );
7667 t2.reRoot( t2.getNode( "A" ) );
7668 t2.reRoot( t2.getNode( "B" ) );
7669 t2.reRoot( t2.getNode( "AB" ) );
7670 t2.reRoot( t2.getNode( "D" ) );
7671 t2.reRoot( t2.getNode( "D" ) );
7672 t2.reRoot( t2.getNode( "C" ) );
7673 t2.reRoot( t2.getNode( "A" ) );
7674 t2.reRoot( t2.getNode( "B" ) );
7675 t2.reRoot( t2.getNode( "AB" ) );
7676 t2.reRoot( t2.getNode( "C" ) );
7677 t2.reRoot( t2.getNode( "D" ) );
7678 t2.reRoot( t2.getNode( "ABC" ) );
7679 t2.reRoot( t2.getNode( "D" ) );
7680 t2.reRoot( t2.getNode( "A" ) );
7681 t2.reRoot( t2.getNode( "B" ) );
7682 t2.reRoot( t2.getNode( "AB" ) );
7683 t2.reRoot( t2.getNode( "C" ) );
7684 t2.reRoot( t2.getNode( "D" ) );
7685 t2.reRoot( t2.getNode( "ABC" ) );
7686 t2.reRoot( t2.getNode( "D" ) );
7687 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7690 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7693 t2.reRoot( t2.getNode( "ABC" ) );
7694 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7697 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7700 t2.reRoot( t2.getNode( "AB" ) );
7701 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7704 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7707 if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7710 t2.reRoot( t2.getNode( "AB" ) );
7711 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7714 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7717 if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7720 t2.reRoot( t2.getNode( "D" ) );
7721 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7724 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7727 t2.reRoot( t2.getNode( "ABC" ) );
7728 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7731 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7734 final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
7735 new NHXParser() )[ 0 ];
7736 t3.reRoot( t3.getNode( "B" ) );
7737 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7740 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7743 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7746 t3.reRoot( t3.getNode( "B" ) );
7747 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7750 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7753 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7756 t3.reRoot( t3.getRoot() );
7757 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7760 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7763 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7767 catch ( final Exception e ) {
7768 e.printStackTrace( System.out );
7774 private static boolean testSDIse() {
7776 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7777 final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
7778 final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
7779 gene1.setRooted( true );
7780 species1.setRooted( true );
7781 final SDI sdi = new SDI( gene1, species1 );
7782 if ( !gene1.getRoot().isDuplication() ) {
7785 final Phylogeny species2 = factory
7786 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7787 new NHXParser() )[ 0 ];
7788 final Phylogeny gene2 = factory
7789 .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7790 new NHXParser() )[ 0 ];
7791 species2.setRooted( true );
7792 gene2.setRooted( true );
7793 final SDI sdi2 = new SDI( gene2, species2 );
7794 if ( sdi2.getDuplicationsSum() != 0 ) {
7797 if ( !gene2.getNode( "ab" ).isSpeciation() ) {
7800 if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
7803 if ( !gene2.getNode( "abc" ).isSpeciation() ) {
7806 if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
7809 if ( !gene2.getNode( "r" ).isSpeciation() ) {
7812 if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
7815 final Phylogeny species3 = factory
7816 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7817 new NHXParser() )[ 0 ];
7818 final Phylogeny gene3 = factory
7819 .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7820 new NHXParser() )[ 0 ];
7821 species3.setRooted( true );
7822 gene3.setRooted( true );
7823 final SDI sdi3 = new SDI( gene3, species3 );
7824 if ( sdi3.getDuplicationsSum() != 1 ) {
7827 if ( !gene3.getNode( "aa" ).isDuplication() ) {
7830 if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
7833 final Phylogeny species4 = factory
7834 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7835 new NHXParser() )[ 0 ];
7836 final Phylogeny gene4 = factory
7837 .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7838 new NHXParser() )[ 0 ];
7839 species4.setRooted( true );
7840 gene4.setRooted( true );
7841 final SDI sdi4 = new SDI( gene4, species4 );
7842 if ( sdi4.getDuplicationsSum() != 1 ) {
7845 if ( !gene4.getNode( "ac" ).isSpeciation() ) {
7848 if ( !gene4.getNode( "abc" ).isDuplication() ) {
7851 if ( gene4.getNode( "abcd" ).isDuplication() ) {
7854 if ( species4.getNumberOfExternalNodes() != 6 ) {
7857 if ( gene4.getNumberOfExternalNodes() != 6 ) {
7860 final Phylogeny species5 = factory
7861 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7862 new NHXParser() )[ 0 ];
7863 final Phylogeny gene5 = factory
7864 .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7865 new NHXParser() )[ 0 ];
7866 species5.setRooted( true );
7867 gene5.setRooted( true );
7868 final SDI sdi5 = new SDI( gene5, species5 );
7869 if ( sdi5.getDuplicationsSum() != 2 ) {
7872 if ( !gene5.getNode( "ad" ).isSpeciation() ) {
7875 if ( !gene5.getNode( "adc" ).isDuplication() ) {
7878 if ( !gene5.getNode( "abcd" ).isDuplication() ) {
7881 if ( species5.getNumberOfExternalNodes() != 6 ) {
7884 if ( gene5.getNumberOfExternalNodes() != 6 ) {
7887 // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
7888 // Conjecture for Comparing Molecular Phylogenies"
7889 // J. of Comput Bio. Vol. 4, No 2, pp.177-187
7890 final Phylogeny species6 = factory
7891 .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,"
7892 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
7893 new NHXParser() )[ 0 ];
7894 final Phylogeny gene6 = factory
7895 .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,"
7896 + "((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,"
7897 + "(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;",
7898 new NHXParser() )[ 0 ];
7899 species6.setRooted( true );
7900 gene6.setRooted( true );
7901 final SDI sdi6 = new SDI( gene6, species6 );
7902 if ( sdi6.getDuplicationsSum() != 3 ) {
7905 if ( !gene6.getNode( "r" ).isDuplication() ) {
7908 if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
7911 if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
7914 if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
7917 if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
7920 if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
7923 if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
7926 if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
7929 sdi6.computeMappingCostL();
7930 if ( sdi6.computeMappingCostL() != 17 ) {
7933 if ( species6.getNumberOfExternalNodes() != 9 ) {
7936 if ( gene6.getNumberOfExternalNodes() != 9 ) {
7939 final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
7940 + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
7941 + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
7942 + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
7943 + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
7944 species7.setRooted( true );
7945 final Phylogeny gene7_1 = Test
7946 .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])" );
7947 gene7_1.setRooted( true );
7948 final SDI sdi7 = new SDI( gene7_1, species7 );
7949 if ( sdi7.getDuplicationsSum() != 0 ) {
7952 if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
7955 if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
7958 if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
7961 if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
7964 if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
7967 if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
7970 if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
7973 if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
7976 final Phylogeny gene7_2 = Test
7977 .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])" );
7978 gene7_2.setRooted( true );
7979 final SDI sdi7_2 = new SDI( gene7_2, species7 );
7980 if ( sdi7_2.getDuplicationsSum() != 1 ) {
7983 if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
7986 if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
7989 if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
7992 if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
7995 if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
7998 if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
8001 if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
8004 if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
8007 if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
8011 catch ( final Exception e ) {
8017 private static boolean testSDIunrooted() {
8019 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8020 final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
8021 final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
8022 final Iterator<PhylogenyBranch> iter = l.iterator();
8023 PhylogenyBranch br = iter.next();
8024 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
8027 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
8031 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
8034 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
8038 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
8041 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
8045 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8048 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8052 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8055 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8059 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
8062 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
8066 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8069 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8073 if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8076 if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8080 if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8083 if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8087 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8090 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8094 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
8097 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
8101 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
8104 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
8108 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
8111 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
8115 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
8118 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
8122 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
8125 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
8128 if ( iter.hasNext() ) {
8131 final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
8132 final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
8133 final Iterator<PhylogenyBranch> iter1 = l1.iterator();
8135 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
8138 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
8142 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8145 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8149 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8152 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8155 if ( iter1.hasNext() ) {
8158 final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
8159 final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
8160 final Iterator<PhylogenyBranch> iter2 = l2.iterator();
8162 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
8165 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
8169 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8172 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8176 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8179 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8182 if ( iter2.hasNext() ) {
8185 final Phylogeny species0 = factory
8186 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
8187 new NHXParser() )[ 0 ];
8188 final Phylogeny gene1 = factory
8189 .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])",
8190 new NHXParser() )[ 0 ];
8191 species0.setRooted( true );
8192 gene1.setRooted( true );
8193 final SDIR sdi_unrooted = new SDIR();
8194 sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
8195 if ( sdi_unrooted.getCount() != 1 ) {
8198 if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
8201 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
8204 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
8207 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8210 final Phylogeny gene2 = factory
8211 .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])",
8212 new NHXParser() )[ 0 ];
8213 gene2.setRooted( true );
8214 sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
8215 if ( sdi_unrooted.getCount() != 1 ) {
8218 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8221 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8224 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
8227 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8230 final Phylogeny species6 = factory
8231 .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,"
8232 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8233 new NHXParser() )[ 0 ];
8234 final Phylogeny gene6 = factory
8235 .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],"
8236 + "(((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],"
8237 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8238 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8239 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8240 new NHXParser() )[ 0 ];
8241 species6.setRooted( true );
8242 gene6.setRooted( true );
8243 Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
8244 if ( sdi_unrooted.getCount() != 1 ) {
8247 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8250 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8253 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8256 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8259 if ( !p6[ 0 ].getRoot().isDuplication() ) {
8262 if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8265 if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8268 if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
8271 if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8274 if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
8277 if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
8280 if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8284 final Phylogeny species7 = factory
8285 .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,"
8286 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8287 new NHXParser() )[ 0 ];
8288 final Phylogeny gene7 = factory
8289 .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],"
8290 + "(((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],"
8291 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8292 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8293 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8294 new NHXParser() )[ 0 ];
8295 species7.setRooted( true );
8296 gene7.setRooted( true );
8297 Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
8298 if ( sdi_unrooted.getCount() != 1 ) {
8301 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8304 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8307 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8310 if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
8313 if ( !p7[ 0 ].getRoot().isDuplication() ) {
8316 if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8319 if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8322 if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
8325 if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8328 if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
8331 if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
8334 if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8338 final Phylogeny species8 = factory
8339 .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,"
8340 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8341 new NHXParser() )[ 0 ];
8342 final Phylogeny gene8 = factory
8343 .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],"
8344 + "(((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],"
8345 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8346 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8347 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8348 new NHXParser() )[ 0 ];
8349 species8.setRooted( true );
8350 gene8.setRooted( true );
8351 Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
8352 if ( sdi_unrooted.getCount() != 1 ) {
8355 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8358 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8361 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8364 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8367 if ( !p8[ 0 ].getRoot().isDuplication() ) {
8370 if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8373 if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8376 if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
8379 if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8382 if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
8385 if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
8388 if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8393 catch ( final Exception e ) {
8394 e.printStackTrace( System.out );
8400 private static boolean testSplit() {
8402 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8403 final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
8404 //Archaeopteryx.createApplication( p0 );
8405 final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
8406 ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8407 ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8408 ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8409 ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8410 ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8411 ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8412 ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8413 ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8414 ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8415 final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
8416 // System.out.println( s0.toString() );
8418 Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
8419 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8420 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8421 if ( s0.match( query_nodes ) ) {
8424 query_nodes = new HashSet<PhylogenyNode>();
8425 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8426 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8427 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8428 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8429 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8430 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8431 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8432 if ( !s0.match( query_nodes ) ) {
8436 query_nodes = new HashSet<PhylogenyNode>();
8437 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8438 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8439 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8440 if ( !s0.match( query_nodes ) ) {
8444 query_nodes = new HashSet<PhylogenyNode>();
8445 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8446 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8447 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8448 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8449 if ( !s0.match( query_nodes ) ) {
8453 query_nodes = new HashSet<PhylogenyNode>();
8454 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8455 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8456 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8457 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8458 if ( !s0.match( query_nodes ) ) {
8462 query_nodes = new HashSet<PhylogenyNode>();
8463 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8464 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8465 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8466 if ( !s0.match( query_nodes ) ) {
8470 query_nodes = new HashSet<PhylogenyNode>();
8471 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8472 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8473 if ( !s0.match( query_nodes ) ) {
8477 query_nodes = new HashSet<PhylogenyNode>();
8478 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8479 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8480 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8481 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8482 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8483 if ( !s0.match( query_nodes ) ) {
8487 query_nodes = new HashSet<PhylogenyNode>();
8488 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8489 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8490 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8491 if ( !s0.match( query_nodes ) ) {
8495 query_nodes = new HashSet<PhylogenyNode>();
8496 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8497 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8498 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8499 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8500 if ( !s0.match( query_nodes ) ) {
8504 query_nodes = new HashSet<PhylogenyNode>();
8505 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8506 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8507 if ( s0.match( query_nodes ) ) {
8511 query_nodes = new HashSet<PhylogenyNode>();
8512 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8513 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8514 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8515 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8516 if ( s0.match( query_nodes ) ) {
8520 query_nodes = new HashSet<PhylogenyNode>();
8521 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8522 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8523 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8524 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8525 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8526 if ( s0.match( query_nodes ) ) {
8530 query_nodes = new HashSet<PhylogenyNode>();
8531 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8532 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8533 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8534 if ( s0.match( query_nodes ) ) {
8538 query_nodes = new HashSet<PhylogenyNode>();
8539 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8540 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8541 if ( s0.match( query_nodes ) ) {
8545 query_nodes = new HashSet<PhylogenyNode>();
8546 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8547 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8548 if ( s0.match( query_nodes ) ) {
8552 query_nodes = new HashSet<PhylogenyNode>();
8553 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8554 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8555 if ( s0.match( query_nodes ) ) {
8559 query_nodes = new HashSet<PhylogenyNode>();
8560 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8561 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8562 if ( s0.match( query_nodes ) ) {
8566 query_nodes = new HashSet<PhylogenyNode>();
8567 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8568 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8569 if ( s0.match( query_nodes ) ) {
8573 query_nodes = new HashSet<PhylogenyNode>();
8574 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8575 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8576 if ( s0.match( query_nodes ) ) {
8580 query_nodes = new HashSet<PhylogenyNode>();
8581 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8582 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8583 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8584 if ( s0.match( query_nodes ) ) {
8588 query_nodes = new HashSet<PhylogenyNode>();
8589 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8590 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8591 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8592 if ( s0.match( query_nodes ) ) {
8596 query_nodes = new HashSet<PhylogenyNode>();
8597 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8598 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8599 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8600 if ( s0.match( query_nodes ) ) {
8604 query_nodes = new HashSet<PhylogenyNode>();
8605 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8606 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8607 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8608 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8609 if ( s0.match( query_nodes ) ) {
8613 // query_nodes = new HashSet<PhylogenyNode>();
8614 // query_nodes.add( new PhylogenyNode( "X" ) );
8615 // query_nodes.add( new PhylogenyNode( "Y" ) );
8616 // query_nodes.add( new PhylogenyNode( "A" ) );
8617 // query_nodes.add( new PhylogenyNode( "B" ) );
8618 // query_nodes.add( new PhylogenyNode( "C" ) );
8619 // query_nodes.add( new PhylogenyNode( "D" ) );
8620 // query_nodes.add( new PhylogenyNode( "E" ) );
8621 // query_nodes.add( new PhylogenyNode( "F" ) );
8622 // query_nodes.add( new PhylogenyNode( "G" ) );
8623 // if ( !s0.match( query_nodes ) ) {
8626 // query_nodes = new HashSet<PhylogenyNode>();
8627 // query_nodes.add( new PhylogenyNode( "X" ) );
8628 // query_nodes.add( new PhylogenyNode( "Y" ) );
8629 // query_nodes.add( new PhylogenyNode( "A" ) );
8630 // query_nodes.add( new PhylogenyNode( "B" ) );
8631 // query_nodes.add( new PhylogenyNode( "C" ) );
8632 // if ( !s0.match( query_nodes ) ) {
8636 // query_nodes = new HashSet<PhylogenyNode>();
8637 // query_nodes.add( new PhylogenyNode( "X" ) );
8638 // query_nodes.add( new PhylogenyNode( "Y" ) );
8639 // query_nodes.add( new PhylogenyNode( "D" ) );
8640 // query_nodes.add( new PhylogenyNode( "E" ) );
8641 // query_nodes.add( new PhylogenyNode( "F" ) );
8642 // query_nodes.add( new PhylogenyNode( "G" ) );
8643 // if ( !s0.match( query_nodes ) ) {
8647 // query_nodes = new HashSet<PhylogenyNode>();
8648 // query_nodes.add( new PhylogenyNode( "X" ) );
8649 // query_nodes.add( new PhylogenyNode( "Y" ) );
8650 // query_nodes.add( new PhylogenyNode( "A" ) );
8651 // query_nodes.add( new PhylogenyNode( "B" ) );
8652 // query_nodes.add( new PhylogenyNode( "C" ) );
8653 // query_nodes.add( new PhylogenyNode( "D" ) );
8654 // if ( !s0.match( query_nodes ) ) {
8658 // query_nodes = new HashSet<PhylogenyNode>();
8659 // query_nodes.add( new PhylogenyNode( "X" ) );
8660 // query_nodes.add( new PhylogenyNode( "Y" ) );
8661 // query_nodes.add( new PhylogenyNode( "E" ) );
8662 // query_nodes.add( new PhylogenyNode( "F" ) );
8663 // query_nodes.add( new PhylogenyNode( "G" ) );
8664 // if ( !s0.match( query_nodes ) ) {
8668 // query_nodes = new HashSet<PhylogenyNode>();
8669 // query_nodes.add( new PhylogenyNode( "X" ) );
8670 // query_nodes.add( new PhylogenyNode( "Y" ) );
8671 // query_nodes.add( new PhylogenyNode( "F" ) );
8672 // query_nodes.add( new PhylogenyNode( "G" ) );
8673 // if ( !s0.match( query_nodes ) ) {
8677 query_nodes = new HashSet<PhylogenyNode>();
8678 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8679 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8680 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8681 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8682 if ( s0.match( query_nodes ) ) {
8686 query_nodes = new HashSet<PhylogenyNode>();
8687 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8688 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8689 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8690 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8691 if ( s0.match( query_nodes ) ) {
8694 ///////////////////////////
8696 query_nodes = new HashSet<PhylogenyNode>();
8697 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8698 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8699 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8700 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8701 if ( s0.match( query_nodes ) ) {
8705 query_nodes = new HashSet<PhylogenyNode>();
8706 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8707 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8708 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8709 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8710 if ( s0.match( query_nodes ) ) {
8714 query_nodes = new HashSet<PhylogenyNode>();
8715 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8716 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8717 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8718 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8719 if ( s0.match( query_nodes ) ) {
8723 query_nodes = new HashSet<PhylogenyNode>();
8724 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8725 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8726 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8727 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8728 if ( s0.match( query_nodes ) ) {
8732 query_nodes = new HashSet<PhylogenyNode>();
8733 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8734 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8735 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8736 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8737 if ( s0.match( query_nodes ) ) {
8741 query_nodes = new HashSet<PhylogenyNode>();
8742 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8743 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8744 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8745 if ( s0.match( query_nodes ) ) {
8749 query_nodes = new HashSet<PhylogenyNode>();
8750 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8751 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8752 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8753 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8754 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8755 if ( s0.match( query_nodes ) ) {
8759 query_nodes = new HashSet<PhylogenyNode>();
8760 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8761 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8762 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8763 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8764 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8765 if ( s0.match( query_nodes ) ) {
8769 query_nodes = new HashSet<PhylogenyNode>();
8770 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8771 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8772 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8773 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8774 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8775 if ( s0.match( query_nodes ) ) {
8779 query_nodes = new HashSet<PhylogenyNode>();
8780 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8781 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8782 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8783 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8784 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8785 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8786 if ( s0.match( query_nodes ) ) {
8790 catch ( final Exception e ) {
8791 e.printStackTrace();
8797 private static boolean testSplitStrict() {
8799 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8800 final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
8801 final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
8802 ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8803 ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8804 ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8805 ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8806 ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8807 ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8808 ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8809 final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
8810 Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
8811 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8812 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8813 if ( s0.match( query_nodes ) ) {
8816 query_nodes = new HashSet<PhylogenyNode>();
8817 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8818 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8819 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8820 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8821 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8822 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8823 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8824 if ( !s0.match( query_nodes ) ) {
8828 query_nodes = new HashSet<PhylogenyNode>();
8829 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8830 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8831 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8832 if ( !s0.match( query_nodes ) ) {
8836 query_nodes = new HashSet<PhylogenyNode>();
8837 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8838 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8839 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8840 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8841 if ( !s0.match( query_nodes ) ) {
8845 query_nodes = new HashSet<PhylogenyNode>();
8846 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8847 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8848 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8849 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8850 if ( !s0.match( query_nodes ) ) {
8854 query_nodes = new HashSet<PhylogenyNode>();
8855 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8856 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8857 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8858 if ( !s0.match( query_nodes ) ) {
8862 query_nodes = new HashSet<PhylogenyNode>();
8863 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8864 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8865 if ( !s0.match( query_nodes ) ) {
8869 query_nodes = new HashSet<PhylogenyNode>();
8870 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8871 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8872 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8873 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8874 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8875 if ( !s0.match( query_nodes ) ) {
8879 query_nodes = new HashSet<PhylogenyNode>();
8880 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8881 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8882 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8883 if ( !s0.match( query_nodes ) ) {
8887 query_nodes = new HashSet<PhylogenyNode>();
8888 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8889 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8890 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8891 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8892 if ( !s0.match( query_nodes ) ) {
8896 query_nodes = new HashSet<PhylogenyNode>();
8897 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8898 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8899 if ( s0.match( query_nodes ) ) {
8903 query_nodes = new HashSet<PhylogenyNode>();
8904 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8905 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8906 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8907 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8908 if ( s0.match( query_nodes ) ) {
8912 query_nodes = new HashSet<PhylogenyNode>();
8913 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8914 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8915 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8916 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8917 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8918 if ( s0.match( query_nodes ) ) {
8922 query_nodes = new HashSet<PhylogenyNode>();
8923 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8924 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8925 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8926 if ( s0.match( query_nodes ) ) {
8930 query_nodes = new HashSet<PhylogenyNode>();
8931 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8932 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8933 if ( s0.match( query_nodes ) ) {
8937 query_nodes = new HashSet<PhylogenyNode>();
8938 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8939 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8940 if ( s0.match( query_nodes ) ) {
8944 query_nodes = new HashSet<PhylogenyNode>();
8945 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8946 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8947 if ( s0.match( query_nodes ) ) {
8951 query_nodes = new HashSet<PhylogenyNode>();
8952 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8953 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8954 if ( s0.match( query_nodes ) ) {
8958 query_nodes = new HashSet<PhylogenyNode>();
8959 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8960 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8961 if ( s0.match( query_nodes ) ) {
8965 query_nodes = new HashSet<PhylogenyNode>();
8966 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8967 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8968 if ( s0.match( query_nodes ) ) {
8972 query_nodes = new HashSet<PhylogenyNode>();
8973 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8974 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8975 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8976 if ( s0.match( query_nodes ) ) {
8980 query_nodes = new HashSet<PhylogenyNode>();
8981 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8982 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8983 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8984 if ( s0.match( query_nodes ) ) {
8988 query_nodes = new HashSet<PhylogenyNode>();
8989 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8990 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8991 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8992 if ( s0.match( query_nodes ) ) {
8996 query_nodes = new HashSet<PhylogenyNode>();
8997 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8998 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8999 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9000 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9001 if ( s0.match( query_nodes ) ) {
9005 catch ( final Exception e ) {
9006 e.printStackTrace();
9012 private static boolean testSubtreeDeletion() {
9014 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9015 final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
9016 t1.deleteSubtree( t1.getNode( "A" ), false );
9017 if ( t1.getNumberOfExternalNodes() != 5 ) {
9020 t1.toNewHampshireX();
9021 t1.deleteSubtree( t1.getNode( "E" ), false );
9022 if ( t1.getNumberOfExternalNodes() != 4 ) {
9025 t1.toNewHampshireX();
9026 t1.deleteSubtree( t1.getNode( "F" ), false );
9027 if ( t1.getNumberOfExternalNodes() != 3 ) {
9030 t1.toNewHampshireX();
9031 t1.deleteSubtree( t1.getNode( "D" ), false );
9032 t1.toNewHampshireX();
9033 if ( t1.getNumberOfExternalNodes() != 3 ) {
9036 t1.deleteSubtree( t1.getNode( "def" ), false );
9037 t1.toNewHampshireX();
9038 if ( t1.getNumberOfExternalNodes() != 2 ) {
9041 t1.deleteSubtree( t1.getNode( "B" ), false );
9042 t1.toNewHampshireX();
9043 if ( t1.getNumberOfExternalNodes() != 1 ) {
9046 t1.deleteSubtree( t1.getNode( "C" ), false );
9047 t1.toNewHampshireX();
9048 if ( t1.getNumberOfExternalNodes() != 1 ) {
9051 t1.deleteSubtree( t1.getNode( "abc" ), false );
9052 t1.toNewHampshireX();
9053 if ( t1.getNumberOfExternalNodes() != 1 ) {
9056 t1.deleteSubtree( t1.getNode( "r" ), false );
9057 if ( t1.getNumberOfExternalNodes() != 0 ) {
9060 if ( !t1.isEmpty() ) {
9063 final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
9064 t2.deleteSubtree( t2.getNode( "A" ), false );
9065 t2.toNewHampshireX();
9066 if ( t2.getNumberOfExternalNodes() != 5 ) {
9069 t2.deleteSubtree( t2.getNode( "abc" ), false );
9070 t2.toNewHampshireX();
9071 if ( t2.getNumberOfExternalNodes() != 3 ) {
9074 t2.deleteSubtree( t2.getNode( "def" ), false );
9075 t2.toNewHampshireX();
9076 if ( t2.getNumberOfExternalNodes() != 1 ) {
9080 catch ( final Exception e ) {
9081 e.printStackTrace( System.out );
9087 private static boolean testSupportCount() {
9089 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9090 final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
9091 final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
9092 + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
9093 + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
9094 + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
9095 + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
9097 SupportCount.count( t0_1, phylogenies_1, true, false );
9098 final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
9099 final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
9100 + "(((((A,B),C),D),E),((F,G),X))"
9101 + "(((((A,Y),B),C),D),((F,G),E))"
9102 + "(((((A,B),C),D),E),(F,G))"
9103 + "(((((A,B),C),D),E),(F,G))"
9104 + "(((((A,B),C),D),E),(F,G))"
9105 + "(((((A,B),C),D),E),(F,G),Z)"
9106 + "(((((A,B),C),D),E),(F,G))"
9107 + "((((((A,B),C),D),E),F),G)"
9108 + "(((((X,Y),F,G),E),((A,B),C)),D)",
9110 SupportCount.count( t0_2, phylogenies_2, true, false );
9111 final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
9112 while ( it.hasNext() ) {
9113 final PhylogenyNode n = it.next();
9114 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
9118 final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
9119 final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
9120 + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
9121 SupportCount.count( t0_3, phylogenies_3, true, false );
9122 t0_3.reRoot( t0_3.getNode( "def" ).getId() );
9123 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
9126 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
9129 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
9132 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
9135 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
9138 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
9141 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
9144 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
9147 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
9150 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
9153 final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9154 final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
9155 + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
9156 SupportCount.count( t0_4, phylogenies_4, true, false );
9157 t0_4.reRoot( t0_4.getNode( "F" ).getId() );
9158 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
9161 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
9164 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
9167 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
9170 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
9173 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
9176 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
9179 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
9182 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
9185 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
9188 Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9189 final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9190 double d = SupportCount.compare( b1, a, true, true, true );
9191 if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
9194 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9195 final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9196 d = SupportCount.compare( b2, a, true, true, true );
9197 if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
9200 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9201 final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
9202 d = SupportCount.compare( b3, a, true, true, true );
9203 if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
9206 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
9207 final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
9208 d = SupportCount.compare( b4, a, true, true, false );
9209 if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
9213 catch ( final Exception e ) {
9214 e.printStackTrace( System.out );
9220 private static boolean testSupportTransfer() {
9222 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9223 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)",
9224 new NHXParser() )[ 0 ];
9225 final Phylogeny p2 = factory
9226 .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 ];
9227 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
9230 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
9233 support_transfer.moveBranchLengthsToBootstrap( p1 );
9234 support_transfer.transferSupportValues( p1, p2 );
9235 if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
9238 if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
9241 if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
9244 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
9247 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
9250 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
9253 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
9256 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
9260 catch ( final Exception e ) {
9261 e.printStackTrace( System.out );
9267 private static boolean testUniprotTaxonomySearch() {
9269 List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
9271 if ( results.size() != 1 ) {
9274 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9277 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9280 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9283 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9286 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9290 results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
9291 if ( results.size() != 1 ) {
9294 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9297 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9300 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9303 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9306 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9310 results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
9311 if ( results.size() != 1 ) {
9314 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9317 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9320 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9323 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9326 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9330 results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
9331 if ( results.size() != 1 ) {
9334 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9337 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9340 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9343 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9346 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9349 if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
9352 if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
9355 if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
9356 .equals( "Nematostella vectensis" ) ) {
9357 System.out.println( results.get( 0 ).getLineage() );
9361 catch ( final IOException e ) {
9362 System.out.println();
9363 System.out.println( "the following might be due to absence internet connection:" );
9364 e.printStackTrace( System.out );
9367 catch ( final Exception e ) {
9373 private static boolean testEmblEntryRetrieval() {
9374 //The format for GenBank Accession numbers are:
9375 //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
9376 //Protein: 3 letters + 5 numerals
9377 //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
9378 if ( !SequenceIdParser.parseGenbankAccessor( "AY423861" ).equals( "AY423861" ) ) {
9381 if ( !SequenceIdParser.parseGenbankAccessor( ".AY423861." ).equals( "AY423861" ) ) {
9384 if ( SequenceIdParser.parseGenbankAccessor( "AAY423861" ) != null ) {
9387 if ( SequenceIdParser.parseGenbankAccessor( "AY4238612" ) != null ) {
9390 if ( SequenceIdParser.parseGenbankAccessor( "AAY4238612" ) != null ) {
9393 if ( SequenceIdParser.parseGenbankAccessor( "Y423861" ) != null ) {
9396 if ( !SequenceIdParser.parseGenbankAccessor( "S12345" ).equals( "S12345" ) ) {
9399 if ( !SequenceIdParser.parseGenbankAccessor( "|S12345|" ).equals( "S12345" ) ) {
9402 if ( SequenceIdParser.parseGenbankAccessor( "|S123456" ) != null ) {
9405 if ( SequenceIdParser.parseGenbankAccessor( "ABC123456" ) != null ) {
9408 if ( !SequenceIdParser.parseGenbankAccessor( "ABC12345" ).equals( "ABC12345" ) ) {
9411 if ( !SequenceIdParser.parseGenbankAccessor( "&ABC12345&" ).equals( "ABC12345" ) ) {
9414 if ( SequenceIdParser.parseGenbankAccessor( "ABCD12345" ) != null ) {
9420 private static boolean testUniprotEntryRetrieval() {
9421 if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345" ).equals( "P12345" ) ) {
9424 if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345" ) != null ) {
9427 if ( SequenceDbWsTools.parseUniProtAccessor( "3 4P12345" ) != null ) {
9430 if ( SequenceDbWsTools.parseUniProtAccessor( "P12345E" ) != null ) {
9433 if ( SequenceDbWsTools.parseUniProtAccessor( "P123455" ) != null ) {
9436 if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345E" ) != null ) {
9439 if ( SequenceDbWsTools.parseUniProtAccessor( "AY423861" ) != null ) {
9442 if ( !SequenceDbWsTools.parseUniProtAccessor( "P1DDD5" ).equals( "P1DDD5" ) ) {
9445 if ( SequenceDbWsTools.parseUniProtAccessor( "P1DDDD" ) != null ) {
9448 if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345/12-42" ).equals( "P12345" ) ) {
9451 if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X P12345 12-42" ).equals( "P12345" ) ) {
9454 if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345/12-42" ).equals( "P12345" ) ) {
9457 if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345" ).equals( "P12345" ) ) {
9461 final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
9462 if ( !entry.getAccession().equals( "P12345" ) ) {
9465 if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
9468 if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
9471 if ( !entry.getSequenceSymbol().equals( "GOT2" ) ) {
9474 if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
9478 catch ( final IOException e ) {
9479 System.out.println();
9480 System.out.println( "the following might be due to absence internet connection:" );
9481 e.printStackTrace( System.out );
9484 catch ( final Exception e ) {
9490 private static boolean testWabiTxSearch() {
9493 result = TxSearch.searchSimple( "nematostella" );
9494 result = TxSearch.getTxId( "nematostella" );
9495 if ( !result.equals( "45350" ) ) {
9498 result = TxSearch.getTxName( "45350" );
9499 if ( !result.equals( "Nematostella" ) ) {
9502 result = TxSearch.getTxId( "nematostella vectensis" );
9503 if ( !result.equals( "45351" ) ) {
9506 result = TxSearch.getTxName( "45351" );
9507 if ( !result.equals( "Nematostella vectensis" ) ) {
9510 result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
9511 if ( !result.equals( "536089" ) ) {
9514 result = TxSearch.getTxName( "536089" );
9515 if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
9518 final List<String> queries = new ArrayList<String>();
9519 queries.add( "Campylobacter coli" );
9520 queries.add( "Escherichia coli" );
9521 queries.add( "Arabidopsis" );
9522 queries.add( "Trichoplax" );
9523 queries.add( "Samanea saman" );
9524 queries.add( "Kluyveromyces marxianus" );
9525 queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
9526 queries.add( "Bornavirus parrot/PDD/2008" );
9527 final List<RANKS> ranks = new ArrayList<RANKS>();
9528 ranks.add( RANKS.SUPERKINGDOM );
9529 ranks.add( RANKS.KINGDOM );
9530 ranks.add( RANKS.FAMILY );
9531 ranks.add( RANKS.GENUS );
9532 ranks.add( RANKS.TRIBE );
9533 result = TxSearch.searchLineage( queries, ranks );
9534 result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
9535 result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
9537 catch ( final Exception e ) {
9538 System.out.println();
9539 System.out.println( "the following might be due to absence internet connection:" );
9540 e.printStackTrace( System.out );
9546 private static boolean testAminoAcidSequence() {
9548 final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
9549 if ( aa1.getLength() != 13 ) {
9552 if ( aa1.getResidueAt( 0 ) != 'A' ) {
9555 if ( aa1.getResidueAt( 2 ) != 'K' ) {
9558 if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
9561 final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
9562 if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
9565 final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
9566 if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
9569 final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
9570 if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
9574 catch ( final Exception e ) {
9575 e.printStackTrace();
9581 private static boolean testCreateBalancedPhylogeny() {
9583 final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
9584 if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
9587 if ( p0.getNumberOfExternalNodes() != 15625 ) {
9590 final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
9591 if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
9594 if ( p1.getNumberOfExternalNodes() != 100 ) {
9598 catch ( final Exception e ) {
9599 e.printStackTrace();
9605 private static boolean testFastaParser() {
9607 if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
9610 if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
9613 final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
9614 if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
9617 if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
9620 if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
9623 if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
9626 if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
9629 if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
9633 catch ( final Exception e ) {
9634 e.printStackTrace();
9640 private static boolean testGeneralMsaParser() {
9642 final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
9643 final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
9644 final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
9645 final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
9646 final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
9647 final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
9648 final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
9649 final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
9650 if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9653 if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9656 if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9659 if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9662 if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9665 if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9668 if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9671 if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9674 if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9677 if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9680 if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9683 if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9686 final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
9687 if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
9690 if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
9693 if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
9696 final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
9697 if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
9700 if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
9703 if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
9706 final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
9707 if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
9710 if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
9713 if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
9717 catch ( final Exception e ) {
9718 e.printStackTrace();
9724 private static boolean testMafft( final String path ) {
9726 final List<String> opts = new ArrayList<String>();
9727 opts.add( "--maxiterate" );
9729 opts.add( "--localpair" );
9730 opts.add( "--quiet" );
9732 final MsaInferrer mafft = Mafft.createInstance( path );
9733 msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
9734 if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
9737 if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
9741 catch ( final Exception e ) {
9742 e.printStackTrace( System.out );
9748 private static boolean testNextNodeWithCollapsing() {
9750 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9752 List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
9753 final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9754 final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
9755 t0.getNode( "cd" ).setCollapse( true );
9756 t0.getNode( "cde" ).setCollapse( true );
9757 n = t0.getFirstExternalNode();
9758 while ( n != null ) {
9760 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9762 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
9765 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
9768 if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
9771 if ( !ext.get( 3 ).getName().equals( "f" ) ) {
9774 if ( !ext.get( 4 ).getName().equals( "g" ) ) {
9777 if ( !ext.get( 5 ).getName().equals( "h" ) ) {
9781 final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9782 final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
9783 t1.getNode( "ab" ).setCollapse( true );
9784 t1.getNode( "cd" ).setCollapse( true );
9785 t1.getNode( "cde" ).setCollapse( true );
9786 n = t1.getNode( "ab" );
9787 ext = new ArrayList<PhylogenyNode>();
9788 while ( n != null ) {
9790 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9792 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9795 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9798 if ( !ext.get( 2 ).getName().equals( "f" ) ) {
9801 if ( !ext.get( 3 ).getName().equals( "g" ) ) {
9804 if ( !ext.get( 4 ).getName().equals( "h" ) ) {
9810 final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9811 final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
9812 t2.getNode( "ab" ).setCollapse( true );
9813 t2.getNode( "cd" ).setCollapse( true );
9814 t2.getNode( "cde" ).setCollapse( true );
9815 t2.getNode( "c" ).setCollapse( true );
9816 t2.getNode( "d" ).setCollapse( true );
9817 t2.getNode( "e" ).setCollapse( true );
9818 t2.getNode( "gh" ).setCollapse( true );
9819 n = t2.getNode( "ab" );
9820 ext = new ArrayList<PhylogenyNode>();
9821 while ( n != null ) {
9823 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9825 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9828 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9831 if ( !ext.get( 2 ).getName().equals( "f" ) ) {
9834 if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
9840 final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9841 final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
9842 t3.getNode( "ab" ).setCollapse( true );
9843 t3.getNode( "cd" ).setCollapse( true );
9844 t3.getNode( "cde" ).setCollapse( true );
9845 t3.getNode( "c" ).setCollapse( true );
9846 t3.getNode( "d" ).setCollapse( true );
9847 t3.getNode( "e" ).setCollapse( true );
9848 t3.getNode( "gh" ).setCollapse( true );
9849 t3.getNode( "fgh" ).setCollapse( true );
9850 n = t3.getNode( "ab" );
9851 ext = new ArrayList<PhylogenyNode>();
9852 while ( n != null ) {
9854 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9856 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9859 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9862 if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
9868 final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9869 final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
9870 t4.getNode( "ab" ).setCollapse( true );
9871 t4.getNode( "cd" ).setCollapse( true );
9872 t4.getNode( "cde" ).setCollapse( true );
9873 t4.getNode( "c" ).setCollapse( true );
9874 t4.getNode( "d" ).setCollapse( true );
9875 t4.getNode( "e" ).setCollapse( true );
9876 t4.getNode( "gh" ).setCollapse( true );
9877 t4.getNode( "fgh" ).setCollapse( true );
9878 t4.getNode( "abcdefgh" ).setCollapse( true );
9879 n = t4.getNode( "abcdefgh" );
9880 if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
9885 final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9886 final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
9888 n = t5.getFirstExternalNode();
9889 while ( n != null ) {
9891 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9893 if ( ext.size() != 8 ) {
9896 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
9899 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
9902 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
9905 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
9908 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
9911 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
9914 if ( !ext.get( 6 ).getName().equals( "g" ) ) {
9917 if ( !ext.get( 7 ).getName().equals( "h" ) ) {
9922 final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9923 final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
9925 t6.getNode( "ab" ).setCollapse( true );
9926 n = t6.getNode( "ab" );
9927 while ( n != null ) {
9929 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9931 if ( ext.size() != 7 ) {
9934 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9937 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
9940 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
9943 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
9946 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
9949 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
9952 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
9957 final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9958 final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
9960 t7.getNode( "cd" ).setCollapse( true );
9961 n = t7.getNode( "a" );
9962 while ( n != null ) {
9964 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9966 if ( ext.size() != 7 ) {
9969 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
9972 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
9975 if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
9978 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
9981 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
9984 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
9987 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
9992 final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9993 final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
9995 t8.getNode( "cd" ).setCollapse( true );
9996 t8.getNode( "c" ).setCollapse( true );
9997 t8.getNode( "d" ).setCollapse( true );
9998 n = t8.getNode( "a" );
9999 while ( n != null ) {
10001 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10003 if ( ext.size() != 7 ) {
10006 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10009 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10012 if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
10013 System.out.println( "2 fail" );
10016 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10019 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
10022 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
10025 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
10030 final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10031 final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
10033 t9.getNode( "gh" ).setCollapse( true );
10034 n = t9.getNode( "a" );
10035 while ( n != null ) {
10037 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10039 if ( ext.size() != 7 ) {
10042 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10045 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10048 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10051 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10054 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10057 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
10060 if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
10065 final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10066 final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
10068 t10.getNode( "gh" ).setCollapse( true );
10069 t10.getNode( "g" ).setCollapse( true );
10070 t10.getNode( "h" ).setCollapse( true );
10071 n = t10.getNode( "a" );
10072 while ( n != null ) {
10074 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10076 if ( ext.size() != 7 ) {
10079 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10082 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10085 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10088 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10091 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10094 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
10097 if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
10102 final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10103 final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
10105 t11.getNode( "gh" ).setCollapse( true );
10106 t11.getNode( "fgh" ).setCollapse( true );
10107 n = t11.getNode( "a" );
10108 while ( n != null ) {
10110 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10112 if ( ext.size() != 6 ) {
10115 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10118 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10121 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10124 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10127 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10130 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10135 final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10136 final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
10138 t12.getNode( "gh" ).setCollapse( true );
10139 t12.getNode( "fgh" ).setCollapse( true );
10140 t12.getNode( "g" ).setCollapse( true );
10141 t12.getNode( "h" ).setCollapse( true );
10142 t12.getNode( "f" ).setCollapse( true );
10143 n = t12.getNode( "a" );
10144 while ( n != null ) {
10146 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10148 if ( ext.size() != 6 ) {
10151 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10154 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10157 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10160 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10163 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10166 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10171 final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10172 final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
10174 t13.getNode( "ab" ).setCollapse( true );
10175 t13.getNode( "b" ).setCollapse( true );
10176 t13.getNode( "fgh" ).setCollapse( true );
10177 t13.getNode( "gh" ).setCollapse( true );
10178 n = t13.getNode( "ab" );
10179 while ( n != null ) {
10181 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10183 if ( ext.size() != 5 ) {
10186 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10189 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10192 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10195 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10198 if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
10203 final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
10204 final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
10206 t14.getNode( "ab" ).setCollapse( true );
10207 t14.getNode( "a" ).setCollapse( true );
10208 t14.getNode( "fgh" ).setCollapse( true );
10209 t14.getNode( "gh" ).setCollapse( true );
10210 n = t14.getNode( "ab" );
10211 while ( n != null ) {
10213 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10215 if ( ext.size() != 5 ) {
10218 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10221 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10224 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10227 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10230 if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
10235 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" );
10236 final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
10238 t15.getNode( "ab" ).setCollapse( true );
10239 t15.getNode( "a" ).setCollapse( true );
10240 t15.getNode( "fgh" ).setCollapse( true );
10241 t15.getNode( "gh" ).setCollapse( true );
10242 n = t15.getNode( "ab" );
10243 while ( n != null ) {
10245 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10247 if ( ext.size() != 6 ) {
10250 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10253 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10256 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10259 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10262 if ( !ext.get( 4 ).getName().equals( "x" ) ) {
10265 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10270 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" );
10271 final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
10273 t16.getNode( "ab" ).setCollapse( true );
10274 t16.getNode( "a" ).setCollapse( true );
10275 t16.getNode( "fgh" ).setCollapse( true );
10276 t16.getNode( "gh" ).setCollapse( true );
10277 t16.getNode( "cd" ).setCollapse( true );
10278 t16.getNode( "cde" ).setCollapse( true );
10279 t16.getNode( "d" ).setCollapse( true );
10280 t16.getNode( "x" ).setCollapse( true );
10281 n = t16.getNode( "ab" );
10282 while ( n != null ) {
10284 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10286 if ( ext.size() != 4 ) {
10289 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10292 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
10295 if ( !ext.get( 2 ).getName().equals( "x" ) ) {
10298 if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
10302 catch ( final Exception e ) {
10303 e.printStackTrace( System.out );
10309 private static boolean testMsaQualityMethod() {
10311 final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
10312 final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
10313 final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
10314 final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
10315 final List<Sequence> l = new ArrayList<Sequence>();
10320 final Msa msa = BasicMsa.createInstance( l );
10321 if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
10324 if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
10327 if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
10330 if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
10334 catch ( final Exception e ) {
10335 e.printStackTrace( System.out );
10341 private static boolean testSequenceIdParsing() {
10343 Identifier id = SequenceIdParser.parse( "gb_ADF31344_segmented_worms_" );
10344 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10345 || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
10346 if ( id != null ) {
10347 System.out.println( "value =" + id.getValue() );
10348 System.out.println( "provider=" + id.getProvider() );
10353 id = SequenceIdParser.parse( "segmented worms|gb_ADF31344" );
10354 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10355 || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
10356 if ( id != null ) {
10357 System.out.println( "value =" + id.getValue() );
10358 System.out.println( "provider=" + id.getProvider() );
10363 id = SequenceIdParser.parse( "segmented worms gb_ADF31344 and more" );
10364 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10365 || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
10366 if ( id != null ) {
10367 System.out.println( "value =" + id.getValue() );
10368 System.out.println( "provider=" + id.getProvider() );
10373 id = SequenceIdParser.parse( "gb_AAA96518_1" );
10374 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10375 || !id.getValue().equals( "AAA96518" ) || !id.getProvider().equals( "ncbi" ) ) {
10376 if ( id != null ) {
10377 System.out.println( "value =" + id.getValue() );
10378 System.out.println( "provider=" + id.getProvider() );
10383 id = SequenceIdParser.parse( "gb_EHB07727_1_rodents_" );
10384 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10385 || !id.getValue().equals( "EHB07727" ) || !id.getProvider().equals( "ncbi" ) ) {
10386 if ( id != null ) {
10387 System.out.println( "value =" + id.getValue() );
10388 System.out.println( "provider=" + id.getProvider() );
10393 id = SequenceIdParser.parse( "dbj_BAF37827_1_turtles_" );
10394 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10395 || !id.getValue().equals( "BAF37827" ) || !id.getProvider().equals( "ncbi" ) ) {
10396 if ( id != null ) {
10397 System.out.println( "value =" + id.getValue() );
10398 System.out.println( "provider=" + id.getProvider() );
10403 id = SequenceIdParser.parse( "emb_CAA73223_1_primates_" );
10404 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10405 || !id.getValue().equals( "CAA73223" ) || !id.getProvider().equals( "ncbi" ) ) {
10406 if ( id != null ) {
10407 System.out.println( "value =" + id.getValue() );
10408 System.out.println( "provider=" + id.getProvider() );
10413 id = SequenceIdParser.parse( "mites|ref_XP_002434188_1" );
10414 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10415 || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
10416 if ( id != null ) {
10417 System.out.println( "value =" + id.getValue() );
10418 System.out.println( "provider=" + id.getProvider() );
10423 id = SequenceIdParser.parse( "mites_ref_XP_002434188_1_bla_XP_12345" );
10424 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10425 || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
10426 if ( id != null ) {
10427 System.out.println( "value =" + id.getValue() );
10428 System.out.println( "provider=" + id.getProvider() );
10433 id = SequenceIdParser.parse( "P4A123" );
10434 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10435 || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
10436 if ( id != null ) {
10437 System.out.println( "value =" + id.getValue() );
10438 System.out.println( "provider=" + id.getProvider() );
10443 id = SequenceIdParser.parse( "pllf[pok P4A123_osdjfosnqo035-9233332904i000490 vf tmv x45" );
10444 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10445 || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
10446 if ( id != null ) {
10447 System.out.println( "value =" + id.getValue() );
10448 System.out.println( "provider=" + id.getProvider() );
10453 id = SequenceIdParser.parse( "XP_12345" );
10454 if ( id != null ) {
10455 System.out.println( "value =" + id.getValue() );
10456 System.out.println( "provider=" + id.getProvider() );
10459 // lcl_91970_unknown_
10461 catch ( final Exception e ) {
10462 e.printStackTrace( System.out );