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.io.writers.SequenceWriter;
61 import org.forester.msa.BasicMsa;
62 import org.forester.msa.Mafft;
63 import org.forester.msa.Msa;
64 import org.forester.msa.MsaInferrer;
65 import org.forester.msa.MsaMethods;
66 import org.forester.pccx.TestPccx;
67 import org.forester.phylogeny.Phylogeny;
68 import org.forester.phylogeny.PhylogenyBranch;
69 import org.forester.phylogeny.PhylogenyMethods;
70 import org.forester.phylogeny.PhylogenyNode;
71 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
72 import org.forester.phylogeny.data.Accession;
73 import org.forester.phylogeny.data.BinaryCharacters;
74 import org.forester.phylogeny.data.BranchWidth;
75 import org.forester.phylogeny.data.Confidence;
76 import org.forester.phylogeny.data.Distribution;
77 import org.forester.phylogeny.data.DomainArchitecture;
78 import org.forester.phylogeny.data.Event;
79 import org.forester.phylogeny.data.Identifier;
80 import org.forester.phylogeny.data.PhylogenyData;
81 import org.forester.phylogeny.data.PhylogenyDataUtil;
82 import org.forester.phylogeny.data.Polygon;
83 import org.forester.phylogeny.data.PropertiesMap;
84 import org.forester.phylogeny.data.Property;
85 import org.forester.phylogeny.data.Property.AppliesTo;
86 import org.forester.phylogeny.data.ProteinDomain;
87 import org.forester.phylogeny.data.Taxonomy;
88 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
89 import org.forester.phylogeny.factories.PhylogenyFactory;
90 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
91 import org.forester.protein.Protein;
92 import org.forester.rio.TestRIO;
93 import org.forester.sdi.SDI;
94 import org.forester.sdi.SDIR;
95 import org.forester.sdi.TestGSDI;
96 import org.forester.sequence.BasicSequence;
97 import org.forester.sequence.Sequence;
98 import org.forester.surfacing.TestSurfacing;
99 import org.forester.tools.ConfidenceAssessor;
100 import org.forester.tools.SupportCount;
101 import org.forester.tools.TreeSplitMatrix;
102 import org.forester.util.AsciiHistogram;
103 import org.forester.util.BasicDescriptiveStatistics;
104 import org.forester.util.BasicTable;
105 import org.forester.util.BasicTableParser;
106 import org.forester.util.DescriptiveStatistics;
107 import org.forester.util.ForesterConstants;
108 import org.forester.util.ForesterUtil;
109 import org.forester.util.GeneralTable;
110 import org.forester.util.SequenceIdParser;
111 import org.forester.ws.seqdb.SequenceDatabaseEntry;
112 import org.forester.ws.seqdb.SequenceDbWsTools;
113 import org.forester.ws.seqdb.UniProtTaxonomy;
114 import org.forester.ws.wabi.TxSearch;
115 import org.forester.ws.wabi.TxSearch.RANKS;
116 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
117 import org.forester.ws.wabi.TxSearch.TAX_RANK;
119 @SuppressWarnings( "unused")
120 public final class Test {
122 private final static double ZERO_DIFF = 1.0E-9;
123 private final static String PATH_TO_TEST_DATA = System.getProperty( "user.dir" )
124 + ForesterUtil.getFileSeparator() + "test_data"
125 + ForesterUtil.getFileSeparator();
126 private final static String PATH_TO_RESOURCES = System.getProperty( "user.dir" )
127 + ForesterUtil.getFileSeparator() + "resources"
128 + ForesterUtil.getFileSeparator();
129 private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
130 private static final String PHYLOXML_REMOTE_XSD = ForesterConstants.PHYLO_XML_LOCATION + "/"
131 + ForesterConstants.PHYLO_XML_VERSION + "/"
132 + ForesterConstants.PHYLO_XML_XSD;
133 private static final String PHYLOXML_LOCAL_XSD = PATH_TO_RESOURCES + "phyloxml_schema/"
134 + ForesterConstants.PHYLO_XML_VERSION + "/"
135 + ForesterConstants.PHYLO_XML_XSD;
137 private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
138 final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
142 private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
143 return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
146 public static boolean isEqual( final double a, final double b ) {
147 return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
150 public static void main( final String[] args ) {
151 System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
152 System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
154 Locale.setDefault( Locale.US );
155 System.out.println( "[Locale: " + Locale.getDefault() + "]" );
158 System.out.print( "[Test if directory with files for testing exists/is readable: " );
159 if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
160 System.out.println( "OK.]" );
163 System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
164 System.out.println( "Testing aborted." );
167 System.out.print( "[Test if resources directory exists/is readable: " );
168 if ( testDir( PATH_TO_RESOURCES ) ) {
169 System.out.println( "OK.]" );
172 System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
173 System.out.println( "Testing aborted." );
176 final long start_time = new Date().getTime();
177 System.out.print( "Sequence writer: " );
178 if ( testSequenceWriter() ) {
179 System.out.println( "OK." );
183 System.out.println( "failed." );
186 System.out.print( "Sequence id parsing: " );
187 if ( testSequenceIdParsing() ) {
188 System.out.println( "OK." );
192 System.out.println( "failed." );
195 System.out.print( "Hmmscan output parser: " );
196 if ( testHmmscanOutputParser() ) {
197 System.out.println( "OK." );
201 System.out.println( "failed." );
204 System.out.print( "Basic node methods: " );
205 if ( Test.testBasicNodeMethods() ) {
206 System.out.println( "OK." );
210 System.out.println( "failed." );
213 System.out.print( "Taxonomy code extraction: " );
214 if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
215 System.out.println( "OK." );
219 System.out.println( "failed." );
222 System.out.print( "SN extraction: " );
223 if ( Test.testExtractSNFromNodeName() ) {
224 System.out.println( "OK." );
228 System.out.println( "failed." );
231 System.out.print( "Taxonomy extraction (general): " );
232 if ( Test.testTaxonomyExtraction() ) {
233 System.out.println( "OK." );
237 System.out.println( "failed." );
240 System.out.print( "UniProtKB id extraction: " );
241 if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
242 System.out.println( "OK." );
246 System.out.println( "failed." );
249 System.out.print( "Uri for Aptx web sequence accession: " );
250 if ( Test.testCreateUriForSeqWeb() ) {
251 System.out.println( "OK." );
255 System.out.println( "failed." );
258 System.out.print( "Basic node construction and parsing of NHX (node level): " );
259 if ( Test.testNHXNodeParsing() ) {
260 System.out.println( "OK." );
264 System.out.println( "failed." );
267 System.out.print( "NHX parsing iterating: " );
268 if ( Test.testNHParsingIter() ) {
269 System.out.println( "OK." );
273 System.out.println( "failed." );
276 System.out.print( "NH parsing: " );
277 if ( Test.testNHParsing() ) {
278 System.out.println( "OK." );
282 System.out.println( "failed." );
285 System.out.print( "Conversion to NHX (node level): " );
286 if ( Test.testNHXconversion() ) {
287 System.out.println( "OK." );
291 System.out.println( "failed." );
294 System.out.print( "NHX parsing: " );
295 if ( Test.testNHXParsing() ) {
296 System.out.println( "OK." );
300 System.out.println( "failed." );
303 System.out.print( "NHX parsing with quotes: " );
304 if ( Test.testNHXParsingQuotes() ) {
305 System.out.println( "OK." );
309 System.out.println( "failed." );
312 System.out.print( "NHX parsing (MrBayes): " );
313 if ( Test.testNHXParsingMB() ) {
314 System.out.println( "OK." );
318 System.out.println( "failed." );
321 System.out.print( "Nexus characters parsing: " );
322 if ( Test.testNexusCharactersParsing() ) {
323 System.out.println( "OK." );
327 System.out.println( "failed." );
330 System.out.print( "Nexus tree parsing iterating: " );
331 if ( Test.testNexusTreeParsingIterating() ) {
332 System.out.println( "OK." );
336 System.out.println( "failed." );
339 System.out.print( "Nexus tree parsing: " );
340 if ( Test.testNexusTreeParsing() ) {
341 System.out.println( "OK." );
345 System.out.println( "failed." );
348 System.out.print( "Nexus tree parsing (translating): " );
349 if ( Test.testNexusTreeParsingTranslating() ) {
350 System.out.println( "OK." );
354 System.out.println( "failed." );
357 System.out.print( "Nexus matrix parsing: " );
358 if ( Test.testNexusMatrixParsing() ) {
359 System.out.println( "OK." );
363 System.out.println( "failed." );
366 System.out.print( "Basic phyloXML parsing: " );
367 if ( Test.testBasicPhyloXMLparsing() ) {
368 System.out.println( "OK." );
372 System.out.println( "failed." );
375 System.out.print( "Basic phyloXML parsing (validating against schema): " );
376 if ( testBasicPhyloXMLparsingValidating() ) {
377 System.out.println( "OK." );
381 System.out.println( "failed." );
384 System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
385 if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
386 System.out.println( "OK." );
390 System.out.println( "failed." );
393 System.out.print( "phyloXML Distribution Element: " );
394 if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
395 System.out.println( "OK." );
399 System.out.println( "failed." );
402 System.out.print( "Tol XML parsing: " );
403 if ( Test.testBasicTolXMLparsing() ) {
404 System.out.println( "OK." );
408 System.out.println( "failed." );
411 System.out.print( "Copying of node data: " );
412 if ( Test.testCopyOfNodeData() ) {
413 System.out.println( "OK." );
417 System.out.println( "failed." );
420 System.out.print( "Basic tree methods: " );
421 if ( Test.testBasicTreeMethods() ) {
422 System.out.println( "OK." );
426 System.out.println( "failed." );
429 System.out.print( "Tree methods: " );
430 if ( Test.testTreeMethods() ) {
431 System.out.println( "OK." );
435 System.out.println( "failed." );
438 System.out.print( "Postorder Iterator: " );
439 if ( Test.testPostOrderIterator() ) {
440 System.out.println( "OK." );
444 System.out.println( "failed." );
447 System.out.print( "Preorder Iterator: " );
448 if ( Test.testPreOrderIterator() ) {
449 System.out.println( "OK." );
453 System.out.println( "failed." );
456 System.out.print( "Levelorder Iterator: " );
457 if ( Test.testLevelOrderIterator() ) {
458 System.out.println( "OK." );
462 System.out.println( "failed." );
465 System.out.print( "Re-id methods: " );
466 if ( Test.testReIdMethods() ) {
467 System.out.println( "OK." );
471 System.out.println( "failed." );
474 System.out.print( "Methods on last external nodes: " );
475 if ( Test.testLastExternalNodeMethods() ) {
476 System.out.println( "OK." );
480 System.out.println( "failed." );
483 System.out.print( "Methods on external nodes: " );
484 if ( Test.testExternalNodeRelatedMethods() ) {
485 System.out.println( "OK." );
489 System.out.println( "failed." );
492 System.out.print( "Deletion of external nodes: " );
493 if ( Test.testDeletionOfExternalNodes() ) {
494 System.out.println( "OK." );
498 System.out.println( "failed." );
501 System.out.print( "Subtree deletion: " );
502 if ( Test.testSubtreeDeletion() ) {
503 System.out.println( "OK." );
507 System.out.println( "failed." );
510 System.out.print( "Phylogeny branch: " );
511 if ( Test.testPhylogenyBranch() ) {
512 System.out.println( "OK." );
516 System.out.println( "failed." );
519 System.out.print( "Rerooting: " );
520 if ( Test.testRerooting() ) {
521 System.out.println( "OK." );
525 System.out.println( "failed." );
528 System.out.print( "Mipoint rooting: " );
529 if ( Test.testMidpointrooting() ) {
530 System.out.println( "OK." );
534 System.out.println( "failed." );
537 System.out.print( "Node removal: " );
538 if ( Test.testNodeRemoval() ) {
539 System.out.println( "OK." );
543 System.out.println( "failed." );
546 System.out.print( "Support count: " );
547 if ( Test.testSupportCount() ) {
548 System.out.println( "OK." );
552 System.out.println( "failed." );
555 System.out.print( "Support transfer: " );
556 if ( Test.testSupportTransfer() ) {
557 System.out.println( "OK." );
561 System.out.println( "failed." );
564 System.out.print( "Finding of LCA: " );
565 if ( Test.testGetLCA() ) {
566 System.out.println( "OK." );
570 System.out.println( "failed." );
573 System.out.print( "Finding of LCA 2: " );
574 if ( Test.testGetLCA2() ) {
575 System.out.println( "OK." );
579 System.out.println( "failed." );
582 System.out.print( "Calculation of distance between nodes: " );
583 if ( Test.testGetDistance() ) {
584 System.out.println( "OK." );
588 System.out.println( "failed." );
591 System.out.print( "Descriptive statistics: " );
592 if ( Test.testDescriptiveStatistics() ) {
593 System.out.println( "OK." );
597 System.out.println( "failed." );
600 System.out.print( "Data objects and methods: " );
601 if ( Test.testDataObjects() ) {
602 System.out.println( "OK." );
606 System.out.println( "failed." );
609 System.out.print( "Properties map: " );
610 if ( Test.testPropertiesMap() ) {
611 System.out.println( "OK." );
615 System.out.println( "failed." );
618 System.out.print( "SDIse: " );
619 if ( Test.testSDIse() ) {
620 System.out.println( "OK." );
624 System.out.println( "failed." );
627 System.out.print( "SDIunrooted: " );
628 if ( Test.testSDIunrooted() ) {
629 System.out.println( "OK." );
633 System.out.println( "failed." );
636 System.out.print( "GSDI: " );
637 if ( TestGSDI.test() ) {
638 System.out.println( "OK." );
642 System.out.println( "failed." );
645 System.out.print( "RIO: " );
646 if ( TestRIO.test() ) {
647 System.out.println( "OK." );
651 System.out.println( "failed." );
654 System.out.print( "Phylogeny reconstruction:" );
655 System.out.println();
656 if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
657 System.out.println( "OK." );
661 System.out.println( "failed." );
664 System.out.print( "Analysis of domain architectures: " );
665 System.out.println();
666 if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
667 System.out.println( "OK." );
671 System.out.println( "failed." );
674 System.out.print( "GO: " );
675 System.out.println();
676 if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
677 System.out.println( "OK." );
681 System.out.println( "failed." );
684 System.out.print( "Modeling tools: " );
685 if ( TestPccx.test() ) {
686 System.out.println( "OK." );
690 System.out.println( "failed." );
693 System.out.print( "Split Matrix strict: " );
694 if ( Test.testSplitStrict() ) {
695 System.out.println( "OK." );
699 System.out.println( "failed." );
702 System.out.print( "Split Matrix: " );
703 if ( Test.testSplit() ) {
704 System.out.println( "OK." );
708 System.out.println( "failed." );
711 System.out.print( "Confidence Assessor: " );
712 if ( Test.testConfidenceAssessor() ) {
713 System.out.println( "OK." );
717 System.out.println( "failed." );
720 System.out.print( "Basic table: " );
721 if ( Test.testBasicTable() ) {
722 System.out.println( "OK." );
726 System.out.println( "failed." );
729 System.out.print( "General table: " );
730 if ( Test.testGeneralTable() ) {
731 System.out.println( "OK." );
735 System.out.println( "failed." );
738 System.out.print( "Amino acid sequence: " );
739 if ( Test.testAminoAcidSequence() ) {
740 System.out.println( "OK." );
744 System.out.println( "failed." );
747 System.out.print( "General MSA parser: " );
748 if ( Test.testGeneralMsaParser() ) {
749 System.out.println( "OK." );
753 System.out.println( "failed." );
756 System.out.print( "Fasta parser for msa: " );
757 if ( Test.testFastaParser() ) {
758 System.out.println( "OK." );
762 System.out.println( "failed." );
765 System.out.print( "Creation of balanced phylogeny: " );
766 if ( Test.testCreateBalancedPhylogeny() ) {
767 System.out.println( "OK." );
771 System.out.println( "failed." );
774 System.out.print( "EMBL Entry Retrieval: " );
775 if ( Test.testEmblEntryRetrieval() ) {
776 System.out.println( "OK." );
780 System.out.println( "failed." );
783 System.out.print( "Uniprot Entry Retrieval: " );
784 if ( Test.testUniprotEntryRetrieval() ) {
785 System.out.println( "OK." );
789 System.out.println( "failed." );
792 System.out.print( "Uniprot Taxonomy Search: " );
793 if ( Test.testUniprotTaxonomySearch() ) {
794 System.out.println( "OK." );
798 System.out.println( "failed." );
803 final String os = ForesterUtil.OS_NAME.toLowerCase();
804 if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
805 path = "/usr/local/bin/mafft";
807 else if ( os.indexOf( "win" ) >= 0 ) {
808 path = "C:\\Program Files\\mafft-win\\mafft.bat";
811 path = "/home/czmasek/bin/mafft";
813 if ( !MsaInferrer.isInstalled( path ) ) {
816 if ( !MsaInferrer.isInstalled( path ) ) {
817 path = "/usr/local/bin/mafft";
819 if ( MsaInferrer.isInstalled( path ) ) {
820 System.out.print( "MAFFT (external program): " );
821 if ( Test.testMafft( path ) ) {
822 System.out.println( "OK." );
826 System.out.println( "failed [will not count towards failed tests]" );
830 System.out.print( "Next nodes with collapsed: " );
831 if ( Test.testNextNodeWithCollapsing() ) {
832 System.out.println( "OK." );
836 System.out.println( "failed." );
839 System.out.print( "Simple MSA quality: " );
840 if ( Test.testMsaQualityMethod() ) {
841 System.out.println( "OK." );
845 System.out.println( "failed." );
848 System.out.println();
849 final Runtime rt = java.lang.Runtime.getRuntime();
850 final long free_memory = rt.freeMemory() / 1000000;
851 final long total_memory = rt.totalMemory() / 1000000;
852 System.out.println( "Running time : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
853 + free_memory + "MB, total memory: " + total_memory + "MB)" );
854 System.out.println();
855 System.out.println( "Successful tests: " + succeeded );
856 System.out.println( "Failed tests: " + failed );
857 System.out.println();
859 System.out.println( "OK." );
862 System.out.println( "Not OK." );
866 private static boolean testExtractUniProtKbProteinSeqIdentifier() {
868 PhylogenyNode n = new PhylogenyNode();
869 n.setName( "tr|B3RJ64" );
870 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
873 n.setName( "tr.B3RJ64" );
874 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
877 n.setName( "tr=B3RJ64" );
878 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
881 n.setName( "tr-B3RJ64" );
882 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
885 n.setName( "tr/B3RJ64" );
886 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
889 n.setName( "tr\\B3RJ64" );
890 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
893 n.setName( "tr_B3RJ64" );
894 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
897 n.setName( " tr|B3RJ64 " );
898 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
901 n.setName( "-tr|B3RJ64-" );
902 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
905 n.setName( "-tr=B3RJ64-" );
906 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
909 n.setName( "_tr=B3RJ64_" );
910 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
913 n.setName( " tr_tr|B3RJ64_sp|123 " );
914 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
917 n.setName( "sp|B3RJ64" );
918 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
921 n.setName( "ssp|B3RJ64" );
922 if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
925 n.setName( "sp|B3RJ64C" );
926 if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
929 n.setName( "sp B3RJ64" );
930 if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
933 n.setName( "sp|B3RJ6X" );
934 if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
937 n.setName( "sp|B3RJ6" );
938 if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
941 n.setName( "K1PYK7_CRAGI" );
942 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
945 n.setName( "K1PYK7_PEA" );
946 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PEA" ) ) {
949 n.setName( "K1PYK7_RAT" );
950 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_RAT" ) ) {
953 n.setName( "K1PYK7_PIG" );
954 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PIG" ) ) {
957 n.setName( "~K1PYK7_PIG~" );
958 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PIG" ) ) {
961 n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
962 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
965 n.setName( "K1PYKX_CRAGI" );
966 if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
969 n.setName( "XXXXX_CRAGI" );
970 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "XXXXX_CRAGI" ) ) {
973 n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
974 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "H3IB65" ) ) {
977 n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
978 if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
981 n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
982 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "Q86U06" ) ) {
985 n = new PhylogenyNode();
986 org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
987 seq.setSymbol( "K1PYK7_CRAGI" );
988 n.getNodeData().addSequence( seq );
989 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
992 seq.setSymbol( "tr|B3RJ64" );
993 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
996 n = new PhylogenyNode();
997 seq = new org.forester.phylogeny.data.Sequence();
998 seq.setName( "K1PYK7_CRAGI" );
999 n.getNodeData().addSequence( seq );
1000 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
1003 seq.setName( "tr|B3RJ64" );
1004 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
1007 n = new PhylogenyNode();
1008 seq = new org.forester.phylogeny.data.Sequence();
1009 seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
1010 n.getNodeData().addSequence( seq );
1011 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK8_CRAGI" ) ) {
1014 n = new PhylogenyNode();
1015 seq = new org.forester.phylogeny.data.Sequence();
1016 seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
1017 n.getNodeData().addSequence( seq );
1018 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
1022 n = new PhylogenyNode();
1023 n.setName( "ACP19736" );
1024 if ( !ForesterUtil.extractGenbankAccessor( n ).equals( "ACP19736" ) ) {
1027 n = new PhylogenyNode();
1028 n.setName( "_ACP19736_" );
1029 if ( !ForesterUtil.extractGenbankAccessor( n ).equals( "ACP19736" ) ) {
1033 catch ( final Exception e ) {
1034 e.printStackTrace( System.out );
1040 private static boolean testCreateUriForSeqWeb() {
1042 final PhylogenyNode n = new PhylogenyNode();
1043 n.setName( "tr|B3RJ64" );
1044 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
1047 n.setName( "B0LM41_HUMAN" );
1048 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
1051 n.setName( "NP_001025424" );
1052 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
1055 n.setName( "_NM_001030253-" );
1056 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
1059 n.setName( "XM_002122186" );
1060 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
1063 n.setName( "dgh_AAA34956_gdg" );
1064 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
1067 n.setName( "j40f4_Q06891.1_fndn2 fnr3" );
1068 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "Q06891.1" ) ) {
1071 n.setName( "GI:394892" );
1072 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
1073 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
1076 n.setName( "gi_394892" );
1077 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
1078 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
1081 n.setName( "gi6335_gi_394892_56635_Gi_43" );
1082 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
1083 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
1087 catch ( final Exception e ) {
1088 e.printStackTrace( System.out );
1094 private static boolean testExtractSNFromNodeName() {
1096 if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
1099 if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus" )
1100 .equals( "Mus musculus musculus" ) ) {
1103 if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus-12" )
1104 .equals( "Mus musculus musculus" ) ) {
1107 if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus-12" ).equals( "Mus musculus" ) ) {
1110 if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus-12 affrre e" )
1111 .equals( "Mus musculus" ) ) {
1115 catch ( final Exception e ) {
1116 e.printStackTrace( System.out );
1122 private static boolean testExtractTaxonomyCodeFromNodeName() {
1124 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1127 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
1128 .equals( "SOYBN" ) ) {
1131 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
1132 .equals( "ARATH" ) ) {
1135 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
1136 .equals( "ARATH" ) ) {
1139 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
1142 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
1145 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1148 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
1149 .equals( "SOYBN" ) ) {
1152 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
1153 .equals( "SOYBN" ) ) {
1156 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
1157 .equals( "SOYBN" ) ) {
1160 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
1161 .equals( "SOYBN" ) ) {
1164 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1165 .equals( "SOYBN" ) ) {
1168 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
1169 .equals( "SOYBN" ) ) {
1172 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
1173 .equals( "SOYBN" ) ) {
1176 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
1177 .equals( "SOYBN" ) ) {
1180 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
1183 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
1184 .equals( "SOYBN" ) ) {
1187 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
1188 TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
1191 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
1192 .equals( "9YX45" ) ) {
1195 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
1196 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1197 .equals( "MOUSE" ) ) {
1200 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
1201 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1202 .equals( "MOUSE" ) ) {
1205 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
1206 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1207 .equals( "MOUSE" ) ) {
1210 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
1211 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1214 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
1215 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1218 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
1219 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1222 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
1223 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1226 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
1227 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
1230 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
1231 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1234 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
1235 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1238 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1239 .equals( "RAT" ) ) {
1242 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
1243 .equals( "PIG" ) ) {
1247 .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
1248 .equals( "MOUSE" ) ) {
1251 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
1252 .equals( "MOUSE" ) ) {
1255 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
1259 catch ( final Exception e ) {
1260 e.printStackTrace( System.out );
1266 private static boolean testBasicNodeMethods() {
1268 if ( PhylogenyNode.getNodeCount() != 0 ) {
1271 final PhylogenyNode n1 = new PhylogenyNode();
1272 final PhylogenyNode n2 = PhylogenyNode
1273 .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1274 final PhylogenyNode n3 = PhylogenyNode
1275 .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1276 final PhylogenyNode n4 = PhylogenyNode
1277 .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1278 if ( n1.isHasAssignedEvent() ) {
1281 if ( PhylogenyNode.getNodeCount() != 4 ) {
1284 if ( n3.getIndicator() != 0 ) {
1287 if ( n3.getNumberOfExternalNodes() != 1 ) {
1290 if ( !n3.isExternal() ) {
1293 if ( !n3.isRoot() ) {
1296 if ( !n4.getName().equals( "n4" ) ) {
1300 catch ( final Exception e ) {
1301 e.printStackTrace( System.out );
1307 private static boolean testBasicPhyloXMLparsing() {
1309 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1310 final PhyloXmlParser xml_parser = new PhyloXmlParser();
1311 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1313 if ( xml_parser.getErrorCount() > 0 ) {
1314 System.out.println( xml_parser.getErrorMessages().toString() );
1317 if ( phylogenies_0.length != 4 ) {
1320 final Phylogeny t1 = phylogenies_0[ 0 ];
1321 final Phylogeny t2 = phylogenies_0[ 1 ];
1322 final Phylogeny t3 = phylogenies_0[ 2 ];
1323 final Phylogeny t4 = phylogenies_0[ 3 ];
1324 if ( t1.getNumberOfExternalNodes() != 1 ) {
1327 if ( !t1.isRooted() ) {
1330 if ( t1.isRerootable() ) {
1333 if ( !t1.getType().equals( "gene_tree" ) ) {
1336 if ( t2.getNumberOfExternalNodes() != 2 ) {
1339 if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1342 if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1345 if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1348 if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1351 if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1354 if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1357 if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1358 .startsWith( "actgtgggggt" ) ) {
1361 if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1362 .startsWith( "ctgtgatgcat" ) ) {
1365 if ( t3.getNumberOfExternalNodes() != 4 ) {
1368 if ( !t1.getName().equals( "t1" ) ) {
1371 if ( !t2.getName().equals( "t2" ) ) {
1374 if ( !t3.getName().equals( "t3" ) ) {
1377 if ( !t4.getName().equals( "t4" ) ) {
1380 if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1383 if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1386 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1389 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1390 .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1393 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1396 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1399 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1402 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1403 .equals( "apoptosis" ) ) {
1406 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1407 .equals( "GO:0006915" ) ) {
1410 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1411 .equals( "UniProtKB" ) ) {
1414 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1415 .equals( "experimental" ) ) {
1418 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1419 .equals( "function" ) ) {
1422 if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1423 .getValue() != 1 ) {
1426 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1427 .getType().equals( "ml" ) ) {
1430 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1431 .equals( "apoptosis" ) ) {
1434 if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1435 .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1438 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1439 .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1442 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1443 .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1446 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1447 .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1450 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1451 .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1454 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1455 .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1458 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1459 .equals( "GO:0005829" ) ) {
1462 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1463 .equals( "intracellular organelle" ) ) {
1466 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1469 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1470 .equals( "UniProt link" ) ) ) {
1473 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1477 catch ( final Exception e ) {
1478 e.printStackTrace( System.out );
1484 private static boolean testBasicPhyloXMLparsingRoundtrip() {
1486 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1487 final PhyloXmlParser xml_parser = new PhyloXmlParser();
1488 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1489 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1492 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1494 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1496 if ( xml_parser.getErrorCount() > 0 ) {
1497 System.out.println( xml_parser.getErrorMessages().toString() );
1500 if ( phylogenies_0.length != 4 ) {
1503 final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1504 final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1505 if ( phylogenies_t1.length != 1 ) {
1508 final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1509 if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1512 if ( !t1_rt.isRooted() ) {
1515 if ( t1_rt.isRerootable() ) {
1518 if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1521 final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1522 final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1523 final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1524 if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1527 if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1530 if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1533 if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1536 if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1537 .startsWith( "actgtgggggt" ) ) {
1540 if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1541 .startsWith( "ctgtgatgcat" ) ) {
1544 final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1545 final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1546 final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1547 final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1548 if ( phylogenies_1.length != 1 ) {
1551 final Phylogeny t3_rt = phylogenies_1[ 0 ];
1552 if ( !t3_rt.getName().equals( "t3" ) ) {
1555 if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1558 if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1561 if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1564 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1567 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1568 .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1571 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1574 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1577 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1578 .equals( "UniProtKB" ) ) {
1581 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1582 .equals( "apoptosis" ) ) {
1585 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1586 .equals( "GO:0006915" ) ) {
1589 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1590 .equals( "UniProtKB" ) ) {
1593 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1594 .equals( "experimental" ) ) {
1597 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1598 .equals( "function" ) ) {
1601 if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1602 .getValue() != 1 ) {
1605 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1606 .getType().equals( "ml" ) ) {
1609 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1610 .equals( "apoptosis" ) ) {
1613 if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1614 .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1617 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1618 .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1621 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1622 .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1625 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1626 .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1629 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1630 .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1633 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1634 .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1637 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1638 .equals( "GO:0005829" ) ) {
1641 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1642 .equals( "intracellular organelle" ) ) {
1645 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1648 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1649 .equals( "UniProt link" ) ) ) {
1652 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1655 if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1658 if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1659 .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." ) ) ) {
1662 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1665 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1668 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1671 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1674 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1675 .equals( "ncbi" ) ) {
1678 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1681 if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1682 .getName().equals( "B" ) ) {
1685 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1686 .getFrom() != 21 ) {
1689 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1692 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1693 .getLength() != 24 ) {
1696 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1697 .getConfidence() != 2144 ) {
1700 if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1701 .equals( "pfam" ) ) {
1704 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1707 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1710 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1713 if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1716 final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1717 if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1720 if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1723 if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1726 if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1729 if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1732 if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1735 if ( taxbb.getSynonyms().size() != 2 ) {
1738 if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1741 if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1744 if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1747 if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1750 if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1753 if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1754 .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1758 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1761 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1764 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1767 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1770 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1773 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1776 if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1780 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1783 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1784 .equalsIgnoreCase( "435" ) ) {
1787 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1790 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1791 .equalsIgnoreCase( "443.7" ) ) {
1794 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1797 if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1800 if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1801 .equalsIgnoreCase( "433" ) ) {
1805 catch ( final Exception e ) {
1806 e.printStackTrace( System.out );
1812 private static boolean testBasicPhyloXMLparsingValidating() {
1814 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1815 PhyloXmlParser xml_parser = null;
1817 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1819 catch ( final Exception e ) {
1820 // Do nothing -- means were not running from jar.
1822 if ( xml_parser == null ) {
1823 xml_parser = new PhyloXmlParser();
1824 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1825 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1828 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1831 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1833 if ( xml_parser.getErrorCount() > 0 ) {
1834 System.out.println( xml_parser.getErrorMessages().toString() );
1837 if ( phylogenies_0.length != 4 ) {
1840 final Phylogeny t1 = phylogenies_0[ 0 ];
1841 final Phylogeny t2 = phylogenies_0[ 1 ];
1842 final Phylogeny t3 = phylogenies_0[ 2 ];
1843 final Phylogeny t4 = phylogenies_0[ 3 ];
1844 if ( !t1.getName().equals( "t1" ) ) {
1847 if ( !t2.getName().equals( "t2" ) ) {
1850 if ( !t3.getName().equals( "t3" ) ) {
1853 if ( !t4.getName().equals( "t4" ) ) {
1856 if ( t1.getNumberOfExternalNodes() != 1 ) {
1859 if ( t2.getNumberOfExternalNodes() != 2 ) {
1862 if ( t3.getNumberOfExternalNodes() != 4 ) {
1865 final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
1866 final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
1867 if ( xml_parser.getErrorCount() > 0 ) {
1868 System.out.println( "errors:" );
1869 System.out.println( xml_parser.getErrorMessages().toString() );
1872 if ( phylogenies_1.length != 4 ) {
1875 final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
1877 if ( xml_parser.getErrorCount() > 0 ) {
1878 System.out.println( "errors:" );
1879 System.out.println( xml_parser.getErrorMessages().toString() );
1882 if ( phylogenies_2.length != 1 ) {
1885 if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
1888 final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
1890 if ( xml_parser.getErrorCount() > 0 ) {
1891 System.out.println( xml_parser.getErrorMessages().toString() );
1894 if ( phylogenies_3.length != 2 ) {
1897 final Phylogeny a = phylogenies_3[ 0 ];
1898 if ( !a.getName().equals( "tree 4" ) ) {
1901 if ( a.getNumberOfExternalNodes() != 3 ) {
1904 if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
1907 if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
1910 final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
1912 if ( xml_parser.getErrorCount() > 0 ) {
1913 System.out.println( xml_parser.getErrorMessages().toString() );
1916 if ( phylogenies_4.length != 1 ) {
1919 final Phylogeny s = phylogenies_4[ 0 ];
1920 if ( s.getNumberOfExternalNodes() != 6 ) {
1923 s.getNode( "first" );
1925 s.getNode( "\"<a'b&c'd\">\"" );
1926 s.getNode( "'''\"" );
1927 s.getNode( "\"\"\"" );
1928 s.getNode( "dick & doof" );
1930 catch ( final Exception e ) {
1931 e.printStackTrace( System.out );
1937 private static boolean testBasicTable() {
1939 final BasicTable<String> t0 = new BasicTable<String>();
1940 if ( t0.getNumberOfColumns() != 0 ) {
1943 if ( t0.getNumberOfRows() != 0 ) {
1946 t0.setValue( 3, 2, "23" );
1947 t0.setValue( 10, 1, "error" );
1948 t0.setValue( 10, 1, "110" );
1949 t0.setValue( 9, 1, "19" );
1950 t0.setValue( 1, 10, "101" );
1951 t0.setValue( 10, 10, "1010" );
1952 t0.setValue( 100, 10, "10100" );
1953 t0.setValue( 0, 0, "00" );
1954 if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
1957 if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
1960 if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
1963 if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
1966 if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
1969 if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
1972 if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
1975 if ( t0.getNumberOfColumns() != 101 ) {
1978 if ( t0.getNumberOfRows() != 11 ) {
1981 if ( t0.getValueAsString( 49, 4 ) != null ) {
1984 final String l = ForesterUtil.getLineSeparator();
1985 final StringBuffer source = new StringBuffer();
1986 source.append( "" + l );
1987 source.append( "# 1 1 1 1 1 1 1 1" + l );
1988 source.append( " 00 01 02 03" + l );
1989 source.append( " 10 11 12 13 " + l );
1990 source.append( "20 21 22 23 " + l );
1991 source.append( " 30 31 32 33" + l );
1992 source.append( "40 41 42 43" + l );
1993 source.append( " # 1 1 1 1 1 " + l );
1994 source.append( "50 51 52 53 54" + l );
1995 final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
1996 if ( t1.getNumberOfColumns() != 5 ) {
1999 if ( t1.getNumberOfRows() != 6 ) {
2002 if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2005 if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2008 if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2011 if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2014 final StringBuffer source1 = new StringBuffer();
2015 source1.append( "" + l );
2016 source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2017 source1.append( " 00; 01 ;02;03" + l );
2018 source1.append( " 10; 11; 12; 13 " + l );
2019 source1.append( "20; 21; 22; 23 " + l );
2020 source1.append( " 30; 31; 32; 33" + l );
2021 source1.append( "40;41;42;43" + l );
2022 source1.append( " # 1 1 1 1 1 " + l );
2023 source1.append( ";;;50 ; ;52; 53;;54 " + l );
2024 final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2025 if ( t2.getNumberOfColumns() != 5 ) {
2028 if ( t2.getNumberOfRows() != 6 ) {
2031 if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2034 if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2037 if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2040 if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2043 if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2046 if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2049 final StringBuffer source2 = new StringBuffer();
2050 source2.append( "" + l );
2051 source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2052 source2.append( " 00; 01 ;02;03" + l );
2053 source2.append( " 10; 11; 12; 13 " + l );
2054 source2.append( "20; 21; 22; 23 " + l );
2055 source2.append( " " + l );
2056 source2.append( " 30; 31; 32; 33" + l );
2057 source2.append( "40;41;42;43" + l );
2058 source2.append( " comment: 1 1 1 1 1 " + l );
2059 source2.append( ";;;50 ; 52; 53;;54 " + l );
2060 final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2066 if ( tl.size() != 2 ) {
2069 final BasicTable<String> t3 = tl.get( 0 );
2070 final BasicTable<String> t4 = tl.get( 1 );
2071 if ( t3.getNumberOfColumns() != 4 ) {
2074 if ( t3.getNumberOfRows() != 3 ) {
2077 if ( t4.getNumberOfColumns() != 4 ) {
2080 if ( t4.getNumberOfRows() != 3 ) {
2083 if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2086 if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2090 catch ( final Exception e ) {
2091 e.printStackTrace( System.out );
2097 private static boolean testBasicTolXMLparsing() {
2099 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2100 final TolParser parser = new TolParser();
2101 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2102 if ( parser.getErrorCount() > 0 ) {
2103 System.out.println( parser.getErrorMessages().toString() );
2106 if ( phylogenies_0.length != 1 ) {
2109 final Phylogeny t1 = phylogenies_0[ 0 ];
2110 if ( t1.getNumberOfExternalNodes() != 5 ) {
2113 if ( !t1.isRooted() ) {
2116 if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2119 if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2122 if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2125 if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2128 final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2129 if ( parser.getErrorCount() > 0 ) {
2130 System.out.println( parser.getErrorMessages().toString() );
2133 if ( phylogenies_1.length != 1 ) {
2136 final Phylogeny t2 = phylogenies_1[ 0 ];
2137 if ( t2.getNumberOfExternalNodes() != 664 ) {
2140 if ( !t2.isRooted() ) {
2143 if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2146 if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2149 if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2152 if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2155 if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2158 if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2159 .equals( "Aquifex" ) ) {
2162 final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2163 if ( parser.getErrorCount() > 0 ) {
2164 System.out.println( parser.getErrorMessages().toString() );
2167 if ( phylogenies_2.length != 1 ) {
2170 final Phylogeny t3 = phylogenies_2[ 0 ];
2171 if ( t3.getNumberOfExternalNodes() != 184 ) {
2174 if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2177 if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2180 if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2183 final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2184 if ( parser.getErrorCount() > 0 ) {
2185 System.out.println( parser.getErrorMessages().toString() );
2188 if ( phylogenies_3.length != 1 ) {
2191 final Phylogeny t4 = phylogenies_3[ 0 ];
2192 if ( t4.getNumberOfExternalNodes() != 1 ) {
2195 if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2198 if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2201 if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2204 final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2205 if ( parser.getErrorCount() > 0 ) {
2206 System.out.println( parser.getErrorMessages().toString() );
2209 if ( phylogenies_4.length != 1 ) {
2212 final Phylogeny t5 = phylogenies_4[ 0 ];
2213 if ( t5.getNumberOfExternalNodes() != 13 ) {
2216 if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2219 if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2222 if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2226 catch ( final Exception e ) {
2227 e.printStackTrace( System.out );
2233 private static boolean testBasicTreeMethods() {
2235 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2236 final Phylogeny t1 = factory.create();
2237 if ( !t1.isEmpty() ) {
2240 final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2241 if ( t2.getNumberOfExternalNodes() != 4 ) {
2244 if ( t2.getHeight() != 8.5 ) {
2247 if ( !t2.isCompletelyBinary() ) {
2250 if ( t2.isEmpty() ) {
2253 final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2254 if ( t3.getNumberOfExternalNodes() != 5 ) {
2257 if ( t3.getHeight() != 11 ) {
2260 if ( t3.isCompletelyBinary() ) {
2263 final PhylogenyNode n = t3.getNode( "ABC" );
2264 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 ];
2265 if ( t4.getNumberOfExternalNodes() != 9 ) {
2268 if ( t4.getHeight() != 11 ) {
2271 if ( t4.isCompletelyBinary() ) {
2274 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)" );
2275 final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2276 if ( t5.getNumberOfExternalNodes() != 8 ) {
2279 if ( t5.getHeight() != 15 ) {
2282 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)" );
2283 final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2284 if ( t6.getHeight() != 15 ) {
2287 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)" );
2288 final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2289 if ( t7.getHeight() != 15 ) {
2292 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)" );
2293 final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2294 if ( t8.getNumberOfExternalNodes() != 10 ) {
2297 if ( t8.getHeight() != 15 ) {
2300 final char[] a9 = new char[] { 'a' };
2301 final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2302 if ( t9.getHeight() != 0 ) {
2305 final char[] a10 = new char[] { 'a', ':', '6' };
2306 final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2307 if ( t10.getHeight() != 6 ) {
2311 catch ( final Exception e ) {
2312 e.printStackTrace( System.out );
2318 private static boolean testTreeMethods() {
2320 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2321 final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
2322 PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
2323 if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
2324 System.out.println( t0.toNewHampshireX() );
2327 final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
2328 PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
2329 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
2332 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
2335 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
2339 catch ( final Exception e ) {
2340 e.printStackTrace( System.out );
2346 private static boolean testConfidenceAssessor() {
2348 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2349 final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2350 final Phylogeny[] ev0 = factory
2351 .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2353 ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2354 if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2357 if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2360 final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2361 final Phylogeny[] ev1 = factory
2362 .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)));",
2364 ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2365 if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2368 if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2371 final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2372 final Phylogeny[] ev_b = factory
2373 .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",
2375 ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2376 if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2379 if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2383 final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2384 final Phylogeny[] ev1x = factory
2385 .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)));",
2387 ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2388 if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2391 if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2394 final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2395 final Phylogeny[] ev_bx = factory
2396 .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",
2398 ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2399 if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2402 if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2406 final Phylogeny[] t2 = factory
2407 .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);",
2409 final Phylogeny[] ev2 = factory
2410 .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);",
2412 for( final Phylogeny target : t2 ) {
2413 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2416 final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2417 new NHXParser() )[ 0 ];
2418 final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2419 ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2420 if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2423 if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2426 if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2430 catch ( final Exception e ) {
2431 e.printStackTrace();
2437 private static boolean testCopyOfNodeData() {
2439 final PhylogenyNode n1 = PhylogenyNode
2440 .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]" );
2441 final PhylogenyNode n2 = n1.copyNodeData();
2442 if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2446 catch ( final Exception e ) {
2447 e.printStackTrace();
2453 private static boolean testDataObjects() {
2455 final Confidence s0 = new Confidence();
2456 final Confidence s1 = new Confidence();
2457 if ( !s0.isEqual( s1 ) ) {
2460 final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2461 final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2462 if ( s2.isEqual( s1 ) ) {
2465 if ( !s2.isEqual( s3 ) ) {
2468 final Confidence s4 = ( Confidence ) s3.copy();
2469 if ( !s4.isEqual( s3 ) ) {
2476 final Taxonomy t1 = new Taxonomy();
2477 final Taxonomy t2 = new Taxonomy();
2478 final Taxonomy t3 = new Taxonomy();
2479 final Taxonomy t4 = new Taxonomy();
2480 final Taxonomy t5 = new Taxonomy();
2481 t1.setIdentifier( new Identifier( "ecoli" ) );
2482 t1.setTaxonomyCode( "ECOLI" );
2483 t1.setScientificName( "E. coli" );
2484 t1.setCommonName( "coli" );
2485 final Taxonomy t0 = ( Taxonomy ) t1.copy();
2486 if ( !t1.isEqual( t0 ) ) {
2489 t2.setIdentifier( new Identifier( "ecoli" ) );
2490 t2.setTaxonomyCode( "OTHER" );
2491 t2.setScientificName( "what" );
2492 t2.setCommonName( "something" );
2493 if ( !t1.isEqual( t2 ) ) {
2496 t2.setIdentifier( new Identifier( "nemve" ) );
2497 if ( t1.isEqual( t2 ) ) {
2500 t1.setIdentifier( null );
2501 t3.setTaxonomyCode( "ECOLI" );
2502 t3.setScientificName( "what" );
2503 t3.setCommonName( "something" );
2504 if ( !t1.isEqual( t3 ) ) {
2507 t1.setIdentifier( null );
2508 t1.setTaxonomyCode( "" );
2509 t4.setScientificName( "E. ColI" );
2510 t4.setCommonName( "something" );
2511 if ( !t1.isEqual( t4 ) ) {
2514 t4.setScientificName( "B. subtilis" );
2515 t4.setCommonName( "something" );
2516 if ( t1.isEqual( t4 ) ) {
2519 t1.setIdentifier( null );
2520 t1.setTaxonomyCode( "" );
2521 t1.setScientificName( "" );
2522 t5.setCommonName( "COLI" );
2523 if ( !t1.isEqual( t5 ) ) {
2526 t5.setCommonName( "vibrio" );
2527 if ( t1.isEqual( t5 ) ) {
2532 final Identifier id0 = new Identifier( "123", "pfam" );
2533 final Identifier id1 = ( Identifier ) id0.copy();
2534 if ( !id1.isEqual( id1 ) ) {
2537 if ( !id1.isEqual( id0 ) ) {
2540 if ( !id0.isEqual( id1 ) ) {
2547 final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
2548 final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
2549 if ( !pd1.isEqual( pd1 ) ) {
2552 if ( !pd1.isEqual( pd0 ) ) {
2557 final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
2558 final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
2559 if ( !pd3.isEqual( pd3 ) ) {
2562 if ( !pd2.isEqual( pd3 ) ) {
2565 if ( !pd0.isEqual( pd3 ) ) {
2570 // DomainArchitecture
2571 // ------------------
2572 final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
2573 final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
2574 final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
2575 final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
2576 final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
2577 final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
2582 final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
2583 if ( ds0.getNumberOfDomains() != 4 ) {
2586 final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
2587 if ( !ds0.isEqual( ds0 ) ) {
2590 if ( !ds0.isEqual( ds1 ) ) {
2593 if ( ds1.getNumberOfDomains() != 4 ) {
2596 final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
2601 final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
2602 if ( ds0.isEqual( ds2 ) ) {
2608 final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
2609 if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
2610 System.out.println( ds3.toNHX() );
2613 if ( ds3.getNumberOfDomains() != 3 ) {
2618 final Event e1 = new Event( Event.EventType.fusion );
2619 if ( e1.isDuplication() ) {
2622 if ( !e1.isFusion() ) {
2625 if ( !e1.asText().toString().equals( "fusion" ) ) {
2628 if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
2631 final Event e11 = new Event( Event.EventType.fusion );
2632 if ( !e11.isEqual( e1 ) ) {
2635 if ( !e11.toNHX().toString().equals( "" ) ) {
2638 final Event e2 = new Event( Event.EventType.speciation_or_duplication );
2639 if ( e2.isDuplication() ) {
2642 if ( !e2.isSpeciationOrDuplication() ) {
2645 if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
2648 if ( !e2.asSimpleText().toString().equals( "?" ) ) {
2651 if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
2654 if ( e11.isEqual( e2 ) ) {
2657 final Event e2c = ( Event ) e2.copy();
2658 if ( !e2c.isEqual( e2 ) ) {
2661 Event e3 = new Event( 1, 2, 3 );
2662 if ( e3.isDuplication() ) {
2665 if ( e3.isSpeciation() ) {
2668 if ( e3.isGeneLoss() ) {
2671 if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2674 final Event e3c = ( Event ) e3.copy();
2675 final Event e3cc = ( Event ) e3c.copy();
2676 if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
2680 if ( !e3c.isEqual( e3cc ) ) {
2683 Event e4 = new Event( 1, 2, 3 );
2684 if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2687 if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
2690 final Event e4c = ( Event ) e4.copy();
2692 final Event e4cc = ( Event ) e4c.copy();
2693 if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2696 if ( !e4c.isEqual( e4cc ) ) {
2699 final Event e5 = new Event();
2700 if ( !e5.isUnassigned() ) {
2703 if ( !e5.asText().toString().equals( "unassigned" ) ) {
2706 if ( !e5.asSimpleText().toString().equals( "" ) ) {
2709 final Event e6 = new Event( 1, 0, 0 );
2710 if ( !e6.asText().toString().equals( "duplication" ) ) {
2713 if ( !e6.asSimpleText().toString().equals( "D" ) ) {
2716 final Event e7 = new Event( 0, 1, 0 );
2717 if ( !e7.asText().toString().equals( "speciation" ) ) {
2720 if ( !e7.asSimpleText().toString().equals( "S" ) ) {
2723 final Event e8 = new Event( 0, 0, 1 );
2724 if ( !e8.asText().toString().equals( "gene-loss" ) ) {
2727 if ( !e8.asSimpleText().toString().equals( "L" ) ) {
2731 catch ( final Exception e ) {
2732 e.printStackTrace( System.out );
2738 private static boolean testDeletionOfExternalNodes() {
2740 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2741 final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
2742 final PhylogenyWriter w = new PhylogenyWriter();
2743 if ( t0.isEmpty() ) {
2746 if ( t0.getNumberOfExternalNodes() != 1 ) {
2749 t0.deleteSubtree( t0.getNode( "A" ), false );
2750 if ( t0.getNumberOfExternalNodes() != 0 ) {
2753 if ( !t0.isEmpty() ) {
2756 final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
2757 if ( t1.getNumberOfExternalNodes() != 2 ) {
2760 t1.deleteSubtree( t1.getNode( "A" ), false );
2761 if ( t1.getNumberOfExternalNodes() != 1 ) {
2764 if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
2767 t1.deleteSubtree( t1.getNode( "B" ), false );
2768 if ( t1.getNumberOfExternalNodes() != 1 ) {
2771 t1.deleteSubtree( t1.getNode( "r" ), false );
2772 if ( !t1.isEmpty() ) {
2775 final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
2776 if ( t2.getNumberOfExternalNodes() != 3 ) {
2779 t2.deleteSubtree( t2.getNode( "B" ), false );
2780 if ( t2.getNumberOfExternalNodes() != 2 ) {
2783 t2.toNewHampshireX();
2784 PhylogenyNode n = t2.getNode( "A" );
2785 if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2788 t2.deleteSubtree( t2.getNode( "A" ), false );
2789 if ( t2.getNumberOfExternalNodes() != 2 ) {
2792 t2.deleteSubtree( t2.getNode( "C" ), true );
2793 if ( t2.getNumberOfExternalNodes() != 1 ) {
2796 final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2797 if ( t3.getNumberOfExternalNodes() != 4 ) {
2800 t3.deleteSubtree( t3.getNode( "B" ), true );
2801 if ( t3.getNumberOfExternalNodes() != 3 ) {
2804 n = t3.getNode( "A" );
2805 if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2808 n = n.getNextExternalNode();
2809 if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2812 t3.deleteSubtree( t3.getNode( "A" ), true );
2813 if ( t3.getNumberOfExternalNodes() != 2 ) {
2816 n = t3.getNode( "C" );
2817 if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2820 t3.deleteSubtree( t3.getNode( "C" ), true );
2821 if ( t3.getNumberOfExternalNodes() != 1 ) {
2824 t3.deleteSubtree( t3.getNode( "D" ), true );
2825 if ( t3.getNumberOfExternalNodes() != 0 ) {
2828 final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2829 if ( t4.getNumberOfExternalNodes() != 6 ) {
2832 t4.deleteSubtree( t4.getNode( "B2" ), true );
2833 if ( t4.getNumberOfExternalNodes() != 5 ) {
2836 String s = w.toNewHampshire( t4, false, true ).toString();
2837 if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2840 t4.deleteSubtree( t4.getNode( "B11" ), true );
2841 if ( t4.getNumberOfExternalNodes() != 4 ) {
2844 t4.deleteSubtree( t4.getNode( "C" ), true );
2845 if ( t4.getNumberOfExternalNodes() != 3 ) {
2848 n = t4.getNode( "A" );
2849 n = n.getNextExternalNode();
2850 if ( !n.getName().equals( "B12" ) ) {
2853 n = n.getNextExternalNode();
2854 if ( !n.getName().equals( "D" ) ) {
2857 s = w.toNewHampshire( t4, false, true ).toString();
2858 if ( !s.equals( "((A,B12),D);" ) ) {
2861 final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2862 t5.deleteSubtree( t5.getNode( "A" ), true );
2863 if ( t5.getNumberOfExternalNodes() != 5 ) {
2866 s = w.toNewHampshire( t5, false, true ).toString();
2867 if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
2870 final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2871 t6.deleteSubtree( t6.getNode( "B11" ), true );
2872 if ( t6.getNumberOfExternalNodes() != 5 ) {
2875 s = w.toNewHampshire( t6, false, false ).toString();
2876 if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
2879 final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2880 t7.deleteSubtree( t7.getNode( "B12" ), true );
2881 if ( t7.getNumberOfExternalNodes() != 5 ) {
2884 s = w.toNewHampshire( t7, false, true ).toString();
2885 if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
2888 final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2889 t8.deleteSubtree( t8.getNode( "B2" ), true );
2890 if ( t8.getNumberOfExternalNodes() != 5 ) {
2893 s = w.toNewHampshire( t8, false, false ).toString();
2894 if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2897 final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2898 t9.deleteSubtree( t9.getNode( "C" ), true );
2899 if ( t9.getNumberOfExternalNodes() != 5 ) {
2902 s = w.toNewHampshire( t9, false, true ).toString();
2903 if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
2906 final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2907 t10.deleteSubtree( t10.getNode( "D" ), true );
2908 if ( t10.getNumberOfExternalNodes() != 5 ) {
2911 s = w.toNewHampshire( t10, false, true ).toString();
2912 if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
2915 final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
2916 t11.deleteSubtree( t11.getNode( "A" ), true );
2917 if ( t11.getNumberOfExternalNodes() != 2 ) {
2920 s = w.toNewHampshire( t11, false, true ).toString();
2921 if ( !s.equals( "(B,C);" ) ) {
2924 t11.deleteSubtree( t11.getNode( "C" ), true );
2925 if ( t11.getNumberOfExternalNodes() != 1 ) {
2928 s = w.toNewHampshire( t11, false, false ).toString();
2929 if ( !s.equals( "B;" ) ) {
2932 final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
2933 t12.deleteSubtree( t12.getNode( "B2" ), true );
2934 if ( t12.getNumberOfExternalNodes() != 8 ) {
2937 s = w.toNewHampshire( t12, false, true ).toString();
2938 if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
2941 t12.deleteSubtree( t12.getNode( "B3" ), true );
2942 if ( t12.getNumberOfExternalNodes() != 7 ) {
2945 s = w.toNewHampshire( t12, false, true ).toString();
2946 if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
2949 t12.deleteSubtree( t12.getNode( "C3" ), true );
2950 if ( t12.getNumberOfExternalNodes() != 6 ) {
2953 s = w.toNewHampshire( t12, false, true ).toString();
2954 if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
2957 t12.deleteSubtree( t12.getNode( "A1" ), true );
2958 if ( t12.getNumberOfExternalNodes() != 5 ) {
2961 s = w.toNewHampshire( t12, false, true ).toString();
2962 if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
2965 t12.deleteSubtree( t12.getNode( "B1" ), true );
2966 if ( t12.getNumberOfExternalNodes() != 4 ) {
2969 s = w.toNewHampshire( t12, false, true ).toString();
2970 if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
2973 t12.deleteSubtree( t12.getNode( "A3" ), true );
2974 if ( t12.getNumberOfExternalNodes() != 3 ) {
2977 s = w.toNewHampshire( t12, false, true ).toString();
2978 if ( !s.equals( "(A2,(C1,C2));" ) ) {
2981 t12.deleteSubtree( t12.getNode( "A2" ), true );
2982 if ( t12.getNumberOfExternalNodes() != 2 ) {
2985 s = w.toNewHampshire( t12, false, true ).toString();
2986 if ( !s.equals( "(C1,C2);" ) ) {
2989 final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
2990 t13.deleteSubtree( t13.getNode( "D" ), true );
2991 if ( t13.getNumberOfExternalNodes() != 4 ) {
2994 s = w.toNewHampshire( t13, false, true ).toString();
2995 if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
2998 final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
2999 t14.deleteSubtree( t14.getNode( "E" ), true );
3000 if ( t14.getNumberOfExternalNodes() != 5 ) {
3003 s = w.toNewHampshire( t14, false, true ).toString();
3004 if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3007 final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3008 t15.deleteSubtree( t15.getNode( "B2" ), true );
3009 if ( t15.getNumberOfExternalNodes() != 11 ) {
3012 t15.deleteSubtree( t15.getNode( "B1" ), true );
3013 if ( t15.getNumberOfExternalNodes() != 10 ) {
3016 t15.deleteSubtree( t15.getNode( "B3" ), true );
3017 if ( t15.getNumberOfExternalNodes() != 9 ) {
3020 t15.deleteSubtree( t15.getNode( "B4" ), true );
3021 if ( t15.getNumberOfExternalNodes() != 8 ) {
3024 t15.deleteSubtree( t15.getNode( "A1" ), true );
3025 if ( t15.getNumberOfExternalNodes() != 7 ) {
3028 t15.deleteSubtree( t15.getNode( "C4" ), true );
3029 if ( t15.getNumberOfExternalNodes() != 6 ) {
3033 catch ( final Exception e ) {
3034 e.printStackTrace( System.out );
3040 private static boolean testDescriptiveStatistics() {
3042 final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3043 dss1.addValue( 82 );
3044 dss1.addValue( 78 );
3045 dss1.addValue( 70 );
3046 dss1.addValue( 58 );
3047 dss1.addValue( 42 );
3048 if ( dss1.getN() != 5 ) {
3051 if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3054 if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3057 if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3060 if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3063 if ( !Test.isEqual( dss1.median(), 70 ) ) {
3066 if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3069 if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3072 if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3075 if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3078 if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3081 if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3084 dss1.addValue( 123 );
3085 if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3088 if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3091 if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3094 final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3095 dss2.addValue( -1.85 );
3096 dss2.addValue( 57.5 );
3097 dss2.addValue( 92.78 );
3098 dss2.addValue( 57.78 );
3099 if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3102 if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3105 final double[] a = dss2.getDataAsDoubleArray();
3106 if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3109 dss2.addValue( -100 );
3110 if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3113 if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3116 final double[] ds = new double[ 14 ];
3131 final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3132 if ( bins.length != 4 ) {
3135 if ( bins[ 0 ] != 2 ) {
3138 if ( bins[ 1 ] != 3 ) {
3141 if ( bins[ 2 ] != 4 ) {
3144 if ( bins[ 3 ] != 5 ) {
3147 final double[] ds1 = new double[ 9 ];
3157 final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3158 if ( bins1.length != 4 ) {
3161 if ( bins1[ 0 ] != 2 ) {
3164 if ( bins1[ 1 ] != 3 ) {
3167 if ( bins1[ 2 ] != 0 ) {
3170 if ( bins1[ 3 ] != 4 ) {
3173 final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3174 if ( bins1_1.length != 3 ) {
3177 if ( bins1_1[ 0 ] != 3 ) {
3180 if ( bins1_1[ 1 ] != 2 ) {
3183 if ( bins1_1[ 2 ] != 4 ) {
3186 final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3187 if ( bins1_2.length != 3 ) {
3190 if ( bins1_2[ 0 ] != 2 ) {
3193 if ( bins1_2[ 1 ] != 2 ) {
3196 if ( bins1_2[ 2 ] != 2 ) {
3199 final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3213 dss3.addValue( 10 );
3214 dss3.addValue( 10 );
3215 dss3.addValue( 10 );
3216 final AsciiHistogram histo = new AsciiHistogram( dss3 );
3217 histo.toStringBuffer( 10, '=', 40, 5 );
3218 histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3220 catch ( final Exception e ) {
3221 e.printStackTrace( System.out );
3227 private static boolean testDir( final String file ) {
3229 final File f = new File( file );
3230 if ( !f.exists() ) {
3233 if ( !f.isDirectory() ) {
3236 if ( !f.canRead() ) {
3240 catch ( final Exception e ) {
3246 private static boolean testExternalNodeRelatedMethods() {
3248 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3249 final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3250 PhylogenyNode n = t1.getNode( "A" );
3251 n = n.getNextExternalNode();
3252 if ( !n.getName().equals( "B" ) ) {
3255 n = n.getNextExternalNode();
3256 if ( !n.getName().equals( "C" ) ) {
3259 n = n.getNextExternalNode();
3260 if ( !n.getName().equals( "D" ) ) {
3263 n = t1.getNode( "B" );
3264 while ( !n.isLastExternalNode() ) {
3265 n = n.getNextExternalNode();
3267 final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
3268 n = t2.getNode( "A" );
3269 n = n.getNextExternalNode();
3270 if ( !n.getName().equals( "B" ) ) {
3273 n = n.getNextExternalNode();
3274 if ( !n.getName().equals( "C" ) ) {
3277 n = n.getNextExternalNode();
3278 if ( !n.getName().equals( "D" ) ) {
3281 n = t2.getNode( "B" );
3282 while ( !n.isLastExternalNode() ) {
3283 n = n.getNextExternalNode();
3285 final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3286 n = t3.getNode( "A" );
3287 n = n.getNextExternalNode();
3288 if ( !n.getName().equals( "B" ) ) {
3291 n = n.getNextExternalNode();
3292 if ( !n.getName().equals( "C" ) ) {
3295 n = n.getNextExternalNode();
3296 if ( !n.getName().equals( "D" ) ) {
3299 n = n.getNextExternalNode();
3300 if ( !n.getName().equals( "E" ) ) {
3303 n = n.getNextExternalNode();
3304 if ( !n.getName().equals( "F" ) ) {
3307 n = n.getNextExternalNode();
3308 if ( !n.getName().equals( "G" ) ) {
3311 n = n.getNextExternalNode();
3312 if ( !n.getName().equals( "H" ) ) {
3315 n = t3.getNode( "B" );
3316 while ( !n.isLastExternalNode() ) {
3317 n = n.getNextExternalNode();
3319 final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3320 for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
3321 final PhylogenyNode node = iter.next();
3323 final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3324 for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
3325 final PhylogenyNode node = iter.next();
3327 final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
3328 final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
3329 if ( !iter.next().getName().equals( "A" ) ) {
3332 if ( !iter.next().getName().equals( "B" ) ) {
3335 if ( !iter.next().getName().equals( "C" ) ) {
3338 if ( !iter.next().getName().equals( "D" ) ) {
3341 if ( !iter.next().getName().equals( "E" ) ) {
3344 if ( !iter.next().getName().equals( "F" ) ) {
3347 if ( iter.hasNext() ) {
3351 catch ( final Exception e ) {
3352 e.printStackTrace( System.out );
3358 private static boolean testGeneralTable() {
3360 final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
3361 t0.setValue( 3, 2, "23" );
3362 t0.setValue( 10, 1, "error" );
3363 t0.setValue( 10, 1, "110" );
3364 t0.setValue( 9, 1, "19" );
3365 t0.setValue( 1, 10, "101" );
3366 t0.setValue( 10, 10, "1010" );
3367 t0.setValue( 100, 10, "10100" );
3368 t0.setValue( 0, 0, "00" );
3369 if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
3372 if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
3375 if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
3378 if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
3381 if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
3384 if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
3387 if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
3390 if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
3393 if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
3396 final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
3397 t1.setValue( "3", "2", "23" );
3398 t1.setValue( "10", "1", "error" );
3399 t1.setValue( "10", "1", "110" );
3400 t1.setValue( "9", "1", "19" );
3401 t1.setValue( "1", "10", "101" );
3402 t1.setValue( "10", "10", "1010" );
3403 t1.setValue( "100", "10", "10100" );
3404 t1.setValue( "0", "0", "00" );
3405 t1.setValue( "qwerty", "zxcvbnm", "asdef" );
3406 if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
3409 if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
3412 if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
3415 if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
3418 if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
3421 if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
3424 if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
3427 if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
3430 if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
3433 if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
3437 catch ( final Exception e ) {
3438 e.printStackTrace( System.out );
3444 private static boolean testGetDistance() {
3446 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3447 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",
3448 new NHXParser() )[ 0 ];
3449 if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
3452 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
3455 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
3458 if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
3461 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
3464 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
3467 if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
3470 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
3473 if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
3476 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
3479 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
3482 if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
3485 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
3488 if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
3491 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
3494 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
3497 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
3500 if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
3503 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
3506 if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
3509 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
3512 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
3515 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
3518 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
3521 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
3524 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
3527 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
3530 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
3533 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
3536 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
3539 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
3542 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",
3543 new NHXParser() )[ 0 ];
3544 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
3547 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
3550 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
3553 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
3556 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
3559 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
3562 if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
3565 if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
3568 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
3571 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
3574 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
3578 catch ( final Exception e ) {
3579 e.printStackTrace( System.out );
3585 private static boolean testGetLCA() {
3587 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3588 final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3589 new NHXParser() )[ 0 ];
3590 final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
3591 if ( !A.getName().equals( "A" ) ) {
3594 final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
3595 if ( !gh.getName().equals( "gh" ) ) {
3598 final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
3599 if ( !ab.getName().equals( "ab" ) ) {
3602 final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
3603 if ( !ab2.getName().equals( "ab" ) ) {
3606 final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
3607 if ( !gh2.getName().equals( "gh" ) ) {
3610 final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
3611 if ( !gh3.getName().equals( "gh" ) ) {
3614 final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
3615 if ( !abc.getName().equals( "abc" ) ) {
3618 final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
3619 if ( !abc2.getName().equals( "abc" ) ) {
3622 final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
3623 if ( !abcd.getName().equals( "abcd" ) ) {
3626 final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
3627 if ( !abcd2.getName().equals( "abcd" ) ) {
3630 final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
3631 if ( !abcdef.getName().equals( "abcdef" ) ) {
3634 final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
3635 if ( !abcdef2.getName().equals( "abcdef" ) ) {
3638 final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
3639 if ( !abcdef3.getName().equals( "abcdef" ) ) {
3642 final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
3643 if ( !abcdef4.getName().equals( "abcdef" ) ) {
3646 final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
3647 if ( !abcde.getName().equals( "abcde" ) ) {
3650 final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
3651 if ( !abcde2.getName().equals( "abcde" ) ) {
3654 final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
3655 if ( !r.getName().equals( "abcdefgh" ) ) {
3658 final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
3659 if ( !r2.getName().equals( "abcdefgh" ) ) {
3662 final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
3663 if ( !r3.getName().equals( "abcdefgh" ) ) {
3666 final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
3667 if ( !abcde3.getName().equals( "abcde" ) ) {
3670 final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
3671 if ( !abcde4.getName().equals( "abcde" ) ) {
3674 final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
3675 if ( !ab3.getName().equals( "ab" ) ) {
3678 final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
3679 if ( !ab4.getName().equals( "ab" ) ) {
3682 final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3683 final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
3684 if ( !cd.getName().equals( "cd" ) ) {
3687 final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
3688 if ( !cd2.getName().equals( "cd" ) ) {
3691 final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
3692 if ( !cde.getName().equals( "cde" ) ) {
3695 final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
3696 if ( !cde2.getName().equals( "cde" ) ) {
3699 final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
3700 if ( !cdef.getName().equals( "cdef" ) ) {
3703 final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
3704 if ( !cdef2.getName().equals( "cdef" ) ) {
3707 final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
3708 if ( !cdef3.getName().equals( "cdef" ) ) {
3711 final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
3712 if ( !rt.getName().equals( "r" ) ) {
3715 final Phylogeny p3 = factory
3716 .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
3717 new NHXParser() )[ 0 ];
3718 final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
3719 if ( !bc_3.getName().equals( "bc" ) ) {
3722 final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
3723 if ( !ac_3.getName().equals( "abc" ) ) {
3726 final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
3727 if ( !ad_3.getName().equals( "abcde" ) ) {
3730 final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
3731 if ( !af_3.getName().equals( "abcdef" ) ) {
3734 final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
3735 if ( !ag_3.getName().equals( "" ) ) {
3738 if ( !ag_3.isRoot() ) {
3741 final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
3742 if ( !al_3.getName().equals( "" ) ) {
3745 if ( !al_3.isRoot() ) {
3748 final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
3749 if ( !kl_3.getName().equals( "" ) ) {
3752 if ( !kl_3.isRoot() ) {
3755 final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
3756 if ( !fl_3.getName().equals( "" ) ) {
3759 if ( !fl_3.isRoot() ) {
3762 final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
3763 if ( !gk_3.getName().equals( "ghijk" ) ) {
3766 final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
3767 final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
3768 if ( !r_4.getName().equals( "r" ) ) {
3771 final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
3772 final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
3773 if ( !r_5.getName().equals( "root" ) ) {
3776 final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
3777 final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
3778 if ( !r_6.getName().equals( "rot" ) ) {
3781 final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
3782 final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
3783 if ( !r_7.getName().equals( "rott" ) ) {
3787 catch ( final Exception e ) {
3788 e.printStackTrace( System.out );
3794 private static boolean testGetLCA2() {
3796 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3797 final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
3798 PhylogenyMethods.preOrderReId( p_a );
3799 final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
3800 p_a.getNode( "a" ) );
3801 if ( !p_a_1.getName().equals( "a" ) ) {
3804 final Phylogeny p_b = factory.create( "((a)b)", new NHXParser() )[ 0 ];
3805 PhylogenyMethods.preOrderReId( p_b );
3806 final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
3807 p_b.getNode( "a" ) );
3808 if ( !p_b_1.getName().equals( "b" ) ) {
3811 final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
3812 p_b.getNode( "b" ) );
3813 if ( !p_b_2.getName().equals( "b" ) ) {
3816 final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
3817 PhylogenyMethods.preOrderReId( p_c );
3818 final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
3819 p_c.getNode( "a" ) );
3820 if ( !p_c_1.getName().equals( "b" ) ) {
3823 final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3824 p_c.getNode( "c" ) );
3825 if ( !p_c_2.getName().equals( "c" ) ) {
3826 System.out.println( p_c_2.getName() );
3830 final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
3831 p_c.getNode( "b" ) );
3832 if ( !p_c_3.getName().equals( "b" ) ) {
3835 final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
3836 p_c.getNode( "a" ) );
3837 if ( !p_c_4.getName().equals( "c" ) ) {
3840 final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3841 new NHXParser() )[ 0 ];
3842 PhylogenyMethods.preOrderReId( p1 );
3843 final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3844 p1.getNode( "A" ) );
3845 if ( !A.getName().equals( "A" ) ) {
3848 final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
3849 p1.getNode( "gh" ) );
3850 if ( !gh.getName().equals( "gh" ) ) {
3853 final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3854 p1.getNode( "B" ) );
3855 if ( !ab.getName().equals( "ab" ) ) {
3858 final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3859 p1.getNode( "A" ) );
3860 if ( !ab2.getName().equals( "ab" ) ) {
3863 final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3864 p1.getNode( "G" ) );
3865 if ( !gh2.getName().equals( "gh" ) ) {
3868 final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
3869 p1.getNode( "H" ) );
3870 if ( !gh3.getName().equals( "gh" ) ) {
3873 final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
3874 p1.getNode( "A" ) );
3875 if ( !abc.getName().equals( "abc" ) ) {
3878 final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3879 p1.getNode( "C" ) );
3880 if ( !abc2.getName().equals( "abc" ) ) {
3883 final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3884 p1.getNode( "D" ) );
3885 if ( !abcd.getName().equals( "abcd" ) ) {
3888 final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
3889 p1.getNode( "A" ) );
3890 if ( !abcd2.getName().equals( "abcd" ) ) {
3893 final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3894 p1.getNode( "F" ) );
3895 if ( !abcdef.getName().equals( "abcdef" ) ) {
3898 final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3899 p1.getNode( "A" ) );
3900 if ( !abcdef2.getName().equals( "abcdef" ) ) {
3903 final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3904 p1.getNode( "F" ) );
3905 if ( !abcdef3.getName().equals( "abcdef" ) ) {
3908 final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3909 p1.getNode( "ab" ) );
3910 if ( !abcdef4.getName().equals( "abcdef" ) ) {
3913 final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3914 p1.getNode( "E" ) );
3915 if ( !abcde.getName().equals( "abcde" ) ) {
3918 final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3919 p1.getNode( "A" ) );
3920 if ( !abcde2.getName().equals( "abcde" ) ) {
3923 final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
3924 p1.getNode( "abcdefgh" ) );
3925 if ( !r.getName().equals( "abcdefgh" ) ) {
3928 final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3929 p1.getNode( "H" ) );
3930 if ( !r2.getName().equals( "abcdefgh" ) ) {
3933 final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3934 p1.getNode( "A" ) );
3935 if ( !r3.getName().equals( "abcdefgh" ) ) {
3938 final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3939 p1.getNode( "abcde" ) );
3940 if ( !abcde3.getName().equals( "abcde" ) ) {
3943 final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
3944 p1.getNode( "E" ) );
3945 if ( !abcde4.getName().equals( "abcde" ) ) {
3948 final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3949 p1.getNode( "B" ) );
3950 if ( !ab3.getName().equals( "ab" ) ) {
3953 final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3954 p1.getNode( "ab" ) );
3955 if ( !ab4.getName().equals( "ab" ) ) {
3958 final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3959 PhylogenyMethods.preOrderReId( p2 );
3960 final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3961 p2.getNode( "d" ) );
3962 if ( !cd.getName().equals( "cd" ) ) {
3965 final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3966 p2.getNode( "c" ) );
3967 if ( !cd2.getName().equals( "cd" ) ) {
3970 final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3971 p2.getNode( "e" ) );
3972 if ( !cde.getName().equals( "cde" ) ) {
3975 final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
3976 p2.getNode( "c" ) );
3977 if ( !cde2.getName().equals( "cde" ) ) {
3980 final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3981 p2.getNode( "f" ) );
3982 if ( !cdef.getName().equals( "cdef" ) ) {
3985 final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3986 p2.getNode( "f" ) );
3987 if ( !cdef2.getName().equals( "cdef" ) ) {
3990 final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
3991 p2.getNode( "d" ) );
3992 if ( !cdef3.getName().equals( "cdef" ) ) {
3995 final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3996 p2.getNode( "a" ) );
3997 if ( !rt.getName().equals( "r" ) ) {
4000 final Phylogeny p3 = factory
4001 .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
4002 new NHXParser() )[ 0 ];
4003 PhylogenyMethods.preOrderReId( p3 );
4004 final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
4005 p3.getNode( "c" ) );
4006 if ( !bc_3.getName().equals( "bc" ) ) {
4009 final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4010 p3.getNode( "c" ) );
4011 if ( !ac_3.getName().equals( "abc" ) ) {
4014 final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4015 p3.getNode( "d" ) );
4016 if ( !ad_3.getName().equals( "abcde" ) ) {
4019 final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4020 p3.getNode( "f" ) );
4021 if ( !af_3.getName().equals( "abcdef" ) ) {
4024 final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4025 p3.getNode( "g" ) );
4026 if ( !ag_3.getName().equals( "" ) ) {
4029 if ( !ag_3.isRoot() ) {
4032 final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4033 p3.getNode( "l" ) );
4034 if ( !al_3.getName().equals( "" ) ) {
4037 if ( !al_3.isRoot() ) {
4040 final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
4041 p3.getNode( "l" ) );
4042 if ( !kl_3.getName().equals( "" ) ) {
4045 if ( !kl_3.isRoot() ) {
4048 final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
4049 p3.getNode( "l" ) );
4050 if ( !fl_3.getName().equals( "" ) ) {
4053 if ( !fl_3.isRoot() ) {
4056 final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
4057 p3.getNode( "k" ) );
4058 if ( !gk_3.getName().equals( "ghijk" ) ) {
4061 final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
4062 PhylogenyMethods.preOrderReId( p4 );
4063 final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
4064 p4.getNode( "c" ) );
4065 if ( !r_4.getName().equals( "r" ) ) {
4068 final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
4069 PhylogenyMethods.preOrderReId( p5 );
4070 final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
4071 p5.getNode( "c" ) );
4072 if ( !r_5.getName().equals( "root" ) ) {
4075 final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
4076 PhylogenyMethods.preOrderReId( p6 );
4077 final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
4078 p6.getNode( "a" ) );
4079 if ( !r_6.getName().equals( "rot" ) ) {
4082 final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
4083 PhylogenyMethods.preOrderReId( p7 );
4084 final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
4085 p7.getNode( "e" ) );
4086 if ( !r_7.getName().equals( "rott" ) ) {
4089 final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4090 p7.getNode( "a" ) );
4091 if ( !r_71.getName().equals( "rott" ) ) {
4094 final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4095 p7.getNode( "rott" ) );
4096 if ( !r_72.getName().equals( "rott" ) ) {
4099 final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
4100 p7.getNode( "a" ) );
4101 if ( !r_73.getName().equals( "rott" ) ) {
4104 final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
4105 p7.getNode( "rott" ) );
4106 if ( !r_74.getName().equals( "rott" ) ) {
4109 final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4110 p7.getNode( "e" ) );
4111 if ( !r_75.getName().equals( "e" ) ) {
4115 catch ( final Exception e ) {
4116 e.printStackTrace( System.out );
4122 private static boolean testHmmscanOutputParser() {
4123 final String test_dir = Test.PATH_TO_TEST_DATA;
4125 final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
4126 + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4128 final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
4129 + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4130 final List<Protein> proteins = parser2.parse();
4131 if ( parser2.getProteinsEncountered() != 4 ) {
4134 if ( proteins.size() != 4 ) {
4137 if ( parser2.getDomainsEncountered() != 69 ) {
4140 if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
4143 if ( parser2.getDomainsIgnoredDueToEval() != 0 ) {
4146 final Protein p1 = proteins.get( 0 );
4147 if ( p1.getNumberOfProteinDomains() != 15 ) {
4150 if ( p1.getLength() != 850 ) {
4153 final Protein p2 = proteins.get( 1 );
4154 if ( p2.getNumberOfProteinDomains() != 51 ) {
4157 if ( p2.getLength() != 1291 ) {
4160 final Protein p3 = proteins.get( 2 );
4161 if ( p3.getNumberOfProteinDomains() != 2 ) {
4164 final Protein p4 = proteins.get( 3 );
4165 if ( p4.getNumberOfProteinDomains() != 1 ) {
4168 if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
4171 if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
4174 if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
4177 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
4180 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
4183 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) {
4186 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) {
4189 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
4192 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
4196 catch ( final Exception e ) {
4197 e.printStackTrace( System.out );
4203 private static boolean testLastExternalNodeMethods() {
4205 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4206 final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
4207 final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
4208 final PhylogenyNode n1 = t0.getNode( "A" );
4209 if ( n1.isLastExternalNode() ) {
4212 final PhylogenyNode n2 = t0.getNode( "B" );
4213 if ( n2.isLastExternalNode() ) {
4216 final PhylogenyNode n3 = t0.getNode( "C" );
4217 if ( n3.isLastExternalNode() ) {
4220 final PhylogenyNode n4 = t0.getNode( "D" );
4221 if ( !n4.isLastExternalNode() ) {
4225 catch ( final Exception e ) {
4226 e.printStackTrace( System.out );
4232 private static boolean testLevelOrderIterator() {
4234 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4235 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
4236 PhylogenyNodeIterator it0;
4237 for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
4240 for( it0.reset(); it0.hasNext(); ) {
4243 final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
4244 if ( !it.next().getName().equals( "r" ) ) {
4247 if ( !it.next().getName().equals( "ab" ) ) {
4250 if ( !it.next().getName().equals( "cd" ) ) {
4253 if ( !it.next().getName().equals( "A" ) ) {
4256 if ( !it.next().getName().equals( "B" ) ) {
4259 if ( !it.next().getName().equals( "C" ) ) {
4262 if ( !it.next().getName().equals( "D" ) ) {
4265 if ( it.hasNext() ) {
4268 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",
4269 new NHXParser() )[ 0 ];
4270 PhylogenyNodeIterator it2;
4271 for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
4274 for( it2.reset(); it2.hasNext(); ) {
4277 final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
4278 if ( !it3.next().getName().equals( "r" ) ) {
4281 if ( !it3.next().getName().equals( "abc" ) ) {
4284 if ( !it3.next().getName().equals( "defg" ) ) {
4287 if ( !it3.next().getName().equals( "A" ) ) {
4290 if ( !it3.next().getName().equals( "B" ) ) {
4293 if ( !it3.next().getName().equals( "C" ) ) {
4296 if ( !it3.next().getName().equals( "D" ) ) {
4299 if ( !it3.next().getName().equals( "E" ) ) {
4302 if ( !it3.next().getName().equals( "F" ) ) {
4305 if ( !it3.next().getName().equals( "G" ) ) {
4308 if ( !it3.next().getName().equals( "1" ) ) {
4311 if ( !it3.next().getName().equals( "2" ) ) {
4314 if ( !it3.next().getName().equals( "3" ) ) {
4317 if ( !it3.next().getName().equals( "4" ) ) {
4320 if ( !it3.next().getName().equals( "5" ) ) {
4323 if ( !it3.next().getName().equals( "6" ) ) {
4326 if ( !it3.next().getName().equals( "f1" ) ) {
4329 if ( !it3.next().getName().equals( "f2" ) ) {
4332 if ( !it3.next().getName().equals( "f3" ) ) {
4335 if ( !it3.next().getName().equals( "a" ) ) {
4338 if ( !it3.next().getName().equals( "b" ) ) {
4341 if ( !it3.next().getName().equals( "f21" ) ) {
4344 if ( !it3.next().getName().equals( "X" ) ) {
4347 if ( !it3.next().getName().equals( "Y" ) ) {
4350 if ( !it3.next().getName().equals( "Z" ) ) {
4353 if ( it3.hasNext() ) {
4356 final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
4357 PhylogenyNodeIterator it4;
4358 for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
4361 for( it4.reset(); it4.hasNext(); ) {
4364 final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
4365 if ( !it5.next().getName().equals( "r" ) ) {
4368 if ( !it5.next().getName().equals( "A" ) ) {
4371 if ( !it5.next().getName().equals( "B" ) ) {
4374 if ( !it5.next().getName().equals( "C" ) ) {
4377 if ( !it5.next().getName().equals( "D" ) ) {
4380 final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
4381 PhylogenyNodeIterator it6;
4382 for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
4385 for( it6.reset(); it6.hasNext(); ) {
4388 final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
4389 if ( !it7.next().getName().equals( "A" ) ) {
4392 if ( it.hasNext() ) {
4396 catch ( final Exception e ) {
4397 e.printStackTrace( System.out );
4403 private static boolean testNodeRemoval() {
4405 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4406 final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
4407 PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
4408 if ( !t0.toNewHampshire().equals( "(a);" ) ) {
4411 final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
4412 PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
4413 if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
4416 final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
4417 PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
4418 if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
4422 catch ( final Exception e ) {
4423 e.printStackTrace( System.out );
4429 private static boolean testMidpointrooting() {
4431 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4432 final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
4433 PhylogenyMethods.midpointRoot( t0 );
4434 if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
4437 if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
4440 if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
4444 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",
4445 new NHXParser() )[ 0 ];
4446 if ( !t1.isRooted() ) {
4449 PhylogenyMethods.midpointRoot( t1 );
4450 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4453 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4456 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4459 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4462 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4465 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4468 t1.reRoot( t1.getNode( "A" ) );
4469 PhylogenyMethods.midpointRoot( t1 );
4470 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4473 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4476 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4479 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4482 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4486 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4490 catch ( final Exception e ) {
4491 e.printStackTrace( System.out );
4497 private static boolean testNexusCharactersParsing() {
4499 final NexusCharactersParser parser = new NexusCharactersParser();
4500 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
4502 String[] labels = parser.getCharStateLabels();
4503 if ( labels.length != 7 ) {
4506 if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4509 if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4512 if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4515 if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4518 if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4521 if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4524 if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4527 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4529 labels = parser.getCharStateLabels();
4530 if ( labels.length != 7 ) {
4533 if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4536 if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4539 if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4542 if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4545 if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4548 if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4551 if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4555 catch ( final Exception e ) {
4556 e.printStackTrace( System.out );
4562 private static boolean testNexusMatrixParsing() {
4564 final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
4565 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
4567 final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
4568 if ( m.getNumberOfCharacters() != 9 ) {
4571 if ( m.getNumberOfIdentifiers() != 5 ) {
4574 if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
4577 if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
4580 if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
4583 if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
4586 if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
4589 if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
4592 if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
4595 // if ( labels.length != 7 ) {
4598 // if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4601 // if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4604 // if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4607 // if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4610 // if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4613 // if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4616 // if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4619 // parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4621 // labels = parser.getCharStateLabels();
4622 // if ( labels.length != 7 ) {
4625 // if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4628 // if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4631 // if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4634 // if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4637 // if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4640 // if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4643 // if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4647 catch ( final Exception e ) {
4648 e.printStackTrace( System.out );
4654 private static boolean testNexusTreeParsing() {
4656 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4657 final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
4658 Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
4659 if ( phylogenies.length != 1 ) {
4662 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
4665 if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4669 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
4670 if ( phylogenies.length != 1 ) {
4673 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4676 if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
4680 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
4681 if ( phylogenies.length != 1 ) {
4684 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4687 if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4690 if ( phylogenies[ 0 ].isRooted() ) {
4694 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
4695 if ( phylogenies.length != 18 ) {
4698 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4701 if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
4704 if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
4707 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
4710 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
4713 if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
4716 if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
4719 if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
4722 if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
4725 if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
4728 if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
4731 if ( phylogenies[ 8 ].isRooted() ) {
4734 if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
4737 if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
4740 if ( !phylogenies[ 9 ].isRooted() ) {
4743 if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
4746 if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
4749 if ( !phylogenies[ 10 ].isRooted() ) {
4752 if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
4755 if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
4758 if ( phylogenies[ 11 ].isRooted() ) {
4761 if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
4764 if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
4767 if ( !phylogenies[ 12 ].isRooted() ) {
4770 if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
4773 if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
4776 if ( !phylogenies[ 13 ].isRooted() ) {
4779 if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
4782 if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
4785 if ( !phylogenies[ 14 ].isRooted() ) {
4788 if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
4791 if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
4794 if ( phylogenies[ 15 ].isRooted() ) {
4797 if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
4800 if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
4803 if ( !phylogenies[ 16 ].isRooted() ) {
4806 if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
4809 if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
4812 if ( phylogenies[ 17 ].isRooted() ) {
4815 if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
4819 catch ( final Exception e ) {
4820 e.printStackTrace( System.out );
4826 private static boolean testNexusTreeParsingIterating() {
4828 final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
4829 p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
4830 if ( !p.hasNext() ) {
4833 Phylogeny phy = p.next();
4834 if ( phy == null ) {
4837 if ( phy.getNumberOfExternalNodes() != 25 ) {
4840 if ( !phy.getName().equals( "" ) ) {
4843 if ( p.hasNext() ) {
4847 if ( phy != null ) {
4852 if ( !p.hasNext() ) {
4856 if ( phy == null ) {
4859 if ( phy.getNumberOfExternalNodes() != 25 ) {
4862 if ( !phy.getName().equals( "" ) ) {
4865 if ( p.hasNext() ) {
4869 if ( phy != null ) {
4873 p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
4874 if ( !p.hasNext() ) {
4878 if ( phy == null ) {
4881 if ( phy.getNumberOfExternalNodes() != 10 ) {
4884 if ( !phy.getName().equals( "name" ) ) {
4887 if ( p.hasNext() ) {
4891 if ( phy != null ) {
4896 if ( !p.hasNext() ) {
4900 if ( phy == null ) {
4903 if ( phy.getNumberOfExternalNodes() != 10 ) {
4906 if ( !phy.getName().equals( "name" ) ) {
4909 if ( p.hasNext() ) {
4913 if ( phy != null ) {
4917 p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
4918 if ( !p.hasNext() ) {
4922 if ( phy == null ) {
4925 if ( phy.getNumberOfExternalNodes() != 3 ) {
4928 if ( !phy.getName().equals( "" ) ) {
4931 if ( phy.isRooted() ) {
4934 if ( p.hasNext() ) {
4938 if ( phy != null ) {
4943 if ( !p.hasNext() ) {
4947 if ( phy == null ) {
4950 if ( phy.getNumberOfExternalNodes() != 3 ) {
4953 if ( !phy.getName().equals( "" ) ) {
4956 if ( p.hasNext() ) {
4960 if ( phy != null ) {
4964 p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
4965 // if ( phylogenies.length != 18 ) {
4969 if ( !p.hasNext() ) {
4973 if ( phy == null ) {
4976 if ( phy.getNumberOfExternalNodes() != 10 ) {
4979 if ( !phy.getName().equals( "tree 0" ) ) {
4983 if ( !p.hasNext() ) {
4987 if ( phy == null ) {
4990 if ( phy.getNumberOfExternalNodes() != 10 ) {
4993 if ( !phy.getName().equals( "tree 1" ) ) {
4997 if ( !p.hasNext() ) {
5001 if ( phy == null ) {
5004 if ( phy.getNumberOfExternalNodes() != 3 ) {
5007 if ( !phy.getName().equals( "" ) ) {
5010 if ( phy.isRooted() ) {
5014 if ( !p.hasNext() ) {
5018 if ( phy == null ) {
5021 if ( phy.getNumberOfExternalNodes() != 4 ) {
5024 if ( !phy.getName().equals( "" ) ) {
5027 if ( !phy.isRooted() ) {
5031 if ( !p.hasNext() ) {
5035 if ( phy == null ) {
5038 if ( phy.getNumberOfExternalNodes() != 5 ) {
5039 System.out.println( phy.getNumberOfExternalNodes() );
5042 if ( !phy.getName().equals( "" ) ) {
5045 if ( !phy.isRooted() ) {
5049 if ( !p.hasNext() ) {
5053 if ( phy == null ) {
5056 if ( phy.getNumberOfExternalNodes() != 3 ) {
5059 if ( !phy.getName().equals( "" ) ) {
5062 if ( phy.isRooted() ) {
5066 if ( !p.hasNext() ) {
5070 if ( phy == null ) {
5073 if ( phy.getNumberOfExternalNodes() != 2 ) {
5076 if ( !phy.getName().equals( "" ) ) {
5079 if ( !phy.isRooted() ) {
5083 if ( !p.hasNext() ) {
5087 if ( phy.getNumberOfExternalNodes() != 3 ) {
5090 if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
5093 if ( !phy.isRooted() ) {
5097 if ( !p.hasNext() ) {
5101 if ( phy.getNumberOfExternalNodes() != 3 ) {
5104 if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
5107 if ( !phy.getName().equals( "tree 8" ) ) {
5111 if ( !p.hasNext() ) {
5115 if ( phy.getNumberOfExternalNodes() != 3 ) {
5118 if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
5121 if ( !phy.getName().equals( "tree 9" ) ) {
5125 if ( !p.hasNext() ) {
5129 if ( phy.getNumberOfExternalNodes() != 3 ) {
5132 if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
5135 if ( !phy.getName().equals( "tree 10" ) ) {
5138 if ( !phy.isRooted() ) {
5142 if ( !p.hasNext() ) {
5146 if ( phy.getNumberOfExternalNodes() != 3 ) {
5149 if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
5152 if ( !phy.getName().equals( "tree 11" ) ) {
5155 if ( phy.isRooted() ) {
5159 if ( !p.hasNext() ) {
5163 if ( phy.getNumberOfExternalNodes() != 3 ) {
5166 if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
5169 if ( !phy.getName().equals( "tree 12" ) ) {
5172 if ( !phy.isRooted() ) {
5176 if ( !p.hasNext() ) {
5180 if ( phy.getNumberOfExternalNodes() != 3 ) {
5183 if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
5186 if ( !phy.getName().equals( "tree 13" ) ) {
5189 if ( !phy.isRooted() ) {
5193 if ( !p.hasNext() ) {
5197 if ( phy.getNumberOfExternalNodes() != 10 ) {
5198 System.out.println( phy.getNumberOfExternalNodes() );
5203 .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;" ) ) {
5204 System.out.println( phy.toNewHampshire() );
5207 if ( !phy.getName().equals( "tree 14" ) ) {
5210 if ( !phy.isRooted() ) {
5214 if ( !p.hasNext() ) {
5218 if ( phy.getNumberOfExternalNodes() != 10 ) {
5219 System.out.println( phy.getNumberOfExternalNodes() );
5224 .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;" ) ) {
5225 System.out.println( phy.toNewHampshire() );
5228 if ( !phy.getName().equals( "tree 15" ) ) {
5231 if ( phy.isRooted() ) {
5235 if ( !p.hasNext() ) {
5239 if ( phy.getNumberOfExternalNodes() != 10 ) {
5240 System.out.println( phy.getNumberOfExternalNodes() );
5245 .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;" ) ) {
5246 System.out.println( phy.toNewHampshire() );
5249 if ( !phy.getName().equals( "tree 16" ) ) {
5252 if ( !phy.isRooted() ) {
5256 if ( !p.hasNext() ) {
5260 if ( phy.getNumberOfExternalNodes() != 10 ) {
5261 System.out.println( phy.getNumberOfExternalNodes() );
5266 .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;" ) ) {
5267 System.out.println( phy.toNewHampshire() );
5270 if ( !phy.getName().equals( "tree 17" ) ) {
5273 if ( phy.isRooted() ) {
5277 if ( p.hasNext() ) {
5281 if ( phy != null ) {
5286 if ( !p.hasNext() ) {
5290 if ( phy == null ) {
5293 if ( phy.getNumberOfExternalNodes() != 10 ) {
5296 if ( !phy.getName().equals( "tree 0" ) ) {
5300 if ( !p.hasNext() ) {
5304 if ( phy == null ) {
5307 if ( phy.getNumberOfExternalNodes() != 10 ) {
5310 if ( !phy.getName().equals( "tree 1" ) ) {
5314 if ( !p.hasNext() ) {
5318 if ( phy == null ) {
5321 if ( phy.getNumberOfExternalNodes() != 3 ) {
5324 if ( !phy.getName().equals( "" ) ) {
5327 if ( phy.isRooted() ) {
5331 if ( !p.hasNext() ) {
5335 if ( phy == null ) {
5338 if ( phy.getNumberOfExternalNodes() != 4 ) {
5341 if ( !phy.getName().equals( "" ) ) {
5344 if ( !phy.isRooted() ) {
5348 if ( !p.hasNext() ) {
5352 if ( phy == null ) {
5355 if ( phy.getNumberOfExternalNodes() != 5 ) {
5356 System.out.println( phy.getNumberOfExternalNodes() );
5359 if ( !phy.getName().equals( "" ) ) {
5362 if ( !phy.isRooted() ) {
5366 if ( !p.hasNext() ) {
5370 if ( phy == null ) {
5373 if ( phy.getNumberOfExternalNodes() != 3 ) {
5376 if ( !phy.getName().equals( "" ) ) {
5379 if ( phy.isRooted() ) {
5383 catch ( final Exception e ) {
5384 e.printStackTrace( System.out );
5390 private static boolean testNexusTreeParsingTranslating() {
5392 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5393 final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
5394 Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
5395 if ( phylogenies.length != 1 ) {
5398 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5401 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5404 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5407 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5410 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5411 .equals( "Aranaeus" ) ) {
5415 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
5416 if ( phylogenies.length != 3 ) {
5419 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5422 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5425 if ( phylogenies[ 0 ].isRooted() ) {
5428 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5431 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5434 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5435 .equals( "Aranaeus" ) ) {
5438 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
5441 if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
5444 if ( phylogenies[ 1 ].isRooted() ) {
5447 if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5450 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5453 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5454 .equals( "Aranaeus" ) ) {
5457 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
5460 if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
5463 if ( !phylogenies[ 2 ].isRooted() ) {
5466 if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5469 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5472 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5473 .equals( "Aranaeus" ) ) {
5477 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
5478 if ( phylogenies.length != 3 ) {
5481 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
5484 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
5487 if ( phylogenies[ 0 ].isRooted() ) {
5490 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5493 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5496 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5497 .equals( "Aranaeus" ) ) {
5500 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
5503 if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
5506 if ( phylogenies[ 1 ].isRooted() ) {
5509 if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5512 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5515 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5516 .equals( "Aranaeus" ) ) {
5519 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
5522 if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
5525 if ( !phylogenies[ 2 ].isRooted() ) {
5528 if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
5531 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
5534 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
5535 .equals( "Aranaeus" ) ) {
5539 catch ( final Exception e ) {
5540 e.printStackTrace( System.out );
5546 private static boolean testNHParsing() {
5548 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5549 final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
5550 if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
5553 final NHXParser nhxp = new NHXParser();
5554 nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
5555 nhxp.setReplaceUnderscores( true );
5556 final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
5557 if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
5560 if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
5563 final Phylogeny p1b = factory
5564 .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 ",
5565 new NHXParser() )[ 0 ];
5566 if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
5569 if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
5572 final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
5573 final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
5574 final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
5575 final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
5576 final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
5577 final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
5578 final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
5579 final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
5580 final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
5581 final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
5582 final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1 3 ; \n)\t ( \n ;"
5583 + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
5584 + "; ; ( \t\n\r\b; G ;, ;H ;1 3; ) ; ; ;",
5586 if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
5589 if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
5592 if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
5595 if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
5598 final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
5599 final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
5600 final String p16_S = "((A,B),C)";
5601 final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
5602 if ( p16.length != 1 ) {
5605 if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
5608 final String p17_S = "(C,(A,B))";
5609 final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
5610 if ( p17.length != 1 ) {
5613 if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
5616 final String p18_S = "((A,B),(C,D))";
5617 final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
5618 if ( p18.length != 1 ) {
5621 if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
5624 final String p19_S = "(((A,B),C),D)";
5625 final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
5626 if ( p19.length != 1 ) {
5629 if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
5632 final String p20_S = "(A,(B,(C,D)))";
5633 final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
5634 if ( p20.length != 1 ) {
5637 if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
5640 final String p21_S = "(A,(B,(C,(D,E))))";
5641 final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
5642 if ( p21.length != 1 ) {
5645 if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
5648 final String p22_S = "((((A,B),C),D),E)";
5649 final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
5650 if ( p22.length != 1 ) {
5653 if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
5656 final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5657 final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
5658 if ( p23.length != 1 ) {
5659 System.out.println( "xl=" + p23.length );
5663 if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
5666 final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5667 final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
5668 if ( p24.length != 1 ) {
5671 if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
5674 final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5675 final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5676 final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
5677 if ( p241.length != 2 ) {
5680 if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
5683 if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
5686 final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
5687 + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
5688 + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
5689 + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
5690 + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
5691 + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
5692 + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
5693 + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
5694 final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
5695 if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
5698 final String p26_S = "(A,B)ab";
5699 final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
5700 if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
5703 final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5704 final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
5705 if ( p27s.length != 1 ) {
5706 System.out.println( "xxl=" + p27s.length );
5710 if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
5711 System.out.println( p27s[ 0 ].toNewHampshireX() );
5715 final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
5717 if ( p27.length != 1 ) {
5718 System.out.println( "yl=" + p27.length );
5722 if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
5723 System.out.println( p27[ 0 ].toNewHampshireX() );
5727 final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
5728 final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
5729 final String p28_S3 = "(A,B)ab";
5730 final String p28_S4 = "((((A,B),C),D),;E;)";
5731 final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
5733 if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
5736 if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
5739 if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
5742 if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
5745 if ( p28.length != 4 ) {
5748 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";
5749 final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
5750 if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
5753 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";
5754 final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
5755 if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
5758 final String p32_S = " ; ; \n \t \b \f \r ;;;;;; ";
5759 final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
5760 if ( ( p32.length != 0 ) ) {
5763 final String p33_S = "A";
5764 final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
5765 if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
5768 final String p34_S = "B;";
5769 final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
5770 if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
5773 final String p35_S = "B:0.2";
5774 final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
5775 if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
5778 final String p36_S = "(A)";
5779 final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
5780 if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
5783 final String p37_S = "((A))";
5784 final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
5785 if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
5788 final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
5789 final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
5790 if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
5793 final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
5794 final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
5795 if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
5798 final String p40_S = "(A,B,C)";
5799 final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
5800 if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
5803 final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
5804 final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
5805 if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
5808 final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
5809 final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
5810 if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
5813 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)";
5814 final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
5815 if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
5818 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)))";
5819 final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
5820 if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
5823 final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
5824 final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
5825 if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
5828 final String p46_S = "";
5829 final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
5830 if ( p46.length != 0 ) {
5833 final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
5834 if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5837 final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5838 if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5841 final Phylogeny p49 = factory
5842 .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
5843 new NHXParser() )[ 0 ];
5844 if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
5847 final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5848 if ( p50.getNode( "A" ) == null ) {
5851 if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
5852 .equals( "((A,B)ab:2.0[88],C);" ) ) {
5855 if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
5858 if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
5859 .equals( "((A,B)88:2.0,C);" ) ) {
5862 final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5863 if ( p51.getNode( "A(A" ) == null ) {
5866 final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
5867 if ( p52.getNode( "A(A" ) == null ) {
5870 final Phylogeny p53 = factory
5871 .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
5872 new NHXParser() )[ 0 ];
5873 if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
5877 final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
5878 if ( p54.getNode( "A" ) == null ) {
5881 if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
5882 .equals( "((A,B)[88],C);" ) ) {
5886 catch ( final Exception e ) {
5887 e.printStackTrace( System.out );
5893 private static boolean testNHParsingIter() {
5895 final String p0_str = "(A,B);";
5896 final NHXParser p = new NHXParser();
5897 p.setSource( p0_str );
5898 if ( !p.hasNext() ) {
5901 final Phylogeny p0 = p.next();
5902 if ( !p0.toNewHampshire().equals( p0_str ) ) {
5903 System.out.println( p0.toNewHampshire() );
5906 if ( p.hasNext() ) {
5909 if ( p.next() != null ) {
5913 final String p00_str = "(A,B)root;";
5914 p.setSource( p00_str );
5915 final Phylogeny p00 = p.next();
5916 if ( !p00.toNewHampshire().equals( p00_str ) ) {
5917 System.out.println( p00.toNewHampshire() );
5921 final String p000_str = "A;";
5922 p.setSource( p000_str );
5923 final Phylogeny p000 = p.next();
5924 if ( !p000.toNewHampshire().equals( p000_str ) ) {
5925 System.out.println( p000.toNewHampshire() );
5929 final String p0000_str = "A";
5930 p.setSource( p0000_str );
5931 final Phylogeny p0000 = p.next();
5932 if ( !p0000.toNewHampshire().equals( "A;" ) ) {
5933 System.out.println( p0000.toNewHampshire() );
5937 p.setSource( "(A)" );
5938 final Phylogeny p00000 = p.next();
5939 if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
5940 System.out.println( p00000.toNewHampshire() );
5944 final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
5945 p.setSource( p1_str );
5946 if ( !p.hasNext() ) {
5949 final Phylogeny p1_0 = p.next();
5950 if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
5951 System.out.println( p1_0.toNewHampshire() );
5954 if ( !p.hasNext() ) {
5957 final Phylogeny p1_1 = p.next();
5958 if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
5959 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
5962 if ( !p.hasNext() ) {
5965 final Phylogeny p1_2 = p.next();
5966 if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
5967 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
5970 if ( !p.hasNext() ) {
5973 final Phylogeny p1_3 = p.next();
5974 if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
5975 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
5978 if ( p.hasNext() ) {
5981 if ( p.next() != null ) {
5985 final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
5986 p.setSource( p2_str );
5987 if ( !p.hasNext() ) {
5990 Phylogeny p2_0 = p.next();
5991 if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
5992 System.out.println( p2_0.toNewHampshire() );
5995 if ( !p.hasNext() ) {
5998 Phylogeny p2_1 = p.next();
5999 if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
6000 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
6003 if ( !p.hasNext() ) {
6006 Phylogeny p2_2 = p.next();
6007 if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
6008 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
6011 if ( !p.hasNext() ) {
6014 Phylogeny p2_3 = p.next();
6015 if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
6016 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
6019 if ( !p.hasNext() ) {
6022 Phylogeny p2_4 = p.next();
6023 if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
6024 System.out.println( "(X) != " + p2_4.toNewHampshire() );
6027 if ( p.hasNext() ) {
6030 if ( p.next() != null ) {
6035 if ( !p.hasNext() ) {
6039 if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
6040 System.out.println( p2_0.toNewHampshire() );
6043 if ( !p.hasNext() ) {
6047 if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
6048 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
6051 if ( !p.hasNext() ) {
6055 if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
6056 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
6059 if ( !p.hasNext() ) {
6063 if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
6064 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
6067 if ( !p.hasNext() ) {
6071 if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
6072 System.out.println( "(X) != " + p2_4.toNewHampshire() );
6075 if ( p.hasNext() ) {
6078 if ( p.next() != null ) {
6082 final String p3_str = "((A,B),C)abc";
6083 p.setSource( p3_str );
6084 if ( !p.hasNext() ) {
6087 final Phylogeny p3_0 = p.next();
6088 if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
6091 if ( p.hasNext() ) {
6094 if ( p.next() != null ) {
6098 final String p4_str = "((A,B)ab,C)abc";
6099 p.setSource( p4_str );
6100 if ( !p.hasNext() ) {
6103 final Phylogeny p4_0 = p.next();
6104 if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
6107 if ( p.hasNext() ) {
6110 if ( p.next() != null ) {
6114 final String p5_str = "(((A,B)ab,C)abc,D)abcd";
6115 p.setSource( p5_str );
6116 if ( !p.hasNext() ) {
6119 final Phylogeny p5_0 = p.next();
6120 if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
6123 if ( p.hasNext() ) {
6126 if ( p.next() != null ) {
6130 final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
6131 p.setSource( p6_str );
6132 if ( !p.hasNext() ) {
6135 Phylogeny p6_0 = p.next();
6136 if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
6139 if ( p.hasNext() ) {
6142 if ( p.next() != null ) {
6146 if ( !p.hasNext() ) {
6150 if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
6153 if ( p.hasNext() ) {
6156 if ( p.next() != null ) {
6160 final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
6161 p.setSource( p7_str );
6162 if ( !p.hasNext() ) {
6165 Phylogeny p7_0 = p.next();
6166 if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6169 if ( p.hasNext() ) {
6172 if ( p.next() != null ) {
6176 if ( !p.hasNext() ) {
6180 if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6183 if ( p.hasNext() ) {
6186 if ( p.next() != null ) {
6190 final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
6191 p.setSource( p8_str );
6192 if ( !p.hasNext() ) {
6195 Phylogeny p8_0 = p.next();
6196 if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6199 if ( !p.hasNext() ) {
6202 if ( !p.hasNext() ) {
6205 Phylogeny p8_1 = p.next();
6206 if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
6209 if ( p.hasNext() ) {
6212 if ( p.next() != null ) {
6216 if ( !p.hasNext() ) {
6220 if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
6223 if ( !p.hasNext() ) {
6227 if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
6230 if ( p.hasNext() ) {
6233 if ( p.next() != null ) {
6239 if ( p.hasNext() ) {
6243 p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
6244 if ( !p.hasNext() ) {
6247 Phylogeny p_27 = p.next();
6248 if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
6249 System.out.println( p_27.toNewHampshireX() );
6253 if ( p.hasNext() ) {
6256 if ( p.next() != null ) {
6260 if ( !p.hasNext() ) {
6264 if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
6265 System.out.println( p_27.toNewHampshireX() );
6269 if ( p.hasNext() ) {
6272 if ( p.next() != null ) {
6276 catch ( final Exception e ) {
6277 e.printStackTrace( System.out );
6283 private static boolean testNHXconversion() {
6285 final PhylogenyNode n1 = new PhylogenyNode();
6286 final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
6287 final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
6288 final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
6289 final PhylogenyNode n5 = PhylogenyNode
6290 .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
6291 final PhylogenyNode n6 = PhylogenyNode
6292 .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
6293 if ( !n1.toNewHampshireX().equals( "" ) ) {
6296 if ( !n2.toNewHampshireX().equals( "" ) ) {
6299 if ( !n3.toNewHampshireX().equals( "n3" ) ) {
6302 if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
6305 if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
6308 if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
6309 System.out.println( n6.toNewHampshireX() );
6313 catch ( final Exception e ) {
6314 e.printStackTrace( System.out );
6320 private static boolean testTaxonomyExtraction() {
6322 final PhylogenyNode n0 = PhylogenyNode
6323 .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6324 if ( n0.getNodeData().isHasTaxonomy() ) {
6327 final PhylogenyNode n1 = PhylogenyNode
6328 .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6329 if ( n1.getNodeData().isHasTaxonomy() ) {
6330 System.out.println( n1.toString() );
6333 final PhylogenyNode n2x = PhylogenyNode
6334 .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6335 if ( n2x.getNodeData().isHasTaxonomy() ) {
6338 final PhylogenyNode n3 = PhylogenyNode
6339 .createInstanceFromNhxString( "blag_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6340 if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6341 System.out.println( n3.toString() );
6344 final PhylogenyNode n4 = PhylogenyNode
6345 .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6346 if ( n4.getNodeData().isHasTaxonomy() ) {
6347 System.out.println( n4.toString() );
6350 final PhylogenyNode n5 = PhylogenyNode
6351 .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6352 if ( n5.getNodeData().isHasTaxonomy() ) {
6353 System.out.println( n5.toString() );
6356 final PhylogenyNode n6 = PhylogenyNode
6357 .createInstanceFromNhxString( "blag-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6358 if ( n6.getNodeData().isHasTaxonomy() ) {
6359 System.out.println( n6.toString() );
6362 final PhylogenyNode n7 = PhylogenyNode
6363 .createInstanceFromNhxString( "blag-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6364 if ( n7.getNodeData().isHasTaxonomy() ) {
6365 System.out.println( n7.toString() );
6368 final PhylogenyNode n8 = PhylogenyNode
6369 .createInstanceFromNhxString( "blag_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6370 if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6371 System.out.println( n8.toString() );
6374 final PhylogenyNode n9 = PhylogenyNode
6375 .createInstanceFromNhxString( "blag_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6376 if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6377 System.out.println( n9.toString() );
6380 final PhylogenyNode n10x = PhylogenyNode
6381 .createInstanceFromNhxString( "blag_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6382 if ( n10x.getNodeData().isHasTaxonomy() ) {
6383 System.out.println( n10x.toString() );
6386 final PhylogenyNode n10xx = PhylogenyNode
6387 .createInstanceFromNhxString( "blag_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6388 if ( n10xx.getNodeData().isHasTaxonomy() ) {
6389 System.out.println( n10xx.toString() );
6392 final PhylogenyNode n10 = PhylogenyNode
6393 .createInstanceFromNhxString( "blag_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6394 if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
6395 System.out.println( n10.toString() );
6398 final PhylogenyNode n11 = PhylogenyNode
6399 .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
6400 if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
6401 System.out.println( n11.toString() );
6404 final PhylogenyNode n12 = PhylogenyNode
6405 .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
6406 NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
6407 if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
6408 System.out.println( n12.toString() );
6411 final PhylogenyNode n13 = PhylogenyNode
6412 .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
6413 if ( n13.getNodeData().isHasTaxonomy() ) {
6414 System.out.println( n13.toString() );
6418 catch ( final Exception e ) {
6419 e.printStackTrace( System.out );
6425 private static boolean testNHXNodeParsing() {
6427 final PhylogenyNode n1 = new PhylogenyNode();
6428 final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
6429 final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
6430 final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
6431 final PhylogenyNode n5 = PhylogenyNode
6432 .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]" );
6433 if ( !n3.getName().equals( "n3" ) ) {
6436 if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6439 if ( n3.isDuplication() ) {
6442 if ( n3.isHasAssignedEvent() ) {
6445 if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
6448 if ( !n4.getName().equals( "n4" ) ) {
6451 if ( n4.getDistanceToParent() != 0.01 ) {
6454 if ( !n5.getName().equals( "n5" ) ) {
6457 if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
6460 if ( n5.getDistanceToParent() != 0.1 ) {
6463 if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
6466 if ( !n5.isDuplication() ) {
6469 if ( !n5.isHasAssignedEvent() ) {
6472 final PhylogenyNode n8 = PhylogenyNode
6473 .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
6474 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6475 if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
6478 if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
6481 final PhylogenyNode n9 = PhylogenyNode
6482 .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
6483 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6484 if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
6487 if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
6490 final PhylogenyNode n10 = PhylogenyNode
6491 .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6492 if ( !n10.getName().equals( "n10.ECOLI" ) ) {
6495 final PhylogenyNode n20 = PhylogenyNode
6496 .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6497 if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
6500 if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
6503 final PhylogenyNode n20x = PhylogenyNode
6504 .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6505 if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
6508 if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
6511 final PhylogenyNode n20xx = PhylogenyNode
6512 .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6513 if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
6516 if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
6519 final PhylogenyNode n20xxx = PhylogenyNode
6520 .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6521 if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
6524 if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
6527 final PhylogenyNode n20xxxx = PhylogenyNode
6528 .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6529 if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
6532 if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
6535 final PhylogenyNode n21 = PhylogenyNode
6536 .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6537 if ( !n21.getName().equals( "N21_PIG" ) ) {
6540 if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
6543 final PhylogenyNode n21x = PhylogenyNode
6544 .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6545 if ( !n21x.getName().equals( "n21_PIG" ) ) {
6548 if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
6551 final PhylogenyNode n22 = PhylogenyNode
6552 .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6553 if ( !n22.getName().equals( "n22/PIG" ) ) {
6556 if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
6559 final PhylogenyNode n23 = PhylogenyNode
6560 .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6561 if ( !n23.getName().equals( "n23/PIG_1" ) ) {
6564 if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
6567 final PhylogenyNode a = PhylogenyNode
6568 .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6569 if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
6572 if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
6575 final PhylogenyNode c1 = PhylogenyNode
6576 .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
6577 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6578 if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
6581 if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
6584 final PhylogenyNode c2 = PhylogenyNode
6585 .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
6586 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6587 if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
6590 if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
6593 final PhylogenyNode e3 = PhylogenyNode
6594 .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6595 if ( !e3.getName().equals( "n10_RAT~" ) ) {
6598 if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
6601 final PhylogenyNode n11 = PhylogenyNode
6602 .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
6603 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6604 if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
6607 if ( n11.getDistanceToParent() != 0.4 ) {
6610 if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
6613 final PhylogenyNode n12 = PhylogenyNode
6614 .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
6615 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6616 if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
6619 if ( n12.getDistanceToParent() != 0.4 ) {
6622 if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
6625 final PhylogenyNode o = PhylogenyNode
6626 .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6627 if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
6630 if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
6633 if ( n1.getName().compareTo( "" ) != 0 ) {
6636 if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
6639 if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6642 if ( n2.getName().compareTo( "" ) != 0 ) {
6645 if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
6648 if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
6651 final PhylogenyNode n00 = PhylogenyNode
6652 .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
6653 if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
6656 if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
6659 final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
6660 if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
6663 final PhylogenyNode n13 = PhylogenyNode
6664 .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6665 if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
6668 if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
6671 if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6674 if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6677 final PhylogenyNode n14 = PhylogenyNode
6678 .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6679 if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
6682 if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
6685 final PhylogenyNode n15 = PhylogenyNode
6686 .createInstanceFromNhxString( "something_wicked[123]",
6687 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6688 if ( !n15.getName().equals( "something_wicked" ) ) {
6691 if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
6694 if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
6697 final PhylogenyNode n16 = PhylogenyNode
6698 .createInstanceFromNhxString( "something_wicked2[9]",
6699 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6700 if ( !n16.getName().equals( "something_wicked2" ) ) {
6703 if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
6706 if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
6709 final PhylogenyNode n17 = PhylogenyNode
6710 .createInstanceFromNhxString( "something_wicked3[a]",
6711 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6712 if ( !n17.getName().equals( "something_wicked3" ) ) {
6715 if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
6718 final PhylogenyNode n18 = PhylogenyNode
6719 .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6720 if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
6723 if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
6726 if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
6729 final PhylogenyNode n19 = PhylogenyNode
6730 .createInstanceFromNhxString( "blah_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6731 if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
6734 if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6737 final PhylogenyNode n30 = PhylogenyNode
6738 .createInstanceFromNhxString( "blah_1234567-roejojoej",
6739 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6740 if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
6743 if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
6746 final PhylogenyNode n31 = PhylogenyNode
6747 .createInstanceFromNhxString( "blah_12345678-roejojoej",
6748 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6749 if ( n31.getNodeData().isHasTaxonomy() ) {
6752 final PhylogenyNode n32 = PhylogenyNode
6753 .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6754 if ( n32.getNodeData().isHasTaxonomy() ) {
6757 final PhylogenyNode n40 = PhylogenyNode
6758 .createInstanceFromNhxString( "bcl2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6759 if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
6762 final PhylogenyNode n41 = PhylogenyNode
6763 .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6764 if ( n41.getNodeData().isHasTaxonomy() ) {
6767 final PhylogenyNode n42 = PhylogenyNode
6768 .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
6769 if ( n42.getNodeData().isHasTaxonomy() ) {
6772 final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
6773 NHXParser.TAXONOMY_EXTRACTION.NO );
6774 if ( n43.getNodeData().isHasTaxonomy() ) {
6777 final PhylogenyNode n44 = PhylogenyNode
6778 .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
6779 if ( n44.getNodeData().isHasTaxonomy() ) {
6783 catch ( final Exception e ) {
6784 e.printStackTrace( System.out );
6790 private static boolean testNHXParsing() {
6792 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6793 final Phylogeny p1 = factory.create( "(A [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
6794 if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
6797 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]";
6798 final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
6799 if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6802 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]";
6803 final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
6804 if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
6807 final Phylogeny[] p3 = factory
6808 .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]",
6810 if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6813 final Phylogeny[] p4 = factory
6814 .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(]",
6816 if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6819 final Phylogeny[] p5 = factory
6820 .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(((]",
6822 if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
6825 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)";
6826 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)";
6827 final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
6828 if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
6831 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)))";
6832 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)))";
6833 final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
6834 if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
6837 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]) ))[,,, ])))))))";
6838 final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
6839 final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
6840 if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
6843 final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
6844 if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
6847 final Phylogeny p10 = factory
6848 .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]",
6849 new NHXParser() )[ 0 ];
6850 if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
6854 catch ( final Exception e ) {
6855 e.printStackTrace( System.out );
6861 private static boolean testNHXParsingQuotes() {
6863 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6864 final NHXParser p = new NHXParser();
6865 final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
6866 if ( phylogenies_0.length != 5 ) {
6869 final Phylogeny phy = phylogenies_0[ 4 ];
6870 if ( phy.getNumberOfExternalNodes() != 7 ) {
6873 if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
6876 if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
6879 if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
6880 .getScientificName().equals( "hsapiens" ) ) {
6883 if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
6886 if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
6889 if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
6892 if ( phy.getNodes( "noquotes" ).size() != 1 ) {
6895 if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
6898 final NHXParser p1p = new NHXParser();
6899 p1p.setIgnoreQuotes( true );
6900 final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
6901 if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
6904 final NHXParser p2p = new NHXParser();
6905 p1p.setIgnoreQuotes( false );
6906 final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
6907 if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
6910 final NHXParser p3p = new NHXParser();
6911 p3p.setIgnoreQuotes( false );
6912 final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
6913 if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
6916 final NHXParser p4p = new NHXParser();
6917 p4p.setIgnoreQuotes( false );
6918 final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
6919 if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
6922 final Phylogeny p10 = factory
6923 .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]",
6924 new NHXParser() )[ 0 ];
6925 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]";
6926 if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
6929 final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
6930 if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
6934 final Phylogeny p12 = factory
6935 .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]",
6936 new NHXParser() )[ 0 ];
6937 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]";
6938 if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
6941 final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
6942 if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
6945 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;";
6946 if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
6949 final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
6950 if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
6954 catch ( final Exception e ) {
6955 e.printStackTrace( System.out );
6961 private static boolean testNHXParsingMB() {
6963 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6964 final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
6965 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6966 + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
6967 + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
6968 + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
6969 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6970 + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
6971 + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
6972 + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
6973 if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
6976 if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
6979 if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
6980 0.1100000000000000e+00 ) ) {
6983 if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
6986 if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
6989 final Phylogeny p2 = factory
6990 .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
6991 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6992 + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
6993 + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
6994 + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
6995 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
6996 + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
6997 + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
6998 + "7.369400000000000e-02}])",
6999 new NHXParser() )[ 0 ];
7000 if ( p2.getNode( "1" ) == null ) {
7003 if ( p2.getNode( "2" ) == null ) {
7007 catch ( final Exception e ) {
7008 e.printStackTrace( System.out );
7015 private static boolean testPhylogenyBranch() {
7017 final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
7018 final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
7019 final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
7020 final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
7021 if ( !a1b1.equals( a1b1 ) ) {
7024 if ( !a1b1.equals( b1a1 ) ) {
7027 if ( !b1a1.equals( a1b1 ) ) {
7030 final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
7031 final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
7032 final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
7033 if ( a1_b1.equals( b1_a1 ) ) {
7036 if ( a1_b1.equals( a1_b1_ ) ) {
7039 final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
7040 if ( !a1_b1.equals( b1_a1_ ) ) {
7043 if ( a1_b1_.equals( b1_a1_ ) ) {
7046 if ( !a1_b1_.equals( b1_a1 ) ) {
7050 catch ( final Exception e ) {
7051 e.printStackTrace( System.out );
7057 private static boolean testPhyloXMLparsingOfDistributionElement() {
7059 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7060 PhyloXmlParser xml_parser = null;
7062 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
7064 catch ( final Exception e ) {
7065 // Do nothing -- means were not running from jar.
7067 if ( xml_parser == null ) {
7068 xml_parser = new PhyloXmlParser();
7069 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
7070 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
7073 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
7076 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
7078 if ( xml_parser.getErrorCount() > 0 ) {
7079 System.out.println( xml_parser.getErrorMessages().toString() );
7082 if ( phylogenies_0.length != 1 ) {
7085 final Phylogeny t1 = phylogenies_0[ 0 ];
7086 PhylogenyNode n = null;
7087 Distribution d = null;
7088 n = t1.getNode( "root node" );
7089 if ( !n.getNodeData().isHasDistribution() ) {
7092 if ( n.getNodeData().getDistributions().size() != 1 ) {
7095 d = n.getNodeData().getDistribution();
7096 if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
7099 if ( d.getPoints().size() != 1 ) {
7102 if ( d.getPolygons() != null ) {
7105 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
7108 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7111 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7114 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
7117 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
7120 n = t1.getNode( "node a" );
7121 if ( !n.getNodeData().isHasDistribution() ) {
7124 if ( n.getNodeData().getDistributions().size() != 2 ) {
7127 d = n.getNodeData().getDistribution( 1 );
7128 if ( !d.getDesc().equals( "San Diego" ) ) {
7131 if ( d.getPoints().size() != 1 ) {
7134 if ( d.getPolygons() != null ) {
7137 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
7140 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7143 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7146 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
7149 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
7152 n = t1.getNode( "node bb" );
7153 if ( !n.getNodeData().isHasDistribution() ) {
7156 if ( n.getNodeData().getDistributions().size() != 1 ) {
7159 d = n.getNodeData().getDistribution( 0 );
7160 if ( d.getPoints().size() != 3 ) {
7163 if ( d.getPolygons().size() != 2 ) {
7166 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
7169 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
7172 if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
7175 if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
7178 if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
7181 if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
7184 Polygon p = d.getPolygons().get( 0 );
7185 if ( p.getPoints().size() != 3 ) {
7188 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
7191 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
7194 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7197 if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
7200 if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
7203 if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
7206 p = d.getPolygons().get( 1 );
7207 if ( p.getPoints().size() != 3 ) {
7210 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
7213 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
7216 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7220 final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
7221 final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
7222 if ( rt.length != 1 ) {
7225 final Phylogeny t1_rt = rt[ 0 ];
7226 n = t1_rt.getNode( "root node" );
7227 if ( !n.getNodeData().isHasDistribution() ) {
7230 if ( n.getNodeData().getDistributions().size() != 1 ) {
7233 d = n.getNodeData().getDistribution();
7234 if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
7237 if ( d.getPoints().size() != 1 ) {
7240 if ( d.getPolygons() != null ) {
7243 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
7246 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7249 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7252 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
7255 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
7258 n = t1_rt.getNode( "node a" );
7259 if ( !n.getNodeData().isHasDistribution() ) {
7262 if ( n.getNodeData().getDistributions().size() != 2 ) {
7265 d = n.getNodeData().getDistribution( 1 );
7266 if ( !d.getDesc().equals( "San Diego" ) ) {
7269 if ( d.getPoints().size() != 1 ) {
7272 if ( d.getPolygons() != null ) {
7275 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
7278 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
7281 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
7284 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
7287 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
7290 n = t1_rt.getNode( "node bb" );
7291 if ( !n.getNodeData().isHasDistribution() ) {
7294 if ( n.getNodeData().getDistributions().size() != 1 ) {
7297 d = n.getNodeData().getDistribution( 0 );
7298 if ( d.getPoints().size() != 3 ) {
7301 if ( d.getPolygons().size() != 2 ) {
7304 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
7307 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
7310 if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
7313 if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
7316 if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
7319 if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
7322 p = d.getPolygons().get( 0 );
7323 if ( p.getPoints().size() != 3 ) {
7326 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
7329 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
7332 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7335 if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
7338 if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
7341 if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
7344 p = d.getPolygons().get( 1 );
7345 if ( p.getPoints().size() != 3 ) {
7348 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
7351 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
7354 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
7358 catch ( final Exception e ) {
7359 e.printStackTrace( System.out );
7365 private static boolean testPostOrderIterator() {
7367 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7368 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
7369 PhylogenyNodeIterator it0;
7370 for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
7373 for( it0.reset(); it0.hasNext(); ) {
7376 final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
7377 final PhylogenyNodeIterator it = t1.iteratorPostorder();
7378 if ( !it.next().getName().equals( "A" ) ) {
7381 if ( !it.next().getName().equals( "B" ) ) {
7384 if ( !it.next().getName().equals( "ab" ) ) {
7387 if ( !it.next().getName().equals( "C" ) ) {
7390 if ( !it.next().getName().equals( "D" ) ) {
7393 if ( !it.next().getName().equals( "cd" ) ) {
7396 if ( !it.next().getName().equals( "abcd" ) ) {
7399 if ( !it.next().getName().equals( "E" ) ) {
7402 if ( !it.next().getName().equals( "F" ) ) {
7405 if ( !it.next().getName().equals( "ef" ) ) {
7408 if ( !it.next().getName().equals( "G" ) ) {
7411 if ( !it.next().getName().equals( "H" ) ) {
7414 if ( !it.next().getName().equals( "gh" ) ) {
7417 if ( !it.next().getName().equals( "efgh" ) ) {
7420 if ( !it.next().getName().equals( "r" ) ) {
7423 if ( it.hasNext() ) {
7427 catch ( final Exception e ) {
7428 e.printStackTrace( System.out );
7434 private static boolean testPreOrderIterator() {
7436 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7437 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
7438 PhylogenyNodeIterator it0;
7439 for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
7442 for( it0.reset(); it0.hasNext(); ) {
7445 PhylogenyNodeIterator it = t0.iteratorPreorder();
7446 if ( !it.next().getName().equals( "r" ) ) {
7449 if ( !it.next().getName().equals( "ab" ) ) {
7452 if ( !it.next().getName().equals( "A" ) ) {
7455 if ( !it.next().getName().equals( "B" ) ) {
7458 if ( !it.next().getName().equals( "cd" ) ) {
7461 if ( !it.next().getName().equals( "C" ) ) {
7464 if ( !it.next().getName().equals( "D" ) ) {
7467 if ( it.hasNext() ) {
7470 final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
7471 it = t1.iteratorPreorder();
7472 if ( !it.next().getName().equals( "r" ) ) {
7475 if ( !it.next().getName().equals( "abcd" ) ) {
7478 if ( !it.next().getName().equals( "ab" ) ) {
7481 if ( !it.next().getName().equals( "A" ) ) {
7484 if ( !it.next().getName().equals( "B" ) ) {
7487 if ( !it.next().getName().equals( "cd" ) ) {
7490 if ( !it.next().getName().equals( "C" ) ) {
7493 if ( !it.next().getName().equals( "D" ) ) {
7496 if ( !it.next().getName().equals( "efgh" ) ) {
7499 if ( !it.next().getName().equals( "ef" ) ) {
7502 if ( !it.next().getName().equals( "E" ) ) {
7505 if ( !it.next().getName().equals( "F" ) ) {
7508 if ( !it.next().getName().equals( "gh" ) ) {
7511 if ( !it.next().getName().equals( "G" ) ) {
7514 if ( !it.next().getName().equals( "H" ) ) {
7517 if ( it.hasNext() ) {
7521 catch ( final Exception e ) {
7522 e.printStackTrace( System.out );
7528 private static boolean testPropertiesMap() {
7530 final PropertiesMap pm = new PropertiesMap();
7531 final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
7532 final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
7533 final Property p2 = new Property( "something:else",
7535 "improbable:research",
7538 pm.addProperty( p0 );
7539 pm.addProperty( p1 );
7540 pm.addProperty( p2 );
7541 if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
7544 if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
7547 if ( pm.getProperties().size() != 3 ) {
7550 if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
7553 if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
7556 if ( pm.getProperties().size() != 3 ) {
7559 pm.removeProperty( "dimensions:diameter" );
7560 if ( pm.getProperties().size() != 2 ) {
7563 if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
7566 if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
7570 catch ( final Exception e ) {
7571 e.printStackTrace( System.out );
7577 private static boolean testReIdMethods() {
7579 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7580 final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
7581 final long count = PhylogenyNode.getNodeCount();
7583 if ( p.getNode( "r" ).getId() != count ) {
7586 if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
7589 if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
7592 if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
7595 if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
7598 if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
7601 if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
7604 if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
7607 if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
7610 if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
7613 if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
7616 if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
7619 if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
7622 if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
7625 if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
7629 catch ( final Exception e ) {
7630 e.printStackTrace( System.out );
7636 private static boolean testRerooting() {
7638 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7639 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",
7640 new NHXParser() )[ 0 ];
7641 if ( !t1.isRooted() ) {
7644 t1.reRoot( t1.getNode( "D" ) );
7645 t1.reRoot( t1.getNode( "CD" ) );
7646 t1.reRoot( t1.getNode( "A" ) );
7647 t1.reRoot( t1.getNode( "B" ) );
7648 t1.reRoot( t1.getNode( "AB" ) );
7649 t1.reRoot( t1.getNode( "D" ) );
7650 t1.reRoot( t1.getNode( "C" ) );
7651 t1.reRoot( t1.getNode( "CD" ) );
7652 t1.reRoot( t1.getNode( "A" ) );
7653 t1.reRoot( t1.getNode( "B" ) );
7654 t1.reRoot( t1.getNode( "AB" ) );
7655 t1.reRoot( t1.getNode( "D" ) );
7656 t1.reRoot( t1.getNode( "D" ) );
7657 t1.reRoot( t1.getNode( "C" ) );
7658 t1.reRoot( t1.getNode( "A" ) );
7659 t1.reRoot( t1.getNode( "B" ) );
7660 t1.reRoot( t1.getNode( "AB" ) );
7661 t1.reRoot( t1.getNode( "C" ) );
7662 t1.reRoot( t1.getNode( "D" ) );
7663 t1.reRoot( t1.getNode( "CD" ) );
7664 t1.reRoot( t1.getNode( "D" ) );
7665 t1.reRoot( t1.getNode( "A" ) );
7666 t1.reRoot( t1.getNode( "B" ) );
7667 t1.reRoot( t1.getNode( "AB" ) );
7668 t1.reRoot( t1.getNode( "C" ) );
7669 t1.reRoot( t1.getNode( "D" ) );
7670 t1.reRoot( t1.getNode( "CD" ) );
7671 t1.reRoot( t1.getNode( "D" ) );
7672 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
7675 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
7678 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
7681 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
7684 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
7687 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
7690 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",
7691 new NHXParser() )[ 0 ];
7692 t2.reRoot( t2.getNode( "A" ) );
7693 t2.reRoot( t2.getNode( "D" ) );
7694 t2.reRoot( t2.getNode( "ABC" ) );
7695 t2.reRoot( t2.getNode( "A" ) );
7696 t2.reRoot( t2.getNode( "B" ) );
7697 t2.reRoot( t2.getNode( "D" ) );
7698 t2.reRoot( t2.getNode( "C" ) );
7699 t2.reRoot( t2.getNode( "ABC" ) );
7700 t2.reRoot( t2.getNode( "A" ) );
7701 t2.reRoot( t2.getNode( "B" ) );
7702 t2.reRoot( t2.getNode( "AB" ) );
7703 t2.reRoot( t2.getNode( "AB" ) );
7704 t2.reRoot( t2.getNode( "D" ) );
7705 t2.reRoot( t2.getNode( "C" ) );
7706 t2.reRoot( t2.getNode( "B" ) );
7707 t2.reRoot( t2.getNode( "AB" ) );
7708 t2.reRoot( t2.getNode( "D" ) );
7709 t2.reRoot( t2.getNode( "D" ) );
7710 t2.reRoot( t2.getNode( "ABC" ) );
7711 t2.reRoot( t2.getNode( "A" ) );
7712 t2.reRoot( t2.getNode( "B" ) );
7713 t2.reRoot( t2.getNode( "AB" ) );
7714 t2.reRoot( t2.getNode( "D" ) );
7715 t2.reRoot( t2.getNode( "C" ) );
7716 t2.reRoot( t2.getNode( "ABC" ) );
7717 t2.reRoot( t2.getNode( "A" ) );
7718 t2.reRoot( t2.getNode( "B" ) );
7719 t2.reRoot( t2.getNode( "AB" ) );
7720 t2.reRoot( t2.getNode( "D" ) );
7721 t2.reRoot( t2.getNode( "D" ) );
7722 t2.reRoot( t2.getNode( "C" ) );
7723 t2.reRoot( t2.getNode( "A" ) );
7724 t2.reRoot( t2.getNode( "B" ) );
7725 t2.reRoot( t2.getNode( "AB" ) );
7726 t2.reRoot( t2.getNode( "C" ) );
7727 t2.reRoot( t2.getNode( "D" ) );
7728 t2.reRoot( t2.getNode( "ABC" ) );
7729 t2.reRoot( t2.getNode( "D" ) );
7730 t2.reRoot( t2.getNode( "A" ) );
7731 t2.reRoot( t2.getNode( "B" ) );
7732 t2.reRoot( t2.getNode( "AB" ) );
7733 t2.reRoot( t2.getNode( "C" ) );
7734 t2.reRoot( t2.getNode( "D" ) );
7735 t2.reRoot( t2.getNode( "ABC" ) );
7736 t2.reRoot( t2.getNode( "D" ) );
7737 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7740 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7743 t2.reRoot( t2.getNode( "ABC" ) );
7744 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7747 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7750 t2.reRoot( t2.getNode( "AB" ) );
7751 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7754 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7757 if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7760 t2.reRoot( t2.getNode( "AB" ) );
7761 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7764 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7767 if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7770 t2.reRoot( t2.getNode( "D" ) );
7771 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7774 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7777 t2.reRoot( t2.getNode( "ABC" ) );
7778 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
7781 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
7784 final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
7785 new NHXParser() )[ 0 ];
7786 t3.reRoot( t3.getNode( "B" ) );
7787 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7790 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7793 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7796 t3.reRoot( t3.getNode( "B" ) );
7797 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7800 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7803 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7806 t3.reRoot( t3.getRoot() );
7807 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7810 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
7813 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
7817 catch ( final Exception e ) {
7818 e.printStackTrace( System.out );
7824 private static boolean testSDIse() {
7826 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7827 final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
7828 final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
7829 gene1.setRooted( true );
7830 species1.setRooted( true );
7831 final SDI sdi = new SDI( gene1, species1 );
7832 if ( !gene1.getRoot().isDuplication() ) {
7835 final Phylogeny species2 = factory
7836 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7837 new NHXParser() )[ 0 ];
7838 final Phylogeny gene2 = factory
7839 .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7840 new NHXParser() )[ 0 ];
7841 species2.setRooted( true );
7842 gene2.setRooted( true );
7843 final SDI sdi2 = new SDI( gene2, species2 );
7844 if ( sdi2.getDuplicationsSum() != 0 ) {
7847 if ( !gene2.getNode( "ab" ).isSpeciation() ) {
7850 if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
7853 if ( !gene2.getNode( "abc" ).isSpeciation() ) {
7856 if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
7859 if ( !gene2.getNode( "r" ).isSpeciation() ) {
7862 if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
7865 final Phylogeny species3 = factory
7866 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7867 new NHXParser() )[ 0 ];
7868 final Phylogeny gene3 = factory
7869 .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7870 new NHXParser() )[ 0 ];
7871 species3.setRooted( true );
7872 gene3.setRooted( true );
7873 final SDI sdi3 = new SDI( gene3, species3 );
7874 if ( sdi3.getDuplicationsSum() != 1 ) {
7877 if ( !gene3.getNode( "aa" ).isDuplication() ) {
7880 if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
7883 final Phylogeny species4 = factory
7884 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7885 new NHXParser() )[ 0 ];
7886 final Phylogeny gene4 = factory
7887 .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7888 new NHXParser() )[ 0 ];
7889 species4.setRooted( true );
7890 gene4.setRooted( true );
7891 final SDI sdi4 = new SDI( gene4, species4 );
7892 if ( sdi4.getDuplicationsSum() != 1 ) {
7895 if ( !gene4.getNode( "ac" ).isSpeciation() ) {
7898 if ( !gene4.getNode( "abc" ).isDuplication() ) {
7901 if ( gene4.getNode( "abcd" ).isDuplication() ) {
7904 if ( species4.getNumberOfExternalNodes() != 6 ) {
7907 if ( gene4.getNumberOfExternalNodes() != 6 ) {
7910 final Phylogeny species5 = factory
7911 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
7912 new NHXParser() )[ 0 ];
7913 final Phylogeny gene5 = factory
7914 .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
7915 new NHXParser() )[ 0 ];
7916 species5.setRooted( true );
7917 gene5.setRooted( true );
7918 final SDI sdi5 = new SDI( gene5, species5 );
7919 if ( sdi5.getDuplicationsSum() != 2 ) {
7922 if ( !gene5.getNode( "ad" ).isSpeciation() ) {
7925 if ( !gene5.getNode( "adc" ).isDuplication() ) {
7928 if ( !gene5.getNode( "abcd" ).isDuplication() ) {
7931 if ( species5.getNumberOfExternalNodes() != 6 ) {
7934 if ( gene5.getNumberOfExternalNodes() != 6 ) {
7937 // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
7938 // Conjecture for Comparing Molecular Phylogenies"
7939 // J. of Comput Bio. Vol. 4, No 2, pp.177-187
7940 final Phylogeny species6 = factory
7941 .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,"
7942 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
7943 new NHXParser() )[ 0 ];
7944 final Phylogeny gene6 = factory
7945 .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,"
7946 + "((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,"
7947 + "(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;",
7948 new NHXParser() )[ 0 ];
7949 species6.setRooted( true );
7950 gene6.setRooted( true );
7951 final SDI sdi6 = new SDI( gene6, species6 );
7952 if ( sdi6.getDuplicationsSum() != 3 ) {
7955 if ( !gene6.getNode( "r" ).isDuplication() ) {
7958 if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
7961 if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
7964 if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
7967 if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
7970 if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
7973 if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
7976 if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
7979 sdi6.computeMappingCostL();
7980 if ( sdi6.computeMappingCostL() != 17 ) {
7983 if ( species6.getNumberOfExternalNodes() != 9 ) {
7986 if ( gene6.getNumberOfExternalNodes() != 9 ) {
7989 final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
7990 + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
7991 + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
7992 + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
7993 + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
7994 species7.setRooted( true );
7995 final Phylogeny gene7_1 = Test
7996 .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])" );
7997 gene7_1.setRooted( true );
7998 final SDI sdi7 = new SDI( gene7_1, species7 );
7999 if ( sdi7.getDuplicationsSum() != 0 ) {
8002 if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
8005 if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
8008 if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
8011 if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
8014 if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
8017 if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
8020 if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
8023 if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
8026 final Phylogeny gene7_2 = Test
8027 .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])" );
8028 gene7_2.setRooted( true );
8029 final SDI sdi7_2 = new SDI( gene7_2, species7 );
8030 if ( sdi7_2.getDuplicationsSum() != 1 ) {
8033 if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
8036 if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
8039 if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
8042 if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
8045 if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
8048 if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
8051 if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
8054 if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
8057 if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
8061 catch ( final Exception e ) {
8067 private static boolean testSDIunrooted() {
8069 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8070 final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
8071 final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
8072 final Iterator<PhylogenyBranch> iter = l.iterator();
8073 PhylogenyBranch br = iter.next();
8074 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
8077 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
8081 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
8084 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
8088 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
8091 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
8095 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8098 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8102 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8105 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8109 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
8112 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
8116 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8119 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8123 if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8126 if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8130 if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8133 if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8137 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
8140 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
8144 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
8147 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
8151 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
8154 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
8158 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
8161 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
8165 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
8168 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
8172 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
8175 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
8178 if ( iter.hasNext() ) {
8181 final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
8182 final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
8183 final Iterator<PhylogenyBranch> iter1 = l1.iterator();
8185 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
8188 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
8192 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8195 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8199 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8202 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8205 if ( iter1.hasNext() ) {
8208 final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
8209 final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
8210 final Iterator<PhylogenyBranch> iter2 = l2.iterator();
8212 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
8215 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
8219 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
8222 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
8226 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
8229 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
8232 if ( iter2.hasNext() ) {
8235 final Phylogeny species0 = factory
8236 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
8237 new NHXParser() )[ 0 ];
8238 final Phylogeny gene1 = factory
8239 .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])",
8240 new NHXParser() )[ 0 ];
8241 species0.setRooted( true );
8242 gene1.setRooted( true );
8243 final SDIR sdi_unrooted = new SDIR();
8244 sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
8245 if ( sdi_unrooted.getCount() != 1 ) {
8248 if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
8251 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
8254 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
8257 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8260 final Phylogeny gene2 = factory
8261 .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])",
8262 new NHXParser() )[ 0 ];
8263 gene2.setRooted( true );
8264 sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
8265 if ( sdi_unrooted.getCount() != 1 ) {
8268 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8271 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8274 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
8277 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8280 final Phylogeny species6 = factory
8281 .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,"
8282 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8283 new NHXParser() )[ 0 ];
8284 final Phylogeny gene6 = factory
8285 .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],"
8286 + "(((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],"
8287 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8288 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8289 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8290 new NHXParser() )[ 0 ];
8291 species6.setRooted( true );
8292 gene6.setRooted( true );
8293 Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
8294 if ( sdi_unrooted.getCount() != 1 ) {
8297 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8300 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8303 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8306 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8309 if ( !p6[ 0 ].getRoot().isDuplication() ) {
8312 if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8315 if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8318 if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
8321 if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8324 if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
8327 if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
8330 if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8334 final Phylogeny species7 = factory
8335 .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,"
8336 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8337 new NHXParser() )[ 0 ];
8338 final Phylogeny gene7 = factory
8339 .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],"
8340 + "(((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],"
8341 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8342 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8343 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8344 new NHXParser() )[ 0 ];
8345 species7.setRooted( true );
8346 gene7.setRooted( true );
8347 Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
8348 if ( sdi_unrooted.getCount() != 1 ) {
8351 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8354 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8357 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8360 if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
8363 if ( !p7[ 0 ].getRoot().isDuplication() ) {
8366 if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8369 if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8372 if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
8375 if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8378 if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
8381 if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
8384 if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8388 final Phylogeny species8 = factory
8389 .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,"
8390 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
8391 new NHXParser() )[ 0 ];
8392 final Phylogeny gene8 = factory
8393 .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],"
8394 + "(((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],"
8395 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
8396 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
8397 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
8398 new NHXParser() )[ 0 ];
8399 species8.setRooted( true );
8400 gene8.setRooted( true );
8401 Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
8402 if ( sdi_unrooted.getCount() != 1 ) {
8405 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
8408 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
8411 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
8414 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
8417 if ( !p8[ 0 ].getRoot().isDuplication() ) {
8420 if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
8423 if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
8426 if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
8429 if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
8432 if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
8435 if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
8438 if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
8443 catch ( final Exception e ) {
8444 e.printStackTrace( System.out );
8450 private static boolean testSplit() {
8452 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8453 final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
8454 //Archaeopteryx.createApplication( p0 );
8455 final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
8456 ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8457 ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8458 ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8459 ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8460 ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8461 ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8462 ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8463 ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8464 ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8465 final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
8466 // System.out.println( s0.toString() );
8468 Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
8469 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8470 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8471 if ( s0.match( query_nodes ) ) {
8474 query_nodes = new HashSet<PhylogenyNode>();
8475 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8476 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8477 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8478 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8479 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8480 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8481 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8482 if ( !s0.match( query_nodes ) ) {
8486 query_nodes = new HashSet<PhylogenyNode>();
8487 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8488 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8489 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8490 if ( !s0.match( query_nodes ) ) {
8494 query_nodes = new HashSet<PhylogenyNode>();
8495 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8496 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8497 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8498 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8499 if ( !s0.match( query_nodes ) ) {
8503 query_nodes = new HashSet<PhylogenyNode>();
8504 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8505 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8506 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8507 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8508 if ( !s0.match( query_nodes ) ) {
8512 query_nodes = new HashSet<PhylogenyNode>();
8513 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8514 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8515 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
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 if ( !s0.match( query_nodes ) ) {
8527 query_nodes = new HashSet<PhylogenyNode>();
8528 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8529 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8530 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8531 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8532 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8533 if ( !s0.match( query_nodes ) ) {
8537 query_nodes = new HashSet<PhylogenyNode>();
8538 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8539 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8540 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8541 if ( !s0.match( query_nodes ) ) {
8545 query_nodes = new HashSet<PhylogenyNode>();
8546 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8547 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8548 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8549 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8550 if ( !s0.match( query_nodes ) ) {
8554 query_nodes = new HashSet<PhylogenyNode>();
8555 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8556 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8557 if ( s0.match( query_nodes ) ) {
8561 query_nodes = new HashSet<PhylogenyNode>();
8562 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8563 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8564 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8565 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8566 if ( s0.match( query_nodes ) ) {
8570 query_nodes = new HashSet<PhylogenyNode>();
8571 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8572 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8573 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8574 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8575 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
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( "B" ) );
8583 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
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( "D" ) );
8591 if ( s0.match( query_nodes ) ) {
8595 query_nodes = new HashSet<PhylogenyNode>();
8596 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8597 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8598 if ( s0.match( query_nodes ) ) {
8602 query_nodes = new HashSet<PhylogenyNode>();
8603 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8604 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8605 if ( s0.match( query_nodes ) ) {
8609 query_nodes = new HashSet<PhylogenyNode>();
8610 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8611 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8612 if ( s0.match( query_nodes ) ) {
8616 query_nodes = new HashSet<PhylogenyNode>();
8617 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8618 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8619 if ( s0.match( query_nodes ) ) {
8623 query_nodes = new HashSet<PhylogenyNode>();
8624 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8625 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8626 if ( s0.match( query_nodes ) ) {
8630 query_nodes = new HashSet<PhylogenyNode>();
8631 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8632 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8633 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8634 if ( s0.match( query_nodes ) ) {
8638 query_nodes = new HashSet<PhylogenyNode>();
8639 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8640 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8641 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8642 if ( s0.match( query_nodes ) ) {
8646 query_nodes = new HashSet<PhylogenyNode>();
8647 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8648 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8649 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8650 if ( s0.match( query_nodes ) ) {
8654 query_nodes = new HashSet<PhylogenyNode>();
8655 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8656 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8657 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8658 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8659 if ( s0.match( query_nodes ) ) {
8663 // query_nodes = new HashSet<PhylogenyNode>();
8664 // query_nodes.add( new PhylogenyNode( "X" ) );
8665 // query_nodes.add( new PhylogenyNode( "Y" ) );
8666 // query_nodes.add( new PhylogenyNode( "A" ) );
8667 // query_nodes.add( new PhylogenyNode( "B" ) );
8668 // query_nodes.add( new PhylogenyNode( "C" ) );
8669 // query_nodes.add( new PhylogenyNode( "D" ) );
8670 // query_nodes.add( new PhylogenyNode( "E" ) );
8671 // query_nodes.add( new PhylogenyNode( "F" ) );
8672 // query_nodes.add( new PhylogenyNode( "G" ) );
8673 // if ( !s0.match( query_nodes ) ) {
8676 // query_nodes = new HashSet<PhylogenyNode>();
8677 // query_nodes.add( new PhylogenyNode( "X" ) );
8678 // query_nodes.add( new PhylogenyNode( "Y" ) );
8679 // query_nodes.add( new PhylogenyNode( "A" ) );
8680 // query_nodes.add( new PhylogenyNode( "B" ) );
8681 // query_nodes.add( new PhylogenyNode( "C" ) );
8682 // if ( !s0.match( query_nodes ) ) {
8686 // query_nodes = new HashSet<PhylogenyNode>();
8687 // query_nodes.add( new PhylogenyNode( "X" ) );
8688 // query_nodes.add( new PhylogenyNode( "Y" ) );
8689 // query_nodes.add( new PhylogenyNode( "D" ) );
8690 // query_nodes.add( new PhylogenyNode( "E" ) );
8691 // query_nodes.add( new PhylogenyNode( "F" ) );
8692 // query_nodes.add( new PhylogenyNode( "G" ) );
8693 // if ( !s0.match( query_nodes ) ) {
8697 // query_nodes = new HashSet<PhylogenyNode>();
8698 // query_nodes.add( new PhylogenyNode( "X" ) );
8699 // query_nodes.add( new PhylogenyNode( "Y" ) );
8700 // query_nodes.add( new PhylogenyNode( "A" ) );
8701 // query_nodes.add( new PhylogenyNode( "B" ) );
8702 // query_nodes.add( new PhylogenyNode( "C" ) );
8703 // query_nodes.add( new PhylogenyNode( "D" ) );
8704 // if ( !s0.match( query_nodes ) ) {
8708 // query_nodes = new HashSet<PhylogenyNode>();
8709 // query_nodes.add( new PhylogenyNode( "X" ) );
8710 // query_nodes.add( new PhylogenyNode( "Y" ) );
8711 // query_nodes.add( new PhylogenyNode( "E" ) );
8712 // query_nodes.add( new PhylogenyNode( "F" ) );
8713 // query_nodes.add( new PhylogenyNode( "G" ) );
8714 // if ( !s0.match( query_nodes ) ) {
8718 // query_nodes = new HashSet<PhylogenyNode>();
8719 // query_nodes.add( new PhylogenyNode( "X" ) );
8720 // query_nodes.add( new PhylogenyNode( "Y" ) );
8721 // query_nodes.add( new PhylogenyNode( "F" ) );
8722 // query_nodes.add( new PhylogenyNode( "G" ) );
8723 // if ( !s0.match( query_nodes ) ) {
8727 query_nodes = new HashSet<PhylogenyNode>();
8728 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8729 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8730 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8731 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8732 if ( s0.match( query_nodes ) ) {
8736 query_nodes = new HashSet<PhylogenyNode>();
8737 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8738 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8739 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8740 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8741 if ( s0.match( query_nodes ) ) {
8744 ///////////////////////////
8746 query_nodes = new HashSet<PhylogenyNode>();
8747 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8748 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8749 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8750 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8751 if ( s0.match( query_nodes ) ) {
8755 query_nodes = new HashSet<PhylogenyNode>();
8756 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8757 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8758 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8759 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8760 if ( s0.match( query_nodes ) ) {
8764 query_nodes = new HashSet<PhylogenyNode>();
8765 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8766 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8767 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8768 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8769 if ( s0.match( query_nodes ) ) {
8773 query_nodes = new HashSet<PhylogenyNode>();
8774 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8775 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8776 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8777 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8778 if ( s0.match( query_nodes ) ) {
8782 query_nodes = new HashSet<PhylogenyNode>();
8783 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8784 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8785 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8786 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8787 if ( s0.match( query_nodes ) ) {
8791 query_nodes = new HashSet<PhylogenyNode>();
8792 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8793 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8794 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8795 if ( s0.match( query_nodes ) ) {
8799 query_nodes = new HashSet<PhylogenyNode>();
8800 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8801 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8802 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8803 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8804 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8805 if ( s0.match( query_nodes ) ) {
8809 query_nodes = new HashSet<PhylogenyNode>();
8810 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8811 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8812 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8813 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8814 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8815 if ( s0.match( query_nodes ) ) {
8819 query_nodes = new HashSet<PhylogenyNode>();
8820 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8821 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8822 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8823 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8824 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8825 if ( s0.match( query_nodes ) ) {
8829 query_nodes = new HashSet<PhylogenyNode>();
8830 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
8831 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
8832 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8833 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8834 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8835 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8836 if ( s0.match( query_nodes ) ) {
8840 catch ( final Exception e ) {
8841 e.printStackTrace();
8847 private static boolean testSplitStrict() {
8849 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8850 final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
8851 final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
8852 ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8853 ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8854 ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8855 ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8856 ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8857 ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8858 ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8859 final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
8860 Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
8861 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8862 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8863 if ( s0.match( query_nodes ) ) {
8866 query_nodes = new HashSet<PhylogenyNode>();
8867 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8868 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8869 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8870 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8871 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8872 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8873 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8874 if ( !s0.match( query_nodes ) ) {
8878 query_nodes = new HashSet<PhylogenyNode>();
8879 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8880 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8881 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8882 if ( !s0.match( query_nodes ) ) {
8886 query_nodes = new HashSet<PhylogenyNode>();
8887 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8888 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8889 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8890 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8891 if ( !s0.match( query_nodes ) ) {
8895 query_nodes = new HashSet<PhylogenyNode>();
8896 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8897 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8898 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8899 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8900 if ( !s0.match( query_nodes ) ) {
8904 query_nodes = new HashSet<PhylogenyNode>();
8905 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8906 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8907 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
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 if ( !s0.match( query_nodes ) ) {
8919 query_nodes = new HashSet<PhylogenyNode>();
8920 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8921 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8922 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8923 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8924 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8925 if ( !s0.match( query_nodes ) ) {
8929 query_nodes = new HashSet<PhylogenyNode>();
8930 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8931 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8932 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8933 if ( !s0.match( query_nodes ) ) {
8937 query_nodes = new HashSet<PhylogenyNode>();
8938 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8939 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8940 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8941 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8942 if ( !s0.match( query_nodes ) ) {
8946 query_nodes = new HashSet<PhylogenyNode>();
8947 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8948 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8949 if ( s0.match( query_nodes ) ) {
8953 query_nodes = new HashSet<PhylogenyNode>();
8954 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8955 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8956 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8957 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8958 if ( s0.match( query_nodes ) ) {
8962 query_nodes = new HashSet<PhylogenyNode>();
8963 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
8964 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
8965 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
8966 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
8967 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
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( "B" ) );
8975 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
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( "D" ) );
8983 if ( s0.match( query_nodes ) ) {
8987 query_nodes = new HashSet<PhylogenyNode>();
8988 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8989 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
8990 if ( s0.match( query_nodes ) ) {
8994 query_nodes = new HashSet<PhylogenyNode>();
8995 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
8996 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
8997 if ( s0.match( query_nodes ) ) {
9001 query_nodes = new HashSet<PhylogenyNode>();
9002 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9003 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9004 if ( s0.match( query_nodes ) ) {
9008 query_nodes = new HashSet<PhylogenyNode>();
9009 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9010 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9011 if ( s0.match( query_nodes ) ) {
9015 query_nodes = new HashSet<PhylogenyNode>();
9016 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9017 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9018 if ( s0.match( query_nodes ) ) {
9022 query_nodes = new HashSet<PhylogenyNode>();
9023 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9024 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
9025 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9026 if ( s0.match( query_nodes ) ) {
9030 query_nodes = new HashSet<PhylogenyNode>();
9031 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9032 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
9033 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9034 if ( s0.match( query_nodes ) ) {
9038 query_nodes = new HashSet<PhylogenyNode>();
9039 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9040 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9041 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9042 if ( s0.match( query_nodes ) ) {
9046 query_nodes = new HashSet<PhylogenyNode>();
9047 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
9048 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
9049 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
9050 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
9051 if ( s0.match( query_nodes ) ) {
9055 catch ( final Exception e ) {
9056 e.printStackTrace();
9062 private static boolean testSubtreeDeletion() {
9064 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9065 final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
9066 t1.deleteSubtree( t1.getNode( "A" ), false );
9067 if ( t1.getNumberOfExternalNodes() != 5 ) {
9070 t1.toNewHampshireX();
9071 t1.deleteSubtree( t1.getNode( "E" ), false );
9072 if ( t1.getNumberOfExternalNodes() != 4 ) {
9075 t1.toNewHampshireX();
9076 t1.deleteSubtree( t1.getNode( "F" ), false );
9077 if ( t1.getNumberOfExternalNodes() != 3 ) {
9080 t1.toNewHampshireX();
9081 t1.deleteSubtree( t1.getNode( "D" ), false );
9082 t1.toNewHampshireX();
9083 if ( t1.getNumberOfExternalNodes() != 3 ) {
9086 t1.deleteSubtree( t1.getNode( "def" ), false );
9087 t1.toNewHampshireX();
9088 if ( t1.getNumberOfExternalNodes() != 2 ) {
9091 t1.deleteSubtree( t1.getNode( "B" ), false );
9092 t1.toNewHampshireX();
9093 if ( t1.getNumberOfExternalNodes() != 1 ) {
9096 t1.deleteSubtree( t1.getNode( "C" ), false );
9097 t1.toNewHampshireX();
9098 if ( t1.getNumberOfExternalNodes() != 1 ) {
9101 t1.deleteSubtree( t1.getNode( "abc" ), false );
9102 t1.toNewHampshireX();
9103 if ( t1.getNumberOfExternalNodes() != 1 ) {
9106 t1.deleteSubtree( t1.getNode( "r" ), false );
9107 if ( t1.getNumberOfExternalNodes() != 0 ) {
9110 if ( !t1.isEmpty() ) {
9113 final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
9114 t2.deleteSubtree( t2.getNode( "A" ), false );
9115 t2.toNewHampshireX();
9116 if ( t2.getNumberOfExternalNodes() != 5 ) {
9119 t2.deleteSubtree( t2.getNode( "abc" ), false );
9120 t2.toNewHampshireX();
9121 if ( t2.getNumberOfExternalNodes() != 3 ) {
9124 t2.deleteSubtree( t2.getNode( "def" ), false );
9125 t2.toNewHampshireX();
9126 if ( t2.getNumberOfExternalNodes() != 1 ) {
9130 catch ( final Exception e ) {
9131 e.printStackTrace( System.out );
9137 private static boolean testSupportCount() {
9139 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9140 final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
9141 final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
9142 + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
9143 + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
9144 + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
9145 + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
9147 SupportCount.count( t0_1, phylogenies_1, true, false );
9148 final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
9149 final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
9150 + "(((((A,B),C),D),E),((F,G),X))"
9151 + "(((((A,Y),B),C),D),((F,G),E))"
9152 + "(((((A,B),C),D),E),(F,G))"
9153 + "(((((A,B),C),D),E),(F,G))"
9154 + "(((((A,B),C),D),E),(F,G))"
9155 + "(((((A,B),C),D),E),(F,G),Z)"
9156 + "(((((A,B),C),D),E),(F,G))"
9157 + "((((((A,B),C),D),E),F),G)"
9158 + "(((((X,Y),F,G),E),((A,B),C)),D)",
9160 SupportCount.count( t0_2, phylogenies_2, true, false );
9161 final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
9162 while ( it.hasNext() ) {
9163 final PhylogenyNode n = it.next();
9164 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
9168 final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
9169 final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
9170 + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
9171 SupportCount.count( t0_3, phylogenies_3, true, false );
9172 t0_3.reRoot( t0_3.getNode( "def" ).getId() );
9173 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
9176 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
9179 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
9182 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
9185 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
9188 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
9191 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
9194 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
9197 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
9200 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
9203 final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9204 final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
9205 + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
9206 SupportCount.count( t0_4, phylogenies_4, true, false );
9207 t0_4.reRoot( t0_4.getNode( "F" ).getId() );
9208 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
9211 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
9214 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
9217 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
9220 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
9223 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
9226 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
9229 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
9232 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
9235 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
9238 Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9239 final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9240 double d = SupportCount.compare( b1, a, true, true, true );
9241 if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
9244 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9245 final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9246 d = SupportCount.compare( b2, a, true, true, true );
9247 if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
9250 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
9251 final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
9252 d = SupportCount.compare( b3, a, true, true, true );
9253 if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
9256 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
9257 final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
9258 d = SupportCount.compare( b4, a, true, true, false );
9259 if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
9263 catch ( final Exception e ) {
9264 e.printStackTrace( System.out );
9270 private static boolean testSupportTransfer() {
9272 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9273 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)",
9274 new NHXParser() )[ 0 ];
9275 final Phylogeny p2 = factory
9276 .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 ];
9277 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
9280 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
9283 support_transfer.moveBranchLengthsToBootstrap( p1 );
9284 support_transfer.transferSupportValues( p1, p2 );
9285 if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
9288 if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
9291 if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
9294 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
9297 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
9300 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
9303 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
9306 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
9310 catch ( final Exception e ) {
9311 e.printStackTrace( System.out );
9317 private static boolean testUniprotTaxonomySearch() {
9319 List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
9321 if ( results.size() != 1 ) {
9324 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9327 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9330 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9333 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9336 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9340 results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
9341 if ( results.size() != 1 ) {
9344 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9347 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9350 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9353 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9356 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9360 results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
9361 if ( results.size() != 1 ) {
9364 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9367 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9370 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9373 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9376 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9380 results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
9381 if ( results.size() != 1 ) {
9384 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
9387 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
9390 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
9393 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
9396 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
9399 if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
9402 if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
9405 if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
9406 .equals( "Nematostella vectensis" ) ) {
9407 System.out.println( results.get( 0 ).getLineage() );
9411 catch ( final IOException e ) {
9412 System.out.println();
9413 System.out.println( "the following might be due to absence internet connection:" );
9414 e.printStackTrace( System.out );
9417 catch ( final Exception e ) {
9423 private static boolean testEmblEntryRetrieval() {
9424 //The format for GenBank Accession numbers are:
9425 //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
9426 //Protein: 3 letters + 5 numerals
9427 //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
9428 if ( !SequenceIdParser.parseGenbankAccessor( "AY423861" ).equals( "AY423861" ) ) {
9431 if ( !SequenceIdParser.parseGenbankAccessor( ".AY423861.2" ).equals( "AY423861.2" ) ) {
9434 if ( !SequenceIdParser.parseGenbankAccessor( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
9437 if ( SequenceIdParser.parseGenbankAccessor( "AAY423861" ) != null ) {
9440 if ( SequenceIdParser.parseGenbankAccessor( "AY4238612" ) != null ) {
9443 if ( SequenceIdParser.parseGenbankAccessor( "AAY4238612" ) != null ) {
9446 if ( SequenceIdParser.parseGenbankAccessor( "Y423861" ) != null ) {
9449 if ( !SequenceIdParser.parseGenbankAccessor( "S12345" ).equals( "S12345" ) ) {
9452 if ( !SequenceIdParser.parseGenbankAccessor( "|S12345|" ).equals( "S12345" ) ) {
9455 if ( SequenceIdParser.parseGenbankAccessor( "|S123456" ) != null ) {
9458 if ( SequenceIdParser.parseGenbankAccessor( "ABC123456" ) != null ) {
9461 if ( !SequenceIdParser.parseGenbankAccessor( "ABC12345" ).equals( "ABC12345" ) ) {
9464 if ( !SequenceIdParser.parseGenbankAccessor( "&ABC12345&" ).equals( "ABC12345" ) ) {
9467 if ( SequenceIdParser.parseGenbankAccessor( "ABCD12345" ) != null ) {
9473 private static boolean testUniprotEntryRetrieval() {
9475 final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
9476 if ( !entry.getAccession().equals( "P12345" ) ) {
9479 if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
9482 if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
9485 if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
9489 catch ( final IOException e ) {
9490 System.out.println();
9491 System.out.println( "the following might be due to absence internet connection:" );
9492 e.printStackTrace( System.out );
9495 catch ( final Exception e ) {
9501 private static boolean testWabiTxSearch() {
9504 result = TxSearch.searchSimple( "nematostella" );
9505 result = TxSearch.getTxId( "nematostella" );
9506 if ( !result.equals( "45350" ) ) {
9509 result = TxSearch.getTxName( "45350" );
9510 if ( !result.equals( "Nematostella" ) ) {
9513 result = TxSearch.getTxId( "nematostella vectensis" );
9514 if ( !result.equals( "45351" ) ) {
9517 result = TxSearch.getTxName( "45351" );
9518 if ( !result.equals( "Nematostella vectensis" ) ) {
9521 result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
9522 if ( !result.equals( "536089" ) ) {
9525 result = TxSearch.getTxName( "536089" );
9526 if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
9529 final List<String> queries = new ArrayList<String>();
9530 queries.add( "Campylobacter coli" );
9531 queries.add( "Escherichia coli" );
9532 queries.add( "Arabidopsis" );
9533 queries.add( "Trichoplax" );
9534 queries.add( "Samanea saman" );
9535 queries.add( "Kluyveromyces marxianus" );
9536 queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
9537 queries.add( "Bornavirus parrot/PDD/2008" );
9538 final List<RANKS> ranks = new ArrayList<RANKS>();
9539 ranks.add( RANKS.SUPERKINGDOM );
9540 ranks.add( RANKS.KINGDOM );
9541 ranks.add( RANKS.FAMILY );
9542 ranks.add( RANKS.GENUS );
9543 ranks.add( RANKS.TRIBE );
9544 result = TxSearch.searchLineage( queries, ranks );
9545 result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
9546 result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
9548 catch ( final Exception e ) {
9549 System.out.println();
9550 System.out.println( "the following might be due to absence internet connection:" );
9551 e.printStackTrace( System.out );
9557 private static boolean testAminoAcidSequence() {
9559 final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
9560 if ( aa1.getLength() != 13 ) {
9563 if ( aa1.getResidueAt( 0 ) != 'A' ) {
9566 if ( aa1.getResidueAt( 2 ) != 'K' ) {
9569 if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
9572 final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
9573 if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
9576 final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
9577 if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
9580 final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
9581 if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
9585 catch ( final Exception e ) {
9586 e.printStackTrace();
9592 private static boolean testSequenceWriter() {
9594 final String n = ForesterUtil.LINE_SEPARATOR;
9595 if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
9598 if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
9601 if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
9604 if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
9607 if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
9608 .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
9611 if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
9612 .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
9616 catch ( final Exception e ) {
9617 e.printStackTrace();
9623 private static boolean testCreateBalancedPhylogeny() {
9625 final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
9626 if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
9629 if ( p0.getNumberOfExternalNodes() != 15625 ) {
9632 final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
9633 if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
9636 if ( p1.getNumberOfExternalNodes() != 100 ) {
9640 catch ( final Exception e ) {
9641 e.printStackTrace();
9647 private static boolean testFastaParser() {
9649 if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
9652 if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
9655 final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
9656 if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
9659 if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
9662 if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
9665 if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
9668 if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
9671 if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
9675 catch ( final Exception e ) {
9676 e.printStackTrace();
9682 private static boolean testGeneralMsaParser() {
9684 final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
9685 final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
9686 final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
9687 final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
9688 final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
9689 final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
9690 final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
9691 final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
9692 if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9695 if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9698 if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9701 if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9704 if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9707 if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9710 if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9713 if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9716 if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
9719 if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
9722 if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
9725 if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
9728 final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
9729 if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
9732 if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
9735 if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
9738 final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
9739 if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
9742 if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
9745 if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
9748 final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
9749 if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
9752 if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
9755 if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
9759 catch ( final Exception e ) {
9760 e.printStackTrace();
9766 private static boolean testMafft( final String path ) {
9768 final List<String> opts = new ArrayList<String>();
9769 opts.add( "--maxiterate" );
9771 opts.add( "--localpair" );
9772 opts.add( "--quiet" );
9774 final MsaInferrer mafft = Mafft.createInstance( path );
9775 msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
9776 if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
9779 if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
9783 catch ( final Exception e ) {
9784 e.printStackTrace( System.out );
9790 private static boolean testNextNodeWithCollapsing() {
9792 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9794 List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
9795 final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9796 final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
9797 t0.getNode( "cd" ).setCollapse( true );
9798 t0.getNode( "cde" ).setCollapse( true );
9799 n = t0.getFirstExternalNode();
9800 while ( n != null ) {
9802 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9804 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
9807 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
9810 if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
9813 if ( !ext.get( 3 ).getName().equals( "f" ) ) {
9816 if ( !ext.get( 4 ).getName().equals( "g" ) ) {
9819 if ( !ext.get( 5 ).getName().equals( "h" ) ) {
9823 final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9824 final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
9825 t1.getNode( "ab" ).setCollapse( true );
9826 t1.getNode( "cd" ).setCollapse( true );
9827 t1.getNode( "cde" ).setCollapse( true );
9828 n = t1.getNode( "ab" );
9829 ext = new ArrayList<PhylogenyNode>();
9830 while ( n != null ) {
9832 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9834 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9837 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9840 if ( !ext.get( 2 ).getName().equals( "f" ) ) {
9843 if ( !ext.get( 3 ).getName().equals( "g" ) ) {
9846 if ( !ext.get( 4 ).getName().equals( "h" ) ) {
9852 final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9853 final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
9854 t2.getNode( "ab" ).setCollapse( true );
9855 t2.getNode( "cd" ).setCollapse( true );
9856 t2.getNode( "cde" ).setCollapse( true );
9857 t2.getNode( "c" ).setCollapse( true );
9858 t2.getNode( "d" ).setCollapse( true );
9859 t2.getNode( "e" ).setCollapse( true );
9860 t2.getNode( "gh" ).setCollapse( true );
9861 n = t2.getNode( "ab" );
9862 ext = new ArrayList<PhylogenyNode>();
9863 while ( n != null ) {
9865 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9867 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9870 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9873 if ( !ext.get( 2 ).getName().equals( "f" ) ) {
9876 if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
9882 final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9883 final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
9884 t3.getNode( "ab" ).setCollapse( true );
9885 t3.getNode( "cd" ).setCollapse( true );
9886 t3.getNode( "cde" ).setCollapse( true );
9887 t3.getNode( "c" ).setCollapse( true );
9888 t3.getNode( "d" ).setCollapse( true );
9889 t3.getNode( "e" ).setCollapse( true );
9890 t3.getNode( "gh" ).setCollapse( true );
9891 t3.getNode( "fgh" ).setCollapse( true );
9892 n = t3.getNode( "ab" );
9893 ext = new ArrayList<PhylogenyNode>();
9894 while ( n != null ) {
9896 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9898 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9901 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
9904 if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
9910 final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
9911 final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
9912 t4.getNode( "ab" ).setCollapse( true );
9913 t4.getNode( "cd" ).setCollapse( true );
9914 t4.getNode( "cde" ).setCollapse( true );
9915 t4.getNode( "c" ).setCollapse( true );
9916 t4.getNode( "d" ).setCollapse( true );
9917 t4.getNode( "e" ).setCollapse( true );
9918 t4.getNode( "gh" ).setCollapse( true );
9919 t4.getNode( "fgh" ).setCollapse( true );
9920 t4.getNode( "abcdefgh" ).setCollapse( true );
9921 n = t4.getNode( "abcdefgh" );
9922 if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
9927 final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9928 final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
9930 n = t5.getFirstExternalNode();
9931 while ( n != null ) {
9933 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9935 if ( ext.size() != 8 ) {
9938 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
9941 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
9944 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
9947 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
9950 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
9953 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
9956 if ( !ext.get( 6 ).getName().equals( "g" ) ) {
9959 if ( !ext.get( 7 ).getName().equals( "h" ) ) {
9964 final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
9965 final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
9967 t6.getNode( "ab" ).setCollapse( true );
9968 n = t6.getNode( "ab" );
9969 while ( n != null ) {
9971 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
9973 if ( ext.size() != 7 ) {
9976 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
9979 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
9982 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
9985 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
9988 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
9991 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
9994 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
9999 final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
10000 final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
10002 t7.getNode( "cd" ).setCollapse( true );
10003 n = t7.getNode( "a" );
10004 while ( n != null ) {
10006 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10008 if ( ext.size() != 7 ) {
10011 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10014 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10017 if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
10020 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10023 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
10026 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
10029 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
10034 final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
10035 final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
10037 t8.getNode( "cd" ).setCollapse( true );
10038 t8.getNode( "c" ).setCollapse( true );
10039 t8.getNode( "d" ).setCollapse( true );
10040 n = t8.getNode( "a" );
10041 while ( n != null ) {
10043 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10045 if ( ext.size() != 7 ) {
10048 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10051 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10054 if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
10055 System.out.println( "2 fail" );
10058 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10061 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
10064 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
10067 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
10072 final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10073 final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
10075 t9.getNode( "gh" ).setCollapse( true );
10076 n = t9.getNode( "a" );
10077 while ( n != null ) {
10079 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10081 if ( ext.size() != 7 ) {
10084 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10087 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10090 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10093 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10096 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10099 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
10102 if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
10107 final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10108 final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
10110 t10.getNode( "gh" ).setCollapse( true );
10111 t10.getNode( "g" ).setCollapse( true );
10112 t10.getNode( "h" ).setCollapse( true );
10113 n = t10.getNode( "a" );
10114 while ( n != null ) {
10116 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10118 if ( ext.size() != 7 ) {
10121 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10124 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10127 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10130 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10133 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10136 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
10139 if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
10144 final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10145 final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
10147 t11.getNode( "gh" ).setCollapse( true );
10148 t11.getNode( "fgh" ).setCollapse( true );
10149 n = t11.getNode( "a" );
10150 while ( n != null ) {
10152 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10154 if ( ext.size() != 6 ) {
10157 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10160 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10163 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10166 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10169 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10172 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10177 final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10178 final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
10180 t12.getNode( "gh" ).setCollapse( true );
10181 t12.getNode( "fgh" ).setCollapse( true );
10182 t12.getNode( "g" ).setCollapse( true );
10183 t12.getNode( "h" ).setCollapse( true );
10184 t12.getNode( "f" ).setCollapse( true );
10185 n = t12.getNode( "a" );
10186 while ( n != null ) {
10188 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10190 if ( ext.size() != 6 ) {
10193 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
10196 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
10199 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
10202 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
10205 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
10208 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10213 final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
10214 final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
10216 t13.getNode( "ab" ).setCollapse( true );
10217 t13.getNode( "b" ).setCollapse( true );
10218 t13.getNode( "fgh" ).setCollapse( true );
10219 t13.getNode( "gh" ).setCollapse( true );
10220 n = t13.getNode( "ab" );
10221 while ( n != null ) {
10223 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10225 if ( ext.size() != 5 ) {
10228 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10231 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10234 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10237 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10240 if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
10245 final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
10246 final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
10248 t14.getNode( "ab" ).setCollapse( true );
10249 t14.getNode( "a" ).setCollapse( true );
10250 t14.getNode( "fgh" ).setCollapse( true );
10251 t14.getNode( "gh" ).setCollapse( true );
10252 n = t14.getNode( "ab" );
10253 while ( n != null ) {
10255 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10257 if ( ext.size() != 5 ) {
10260 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10263 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10266 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10269 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10272 if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
10277 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" );
10278 final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
10280 t15.getNode( "ab" ).setCollapse( true );
10281 t15.getNode( "a" ).setCollapse( true );
10282 t15.getNode( "fgh" ).setCollapse( true );
10283 t15.getNode( "gh" ).setCollapse( true );
10284 n = t15.getNode( "ab" );
10285 while ( n != null ) {
10287 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10289 if ( ext.size() != 6 ) {
10292 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10295 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
10298 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
10301 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
10304 if ( !ext.get( 4 ).getName().equals( "x" ) ) {
10307 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
10312 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" );
10313 final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
10315 t16.getNode( "ab" ).setCollapse( true );
10316 t16.getNode( "a" ).setCollapse( true );
10317 t16.getNode( "fgh" ).setCollapse( true );
10318 t16.getNode( "gh" ).setCollapse( true );
10319 t16.getNode( "cd" ).setCollapse( true );
10320 t16.getNode( "cde" ).setCollapse( true );
10321 t16.getNode( "d" ).setCollapse( true );
10322 t16.getNode( "x" ).setCollapse( true );
10323 n = t16.getNode( "ab" );
10324 while ( n != null ) {
10326 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
10328 if ( ext.size() != 4 ) {
10331 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
10334 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
10337 if ( !ext.get( 2 ).getName().equals( "x" ) ) {
10340 if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
10344 catch ( final Exception e ) {
10345 e.printStackTrace( System.out );
10351 private static boolean testMsaQualityMethod() {
10353 final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
10354 final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
10355 final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
10356 final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
10357 final List<Sequence> l = new ArrayList<Sequence>();
10362 final Msa msa = BasicMsa.createInstance( l );
10363 if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
10366 if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
10369 if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
10372 if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
10376 catch ( final Exception e ) {
10377 e.printStackTrace( System.out );
10383 private static boolean testSequenceIdParsing() {
10385 Identifier id = SequenceIdParser.parse( "gb_ADF31344_segmented_worms_" );
10386 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10387 || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
10388 if ( id != null ) {
10389 System.out.println( "value =" + id.getValue() );
10390 System.out.println( "provider=" + id.getProvider() );
10395 id = SequenceIdParser.parse( "segmented worms|gb_ADF31344" );
10396 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10397 || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
10398 if ( id != null ) {
10399 System.out.println( "value =" + id.getValue() );
10400 System.out.println( "provider=" + id.getProvider() );
10405 id = SequenceIdParser.parse( "segmented worms gb_ADF31344 and more" );
10406 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10407 || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
10408 if ( id != null ) {
10409 System.out.println( "value =" + id.getValue() );
10410 System.out.println( "provider=" + id.getProvider() );
10415 id = SequenceIdParser.parse( "gb_AAA96518_1" );
10416 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10417 || !id.getValue().equals( "AAA96518" ) || !id.getProvider().equals( "ncbi" ) ) {
10418 if ( id != null ) {
10419 System.out.println( "value =" + id.getValue() );
10420 System.out.println( "provider=" + id.getProvider() );
10425 id = SequenceIdParser.parse( "gb_EHB07727_1_rodents_" );
10426 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10427 || !id.getValue().equals( "EHB07727" ) || !id.getProvider().equals( "ncbi" ) ) {
10428 if ( id != null ) {
10429 System.out.println( "value =" + id.getValue() );
10430 System.out.println( "provider=" + id.getProvider() );
10435 id = SequenceIdParser.parse( "dbj_BAF37827_1_turtles_" );
10436 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10437 || !id.getValue().equals( "BAF37827" ) || !id.getProvider().equals( "ncbi" ) ) {
10438 if ( id != null ) {
10439 System.out.println( "value =" + id.getValue() );
10440 System.out.println( "provider=" + id.getProvider() );
10445 id = SequenceIdParser.parse( "emb_CAA73223_1_primates_" );
10446 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10447 || !id.getValue().equals( "CAA73223" ) || !id.getProvider().equals( "ncbi" ) ) {
10448 if ( id != null ) {
10449 System.out.println( "value =" + id.getValue() );
10450 System.out.println( "provider=" + id.getProvider() );
10455 id = SequenceIdParser.parse( "mites|ref_XP_002434188_1" );
10456 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10457 || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
10458 if ( id != null ) {
10459 System.out.println( "value =" + id.getValue() );
10460 System.out.println( "provider=" + id.getProvider() );
10465 id = SequenceIdParser.parse( "mites_ref_XP_002434188_1_bla_XP_12345" );
10466 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10467 || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
10468 if ( id != null ) {
10469 System.out.println( "value =" + id.getValue() );
10470 System.out.println( "provider=" + id.getProvider() );
10475 id = SequenceIdParser.parse( "P4A123" );
10476 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10477 || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
10478 if ( id != null ) {
10479 System.out.println( "value =" + id.getValue() );
10480 System.out.println( "provider=" + id.getProvider() );
10485 id = SequenceIdParser.parse( "pllf[pok P4A123_osdjfosnqo035-9233332904i000490 vf tmv x45" );
10486 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
10487 || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
10488 if ( id != null ) {
10489 System.out.println( "value =" + id.getValue() );
10490 System.out.println( "provider=" + id.getProvider() );
10495 id = SequenceIdParser.parse( "XP_12345" );
10496 if ( id != null ) {
10497 System.out.println( "value =" + id.getValue() );
10498 System.out.println( "provider=" + id.getProvider() );
10501 // lcl_91970_unknown_
10503 catch ( final Exception e ) {
10504 e.printStackTrace( System.out );