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: www.phylosoft.org/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.datastructures.IntMatrix;
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.phyloxml.PhyloXmlParser;
56 import org.forester.io.parsers.tol.TolParser;
57 import org.forester.io.writers.PhylogenyWriter;
58 import org.forester.msa.BasicMsa;
59 import org.forester.msa.Mafft;
60 import org.forester.msa.Msa;
61 import org.forester.msa.MsaInferrer;
62 import org.forester.msa.MsaMethods;
63 import org.forester.pccx.TestPccx;
64 import org.forester.phylogeny.Phylogeny;
65 import org.forester.phylogeny.PhylogenyBranch;
66 import org.forester.phylogeny.PhylogenyMethods;
67 import org.forester.phylogeny.PhylogenyMethods.TAXONOMY_EXTRACTION;
68 import org.forester.phylogeny.PhylogenyNode;
69 import org.forester.phylogeny.PhylogenyNodeI.NH_CONVERSION_SUPPORT_VALUE_STYLE;
70 import org.forester.phylogeny.data.BinaryCharacters;
71 import org.forester.phylogeny.data.BranchWidth;
72 import org.forester.phylogeny.data.Confidence;
73 import org.forester.phylogeny.data.Distribution;
74 import org.forester.phylogeny.data.DomainArchitecture;
75 import org.forester.phylogeny.data.Event;
76 import org.forester.phylogeny.data.Identifier;
77 import org.forester.phylogeny.data.PhylogenyData;
78 import org.forester.phylogeny.data.PhylogenyDataUtil;
79 import org.forester.phylogeny.data.Polygon;
80 import org.forester.phylogeny.data.PropertiesMap;
81 import org.forester.phylogeny.data.Property;
82 import org.forester.phylogeny.data.Property.AppliesTo;
83 import org.forester.phylogeny.data.ProteinDomain;
84 import org.forester.phylogeny.data.Taxonomy;
85 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
86 import org.forester.phylogeny.factories.PhylogenyFactory;
87 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
88 import org.forester.protein.Protein;
89 import org.forester.sdi.GSDI;
90 import org.forester.sdi.RIO;
91 import org.forester.sdi.SDI;
92 import org.forester.sdi.SDIR;
93 import org.forester.sdi.SDIse;
94 import org.forester.sdi.TestGSDI;
95 import org.forester.sequence.BasicSequence;
96 import org.forester.sequence.Sequence;
97 import org.forester.surfacing.TestSurfacing;
98 import org.forester.tools.ConfidenceAssessor;
99 import org.forester.tools.SupportCount;
100 import org.forester.tools.TreeSplitMatrix;
101 import org.forester.util.AsciiHistogram;
102 import org.forester.util.BasicDescriptiveStatistics;
103 import org.forester.util.BasicTable;
104 import org.forester.util.BasicTableParser;
105 import org.forester.util.DescriptiveStatistics;
106 import org.forester.util.ForesterConstants;
107 import org.forester.util.ForesterUtil;
108 import org.forester.util.GeneralTable;
109 import org.forester.util.SequenceIdParser;
110 import org.forester.ws.seqdb.SequenceDatabaseEntry;
111 import org.forester.ws.seqdb.SequenceDbWsTools;
112 import org.forester.ws.seqdb.UniProtTaxonomy;
113 import org.forester.ws.wabi.TxSearch;
114 import org.forester.ws.wabi.TxSearch.RANKS;
115 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
116 import org.forester.ws.wabi.TxSearch.TAX_RANK;
118 @SuppressWarnings( "unused")
119 public final class Test {
121 private final static double ZERO_DIFF = 1.0E-9;
122 private final static String PATH_TO_TEST_DATA = System.getProperty( "user.dir" )
123 + ForesterUtil.getFileSeparator() + "test_data"
124 + ForesterUtil.getFileSeparator();
125 private final static String PATH_TO_RESOURCES = System.getProperty( "user.dir" )
126 + ForesterUtil.getFileSeparator() + "resources"
127 + ForesterUtil.getFileSeparator();
128 private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
129 private static final String PHYLOXML_REMOTE_XSD = ForesterConstants.PHYLO_XML_LOCATION + "/"
130 + ForesterConstants.PHYLO_XML_VERSION + "/"
131 + ForesterConstants.PHYLO_XML_XSD;
132 private static final String PHYLOXML_LOCAL_XSD = PATH_TO_RESOURCES + "phyloxml_schema/"
133 + ForesterConstants.PHYLO_XML_VERSION + "/"
134 + ForesterConstants.PHYLO_XML_XSD;
136 private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
137 final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
141 private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
142 final PhylogenyMethods pm = PhylogenyMethods.getInstance();
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 id parsing: " );
178 if ( testSequenceIdParsing() ) {
179 System.out.println( "OK." );
183 System.out.println( "failed." );
184 System.exit( -1 ); //TODO FIXME remove me!! ~
187 System.out.print( "Hmmscan output parser: " );
188 if ( testHmmscanOutputParser() ) {
189 System.out.println( "OK." );
193 System.out.println( "failed." );
196 System.out.print( "Basic node methods: " );
197 if ( Test.testBasicNodeMethods() ) {
198 System.out.println( "OK." );
202 System.out.println( "failed." );
205 System.out.print( "Basic node construction and parsing of NHX (node level): " );
206 if ( Test.testNHXNodeParsing() ) {
207 System.out.println( "OK." );
211 System.out.println( "failed." );
214 System.out.print( "NH parsing: " );
215 if ( Test.testNHParsing() ) {
216 System.out.println( "OK." );
220 System.out.println( "failed." );
223 System.out.print( "Conversion to NHX (node level): " );
224 if ( Test.testNHXconversion() ) {
225 System.out.println( "OK." );
229 System.out.println( "failed." );
232 System.out.print( "NHX parsing: " );
233 if ( Test.testNHXParsing() ) {
234 System.out.println( "OK." );
238 System.out.println( "failed." );
241 System.out.print( "NHX parsing with quotes: " );
242 if ( Test.testNHXParsingQuotes() ) {
243 System.out.println( "OK." );
247 System.out.println( "failed." );
250 System.out.print( "NHX parsing (MrBayes): " );
251 if ( Test.testNHXParsingMB() ) {
252 System.out.println( "OK." );
256 System.out.println( "failed." );
259 System.out.print( "Nexus characters parsing: " );
260 if ( Test.testNexusCharactersParsing() ) {
261 System.out.println( "OK." );
265 System.out.println( "failed." );
268 System.out.print( "Nexus tree parsing: " );
269 if ( Test.testNexusTreeParsing() ) {
270 System.out.println( "OK." );
274 System.out.println( "failed." );
277 System.out.print( "Nexus tree parsing (translating): " );
278 if ( Test.testNexusTreeParsingTranslating() ) {
279 System.out.println( "OK." );
283 System.out.println( "failed." );
286 System.out.print( "Nexus matrix parsing: " );
287 if ( Test.testNexusMatrixParsing() ) {
288 System.out.println( "OK." );
292 System.out.println( "failed." );
295 System.out.print( "Basic phyloXML parsing: " );
296 if ( Test.testBasicPhyloXMLparsing() ) {
297 System.out.println( "OK." );
301 System.out.println( "failed." );
304 System.out.print( "Basic phyloXML parsing (validating against schema): " );
305 if ( testBasicPhyloXMLparsingValidating() ) {
306 System.out.println( "OK." );
310 System.out.println( "failed." );
313 System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
314 if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
315 System.out.println( "OK." );
319 System.out.println( "failed." );
322 System.out.print( "phyloXML Distribution Element: " );
323 if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
324 System.out.println( "OK." );
328 System.out.println( "failed." );
331 System.out.print( "Tol XML parsing: " );
332 if ( Test.testBasicTolXMLparsing() ) {
333 System.out.println( "OK." );
337 System.out.println( "failed." );
340 System.out.print( "Copying of node data: " );
341 if ( Test.testCopyOfNodeData() ) {
342 System.out.println( "OK." );
346 System.out.println( "failed." );
349 System.out.print( "Basic tree methods: " );
350 if ( Test.testBasicTreeMethods() ) {
351 System.out.println( "OK." );
355 System.out.println( "failed." );
358 System.out.print( "Postorder Iterator: " );
359 if ( Test.testPostOrderIterator() ) {
360 System.out.println( "OK." );
364 System.out.println( "failed." );
367 System.out.print( "Preorder Iterator: " );
368 if ( Test.testPreOrderIterator() ) {
369 System.out.println( "OK." );
373 System.out.println( "failed." );
376 System.out.print( "Levelorder Iterator: " );
377 if ( Test.testLevelOrderIterator() ) {
378 System.out.println( "OK." );
382 System.out.println( "failed." );
385 System.out.print( "Re-id methods: " );
386 if ( Test.testReIdMethods() ) {
387 System.out.println( "OK." );
391 System.out.println( "failed." );
394 System.out.print( "Methods on last external nodes: " );
395 if ( Test.testLastExternalNodeMethods() ) {
396 System.out.println( "OK." );
400 System.out.println( "failed." );
403 System.out.print( "Methods on external nodes: " );
404 if ( Test.testExternalNodeRelatedMethods() ) {
405 System.out.println( "OK." );
409 System.out.println( "failed." );
412 System.out.print( "Deletion of external nodes: " );
413 if ( Test.testDeletionOfExternalNodes() ) {
414 System.out.println( "OK." );
418 System.out.println( "failed." );
421 System.out.print( "Subtree deletion: " );
422 if ( Test.testSubtreeDeletion() ) {
423 System.out.println( "OK." );
427 System.out.println( "failed." );
430 System.out.print( "Phylogeny branch: " );
431 if ( Test.testPhylogenyBranch() ) {
432 System.out.println( "OK." );
436 System.out.println( "failed." );
439 System.out.print( "Rerooting: " );
440 if ( Test.testRerooting() ) {
441 System.out.println( "OK." );
445 System.out.println( "failed." );
448 System.out.print( "Mipoint rooting: " );
449 if ( Test.testMidpointrooting() ) {
450 System.out.println( "OK." );
454 System.out.println( "failed." );
457 System.out.print( "Support count: " );
458 if ( Test.testSupportCount() ) {
459 System.out.println( "OK." );
463 System.out.println( "failed." );
466 System.out.print( "Support transfer: " );
467 if ( Test.testSupportTransfer() ) {
468 System.out.println( "OK." );
472 System.out.println( "failed." );
475 System.out.print( "Finding of LCA: " );
476 if ( Test.testGetLCA() ) {
477 System.out.println( "OK." );
481 System.out.println( "failed." );
484 System.out.print( "Finding of LCA 2: " );
485 if ( Test.testGetLCA2() ) {
486 System.out.println( "OK." );
490 System.out.println( "failed." );
493 System.out.print( "Calculation of distance between nodes: " );
494 if ( Test.testGetDistance() ) {
495 System.out.println( "OK." );
499 System.out.println( "failed." );
502 System.out.print( "SDIse: " );
503 if ( Test.testSDIse() ) {
504 System.out.println( "OK." );
508 System.out.println( "failed." );
511 System.out.print( "SDIunrooted: " );
512 if ( Test.testSDIunrooted() ) {
513 System.out.println( "OK." );
517 System.out.println( "failed." );
520 System.out.print( "GSDI: " );
521 if ( TestGSDI.test() ) {
522 System.out.println( "OK." );
526 System.out.println( "failed." );
529 System.out.print( "Ortholog table: " );
530 if ( Test.testOrthologTable() ) {
531 System.out.println( "OK." );
535 System.out.println( "failed." );
538 System.out.print( "Descriptive statistics: " );
539 if ( Test.testDescriptiveStatistics() ) {
540 System.out.println( "OK." );
544 System.out.println( "failed." );
547 System.out.print( "Data objects and methods: " );
548 if ( Test.testDataObjects() ) {
549 System.out.println( "OK." );
553 System.out.println( "failed." );
556 System.out.print( "Properties map: " );
557 if ( Test.testPropertiesMap() ) {
558 System.out.println( "OK." );
562 System.out.println( "failed." );
565 System.out.print( "Phylogeny reconstruction:" );
566 System.out.println();
567 if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
568 System.out.println( "OK." );
572 System.out.println( "failed." );
575 System.out.print( "Analysis of domain architectures: " );
576 System.out.println();
577 if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
578 System.out.println( "OK." );
582 System.out.println( "failed." );
585 System.out.print( "GO: " );
586 System.out.println();
587 if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
588 System.out.println( "OK." );
592 System.out.println( "failed." );
595 System.out.print( "Modeling tools: " );
596 if ( TestPccx.test() ) {
597 System.out.println( "OK." );
601 System.out.println( "failed." );
604 System.out.print( "Split Matrix strict: " );
605 if ( Test.testSplitStrict() ) {
606 System.out.println( "OK." );
610 System.out.println( "failed." );
613 System.out.print( "Split Matrix: " );
614 if ( Test.testSplit() ) {
615 System.out.println( "OK." );
619 System.out.println( "failed." );
622 System.out.print( "Confidence Assessor: " );
623 if ( Test.testConfidenceAssessor() ) {
624 System.out.println( "OK." );
628 System.out.println( "failed." );
631 System.out.print( "Basic table: " );
632 if ( Test.testBasicTable() ) {
633 System.out.println( "OK." );
637 System.out.println( "failed." );
640 System.out.print( "General table: " );
641 if ( Test.testGeneralTable() ) {
642 System.out.println( "OK." );
646 System.out.println( "failed." );
649 System.out.print( "Amino acid sequence: " );
650 if ( Test.testAminoAcidSequence() ) {
651 System.out.println( "OK." );
655 System.out.println( "failed." );
658 System.out.print( "General MSA parser: " );
659 if ( Test.testGeneralMsaParser() ) {
660 System.out.println( "OK." );
664 System.out.println( "failed." );
667 System.out.print( "Fasta parser for msa: " );
668 if ( Test.testFastaParser() ) {
669 System.out.println( "OK." );
673 System.out.println( "failed." );
676 System.out.print( "Creation of balanced phylogeny: " );
677 if ( Test.testCreateBalancedPhylogeny() ) {
678 System.out.println( "OK." );
682 System.out.println( "failed." );
685 System.out.print( "EMBL Entry Retrieval: " );
686 if ( Test.testEmblEntryRetrieval() ) {
687 System.out.println( "OK." );
691 System.out.println( "failed." );
694 System.out.print( "Uniprot Entry Retrieval: " );
695 if ( Test.testUniprotEntryRetrieval() ) {
696 System.out.println( "OK." );
700 System.out.println( "failed." );
703 System.out.print( "Uniprot Taxonomy Search: " );
704 if ( Test.testUniprotTaxonomySearch() ) {
705 System.out.println( "OK." );
709 System.out.println( "failed." );
714 final String os = ForesterUtil.OS_NAME.toLowerCase();
715 if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
716 path = "/usr/local/bin/mafft";
718 else if ( os.indexOf( "win" ) >= 0 ) {
719 path = "C:\\Program Files\\mafft-win\\mafft.bat";
722 path = "/home/czmasek/bin/mafft";
724 if ( !MsaInferrer.isInstalled( path ) ) {
727 if ( !MsaInferrer.isInstalled( path ) ) {
728 path = "/usr/local/bin/mafft";
730 if ( MsaInferrer.isInstalled( path ) ) {
731 System.out.print( "MAFFT (external program): " );
732 if ( Test.testMafft( path ) ) {
733 System.out.println( "OK." );
737 System.out.println( "failed [will not count towards failed tests]" );
741 System.out.print( "Next nodes with collapsed: " );
742 if ( Test.testNextNodeWithCollapsing() ) {
743 System.out.println( "OK." );
747 System.out.println( "failed." );
750 System.out.print( "Simple MSA quality: " );
751 if ( Test.testMsaQualityMethod() ) {
752 System.out.println( "OK." );
756 System.out.println( "failed." );
759 // System.out.print( "WABI TxSearch: " );
760 // if ( Test.testWabiTxSearch() ) {
761 // System.out.println( "OK." );
766 // .println( "failed [will not count towards failed tests since it might be due to absence internet connection]" );
768 System.out.println();
769 final Runtime rt = java.lang.Runtime.getRuntime();
770 final long free_memory = rt.freeMemory() / 1000000;
771 final long total_memory = rt.totalMemory() / 1000000;
772 System.out.println( "Running time : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
773 + free_memory + "MB, total memory: " + total_memory + "MB)" );
774 System.out.println();
775 System.out.println( "Successful tests: " + succeeded );
776 System.out.println( "Failed tests: " + failed );
777 System.out.println();
779 System.out.println( "OK." );
782 System.out.println( "Not OK." );
784 // System.out.println();
785 // Development.setTime( true );
787 // final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
788 // final String clc = System.getProperty( "user.dir" ) + ForesterUtil.getFileSeparator()
789 // + "examples" + ForesterUtil.getFileSeparator() + "CLC.nhx";
790 // final String multi = Test.PATH_TO_EXAMPLE_FILES +
791 // "multifurcations_ex_1.nhx";
792 // final String domains = Test.PATH_TO_EXAMPLE_FILES + "domains1.nhx";
793 // final Phylogeny t1 = factory.create( new File( domains ), new
794 // NHXParser() )[ 0 ];
795 // final Phylogeny t2 = factory.create( new File( clc ), new NHXParser() )[ 0 ];
797 // catch ( final Exception e ) {
798 // e.printStackTrace();
800 // t1.getRoot().preorderPrint();
801 // final PhylogenyFactory factory = ParserBasedPhylogenyFactory
805 // Helper.readNHtree( new File( PATH_TO_EXAMPLE_FILES
806 // + "\\AtNBSpos.nhx" ) );
808 // new File( PATH_TO_EXAMPLE_FILES + "\\AtNBSpos.nhx" ),
809 // new NHXParser() );
810 // Helper.readNHtree( new File( PATH_TO_EXAMPLE_FILES
811 // + "\\AtNBSpos.nhx" ) );
813 // new File( PATH_TO_EXAMPLE_FILES + "\\AtNBSpos.nhx" ),
814 // new NHXParser() );
817 // Helper.readNHtree( new File( PATH_TO_EXAMPLE_FILES
818 // + "\\big_tree.nhx" ) );
819 // Helper.readNHtree( new File( PATH_TO_EXAMPLE_FILES
820 // + "\\big_tree.nhx" ) );
822 // new File( PATH_TO_EXAMPLE_FILES + "\\big_tree.nhx" ),
823 // new NHXParser() );
825 // new File( PATH_TO_EXAMPLE_FILES + "\\big_tree.nhx" ),
826 // new NHXParser() );
828 // Helper.readNHtree( new File( PATH_TO_EXAMPLE_FILES
829 // + "\\big_tree.nhx" ) );
830 // Helper.readNHtree( new File( PATH_TO_EXAMPLE_FILES
831 // + "\\big_tree.nhx" ) );
834 // new File( PATH_TO_EXAMPLE_FILES + "\\big_tree.nhx" ),
835 // new NHXParser() );
837 // new File( PATH_TO_EXAMPLE_FILES + "\\big_tree.nhx" ),
838 // new NHXParser() );
840 // Helper.readNHtree( new File( PATH_TO_EXAMPLE_FILES
841 // + "\\AtNBSpos.nhx" ) );
843 // new File( PATH_TO_EXAMPLE_FILES + "\\AtNBSpos.nhx" ),
844 // new NHXParser() );
847 // catch ( IOException e ) {
848 // // TODO Auto-generated catch block
849 // e.printStackTrace();
853 private static boolean testBasicNodeMethods() {
855 if ( PhylogenyNode.getNodeCount() != 0 ) {
858 final PhylogenyNode n1 = new PhylogenyNode();
859 final PhylogenyNode n2 = PhylogenyNode
860 .createInstanceFromNhxString( "", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
861 final PhylogenyNode n3 = PhylogenyNode
862 .createInstanceFromNhxString( "n3", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
863 final PhylogenyNode n4 = PhylogenyNode
864 .createInstanceFromNhxString( "n4:0.01", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
865 if ( n1.isHasAssignedEvent() ) {
868 if ( PhylogenyNode.getNodeCount() != 4 ) {
871 if ( n3.getIndicator() != 0 ) {
874 if ( n3.getNumberOfExternalNodes() != 1 ) {
877 if ( !n3.isExternal() ) {
880 if ( !n3.isRoot() ) {
883 if ( !n4.getName().equals( "n4" ) ) {
887 catch ( final Exception e ) {
888 e.printStackTrace( System.out );
894 private static boolean testBasicPhyloXMLparsing() {
896 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
897 final PhyloXmlParser xml_parser = new PhyloXmlParser();
898 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
900 if ( xml_parser.getErrorCount() > 0 ) {
901 System.out.println( xml_parser.getErrorMessages().toString() );
904 if ( phylogenies_0.length != 4 ) {
907 final Phylogeny t1 = phylogenies_0[ 0 ];
908 final Phylogeny t2 = phylogenies_0[ 1 ];
909 final Phylogeny t3 = phylogenies_0[ 2 ];
910 final Phylogeny t4 = phylogenies_0[ 3 ];
911 if ( t1.getNumberOfExternalNodes() != 1 ) {
914 if ( !t1.isRooted() ) {
917 if ( t1.isRerootable() ) {
920 if ( !t1.getType().equals( "gene_tree" ) ) {
923 if ( t2.getNumberOfExternalNodes() != 2 ) {
926 if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
929 if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
932 if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
935 if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
938 if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
941 if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
944 if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
945 .startsWith( "actgtgggggt" ) ) {
948 if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
949 .startsWith( "ctgtgatgcat" ) ) {
952 if ( t3.getNumberOfExternalNodes() != 4 ) {
955 if ( !t1.getName().equals( "t1" ) ) {
958 if ( !t2.getName().equals( "t2" ) ) {
961 if ( !t3.getName().equals( "t3" ) ) {
964 if ( !t4.getName().equals( "t4" ) ) {
967 if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
970 if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
973 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
976 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
977 .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
980 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
983 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
986 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
989 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getDesc()
990 .equals( "apoptosis" ) ) {
993 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
994 .equals( "GO:0006915" ) ) {
997 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getSource()
998 .equals( "UniProtKB" ) ) {
1001 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getEvidence()
1002 .equals( "experimental" ) ) {
1005 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getType()
1006 .equals( "function" ) ) {
1009 if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getConfidence()
1010 .getValue() != 1 ) {
1013 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getConfidence()
1014 .getType().equals( "ml" ) ) {
1017 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getDesc()
1018 .equals( "apoptosis" ) ) {
1021 if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getProperties()
1022 .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1025 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getProperties()
1026 .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1029 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getProperties()
1030 .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1033 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getProperties()
1034 .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1037 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getProperties()
1038 .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1041 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getProperties()
1042 .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1045 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getRef()
1046 .equals( "GO:0005829" ) ) {
1049 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1050 .equals( "intracellular organelle" ) ) {
1053 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1056 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1057 .equals( "UniProt link" ) ) ) {
1060 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1063 //if ( !( t3.getNode( "root node" ).getNodeData().getDistribution().getDesc().equals( "irgendwo" ) ) ) {
1066 // if ( !( t3.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1074/jbc.M005889200" ) ) ) {
1069 // if ( !t3.getNode( "root node" ).getNodeData().getTaxonomy().getType().equals( "host" ) ) {
1072 // if ( !t3.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1075 // if ( !t3.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1078 // if ( !t3.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1081 // if ( !t3.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1084 // if ( !t3.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getType().equals( "ncbi" ) ) {
1087 // if ( t3.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1090 // if ( !t3.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getName()
1091 // .equals( "B" ) ) {
1094 // if ( t3.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getFrom() != 21 ) {
1097 // if ( t3.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1100 // if ( t3.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getLength() != 24 ) {
1103 // if ( t3.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1104 // .getConfidence() != 2144 ) {
1107 // if ( !t3.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1108 // .equals( "pfam" ) ) {
1111 // if ( t3.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1114 // if ( t3.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1117 // if ( t3.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1120 // if ( !t3.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1123 // if ( ( ( BinaryCharacters ) t3.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1124 // .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1128 // if ( t3.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1131 // if ( t3.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1134 // if ( t3.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1137 // if ( t3.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1140 // if ( t3.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1143 // if ( t3.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1146 // if ( !t3.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1149 // final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
1151 // if ( xml_parser.getErrorCount() > 0 ) {
1152 // System.out.println( xml_parser.getErrorMessages().toString() );
1155 // if ( phylogenies_1.length != 2 ) {
1158 // final Phylogeny a = phylogenies_1[ 0 ];
1159 // if ( !a.getName().equals( "tree 4" ) ) {
1162 // if ( a.getNumberOfExternalNodes() != 3 ) {
1165 // if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
1168 // if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
1172 catch ( final Exception e ) {
1173 e.printStackTrace( System.out );
1179 private static boolean testBasicPhyloXMLparsingRoundtrip() {
1181 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1182 final PhyloXmlParser xml_parser = new PhyloXmlParser();
1183 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1184 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1187 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1189 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1191 if ( xml_parser.getErrorCount() > 0 ) {
1192 System.out.println( xml_parser.getErrorMessages().toString() );
1195 if ( phylogenies_0.length != 4 ) {
1198 final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1199 final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1200 if ( phylogenies_t1.length != 1 ) {
1203 final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1204 if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1207 if ( !t1_rt.isRooted() ) {
1210 if ( t1_rt.isRerootable() ) {
1213 if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1216 final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1217 final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1218 final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1219 if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1222 if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1225 if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1228 if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1231 if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1232 .startsWith( "actgtgggggt" ) ) {
1235 if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1236 .startsWith( "ctgtgatgcat" ) ) {
1239 final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1240 final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1241 final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1242 final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1243 if ( phylogenies_1.length != 1 ) {
1246 final Phylogeny t3_rt = phylogenies_1[ 0 ];
1247 if ( !t3_rt.getName().equals( "t3" ) ) {
1250 if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1253 if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1256 if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1259 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1262 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1263 .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1266 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1269 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1272 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1273 .equals( "UniProtKB" ) ) {
1276 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getDesc()
1277 .equals( "apoptosis" ) ) {
1280 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1281 .equals( "GO:0006915" ) ) {
1284 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getSource()
1285 .equals( "UniProtKB" ) ) {
1288 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getEvidence()
1289 .equals( "experimental" ) ) {
1292 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getType()
1293 .equals( "function" ) ) {
1296 if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getConfidence()
1297 .getValue() != 1 ) {
1300 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getConfidence()
1301 .getType().equals( "ml" ) ) {
1304 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getDesc()
1305 .equals( "apoptosis" ) ) {
1308 if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getProperties()
1309 .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1312 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getProperties()
1313 .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1316 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getProperties()
1317 .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1320 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getProperties()
1321 .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1324 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getProperties()
1325 .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1328 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getProperties()
1329 .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1332 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getRef()
1333 .equals( "GO:0005829" ) ) {
1336 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1337 .equals( "intracellular organelle" ) ) {
1340 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1343 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1344 .equals( "UniProt link" ) ) ) {
1347 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1350 if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1353 if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1354 .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." ) ) ) {
1357 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1360 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1363 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1366 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1369 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1370 .equals( "ncbi" ) ) {
1373 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1376 if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1377 .getName().equals( "B" ) ) {
1380 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1381 .getFrom() != 21 ) {
1384 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1387 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1388 .getLength() != 24 ) {
1391 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1392 .getConfidence() != 2144 ) {
1395 if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1396 .equals( "pfam" ) ) {
1399 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1402 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1405 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1408 if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1411 final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1412 if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1415 if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1418 if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1421 if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1424 if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1427 if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1430 if ( taxbb.getSynonyms().size() != 2 ) {
1433 if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1436 if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1439 if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1442 if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1445 if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1448 if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1449 .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1453 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1456 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1459 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1462 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1465 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1468 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1471 if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1475 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1478 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1479 .equalsIgnoreCase( "435" ) ) {
1482 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1485 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1486 .equalsIgnoreCase( "443.7" ) ) {
1489 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1492 if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1495 if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1496 .equalsIgnoreCase( "433" ) ) {
1500 catch ( final Exception e ) {
1501 e.printStackTrace( System.out );
1507 private static boolean testBasicPhyloXMLparsingValidating() {
1509 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1510 PhyloXmlParser xml_parser = null;
1512 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1514 catch ( final Exception e ) {
1515 // Do nothing -- means were not running from jar.
1517 if ( xml_parser == null ) {
1518 xml_parser = new PhyloXmlParser();
1519 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1520 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1523 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1526 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1528 if ( xml_parser.getErrorCount() > 0 ) {
1529 System.out.println( xml_parser.getErrorMessages().toString() );
1532 if ( phylogenies_0.length != 4 ) {
1535 final Phylogeny t1 = phylogenies_0[ 0 ];
1536 final Phylogeny t2 = phylogenies_0[ 1 ];
1537 final Phylogeny t3 = phylogenies_0[ 2 ];
1538 final Phylogeny t4 = phylogenies_0[ 3 ];
1539 if ( !t1.getName().equals( "t1" ) ) {
1542 if ( !t2.getName().equals( "t2" ) ) {
1545 if ( !t3.getName().equals( "t3" ) ) {
1548 if ( !t4.getName().equals( "t4" ) ) {
1551 if ( t1.getNumberOfExternalNodes() != 1 ) {
1554 if ( t2.getNumberOfExternalNodes() != 2 ) {
1557 if ( t3.getNumberOfExternalNodes() != 4 ) {
1560 final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
1561 final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
1562 if ( xml_parser.getErrorCount() > 0 ) {
1563 System.out.println( "errors:" );
1564 System.out.println( xml_parser.getErrorMessages().toString() );
1567 if ( phylogenies_1.length != 4 ) {
1570 final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
1572 if ( xml_parser.getErrorCount() > 0 ) {
1573 System.out.println( "errors:" );
1574 System.out.println( xml_parser.getErrorMessages().toString() );
1577 if ( phylogenies_2.length != 1 ) {
1580 if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
1583 final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
1585 if ( xml_parser.getErrorCount() > 0 ) {
1586 System.out.println( xml_parser.getErrorMessages().toString() );
1589 if ( phylogenies_3.length != 2 ) {
1592 final Phylogeny a = phylogenies_3[ 0 ];
1593 if ( !a.getName().equals( "tree 4" ) ) {
1596 if ( a.getNumberOfExternalNodes() != 3 ) {
1599 if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
1602 if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
1605 final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
1607 if ( xml_parser.getErrorCount() > 0 ) {
1608 System.out.println( xml_parser.getErrorMessages().toString() );
1611 if ( phylogenies_4.length != 1 ) {
1614 final Phylogeny s = phylogenies_4[ 0 ];
1615 if ( s.getNumberOfExternalNodes() != 6 ) {
1618 s.getNode( "first" );
1620 s.getNode( "\"<a'b&c'd\">\"" );
1621 s.getNode( "'''\"" );
1622 s.getNode( "\"\"\"" );
1623 s.getNode( "dick & doof" );
1625 catch ( final Exception e ) {
1626 e.printStackTrace( System.out );
1632 private static boolean testBasicTable() {
1634 final BasicTable<String> t0 = new BasicTable<String>();
1635 if ( t0.getNumberOfColumns() != 0 ) {
1638 if ( t0.getNumberOfRows() != 0 ) {
1641 t0.setValue( 3, 2, "23" );
1642 t0.setValue( 10, 1, "error" );
1643 t0.setValue( 10, 1, "110" );
1644 t0.setValue( 9, 1, "19" );
1645 t0.setValue( 1, 10, "101" );
1646 t0.setValue( 10, 10, "1010" );
1647 t0.setValue( 100, 10, "10100" );
1648 t0.setValue( 0, 0, "00" );
1649 if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
1652 if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
1655 if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
1658 if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
1661 if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
1664 if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
1667 if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
1670 if ( t0.getNumberOfColumns() != 101 ) {
1673 if ( t0.getNumberOfRows() != 11 ) {
1676 if ( t0.getValueAsString( 49, 4 ) != null ) {
1679 final String l = ForesterUtil.getLineSeparator();
1680 final StringBuffer source = new StringBuffer();
1681 source.append( "" + l );
1682 source.append( "# 1 1 1 1 1 1 1 1" + l );
1683 source.append( " 00 01 02 03" + l );
1684 source.append( " 10 11 12 13 " + l );
1685 source.append( "20 21 22 23 " + l );
1686 source.append( " 30 31 32 33" + l );
1687 source.append( "40 41 42 43" + l );
1688 source.append( " # 1 1 1 1 1 " + l );
1689 source.append( "50 51 52 53 54" + l );
1690 final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), " " );
1691 if ( t1.getNumberOfColumns() != 5 ) {
1694 if ( t1.getNumberOfRows() != 6 ) {
1697 if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
1700 if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
1703 if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
1706 if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
1709 final StringBuffer source1 = new StringBuffer();
1710 source1.append( "" + l );
1711 source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
1712 source1.append( " 00; 01 ;02;03" + l );
1713 source1.append( " 10; 11; 12; 13 " + l );
1714 source1.append( "20; 21; 22; 23 " + l );
1715 source1.append( " 30; 31; 32; 33" + l );
1716 source1.append( "40;41;42;43" + l );
1717 source1.append( " # 1 1 1 1 1 " + l );
1718 source1.append( ";;;50 ; ;52; 53;;54 " + l );
1719 final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ";" );
1720 if ( t2.getNumberOfColumns() != 5 ) {
1723 if ( t2.getNumberOfRows() != 6 ) {
1726 if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
1729 if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
1732 if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
1735 if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
1738 if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
1741 if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
1744 final StringBuffer source2 = new StringBuffer();
1745 source2.append( "" + l );
1746 source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
1747 source2.append( " 00; 01 ;02;03" + l );
1748 source2.append( " 10; 11; 12; 13 " + l );
1749 source2.append( "20; 21; 22; 23 " + l );
1750 source2.append( " " + l );
1751 source2.append( " 30; 31; 32; 33" + l );
1752 source2.append( "40;41;42;43" + l );
1753 source2.append( " comment: 1 1 1 1 1 " + l );
1754 source2.append( ";;;50 ; 52; 53;;54 " + l );
1755 final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
1761 if ( tl.size() != 2 ) {
1764 final BasicTable<String> t3 = tl.get( 0 );
1765 final BasicTable<String> t4 = tl.get( 1 );
1766 if ( t3.getNumberOfColumns() != 4 ) {
1769 if ( t3.getNumberOfRows() != 3 ) {
1772 if ( t4.getNumberOfColumns() != 4 ) {
1775 if ( t4.getNumberOfRows() != 3 ) {
1778 if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
1781 if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
1785 catch ( final Exception e ) {
1786 e.printStackTrace( System.out );
1792 private static boolean testBasicTolXMLparsing() {
1794 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1795 final TolParser parser = new TolParser();
1796 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
1797 if ( parser.getErrorCount() > 0 ) {
1798 System.out.println( parser.getErrorMessages().toString() );
1801 if ( phylogenies_0.length != 1 ) {
1804 final Phylogeny t1 = phylogenies_0[ 0 ];
1805 if ( t1.getNumberOfExternalNodes() != 5 ) {
1808 if ( !t1.isRooted() ) {
1811 if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
1814 if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
1817 if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
1820 if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
1823 final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
1824 if ( parser.getErrorCount() > 0 ) {
1825 System.out.println( parser.getErrorMessages().toString() );
1828 if ( phylogenies_1.length != 1 ) {
1831 final Phylogeny t2 = phylogenies_1[ 0 ];
1832 if ( t2.getNumberOfExternalNodes() != 664 ) {
1835 if ( !t2.isRooted() ) {
1838 if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
1841 if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
1844 if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
1847 if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
1850 if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
1853 if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
1854 .equals( "Aquifex" ) ) {
1857 final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
1858 if ( parser.getErrorCount() > 0 ) {
1859 System.out.println( parser.getErrorMessages().toString() );
1862 if ( phylogenies_2.length != 1 ) {
1865 final Phylogeny t3 = phylogenies_2[ 0 ];
1866 if ( t3.getNumberOfExternalNodes() != 184 ) {
1869 if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
1872 if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
1875 if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
1878 final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
1879 if ( parser.getErrorCount() > 0 ) {
1880 System.out.println( parser.getErrorMessages().toString() );
1883 if ( phylogenies_3.length != 1 ) {
1886 final Phylogeny t4 = phylogenies_3[ 0 ];
1887 if ( t4.getNumberOfExternalNodes() != 1 ) {
1890 if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
1893 if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
1896 if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
1899 final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
1900 if ( parser.getErrorCount() > 0 ) {
1901 System.out.println( parser.getErrorMessages().toString() );
1904 if ( phylogenies_4.length != 1 ) {
1907 final Phylogeny t5 = phylogenies_4[ 0 ];
1908 if ( t5.getNumberOfExternalNodes() != 13 ) {
1911 if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
1914 if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
1917 if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
1921 catch ( final Exception e ) {
1922 e.printStackTrace( System.out );
1928 private static boolean testBasicTreeMethods() {
1930 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1931 final Phylogeny t1 = factory.create();
1932 if ( !t1.isEmpty() ) {
1935 final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
1936 if ( t2.getNumberOfExternalNodes() != 4 ) {
1939 if ( t2.getHeight() != 8.5 ) {
1942 if ( !t2.isCompletelyBinary() ) {
1945 if ( t2.isEmpty() ) {
1948 final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
1949 if ( t3.getNumberOfExternalNodes() != 5 ) {
1952 if ( t3.getHeight() != 11 ) {
1955 if ( t3.isCompletelyBinary() ) {
1958 final PhylogenyNode n = t3.getNode( "ABC" );
1959 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 ];
1960 if ( t4.getNumberOfExternalNodes() != 9 ) {
1963 if ( t4.getHeight() != 11 ) {
1966 if ( t4.isCompletelyBinary() ) {
1969 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)" );
1970 final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
1971 if ( t5.getNumberOfExternalNodes() != 8 ) {
1974 if ( t5.getHeight() != 15 ) {
1977 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)" );
1978 final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
1979 if ( t6.getHeight() != 15 ) {
1982 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)" );
1983 final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
1984 if ( t7.getHeight() != 15 ) {
1987 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)" );
1988 final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
1989 if ( t8.getNumberOfExternalNodes() != 10 ) {
1992 if ( t8.getHeight() != 15 ) {
1995 final char[] a9 = new char[] {};
1996 final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
1997 if ( t9.getHeight() != 0 ) {
2000 final char[] a10 = new char[] { 'a', ':', '6' };
2001 final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2002 if ( t10.getHeight() != 6 ) {
2006 catch ( final Exception e ) {
2007 e.printStackTrace( System.out );
2013 private static boolean testConfidenceAssessor() {
2015 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2016 final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2017 final Phylogeny[] ev0 = factory
2018 .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2020 ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2021 if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2024 if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2027 final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2028 final Phylogeny[] ev1 = factory
2029 .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)));",
2031 ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2032 if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2035 if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2038 final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2039 final Phylogeny[] ev_b = factory
2040 .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",
2042 ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2043 if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2046 if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2050 final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2051 final Phylogeny[] ev1x = factory
2052 .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)));",
2054 ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2055 if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2058 if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2061 final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2062 final Phylogeny[] ev_bx = factory
2063 .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",
2065 ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2066 if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2069 if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2073 final Phylogeny[] t2 = factory
2074 .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);",
2076 final Phylogeny[] ev2 = factory
2077 .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);",
2079 for( final Phylogeny target : t2 ) {
2080 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2083 final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2084 new NHXParser() )[ 0 ];
2085 final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2086 ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2087 if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2090 if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2093 if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2097 catch ( final Exception e ) {
2098 e.printStackTrace();
2104 private static boolean testCopyOfNodeData() {
2106 final PhylogenyNode n1 = PhylogenyNode
2107 .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]" );
2108 final PhylogenyNode n2 = n1.copyNodeData();
2109 if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2113 catch ( final Exception e ) {
2114 e.printStackTrace();
2120 private static boolean testDataObjects() {
2122 final Confidence s0 = new Confidence();
2123 final Confidence s1 = new Confidence();
2124 if ( !s0.isEqual( s1 ) ) {
2127 final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2128 final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2129 if ( s2.isEqual( s1 ) ) {
2132 if ( !s2.isEqual( s3 ) ) {
2135 final Confidence s4 = ( Confidence ) s3.copy();
2136 if ( !s4.isEqual( s3 ) ) {
2143 final Taxonomy t1 = new Taxonomy();
2144 final Taxonomy t2 = new Taxonomy();
2145 final Taxonomy t3 = new Taxonomy();
2146 final Taxonomy t4 = new Taxonomy();
2147 final Taxonomy t5 = new Taxonomy();
2148 t1.setIdentifier( new Identifier( "ecoli" ) );
2149 t1.setTaxonomyCode( "ECOLI" );
2150 t1.setScientificName( "E. coli" );
2151 t1.setCommonName( "coli" );
2152 final Taxonomy t0 = ( Taxonomy ) t1.copy();
2153 if ( !t1.isEqual( t0 ) ) {
2156 t2.setIdentifier( new Identifier( "ecoli" ) );
2157 t2.setTaxonomyCode( "OTHER" );
2158 t2.setScientificName( "what" );
2159 t2.setCommonName( "something" );
2160 if ( !t1.isEqual( t2 ) ) {
2163 t2.setIdentifier( new Identifier( "nemve" ) );
2164 if ( t1.isEqual( t2 ) ) {
2167 t1.setIdentifier( null );
2168 t3.setTaxonomyCode( "ECOLI" );
2169 t3.setScientificName( "what" );
2170 t3.setCommonName( "something" );
2171 if ( !t1.isEqual( t3 ) ) {
2174 t1.setIdentifier( null );
2175 t1.setTaxonomyCode( "" );
2176 t4.setScientificName( "E. ColI" );
2177 t4.setCommonName( "something" );
2178 if ( !t1.isEqual( t4 ) ) {
2181 t4.setScientificName( "B. subtilis" );
2182 t4.setCommonName( "something" );
2183 if ( t1.isEqual( t4 ) ) {
2186 t1.setIdentifier( null );
2187 t1.setTaxonomyCode( "" );
2188 t1.setScientificName( "" );
2189 t5.setCommonName( "COLI" );
2190 if ( !t1.isEqual( t5 ) ) {
2193 t5.setCommonName( "vibrio" );
2194 if ( t1.isEqual( t5 ) ) {
2199 final Identifier id0 = new Identifier( "123", "pfam" );
2200 final Identifier id1 = ( Identifier ) id0.copy();
2201 if ( !id1.isEqual( id1 ) ) {
2204 if ( !id1.isEqual( id0 ) ) {
2207 if ( !id0.isEqual( id1 ) ) {
2214 final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
2215 final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
2216 if ( !pd1.isEqual( pd1 ) ) {
2219 if ( !pd1.isEqual( pd0 ) ) {
2224 final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
2225 final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
2226 if ( !pd3.isEqual( pd3 ) ) {
2229 if ( !pd2.isEqual( pd3 ) ) {
2232 if ( !pd0.isEqual( pd3 ) ) {
2237 // DomainArchitecture
2238 // ------------------
2239 final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
2240 final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
2241 final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
2242 final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
2243 final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
2244 final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
2249 final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
2250 if ( ds0.getNumberOfDomains() != 4 ) {
2253 final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
2254 if ( !ds0.isEqual( ds0 ) ) {
2257 if ( !ds0.isEqual( ds1 ) ) {
2260 if ( ds1.getNumberOfDomains() != 4 ) {
2263 final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
2268 final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
2269 if ( ds0.isEqual( ds2 ) ) {
2275 final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
2276 if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
2277 System.out.println( ds3.toNHX() );
2280 if ( ds3.getNumberOfDomains() != 3 ) {
2285 final Event e1 = new Event( Event.EventType.fusion );
2286 if ( e1.isDuplication() ) {
2289 if ( !e1.isFusion() ) {
2292 if ( !e1.asText().toString().equals( "fusion" ) ) {
2295 if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
2298 final Event e11 = new Event( Event.EventType.fusion );
2299 if ( !e11.isEqual( e1 ) ) {
2302 if ( !e11.toNHX().toString().equals( "" ) ) {
2305 final Event e2 = new Event( Event.EventType.speciation_or_duplication );
2306 if ( e2.isDuplication() ) {
2309 if ( !e2.isSpeciationOrDuplication() ) {
2312 if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
2315 if ( !e2.asSimpleText().toString().equals( "?" ) ) {
2318 if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
2321 if ( e11.isEqual( e2 ) ) {
2324 final Event e2c = ( Event ) e2.copy();
2325 if ( !e2c.isEqual( e2 ) ) {
2328 Event e3 = new Event( 1, 2, 3 );
2329 if ( e3.isDuplication() ) {
2332 if ( e3.isSpeciation() ) {
2335 if ( e3.isGeneLoss() ) {
2338 if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2341 final Event e3c = ( Event ) e3.copy();
2342 final Event e3cc = ( Event ) e3c.copy();
2343 if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
2347 if ( !e3c.isEqual( e3cc ) ) {
2350 Event e4 = new Event( 1, 2, 3 );
2351 if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2354 if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
2357 final Event e4c = ( Event ) e4.copy();
2359 final Event e4cc = ( Event ) e4c.copy();
2360 if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2363 if ( !e4c.isEqual( e4cc ) ) {
2366 final Event e5 = new Event();
2367 if ( !e5.isUnassigned() ) {
2370 if ( !e5.asText().toString().equals( "unassigned" ) ) {
2373 if ( !e5.asSimpleText().toString().equals( "" ) ) {
2376 final Event e6 = new Event( 1, 0, 0 );
2377 if ( !e6.asText().toString().equals( "duplication" ) ) {
2380 if ( !e6.asSimpleText().toString().equals( "D" ) ) {
2383 final Event e7 = new Event( 0, 1, 0 );
2384 if ( !e7.asText().toString().equals( "speciation" ) ) {
2387 if ( !e7.asSimpleText().toString().equals( "S" ) ) {
2390 final Event e8 = new Event( 0, 0, 1 );
2391 if ( !e8.asText().toString().equals( "gene-loss" ) ) {
2394 if ( !e8.asSimpleText().toString().equals( "L" ) ) {
2398 catch ( final Exception e ) {
2399 e.printStackTrace( System.out );
2405 private static boolean testDeletionOfExternalNodes() {
2407 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2408 final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
2409 final PhylogenyWriter w = new PhylogenyWriter();
2410 if ( t0.isEmpty() ) {
2413 if ( t0.getNumberOfExternalNodes() != 1 ) {
2416 t0.deleteSubtree( t0.getNode( "A" ), false );
2417 if ( t0.getNumberOfExternalNodes() != 0 ) {
2420 if ( !t0.isEmpty() ) {
2423 final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
2424 if ( t1.getNumberOfExternalNodes() != 2 ) {
2427 t1.deleteSubtree( t1.getNode( "A" ), false );
2428 if ( t1.getNumberOfExternalNodes() != 1 ) {
2431 if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
2434 t1.deleteSubtree( t1.getNode( "B" ), false );
2435 if ( t1.getNumberOfExternalNodes() != 1 ) {
2438 t1.deleteSubtree( t1.getNode( "r" ), false );
2439 if ( !t1.isEmpty() ) {
2442 final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
2443 if ( t2.getNumberOfExternalNodes() != 3 ) {
2446 t2.deleteSubtree( t2.getNode( "B" ), false );
2447 if ( t2.getNumberOfExternalNodes() != 2 ) {
2450 t2.toNewHampshireX();
2451 PhylogenyNode n = t2.getNode( "A" );
2452 if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2455 t2.deleteSubtree( t2.getNode( "A" ), false );
2456 if ( t2.getNumberOfExternalNodes() != 2 ) {
2459 t2.deleteSubtree( t2.getNode( "C" ), true );
2460 if ( t2.getNumberOfExternalNodes() != 1 ) {
2463 final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2464 if ( t3.getNumberOfExternalNodes() != 4 ) {
2467 t3.deleteSubtree( t3.getNode( "B" ), true );
2468 if ( t3.getNumberOfExternalNodes() != 3 ) {
2471 n = t3.getNode( "A" );
2472 if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
2475 n = n.getNextExternalNode();
2476 if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2479 t3.deleteSubtree( t3.getNode( "A" ), true );
2480 if ( t3.getNumberOfExternalNodes() != 2 ) {
2483 n = t3.getNode( "C" );
2484 if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
2487 t3.deleteSubtree( t3.getNode( "C" ), true );
2488 if ( t3.getNumberOfExternalNodes() != 1 ) {
2491 t3.deleteSubtree( t3.getNode( "D" ), true );
2492 if ( t3.getNumberOfExternalNodes() != 0 ) {
2495 final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2496 if ( t4.getNumberOfExternalNodes() != 6 ) {
2499 t4.deleteSubtree( t4.getNode( "B2" ), true );
2500 if ( t4.getNumberOfExternalNodes() != 5 ) {
2503 String s = w.toNewHampshire( t4, false, true ).toString();
2504 if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2507 t4.deleteSubtree( t4.getNode( "B11" ), true );
2508 if ( t4.getNumberOfExternalNodes() != 4 ) {
2511 t4.deleteSubtree( t4.getNode( "C" ), true );
2512 if ( t4.getNumberOfExternalNodes() != 3 ) {
2515 n = t4.getNode( "A" );
2516 n = n.getNextExternalNode();
2517 if ( !n.getName().equals( "B12" ) ) {
2520 n = n.getNextExternalNode();
2521 if ( !n.getName().equals( "D" ) ) {
2524 s = w.toNewHampshire( t4, false, true ).toString();
2525 if ( !s.equals( "((A,B12),D);" ) ) {
2528 final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2529 t5.deleteSubtree( t5.getNode( "A" ), true );
2530 if ( t5.getNumberOfExternalNodes() != 5 ) {
2533 s = w.toNewHampshire( t5, false, true ).toString();
2534 if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
2537 final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2538 t6.deleteSubtree( t6.getNode( "B11" ), true );
2539 if ( t6.getNumberOfExternalNodes() != 5 ) {
2542 s = w.toNewHampshire( t6, false, false ).toString();
2543 if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
2546 final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2547 t7.deleteSubtree( t7.getNode( "B12" ), true );
2548 if ( t7.getNumberOfExternalNodes() != 5 ) {
2551 s = w.toNewHampshire( t7, false, true ).toString();
2552 if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
2555 final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2556 t8.deleteSubtree( t8.getNode( "B2" ), true );
2557 if ( t8.getNumberOfExternalNodes() != 5 ) {
2560 s = w.toNewHampshire( t8, false, false ).toString();
2561 if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
2564 final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2565 t9.deleteSubtree( t9.getNode( "C" ), true );
2566 if ( t9.getNumberOfExternalNodes() != 5 ) {
2569 s = w.toNewHampshire( t9, false, true ).toString();
2570 if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
2573 final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
2574 t10.deleteSubtree( t10.getNode( "D" ), true );
2575 if ( t10.getNumberOfExternalNodes() != 5 ) {
2578 s = w.toNewHampshire( t10, false, true ).toString();
2579 if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
2582 final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
2583 t11.deleteSubtree( t11.getNode( "A" ), true );
2584 if ( t11.getNumberOfExternalNodes() != 2 ) {
2587 s = w.toNewHampshire( t11, false, true ).toString();
2588 if ( !s.equals( "(B,C);" ) ) {
2591 t11.deleteSubtree( t11.getNode( "C" ), true );
2592 if ( t11.getNumberOfExternalNodes() != 1 ) {
2595 s = w.toNewHampshire( t11, false, false ).toString();
2596 if ( !s.equals( "B;" ) ) {
2599 final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
2600 t12.deleteSubtree( t12.getNode( "B2" ), true );
2601 if ( t12.getNumberOfExternalNodes() != 8 ) {
2604 s = w.toNewHampshire( t12, false, true ).toString();
2605 if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
2608 t12.deleteSubtree( t12.getNode( "B3" ), true );
2609 if ( t12.getNumberOfExternalNodes() != 7 ) {
2612 s = w.toNewHampshire( t12, false, true ).toString();
2613 if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
2616 t12.deleteSubtree( t12.getNode( "C3" ), true );
2617 if ( t12.getNumberOfExternalNodes() != 6 ) {
2620 s = w.toNewHampshire( t12, false, true ).toString();
2621 if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
2624 t12.deleteSubtree( t12.getNode( "A1" ), true );
2625 if ( t12.getNumberOfExternalNodes() != 5 ) {
2628 s = w.toNewHampshire( t12, false, true ).toString();
2629 if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
2632 t12.deleteSubtree( t12.getNode( "B1" ), true );
2633 if ( t12.getNumberOfExternalNodes() != 4 ) {
2636 s = w.toNewHampshire( t12, false, true ).toString();
2637 if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
2640 t12.deleteSubtree( t12.getNode( "A3" ), true );
2641 if ( t12.getNumberOfExternalNodes() != 3 ) {
2644 s = w.toNewHampshire( t12, false, true ).toString();
2645 if ( !s.equals( "(A2,(C1,C2));" ) ) {
2648 t12.deleteSubtree( t12.getNode( "A2" ), true );
2649 if ( t12.getNumberOfExternalNodes() != 2 ) {
2652 s = w.toNewHampshire( t12, false, true ).toString();
2653 if ( !s.equals( "(C1,C2);" ) ) {
2656 final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
2657 t13.deleteSubtree( t13.getNode( "D" ), true );
2658 if ( t13.getNumberOfExternalNodes() != 4 ) {
2661 s = w.toNewHampshire( t13, false, true ).toString();
2662 if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
2665 final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
2666 t14.deleteSubtree( t14.getNode( "E" ), true );
2667 if ( t14.getNumberOfExternalNodes() != 5 ) {
2670 s = w.toNewHampshire( t14, false, true ).toString();
2671 if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
2674 final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
2675 t15.deleteSubtree( t15.getNode( "B2" ), true );
2676 if ( t15.getNumberOfExternalNodes() != 11 ) {
2679 t15.deleteSubtree( t15.getNode( "B1" ), true );
2680 if ( t15.getNumberOfExternalNodes() != 10 ) {
2683 t15.deleteSubtree( t15.getNode( "B3" ), true );
2684 if ( t15.getNumberOfExternalNodes() != 9 ) {
2687 t15.deleteSubtree( t15.getNode( "B4" ), true );
2688 if ( t15.getNumberOfExternalNodes() != 8 ) {
2691 t15.deleteSubtree( t15.getNode( "A1" ), true );
2692 if ( t15.getNumberOfExternalNodes() != 7 ) {
2695 t15.deleteSubtree( t15.getNode( "C4" ), true );
2696 if ( t15.getNumberOfExternalNodes() != 6 ) {
2700 catch ( final Exception e ) {
2701 e.printStackTrace( System.out );
2707 private static boolean testDescriptiveStatistics() {
2709 final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
2710 dss1.addValue( 82 );
2711 dss1.addValue( 78 );
2712 dss1.addValue( 70 );
2713 dss1.addValue( 58 );
2714 dss1.addValue( 42 );
2715 if ( dss1.getN() != 5 ) {
2718 if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
2721 if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
2724 if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
2727 if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
2730 if ( !Test.isEqual( dss1.median(), 70 ) ) {
2733 if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
2736 if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
2739 if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
2742 if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
2745 if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
2748 if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
2751 dss1.addValue( 123 );
2752 if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
2755 if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
2758 if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
2761 final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
2762 dss2.addValue( -1.85 );
2763 dss2.addValue( 57.5 );
2764 dss2.addValue( 92.78 );
2765 dss2.addValue( 57.78 );
2766 if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
2769 if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
2772 final double[] a = dss2.getDataAsDoubleArray();
2773 if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
2776 dss2.addValue( -100 );
2777 if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
2780 if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
2783 final double[] ds = new double[ 14 ];
2798 final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
2799 if ( bins.length != 4 ) {
2802 if ( bins[ 0 ] != 2 ) {
2805 if ( bins[ 1 ] != 3 ) {
2808 if ( bins[ 2 ] != 4 ) {
2811 if ( bins[ 3 ] != 5 ) {
2814 final double[] ds1 = new double[ 9 ];
2824 final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
2825 if ( bins1.length != 4 ) {
2828 if ( bins1[ 0 ] != 2 ) {
2831 if ( bins1[ 1 ] != 3 ) {
2834 if ( bins1[ 2 ] != 0 ) {
2837 if ( bins1[ 3 ] != 4 ) {
2840 final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
2841 if ( bins1_1.length != 3 ) {
2844 if ( bins1_1[ 0 ] != 3 ) {
2847 if ( bins1_1[ 1 ] != 2 ) {
2850 if ( bins1_1[ 2 ] != 4 ) {
2853 final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
2854 if ( bins1_2.length != 3 ) {
2857 if ( bins1_2[ 0 ] != 2 ) {
2860 if ( bins1_2[ 1 ] != 2 ) {
2863 if ( bins1_2[ 2 ] != 2 ) {
2866 final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
2880 dss3.addValue( 10 );
2881 dss3.addValue( 10 );
2882 dss3.addValue( 10 );
2883 final AsciiHistogram histo = new AsciiHistogram( dss3 );
2884 histo.toStringBuffer( 10, '=', 40, 5 );
2885 histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
2887 catch ( final Exception e ) {
2888 e.printStackTrace( System.out );
2894 private static boolean testDir( final String file ) {
2896 final File f = new File( file );
2897 if ( !f.exists() ) {
2900 if ( !f.isDirectory() ) {
2903 if ( !f.canRead() ) {
2907 catch ( final Exception e ) {
2913 private static boolean testExternalNodeRelatedMethods() {
2915 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2916 final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2917 PhylogenyNode n = t1.getNode( "A" );
2918 n = n.getNextExternalNode();
2919 if ( !n.getName().equals( "B" ) ) {
2922 n = n.getNextExternalNode();
2923 if ( !n.getName().equals( "C" ) ) {
2926 n = n.getNextExternalNode();
2927 if ( !n.getName().equals( "D" ) ) {
2930 n = t1.getNode( "B" );
2931 while ( !n.isLastExternalNode() ) {
2932 n = n.getNextExternalNode();
2934 final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
2935 n = t2.getNode( "A" );
2936 n = n.getNextExternalNode();
2937 if ( !n.getName().equals( "B" ) ) {
2940 n = n.getNextExternalNode();
2941 if ( !n.getName().equals( "C" ) ) {
2944 n = n.getNextExternalNode();
2945 if ( !n.getName().equals( "D" ) ) {
2948 n = t2.getNode( "B" );
2949 while ( !n.isLastExternalNode() ) {
2950 n = n.getNextExternalNode();
2952 final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
2953 n = t3.getNode( "A" );
2954 n = n.getNextExternalNode();
2955 if ( !n.getName().equals( "B" ) ) {
2958 n = n.getNextExternalNode();
2959 if ( !n.getName().equals( "C" ) ) {
2962 n = n.getNextExternalNode();
2963 if ( !n.getName().equals( "D" ) ) {
2966 n = n.getNextExternalNode();
2967 if ( !n.getName().equals( "E" ) ) {
2970 n = n.getNextExternalNode();
2971 if ( !n.getName().equals( "F" ) ) {
2974 n = n.getNextExternalNode();
2975 if ( !n.getName().equals( "G" ) ) {
2978 n = n.getNextExternalNode();
2979 if ( !n.getName().equals( "H" ) ) {
2982 n = t3.getNode( "B" );
2983 while ( !n.isLastExternalNode() ) {
2984 n = n.getNextExternalNode();
2986 final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
2987 for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
2988 final PhylogenyNode node = iter.next();
2990 final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
2991 for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
2992 final PhylogenyNode node = iter.next();
2995 catch ( final Exception e ) {
2996 e.printStackTrace( System.out );
3002 private static boolean testGeneralTable() {
3004 final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
3005 t0.setValue( 3, 2, "23" );
3006 t0.setValue( 10, 1, "error" );
3007 t0.setValue( 10, 1, "110" );
3008 t0.setValue( 9, 1, "19" );
3009 t0.setValue( 1, 10, "101" );
3010 t0.setValue( 10, 10, "1010" );
3011 t0.setValue( 100, 10, "10100" );
3012 t0.setValue( 0, 0, "00" );
3013 if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
3016 if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
3019 if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
3022 if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
3025 if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
3028 if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
3031 if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
3034 if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
3037 if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
3040 final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
3041 t1.setValue( "3", "2", "23" );
3042 t1.setValue( "10", "1", "error" );
3043 t1.setValue( "10", "1", "110" );
3044 t1.setValue( "9", "1", "19" );
3045 t1.setValue( "1", "10", "101" );
3046 t1.setValue( "10", "10", "1010" );
3047 t1.setValue( "100", "10", "10100" );
3048 t1.setValue( "0", "0", "00" );
3049 t1.setValue( "qwerty", "zxcvbnm", "asdef" );
3050 if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
3053 if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
3056 if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
3059 if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
3062 if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
3065 if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
3068 if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
3071 if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
3074 if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
3077 if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
3081 catch ( final Exception e ) {
3082 e.printStackTrace( System.out );
3088 private static boolean testGetDistance() {
3090 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3091 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",
3092 new NHXParser() )[ 0 ];
3093 final PhylogenyMethods pm = PhylogenyMethods.getInstance();
3094 if ( pm.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
3097 if ( pm.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
3100 if ( pm.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
3103 if ( pm.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
3106 if ( pm.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
3109 if ( pm.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
3112 if ( pm.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
3115 if ( pm.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
3118 if ( pm.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
3121 if ( pm.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
3124 if ( pm.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
3127 if ( pm.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
3130 if ( pm.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
3133 if ( pm.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
3136 if ( pm.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
3139 if ( pm.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
3142 if ( pm.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
3145 if ( pm.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
3148 if ( pm.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
3151 if ( pm.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
3154 if ( pm.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
3157 if ( pm.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
3160 if ( pm.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
3163 if ( pm.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
3166 if ( pm.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
3169 if ( pm.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
3172 if ( pm.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
3175 if ( pm.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
3178 if ( pm.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
3181 if ( pm.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
3184 if ( pm.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
3187 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",
3188 new NHXParser() )[ 0 ];
3189 if ( pm.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
3192 if ( pm.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
3195 if ( pm.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
3198 if ( pm.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
3201 if ( pm.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
3204 if ( pm.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
3207 if ( pm.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
3210 if ( pm.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
3213 if ( pm.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
3216 if ( pm.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
3219 if ( pm.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
3223 catch ( final Exception e ) {
3224 e.printStackTrace( System.out );
3230 private static boolean testGetLCA() {
3232 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3233 final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3234 new NHXParser() )[ 0 ];
3235 final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
3236 if ( !A.getName().equals( "A" ) ) {
3239 final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
3240 if ( !gh.getName().equals( "gh" ) ) {
3243 final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
3244 if ( !ab.getName().equals( "ab" ) ) {
3247 final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
3248 if ( !ab2.getName().equals( "ab" ) ) {
3251 final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
3252 if ( !gh2.getName().equals( "gh" ) ) {
3255 final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
3256 if ( !gh3.getName().equals( "gh" ) ) {
3259 final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
3260 if ( !abc.getName().equals( "abc" ) ) {
3263 final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
3264 if ( !abc2.getName().equals( "abc" ) ) {
3267 final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
3268 if ( !abcd.getName().equals( "abcd" ) ) {
3271 final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
3272 if ( !abcd2.getName().equals( "abcd" ) ) {
3275 final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
3276 if ( !abcdef.getName().equals( "abcdef" ) ) {
3279 final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
3280 if ( !abcdef2.getName().equals( "abcdef" ) ) {
3283 final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
3284 if ( !abcdef3.getName().equals( "abcdef" ) ) {
3287 final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
3288 if ( !abcdef4.getName().equals( "abcdef" ) ) {
3291 final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
3292 if ( !abcde.getName().equals( "abcde" ) ) {
3295 final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
3296 if ( !abcde2.getName().equals( "abcde" ) ) {
3299 final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
3300 if ( !r.getName().equals( "abcdefgh" ) ) {
3303 final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
3304 if ( !r2.getName().equals( "abcdefgh" ) ) {
3307 final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
3308 if ( !r3.getName().equals( "abcdefgh" ) ) {
3311 final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
3312 if ( !abcde3.getName().equals( "abcde" ) ) {
3315 final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
3316 if ( !abcde4.getName().equals( "abcde" ) ) {
3319 final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
3320 if ( !ab3.getName().equals( "ab" ) ) {
3323 final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
3324 if ( !ab4.getName().equals( "ab" ) ) {
3327 final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3328 final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
3329 if ( !cd.getName().equals( "cd" ) ) {
3332 final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
3333 if ( !cd2.getName().equals( "cd" ) ) {
3336 final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
3337 if ( !cde.getName().equals( "cde" ) ) {
3340 final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
3341 if ( !cde2.getName().equals( "cde" ) ) {
3344 final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
3345 if ( !cdef.getName().equals( "cdef" ) ) {
3348 final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
3349 if ( !cdef2.getName().equals( "cdef" ) ) {
3352 final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
3353 if ( !cdef3.getName().equals( "cdef" ) ) {
3356 final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
3357 if ( !rt.getName().equals( "r" ) ) {
3360 final Phylogeny p3 = factory
3361 .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
3362 new NHXParser() )[ 0 ];
3363 final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
3364 if ( !bc_3.getName().equals( "bc" ) ) {
3367 final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
3368 if ( !ac_3.getName().equals( "abc" ) ) {
3371 final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
3372 if ( !ad_3.getName().equals( "abcde" ) ) {
3375 final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
3376 if ( !af_3.getName().equals( "abcdef" ) ) {
3379 final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
3380 if ( !ag_3.getName().equals( "" ) ) {
3383 if ( !ag_3.isRoot() ) {
3386 final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
3387 if ( !al_3.getName().equals( "" ) ) {
3390 if ( !al_3.isRoot() ) {
3393 final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
3394 if ( !kl_3.getName().equals( "" ) ) {
3397 if ( !kl_3.isRoot() ) {
3400 final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
3401 if ( !fl_3.getName().equals( "" ) ) {
3404 if ( !fl_3.isRoot() ) {
3407 final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
3408 if ( !gk_3.getName().equals( "ghijk" ) ) {
3411 final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
3412 final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
3413 if ( !r_4.getName().equals( "r" ) ) {
3416 final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
3417 final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
3418 if ( !r_5.getName().equals( "root" ) ) {
3421 final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
3422 final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
3423 if ( !r_6.getName().equals( "rot" ) ) {
3426 final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
3427 final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
3428 if ( !r_7.getName().equals( "rott" ) ) {
3432 catch ( final Exception e ) {
3433 e.printStackTrace( System.out );
3439 private static boolean testGetLCA2() {
3441 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3442 final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
3443 new NHXParser() )[ 0 ];
3444 PhylogenyMethods.preOrderReId( p1 );
3445 final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3446 p1.getNode( "A" ) );
3447 if ( !A.getName().equals( "A" ) ) {
3450 final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
3451 p1.getNode( "gh" ) );
3452 if ( !gh.getName().equals( "gh" ) ) {
3455 final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3456 p1.getNode( "B" ) );
3457 if ( !ab.getName().equals( "ab" ) ) {
3460 final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3461 p1.getNode( "A" ) );
3462 if ( !ab2.getName().equals( "ab" ) ) {
3465 final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3466 p1.getNode( "G" ) );
3467 if ( !gh2.getName().equals( "gh" ) ) {
3470 final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
3471 p1.getNode( "H" ) );
3472 if ( !gh3.getName().equals( "gh" ) ) {
3475 final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
3476 p1.getNode( "A" ) );
3477 if ( !abc.getName().equals( "abc" ) ) {
3480 final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3481 p1.getNode( "C" ) );
3482 if ( !abc2.getName().equals( "abc" ) ) {
3485 final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3486 p1.getNode( "D" ) );
3487 if ( !abcd.getName().equals( "abcd" ) ) {
3490 final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
3491 p1.getNode( "A" ) );
3492 if ( !abcd2.getName().equals( "abcd" ) ) {
3495 final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3496 p1.getNode( "F" ) );
3497 if ( !abcdef.getName().equals( "abcdef" ) ) {
3500 final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3501 p1.getNode( "A" ) );
3502 if ( !abcdef2.getName().equals( "abcdef" ) ) {
3505 final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3506 p1.getNode( "F" ) );
3507 if ( !abcdef3.getName().equals( "abcdef" ) ) {
3510 final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
3511 p1.getNode( "ab" ) );
3512 if ( !abcdef4.getName().equals( "abcdef" ) ) {
3515 final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3516 p1.getNode( "E" ) );
3517 if ( !abcde.getName().equals( "abcde" ) ) {
3520 final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3521 p1.getNode( "A" ) );
3522 if ( !abcde2.getName().equals( "abcde" ) ) {
3525 final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
3526 p1.getNode( "abcdefgh" ) );
3527 if ( !r.getName().equals( "abcdefgh" ) ) {
3530 final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
3531 p1.getNode( "H" ) );
3532 if ( !r2.getName().equals( "abcdefgh" ) ) {
3535 final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
3536 p1.getNode( "A" ) );
3537 if ( !r3.getName().equals( "abcdefgh" ) ) {
3540 final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
3541 p1.getNode( "abcde" ) );
3542 if ( !abcde3.getName().equals( "abcde" ) ) {
3545 final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
3546 p1.getNode( "E" ) );
3547 if ( !abcde4.getName().equals( "abcde" ) ) {
3550 final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
3551 p1.getNode( "B" ) );
3552 if ( !ab3.getName().equals( "ab" ) ) {
3555 final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
3556 p1.getNode( "ab" ) );
3557 if ( !ab4.getName().equals( "ab" ) ) {
3560 final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
3561 PhylogenyMethods.preOrderReId( p2 );
3562 final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3563 p2.getNode( "d" ) );
3564 if ( !cd.getName().equals( "cd" ) ) {
3567 final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3568 p2.getNode( "c" ) );
3569 if ( !cd2.getName().equals( "cd" ) ) {
3572 final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3573 p2.getNode( "e" ) );
3574 if ( !cde.getName().equals( "cde" ) ) {
3577 final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
3578 p2.getNode( "c" ) );
3579 if ( !cde2.getName().equals( "cde" ) ) {
3582 final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3583 p2.getNode( "f" ) );
3584 if ( !cdef.getName().equals( "cdef" ) ) {
3587 final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
3588 p2.getNode( "f" ) );
3589 if ( !cdef2.getName().equals( "cdef" ) ) {
3592 final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
3593 p2.getNode( "d" ) );
3594 if ( !cdef3.getName().equals( "cdef" ) ) {
3597 final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
3598 p2.getNode( "a" ) );
3599 if ( !rt.getName().equals( "r" ) ) {
3602 final Phylogeny p3 = factory
3603 .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
3604 new NHXParser() )[ 0 ];
3605 PhylogenyMethods.preOrderReId( p3 );
3606 final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
3607 p3.getNode( "c" ) );
3608 if ( !bc_3.getName().equals( "bc" ) ) {
3611 final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3612 p3.getNode( "c" ) );
3613 if ( !ac_3.getName().equals( "abc" ) ) {
3616 final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3617 p3.getNode( "d" ) );
3618 if ( !ad_3.getName().equals( "abcde" ) ) {
3621 final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3622 p3.getNode( "f" ) );
3623 if ( !af_3.getName().equals( "abcdef" ) ) {
3626 final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3627 p3.getNode( "g" ) );
3628 if ( !ag_3.getName().equals( "" ) ) {
3631 if ( !ag_3.isRoot() ) {
3634 final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
3635 p3.getNode( "l" ) );
3636 if ( !al_3.getName().equals( "" ) ) {
3639 if ( !al_3.isRoot() ) {
3642 final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
3643 p3.getNode( "l" ) );
3644 if ( !kl_3.getName().equals( "" ) ) {
3647 if ( !kl_3.isRoot() ) {
3650 final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
3651 p3.getNode( "l" ) );
3652 if ( !fl_3.getName().equals( "" ) ) {
3655 if ( !fl_3.isRoot() ) {
3658 final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
3659 p3.getNode( "k" ) );
3660 if ( !gk_3.getName().equals( "ghijk" ) ) {
3663 final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
3664 PhylogenyMethods.preOrderReId( p4 );
3665 final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
3666 p4.getNode( "c" ) );
3667 if ( !r_4.getName().equals( "r" ) ) {
3670 final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
3671 PhylogenyMethods.preOrderReId( p5 );
3672 final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
3673 p5.getNode( "c" ) );
3674 if ( !r_5.getName().equals( "root" ) ) {
3677 final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
3678 PhylogenyMethods.preOrderReId( p6 );
3679 final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
3680 p6.getNode( "a" ) );
3681 if ( !r_6.getName().equals( "rot" ) ) {
3684 final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
3685 PhylogenyMethods.preOrderReId( p7 );
3686 final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
3687 p7.getNode( "e" ) );
3688 if ( !r_7.getName().equals( "rott" ) ) {
3691 final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
3692 p7.getNode( "a" ) );
3693 if ( !r_71.getName().equals( "rott" ) ) {
3696 final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
3697 p7.getNode( "rott" ) );
3698 if ( !r_72.getName().equals( "rott" ) ) {
3701 final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
3702 p7.getNode( "a" ) );
3703 if ( !r_73.getName().equals( "rott" ) ) {
3706 final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
3707 p7.getNode( "rott" ) );
3708 if ( !r_74.getName().equals( "rott" ) ) {
3711 final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
3712 p7.getNode( "e" ) );
3713 if ( !r_75.getName().equals( "e" ) ) {
3717 catch ( final Exception e ) {
3718 e.printStackTrace( System.out );
3724 private static boolean testHmmscanOutputParser() {
3725 final String test_dir = Test.PATH_TO_TEST_DATA;
3727 final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
3728 + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
3730 final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
3731 + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
3732 final List<Protein> proteins = parser2.parse();
3733 if ( parser2.getProteinsEncountered() != 4 ) {
3736 if ( proteins.size() != 4 ) {
3739 if ( parser2.getDomainsEncountered() != 69 ) {
3742 if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
3745 if ( parser2.getDomainsIgnoredDueToEval() != 0 ) {
3748 final Protein p1 = proteins.get( 0 );
3749 if ( p1.getNumberOfProteinDomains() != 15 ) {
3752 if ( p1.getLength() != 850 ) {
3755 final Protein p2 = proteins.get( 1 );
3756 if ( p2.getNumberOfProteinDomains() != 51 ) {
3759 if ( p2.getLength() != 1291 ) {
3762 final Protein p3 = proteins.get( 2 );
3763 if ( p3.getNumberOfProteinDomains() != 2 ) {
3766 final Protein p4 = proteins.get( 3 );
3767 if ( p4.getNumberOfProteinDomains() != 1 ) {
3770 if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
3773 if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
3776 if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
3779 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
3782 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
3785 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) {
3788 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) {
3791 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
3794 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
3798 catch ( final Exception e ) {
3799 e.printStackTrace( System.out );
3805 private static boolean testLastExternalNodeMethods() {
3807 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3808 final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
3809 final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
3810 final PhylogenyNode n1 = t0.getNode( "A" );
3811 if ( n1.isLastExternalNode() ) {
3814 final PhylogenyNode n2 = t0.getNode( "B" );
3815 if ( n2.isLastExternalNode() ) {
3818 final PhylogenyNode n3 = t0.getNode( "C" );
3819 if ( n3.isLastExternalNode() ) {
3822 final PhylogenyNode n4 = t0.getNode( "D" );
3823 if ( !n4.isLastExternalNode() ) {
3827 catch ( final Exception e ) {
3828 e.printStackTrace( System.out );
3834 private static boolean testLevelOrderIterator() {
3836 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3837 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
3838 PhylogenyNodeIterator it0;
3839 for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
3842 for( it0.reset(); it0.hasNext(); ) {
3845 final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
3846 if ( !it.next().getName().equals( "r" ) ) {
3849 if ( !it.next().getName().equals( "ab" ) ) {
3852 if ( !it.next().getName().equals( "cd" ) ) {
3855 if ( !it.next().getName().equals( "A" ) ) {
3858 if ( !it.next().getName().equals( "B" ) ) {
3861 if ( !it.next().getName().equals( "C" ) ) {
3864 if ( !it.next().getName().equals( "D" ) ) {
3867 if ( it.hasNext() ) {
3870 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",
3871 new NHXParser() )[ 0 ];
3872 PhylogenyNodeIterator it2;
3873 for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
3876 for( it2.reset(); it2.hasNext(); ) {
3879 final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
3880 if ( !it3.next().getName().equals( "r" ) ) {
3883 if ( !it3.next().getName().equals( "abc" ) ) {
3886 if ( !it3.next().getName().equals( "defg" ) ) {
3889 if ( !it3.next().getName().equals( "A" ) ) {
3892 if ( !it3.next().getName().equals( "B" ) ) {
3895 if ( !it3.next().getName().equals( "C" ) ) {
3898 if ( !it3.next().getName().equals( "D" ) ) {
3901 if ( !it3.next().getName().equals( "E" ) ) {
3904 if ( !it3.next().getName().equals( "F" ) ) {
3907 if ( !it3.next().getName().equals( "G" ) ) {
3910 if ( !it3.next().getName().equals( "1" ) ) {
3913 if ( !it3.next().getName().equals( "2" ) ) {
3916 if ( !it3.next().getName().equals( "3" ) ) {
3919 if ( !it3.next().getName().equals( "4" ) ) {
3922 if ( !it3.next().getName().equals( "5" ) ) {
3925 if ( !it3.next().getName().equals( "6" ) ) {
3928 if ( !it3.next().getName().equals( "f1" ) ) {
3931 if ( !it3.next().getName().equals( "f2" ) ) {
3934 if ( !it3.next().getName().equals( "f3" ) ) {
3937 if ( !it3.next().getName().equals( "a" ) ) {
3940 if ( !it3.next().getName().equals( "b" ) ) {
3943 if ( !it3.next().getName().equals( "f21" ) ) {
3946 if ( !it3.next().getName().equals( "X" ) ) {
3949 if ( !it3.next().getName().equals( "Y" ) ) {
3952 if ( !it3.next().getName().equals( "Z" ) ) {
3955 if ( it3.hasNext() ) {
3958 final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
3959 PhylogenyNodeIterator it4;
3960 for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
3963 for( it4.reset(); it4.hasNext(); ) {
3966 final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
3967 if ( !it5.next().getName().equals( "r" ) ) {
3970 if ( !it5.next().getName().equals( "A" ) ) {
3973 if ( !it5.next().getName().equals( "B" ) ) {
3976 if ( !it5.next().getName().equals( "C" ) ) {
3979 if ( !it5.next().getName().equals( "D" ) ) {
3982 final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
3983 PhylogenyNodeIterator it6;
3984 for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
3987 for( it6.reset(); it6.hasNext(); ) {
3990 final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
3991 if ( !it7.next().getName().equals( "A" ) ) {
3994 if ( it.hasNext() ) {
3998 catch ( final Exception e ) {
3999 e.printStackTrace( System.out );
4005 private static boolean testMidpointrooting() {
4007 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4008 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",
4009 new NHXParser() )[ 0 ];
4010 if ( !t1.isRooted() ) {
4013 PhylogenyMethods.midpointRoot( t1 );
4014 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4017 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4020 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4023 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4026 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4029 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4032 t1.reRoot( t1.getNode( "A" ) );
4033 PhylogenyMethods.midpointRoot( t1 );
4034 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
4037 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
4040 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
4043 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
4046 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
4049 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
4053 catch ( final Exception e ) {
4054 e.printStackTrace( System.out );
4060 private static boolean testNexusCharactersParsing() {
4062 final NexusCharactersParser parser = new NexusCharactersParser();
4063 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
4065 String[] labels = parser.getCharStateLabels();
4066 if ( labels.length != 7 ) {
4069 if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4072 if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4075 if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4078 if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4081 if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4084 if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4087 if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4090 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4092 labels = parser.getCharStateLabels();
4093 if ( labels.length != 7 ) {
4096 if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4099 if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4102 if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4105 if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4108 if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4111 if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4114 if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4118 catch ( final Exception e ) {
4119 e.printStackTrace( System.out );
4125 private static boolean testNexusMatrixParsing() {
4127 final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
4128 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
4130 final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
4131 if ( m.getNumberOfCharacters() != 9 ) {
4134 if ( m.getNumberOfIdentifiers() != 5 ) {
4137 if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
4140 if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
4143 if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
4146 if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
4149 if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
4152 if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
4155 if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
4158 // if ( labels.length != 7 ) {
4161 // if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4164 // if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4167 // if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4170 // if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4173 // if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4176 // if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4179 // if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4182 // parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
4184 // labels = parser.getCharStateLabels();
4185 // if ( labels.length != 7 ) {
4188 // if ( !labels[ 0 ].equals( "14-3-3" ) ) {
4191 // if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
4194 // if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
4197 // if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
4200 // if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
4203 // if ( !labels[ 5 ].equals( "3-HAO" ) ) {
4206 // if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
4210 catch ( final Exception e ) {
4211 e.printStackTrace( System.out );
4217 private static boolean testNexusTreeParsing() {
4219 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4220 final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
4221 Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
4222 if ( phylogenies.length != 1 ) {
4225 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
4228 if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4232 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
4233 if ( phylogenies.length != 1 ) {
4236 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4239 if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
4243 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
4244 if ( phylogenies.length != 1 ) {
4247 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4250 if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
4253 if ( phylogenies[ 0 ].isRooted() ) {
4257 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
4258 if ( phylogenies.length != 18 ) {
4261 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
4264 if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
4267 if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
4270 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
4273 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
4276 if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
4279 if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
4282 if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
4285 if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
4288 if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
4291 if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
4294 if ( phylogenies[ 8 ].isRooted() ) {
4297 if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
4300 if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
4303 if ( !phylogenies[ 9 ].isRooted() ) {
4306 if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
4309 if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
4312 if ( !phylogenies[ 10 ].isRooted() ) {
4315 if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
4318 if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
4321 if ( phylogenies[ 11 ].isRooted() ) {
4324 if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
4327 if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
4330 if ( !phylogenies[ 12 ].isRooted() ) {
4333 if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
4336 if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
4339 if ( !phylogenies[ 13 ].isRooted() ) {
4342 if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
4345 if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
4348 if ( !phylogenies[ 14 ].isRooted() ) {
4351 if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
4354 if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
4357 if ( phylogenies[ 15 ].isRooted() ) {
4360 if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
4363 if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
4366 if ( !phylogenies[ 16 ].isRooted() ) {
4369 if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
4372 if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
4375 if ( phylogenies[ 17 ].isRooted() ) {
4378 if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
4382 catch ( final Exception e ) {
4383 e.printStackTrace( System.out );
4389 private static boolean testNexusTreeParsingTranslating() {
4391 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4392 final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
4393 Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
4394 if ( phylogenies.length != 1 ) {
4397 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4400 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
4403 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4406 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4409 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4410 .equals( "Aranaeus" ) ) {
4414 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
4415 if ( phylogenies.length != 3 ) {
4418 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4421 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
4424 if ( phylogenies[ 0 ].isRooted() ) {
4427 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4430 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4433 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4434 .equals( "Aranaeus" ) ) {
4437 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
4440 if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
4443 if ( phylogenies[ 1 ].isRooted() ) {
4446 if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4449 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4452 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4453 .equals( "Aranaeus" ) ) {
4456 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
4459 if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
4462 if ( !phylogenies[ 2 ].isRooted() ) {
4465 if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4468 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4471 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4472 .equals( "Aranaeus" ) ) {
4476 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
4477 if ( phylogenies.length != 3 ) {
4480 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
4483 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
4486 if ( phylogenies[ 0 ].isRooted() ) {
4489 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4492 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4495 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4496 .equals( "Aranaeus" ) ) {
4499 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
4502 if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
4505 if ( phylogenies[ 1 ].isRooted() ) {
4508 if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4511 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4514 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4515 .equals( "Aranaeus" ) ) {
4518 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
4521 if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
4524 if ( !phylogenies[ 2 ].isRooted() ) {
4527 if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
4530 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
4533 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
4534 .equals( "Aranaeus" ) ) {
4538 catch ( final Exception e ) {
4539 e.printStackTrace( System.out );
4545 private static boolean testNHParsing() {
4547 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4548 final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
4549 if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
4552 final NHXParser nhxp = new NHXParser();
4553 nhxp.setTaxonomyExtraction( PhylogenyMethods.TAXONOMY_EXTRACTION.NO );
4554 nhxp.setReplaceUnderscores( true );
4555 final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
4556 if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
4559 if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
4562 final Phylogeny p1b = factory
4563 .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 ",
4564 new NHXParser() )[ 0 ];
4565 if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
4568 if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
4571 final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
4572 final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
4573 final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
4574 final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
4575 final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
4576 final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
4577 final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
4578 final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
4579 final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
4580 final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
4581 final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1 3 ; \n)\t ( \n ;"
4582 + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
4583 + "; ; ( \t\n\r\b; G ;, ;H ;1 3; ) ; ; ;",
4585 if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
4588 if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
4591 if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
4594 if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
4597 final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
4598 final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
4599 final String p16_S = "((A,B),C)";
4600 final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
4601 if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
4604 final String p17_S = "(C,(A,B))";
4605 final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
4606 if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
4609 final String p18_S = "((A,B),(C,D))";
4610 final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
4611 if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
4614 final String p19_S = "(((A,B),C),D)";
4615 final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
4616 if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
4619 final String p20_S = "(A,(B,(C,D)))";
4620 final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
4621 if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
4624 final String p21_S = "(A,(B,(C,(D,E))))";
4625 final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
4626 if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
4629 final String p22_S = "((((A,B),C),D),E)";
4630 final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
4631 if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
4634 final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
4635 final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
4636 if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
4639 final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
4640 final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
4641 if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
4644 final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
4645 final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
4646 final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
4647 if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
4650 if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
4653 final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
4654 + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
4655 + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
4656 + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
4657 + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
4658 + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
4659 + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
4660 + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
4661 final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
4662 if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
4665 final String p26_S = "(A,B)ab";
4666 final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
4667 if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
4670 final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
4671 final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
4673 if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
4676 final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
4677 final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
4678 final String p28_S3 = "(A,B)ab";
4679 final String p28_S4 = "((((A,B),C),D),;E;)";
4680 final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
4682 if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
4685 if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
4688 if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
4691 if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
4694 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";
4695 final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
4696 if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
4699 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";
4700 final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
4701 if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
4704 final String p32_S = " ; ; \n \t \b \f \r ;;;;;; ";
4705 final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
4706 if ( ( p32.length != 1 ) || !p32[ 0 ].isEmpty() ) {
4709 final String p33_S = "A";
4710 final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
4711 if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
4714 final String p34_S = "B;";
4715 final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
4716 if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
4719 final String p35_S = "B:0.2";
4720 final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
4721 if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
4724 final String p36_S = "(A)";
4725 final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
4726 if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
4729 final String p37_S = "((A))";
4730 final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
4731 if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
4734 final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
4735 final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
4736 if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
4739 final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
4740 final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
4741 if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
4744 final String p40_S = "(A,B,C)";
4745 final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
4746 if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
4749 final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
4750 final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
4751 if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
4754 final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
4755 final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
4756 if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
4759 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)";
4760 final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
4761 if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
4764 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)))";
4765 final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
4766 if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
4769 final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
4770 final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
4771 if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
4774 final String p46_S = "";
4775 final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
4776 if ( ( p46.length != 1 ) || !p46[ 0 ].isEmpty() ) {
4779 final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
4780 if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
4783 final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
4784 if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
4787 final Phylogeny p49 = factory
4788 .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
4789 new NHXParser() )[ 0 ];
4790 if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
4793 final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
4794 if ( p50.getNode( "A" ) == null ) {
4797 if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
4798 .equals( "((A,B)ab:2.0[88],C);" ) ) {
4801 if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
4804 if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
4805 .equals( "((A,B)88:2.0,C);" ) ) {
4808 final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
4809 if ( p51.getNode( "A(A" ) == null ) {
4812 final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
4813 if ( p52.getNode( "A(A" ) == null ) {
4816 final Phylogeny p53 = factory
4817 .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
4818 new NHXParser() )[ 0 ];
4819 if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
4823 final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
4824 if ( p54.getNode( "A" ) == null ) {
4827 if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
4828 .equals( "((A,B)[88],C);" ) ) {
4832 catch ( final Exception e ) {
4833 e.printStackTrace( System.out );
4839 private static boolean testNHXconversion() {
4841 final PhylogenyNode n1 = new PhylogenyNode();
4842 final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
4843 final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
4844 final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
4845 final PhylogenyNode n5 = PhylogenyNode
4846 .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1:W=2:C=10.20.30:XN=S=tag1=value1=unit1]" );
4847 final PhylogenyNode n6 = PhylogenyNode
4848 .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1:W=2:C=0.0.0:XN=B=bool_tag=T]" );
4849 if ( !n1.toNewHampshireX().equals( "" ) ) {
4852 if ( !n2.toNewHampshireX().equals( "" ) ) {
4855 if ( !n3.toNewHampshireX().equals( "n3" ) ) {
4858 if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
4861 if ( !n5.toNewHampshireX()
4862 .equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:XN=S=tag1=value1=unit1:B=56:W=2.0:C=10.20.30]" ) ) {
4865 if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:XN=B=bool_tag=T:B=100:W=2.0:C=0.0.0]" ) ) {
4869 catch ( final Exception e ) {
4870 e.printStackTrace( System.out );
4876 private static boolean testNHXNodeParsing() {
4878 final PhylogenyNode n1 = new PhylogenyNode();
4879 final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
4880 final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
4881 final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
4882 final PhylogenyNode n5 = PhylogenyNode
4883 .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]" );
4884 if ( !n3.getName().equals( "n3" ) ) {
4887 if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
4890 if ( n3.isDuplication() ) {
4893 if ( n3.isHasAssignedEvent() ) {
4896 if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
4899 if ( !n4.getName().equals( "n4" ) ) {
4902 if ( n4.getDistanceToParent() != 0.01 ) {
4905 if ( !n5.getName().equals( "n5" ) ) {
4908 if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
4911 if ( n5.getDistanceToParent() != 0.1 ) {
4914 if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
4917 if ( !n5.isDuplication() ) {
4920 if ( !n5.isHasAssignedEvent() ) {
4923 if ( PhylogenyMethods.getBranchWidthValue( n5 ) != 2 ) {
4926 if ( n5.getNodeData().getProperties().getPropertyRefs().length != 2 ) {
4929 final PhylogenyNode n8 = PhylogenyNode
4930 .createInstanceFromNhxString( "n8_ECOLI/12:0.01",
4931 PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4932 if ( !n8.getName().equals( "n8_ECOLI/12" ) ) {
4935 if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
4938 final PhylogenyNode n9 = PhylogenyNode
4939 .createInstanceFromNhxString( "n9_ECOLI/12=12:0.01",
4940 PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4941 if ( !n9.getName().equals( "n9_ECOLI/12=12" ) ) {
4944 if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
4947 final PhylogenyNode n10 = PhylogenyNode
4948 .createInstanceFromNhxString( "n10.ECOLI", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4949 if ( !n10.getName().equals( "n10.ECOLI" ) ) {
4952 final PhylogenyNode n20 = PhylogenyNode
4953 .createInstanceFromNhxString( "n20_ECOLI/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4954 if ( !n20.getName().equals( "n20_ECOLI/1-2" ) ) {
4957 if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
4960 final PhylogenyNode n20x = PhylogenyNode
4961 .createInstanceFromNhxString( "n20_ECOL1/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.YES );
4962 if ( !n20x.getName().equals( "n20_ECOL1/1-2" ) ) {
4965 if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
4968 final PhylogenyNode n20xx = PhylogenyNode
4969 .createInstanceFromNhxString( "n20_eCOL1/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4970 if ( !n20xx.getName().equals( "n20_eCOL1/1-2" ) ) {
4973 if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
4976 final PhylogenyNode n20xxx = PhylogenyNode
4977 .createInstanceFromNhxString( "n20_ecoli/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4978 if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
4981 if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
4984 final PhylogenyNode n20xxxx = PhylogenyNode
4985 .createInstanceFromNhxString( "n20_Ecoli/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
4986 if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
4989 if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
4992 final PhylogenyNode n21 = PhylogenyNode
4993 .createInstanceFromNhxString( "n21_PIG", PhylogenyMethods.TAXONOMY_EXTRACTION.YES );
4994 if ( !n21.getName().equals( "n21_PIG" ) ) {
4997 if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
5000 final PhylogenyNode n21x = PhylogenyNode
5001 .createInstanceFromNhxString( "n21_PIG", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5002 if ( !n21x.getName().equals( "n21_PIG" ) ) {
5005 if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
5008 final PhylogenyNode n22 = PhylogenyNode
5009 .createInstanceFromNhxString( "n22/PIG", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5010 if ( !n22.getName().equals( "n22/PIG" ) ) {
5013 if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
5016 final PhylogenyNode n23 = PhylogenyNode
5017 .createInstanceFromNhxString( "n23/PIG_1", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5018 if ( !n23.getName().equals( "n23/PIG_1" ) ) {
5021 if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
5024 final PhylogenyNode a = PhylogenyNode
5025 .createInstanceFromNhxString( "n10_ECOLI/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5026 if ( !a.getName().equals( "n10_ECOLI/1-2" ) ) {
5029 if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
5032 final PhylogenyNode b = PhylogenyNode
5033 .createInstanceFromNhxString( "n10_ECOLI1/1-2",
5034 PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5035 if ( !b.getName().equals( "n10_ECOLI1/1-2" ) ) {
5038 if ( !PhylogenyMethods.getSpecies( b ).equals( "ECOLI" ) ) {
5041 final PhylogenyNode c = PhylogenyNode
5042 .createInstanceFromNhxString( "n10_RATAF12/1000-2000",
5043 PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5044 if ( !c.getName().equals( "n10_RATAF12/1000-2000" ) ) {
5047 if ( !PhylogenyMethods.getSpecies( c ).equals( "RATAF" ) ) {
5050 final PhylogenyNode c1 = PhylogenyNode
5051 .createInstanceFromNhxString( "n10_BOVIN_1/1000-2000",
5052 PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5053 if ( !c1.getName().equals( "n10_BOVIN_1/1000-2000" ) ) {
5056 if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
5059 final PhylogenyNode c2 = PhylogenyNode
5060 .createInstanceFromNhxString( "n10_Bovin_1/1000-2000",
5061 PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5062 if ( !c2.getName().equals( "n10_Bovin_1/1000-2000" ) ) {
5065 if ( !PhylogenyMethods.getSpecies( c2 ).equals( "" ) ) {
5068 final PhylogenyNode d = PhylogenyNode
5069 .createInstanceFromNhxString( "n10_RAT1/1-2", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5070 if ( !d.getName().equals( "n10_RAT1/1-2" ) ) {
5073 if ( !PhylogenyMethods.getSpecies( d ).equals( "RAT" ) ) {
5076 final PhylogenyNode e = PhylogenyNode
5077 .createInstanceFromNhxString( "n10_RAT1", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5078 if ( !e.getName().equals( "n10_RAT1" ) ) {
5081 if ( !ForesterUtil.isEmpty( PhylogenyMethods.getSpecies( e ) ) ) {
5084 final PhylogenyNode e2 = PhylogenyNode
5085 .createInstanceFromNhxString( "n10_RAT1", PhylogenyMethods.TAXONOMY_EXTRACTION.YES );
5086 if ( !e2.getName().equals( "n10_RAT1" ) ) {
5089 if ( !PhylogenyMethods.getSpecies( e2 ).equals( "RAT" ) ) {
5092 final PhylogenyNode e3 = PhylogenyNode
5093 .createInstanceFromNhxString( "n10_RAT~", PhylogenyMethods.TAXONOMY_EXTRACTION.YES );
5094 if ( !e3.getName().equals( "n10_RAT~" ) ) {
5097 if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
5100 final PhylogenyNode n11 = PhylogenyNode
5101 .createInstanceFromNhxString( "n111111_ECOLI/jdj:0.4",
5102 PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5103 if ( !n11.getName().equals( "n111111_ECOLI/jdj" ) ) {
5106 if ( n11.getDistanceToParent() != 0.4 ) {
5109 if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
5112 final PhylogenyNode n12 = PhylogenyNode
5113 .createInstanceFromNhxString( "n111111-ECOLI---/jdj:0.4",
5114 PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5115 if ( !n12.getName().equals( "n111111-ECOLI---/jdj" ) ) {
5118 if ( n12.getDistanceToParent() != 0.4 ) {
5121 if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
5124 final PhylogenyNode m = PhylogenyNode
5125 .createInstanceFromNhxString( "n10_MOUSEa", PhylogenyMethods.TAXONOMY_EXTRACTION.YES );
5126 if ( !m.getName().equals( "n10_MOUSEa" ) ) {
5129 if ( !PhylogenyMethods.getSpecies( m ).equals( "MOUSE" ) ) {
5132 final PhylogenyNode o = PhylogenyNode
5133 .createInstanceFromNhxString( "n10_MOUSE_", PhylogenyMethods.TAXONOMY_EXTRACTION.YES );
5134 if ( !o.getName().equals( "n10_MOUSE_" ) ) {
5137 if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
5140 final Property tvu1 = n5.getNodeData().getProperties().getProperty( "tag1" );
5141 final Property tvu3 = n5.getNodeData().getProperties().getProperty( "tag3" );
5142 if ( !tvu1.getRef().equals( "tag1" ) ) {
5145 if ( !tvu1.getDataType().equals( "xsd:string" ) ) {
5148 if ( !tvu1.getUnit().equals( "unit1" ) ) {
5151 if ( !tvu1.getValue().equals( "value1" ) ) {
5154 if ( !tvu3.getRef().equals( "tag3" ) ) {
5157 if ( !tvu3.getDataType().equals( "xsd:string" ) ) {
5160 if ( !tvu3.getUnit().equals( "unit3" ) ) {
5163 if ( !tvu3.getValue().equals( "value3" ) ) {
5166 if ( n1.getName().compareTo( "" ) != 0 ) {
5169 if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
5172 if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
5175 if ( n2.getName().compareTo( "" ) != 0 ) {
5178 if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
5181 if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
5184 final PhylogenyNode n00 = PhylogenyNode
5185 .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:ID=node_identifier:S=Ecoli:D=N:Co=N:B=100:T=1:On=100:SOn=100:SNn=100:W=2:C=0.0.0:XN=U=url_tag=www.yahoo.com]" );
5186 if ( !n00.getNodeData().getNodeIdentifier().getValue().equals( "node_identifier" ) ) {
5189 if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
5192 if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
5195 if ( !n00.getNodeData().getProperties().getProperty( "url_tag" ).getRef().equals( "url_tag" ) ) {
5198 if ( n00.getNodeData().getProperties().getProperty( "url_tag" ).getAppliesTo() != Property.AppliesTo.NODE ) {
5201 if ( !n00.getNodeData().getProperties().getProperty( "url_tag" ).getDataType().equals( "xsd:anyURI" ) ) {
5204 if ( !n00.getNodeData().getProperties().getProperty( "url_tag" ).getValue().equals( "www.yahoo.com" ) ) {
5207 if ( !n00.getNodeData().getProperties().getProperty( "url_tag" ).getUnit().equals( "" ) ) {
5210 final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
5211 if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
5214 final PhylogenyNode nx2 = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:G=gene_2]" );
5215 if ( !nx2.getNodeData().getSequence().getName().equals( "gene_2" ) ) {
5218 final PhylogenyNode n13 = PhylogenyNode
5219 .createInstanceFromNhxString( "blah_12345/1-2",
5220 PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5221 if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
5224 if ( !PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
5227 final PhylogenyNode n14 = PhylogenyNode
5228 .createInstanceFromNhxString( "blah_12X45/1-2",
5229 PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5230 if ( !n14.getName().equals( "blah_12X45/1-2" ) ) {
5233 if ( !PhylogenyMethods.getSpecies( n14 ).equals( "12X45" ) ) {
5236 final PhylogenyNode n15 = PhylogenyNode
5237 .createInstanceFromNhxString( "something_wicked[123]",
5238 PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5239 if ( !n15.getName().equals( "something_wicked" ) ) {
5242 if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
5245 if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
5248 final PhylogenyNode n16 = PhylogenyNode
5249 .createInstanceFromNhxString( "something_wicked2[9]",
5250 PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5251 if ( !n16.getName().equals( "something_wicked2" ) ) {
5254 if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
5257 if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
5260 final PhylogenyNode n17 = PhylogenyNode
5261 .createInstanceFromNhxString( "something_wicked3[a]",
5262 PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5263 if ( !n17.getName().equals( "something_wicked3" ) ) {
5266 if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
5269 final PhylogenyNode n18 = PhylogenyNode
5270 .createInstanceFromNhxString( ":0.5[91]", PhylogenyMethods.TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
5271 if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
5274 if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
5277 if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
5281 catch ( final Exception e ) {
5282 e.printStackTrace( System.out );
5288 private static boolean testNHXParsing() {
5290 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5291 final Phylogeny p1 = factory.create( "(A [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
5292 if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
5295 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]";
5296 final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
5297 if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
5300 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]";
5301 final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
5302 if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
5305 final Phylogeny[] p3 = factory
5306 .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]",
5308 if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
5311 final Phylogeny[] p4 = factory
5312 .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(]",
5314 if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
5317 final Phylogeny[] p5 = factory
5318 .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(((]",
5320 if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
5323 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)";
5324 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)";
5325 final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
5326 if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
5329 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)))";
5330 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)))";
5331 final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
5332 if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
5335 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]) ))[,,, ])))))))";
5336 final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
5337 final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
5338 if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
5341 final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
5342 if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
5345 final Phylogeny p10 = factory
5346 .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]",
5347 new NHXParser() )[ 0 ];
5348 if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
5352 catch ( final Exception e ) {
5353 e.printStackTrace( System.out );
5359 private static boolean testNHXParsingQuotes() {
5361 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5362 final NHXParser p = new NHXParser();
5363 final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
5364 if ( phylogenies_0.length != 5 ) {
5367 final Phylogeny phy = phylogenies_0[ 4 ];
5368 if ( phy.getNumberOfExternalNodes() != 7 ) {
5371 if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
5374 if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
5377 if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
5378 .getScientificName().equals( "hsapiens" ) ) {
5381 if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
5384 if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
5387 if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
5390 if ( phy.getNodes( "noquotes" ).size() != 1 ) {
5393 if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
5396 final NHXParser p1p = new NHXParser();
5397 p1p.setIgnoreQuotes( true );
5398 final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
5399 if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
5402 final NHXParser p2p = new NHXParser();
5403 p1p.setIgnoreQuotes( false );
5404 final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
5405 if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
5408 final NHXParser p3p = new NHXParser();
5409 p3p.setIgnoreQuotes( false );
5410 final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
5411 if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
5414 final NHXParser p4p = new NHXParser();
5415 p4p.setIgnoreQuotes( false );
5416 final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
5417 if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
5420 final Phylogeny p10 = factory
5421 .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]",
5422 new NHXParser() )[ 0 ];
5423 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]";
5424 if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
5427 final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
5428 if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
5432 final Phylogeny p12 = factory
5433 .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]",
5434 new NHXParser() )[ 0 ];
5435 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]";
5436 if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
5439 final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
5440 if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
5443 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;";
5444 if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
5447 final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
5448 if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
5452 catch ( final Exception e ) {
5453 e.printStackTrace( System.out );
5459 private static boolean testNHXParsingMB() {
5461 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5462 final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
5463 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
5464 + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
5465 + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
5466 + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
5467 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
5468 + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
5469 + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
5470 + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
5471 if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
5474 if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
5477 if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
5478 0.1100000000000000e+00 ) ) {
5481 if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
5484 if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
5487 final Phylogeny p2 = factory
5488 .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
5489 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
5490 + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
5491 + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
5492 + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
5493 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
5494 + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
5495 + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
5496 + "7.369400000000000e-02}])",
5497 new NHXParser() )[ 0 ];
5498 if ( p2.getNode( "1" ) == null ) {
5501 if ( p2.getNode( "2" ) == null ) {
5505 catch ( final Exception e ) {
5506 e.printStackTrace( System.out );
5513 private static boolean testPhylogenyBranch() {
5515 final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
5516 final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
5517 final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
5518 final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
5519 if ( !a1b1.equals( a1b1 ) ) {
5522 if ( !a1b1.equals( b1a1 ) ) {
5525 if ( !b1a1.equals( a1b1 ) ) {
5528 final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
5529 final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
5530 final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
5531 if ( a1_b1.equals( b1_a1 ) ) {
5534 if ( a1_b1.equals( a1_b1_ ) ) {
5537 final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
5538 if ( !a1_b1.equals( b1_a1_ ) ) {
5541 if ( a1_b1_.equals( b1_a1_ ) ) {
5544 if ( !a1_b1_.equals( b1_a1 ) ) {
5548 catch ( final Exception e ) {
5549 e.printStackTrace( System.out );
5555 private static boolean testPhyloXMLparsingOfDistributionElement() {
5557 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5558 PhyloXmlParser xml_parser = null;
5560 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
5562 catch ( final Exception e ) {
5563 // Do nothing -- means were not running from jar.
5565 if ( xml_parser == null ) {
5566 xml_parser = new PhyloXmlParser();
5567 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
5568 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
5571 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
5574 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
5576 if ( xml_parser.getErrorCount() > 0 ) {
5577 System.out.println( xml_parser.getErrorMessages().toString() );
5580 if ( phylogenies_0.length != 1 ) {
5583 final Phylogeny t1 = phylogenies_0[ 0 ];
5584 PhylogenyNode n = null;
5585 Distribution d = null;
5586 n = t1.getNode( "root node" );
5587 if ( !n.getNodeData().isHasDistribution() ) {
5590 if ( n.getNodeData().getDistributions().size() != 1 ) {
5593 d = n.getNodeData().getDistribution();
5594 if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
5597 if ( d.getPoints().size() != 1 ) {
5600 if ( d.getPolygons() != null ) {
5603 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
5606 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
5609 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
5612 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
5615 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
5618 n = t1.getNode( "node a" );
5619 if ( !n.getNodeData().isHasDistribution() ) {
5622 if ( n.getNodeData().getDistributions().size() != 2 ) {
5625 d = n.getNodeData().getDistribution( 1 );
5626 if ( !d.getDesc().equals( "San Diego" ) ) {
5629 if ( d.getPoints().size() != 1 ) {
5632 if ( d.getPolygons() != null ) {
5635 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
5638 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
5641 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
5644 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
5647 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
5650 n = t1.getNode( "node bb" );
5651 if ( !n.getNodeData().isHasDistribution() ) {
5654 if ( n.getNodeData().getDistributions().size() != 1 ) {
5657 d = n.getNodeData().getDistribution( 0 );
5658 if ( d.getPoints().size() != 3 ) {
5661 if ( d.getPolygons().size() != 2 ) {
5664 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
5667 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
5670 if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
5673 if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
5676 if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
5679 if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
5682 Polygon p = d.getPolygons().get( 0 );
5683 if ( p.getPoints().size() != 3 ) {
5686 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
5689 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
5692 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
5695 if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
5698 if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
5701 if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
5704 p = d.getPolygons().get( 1 );
5705 if ( p.getPoints().size() != 3 ) {
5708 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
5711 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
5714 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
5718 final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
5719 final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
5720 if ( rt.length != 1 ) {
5723 final Phylogeny t1_rt = rt[ 0 ];
5724 n = t1_rt.getNode( "root node" );
5725 if ( !n.getNodeData().isHasDistribution() ) {
5728 if ( n.getNodeData().getDistributions().size() != 1 ) {
5731 d = n.getNodeData().getDistribution();
5732 if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
5735 if ( d.getPoints().size() != 1 ) {
5738 if ( d.getPolygons() != null ) {
5741 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
5744 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
5747 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
5750 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
5753 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
5756 n = t1_rt.getNode( "node a" );
5757 if ( !n.getNodeData().isHasDistribution() ) {
5760 if ( n.getNodeData().getDistributions().size() != 2 ) {
5763 d = n.getNodeData().getDistribution( 1 );
5764 if ( !d.getDesc().equals( "San Diego" ) ) {
5767 if ( d.getPoints().size() != 1 ) {
5770 if ( d.getPolygons() != null ) {
5773 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
5776 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
5779 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
5782 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
5785 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
5788 n = t1_rt.getNode( "node bb" );
5789 if ( !n.getNodeData().isHasDistribution() ) {
5792 if ( n.getNodeData().getDistributions().size() != 1 ) {
5795 d = n.getNodeData().getDistribution( 0 );
5796 if ( d.getPoints().size() != 3 ) {
5799 if ( d.getPolygons().size() != 2 ) {
5802 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
5805 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
5808 if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
5811 if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
5814 if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
5817 if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
5820 p = d.getPolygons().get( 0 );
5821 if ( p.getPoints().size() != 3 ) {
5824 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
5827 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
5830 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
5833 if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
5836 if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
5839 if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
5842 p = d.getPolygons().get( 1 );
5843 if ( p.getPoints().size() != 3 ) {
5846 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
5849 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
5852 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
5856 catch ( final Exception e ) {
5857 e.printStackTrace( System.out );
5863 private static boolean testPostOrderIterator() {
5865 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5866 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5867 PhylogenyNodeIterator it0;
5868 for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
5871 for( it0.reset(); it0.hasNext(); ) {
5874 final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
5875 final PhylogenyNodeIterator it = t1.iteratorPostorder();
5876 if ( !it.next().getName().equals( "A" ) ) {
5879 if ( !it.next().getName().equals( "B" ) ) {
5882 if ( !it.next().getName().equals( "ab" ) ) {
5885 if ( !it.next().getName().equals( "C" ) ) {
5888 if ( !it.next().getName().equals( "D" ) ) {
5891 if ( !it.next().getName().equals( "cd" ) ) {
5894 if ( !it.next().getName().equals( "abcd" ) ) {
5897 if ( !it.next().getName().equals( "E" ) ) {
5900 if ( !it.next().getName().equals( "F" ) ) {
5903 if ( !it.next().getName().equals( "ef" ) ) {
5906 if ( !it.next().getName().equals( "G" ) ) {
5909 if ( !it.next().getName().equals( "H" ) ) {
5912 if ( !it.next().getName().equals( "gh" ) ) {
5915 if ( !it.next().getName().equals( "efgh" ) ) {
5918 if ( !it.next().getName().equals( "r" ) ) {
5921 if ( it.hasNext() ) {
5925 catch ( final Exception e ) {
5926 e.printStackTrace( System.out );
5932 private static boolean testPreOrderIterator() {
5934 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5935 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5936 PhylogenyNodeIterator it0;
5937 for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
5940 for( it0.reset(); it0.hasNext(); ) {
5943 PhylogenyNodeIterator it = t0.iteratorPreorder();
5944 if ( !it.next().getName().equals( "r" ) ) {
5947 if ( !it.next().getName().equals( "ab" ) ) {
5950 if ( !it.next().getName().equals( "A" ) ) {
5953 if ( !it.next().getName().equals( "B" ) ) {
5956 if ( !it.next().getName().equals( "cd" ) ) {
5959 if ( !it.next().getName().equals( "C" ) ) {
5962 if ( !it.next().getName().equals( "D" ) ) {
5965 if ( it.hasNext() ) {
5968 final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
5969 it = t1.iteratorPreorder();
5970 if ( !it.next().getName().equals( "r" ) ) {
5973 if ( !it.next().getName().equals( "abcd" ) ) {
5976 if ( !it.next().getName().equals( "ab" ) ) {
5979 if ( !it.next().getName().equals( "A" ) ) {
5982 if ( !it.next().getName().equals( "B" ) ) {
5985 if ( !it.next().getName().equals( "cd" ) ) {
5988 if ( !it.next().getName().equals( "C" ) ) {
5991 if ( !it.next().getName().equals( "D" ) ) {
5994 if ( !it.next().getName().equals( "efgh" ) ) {
5997 if ( !it.next().getName().equals( "ef" ) ) {
6000 if ( !it.next().getName().equals( "E" ) ) {
6003 if ( !it.next().getName().equals( "F" ) ) {
6006 if ( !it.next().getName().equals( "gh" ) ) {
6009 if ( !it.next().getName().equals( "G" ) ) {
6012 if ( !it.next().getName().equals( "H" ) ) {
6015 if ( it.hasNext() ) {
6019 catch ( final Exception e ) {
6020 e.printStackTrace( System.out );
6026 private static boolean testPropertiesMap() {
6028 final PropertiesMap pm = new PropertiesMap();
6029 final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
6030 final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
6031 final Property p2 = new Property( "something:else",
6033 "improbable:research",
6036 pm.addProperty( p0 );
6037 pm.addProperty( p1 );
6038 pm.addProperty( p2 );
6039 if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
6042 if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
6045 if ( pm.getProperties().size() != 3 ) {
6048 if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
6051 if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
6054 if ( pm.getProperties().size() != 3 ) {
6057 pm.removeProperty( "dimensions:diameter" );
6058 if ( pm.getProperties().size() != 2 ) {
6061 if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
6064 if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
6068 catch ( final Exception e ) {
6069 e.printStackTrace( System.out );
6075 private static boolean testReIdMethods() {
6077 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6078 final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
6079 final int count = PhylogenyNode.getNodeCount();
6081 if ( p.getNode( "r" ).getId() != count ) {
6084 if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
6087 if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
6090 if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
6093 if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
6096 if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
6099 if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
6102 if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
6105 if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
6108 if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
6111 if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
6114 if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
6117 if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
6120 if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
6123 if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
6127 catch ( final Exception e ) {
6128 e.printStackTrace( System.out );
6134 private static boolean testRerooting() {
6136 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6137 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",
6138 new NHXParser() )[ 0 ];
6139 if ( !t1.isRooted() ) {
6142 t1.reRoot( t1.getNode( "D" ) );
6143 t1.reRoot( t1.getNode( "CD" ) );
6144 t1.reRoot( t1.getNode( "A" ) );
6145 t1.reRoot( t1.getNode( "B" ) );
6146 t1.reRoot( t1.getNode( "AB" ) );
6147 t1.reRoot( t1.getNode( "D" ) );
6148 t1.reRoot( t1.getNode( "C" ) );
6149 t1.reRoot( t1.getNode( "CD" ) );
6150 t1.reRoot( t1.getNode( "A" ) );
6151 t1.reRoot( t1.getNode( "B" ) );
6152 t1.reRoot( t1.getNode( "AB" ) );
6153 t1.reRoot( t1.getNode( "D" ) );
6154 t1.reRoot( t1.getNode( "D" ) );
6155 t1.reRoot( t1.getNode( "C" ) );
6156 t1.reRoot( t1.getNode( "A" ) );
6157 t1.reRoot( t1.getNode( "B" ) );
6158 t1.reRoot( t1.getNode( "AB" ) );
6159 t1.reRoot( t1.getNode( "C" ) );
6160 t1.reRoot( t1.getNode( "D" ) );
6161 t1.reRoot( t1.getNode( "CD" ) );
6162 t1.reRoot( t1.getNode( "D" ) );
6163 t1.reRoot( t1.getNode( "A" ) );
6164 t1.reRoot( t1.getNode( "B" ) );
6165 t1.reRoot( t1.getNode( "AB" ) );
6166 t1.reRoot( t1.getNode( "C" ) );
6167 t1.reRoot( t1.getNode( "D" ) );
6168 t1.reRoot( t1.getNode( "CD" ) );
6169 t1.reRoot( t1.getNode( "D" ) );
6170 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6173 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6176 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6179 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
6182 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
6185 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
6188 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",
6189 new NHXParser() )[ 0 ];
6190 t2.reRoot( t2.getNode( "A" ) );
6191 t2.reRoot( t2.getNode( "D" ) );
6192 t2.reRoot( t2.getNode( "ABC" ) );
6193 t2.reRoot( t2.getNode( "A" ) );
6194 t2.reRoot( t2.getNode( "B" ) );
6195 t2.reRoot( t2.getNode( "D" ) );
6196 t2.reRoot( t2.getNode( "C" ) );
6197 t2.reRoot( t2.getNode( "ABC" ) );
6198 t2.reRoot( t2.getNode( "A" ) );
6199 t2.reRoot( t2.getNode( "B" ) );
6200 t2.reRoot( t2.getNode( "AB" ) );
6201 t2.reRoot( t2.getNode( "AB" ) );
6202 t2.reRoot( t2.getNode( "D" ) );
6203 t2.reRoot( t2.getNode( "C" ) );
6204 t2.reRoot( t2.getNode( "B" ) );
6205 t2.reRoot( t2.getNode( "AB" ) );
6206 t2.reRoot( t2.getNode( "D" ) );
6207 t2.reRoot( t2.getNode( "D" ) );
6208 t2.reRoot( t2.getNode( "ABC" ) );
6209 t2.reRoot( t2.getNode( "A" ) );
6210 t2.reRoot( t2.getNode( "B" ) );
6211 t2.reRoot( t2.getNode( "AB" ) );
6212 t2.reRoot( t2.getNode( "D" ) );
6213 t2.reRoot( t2.getNode( "C" ) );
6214 t2.reRoot( t2.getNode( "ABC" ) );
6215 t2.reRoot( t2.getNode( "A" ) );
6216 t2.reRoot( t2.getNode( "B" ) );
6217 t2.reRoot( t2.getNode( "AB" ) );
6218 t2.reRoot( t2.getNode( "D" ) );
6219 t2.reRoot( t2.getNode( "D" ) );
6220 t2.reRoot( t2.getNode( "C" ) );
6221 t2.reRoot( t2.getNode( "A" ) );
6222 t2.reRoot( t2.getNode( "B" ) );
6223 t2.reRoot( t2.getNode( "AB" ) );
6224 t2.reRoot( t2.getNode( "C" ) );
6225 t2.reRoot( t2.getNode( "D" ) );
6226 t2.reRoot( t2.getNode( "ABC" ) );
6227 t2.reRoot( t2.getNode( "D" ) );
6228 t2.reRoot( t2.getNode( "A" ) );
6229 t2.reRoot( t2.getNode( "B" ) );
6230 t2.reRoot( t2.getNode( "AB" ) );
6231 t2.reRoot( t2.getNode( "C" ) );
6232 t2.reRoot( t2.getNode( "D" ) );
6233 t2.reRoot( t2.getNode( "ABC" ) );
6234 t2.reRoot( t2.getNode( "D" ) );
6235 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6238 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6241 t2.reRoot( t2.getNode( "ABC" ) );
6242 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6245 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6248 t2.reRoot( t2.getNode( "AB" ) );
6249 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6252 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6255 if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6258 t2.reRoot( t2.getNode( "AB" ) );
6259 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6262 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6265 if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6268 t2.reRoot( t2.getNode( "D" ) );
6269 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6272 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6275 t2.reRoot( t2.getNode( "ABC" ) );
6276 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
6279 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
6282 final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
6283 new NHXParser() )[ 0 ];
6284 t3.reRoot( t3.getNode( "B" ) );
6285 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6288 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6291 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
6294 t3.reRoot( t3.getNode( "B" ) );
6295 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6298 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6301 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
6304 t3.reRoot( t3.getRoot() );
6305 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6308 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
6311 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
6315 catch ( final Exception e ) {
6316 e.printStackTrace( System.out );
6322 private static boolean testSDIse() {
6324 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6325 final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
6326 final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
6327 gene1.setRooted( true );
6328 species1.setRooted( true );
6329 final SDI sdi = new SDIse( gene1, species1 );
6330 if ( !gene1.getRoot().isDuplication() ) {
6333 final Phylogeny species2 = factory
6334 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
6335 new NHXParser() )[ 0 ];
6336 final Phylogeny gene2 = factory
6337 .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
6338 new NHXParser() )[ 0 ];
6339 species2.setRooted( true );
6340 gene2.setRooted( true );
6341 final SDI sdi2 = new SDIse( gene2, species2 );
6342 if ( sdi2.getDuplicationsSum() != 0 ) {
6345 if ( !gene2.getNode( "ab" ).isSpeciation() ) {
6348 if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
6351 if ( !gene2.getNode( "abc" ).isSpeciation() ) {
6354 if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
6357 if ( !gene2.getNode( "r" ).isSpeciation() ) {
6360 if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
6363 final Phylogeny species3 = factory
6364 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
6365 new NHXParser() )[ 0 ];
6366 final Phylogeny gene3 = factory
6367 .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
6368 new NHXParser() )[ 0 ];
6369 species3.setRooted( true );
6370 gene3.setRooted( true );
6371 final SDI sdi3 = new SDIse( gene3, species3 );
6372 if ( sdi3.getDuplicationsSum() != 1 ) {
6375 if ( !gene3.getNode( "aa" ).isDuplication() ) {
6378 if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
6381 final Phylogeny species4 = factory
6382 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
6383 new NHXParser() )[ 0 ];
6384 final Phylogeny gene4 = factory
6385 .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
6386 new NHXParser() )[ 0 ];
6387 species4.setRooted( true );
6388 gene4.setRooted( true );
6389 final SDI sdi4 = new SDIse( gene4, species4 );
6390 if ( sdi4.getDuplicationsSum() != 1 ) {
6393 if ( !gene4.getNode( "ac" ).isSpeciation() ) {
6396 if ( !gene4.getNode( "abc" ).isDuplication() ) {
6399 if ( gene4.getNode( "abcd" ).isDuplication() ) {
6402 if ( species4.getNumberOfExternalNodes() != 6 ) {
6405 if ( gene4.getNumberOfExternalNodes() != 6 ) {
6408 final Phylogeny species5 = factory
6409 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
6410 new NHXParser() )[ 0 ];
6411 final Phylogeny gene5 = factory
6412 .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
6413 new NHXParser() )[ 0 ];
6414 species5.setRooted( true );
6415 gene5.setRooted( true );
6416 final SDI sdi5 = new SDIse( gene5, species5 );
6417 if ( sdi5.getDuplicationsSum() != 2 ) {
6420 if ( !gene5.getNode( "ad" ).isSpeciation() ) {
6423 if ( !gene5.getNode( "adc" ).isDuplication() ) {
6426 if ( !gene5.getNode( "abcd" ).isDuplication() ) {
6429 if ( species5.getNumberOfExternalNodes() != 6 ) {
6432 if ( gene5.getNumberOfExternalNodes() != 6 ) {
6435 // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
6436 // Conjecture for Comparing Molecular Phylogenies"
6437 // J. of Comput Bio. Vol. 4, No 2, pp.177-187
6438 final Phylogeny species6 = factory
6439 .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,"
6440 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
6441 new NHXParser() )[ 0 ];
6442 final Phylogeny gene6 = factory
6443 .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,"
6444 + "((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,"
6445 + "(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;",
6446 new NHXParser() )[ 0 ];
6447 species6.setRooted( true );
6448 gene6.setRooted( true );
6449 final SDI sdi6 = new SDIse( gene6, species6 );
6450 if ( sdi6.getDuplicationsSum() != 3 ) {
6453 if ( !gene6.getNode( "r" ).isDuplication() ) {
6456 if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
6459 if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
6462 if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
6465 if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
6468 if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
6471 if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
6474 if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
6477 sdi6.computeMappingCostL();
6478 if ( sdi6.computeMappingCostL() != 17 ) {
6481 if ( species6.getNumberOfExternalNodes() != 9 ) {
6484 if ( gene6.getNumberOfExternalNodes() != 9 ) {
6487 final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
6488 + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
6489 + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
6490 + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
6491 + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
6492 species7.setRooted( true );
6493 final Phylogeny gene7_1 = Test
6494 .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])" );
6495 gene7_1.setRooted( true );
6496 final SDI sdi7 = new SDIse( gene7_1, species7 );
6497 if ( sdi7.getDuplicationsSum() != 0 ) {
6500 if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
6503 if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
6506 if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
6509 if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
6512 if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
6515 if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
6518 if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
6521 if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
6524 final Phylogeny gene7_2 = Test
6525 .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])" );
6526 gene7_2.setRooted( true );
6527 final SDI sdi7_2 = new SDIse( gene7_2, species7 );
6528 if ( sdi7_2.getDuplicationsSum() != 1 ) {
6531 if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
6534 if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
6537 if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
6540 if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
6543 if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
6546 if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
6549 if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
6552 if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
6555 if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
6559 catch ( final Exception e ) {
6565 private static boolean testSDIunrooted() {
6567 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6568 final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
6569 final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
6570 final Iterator<PhylogenyBranch> iter = l.iterator();
6571 PhylogenyBranch br = iter.next();
6572 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
6575 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
6579 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
6582 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
6586 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
6589 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
6593 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
6596 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
6600 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
6603 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
6607 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
6610 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
6614 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
6617 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
6621 if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
6624 if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
6628 if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
6631 if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
6635 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
6638 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
6642 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
6645 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
6649 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
6652 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
6656 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
6659 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
6663 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
6666 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
6670 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
6673 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
6676 if ( iter.hasNext() ) {
6679 final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
6680 final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
6681 final Iterator<PhylogenyBranch> iter1 = l1.iterator();
6683 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
6686 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
6690 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
6693 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
6697 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
6700 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
6703 if ( iter1.hasNext() ) {
6706 final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
6707 final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
6708 final Iterator<PhylogenyBranch> iter2 = l2.iterator();
6710 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
6713 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
6717 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
6720 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
6724 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
6727 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
6730 if ( iter2.hasNext() ) {
6733 final Phylogeny species0 = factory
6734 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
6735 new NHXParser() )[ 0 ];
6736 final Phylogeny gene1 = factory
6737 .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])",
6738 new NHXParser() )[ 0 ];
6739 species0.setRooted( true );
6740 gene1.setRooted( true );
6741 final SDIR sdi_unrooted = new SDIR();
6742 sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
6743 if ( sdi_unrooted.getCount() != 1 ) {
6746 if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
6749 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
6752 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
6755 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
6758 final Phylogeny gene2 = factory
6759 .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])",
6760 new NHXParser() )[ 0 ];
6761 gene2.setRooted( true );
6762 sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
6763 if ( sdi_unrooted.getCount() != 1 ) {
6766 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
6769 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
6772 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
6775 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
6778 final Phylogeny species6 = factory
6779 .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,"
6780 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
6781 new NHXParser() )[ 0 ];
6782 final Phylogeny gene6 = factory
6783 .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],"
6784 + "(((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],"
6785 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
6786 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
6787 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
6788 new NHXParser() )[ 0 ];
6789 species6.setRooted( true );
6790 gene6.setRooted( true );
6791 Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
6792 if ( sdi_unrooted.getCount() != 1 ) {
6795 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
6798 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
6801 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
6804 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
6807 if ( !p6[ 0 ].getRoot().isDuplication() ) {
6810 if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
6813 if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
6816 if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
6819 if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
6822 if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
6825 if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
6828 if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
6832 final Phylogeny species7 = factory
6833 .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,"
6834 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
6835 new NHXParser() )[ 0 ];
6836 final Phylogeny gene7 = factory
6837 .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],"
6838 + "(((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],"
6839 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
6840 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
6841 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
6842 new NHXParser() )[ 0 ];
6843 species7.setRooted( true );
6844 gene7.setRooted( true );
6845 Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
6846 if ( sdi_unrooted.getCount() != 1 ) {
6849 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
6852 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
6855 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
6858 if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
6861 if ( !p7[ 0 ].getRoot().isDuplication() ) {
6864 if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
6867 if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
6870 if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
6873 if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
6876 if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
6879 if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
6882 if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
6886 final Phylogeny species8 = factory
6887 .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,"
6888 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
6889 new NHXParser() )[ 0 ];
6890 final Phylogeny gene8 = factory
6891 .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],"
6892 + "(((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],"
6893 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
6894 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
6895 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
6896 new NHXParser() )[ 0 ];
6897 species8.setRooted( true );
6898 gene8.setRooted( true );
6899 Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
6900 if ( sdi_unrooted.getCount() != 1 ) {
6903 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
6906 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
6909 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
6912 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
6915 if ( !p8[ 0 ].getRoot().isDuplication() ) {
6918 if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
6921 if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
6924 if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
6927 if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
6930 if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
6933 if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
6936 if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
6941 catch ( final Exception e ) {
6942 e.printStackTrace( System.out );
6948 private static boolean testOrthologTable() {
6950 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6951 final Phylogeny s1 = factory.create( Test.PATH_TO_TEST_DATA + "rio_species.xml", new PhyloXmlParser() )[ 0 ];
6952 final NHXParser p = new NHXParser();
6953 p.setTaxonomyExtraction( TAXONOMY_EXTRACTION.YES );
6954 final Phylogeny g1[] = factory.create( new File( Test.PATH_TO_TEST_DATA
6955 + "rio_Bcl-2_e1_20_mafft_05_40_fme.mlt" ), p );
6956 for( final Phylogeny gt : g1 ) {
6957 gt.setRooted( true );
6958 final GSDI sdi = new GSDI( gt, s1, true, true, true );
6960 final IntMatrix m = RIO.calculateOrthologTable( g1 );
6961 System.out.println( m.toString() );
6963 catch ( final Exception e ) {
6964 e.printStackTrace();
6970 private static boolean testSplit() {
6972 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6973 final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
6974 //Archaeopteryx.createApplication( p0 );
6975 final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
6976 ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
6977 ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
6978 ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
6979 ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
6980 ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
6981 ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
6982 ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
6983 ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
6984 ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
6985 final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
6986 // System.out.println( s0.toString() );
6988 Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
6989 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
6990 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
6991 if ( s0.match( query_nodes ) ) {
6994 query_nodes = new HashSet<PhylogenyNode>();
6995 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
6996 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
6997 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
6998 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
6999 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7000 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7001 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7002 if ( !s0.match( query_nodes ) ) {
7006 query_nodes = new HashSet<PhylogenyNode>();
7007 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7008 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7009 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7010 if ( !s0.match( query_nodes ) ) {
7014 query_nodes = new HashSet<PhylogenyNode>();
7015 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7016 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7017 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7018 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7019 if ( !s0.match( query_nodes ) ) {
7023 query_nodes = new HashSet<PhylogenyNode>();
7024 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7025 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7026 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7027 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7028 if ( !s0.match( query_nodes ) ) {
7032 query_nodes = new HashSet<PhylogenyNode>();
7033 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7034 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7035 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7036 if ( !s0.match( query_nodes ) ) {
7040 query_nodes = new HashSet<PhylogenyNode>();
7041 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7042 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7043 if ( !s0.match( query_nodes ) ) {
7047 query_nodes = new HashSet<PhylogenyNode>();
7048 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7049 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7050 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7051 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7052 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7053 if ( !s0.match( query_nodes ) ) {
7057 query_nodes = new HashSet<PhylogenyNode>();
7058 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7059 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7060 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7061 if ( !s0.match( query_nodes ) ) {
7065 query_nodes = new HashSet<PhylogenyNode>();
7066 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7067 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7068 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7069 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7070 if ( !s0.match( query_nodes ) ) {
7074 query_nodes = new HashSet<PhylogenyNode>();
7075 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7076 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7077 if ( s0.match( query_nodes ) ) {
7081 query_nodes = new HashSet<PhylogenyNode>();
7082 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7083 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7084 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7085 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7086 if ( s0.match( query_nodes ) ) {
7090 query_nodes = new HashSet<PhylogenyNode>();
7091 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7092 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7093 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7094 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7095 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7096 if ( s0.match( query_nodes ) ) {
7100 query_nodes = new HashSet<PhylogenyNode>();
7101 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7102 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7103 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7104 if ( s0.match( query_nodes ) ) {
7108 query_nodes = new HashSet<PhylogenyNode>();
7109 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7110 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7111 if ( s0.match( query_nodes ) ) {
7115 query_nodes = new HashSet<PhylogenyNode>();
7116 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7117 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7118 if ( s0.match( query_nodes ) ) {
7122 query_nodes = new HashSet<PhylogenyNode>();
7123 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7124 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7125 if ( s0.match( query_nodes ) ) {
7129 query_nodes = new HashSet<PhylogenyNode>();
7130 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7131 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7132 if ( s0.match( query_nodes ) ) {
7136 query_nodes = new HashSet<PhylogenyNode>();
7137 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7138 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7139 if ( s0.match( query_nodes ) ) {
7143 query_nodes = new HashSet<PhylogenyNode>();
7144 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7145 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7146 if ( s0.match( query_nodes ) ) {
7150 query_nodes = new HashSet<PhylogenyNode>();
7151 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7152 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7153 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7154 if ( s0.match( query_nodes ) ) {
7158 query_nodes = new HashSet<PhylogenyNode>();
7159 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7160 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7161 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7162 if ( s0.match( query_nodes ) ) {
7166 query_nodes = new HashSet<PhylogenyNode>();
7167 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7168 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7169 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7170 if ( s0.match( query_nodes ) ) {
7174 query_nodes = new HashSet<PhylogenyNode>();
7175 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7176 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7177 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7178 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7179 if ( s0.match( query_nodes ) ) {
7183 // query_nodes = new HashSet<PhylogenyNode>();
7184 // query_nodes.add( new PhylogenyNode( "X" ) );
7185 // query_nodes.add( new PhylogenyNode( "Y" ) );
7186 // query_nodes.add( new PhylogenyNode( "A" ) );
7187 // query_nodes.add( new PhylogenyNode( "B" ) );
7188 // query_nodes.add( new PhylogenyNode( "C" ) );
7189 // query_nodes.add( new PhylogenyNode( "D" ) );
7190 // query_nodes.add( new PhylogenyNode( "E" ) );
7191 // query_nodes.add( new PhylogenyNode( "F" ) );
7192 // query_nodes.add( new PhylogenyNode( "G" ) );
7193 // if ( !s0.match( query_nodes ) ) {
7196 // query_nodes = new HashSet<PhylogenyNode>();
7197 // query_nodes.add( new PhylogenyNode( "X" ) );
7198 // query_nodes.add( new PhylogenyNode( "Y" ) );
7199 // query_nodes.add( new PhylogenyNode( "A" ) );
7200 // query_nodes.add( new PhylogenyNode( "B" ) );
7201 // query_nodes.add( new PhylogenyNode( "C" ) );
7202 // if ( !s0.match( query_nodes ) ) {
7206 // query_nodes = new HashSet<PhylogenyNode>();
7207 // query_nodes.add( new PhylogenyNode( "X" ) );
7208 // query_nodes.add( new PhylogenyNode( "Y" ) );
7209 // query_nodes.add( new PhylogenyNode( "D" ) );
7210 // query_nodes.add( new PhylogenyNode( "E" ) );
7211 // query_nodes.add( new PhylogenyNode( "F" ) );
7212 // query_nodes.add( new PhylogenyNode( "G" ) );
7213 // if ( !s0.match( query_nodes ) ) {
7217 // query_nodes = new HashSet<PhylogenyNode>();
7218 // query_nodes.add( new PhylogenyNode( "X" ) );
7219 // query_nodes.add( new PhylogenyNode( "Y" ) );
7220 // query_nodes.add( new PhylogenyNode( "A" ) );
7221 // query_nodes.add( new PhylogenyNode( "B" ) );
7222 // query_nodes.add( new PhylogenyNode( "C" ) );
7223 // query_nodes.add( new PhylogenyNode( "D" ) );
7224 // if ( !s0.match( query_nodes ) ) {
7228 // query_nodes = new HashSet<PhylogenyNode>();
7229 // query_nodes.add( new PhylogenyNode( "X" ) );
7230 // query_nodes.add( new PhylogenyNode( "Y" ) );
7231 // query_nodes.add( new PhylogenyNode( "E" ) );
7232 // query_nodes.add( new PhylogenyNode( "F" ) );
7233 // query_nodes.add( new PhylogenyNode( "G" ) );
7234 // if ( !s0.match( query_nodes ) ) {
7238 // query_nodes = new HashSet<PhylogenyNode>();
7239 // query_nodes.add( new PhylogenyNode( "X" ) );
7240 // query_nodes.add( new PhylogenyNode( "Y" ) );
7241 // query_nodes.add( new PhylogenyNode( "F" ) );
7242 // query_nodes.add( new PhylogenyNode( "G" ) );
7243 // if ( !s0.match( query_nodes ) ) {
7247 query_nodes = new HashSet<PhylogenyNode>();
7248 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7249 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7250 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7251 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7252 if ( s0.match( query_nodes ) ) {
7256 query_nodes = new HashSet<PhylogenyNode>();
7257 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7258 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7259 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7260 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7261 if ( s0.match( query_nodes ) ) {
7264 ///////////////////////////
7266 query_nodes = new HashSet<PhylogenyNode>();
7267 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7268 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7269 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7270 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7271 if ( s0.match( query_nodes ) ) {
7275 query_nodes = new HashSet<PhylogenyNode>();
7276 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7277 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7278 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7279 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7280 if ( s0.match( query_nodes ) ) {
7284 query_nodes = new HashSet<PhylogenyNode>();
7285 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7286 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7287 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7288 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7289 if ( s0.match( query_nodes ) ) {
7293 query_nodes = new HashSet<PhylogenyNode>();
7294 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7295 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7296 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7297 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7298 if ( s0.match( query_nodes ) ) {
7302 query_nodes = new HashSet<PhylogenyNode>();
7303 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7304 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7305 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7306 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7307 if ( s0.match( query_nodes ) ) {
7311 query_nodes = new HashSet<PhylogenyNode>();
7312 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7313 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7314 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7315 if ( s0.match( query_nodes ) ) {
7319 query_nodes = new HashSet<PhylogenyNode>();
7320 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7321 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7322 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7323 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7324 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7325 if ( s0.match( query_nodes ) ) {
7329 query_nodes = new HashSet<PhylogenyNode>();
7330 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7331 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7332 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7333 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7334 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7335 if ( s0.match( query_nodes ) ) {
7339 query_nodes = new HashSet<PhylogenyNode>();
7340 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7341 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7342 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7343 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7344 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7345 if ( s0.match( query_nodes ) ) {
7349 query_nodes = new HashSet<PhylogenyNode>();
7350 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
7351 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
7352 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7353 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7354 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7355 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7356 if ( s0.match( query_nodes ) ) {
7360 catch ( final Exception e ) {
7361 e.printStackTrace();
7367 private static boolean testSplitStrict() {
7369 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7370 final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
7371 final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
7372 ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7373 ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7374 ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7375 ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7376 ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7377 ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7378 ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7379 final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
7380 Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
7381 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7382 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7383 if ( s0.match( query_nodes ) ) {
7386 query_nodes = new HashSet<PhylogenyNode>();
7387 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7388 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7389 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7390 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7391 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7392 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7393 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7394 if ( !s0.match( query_nodes ) ) {
7398 query_nodes = new HashSet<PhylogenyNode>();
7399 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7400 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7401 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7402 if ( !s0.match( query_nodes ) ) {
7406 query_nodes = new HashSet<PhylogenyNode>();
7407 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7408 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7409 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7410 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7411 if ( !s0.match( query_nodes ) ) {
7415 query_nodes = new HashSet<PhylogenyNode>();
7416 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7417 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7418 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7419 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7420 if ( !s0.match( query_nodes ) ) {
7424 query_nodes = new HashSet<PhylogenyNode>();
7425 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7426 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7427 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7428 if ( !s0.match( query_nodes ) ) {
7432 query_nodes = new HashSet<PhylogenyNode>();
7433 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7434 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7435 if ( !s0.match( query_nodes ) ) {
7439 query_nodes = new HashSet<PhylogenyNode>();
7440 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7441 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7442 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7443 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7444 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7445 if ( !s0.match( query_nodes ) ) {
7449 query_nodes = new HashSet<PhylogenyNode>();
7450 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7451 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7452 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7453 if ( !s0.match( query_nodes ) ) {
7457 query_nodes = new HashSet<PhylogenyNode>();
7458 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7459 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7460 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7461 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7462 if ( !s0.match( query_nodes ) ) {
7466 query_nodes = new HashSet<PhylogenyNode>();
7467 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7468 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7469 if ( s0.match( query_nodes ) ) {
7473 query_nodes = new HashSet<PhylogenyNode>();
7474 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7475 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7476 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7477 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7478 if ( s0.match( query_nodes ) ) {
7482 query_nodes = new HashSet<PhylogenyNode>();
7483 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7484 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7485 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7486 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7487 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7488 if ( s0.match( query_nodes ) ) {
7492 query_nodes = new HashSet<PhylogenyNode>();
7493 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7494 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7495 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7496 if ( s0.match( query_nodes ) ) {
7500 query_nodes = new HashSet<PhylogenyNode>();
7501 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7502 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7503 if ( s0.match( query_nodes ) ) {
7507 query_nodes = new HashSet<PhylogenyNode>();
7508 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7509 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7510 if ( s0.match( query_nodes ) ) {
7514 query_nodes = new HashSet<PhylogenyNode>();
7515 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7516 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
7517 if ( s0.match( query_nodes ) ) {
7521 query_nodes = new HashSet<PhylogenyNode>();
7522 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7523 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7524 if ( s0.match( query_nodes ) ) {
7528 query_nodes = new HashSet<PhylogenyNode>();
7529 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7530 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7531 if ( s0.match( query_nodes ) ) {
7535 query_nodes = new HashSet<PhylogenyNode>();
7536 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7537 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7538 if ( s0.match( query_nodes ) ) {
7542 query_nodes = new HashSet<PhylogenyNode>();
7543 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7544 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
7545 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7546 if ( s0.match( query_nodes ) ) {
7550 query_nodes = new HashSet<PhylogenyNode>();
7551 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7552 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
7553 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7554 if ( s0.match( query_nodes ) ) {
7558 query_nodes = new HashSet<PhylogenyNode>();
7559 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7560 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7561 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7562 if ( s0.match( query_nodes ) ) {
7566 query_nodes = new HashSet<PhylogenyNode>();
7567 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
7568 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
7569 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
7570 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
7571 if ( s0.match( query_nodes ) ) {
7575 catch ( final Exception e ) {
7576 e.printStackTrace();
7582 private static boolean testSubtreeDeletion() {
7584 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7585 final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
7586 t1.deleteSubtree( t1.getNode( "A" ), false );
7587 if ( t1.getNumberOfExternalNodes() != 5 ) {
7590 t1.toNewHampshireX();
7591 t1.deleteSubtree( t1.getNode( "E" ), false );
7592 if ( t1.getNumberOfExternalNodes() != 4 ) {
7595 t1.toNewHampshireX();
7596 t1.deleteSubtree( t1.getNode( "F" ), false );
7597 if ( t1.getNumberOfExternalNodes() != 3 ) {
7600 t1.toNewHampshireX();
7601 t1.deleteSubtree( t1.getNode( "D" ), false );
7602 t1.toNewHampshireX();
7603 if ( t1.getNumberOfExternalNodes() != 3 ) {
7606 t1.deleteSubtree( t1.getNode( "def" ), false );
7607 t1.toNewHampshireX();
7608 if ( t1.getNumberOfExternalNodes() != 2 ) {
7611 t1.deleteSubtree( t1.getNode( "B" ), false );
7612 t1.toNewHampshireX();
7613 if ( t1.getNumberOfExternalNodes() != 1 ) {
7616 t1.deleteSubtree( t1.getNode( "C" ), false );
7617 t1.toNewHampshireX();
7618 if ( t1.getNumberOfExternalNodes() != 1 ) {
7621 t1.deleteSubtree( t1.getNode( "abc" ), false );
7622 t1.toNewHampshireX();
7623 if ( t1.getNumberOfExternalNodes() != 1 ) {
7626 t1.deleteSubtree( t1.getNode( "r" ), false );
7627 if ( t1.getNumberOfExternalNodes() != 0 ) {
7630 if ( !t1.isEmpty() ) {
7633 final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
7634 t2.deleteSubtree( t2.getNode( "A" ), false );
7635 t2.toNewHampshireX();
7636 if ( t2.getNumberOfExternalNodes() != 5 ) {
7639 t2.deleteSubtree( t2.getNode( "abc" ), false );
7640 t2.toNewHampshireX();
7641 if ( t2.getNumberOfExternalNodes() != 3 ) {
7644 t2.deleteSubtree( t2.getNode( "def" ), false );
7645 t2.toNewHampshireX();
7646 if ( t2.getNumberOfExternalNodes() != 1 ) {
7650 catch ( final Exception e ) {
7651 e.printStackTrace( System.out );
7657 private static boolean testSupportCount() {
7659 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7660 final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
7661 final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
7662 + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
7663 + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
7664 + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
7665 + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
7667 SupportCount.count( t0_1, phylogenies_1, true, false );
7668 final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
7669 final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
7670 + "(((((A,B),C),D),E),((F,G),X))"
7671 + "(((((A,Y),B),C),D),((F,G),E))"
7672 + "(((((A,B),C),D),E),(F,G))"
7673 + "(((((A,B),C),D),E),(F,G))"
7674 + "(((((A,B),C),D),E),(F,G))"
7675 + "(((((A,B),C),D),E),(F,G),Z)"
7676 + "(((((A,B),C),D),E),(F,G))"
7677 + "((((((A,B),C),D),E),F),G)"
7678 + "(((((X,Y),F,G),E),((A,B),C)),D)",
7680 SupportCount.count( t0_2, phylogenies_2, true, false );
7681 final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
7682 while ( it.hasNext() ) {
7683 final PhylogenyNode n = it.next();
7684 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
7688 final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
7689 final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
7690 + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
7691 SupportCount.count( t0_3, phylogenies_3, true, false );
7692 t0_3.reRoot( t0_3.getNode( "def" ).getId() );
7693 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
7696 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
7699 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
7702 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
7705 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
7708 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
7711 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
7714 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
7717 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
7720 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
7723 final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7724 final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
7725 + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
7726 SupportCount.count( t0_4, phylogenies_4, true, false );
7727 t0_4.reRoot( t0_4.getNode( "F" ).getId() );
7728 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
7731 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
7734 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
7737 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
7740 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
7743 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
7746 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
7749 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
7752 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
7755 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
7758 Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7759 final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7760 double d = SupportCount.compare( b1, a, true, true, true );
7761 if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
7764 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7765 final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7766 d = SupportCount.compare( b2, a, true, true, true );
7767 if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
7770 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
7771 final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
7772 d = SupportCount.compare( b3, a, true, true, true );
7773 if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
7776 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
7777 final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
7778 d = SupportCount.compare( b4, a, true, true, false );
7779 if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
7783 catch ( final Exception e ) {
7784 e.printStackTrace( System.out );
7790 private static boolean testSupportTransfer() {
7792 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7793 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)",
7794 new NHXParser() )[ 0 ];
7795 final Phylogeny p2 = factory
7796 .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 ];
7797 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
7800 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
7803 support_transfer.moveBranchLengthsToBootstrap( p1 );
7804 support_transfer.transferSupportValues( p1, p2 );
7805 if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
7808 if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
7811 if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
7814 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
7817 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
7820 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
7823 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
7826 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
7830 catch ( final Exception e ) {
7831 e.printStackTrace( System.out );
7837 private static boolean testUniprotTaxonomySearch() {
7839 List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
7841 if ( results.size() != 1 ) {
7844 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
7847 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
7850 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
7853 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
7856 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
7860 results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
7861 if ( results.size() != 1 ) {
7864 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
7867 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
7870 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
7873 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
7876 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
7880 results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
7881 if ( results.size() != 1 ) {
7884 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
7887 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
7890 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
7893 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
7896 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
7900 results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
7901 if ( results.size() != 1 ) {
7904 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
7907 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
7910 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
7913 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
7916 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
7919 if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
7922 if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
7925 if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
7926 .equals( "Nematostella vectensis" ) ) {
7927 System.out.println( results.get( 0 ).getLineage() );
7931 catch ( final IOException e ) {
7932 System.out.println();
7933 System.out.println( "the following might be due to absence internet connection:" );
7934 e.printStackTrace( System.out );
7937 catch ( final Exception e ) {
7943 private static boolean testEmblEntryRetrieval() {
7944 //The format for GenBank Accession numbers are:
7945 //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
7946 //Protein: 3 letters + 5 numerals
7947 //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
7948 if ( !SequenceIdParser.parseGenbankAccessor( "AY423861" ).equals( "AY423861" ) ) {
7951 if ( !SequenceIdParser.parseGenbankAccessor( ".AY423861." ).equals( "AY423861" ) ) {
7954 if ( SequenceIdParser.parseGenbankAccessor( "AAY423861" ) != null ) {
7957 if ( SequenceIdParser.parseGenbankAccessor( "AY4238612" ) != null ) {
7960 if ( SequenceIdParser.parseGenbankAccessor( "AAY4238612" ) != null ) {
7963 if ( SequenceIdParser.parseGenbankAccessor( "Y423861" ) != null ) {
7966 if ( !SequenceIdParser.parseGenbankAccessor( "S12345" ).equals( "S12345" ) ) {
7969 if ( !SequenceIdParser.parseGenbankAccessor( "|S12345|" ).equals( "S12345" ) ) {
7972 if ( SequenceIdParser.parseGenbankAccessor( "|S123456" ) != null ) {
7975 if ( SequenceIdParser.parseGenbankAccessor( "ABC123456" ) != null ) {
7978 if ( !SequenceIdParser.parseGenbankAccessor( "ABC12345" ).equals( "ABC12345" ) ) {
7981 if ( !SequenceIdParser.parseGenbankAccessor( "&ABC12345&" ).equals( "ABC12345" ) ) {
7984 if ( SequenceIdParser.parseGenbankAccessor( "ABCD12345" ) != null ) {
7990 private static boolean testUniprotEntryRetrieval() {
7991 if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345" ).equals( "P12345" ) ) {
7994 if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345" ) != null ) {
7997 if ( SequenceDbWsTools.parseUniProtAccessor( "3 4P12345" ) != null ) {
8000 if ( SequenceDbWsTools.parseUniProtAccessor( "P12345E" ) != null ) {
8003 if ( SequenceDbWsTools.parseUniProtAccessor( "P123455" ) != null ) {
8006 if ( SequenceDbWsTools.parseUniProtAccessor( "EP12345E" ) != null ) {
8009 if ( SequenceDbWsTools.parseUniProtAccessor( "AY423861" ) != null ) {
8012 if ( !SequenceDbWsTools.parseUniProtAccessor( "P1DDD5" ).equals( "P1DDD5" ) ) {
8015 if ( SequenceDbWsTools.parseUniProtAccessor( "P1DDDD" ) != null ) {
8018 if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345/12-42" ).equals( "P12345" ) ) {
8021 if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X P12345 12-42" ).equals( "P12345" ) ) {
8024 if ( !SequenceDbWsTools.parseUniProtAccessor( "P12345/12-42" ).equals( "P12345" ) ) {
8027 if ( !SequenceDbWsTools.parseUniProtAccessor( "P1234X/P12345" ).equals( "P12345" ) ) {
8031 final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
8032 if ( !entry.getAccession().equals( "P12345" ) ) {
8035 if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
8038 if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
8041 if ( !entry.getSequenceSymbol().equals( "GOT2" ) ) {
8044 if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
8048 catch ( final IOException e ) {
8049 System.out.println();
8050 System.out.println( "the following might be due to absence internet connection:" );
8051 e.printStackTrace( System.out );
8054 catch ( final Exception e ) {
8060 private static boolean testWabiTxSearch() {
8063 result = TxSearch.searchSimple( "nematostella" );
8064 result = TxSearch.getTxId( "nematostella" );
8065 if ( !result.equals( "45350" ) ) {
8068 result = TxSearch.getTxName( "45350" );
8069 if ( !result.equals( "Nematostella" ) ) {
8072 result = TxSearch.getTxId( "nematostella vectensis" );
8073 if ( !result.equals( "45351" ) ) {
8076 result = TxSearch.getTxName( "45351" );
8077 if ( !result.equals( "Nematostella vectensis" ) ) {
8080 result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
8081 if ( !result.equals( "536089" ) ) {
8084 result = TxSearch.getTxName( "536089" );
8085 if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
8088 final List<String> queries = new ArrayList<String>();
8089 queries.add( "Campylobacter coli" );
8090 queries.add( "Escherichia coli" );
8091 queries.add( "Arabidopsis" );
8092 queries.add( "Trichoplax" );
8093 queries.add( "Samanea saman" );
8094 queries.add( "Kluyveromyces marxianus" );
8095 queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
8096 queries.add( "Bornavirus parrot/PDD/2008" );
8097 final List<RANKS> ranks = new ArrayList<RANKS>();
8098 ranks.add( RANKS.SUPERKINGDOM );
8099 ranks.add( RANKS.KINGDOM );
8100 ranks.add( RANKS.FAMILY );
8101 ranks.add( RANKS.GENUS );
8102 ranks.add( RANKS.TRIBE );
8103 result = TxSearch.searchLineage( queries, ranks );
8104 result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
8105 result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
8107 catch ( final Exception e ) {
8108 System.out.println();
8109 System.out.println( "the following might be due to absence internet connection:" );
8110 e.printStackTrace( System.out );
8116 private static boolean testAminoAcidSequence() {
8118 final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
8119 if ( aa1.getLength() != 13 ) {
8122 if ( aa1.getResidueAt( 0 ) != 'A' ) {
8125 if ( aa1.getResidueAt( 2 ) != 'K' ) {
8128 if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
8131 final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
8132 if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
8135 final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
8136 if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
8139 final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
8140 if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
8144 catch ( final Exception e ) {
8145 e.printStackTrace();
8151 private static boolean testCreateBalancedPhylogeny() {
8153 final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
8154 if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
8157 if ( p0.getNumberOfExternalNodes() != 15625 ) {
8160 final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
8161 if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
8164 if ( p1.getNumberOfExternalNodes() != 100 ) {
8168 catch ( final Exception e ) {
8169 e.printStackTrace();
8175 private static boolean testFastaParser() {
8177 if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
8180 if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
8183 final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
8184 if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
8187 if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
8190 if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
8193 if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
8196 if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
8199 if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
8203 catch ( final Exception e ) {
8204 e.printStackTrace();
8210 private static boolean testGeneralMsaParser() {
8212 final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
8213 final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
8214 final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
8215 final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
8216 final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
8217 final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
8218 final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
8219 final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
8220 if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
8223 if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
8226 if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
8229 if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
8232 if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
8235 if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
8238 if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
8241 if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
8244 if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
8247 if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
8250 if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
8253 if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
8256 final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
8257 if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
8260 if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
8263 if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
8266 final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
8267 if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
8270 if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
8273 if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
8276 final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
8277 if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
8280 if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
8283 if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
8287 catch ( final Exception e ) {
8288 e.printStackTrace();
8294 private static boolean testMafft( final String path ) {
8296 final List<String> opts = new ArrayList<String>();
8297 opts.add( "--maxiterate" );
8299 opts.add( "--localpair" );
8300 opts.add( "--quiet" );
8302 final MsaInferrer mafft = Mafft.createInstance( path );
8303 msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
8304 if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
8307 if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
8311 catch ( final Exception e ) {
8312 e.printStackTrace( System.out );
8318 private static boolean testNextNodeWithCollapsing() {
8320 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8322 List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
8323 final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8324 final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
8325 t0.getNode( "cd" ).setCollapse( true );
8326 t0.getNode( "cde" ).setCollapse( true );
8327 n = t0.getFirstExternalNode();
8328 while ( n != null ) {
8330 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8332 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8335 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8338 if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
8341 if ( !ext.get( 3 ).getName().equals( "f" ) ) {
8344 if ( !ext.get( 4 ).getName().equals( "g" ) ) {
8347 if ( !ext.get( 5 ).getName().equals( "h" ) ) {
8351 final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8352 final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
8353 t1.getNode( "ab" ).setCollapse( true );
8354 t1.getNode( "cd" ).setCollapse( true );
8355 t1.getNode( "cde" ).setCollapse( true );
8356 n = t1.getNode( "ab" );
8357 ext = new ArrayList<PhylogenyNode>();
8358 while ( n != null ) {
8360 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8362 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8365 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
8368 if ( !ext.get( 2 ).getName().equals( "f" ) ) {
8371 if ( !ext.get( 3 ).getName().equals( "g" ) ) {
8374 if ( !ext.get( 4 ).getName().equals( "h" ) ) {
8380 final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8381 final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
8382 t2.getNode( "ab" ).setCollapse( true );
8383 t2.getNode( "cd" ).setCollapse( true );
8384 t2.getNode( "cde" ).setCollapse( true );
8385 t2.getNode( "c" ).setCollapse( true );
8386 t2.getNode( "d" ).setCollapse( true );
8387 t2.getNode( "e" ).setCollapse( true );
8388 t2.getNode( "gh" ).setCollapse( true );
8389 n = t2.getNode( "ab" );
8390 ext = new ArrayList<PhylogenyNode>();
8391 while ( n != null ) {
8393 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8395 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8398 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
8401 if ( !ext.get( 2 ).getName().equals( "f" ) ) {
8404 if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
8410 final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8411 final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
8412 t3.getNode( "ab" ).setCollapse( true );
8413 t3.getNode( "cd" ).setCollapse( true );
8414 t3.getNode( "cde" ).setCollapse( true );
8415 t3.getNode( "c" ).setCollapse( true );
8416 t3.getNode( "d" ).setCollapse( true );
8417 t3.getNode( "e" ).setCollapse( true );
8418 t3.getNode( "gh" ).setCollapse( true );
8419 t3.getNode( "fgh" ).setCollapse( true );
8420 n = t3.getNode( "ab" );
8421 ext = new ArrayList<PhylogenyNode>();
8422 while ( n != null ) {
8424 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8426 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8429 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
8432 if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
8438 final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8439 final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
8440 t4.getNode( "ab" ).setCollapse( true );
8441 t4.getNode( "cd" ).setCollapse( true );
8442 t4.getNode( "cde" ).setCollapse( true );
8443 t4.getNode( "c" ).setCollapse( true );
8444 t4.getNode( "d" ).setCollapse( true );
8445 t4.getNode( "e" ).setCollapse( true );
8446 t4.getNode( "gh" ).setCollapse( true );
8447 t4.getNode( "fgh" ).setCollapse( true );
8448 t4.getNode( "abcdefgh" ).setCollapse( true );
8449 n = t4.getNode( "abcdefgh" );
8450 if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
8455 final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8456 final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
8458 n = t5.getFirstExternalNode();
8459 while ( n != null ) {
8461 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8463 if ( ext.size() != 8 ) {
8466 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8469 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8472 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
8475 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
8478 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
8481 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
8484 if ( !ext.get( 6 ).getName().equals( "g" ) ) {
8487 if ( !ext.get( 7 ).getName().equals( "h" ) ) {
8492 final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8493 final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
8495 t6.getNode( "ab" ).setCollapse( true );
8496 n = t6.getNode( "ab" );
8497 while ( n != null ) {
8499 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8501 if ( ext.size() != 7 ) {
8504 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8507 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
8510 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
8513 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8516 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
8519 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
8522 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
8527 final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8528 final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
8530 t7.getNode( "cd" ).setCollapse( true );
8531 n = t7.getNode( "a" );
8532 while ( n != null ) {
8534 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8536 if ( ext.size() != 7 ) {
8539 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8542 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8545 if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
8548 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8551 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
8554 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
8557 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
8562 final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
8563 final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
8565 t8.getNode( "cd" ).setCollapse( true );
8566 t8.getNode( "c" ).setCollapse( true );
8567 t8.getNode( "d" ).setCollapse( true );
8568 n = t8.getNode( "a" );
8569 while ( n != null ) {
8571 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8573 if ( ext.size() != 7 ) {
8576 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8579 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8582 if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
8583 System.out.println( "2 fail" );
8586 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8589 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
8592 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
8595 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
8600 final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8601 final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
8603 t9.getNode( "gh" ).setCollapse( true );
8604 n = t9.getNode( "a" );
8605 while ( n != null ) {
8607 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8609 if ( ext.size() != 7 ) {
8612 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8615 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8618 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
8621 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
8624 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
8627 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
8630 if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
8635 final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8636 final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
8638 t10.getNode( "gh" ).setCollapse( true );
8639 t10.getNode( "g" ).setCollapse( true );
8640 t10.getNode( "h" ).setCollapse( true );
8641 n = t10.getNode( "a" );
8642 while ( n != null ) {
8644 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8646 if ( ext.size() != 7 ) {
8649 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8652 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8655 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
8658 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
8661 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
8664 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
8667 if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
8672 final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8673 final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
8675 t11.getNode( "gh" ).setCollapse( true );
8676 t11.getNode( "fgh" ).setCollapse( true );
8677 n = t11.getNode( "a" );
8678 while ( n != null ) {
8680 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8682 if ( ext.size() != 6 ) {
8685 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8688 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8691 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
8694 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
8697 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
8700 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
8705 final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8706 final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
8708 t12.getNode( "gh" ).setCollapse( true );
8709 t12.getNode( "fgh" ).setCollapse( true );
8710 t12.getNode( "g" ).setCollapse( true );
8711 t12.getNode( "h" ).setCollapse( true );
8712 t12.getNode( "f" ).setCollapse( true );
8713 n = t12.getNode( "a" );
8714 while ( n != null ) {
8716 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8718 if ( ext.size() != 6 ) {
8721 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
8724 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
8727 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
8730 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
8733 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
8736 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
8741 final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
8742 final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
8744 t13.getNode( "ab" ).setCollapse( true );
8745 t13.getNode( "b" ).setCollapse( true );
8746 t13.getNode( "fgh" ).setCollapse( true );
8747 t13.getNode( "gh" ).setCollapse( true );
8748 n = t13.getNode( "ab" );
8749 while ( n != null ) {
8751 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8753 if ( ext.size() != 5 ) {
8756 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8759 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
8762 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
8765 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8768 if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
8773 final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
8774 final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
8776 t14.getNode( "ab" ).setCollapse( true );
8777 t14.getNode( "a" ).setCollapse( true );
8778 t14.getNode( "fgh" ).setCollapse( true );
8779 t14.getNode( "gh" ).setCollapse( true );
8780 n = t14.getNode( "ab" );
8781 while ( n != null ) {
8783 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8785 if ( ext.size() != 5 ) {
8788 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8791 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
8794 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
8797 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8800 if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
8805 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" );
8806 final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
8808 t15.getNode( "ab" ).setCollapse( true );
8809 t15.getNode( "a" ).setCollapse( true );
8810 t15.getNode( "fgh" ).setCollapse( true );
8811 t15.getNode( "gh" ).setCollapse( true );
8812 n = t15.getNode( "ab" );
8813 while ( n != null ) {
8815 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8817 if ( ext.size() != 6 ) {
8820 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8823 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
8826 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
8829 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
8832 if ( !ext.get( 4 ).getName().equals( "x" ) ) {
8835 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
8840 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" );
8841 final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
8843 t16.getNode( "ab" ).setCollapse( true );
8844 t16.getNode( "a" ).setCollapse( true );
8845 t16.getNode( "fgh" ).setCollapse( true );
8846 t16.getNode( "gh" ).setCollapse( true );
8847 t16.getNode( "cd" ).setCollapse( true );
8848 t16.getNode( "cde" ).setCollapse( true );
8849 t16.getNode( "d" ).setCollapse( true );
8850 t16.getNode( "x" ).setCollapse( true );
8851 n = t16.getNode( "ab" );
8852 while ( n != null ) {
8854 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
8856 if ( ext.size() != 4 ) {
8859 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
8862 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
8865 if ( !ext.get( 2 ).getName().equals( "x" ) ) {
8868 if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
8872 catch ( final Exception e ) {
8873 e.printStackTrace( System.out );
8879 private static boolean testMsaQualityMethod() {
8881 final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
8882 final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
8883 final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
8884 final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
8885 final List<Sequence> l = new ArrayList<Sequence>();
8890 final Msa msa = BasicMsa.createInstance( l );
8891 if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
8894 if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
8897 if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
8900 if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
8904 catch ( final Exception e ) {
8905 e.printStackTrace( System.out );
8911 private static boolean testSequenceIdParsing() {
8913 Identifier id = SequenceIdParser.parse( "gb_ADF31344_segmented_worms_" );
8914 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8915 || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
8917 System.out.println( "value =" + id.getValue() );
8918 System.out.println( "provider=" + id.getProvider() );
8923 id = SequenceIdParser.parse( "segmented worms|gb_ADF31344" );
8924 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8925 || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
8927 System.out.println( "value =" + id.getValue() );
8928 System.out.println( "provider=" + id.getProvider() );
8933 id = SequenceIdParser.parse( "segmented worms gb_ADF31344 and more" );
8934 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8935 || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
8937 System.out.println( "value =" + id.getValue() );
8938 System.out.println( "provider=" + id.getProvider() );
8943 id = SequenceIdParser.parse( "gb_AAA96518_1" );
8944 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8945 || !id.getValue().equals( "AAA96518" ) || !id.getProvider().equals( "ncbi" ) ) {
8947 System.out.println( "value =" + id.getValue() );
8948 System.out.println( "provider=" + id.getProvider() );
8953 id = SequenceIdParser.parse( "gb_EHB07727_1_rodents_" );
8954 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8955 || !id.getValue().equals( "EHB07727" ) || !id.getProvider().equals( "ncbi" ) ) {
8957 System.out.println( "value =" + id.getValue() );
8958 System.out.println( "provider=" + id.getProvider() );
8963 id = SequenceIdParser.parse( "dbj_BAF37827_1_turtles_" );
8964 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8965 || !id.getValue().equals( "BAF37827" ) || !id.getProvider().equals( "ncbi" ) ) {
8967 System.out.println( "value =" + id.getValue() );
8968 System.out.println( "provider=" + id.getProvider() );
8973 id = SequenceIdParser.parse( "emb_CAA73223_1_primates_" );
8974 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8975 || !id.getValue().equals( "CAA73223" ) || !id.getProvider().equals( "ncbi" ) ) {
8977 System.out.println( "value =" + id.getValue() );
8978 System.out.println( "provider=" + id.getProvider() );
8983 id = SequenceIdParser.parse( "mites|ref_XP_002434188_1" );
8984 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8985 || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
8987 System.out.println( "value =" + id.getValue() );
8988 System.out.println( "provider=" + id.getProvider() );
8993 id = SequenceIdParser.parse( "mites_ref_XP_002434188_1_bla_XP_12345" );
8994 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
8995 || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
8997 System.out.println( "value =" + id.getValue() );
8998 System.out.println( "provider=" + id.getProvider() );
9003 id = SequenceIdParser.parse( "P4A123" );
9004 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9005 || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
9007 System.out.println( "value =" + id.getValue() );
9008 System.out.println( "provider=" + id.getProvider() );
9013 id = SequenceIdParser.parse( "pllf[pok P4A123_osdjfosnqo035-9233332904i000490 vf tmv x45" );
9014 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9015 || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
9017 System.out.println( "value =" + id.getValue() );
9018 System.out.println( "provider=" + id.getProvider() );
9023 id = SequenceIdParser.parse( "XP_12345" );
9025 System.out.println( "value =" + id.getValue() );
9026 System.out.println( "provider=" + id.getProvider() );
9029 // lcl_91970_unknown_
9031 catch ( final Exception e ) {
9032 e.printStackTrace( System.out );