2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 // Contact: phylosoft @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
26 package org.forester.test;
28 import java.io.ByteArrayInputStream;
30 import java.io.FileInputStream;
31 import java.io.IOException;
32 import java.util.ArrayList;
33 import java.util.Date;
34 import java.util.HashSet;
35 import java.util.Iterator;
36 import java.util.List;
37 import java.util.Locale;
40 import org.forester.application.support_transfer;
41 import org.forester.archaeopteryx.AptxUtil;
42 import org.forester.development.DevelopmentTools;
43 import org.forester.evoinference.TestPhylogenyReconstruction;
44 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
45 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
46 import org.forester.go.TestGo;
47 import org.forester.io.parsers.FastaParser;
48 import org.forester.io.parsers.GeneralMsaParser;
49 import org.forester.io.parsers.HmmscanPerDomainTableParser;
50 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
51 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
52 import org.forester.io.parsers.nexus.NexusCharactersParser;
53 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
54 import org.forester.io.parsers.nhx.NHXParser;
55 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
56 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
57 import org.forester.io.parsers.tol.TolParser;
58 import org.forester.io.parsers.util.ParserUtils;
59 import org.forester.io.writers.PhylogenyWriter;
60 import org.forester.io.writers.SequenceWriter;
61 import org.forester.msa.BasicMsa;
62 import org.forester.msa.Mafft;
63 import org.forester.msa.Msa;
64 import org.forester.msa.MsaInferrer;
65 import org.forester.msa.MsaMethods;
66 import org.forester.pccx.TestPccx;
67 import org.forester.phylogeny.Phylogeny;
68 import org.forester.phylogeny.PhylogenyBranch;
69 import org.forester.phylogeny.PhylogenyMethods;
70 import org.forester.phylogeny.PhylogenyNode;
71 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
72 import org.forester.phylogeny.data.Accession;
73 import org.forester.phylogeny.data.BinaryCharacters;
74 import org.forester.phylogeny.data.BranchWidth;
75 import org.forester.phylogeny.data.Confidence;
76 import org.forester.phylogeny.data.Distribution;
77 import org.forester.phylogeny.data.DomainArchitecture;
78 import org.forester.phylogeny.data.Event;
79 import org.forester.phylogeny.data.Identifier;
80 import org.forester.phylogeny.data.PhylogenyData;
81 import org.forester.phylogeny.data.PhylogenyDataUtil;
82 import org.forester.phylogeny.data.Polygon;
83 import org.forester.phylogeny.data.PropertiesMap;
84 import org.forester.phylogeny.data.Property;
85 import org.forester.phylogeny.data.Property.AppliesTo;
86 import org.forester.phylogeny.data.ProteinDomain;
87 import org.forester.phylogeny.data.Taxonomy;
88 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
89 import org.forester.phylogeny.factories.PhylogenyFactory;
90 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
91 import org.forester.protein.BasicDomain;
92 import org.forester.protein.BasicProtein;
93 import org.forester.protein.Domain;
94 import org.forester.protein.DomainId;
95 import org.forester.protein.Protein;
96 import org.forester.protein.ProteinId;
97 import org.forester.rio.TestRIO;
98 import org.forester.sdi.SDI;
99 import org.forester.sdi.SDIR;
100 import org.forester.sdi.TestGSDI;
101 import org.forester.sequence.BasicSequence;
102 import org.forester.sequence.Sequence;
103 import org.forester.species.BasicSpecies;
104 import org.forester.species.Species;
105 import org.forester.surfacing.TestSurfacing;
106 import org.forester.tools.ConfidenceAssessor;
107 import org.forester.tools.SupportCount;
108 import org.forester.tools.TreeSplitMatrix;
109 import org.forester.util.AsciiHistogram;
110 import org.forester.util.BasicDescriptiveStatistics;
111 import org.forester.util.BasicTable;
112 import org.forester.util.BasicTableParser;
113 import org.forester.util.DescriptiveStatistics;
114 import org.forester.util.ForesterConstants;
115 import org.forester.util.ForesterUtil;
116 import org.forester.util.GeneralTable;
117 import org.forester.util.SequenceIdParser;
118 import org.forester.ws.seqdb.SequenceDatabaseEntry;
119 import org.forester.ws.seqdb.SequenceDbWsTools;
120 import org.forester.ws.seqdb.UniProtTaxonomy;
121 import org.forester.ws.wabi.TxSearch;
122 import org.forester.ws.wabi.TxSearch.RANKS;
123 import org.forester.ws.wabi.TxSearch.TAX_NAME_CLASS;
124 import org.forester.ws.wabi.TxSearch.TAX_RANK;
126 @SuppressWarnings( "unused")
127 public final class Test {
129 private final static double ZERO_DIFF = 1.0E-9;
130 private final static String PATH_TO_TEST_DATA = System.getProperty( "user.dir" )
131 + ForesterUtil.getFileSeparator() + "test_data"
132 + ForesterUtil.getFileSeparator();
133 private final static String PATH_TO_RESOURCES = System.getProperty( "user.dir" )
134 + ForesterUtil.getFileSeparator() + "resources"
135 + ForesterUtil.getFileSeparator();
136 private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
137 private static final String PHYLOXML_REMOTE_XSD = ForesterConstants.PHYLO_XML_LOCATION + "/"
138 + ForesterConstants.PHYLO_XML_VERSION + "/"
139 + ForesterConstants.PHYLO_XML_XSD;
140 private static final String PHYLOXML_LOCAL_XSD = PATH_TO_RESOURCES + "phyloxml_schema/"
141 + ForesterConstants.PHYLO_XML_VERSION + "/"
142 + ForesterConstants.PHYLO_XML_XSD;
144 public static boolean isEqual( final double a, final double b ) {
145 return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
148 public static void main( final String[] args ) {
149 System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
150 System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
152 Locale.setDefault( Locale.US );
153 System.out.println( "[Locale: " + Locale.getDefault() + "]" );
156 System.out.print( "[Test if directory with files for testing exists/is readable: " );
157 if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
158 System.out.println( "OK.]" );
161 System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
162 System.out.println( "Testing aborted." );
165 System.out.print( "[Test if resources directory exists/is readable: " );
166 if ( testDir( PATH_TO_RESOURCES ) ) {
167 System.out.println( "OK.]" );
170 System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
171 System.out.println( "Testing aborted." );
174 final long start_time = new Date().getTime();
175 System.out.print( "Domain id: " );
176 if ( !testDomainId() ) {
177 System.out.println( "failed." );
183 System.out.println( "OK." );
184 System.out.print( "Protein id: " );
185 if ( !testProteinId() ) {
186 System.out.println( "failed." );
192 System.out.println( "OK." );
193 System.out.print( "Species: " );
194 if ( !testSpecies() ) {
195 System.out.println( "failed." );
201 System.out.println( "OK." );
202 System.out.print( "Basic domain: " );
203 if ( !testBasicDomain() ) {
204 System.out.println( "failed." );
210 System.out.println( "OK." );
211 System.out.print( "Basic protein: " );
212 if ( !testBasicProtein() ) {
213 System.out.println( "failed." );
219 System.out.println( "OK." );
220 System.out.print( "Sequence writer: " );
221 if ( testSequenceWriter() ) {
222 System.out.println( "OK." );
226 System.out.println( "failed." );
229 System.out.print( "Sequence id parsing: " );
230 if ( testSequenceIdParsing() ) {
231 System.out.println( "OK." );
235 System.out.println( "failed." );
238 System.out.print( "Hmmscan output parser: " );
239 if ( testHmmscanOutputParser() ) {
240 System.out.println( "OK." );
244 System.out.println( "failed." );
247 System.out.print( "Basic node methods: " );
248 if ( Test.testBasicNodeMethods() ) {
249 System.out.println( "OK." );
253 System.out.println( "failed." );
256 System.out.print( "Taxonomy code extraction: " );
257 if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
258 System.out.println( "OK." );
262 System.out.println( "failed." );
265 System.out.print( "SN extraction: " );
266 if ( Test.testExtractSNFromNodeName() ) {
267 System.out.println( "OK." );
271 System.out.println( "failed." );
274 System.out.print( "Taxonomy extraction (general): " );
275 if ( Test.testTaxonomyExtraction() ) {
276 System.out.println( "OK." );
280 System.out.println( "failed." );
283 System.out.print( "UniProtKB id extraction: " );
284 if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
285 System.out.println( "OK." );
289 System.out.println( "failed." );
292 System.out.print( "Uri for Aptx web sequence accession: " );
293 if ( Test.testCreateUriForSeqWeb() ) {
294 System.out.println( "OK." );
298 System.out.println( "failed." );
301 System.out.print( "Basic node construction and parsing of NHX (node level): " );
302 if ( Test.testNHXNodeParsing() ) {
303 System.out.println( "OK." );
307 System.out.println( "failed." );
310 System.out.print( "NHX parsing iterating: " );
311 if ( Test.testNHParsingIter() ) {
312 System.out.println( "OK." );
316 System.out.println( "failed." );
319 System.out.print( "NH parsing: " );
320 if ( Test.testNHParsing() ) {
321 System.out.println( "OK." );
325 System.out.println( "failed." );
328 System.out.print( "Conversion to NHX (node level): " );
329 if ( Test.testNHXconversion() ) {
330 System.out.println( "OK." );
334 System.out.println( "failed." );
337 System.out.print( "NHX parsing: " );
338 if ( Test.testNHXParsing() ) {
339 System.out.println( "OK." );
343 System.out.println( "failed." );
346 System.out.print( "NHX parsing with quotes: " );
347 if ( Test.testNHXParsingQuotes() ) {
348 System.out.println( "OK." );
352 System.out.println( "failed." );
355 System.out.print( "NHX parsing (MrBayes): " );
356 if ( Test.testNHXParsingMB() ) {
357 System.out.println( "OK." );
361 System.out.println( "failed." );
364 System.out.print( "Nexus characters parsing: " );
365 if ( Test.testNexusCharactersParsing() ) {
366 System.out.println( "OK." );
370 System.out.println( "failed." );
373 System.out.print( "Nexus tree parsing iterating: " );
374 if ( Test.testNexusTreeParsingIterating() ) {
375 System.out.println( "OK." );
379 System.out.println( "failed." );
382 System.out.print( "Nexus tree parsing: " );
383 if ( Test.testNexusTreeParsing() ) {
384 System.out.println( "OK." );
388 System.out.println( "failed." );
391 System.out.print( "Nexus tree parsing (translating): " );
392 if ( Test.testNexusTreeParsingTranslating() ) {
393 System.out.println( "OK." );
397 System.out.println( "failed." );
400 System.out.print( "Nexus matrix parsing: " );
401 if ( Test.testNexusMatrixParsing() ) {
402 System.out.println( "OK." );
406 System.out.println( "failed." );
409 System.out.print( "Basic phyloXML parsing: " );
410 if ( Test.testBasicPhyloXMLparsing() ) {
411 System.out.println( "OK." );
415 System.out.println( "failed." );
418 System.out.print( "Basic phyloXML parsing (validating against schema): " );
419 if ( testBasicPhyloXMLparsingValidating() ) {
420 System.out.println( "OK." );
424 System.out.println( "failed." );
427 System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
428 if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
429 System.out.println( "OK." );
433 System.out.println( "failed." );
436 System.out.print( "phyloXML Distribution Element: " );
437 if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
438 System.out.println( "OK." );
442 System.out.println( "failed." );
445 System.out.print( "Tol XML parsing: " );
446 if ( Test.testBasicTolXMLparsing() ) {
447 System.out.println( "OK." );
451 System.out.println( "failed." );
454 System.out.print( "Copying of node data: " );
455 if ( Test.testCopyOfNodeData() ) {
456 System.out.println( "OK." );
460 System.out.println( "failed." );
463 System.out.print( "Basic tree methods: " );
464 if ( Test.testBasicTreeMethods() ) {
465 System.out.println( "OK." );
469 System.out.println( "failed." );
472 System.out.print( "Tree methods: " );
473 if ( Test.testTreeMethods() ) {
474 System.out.println( "OK." );
478 System.out.println( "failed." );
481 System.out.print( "Postorder Iterator: " );
482 if ( Test.testPostOrderIterator() ) {
483 System.out.println( "OK." );
487 System.out.println( "failed." );
490 System.out.print( "Preorder Iterator: " );
491 if ( Test.testPreOrderIterator() ) {
492 System.out.println( "OK." );
496 System.out.println( "failed." );
499 System.out.print( "Levelorder Iterator: " );
500 if ( Test.testLevelOrderIterator() ) {
501 System.out.println( "OK." );
505 System.out.println( "failed." );
508 System.out.print( "Re-id methods: " );
509 if ( Test.testReIdMethods() ) {
510 System.out.println( "OK." );
514 System.out.println( "failed." );
517 System.out.print( "Methods on last external nodes: " );
518 if ( Test.testLastExternalNodeMethods() ) {
519 System.out.println( "OK." );
523 System.out.println( "failed." );
526 System.out.print( "Methods on external nodes: " );
527 if ( Test.testExternalNodeRelatedMethods() ) {
528 System.out.println( "OK." );
532 System.out.println( "failed." );
535 System.out.print( "Deletion of external nodes: " );
536 if ( Test.testDeletionOfExternalNodes() ) {
537 System.out.println( "OK." );
541 System.out.println( "failed." );
544 System.out.print( "Subtree deletion: " );
545 if ( Test.testSubtreeDeletion() ) {
546 System.out.println( "OK." );
550 System.out.println( "failed." );
553 System.out.print( "Phylogeny branch: " );
554 if ( Test.testPhylogenyBranch() ) {
555 System.out.println( "OK." );
559 System.out.println( "failed." );
562 System.out.print( "Rerooting: " );
563 if ( Test.testRerooting() ) {
564 System.out.println( "OK." );
568 System.out.println( "failed." );
571 System.out.print( "Mipoint rooting: " );
572 if ( Test.testMidpointrooting() ) {
573 System.out.println( "OK." );
577 System.out.println( "failed." );
580 System.out.print( "Node removal: " );
581 if ( Test.testNodeRemoval() ) {
582 System.out.println( "OK." );
586 System.out.println( "failed." );
589 System.out.print( "Support count: " );
590 if ( Test.testSupportCount() ) {
591 System.out.println( "OK." );
595 System.out.println( "failed." );
598 System.out.print( "Support transfer: " );
599 if ( Test.testSupportTransfer() ) {
600 System.out.println( "OK." );
604 System.out.println( "failed." );
607 System.out.print( "Finding of LCA: " );
608 if ( Test.testGetLCA() ) {
609 System.out.println( "OK." );
613 System.out.println( "failed." );
616 System.out.print( "Finding of LCA 2: " );
617 if ( Test.testGetLCA2() ) {
618 System.out.println( "OK." );
622 System.out.println( "failed." );
625 System.out.print( "Calculation of distance between nodes: " );
626 if ( Test.testGetDistance() ) {
627 System.out.println( "OK." );
631 System.out.println( "failed." );
634 System.out.print( "Descriptive statistics: " );
635 if ( Test.testDescriptiveStatistics() ) {
636 System.out.println( "OK." );
640 System.out.println( "failed." );
643 System.out.print( "Data objects and methods: " );
644 if ( Test.testDataObjects() ) {
645 System.out.println( "OK." );
649 System.out.println( "failed." );
652 System.out.print( "Properties map: " );
653 if ( Test.testPropertiesMap() ) {
654 System.out.println( "OK." );
658 System.out.println( "failed." );
661 System.out.print( "SDIse: " );
662 if ( Test.testSDIse() ) {
663 System.out.println( "OK." );
667 System.out.println( "failed." );
670 System.out.print( "SDIunrooted: " );
671 if ( Test.testSDIunrooted() ) {
672 System.out.println( "OK." );
676 System.out.println( "failed." );
679 System.out.print( "GSDI: " );
680 if ( TestGSDI.test() ) {
681 System.out.println( "OK." );
685 System.out.println( "failed." );
688 System.out.print( "RIO: " );
689 if ( TestRIO.test() ) {
690 System.out.println( "OK." );
694 System.out.println( "failed." );
697 System.out.print( "Phylogeny reconstruction:" );
698 System.out.println();
699 if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
700 System.out.println( "OK." );
704 System.out.println( "failed." );
707 System.out.print( "Analysis of domain architectures: " );
708 System.out.println();
709 if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
710 System.out.println( "OK." );
714 System.out.println( "failed." );
717 System.out.print( "GO: " );
718 System.out.println();
719 if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
720 System.out.println( "OK." );
724 System.out.println( "failed." );
727 System.out.print( "Modeling tools: " );
728 if ( TestPccx.test() ) {
729 System.out.println( "OK." );
733 System.out.println( "failed." );
736 System.out.print( "Split Matrix strict: " );
737 if ( Test.testSplitStrict() ) {
738 System.out.println( "OK." );
742 System.out.println( "failed." );
745 System.out.print( "Split Matrix: " );
746 if ( Test.testSplit() ) {
747 System.out.println( "OK." );
751 System.out.println( "failed." );
754 System.out.print( "Confidence Assessor: " );
755 if ( Test.testConfidenceAssessor() ) {
756 System.out.println( "OK." );
760 System.out.println( "failed." );
763 System.out.print( "Basic table: " );
764 if ( Test.testBasicTable() ) {
765 System.out.println( "OK." );
769 System.out.println( "failed." );
772 System.out.print( "General table: " );
773 if ( Test.testGeneralTable() ) {
774 System.out.println( "OK." );
778 System.out.println( "failed." );
781 System.out.print( "Amino acid sequence: " );
782 if ( Test.testAminoAcidSequence() ) {
783 System.out.println( "OK." );
787 System.out.println( "failed." );
790 System.out.print( "General MSA parser: " );
791 if ( Test.testGeneralMsaParser() ) {
792 System.out.println( "OK." );
796 System.out.println( "failed." );
799 System.out.print( "Fasta parser for msa: " );
800 if ( Test.testFastaParser() ) {
801 System.out.println( "OK." );
805 System.out.println( "failed." );
808 System.out.print( "Creation of balanced phylogeny: " );
809 if ( Test.testCreateBalancedPhylogeny() ) {
810 System.out.println( "OK." );
814 System.out.println( "failed." );
817 System.out.print( "EMBL Entry Retrieval: " );
818 if ( Test.testEmblEntryRetrieval() ) {
819 System.out.println( "OK." );
823 System.out.println( "failed." );
826 System.out.print( "Uniprot Entry Retrieval: " );
827 if ( Test.testUniprotEntryRetrieval() ) {
828 System.out.println( "OK." );
832 System.out.println( "failed." );
835 System.out.print( "Uniprot Taxonomy Search: " );
836 if ( Test.testUniprotTaxonomySearch() ) {
837 System.out.println( "OK." );
841 System.out.println( "failed." );
846 final String os = ForesterUtil.OS_NAME.toLowerCase();
847 if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
848 path = "/usr/local/bin/mafft";
850 else if ( os.indexOf( "win" ) >= 0 ) {
851 path = "C:\\Program Files\\mafft-win\\mafft.bat";
854 path = "/home/czmasek/bin/mafft";
856 if ( !MsaInferrer.isInstalled( path ) ) {
859 if ( !MsaInferrer.isInstalled( path ) ) {
860 path = "/usr/local/bin/mafft";
862 if ( MsaInferrer.isInstalled( path ) ) {
863 System.out.print( "MAFFT (external program): " );
864 if ( Test.testMafft( path ) ) {
865 System.out.println( "OK." );
869 System.out.println( "failed [will not count towards failed tests]" );
873 System.out.print( "Next nodes with collapsed: " );
874 if ( Test.testNextNodeWithCollapsing() ) {
875 System.out.println( "OK." );
879 System.out.println( "failed." );
882 System.out.print( "Simple MSA quality: " );
883 if ( Test.testMsaQualityMethod() ) {
884 System.out.println( "OK." );
888 System.out.println( "failed." );
891 System.out.println();
892 final Runtime rt = java.lang.Runtime.getRuntime();
893 final long free_memory = rt.freeMemory() / 1000000;
894 final long total_memory = rt.totalMemory() / 1000000;
895 System.out.println( "Running time : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
896 + free_memory + "MB, total memory: " + total_memory + "MB)" );
897 System.out.println();
898 System.out.println( "Successful tests: " + succeeded );
899 System.out.println( "Failed tests: " + failed );
900 System.out.println();
902 System.out.println( "OK." );
905 System.out.println( "Not OK." );
909 private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
910 final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
914 private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
915 return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
918 private static boolean testAminoAcidSequence() {
920 final Sequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
921 if ( aa1.getLength() != 13 ) {
924 if ( aa1.getResidueAt( 0 ) != 'A' ) {
927 if ( aa1.getResidueAt( 2 ) != 'K' ) {
930 if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
933 final Sequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
934 if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZXXU" ) ) {
937 final Sequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
938 if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
941 final Sequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
942 if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
946 catch ( final Exception e ) {
953 private static boolean testBasicDomain() {
955 final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
956 if ( !pd.getDomainId().getId().equals( "id" ) ) {
959 if ( pd.getNumber() != 1 ) {
962 if ( pd.getTotalCount() != 4 ) {
965 if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
968 final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
969 final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
970 final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
971 final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
972 final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
973 if ( !a1.equals( a1 ) ) {
976 if ( !a1.equals( a1_copy ) ) {
979 if ( !a1.equals( a1_equal ) ) {
982 if ( !a1.equals( a2 ) ) {
985 if ( a1.equals( a3 ) ) {
988 if ( a1.compareTo( a1 ) != 0 ) {
991 if ( a1.compareTo( a1_copy ) != 0 ) {
994 if ( a1.compareTo( a1_equal ) != 0 ) {
997 if ( a1.compareTo( a2 ) != 0 ) {
1000 if ( a1.compareTo( a3 ) != 0 ) {
1004 catch ( final Exception e ) {
1005 e.printStackTrace( System.out );
1011 private static boolean testBasicNodeMethods() {
1013 if ( PhylogenyNode.getNodeCount() != 0 ) {
1016 final PhylogenyNode n1 = new PhylogenyNode();
1017 final PhylogenyNode n2 = PhylogenyNode
1018 .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1019 final PhylogenyNode n3 = PhylogenyNode
1020 .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1021 final PhylogenyNode n4 = PhylogenyNode
1022 .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1023 if ( n1.isHasAssignedEvent() ) {
1026 if ( PhylogenyNode.getNodeCount() != 4 ) {
1029 if ( n3.getIndicator() != 0 ) {
1032 if ( n3.getNumberOfExternalNodes() != 1 ) {
1035 if ( !n3.isExternal() ) {
1038 if ( !n3.isRoot() ) {
1041 if ( !n4.getName().equals( "n4" ) ) {
1045 catch ( final Exception e ) {
1046 e.printStackTrace( System.out );
1052 private static boolean testBasicPhyloXMLparsing() {
1054 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1055 final PhyloXmlParser xml_parser = new PhyloXmlParser();
1056 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1058 if ( xml_parser.getErrorCount() > 0 ) {
1059 System.out.println( xml_parser.getErrorMessages().toString() );
1062 if ( phylogenies_0.length != 4 ) {
1065 final Phylogeny t1 = phylogenies_0[ 0 ];
1066 final Phylogeny t2 = phylogenies_0[ 1 ];
1067 final Phylogeny t3 = phylogenies_0[ 2 ];
1068 final Phylogeny t4 = phylogenies_0[ 3 ];
1069 if ( t1.getNumberOfExternalNodes() != 1 ) {
1072 if ( !t1.isRooted() ) {
1075 if ( t1.isRerootable() ) {
1078 if ( !t1.getType().equals( "gene_tree" ) ) {
1081 if ( t2.getNumberOfExternalNodes() != 2 ) {
1084 if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1087 if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1090 if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1093 if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1096 if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1099 if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1102 if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1103 .startsWith( "actgtgggggt" ) ) {
1106 if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1107 .startsWith( "ctgtgatgcat" ) ) {
1110 if ( t3.getNumberOfExternalNodes() != 4 ) {
1113 if ( !t1.getName().equals( "t1" ) ) {
1116 if ( !t2.getName().equals( "t2" ) ) {
1119 if ( !t3.getName().equals( "t3" ) ) {
1122 if ( !t4.getName().equals( "t4" ) ) {
1125 if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1128 if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1131 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1134 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1135 .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1138 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1141 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1144 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1147 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1148 .equals( "apoptosis" ) ) {
1151 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1152 .equals( "GO:0006915" ) ) {
1155 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1156 .equals( "UniProtKB" ) ) {
1159 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1160 .equals( "experimental" ) ) {
1163 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1164 .equals( "function" ) ) {
1167 if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1168 .getValue() != 1 ) {
1171 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1172 .getType().equals( "ml" ) ) {
1175 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1176 .equals( "apoptosis" ) ) {
1179 if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1180 .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1183 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1184 .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1187 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1188 .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1191 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1192 .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1195 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1196 .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1199 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1200 .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1203 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1204 .equals( "GO:0005829" ) ) {
1207 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1208 .equals( "intracellular organelle" ) ) {
1211 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1214 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1215 .equals( "UniProt link" ) ) ) {
1218 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1222 catch ( final Exception e ) {
1223 e.printStackTrace( System.out );
1229 private static boolean testBasicPhyloXMLparsingRoundtrip() {
1231 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1232 final PhyloXmlParser xml_parser = new PhyloXmlParser();
1233 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1234 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1237 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1239 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1241 if ( xml_parser.getErrorCount() > 0 ) {
1242 System.out.println( xml_parser.getErrorMessages().toString() );
1245 if ( phylogenies_0.length != 4 ) {
1248 final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1249 final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1250 if ( phylogenies_t1.length != 1 ) {
1253 final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1254 if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1257 if ( !t1_rt.isRooted() ) {
1260 if ( t1_rt.isRerootable() ) {
1263 if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1266 final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1267 final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1268 final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1269 if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1272 if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1275 if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1278 if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1281 if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1282 .startsWith( "actgtgggggt" ) ) {
1285 if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1286 .startsWith( "ctgtgatgcat" ) ) {
1289 final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1290 final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1291 final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1292 final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1293 if ( phylogenies_1.length != 1 ) {
1296 final Phylogeny t3_rt = phylogenies_1[ 0 ];
1297 if ( !t3_rt.getName().equals( "t3" ) ) {
1300 if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
1303 if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
1306 if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
1309 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1312 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
1313 .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1316 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1319 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1322 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
1323 .equals( "UniProtKB" ) ) {
1326 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1327 .equals( "apoptosis" ) ) {
1330 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1331 .equals( "GO:0006915" ) ) {
1334 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1335 .equals( "UniProtKB" ) ) {
1338 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1339 .equals( "experimental" ) ) {
1342 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1343 .equals( "function" ) ) {
1346 if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1347 .getValue() != 1 ) {
1350 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1351 .getType().equals( "ml" ) ) {
1354 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1355 .equals( "apoptosis" ) ) {
1358 if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1359 .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1362 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1363 .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1366 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1367 .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1370 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1371 .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1374 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1375 .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1378 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1379 .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1382 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1383 .equals( "GO:0005829" ) ) {
1386 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1387 .equals( "intracellular organelle" ) ) {
1390 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1393 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1394 .equals( "UniProt link" ) ) ) {
1397 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1400 if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
1403 if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
1404 .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." ) ) ) {
1407 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
1410 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
1413 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
1416 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
1419 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
1420 .equals( "ncbi" ) ) {
1423 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
1426 if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1427 .getName().equals( "B" ) ) {
1430 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1431 .getFrom() != 21 ) {
1434 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
1437 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1438 .getLength() != 24 ) {
1441 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
1442 .getConfidence() != 2144 ) {
1445 if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
1446 .equals( "pfam" ) ) {
1449 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
1452 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1455 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
1458 if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
1461 final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
1462 if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
1465 if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
1468 if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
1471 if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
1474 if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
1477 if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
1480 if ( taxbb.getSynonyms().size() != 2 ) {
1483 if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
1486 if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
1489 if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
1492 if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
1495 if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
1498 if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
1499 .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
1503 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
1506 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
1509 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
1512 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
1515 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
1518 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
1521 if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
1525 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
1528 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
1529 .equalsIgnoreCase( "435" ) ) {
1532 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
1535 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
1536 .equalsIgnoreCase( "443.7" ) ) {
1539 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
1542 if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
1545 if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
1546 .equalsIgnoreCase( "433" ) ) {
1550 catch ( final Exception e ) {
1551 e.printStackTrace( System.out );
1557 private static boolean testBasicPhyloXMLparsingValidating() {
1559 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1560 PhyloXmlParser xml_parser = null;
1562 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
1564 catch ( final Exception e ) {
1565 // Do nothing -- means were not running from jar.
1567 if ( xml_parser == null ) {
1568 xml_parser = new PhyloXmlParser();
1569 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1570 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1573 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1576 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1578 if ( xml_parser.getErrorCount() > 0 ) {
1579 System.out.println( xml_parser.getErrorMessages().toString() );
1582 if ( phylogenies_0.length != 4 ) {
1585 final Phylogeny t1 = phylogenies_0[ 0 ];
1586 final Phylogeny t2 = phylogenies_0[ 1 ];
1587 final Phylogeny t3 = phylogenies_0[ 2 ];
1588 final Phylogeny t4 = phylogenies_0[ 3 ];
1589 if ( !t1.getName().equals( "t1" ) ) {
1592 if ( !t2.getName().equals( "t2" ) ) {
1595 if ( !t3.getName().equals( "t3" ) ) {
1598 if ( !t4.getName().equals( "t4" ) ) {
1601 if ( t1.getNumberOfExternalNodes() != 1 ) {
1604 if ( t2.getNumberOfExternalNodes() != 2 ) {
1607 if ( t3.getNumberOfExternalNodes() != 4 ) {
1610 final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
1611 final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
1612 if ( xml_parser.getErrorCount() > 0 ) {
1613 System.out.println( "errors:" );
1614 System.out.println( xml_parser.getErrorMessages().toString() );
1617 if ( phylogenies_1.length != 4 ) {
1620 final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
1622 if ( xml_parser.getErrorCount() > 0 ) {
1623 System.out.println( "errors:" );
1624 System.out.println( xml_parser.getErrorMessages().toString() );
1627 if ( phylogenies_2.length != 1 ) {
1630 if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
1633 final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
1635 if ( xml_parser.getErrorCount() > 0 ) {
1636 System.out.println( xml_parser.getErrorMessages().toString() );
1639 if ( phylogenies_3.length != 2 ) {
1642 final Phylogeny a = phylogenies_3[ 0 ];
1643 if ( !a.getName().equals( "tree 4" ) ) {
1646 if ( a.getNumberOfExternalNodes() != 3 ) {
1649 if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
1652 if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
1655 final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
1657 if ( xml_parser.getErrorCount() > 0 ) {
1658 System.out.println( xml_parser.getErrorMessages().toString() );
1661 if ( phylogenies_4.length != 1 ) {
1664 final Phylogeny s = phylogenies_4[ 0 ];
1665 if ( s.getNumberOfExternalNodes() != 6 ) {
1668 s.getNode( "first" );
1670 s.getNode( "\"<a'b&c'd\">\"" );
1671 s.getNode( "'''\"" );
1672 s.getNode( "\"\"\"" );
1673 s.getNode( "dick & doof" );
1675 catch ( final Exception e ) {
1676 e.printStackTrace( System.out );
1682 private static boolean testBasicProtein() {
1684 final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
1685 final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1686 final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
1687 final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
1688 final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
1689 final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
1690 final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1691 final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1692 p0.addProteinDomain( y );
1693 p0.addProteinDomain( e );
1694 p0.addProteinDomain( b );
1695 p0.addProteinDomain( c );
1696 p0.addProteinDomain( d );
1697 p0.addProteinDomain( a );
1698 p0.addProteinDomain( x );
1699 if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
1702 if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
1706 final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
1707 final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1708 aa0.addProteinDomain( a1 );
1709 if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
1712 if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
1716 final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
1717 final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1718 final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
1719 aa1.addProteinDomain( a11 );
1720 aa1.addProteinDomain( a12 );
1721 if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
1724 if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
1727 aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1728 if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
1731 if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
1734 if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
1737 aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1738 if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
1741 if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
1744 if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
1747 if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
1750 aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1751 if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
1754 if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
1757 if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
1760 if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
1763 aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
1764 if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
1767 if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
1770 if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
1773 if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
1777 final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
1778 final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
1779 final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
1780 final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
1781 final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
1782 final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
1783 final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
1784 final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
1785 final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
1786 final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
1787 final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
1788 final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1789 final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
1790 final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
1791 final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
1792 final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
1793 final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
1794 final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
1795 final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
1796 final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
1797 final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
1798 p00.addProteinDomain( y0 );
1799 p00.addProteinDomain( e0 );
1800 p00.addProteinDomain( b0 );
1801 p00.addProteinDomain( c0 );
1802 p00.addProteinDomain( d0 );
1803 p00.addProteinDomain( a0 );
1804 p00.addProteinDomain( x0 );
1805 p00.addProteinDomain( y1 );
1806 p00.addProteinDomain( y2 );
1807 p00.addProteinDomain( y3 );
1808 p00.addProteinDomain( e1 );
1809 p00.addProteinDomain( e2 );
1810 p00.addProteinDomain( e3 );
1811 p00.addProteinDomain( e4 );
1812 p00.addProteinDomain( e5 );
1813 p00.addProteinDomain( z0 );
1814 p00.addProteinDomain( z1 );
1815 p00.addProteinDomain( z2 );
1816 p00.addProteinDomain( zz0 );
1817 p00.addProteinDomain( zz1 );
1818 if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
1821 if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
1824 if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
1827 if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
1830 if ( !p00.toDomainArchitectureString( "~", 7, "" ).equals( "a~b~c~d~e~e~e~e~e~e~x~y~y~y~y~z~z~z~Z~Z" ) ) {
1833 // A0 A10 B15 A20 B25 A30 B35 B40 C50 A60 C70 D80
1834 final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1835 final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
1836 final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
1837 final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
1838 final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
1839 final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
1840 final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
1841 final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
1842 final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
1843 final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
1844 final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
1845 final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
1846 final BasicProtein p = new BasicProtein( "p", "owl", 0 );
1847 p.addProteinDomain( B15 );
1848 p.addProteinDomain( C50 );
1849 p.addProteinDomain( A60 );
1850 p.addProteinDomain( A30 );
1851 p.addProteinDomain( C70 );
1852 p.addProteinDomain( B35 );
1853 p.addProteinDomain( B40 );
1854 p.addProteinDomain( A0 );
1855 p.addProteinDomain( A10 );
1856 p.addProteinDomain( A20 );
1857 p.addProteinDomain( B25 );
1858 p.addProteinDomain( D80 );
1859 List<DomainId> domains_ids = new ArrayList<DomainId>();
1860 domains_ids.add( new DomainId( "A" ) );
1861 domains_ids.add( new DomainId( "B" ) );
1862 domains_ids.add( new DomainId( "C" ) );
1863 if ( !p.contains( domains_ids, false ) ) {
1866 if ( !p.contains( domains_ids, true ) ) {
1869 domains_ids.add( new DomainId( "X" ) );
1870 if ( p.contains( domains_ids, false ) ) {
1873 if ( p.contains( domains_ids, true ) ) {
1876 domains_ids = new ArrayList<DomainId>();
1877 domains_ids.add( new DomainId( "A" ) );
1878 domains_ids.add( new DomainId( "C" ) );
1879 domains_ids.add( new DomainId( "D" ) );
1880 if ( !p.contains( domains_ids, false ) ) {
1883 if ( !p.contains( domains_ids, true ) ) {
1886 domains_ids = new ArrayList<DomainId>();
1887 domains_ids.add( new DomainId( "A" ) );
1888 domains_ids.add( new DomainId( "D" ) );
1889 domains_ids.add( new DomainId( "C" ) );
1890 if ( !p.contains( domains_ids, false ) ) {
1893 if ( p.contains( domains_ids, true ) ) {
1896 domains_ids = new ArrayList<DomainId>();
1897 domains_ids.add( new DomainId( "A" ) );
1898 domains_ids.add( new DomainId( "A" ) );
1899 domains_ids.add( new DomainId( "B" ) );
1900 if ( !p.contains( domains_ids, false ) ) {
1903 if ( !p.contains( domains_ids, true ) ) {
1906 domains_ids = new ArrayList<DomainId>();
1907 domains_ids.add( new DomainId( "A" ) );
1908 domains_ids.add( new DomainId( "A" ) );
1909 domains_ids.add( new DomainId( "A" ) );
1910 domains_ids.add( new DomainId( "B" ) );
1911 domains_ids.add( new DomainId( "B" ) );
1912 if ( !p.contains( domains_ids, false ) ) {
1915 if ( !p.contains( domains_ids, true ) ) {
1918 domains_ids = new ArrayList<DomainId>();
1919 domains_ids.add( new DomainId( "A" ) );
1920 domains_ids.add( new DomainId( "A" ) );
1921 domains_ids.add( new DomainId( "A" ) );
1922 domains_ids.add( new DomainId( "A" ) );
1923 domains_ids.add( new DomainId( "B" ) );
1924 domains_ids.add( new DomainId( "B" ) );
1925 if ( !p.contains( domains_ids, false ) ) {
1928 if ( !p.contains( domains_ids, true ) ) {
1931 domains_ids = new ArrayList<DomainId>();
1932 domains_ids.add( new DomainId( "A" ) );
1933 domains_ids.add( new DomainId( "A" ) );
1934 domains_ids.add( new DomainId( "A" ) );
1935 domains_ids.add( new DomainId( "A" ) );
1936 domains_ids.add( new DomainId( "A" ) );
1937 domains_ids.add( new DomainId( "B" ) );
1938 domains_ids.add( new DomainId( "B" ) );
1939 if ( !p.contains( domains_ids, false ) ) {
1942 if ( p.contains( domains_ids, true ) ) {
1945 domains_ids = new ArrayList<DomainId>();
1946 domains_ids.add( new DomainId( "A" ) );
1947 domains_ids.add( new DomainId( "A" ) );
1948 domains_ids.add( new DomainId( "B" ) );
1949 domains_ids.add( new DomainId( "A" ) );
1950 domains_ids.add( new DomainId( "B" ) );
1951 domains_ids.add( new DomainId( "A" ) );
1952 domains_ids.add( new DomainId( "B" ) );
1953 domains_ids.add( new DomainId( "B" ) );
1954 domains_ids.add( new DomainId( "C" ) );
1955 domains_ids.add( new DomainId( "A" ) );
1956 domains_ids.add( new DomainId( "C" ) );
1957 domains_ids.add( new DomainId( "D" ) );
1958 if ( !p.contains( domains_ids, false ) ) {
1961 if ( !p.contains( domains_ids, true ) ) {
1964 domains_ids = new ArrayList<DomainId>();
1965 domains_ids.add( new DomainId( "A" ) );
1966 domains_ids.add( new DomainId( "B" ) );
1967 domains_ids.add( new DomainId( "A" ) );
1968 domains_ids.add( new DomainId( "B" ) );
1969 domains_ids.add( new DomainId( "A" ) );
1970 domains_ids.add( new DomainId( "B" ) );
1971 domains_ids.add( new DomainId( "B" ) );
1972 domains_ids.add( new DomainId( "A" ) );
1973 domains_ids.add( new DomainId( "C" ) );
1974 domains_ids.add( new DomainId( "D" ) );
1975 if ( !p.contains( domains_ids, false ) ) {
1978 if ( !p.contains( domains_ids, true ) ) {
1981 domains_ids = new ArrayList<DomainId>();
1982 domains_ids.add( new DomainId( "A" ) );
1983 domains_ids.add( new DomainId( "A" ) );
1984 domains_ids.add( new DomainId( "B" ) );
1985 domains_ids.add( new DomainId( "A" ) );
1986 domains_ids.add( new DomainId( "B" ) );
1987 domains_ids.add( new DomainId( "A" ) );
1988 domains_ids.add( new DomainId( "B" ) );
1989 domains_ids.add( new DomainId( "B" ) );
1990 domains_ids.add( new DomainId( "C" ) );
1991 domains_ids.add( new DomainId( "C" ) );
1992 domains_ids.add( new DomainId( "A" ) );
1993 domains_ids.add( new DomainId( "C" ) );
1994 domains_ids.add( new DomainId( "D" ) );
1995 if ( !p.contains( domains_ids, false ) ) {
1998 if ( p.contains( domains_ids, true ) ) {
2001 domains_ids = new ArrayList<DomainId>();
2002 domains_ids.add( new DomainId( "A" ) );
2003 domains_ids.add( new DomainId( "A" ) );
2004 domains_ids.add( new DomainId( "A" ) );
2005 domains_ids.add( new DomainId( "B" ) );
2006 domains_ids.add( new DomainId( "A" ) );
2007 domains_ids.add( new DomainId( "B" ) );
2008 domains_ids.add( new DomainId( "A" ) );
2009 domains_ids.add( new DomainId( "B" ) );
2010 domains_ids.add( new DomainId( "B" ) );
2011 domains_ids.add( new DomainId( "C" ) );
2012 domains_ids.add( new DomainId( "A" ) );
2013 domains_ids.add( new DomainId( "C" ) );
2014 domains_ids.add( new DomainId( "D" ) );
2015 if ( !p.contains( domains_ids, false ) ) {
2018 if ( p.contains( domains_ids, true ) ) {
2021 domains_ids = new ArrayList<DomainId>();
2022 domains_ids.add( new DomainId( "A" ) );
2023 domains_ids.add( new DomainId( "A" ) );
2024 domains_ids.add( new DomainId( "B" ) );
2025 domains_ids.add( new DomainId( "A" ) );
2026 domains_ids.add( new DomainId( "B" ) );
2027 domains_ids.add( new DomainId( "A" ) );
2028 domains_ids.add( new DomainId( "B" ) );
2029 domains_ids.add( new DomainId( "B" ) );
2030 domains_ids.add( new DomainId( "A" ) );
2031 domains_ids.add( new DomainId( "D" ) );
2032 if ( !p.contains( domains_ids, false ) ) {
2035 if ( !p.contains( domains_ids, true ) ) {
2038 domains_ids = new ArrayList<DomainId>();
2039 domains_ids.add( new DomainId( "A" ) );
2040 domains_ids.add( new DomainId( "A" ) );
2041 domains_ids.add( new DomainId( "B" ) );
2042 domains_ids.add( new DomainId( "A" ) );
2043 domains_ids.add( new DomainId( "B" ) );
2044 domains_ids.add( new DomainId( "A" ) );
2045 domains_ids.add( new DomainId( "B" ) );
2046 domains_ids.add( new DomainId( "B" ) );
2047 domains_ids.add( new DomainId( "C" ) );
2048 domains_ids.add( new DomainId( "A" ) );
2049 domains_ids.add( new DomainId( "C" ) );
2050 domains_ids.add( new DomainId( "D" ) );
2051 domains_ids.add( new DomainId( "X" ) );
2052 if ( p.contains( domains_ids, false ) ) {
2055 if ( p.contains( domains_ids, true ) ) {
2058 domains_ids = new ArrayList<DomainId>();
2059 domains_ids.add( new DomainId( "X" ) );
2060 domains_ids.add( new DomainId( "A" ) );
2061 domains_ids.add( new DomainId( "A" ) );
2062 domains_ids.add( new DomainId( "B" ) );
2063 domains_ids.add( new DomainId( "A" ) );
2064 domains_ids.add( new DomainId( "B" ) );
2065 domains_ids.add( new DomainId( "A" ) );
2066 domains_ids.add( new DomainId( "B" ) );
2067 domains_ids.add( new DomainId( "B" ) );
2068 domains_ids.add( new DomainId( "C" ) );
2069 domains_ids.add( new DomainId( "A" ) );
2070 domains_ids.add( new DomainId( "C" ) );
2071 domains_ids.add( new DomainId( "D" ) );
2072 if ( p.contains( domains_ids, false ) ) {
2075 if ( p.contains( domains_ids, true ) ) {
2078 domains_ids = new ArrayList<DomainId>();
2079 domains_ids.add( new DomainId( "A" ) );
2080 domains_ids.add( new DomainId( "A" ) );
2081 domains_ids.add( new DomainId( "B" ) );
2082 domains_ids.add( new DomainId( "A" ) );
2083 domains_ids.add( new DomainId( "B" ) );
2084 domains_ids.add( new DomainId( "B" ) );
2085 domains_ids.add( new DomainId( "A" ) );
2086 domains_ids.add( new DomainId( "B" ) );
2087 domains_ids.add( new DomainId( "C" ) );
2088 domains_ids.add( new DomainId( "A" ) );
2089 domains_ids.add( new DomainId( "C" ) );
2090 domains_ids.add( new DomainId( "D" ) );
2091 if ( !p.contains( domains_ids, false ) ) {
2094 if ( p.contains( domains_ids, true ) ) {
2098 catch ( final Exception e ) {
2099 e.printStackTrace( System.out );
2105 private static boolean testBasicTable() {
2107 final BasicTable<String> t0 = new BasicTable<String>();
2108 if ( t0.getNumberOfColumns() != 0 ) {
2111 if ( t0.getNumberOfRows() != 0 ) {
2114 t0.setValue( 3, 2, "23" );
2115 t0.setValue( 10, 1, "error" );
2116 t0.setValue( 10, 1, "110" );
2117 t0.setValue( 9, 1, "19" );
2118 t0.setValue( 1, 10, "101" );
2119 t0.setValue( 10, 10, "1010" );
2120 t0.setValue( 100, 10, "10100" );
2121 t0.setValue( 0, 0, "00" );
2122 if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2125 if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2128 if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2131 if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2134 if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2137 if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2140 if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2143 if ( t0.getNumberOfColumns() != 101 ) {
2146 if ( t0.getNumberOfRows() != 11 ) {
2149 if ( t0.getValueAsString( 49, 4 ) != null ) {
2152 final String l = ForesterUtil.getLineSeparator();
2153 final StringBuffer source = new StringBuffer();
2154 source.append( "" + l );
2155 source.append( "# 1 1 1 1 1 1 1 1" + l );
2156 source.append( " 00 01 02 03" + l );
2157 source.append( " 10 11 12 13 " + l );
2158 source.append( "20 21 22 23 " + l );
2159 source.append( " 30 31 32 33" + l );
2160 source.append( "40 41 42 43" + l );
2161 source.append( " # 1 1 1 1 1 " + l );
2162 source.append( "50 51 52 53 54" + l );
2163 final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2164 if ( t1.getNumberOfColumns() != 5 ) {
2167 if ( t1.getNumberOfRows() != 6 ) {
2170 if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2173 if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2176 if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2179 if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2182 final StringBuffer source1 = new StringBuffer();
2183 source1.append( "" + l );
2184 source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2185 source1.append( " 00; 01 ;02;03" + l );
2186 source1.append( " 10; 11; 12; 13 " + l );
2187 source1.append( "20; 21; 22; 23 " + l );
2188 source1.append( " 30; 31; 32; 33" + l );
2189 source1.append( "40;41;42;43" + l );
2190 source1.append( " # 1 1 1 1 1 " + l );
2191 source1.append( ";;;50 ; ;52; 53;;54 " + l );
2192 final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2193 if ( t2.getNumberOfColumns() != 5 ) {
2196 if ( t2.getNumberOfRows() != 6 ) {
2199 if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2202 if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2205 if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2208 if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2211 if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2214 if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2217 final StringBuffer source2 = new StringBuffer();
2218 source2.append( "" + l );
2219 source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2220 source2.append( " 00; 01 ;02;03" + l );
2221 source2.append( " 10; 11; 12; 13 " + l );
2222 source2.append( "20; 21; 22; 23 " + l );
2223 source2.append( " " + l );
2224 source2.append( " 30; 31; 32; 33" + l );
2225 source2.append( "40;41;42;43" + l );
2226 source2.append( " comment: 1 1 1 1 1 " + l );
2227 source2.append( ";;;50 ; 52; 53;;54 " + l );
2228 final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2234 if ( tl.size() != 2 ) {
2237 final BasicTable<String> t3 = tl.get( 0 );
2238 final BasicTable<String> t4 = tl.get( 1 );
2239 if ( t3.getNumberOfColumns() != 4 ) {
2242 if ( t3.getNumberOfRows() != 3 ) {
2245 if ( t4.getNumberOfColumns() != 4 ) {
2248 if ( t4.getNumberOfRows() != 3 ) {
2251 if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2254 if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2258 catch ( final Exception e ) {
2259 e.printStackTrace( System.out );
2265 private static boolean testBasicTolXMLparsing() {
2267 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2268 final TolParser parser = new TolParser();
2269 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2270 if ( parser.getErrorCount() > 0 ) {
2271 System.out.println( parser.getErrorMessages().toString() );
2274 if ( phylogenies_0.length != 1 ) {
2277 final Phylogeny t1 = phylogenies_0[ 0 ];
2278 if ( t1.getNumberOfExternalNodes() != 5 ) {
2281 if ( !t1.isRooted() ) {
2284 if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2287 if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2290 if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2293 if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2296 final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2297 if ( parser.getErrorCount() > 0 ) {
2298 System.out.println( parser.getErrorMessages().toString() );
2301 if ( phylogenies_1.length != 1 ) {
2304 final Phylogeny t2 = phylogenies_1[ 0 ];
2305 if ( t2.getNumberOfExternalNodes() != 664 ) {
2308 if ( !t2.isRooted() ) {
2311 if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2314 if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2317 if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2320 if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2323 if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2326 if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2327 .equals( "Aquifex" ) ) {
2330 final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2331 if ( parser.getErrorCount() > 0 ) {
2332 System.out.println( parser.getErrorMessages().toString() );
2335 if ( phylogenies_2.length != 1 ) {
2338 final Phylogeny t3 = phylogenies_2[ 0 ];
2339 if ( t3.getNumberOfExternalNodes() != 184 ) {
2342 if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2345 if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2348 if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2351 final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2352 if ( parser.getErrorCount() > 0 ) {
2353 System.out.println( parser.getErrorMessages().toString() );
2356 if ( phylogenies_3.length != 1 ) {
2359 final Phylogeny t4 = phylogenies_3[ 0 ];
2360 if ( t4.getNumberOfExternalNodes() != 1 ) {
2363 if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2366 if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2369 if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2372 final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2373 if ( parser.getErrorCount() > 0 ) {
2374 System.out.println( parser.getErrorMessages().toString() );
2377 if ( phylogenies_4.length != 1 ) {
2380 final Phylogeny t5 = phylogenies_4[ 0 ];
2381 if ( t5.getNumberOfExternalNodes() != 13 ) {
2384 if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2387 if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2390 if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2394 catch ( final Exception e ) {
2395 e.printStackTrace( System.out );
2401 private static boolean testBasicTreeMethods() {
2403 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2404 final Phylogeny t1 = factory.create();
2405 if ( !t1.isEmpty() ) {
2408 final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2409 if ( t2.getNumberOfExternalNodes() != 4 ) {
2412 if ( t2.getHeight() != 8.5 ) {
2415 if ( !t2.isCompletelyBinary() ) {
2418 if ( t2.isEmpty() ) {
2421 final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2422 if ( t3.getNumberOfExternalNodes() != 5 ) {
2425 if ( t3.getHeight() != 11 ) {
2428 if ( t3.isCompletelyBinary() ) {
2431 final PhylogenyNode n = t3.getNode( "ABC" );
2432 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 ];
2433 if ( t4.getNumberOfExternalNodes() != 9 ) {
2436 if ( t4.getHeight() != 11 ) {
2439 if ( t4.isCompletelyBinary() ) {
2442 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)" );
2443 final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2444 if ( t5.getNumberOfExternalNodes() != 8 ) {
2447 if ( t5.getHeight() != 15 ) {
2450 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)" );
2451 final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
2452 if ( t6.getHeight() != 15 ) {
2455 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)" );
2456 final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
2457 if ( t7.getHeight() != 15 ) {
2460 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)" );
2461 final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
2462 if ( t8.getNumberOfExternalNodes() != 10 ) {
2465 if ( t8.getHeight() != 15 ) {
2468 final char[] a9 = new char[] { 'a' };
2469 final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
2470 if ( t9.getHeight() != 0 ) {
2473 final char[] a10 = new char[] { 'a', ':', '6' };
2474 final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
2475 if ( t10.getHeight() != 6 ) {
2479 catch ( final Exception e ) {
2480 e.printStackTrace( System.out );
2486 private static boolean testConfidenceAssessor() {
2488 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2489 final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2490 final Phylogeny[] ev0 = factory
2491 .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
2493 ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
2494 if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2497 if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
2500 final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2501 final Phylogeny[] ev1 = factory
2502 .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)));",
2504 ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
2505 if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
2508 if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2511 final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2512 final Phylogeny[] ev_b = factory
2513 .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",
2515 ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
2516 if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
2519 if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2523 final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
2524 final Phylogeny[] ev1x = factory
2525 .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)));",
2527 ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
2528 if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2531 if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
2534 final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
2535 final Phylogeny[] ev_bx = factory
2536 .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",
2538 ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
2539 if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2542 if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2546 final Phylogeny[] t2 = factory
2547 .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);",
2549 final Phylogeny[] ev2 = factory
2550 .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);",
2552 for( final Phylogeny target : t2 ) {
2553 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
2556 final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
2557 new NHXParser() )[ 0 ];
2558 final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
2559 ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
2560 if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2563 if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
2566 if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
2570 catch ( final Exception e ) {
2571 e.printStackTrace();
2577 private static boolean testCopyOfNodeData() {
2579 final PhylogenyNode n1 = PhylogenyNode
2580 .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]" );
2581 final PhylogenyNode n2 = n1.copyNodeData();
2582 if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
2586 catch ( final Exception e ) {
2587 e.printStackTrace();
2593 private static boolean testCreateBalancedPhylogeny() {
2595 final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
2596 if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
2599 if ( p0.getNumberOfExternalNodes() != 15625 ) {
2602 final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
2603 if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
2606 if ( p1.getNumberOfExternalNodes() != 100 ) {
2610 catch ( final Exception e ) {
2611 e.printStackTrace();
2617 private static boolean testCreateUriForSeqWeb() {
2619 final PhylogenyNode n = new PhylogenyNode();
2620 n.setName( "tr|B3RJ64" );
2621 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
2624 n.setName( "B0LM41_HUMAN" );
2625 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
2628 n.setName( "NP_001025424" );
2629 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
2632 n.setName( "_NM_001030253-" );
2633 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
2636 n.setName( "XM_002122186" );
2637 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
2640 n.setName( "dgh_AAA34956_gdg" );
2641 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
2644 n.setName( "j40f4_Q06891.1_fndn2 fnr3" );
2645 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "Q06891.1" ) ) {
2648 n.setName( "GI:394892" );
2649 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2650 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
2653 n.setName( "gi_394892" );
2654 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2655 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
2658 n.setName( "gi6335_gi_394892_56635_Gi_43" );
2659 if ( !AptxUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
2660 System.out.println( AptxUtil.createUriForSeqWeb( n, null, null ) );
2664 catch ( final Exception e ) {
2665 e.printStackTrace( System.out );
2671 private static boolean testDataObjects() {
2673 final Confidence s0 = new Confidence();
2674 final Confidence s1 = new Confidence();
2675 if ( !s0.isEqual( s1 ) ) {
2678 final Confidence s2 = new Confidence( 0.23, "bootstrap" );
2679 final Confidence s3 = new Confidence( 0.23, "bootstrap" );
2680 if ( s2.isEqual( s1 ) ) {
2683 if ( !s2.isEqual( s3 ) ) {
2686 final Confidence s4 = ( Confidence ) s3.copy();
2687 if ( !s4.isEqual( s3 ) ) {
2694 final Taxonomy t1 = new Taxonomy();
2695 final Taxonomy t2 = new Taxonomy();
2696 final Taxonomy t3 = new Taxonomy();
2697 final Taxonomy t4 = new Taxonomy();
2698 final Taxonomy t5 = new Taxonomy();
2699 t1.setIdentifier( new Identifier( "ecoli" ) );
2700 t1.setTaxonomyCode( "ECOLI" );
2701 t1.setScientificName( "E. coli" );
2702 t1.setCommonName( "coli" );
2703 final Taxonomy t0 = ( Taxonomy ) t1.copy();
2704 if ( !t1.isEqual( t0 ) ) {
2707 t2.setIdentifier( new Identifier( "ecoli" ) );
2708 t2.setTaxonomyCode( "OTHER" );
2709 t2.setScientificName( "what" );
2710 t2.setCommonName( "something" );
2711 if ( !t1.isEqual( t2 ) ) {
2714 t2.setIdentifier( new Identifier( "nemve" ) );
2715 if ( t1.isEqual( t2 ) ) {
2718 t1.setIdentifier( null );
2719 t3.setTaxonomyCode( "ECOLI" );
2720 t3.setScientificName( "what" );
2721 t3.setCommonName( "something" );
2722 if ( !t1.isEqual( t3 ) ) {
2725 t1.setIdentifier( null );
2726 t1.setTaxonomyCode( "" );
2727 t4.setScientificName( "E. ColI" );
2728 t4.setCommonName( "something" );
2729 if ( !t1.isEqual( t4 ) ) {
2732 t4.setScientificName( "B. subtilis" );
2733 t4.setCommonName( "something" );
2734 if ( t1.isEqual( t4 ) ) {
2737 t1.setIdentifier( null );
2738 t1.setTaxonomyCode( "" );
2739 t1.setScientificName( "" );
2740 t5.setCommonName( "COLI" );
2741 if ( !t1.isEqual( t5 ) ) {
2744 t5.setCommonName( "vibrio" );
2745 if ( t1.isEqual( t5 ) ) {
2750 final Identifier id0 = new Identifier( "123", "pfam" );
2751 final Identifier id1 = ( Identifier ) id0.copy();
2752 if ( !id1.isEqual( id1 ) ) {
2755 if ( !id1.isEqual( id0 ) ) {
2758 if ( !id0.isEqual( id1 ) ) {
2765 final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
2766 final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
2767 if ( !pd1.isEqual( pd1 ) ) {
2770 if ( !pd1.isEqual( pd0 ) ) {
2775 final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
2776 final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
2777 if ( !pd3.isEqual( pd3 ) ) {
2780 if ( !pd2.isEqual( pd3 ) ) {
2783 if ( !pd0.isEqual( pd3 ) ) {
2788 // DomainArchitecture
2789 // ------------------
2790 final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
2791 final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
2792 final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
2793 final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
2794 final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
2795 final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
2800 final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
2801 if ( ds0.getNumberOfDomains() != 4 ) {
2804 final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
2805 if ( !ds0.isEqual( ds0 ) ) {
2808 if ( !ds0.isEqual( ds1 ) ) {
2811 if ( ds1.getNumberOfDomains() != 4 ) {
2814 final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
2819 final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
2820 if ( ds0.isEqual( ds2 ) ) {
2826 final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
2827 if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
2828 System.out.println( ds3.toNHX() );
2831 if ( ds3.getNumberOfDomains() != 3 ) {
2836 final Event e1 = new Event( Event.EventType.fusion );
2837 if ( e1.isDuplication() ) {
2840 if ( !e1.isFusion() ) {
2843 if ( !e1.asText().toString().equals( "fusion" ) ) {
2846 if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
2849 final Event e11 = new Event( Event.EventType.fusion );
2850 if ( !e11.isEqual( e1 ) ) {
2853 if ( !e11.toNHX().toString().equals( "" ) ) {
2856 final Event e2 = new Event( Event.EventType.speciation_or_duplication );
2857 if ( e2.isDuplication() ) {
2860 if ( !e2.isSpeciationOrDuplication() ) {
2863 if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
2866 if ( !e2.asSimpleText().toString().equals( "?" ) ) {
2869 if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
2872 if ( e11.isEqual( e2 ) ) {
2875 final Event e2c = ( Event ) e2.copy();
2876 if ( !e2c.isEqual( e2 ) ) {
2879 Event e3 = new Event( 1, 2, 3 );
2880 if ( e3.isDuplication() ) {
2883 if ( e3.isSpeciation() ) {
2886 if ( e3.isGeneLoss() ) {
2889 if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2892 final Event e3c = ( Event ) e3.copy();
2893 final Event e3cc = ( Event ) e3c.copy();
2894 if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
2898 if ( !e3c.isEqual( e3cc ) ) {
2901 Event e4 = new Event( 1, 2, 3 );
2902 if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2905 if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
2908 final Event e4c = ( Event ) e4.copy();
2910 final Event e4cc = ( Event ) e4c.copy();
2911 if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
2914 if ( !e4c.isEqual( e4cc ) ) {
2917 final Event e5 = new Event();
2918 if ( !e5.isUnassigned() ) {
2921 if ( !e5.asText().toString().equals( "unassigned" ) ) {
2924 if ( !e5.asSimpleText().toString().equals( "" ) ) {
2927 final Event e6 = new Event( 1, 0, 0 );
2928 if ( !e6.asText().toString().equals( "duplication" ) ) {
2931 if ( !e6.asSimpleText().toString().equals( "D" ) ) {
2934 final Event e7 = new Event( 0, 1, 0 );
2935 if ( !e7.asText().toString().equals( "speciation" ) ) {
2938 if ( !e7.asSimpleText().toString().equals( "S" ) ) {
2941 final Event e8 = new Event( 0, 0, 1 );
2942 if ( !e8.asText().toString().equals( "gene-loss" ) ) {
2945 if ( !e8.asSimpleText().toString().equals( "L" ) ) {
2949 catch ( final Exception e ) {
2950 e.printStackTrace( System.out );
2956 private static boolean testDeletionOfExternalNodes() {
2958 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2959 final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
2960 final PhylogenyWriter w = new PhylogenyWriter();
2961 if ( t0.isEmpty() ) {
2964 if ( t0.getNumberOfExternalNodes() != 1 ) {
2967 t0.deleteSubtree( t0.getNode( "A" ), false );
2968 if ( t0.getNumberOfExternalNodes() != 0 ) {
2971 if ( !t0.isEmpty() ) {
2974 final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
2975 if ( t1.getNumberOfExternalNodes() != 2 ) {
2978 t1.deleteSubtree( t1.getNode( "A" ), false );
2979 if ( t1.getNumberOfExternalNodes() != 1 ) {
2982 if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
2985 t1.deleteSubtree( t1.getNode( "B" ), false );
2986 if ( t1.getNumberOfExternalNodes() != 1 ) {
2989 t1.deleteSubtree( t1.getNode( "r" ), false );
2990 if ( !t1.isEmpty() ) {
2993 final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
2994 if ( t2.getNumberOfExternalNodes() != 3 ) {
2997 t2.deleteSubtree( t2.getNode( "B" ), false );
2998 if ( t2.getNumberOfExternalNodes() != 2 ) {
3001 t2.toNewHampshireX();
3002 PhylogenyNode n = t2.getNode( "A" );
3003 if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3006 t2.deleteSubtree( t2.getNode( "A" ), false );
3007 if ( t2.getNumberOfExternalNodes() != 2 ) {
3010 t2.deleteSubtree( t2.getNode( "C" ), true );
3011 if ( t2.getNumberOfExternalNodes() != 1 ) {
3014 final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3015 if ( t3.getNumberOfExternalNodes() != 4 ) {
3018 t3.deleteSubtree( t3.getNode( "B" ), true );
3019 if ( t3.getNumberOfExternalNodes() != 3 ) {
3022 n = t3.getNode( "A" );
3023 if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3026 n = n.getNextExternalNode();
3027 if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3030 t3.deleteSubtree( t3.getNode( "A" ), true );
3031 if ( t3.getNumberOfExternalNodes() != 2 ) {
3034 n = t3.getNode( "C" );
3035 if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3038 t3.deleteSubtree( t3.getNode( "C" ), true );
3039 if ( t3.getNumberOfExternalNodes() != 1 ) {
3042 t3.deleteSubtree( t3.getNode( "D" ), true );
3043 if ( t3.getNumberOfExternalNodes() != 0 ) {
3046 final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3047 if ( t4.getNumberOfExternalNodes() != 6 ) {
3050 t4.deleteSubtree( t4.getNode( "B2" ), true );
3051 if ( t4.getNumberOfExternalNodes() != 5 ) {
3054 String s = w.toNewHampshire( t4, false, true ).toString();
3055 if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3058 t4.deleteSubtree( t4.getNode( "B11" ), true );
3059 if ( t4.getNumberOfExternalNodes() != 4 ) {
3062 t4.deleteSubtree( t4.getNode( "C" ), true );
3063 if ( t4.getNumberOfExternalNodes() != 3 ) {
3066 n = t4.getNode( "A" );
3067 n = n.getNextExternalNode();
3068 if ( !n.getName().equals( "B12" ) ) {
3071 n = n.getNextExternalNode();
3072 if ( !n.getName().equals( "D" ) ) {
3075 s = w.toNewHampshire( t4, false, true ).toString();
3076 if ( !s.equals( "((A,B12),D);" ) ) {
3079 final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3080 t5.deleteSubtree( t5.getNode( "A" ), true );
3081 if ( t5.getNumberOfExternalNodes() != 5 ) {
3084 s = w.toNewHampshire( t5, false, true ).toString();
3085 if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3088 final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3089 t6.deleteSubtree( t6.getNode( "B11" ), true );
3090 if ( t6.getNumberOfExternalNodes() != 5 ) {
3093 s = w.toNewHampshire( t6, false, false ).toString();
3094 if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3097 final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3098 t7.deleteSubtree( t7.getNode( "B12" ), true );
3099 if ( t7.getNumberOfExternalNodes() != 5 ) {
3102 s = w.toNewHampshire( t7, false, true ).toString();
3103 if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3106 final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3107 t8.deleteSubtree( t8.getNode( "B2" ), true );
3108 if ( t8.getNumberOfExternalNodes() != 5 ) {
3111 s = w.toNewHampshire( t8, false, false ).toString();
3112 if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3115 final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3116 t9.deleteSubtree( t9.getNode( "C" ), true );
3117 if ( t9.getNumberOfExternalNodes() != 5 ) {
3120 s = w.toNewHampshire( t9, false, true ).toString();
3121 if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3124 final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3125 t10.deleteSubtree( t10.getNode( "D" ), true );
3126 if ( t10.getNumberOfExternalNodes() != 5 ) {
3129 s = w.toNewHampshire( t10, false, true ).toString();
3130 if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3133 final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3134 t11.deleteSubtree( t11.getNode( "A" ), true );
3135 if ( t11.getNumberOfExternalNodes() != 2 ) {
3138 s = w.toNewHampshire( t11, false, true ).toString();
3139 if ( !s.equals( "(B,C);" ) ) {
3142 t11.deleteSubtree( t11.getNode( "C" ), true );
3143 if ( t11.getNumberOfExternalNodes() != 1 ) {
3146 s = w.toNewHampshire( t11, false, false ).toString();
3147 if ( !s.equals( "B;" ) ) {
3150 final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3151 t12.deleteSubtree( t12.getNode( "B2" ), true );
3152 if ( t12.getNumberOfExternalNodes() != 8 ) {
3155 s = w.toNewHampshire( t12, false, true ).toString();
3156 if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3159 t12.deleteSubtree( t12.getNode( "B3" ), true );
3160 if ( t12.getNumberOfExternalNodes() != 7 ) {
3163 s = w.toNewHampshire( t12, false, true ).toString();
3164 if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3167 t12.deleteSubtree( t12.getNode( "C3" ), true );
3168 if ( t12.getNumberOfExternalNodes() != 6 ) {
3171 s = w.toNewHampshire( t12, false, true ).toString();
3172 if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3175 t12.deleteSubtree( t12.getNode( "A1" ), true );
3176 if ( t12.getNumberOfExternalNodes() != 5 ) {
3179 s = w.toNewHampshire( t12, false, true ).toString();
3180 if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3183 t12.deleteSubtree( t12.getNode( "B1" ), true );
3184 if ( t12.getNumberOfExternalNodes() != 4 ) {
3187 s = w.toNewHampshire( t12, false, true ).toString();
3188 if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3191 t12.deleteSubtree( t12.getNode( "A3" ), true );
3192 if ( t12.getNumberOfExternalNodes() != 3 ) {
3195 s = w.toNewHampshire( t12, false, true ).toString();
3196 if ( !s.equals( "(A2,(C1,C2));" ) ) {
3199 t12.deleteSubtree( t12.getNode( "A2" ), true );
3200 if ( t12.getNumberOfExternalNodes() != 2 ) {
3203 s = w.toNewHampshire( t12, false, true ).toString();
3204 if ( !s.equals( "(C1,C2);" ) ) {
3207 final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3208 t13.deleteSubtree( t13.getNode( "D" ), true );
3209 if ( t13.getNumberOfExternalNodes() != 4 ) {
3212 s = w.toNewHampshire( t13, false, true ).toString();
3213 if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3216 final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3217 t14.deleteSubtree( t14.getNode( "E" ), true );
3218 if ( t14.getNumberOfExternalNodes() != 5 ) {
3221 s = w.toNewHampshire( t14, false, true ).toString();
3222 if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3225 final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3226 t15.deleteSubtree( t15.getNode( "B2" ), true );
3227 if ( t15.getNumberOfExternalNodes() != 11 ) {
3230 t15.deleteSubtree( t15.getNode( "B1" ), true );
3231 if ( t15.getNumberOfExternalNodes() != 10 ) {
3234 t15.deleteSubtree( t15.getNode( "B3" ), true );
3235 if ( t15.getNumberOfExternalNodes() != 9 ) {
3238 t15.deleteSubtree( t15.getNode( "B4" ), true );
3239 if ( t15.getNumberOfExternalNodes() != 8 ) {
3242 t15.deleteSubtree( t15.getNode( "A1" ), true );
3243 if ( t15.getNumberOfExternalNodes() != 7 ) {
3246 t15.deleteSubtree( t15.getNode( "C4" ), true );
3247 if ( t15.getNumberOfExternalNodes() != 6 ) {
3251 catch ( final Exception e ) {
3252 e.printStackTrace( System.out );
3258 private static boolean testDescriptiveStatistics() {
3260 final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3261 dss1.addValue( 82 );
3262 dss1.addValue( 78 );
3263 dss1.addValue( 70 );
3264 dss1.addValue( 58 );
3265 dss1.addValue( 42 );
3266 if ( dss1.getN() != 5 ) {
3269 if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3272 if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3275 if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3278 if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3281 if ( !Test.isEqual( dss1.median(), 70 ) ) {
3284 if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3287 if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3290 if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3293 if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3296 if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3299 if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3302 dss1.addValue( 123 );
3303 if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3306 if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3309 if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3312 final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3313 dss2.addValue( -1.85 );
3314 dss2.addValue( 57.5 );
3315 dss2.addValue( 92.78 );
3316 dss2.addValue( 57.78 );
3317 if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3320 if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3323 final double[] a = dss2.getDataAsDoubleArray();
3324 if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3327 dss2.addValue( -100 );
3328 if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3331 if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3334 final double[] ds = new double[ 14 ];
3349 final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3350 if ( bins.length != 4 ) {
3353 if ( bins[ 0 ] != 2 ) {
3356 if ( bins[ 1 ] != 3 ) {
3359 if ( bins[ 2 ] != 4 ) {
3362 if ( bins[ 3 ] != 5 ) {
3365 final double[] ds1 = new double[ 9 ];
3375 final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3376 if ( bins1.length != 4 ) {
3379 if ( bins1[ 0 ] != 2 ) {
3382 if ( bins1[ 1 ] != 3 ) {
3385 if ( bins1[ 2 ] != 0 ) {
3388 if ( bins1[ 3 ] != 4 ) {
3391 final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3392 if ( bins1_1.length != 3 ) {
3395 if ( bins1_1[ 0 ] != 3 ) {
3398 if ( bins1_1[ 1 ] != 2 ) {
3401 if ( bins1_1[ 2 ] != 4 ) {
3404 final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3405 if ( bins1_2.length != 3 ) {
3408 if ( bins1_2[ 0 ] != 2 ) {
3411 if ( bins1_2[ 1 ] != 2 ) {
3414 if ( bins1_2[ 2 ] != 2 ) {
3417 final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3431 dss3.addValue( 10 );
3432 dss3.addValue( 10 );
3433 dss3.addValue( 10 );
3434 final AsciiHistogram histo = new AsciiHistogram( dss3 );
3435 histo.toStringBuffer( 10, '=', 40, 5 );
3436 histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3438 catch ( final Exception e ) {
3439 e.printStackTrace( System.out );
3445 private static boolean testDir( final String file ) {
3447 final File f = new File( file );
3448 if ( !f.exists() ) {
3451 if ( !f.isDirectory() ) {
3454 if ( !f.canRead() ) {
3458 catch ( final Exception e ) {
3464 private static boolean testDomainId() {
3466 final DomainId id1 = new DomainId( "a" );
3467 final DomainId id2 = new DomainId( "a" );
3468 final DomainId id3 = new DomainId( "A" );
3469 final DomainId id4 = new DomainId( "b" );
3470 if ( !id1.equals( id1 ) ) {
3473 if ( id1.getId().equals( "x" ) ) {
3476 if ( id1.getId().equals( null ) ) {
3479 if ( !id1.equals( id2 ) ) {
3482 if ( id1.equals( id3 ) ) {
3485 if ( id1.hashCode() != id1.hashCode() ) {
3488 if ( id1.hashCode() != id2.hashCode() ) {
3491 if ( id1.hashCode() == id3.hashCode() ) {
3494 if ( id1.compareTo( id1 ) != 0 ) {
3497 if ( id1.compareTo( id2 ) != 0 ) {
3500 if ( id1.compareTo( id3 ) != 0 ) {
3503 if ( id1.compareTo( id4 ) >= 0 ) {
3506 if ( id4.compareTo( id1 ) <= 0 ) {
3509 if ( !id4.getId().equals( "b" ) ) {
3512 final DomainId id5 = new DomainId( " C " );
3513 if ( !id5.getId().equals( "C" ) ) {
3516 if ( id5.equals( id1 ) ) {
3520 catch ( final Exception e ) {
3521 e.printStackTrace( System.out );
3527 private static boolean testEmblEntryRetrieval() {
3528 //The format for GenBank Accession numbers are:
3529 //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
3530 //Protein: 3 letters + 5 numerals
3531 //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
3532 if ( !SequenceIdParser.parseGenbankAccessor( "AY423861" ).equals( "AY423861" ) ) {
3535 if ( !SequenceIdParser.parseGenbankAccessor( ".AY423861.2" ).equals( "AY423861.2" ) ) {
3538 if ( !SequenceIdParser.parseGenbankAccessor( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
3541 if ( SequenceIdParser.parseGenbankAccessor( "AAY423861" ) != null ) {
3544 if ( SequenceIdParser.parseGenbankAccessor( "AY4238612" ) != null ) {
3547 if ( SequenceIdParser.parseGenbankAccessor( "AAY4238612" ) != null ) {
3550 if ( SequenceIdParser.parseGenbankAccessor( "Y423861" ) != null ) {
3553 if ( !SequenceIdParser.parseGenbankAccessor( "S12345" ).equals( "S12345" ) ) {
3556 if ( !SequenceIdParser.parseGenbankAccessor( "|S12345|" ).equals( "S12345" ) ) {
3559 if ( SequenceIdParser.parseGenbankAccessor( "|S123456" ) != null ) {
3562 if ( SequenceIdParser.parseGenbankAccessor( "ABC123456" ) != null ) {
3565 if ( !SequenceIdParser.parseGenbankAccessor( "ABC12345" ).equals( "ABC12345" ) ) {
3568 if ( !SequenceIdParser.parseGenbankAccessor( "&ABC12345&" ).equals( "ABC12345" ) ) {
3571 if ( SequenceIdParser.parseGenbankAccessor( "ABCD12345" ) != null ) {
3577 private static boolean testExternalNodeRelatedMethods() {
3579 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3580 final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3581 PhylogenyNode n = t1.getNode( "A" );
3582 n = n.getNextExternalNode();
3583 if ( !n.getName().equals( "B" ) ) {
3586 n = n.getNextExternalNode();
3587 if ( !n.getName().equals( "C" ) ) {
3590 n = n.getNextExternalNode();
3591 if ( !n.getName().equals( "D" ) ) {
3594 n = t1.getNode( "B" );
3595 while ( !n.isLastExternalNode() ) {
3596 n = n.getNextExternalNode();
3598 final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
3599 n = t2.getNode( "A" );
3600 n = n.getNextExternalNode();
3601 if ( !n.getName().equals( "B" ) ) {
3604 n = n.getNextExternalNode();
3605 if ( !n.getName().equals( "C" ) ) {
3608 n = n.getNextExternalNode();
3609 if ( !n.getName().equals( "D" ) ) {
3612 n = t2.getNode( "B" );
3613 while ( !n.isLastExternalNode() ) {
3614 n = n.getNextExternalNode();
3616 final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3617 n = t3.getNode( "A" );
3618 n = n.getNextExternalNode();
3619 if ( !n.getName().equals( "B" ) ) {
3622 n = n.getNextExternalNode();
3623 if ( !n.getName().equals( "C" ) ) {
3626 n = n.getNextExternalNode();
3627 if ( !n.getName().equals( "D" ) ) {
3630 n = n.getNextExternalNode();
3631 if ( !n.getName().equals( "E" ) ) {
3634 n = n.getNextExternalNode();
3635 if ( !n.getName().equals( "F" ) ) {
3638 n = n.getNextExternalNode();
3639 if ( !n.getName().equals( "G" ) ) {
3642 n = n.getNextExternalNode();
3643 if ( !n.getName().equals( "H" ) ) {
3646 n = t3.getNode( "B" );
3647 while ( !n.isLastExternalNode() ) {
3648 n = n.getNextExternalNode();
3650 final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3651 for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
3652 final PhylogenyNode node = iter.next();
3654 final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
3655 for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
3656 final PhylogenyNode node = iter.next();
3658 final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
3659 final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
3660 if ( !iter.next().getName().equals( "A" ) ) {
3663 if ( !iter.next().getName().equals( "B" ) ) {
3666 if ( !iter.next().getName().equals( "C" ) ) {
3669 if ( !iter.next().getName().equals( "D" ) ) {
3672 if ( !iter.next().getName().equals( "E" ) ) {
3675 if ( !iter.next().getName().equals( "F" ) ) {
3678 if ( iter.hasNext() ) {
3682 catch ( final Exception e ) {
3683 e.printStackTrace( System.out );
3689 private static boolean testExtractSNFromNodeName() {
3691 if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
3694 if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus" )
3695 .equals( "Mus musculus musculus" ) ) {
3698 if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus_musculus-12" )
3699 .equals( "Mus musculus musculus" ) ) {
3702 if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus-12" ).equals( "Mus musculus" ) ) {
3705 if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus-12 affrre e" )
3706 .equals( "Mus musculus" ) ) {
3710 catch ( final Exception e ) {
3711 e.printStackTrace( System.out );
3717 private static boolean testExtractTaxonomyCodeFromNodeName() {
3719 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3722 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3723 .equals( "SOYBN" ) ) {
3726 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
3727 .equals( "ARATH" ) ) {
3730 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
3731 .equals( "ARATH" ) ) {
3734 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
3737 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
3740 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3743 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3744 .equals( "SOYBN" ) ) {
3747 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3748 .equals( "SOYBN" ) ) {
3751 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3752 .equals( "SOYBN" ) ) {
3755 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3756 .equals( "SOYBN" ) ) {
3759 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3760 .equals( "SOYBN" ) ) {
3763 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
3764 .equals( "SOYBN" ) ) {
3767 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
3768 .equals( "SOYBN" ) ) {
3771 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
3772 .equals( "SOYBN" ) ) {
3775 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
3778 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
3779 .equals( "SOYBN" ) ) {
3782 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
3783 TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
3786 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
3787 .equals( "9YX45" ) ) {
3790 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
3791 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3792 .equals( "MOUSE" ) ) {
3795 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
3796 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3797 .equals( "MOUSE" ) ) {
3800 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
3801 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3802 .equals( "MOUSE" ) ) {
3805 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
3806 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3809 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
3810 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3813 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
3814 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
3817 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
3818 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
3821 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
3822 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
3825 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
3826 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3829 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
3830 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3833 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3834 .equals( "RAT" ) ) {
3837 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
3838 .equals( "PIG" ) ) {
3842 .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
3843 .equals( "MOUSE" ) ) {
3846 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
3847 .equals( "MOUSE" ) ) {
3850 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
3854 catch ( final Exception e ) {
3855 e.printStackTrace( System.out );
3861 private static boolean testExtractUniProtKbProteinSeqIdentifier() {
3863 PhylogenyNode n = new PhylogenyNode();
3864 n.setName( "tr|B3RJ64" );
3865 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3868 n.setName( "tr.B3RJ64" );
3869 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3872 n.setName( "tr=B3RJ64" );
3873 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3876 n.setName( "tr-B3RJ64" );
3877 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3880 n.setName( "tr/B3RJ64" );
3881 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3884 n.setName( "tr\\B3RJ64" );
3885 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3888 n.setName( "tr_B3RJ64" );
3889 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3892 n.setName( " tr|B3RJ64 " );
3893 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3896 n.setName( "-tr|B3RJ64-" );
3897 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3900 n.setName( "-tr=B3RJ64-" );
3901 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3904 n.setName( "_tr=B3RJ64_" );
3905 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3908 n.setName( " tr_tr|B3RJ64_sp|123 " );
3909 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3912 n.setName( "sp|B3RJ64" );
3913 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3916 n.setName( "ssp|B3RJ64" );
3917 if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3920 n.setName( "sp|B3RJ64C" );
3921 if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3924 n.setName( "sp B3RJ64" );
3925 if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3928 n.setName( "sp|B3RJ6X" );
3929 if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3932 n.setName( "sp|B3RJ6" );
3933 if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3936 n.setName( "K1PYK7_CRAGI" );
3937 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
3940 n.setName( "K1PYK7_PEA" );
3941 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PEA" ) ) {
3944 n.setName( "K1PYK7_RAT" );
3945 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_RAT" ) ) {
3948 n.setName( "K1PYK7_PIG" );
3949 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PIG" ) ) {
3952 n.setName( "~K1PYK7_PIG~" );
3953 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_PIG" ) ) {
3956 n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
3957 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
3960 n.setName( "K1PYKX_CRAGI" );
3961 if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3964 n.setName( "XXXXX_CRAGI" );
3965 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "XXXXX_CRAGI" ) ) {
3968 n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
3969 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "H3IB65" ) ) {
3972 n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
3973 if ( ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ) != null ) {
3976 n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
3977 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "Q86U06" ) ) {
3980 n = new PhylogenyNode();
3981 org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
3982 seq.setSymbol( "K1PYK7_CRAGI" );
3983 n.getNodeData().addSequence( seq );
3984 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
3987 seq.setSymbol( "tr|B3RJ64" );
3988 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
3991 n = new PhylogenyNode();
3992 seq = new org.forester.phylogeny.data.Sequence();
3993 seq.setName( "K1PYK7_CRAGI" );
3994 n.getNodeData().addSequence( seq );
3995 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK7_CRAGI" ) ) {
3998 seq.setName( "tr|B3RJ64" );
3999 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
4002 n = new PhylogenyNode();
4003 seq = new org.forester.phylogeny.data.Sequence();
4004 seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4005 n.getNodeData().addSequence( seq );
4006 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "K1PYK8_CRAGI" ) ) {
4009 n = new PhylogenyNode();
4010 seq = new org.forester.phylogeny.data.Sequence();
4011 seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4012 n.getNodeData().addSequence( seq );
4013 if ( !ForesterUtil.extractUniProtKbProteinSeqIdentifier( n ).equals( "B3RJ64" ) ) {
4017 n = new PhylogenyNode();
4018 n.setName( "ACP19736" );
4019 if ( !ForesterUtil.extractGenbankAccessor( n ).equals( "ACP19736" ) ) {
4022 n = new PhylogenyNode();
4023 n.setName( "_ACP19736_" );
4024 if ( !ForesterUtil.extractGenbankAccessor( n ).equals( "ACP19736" ) ) {
4028 catch ( final Exception e ) {
4029 e.printStackTrace( System.out );
4035 private static boolean testFastaParser() {
4037 if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
4040 if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
4043 final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
4044 if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
4047 if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
4050 if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
4053 if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPRXWXERR" ) ) {
4056 if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
4059 if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
4063 catch ( final Exception e ) {
4064 e.printStackTrace();
4070 private static boolean testGeneralMsaParser() {
4072 final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
4073 final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
4074 final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
4075 final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
4076 final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
4077 final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
4078 final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
4079 final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
4080 if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4083 if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4086 if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4089 if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4092 if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4095 if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4098 if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4101 if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4104 if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
4107 if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
4110 if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
4113 if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
4116 final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
4117 if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4120 if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4123 if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4126 final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
4127 if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
4130 if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
4133 if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
4136 final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
4137 if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
4140 if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
4143 if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
4147 catch ( final Exception e ) {
4148 e.printStackTrace();
4154 private static boolean testGeneralTable() {
4156 final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
4157 t0.setValue( 3, 2, "23" );
4158 t0.setValue( 10, 1, "error" );
4159 t0.setValue( 10, 1, "110" );
4160 t0.setValue( 9, 1, "19" );
4161 t0.setValue( 1, 10, "101" );
4162 t0.setValue( 10, 10, "1010" );
4163 t0.setValue( 100, 10, "10100" );
4164 t0.setValue( 0, 0, "00" );
4165 if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
4168 if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
4171 if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
4174 if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
4177 if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
4180 if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
4183 if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
4186 if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
4189 if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
4192 final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
4193 t1.setValue( "3", "2", "23" );
4194 t1.setValue( "10", "1", "error" );
4195 t1.setValue( "10", "1", "110" );
4196 t1.setValue( "9", "1", "19" );
4197 t1.setValue( "1", "10", "101" );
4198 t1.setValue( "10", "10", "1010" );
4199 t1.setValue( "100", "10", "10100" );
4200 t1.setValue( "0", "0", "00" );
4201 t1.setValue( "qwerty", "zxcvbnm", "asdef" );
4202 if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
4205 if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
4208 if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
4211 if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
4214 if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
4217 if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
4220 if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
4223 if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
4226 if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
4229 if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
4233 catch ( final Exception e ) {
4234 e.printStackTrace( System.out );
4240 private static boolean testGetDistance() {
4242 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4243 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",
4244 new NHXParser() )[ 0 ];
4245 if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
4248 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
4251 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
4254 if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
4257 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
4260 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
4263 if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
4266 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
4269 if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
4272 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
4275 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
4278 if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
4281 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
4284 if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
4287 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
4290 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
4293 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
4296 if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
4299 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
4302 if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
4305 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
4308 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
4311 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
4314 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
4317 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
4320 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
4323 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
4326 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
4329 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
4332 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
4335 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
4338 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",
4339 new NHXParser() )[ 0 ];
4340 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
4343 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
4346 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
4349 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
4352 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
4355 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
4358 if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
4361 if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
4364 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
4367 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
4370 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
4374 catch ( final Exception e ) {
4375 e.printStackTrace( System.out );
4381 private static boolean testGetLCA() {
4383 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4384 final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
4385 new NHXParser() )[ 0 ];
4386 final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
4387 if ( !A.getName().equals( "A" ) ) {
4390 final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
4391 if ( !gh.getName().equals( "gh" ) ) {
4394 final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
4395 if ( !ab.getName().equals( "ab" ) ) {
4398 final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
4399 if ( !ab2.getName().equals( "ab" ) ) {
4402 final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
4403 if ( !gh2.getName().equals( "gh" ) ) {
4406 final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
4407 if ( !gh3.getName().equals( "gh" ) ) {
4410 final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
4411 if ( !abc.getName().equals( "abc" ) ) {
4414 final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
4415 if ( !abc2.getName().equals( "abc" ) ) {
4418 final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
4419 if ( !abcd.getName().equals( "abcd" ) ) {
4422 final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
4423 if ( !abcd2.getName().equals( "abcd" ) ) {
4426 final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
4427 if ( !abcdef.getName().equals( "abcdef" ) ) {
4430 final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
4431 if ( !abcdef2.getName().equals( "abcdef" ) ) {
4434 final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
4435 if ( !abcdef3.getName().equals( "abcdef" ) ) {
4438 final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
4439 if ( !abcdef4.getName().equals( "abcdef" ) ) {
4442 final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
4443 if ( !abcde.getName().equals( "abcde" ) ) {
4446 final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
4447 if ( !abcde2.getName().equals( "abcde" ) ) {
4450 final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
4451 if ( !r.getName().equals( "abcdefgh" ) ) {
4454 final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
4455 if ( !r2.getName().equals( "abcdefgh" ) ) {
4458 final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
4459 if ( !r3.getName().equals( "abcdefgh" ) ) {
4462 final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
4463 if ( !abcde3.getName().equals( "abcde" ) ) {
4466 final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
4467 if ( !abcde4.getName().equals( "abcde" ) ) {
4470 final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
4471 if ( !ab3.getName().equals( "ab" ) ) {
4474 final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
4475 if ( !ab4.getName().equals( "ab" ) ) {
4478 final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
4479 final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
4480 if ( !cd.getName().equals( "cd" ) ) {
4483 final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
4484 if ( !cd2.getName().equals( "cd" ) ) {
4487 final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
4488 if ( !cde.getName().equals( "cde" ) ) {
4491 final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
4492 if ( !cde2.getName().equals( "cde" ) ) {
4495 final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
4496 if ( !cdef.getName().equals( "cdef" ) ) {
4499 final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
4500 if ( !cdef2.getName().equals( "cdef" ) ) {
4503 final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
4504 if ( !cdef3.getName().equals( "cdef" ) ) {
4507 final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
4508 if ( !rt.getName().equals( "r" ) ) {
4511 final Phylogeny p3 = factory
4512 .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
4513 new NHXParser() )[ 0 ];
4514 final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
4515 if ( !bc_3.getName().equals( "bc" ) ) {
4518 final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
4519 if ( !ac_3.getName().equals( "abc" ) ) {
4522 final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
4523 if ( !ad_3.getName().equals( "abcde" ) ) {
4526 final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
4527 if ( !af_3.getName().equals( "abcdef" ) ) {
4530 final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
4531 if ( !ag_3.getName().equals( "" ) ) {
4534 if ( !ag_3.isRoot() ) {
4537 final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
4538 if ( !al_3.getName().equals( "" ) ) {
4541 if ( !al_3.isRoot() ) {
4544 final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
4545 if ( !kl_3.getName().equals( "" ) ) {
4548 if ( !kl_3.isRoot() ) {
4551 final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
4552 if ( !fl_3.getName().equals( "" ) ) {
4555 if ( !fl_3.isRoot() ) {
4558 final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
4559 if ( !gk_3.getName().equals( "ghijk" ) ) {
4562 final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
4563 final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
4564 if ( !r_4.getName().equals( "r" ) ) {
4567 final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
4568 final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
4569 if ( !r_5.getName().equals( "root" ) ) {
4572 final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
4573 final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
4574 if ( !r_6.getName().equals( "rot" ) ) {
4577 final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
4578 final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
4579 if ( !r_7.getName().equals( "rott" ) ) {
4583 catch ( final Exception e ) {
4584 e.printStackTrace( System.out );
4590 private static boolean testGetLCA2() {
4592 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4593 final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
4594 PhylogenyMethods.preOrderReId( p_a );
4595 final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
4596 p_a.getNode( "a" ) );
4597 if ( !p_a_1.getName().equals( "a" ) ) {
4600 final Phylogeny p_b = factory.create( "((a)b)", new NHXParser() )[ 0 ];
4601 PhylogenyMethods.preOrderReId( p_b );
4602 final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
4603 p_b.getNode( "a" ) );
4604 if ( !p_b_1.getName().equals( "b" ) ) {
4607 final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
4608 p_b.getNode( "b" ) );
4609 if ( !p_b_2.getName().equals( "b" ) ) {
4612 final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
4613 PhylogenyMethods.preOrderReId( p_c );
4614 final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
4615 p_c.getNode( "a" ) );
4616 if ( !p_c_1.getName().equals( "b" ) ) {
4619 final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
4620 p_c.getNode( "c" ) );
4621 if ( !p_c_2.getName().equals( "c" ) ) {
4622 System.out.println( p_c_2.getName() );
4626 final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
4627 p_c.getNode( "b" ) );
4628 if ( !p_c_3.getName().equals( "b" ) ) {
4631 final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
4632 p_c.getNode( "a" ) );
4633 if ( !p_c_4.getName().equals( "c" ) ) {
4636 final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
4637 new NHXParser() )[ 0 ];
4638 PhylogenyMethods.preOrderReId( p1 );
4639 final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4640 p1.getNode( "A" ) );
4641 if ( !A.getName().equals( "A" ) ) {
4644 final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
4645 p1.getNode( "gh" ) );
4646 if ( !gh.getName().equals( "gh" ) ) {
4649 final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4650 p1.getNode( "B" ) );
4651 if ( !ab.getName().equals( "ab" ) ) {
4654 final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
4655 p1.getNode( "A" ) );
4656 if ( !ab2.getName().equals( "ab" ) ) {
4659 final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
4660 p1.getNode( "G" ) );
4661 if ( !gh2.getName().equals( "gh" ) ) {
4664 final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
4665 p1.getNode( "H" ) );
4666 if ( !gh3.getName().equals( "gh" ) ) {
4669 final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
4670 p1.getNode( "A" ) );
4671 if ( !abc.getName().equals( "abc" ) ) {
4674 final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4675 p1.getNode( "C" ) );
4676 if ( !abc2.getName().equals( "abc" ) ) {
4679 final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4680 p1.getNode( "D" ) );
4681 if ( !abcd.getName().equals( "abcd" ) ) {
4684 final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
4685 p1.getNode( "A" ) );
4686 if ( !abcd2.getName().equals( "abcd" ) ) {
4689 final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4690 p1.getNode( "F" ) );
4691 if ( !abcdef.getName().equals( "abcdef" ) ) {
4694 final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
4695 p1.getNode( "A" ) );
4696 if ( !abcdef2.getName().equals( "abcdef" ) ) {
4699 final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
4700 p1.getNode( "F" ) );
4701 if ( !abcdef3.getName().equals( "abcdef" ) ) {
4704 final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
4705 p1.getNode( "ab" ) );
4706 if ( !abcdef4.getName().equals( "abcdef" ) ) {
4709 final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4710 p1.getNode( "E" ) );
4711 if ( !abcde.getName().equals( "abcde" ) ) {
4714 final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
4715 p1.getNode( "A" ) );
4716 if ( !abcde2.getName().equals( "abcde" ) ) {
4719 final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
4720 p1.getNode( "abcdefgh" ) );
4721 if ( !r.getName().equals( "abcdefgh" ) ) {
4724 final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
4725 p1.getNode( "H" ) );
4726 if ( !r2.getName().equals( "abcdefgh" ) ) {
4729 final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
4730 p1.getNode( "A" ) );
4731 if ( !r3.getName().equals( "abcdefgh" ) ) {
4734 final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
4735 p1.getNode( "abcde" ) );
4736 if ( !abcde3.getName().equals( "abcde" ) ) {
4739 final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
4740 p1.getNode( "E" ) );
4741 if ( !abcde4.getName().equals( "abcde" ) ) {
4744 final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
4745 p1.getNode( "B" ) );
4746 if ( !ab3.getName().equals( "ab" ) ) {
4749 final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
4750 p1.getNode( "ab" ) );
4751 if ( !ab4.getName().equals( "ab" ) ) {
4754 final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
4755 PhylogenyMethods.preOrderReId( p2 );
4756 final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4757 p2.getNode( "d" ) );
4758 if ( !cd.getName().equals( "cd" ) ) {
4761 final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
4762 p2.getNode( "c" ) );
4763 if ( !cd2.getName().equals( "cd" ) ) {
4766 final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4767 p2.getNode( "e" ) );
4768 if ( !cde.getName().equals( "cde" ) ) {
4771 final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
4772 p2.getNode( "c" ) );
4773 if ( !cde2.getName().equals( "cde" ) ) {
4776 final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4777 p2.getNode( "f" ) );
4778 if ( !cdef.getName().equals( "cdef" ) ) {
4781 final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
4782 p2.getNode( "f" ) );
4783 if ( !cdef2.getName().equals( "cdef" ) ) {
4786 final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
4787 p2.getNode( "d" ) );
4788 if ( !cdef3.getName().equals( "cdef" ) ) {
4791 final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
4792 p2.getNode( "a" ) );
4793 if ( !rt.getName().equals( "r" ) ) {
4796 final Phylogeny p3 = factory
4797 .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
4798 new NHXParser() )[ 0 ];
4799 PhylogenyMethods.preOrderReId( p3 );
4800 final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
4801 p3.getNode( "c" ) );
4802 if ( !bc_3.getName().equals( "bc" ) ) {
4805 final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4806 p3.getNode( "c" ) );
4807 if ( !ac_3.getName().equals( "abc" ) ) {
4810 final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4811 p3.getNode( "d" ) );
4812 if ( !ad_3.getName().equals( "abcde" ) ) {
4815 final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4816 p3.getNode( "f" ) );
4817 if ( !af_3.getName().equals( "abcdef" ) ) {
4820 final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4821 p3.getNode( "g" ) );
4822 if ( !ag_3.getName().equals( "" ) ) {
4825 if ( !ag_3.isRoot() ) {
4828 final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
4829 p3.getNode( "l" ) );
4830 if ( !al_3.getName().equals( "" ) ) {
4833 if ( !al_3.isRoot() ) {
4836 final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
4837 p3.getNode( "l" ) );
4838 if ( !kl_3.getName().equals( "" ) ) {
4841 if ( !kl_3.isRoot() ) {
4844 final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
4845 p3.getNode( "l" ) );
4846 if ( !fl_3.getName().equals( "" ) ) {
4849 if ( !fl_3.isRoot() ) {
4852 final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
4853 p3.getNode( "k" ) );
4854 if ( !gk_3.getName().equals( "ghijk" ) ) {
4857 final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
4858 PhylogenyMethods.preOrderReId( p4 );
4859 final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
4860 p4.getNode( "c" ) );
4861 if ( !r_4.getName().equals( "r" ) ) {
4864 final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
4865 PhylogenyMethods.preOrderReId( p5 );
4866 final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
4867 p5.getNode( "c" ) );
4868 if ( !r_5.getName().equals( "root" ) ) {
4871 final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
4872 PhylogenyMethods.preOrderReId( p6 );
4873 final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
4874 p6.getNode( "a" ) );
4875 if ( !r_6.getName().equals( "rot" ) ) {
4878 final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
4879 PhylogenyMethods.preOrderReId( p7 );
4880 final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
4881 p7.getNode( "e" ) );
4882 if ( !r_7.getName().equals( "rott" ) ) {
4885 final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4886 p7.getNode( "a" ) );
4887 if ( !r_71.getName().equals( "rott" ) ) {
4890 final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4891 p7.getNode( "rott" ) );
4892 if ( !r_72.getName().equals( "rott" ) ) {
4895 final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
4896 p7.getNode( "a" ) );
4897 if ( !r_73.getName().equals( "rott" ) ) {
4900 final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
4901 p7.getNode( "rott" ) );
4902 if ( !r_74.getName().equals( "rott" ) ) {
4905 final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
4906 p7.getNode( "e" ) );
4907 if ( !r_75.getName().equals( "e" ) ) {
4911 catch ( final Exception e ) {
4912 e.printStackTrace( System.out );
4918 private static boolean testHmmscanOutputParser() {
4919 final String test_dir = Test.PATH_TO_TEST_DATA;
4921 final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
4922 + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4924 final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
4925 + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
4926 final List<Protein> proteins = parser2.parse();
4927 if ( parser2.getProteinsEncountered() != 4 ) {
4930 if ( proteins.size() != 4 ) {
4933 if ( parser2.getDomainsEncountered() != 69 ) {
4936 if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
4939 if ( parser2.getDomainsIgnoredDueToEval() != 0 ) {
4942 final Protein p1 = proteins.get( 0 );
4943 if ( p1.getNumberOfProteinDomains() != 15 ) {
4946 if ( p1.getLength() != 850 ) {
4949 final Protein p2 = proteins.get( 1 );
4950 if ( p2.getNumberOfProteinDomains() != 51 ) {
4953 if ( p2.getLength() != 1291 ) {
4956 final Protein p3 = proteins.get( 2 );
4957 if ( p3.getNumberOfProteinDomains() != 2 ) {
4960 final Protein p4 = proteins.get( 3 );
4961 if ( p4.getNumberOfProteinDomains() != 1 ) {
4964 if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
4967 if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
4970 if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
4973 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
4976 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
4979 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceEvalue(), 8.3e-40 ) ) {
4982 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerSequenceScore(), 136.3 ) ) {
4985 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
4988 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
4992 catch ( final Exception e ) {
4993 e.printStackTrace( System.out );
4999 private static boolean testLastExternalNodeMethods() {
5001 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5002 final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
5003 final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
5004 final PhylogenyNode n1 = t0.getNode( "A" );
5005 if ( n1.isLastExternalNode() ) {
5008 final PhylogenyNode n2 = t0.getNode( "B" );
5009 if ( n2.isLastExternalNode() ) {
5012 final PhylogenyNode n3 = t0.getNode( "C" );
5013 if ( n3.isLastExternalNode() ) {
5016 final PhylogenyNode n4 = t0.getNode( "D" );
5017 if ( !n4.isLastExternalNode() ) {
5021 catch ( final Exception e ) {
5022 e.printStackTrace( System.out );
5028 private static boolean testLevelOrderIterator() {
5030 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5031 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5032 PhylogenyNodeIterator it0;
5033 for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
5036 for( it0.reset(); it0.hasNext(); ) {
5039 final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
5040 if ( !it.next().getName().equals( "r" ) ) {
5043 if ( !it.next().getName().equals( "ab" ) ) {
5046 if ( !it.next().getName().equals( "cd" ) ) {
5049 if ( !it.next().getName().equals( "A" ) ) {
5052 if ( !it.next().getName().equals( "B" ) ) {
5055 if ( !it.next().getName().equals( "C" ) ) {
5058 if ( !it.next().getName().equals( "D" ) ) {
5061 if ( it.hasNext() ) {
5064 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",
5065 new NHXParser() )[ 0 ];
5066 PhylogenyNodeIterator it2;
5067 for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
5070 for( it2.reset(); it2.hasNext(); ) {
5073 final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
5074 if ( !it3.next().getName().equals( "r" ) ) {
5077 if ( !it3.next().getName().equals( "abc" ) ) {
5080 if ( !it3.next().getName().equals( "defg" ) ) {
5083 if ( !it3.next().getName().equals( "A" ) ) {
5086 if ( !it3.next().getName().equals( "B" ) ) {
5089 if ( !it3.next().getName().equals( "C" ) ) {
5092 if ( !it3.next().getName().equals( "D" ) ) {
5095 if ( !it3.next().getName().equals( "E" ) ) {
5098 if ( !it3.next().getName().equals( "F" ) ) {
5101 if ( !it3.next().getName().equals( "G" ) ) {
5104 if ( !it3.next().getName().equals( "1" ) ) {
5107 if ( !it3.next().getName().equals( "2" ) ) {
5110 if ( !it3.next().getName().equals( "3" ) ) {
5113 if ( !it3.next().getName().equals( "4" ) ) {
5116 if ( !it3.next().getName().equals( "5" ) ) {
5119 if ( !it3.next().getName().equals( "6" ) ) {
5122 if ( !it3.next().getName().equals( "f1" ) ) {
5125 if ( !it3.next().getName().equals( "f2" ) ) {
5128 if ( !it3.next().getName().equals( "f3" ) ) {
5131 if ( !it3.next().getName().equals( "a" ) ) {
5134 if ( !it3.next().getName().equals( "b" ) ) {
5137 if ( !it3.next().getName().equals( "f21" ) ) {
5140 if ( !it3.next().getName().equals( "X" ) ) {
5143 if ( !it3.next().getName().equals( "Y" ) ) {
5146 if ( !it3.next().getName().equals( "Z" ) ) {
5149 if ( it3.hasNext() ) {
5152 final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
5153 PhylogenyNodeIterator it4;
5154 for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
5157 for( it4.reset(); it4.hasNext(); ) {
5160 final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
5161 if ( !it5.next().getName().equals( "r" ) ) {
5164 if ( !it5.next().getName().equals( "A" ) ) {
5167 if ( !it5.next().getName().equals( "B" ) ) {
5170 if ( !it5.next().getName().equals( "C" ) ) {
5173 if ( !it5.next().getName().equals( "D" ) ) {
5176 final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
5177 PhylogenyNodeIterator it6;
5178 for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
5181 for( it6.reset(); it6.hasNext(); ) {
5184 final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
5185 if ( !it7.next().getName().equals( "A" ) ) {
5188 if ( it.hasNext() ) {
5192 catch ( final Exception e ) {
5193 e.printStackTrace( System.out );
5199 private static boolean testMafft( final String path ) {
5201 final List<String> opts = new ArrayList<String>();
5202 opts.add( "--maxiterate" );
5204 opts.add( "--localpair" );
5205 opts.add( "--quiet" );
5207 final MsaInferrer mafft = Mafft.createInstance( path );
5208 msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
5209 if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
5212 if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
5216 catch ( final Exception e ) {
5217 e.printStackTrace( System.out );
5223 private static boolean testMidpointrooting() {
5225 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5226 final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
5227 PhylogenyMethods.midpointRoot( t0 );
5228 if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
5231 if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
5234 if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
5238 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",
5239 new NHXParser() )[ 0 ];
5240 if ( !t1.isRooted() ) {
5243 PhylogenyMethods.midpointRoot( t1 );
5244 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5247 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5250 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5253 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5256 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5259 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5262 t1.reRoot( t1.getNode( "A" ) );
5263 PhylogenyMethods.midpointRoot( t1 );
5264 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
5267 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
5270 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
5273 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
5276 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
5280 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
5284 catch ( final Exception e ) {
5285 e.printStackTrace( System.out );
5291 private static boolean testMsaQualityMethod() {
5293 final Sequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJ" );
5294 final Sequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJ" );
5295 final Sequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJ" );
5296 final Sequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ" );
5297 final List<Sequence> l = new ArrayList<Sequence>();
5302 final Msa msa = BasicMsa.createInstance( l );
5303 if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
5306 if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
5309 if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
5312 if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
5316 catch ( final Exception e ) {
5317 e.printStackTrace( System.out );
5323 private static boolean testNextNodeWithCollapsing() {
5325 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5327 List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
5328 final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5329 final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
5330 t0.getNode( "cd" ).setCollapse( true );
5331 t0.getNode( "cde" ).setCollapse( true );
5332 n = t0.getFirstExternalNode();
5333 while ( n != null ) {
5335 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5337 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5340 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5343 if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
5346 if ( !ext.get( 3 ).getName().equals( "f" ) ) {
5349 if ( !ext.get( 4 ).getName().equals( "g" ) ) {
5352 if ( !ext.get( 5 ).getName().equals( "h" ) ) {
5356 final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5357 final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
5358 t1.getNode( "ab" ).setCollapse( true );
5359 t1.getNode( "cd" ).setCollapse( true );
5360 t1.getNode( "cde" ).setCollapse( true );
5361 n = t1.getNode( "ab" );
5362 ext = new ArrayList<PhylogenyNode>();
5363 while ( n != null ) {
5365 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5367 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5370 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5373 if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5376 if ( !ext.get( 3 ).getName().equals( "g" ) ) {
5379 if ( !ext.get( 4 ).getName().equals( "h" ) ) {
5385 final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5386 final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
5387 t2.getNode( "ab" ).setCollapse( true );
5388 t2.getNode( "cd" ).setCollapse( true );
5389 t2.getNode( "cde" ).setCollapse( true );
5390 t2.getNode( "c" ).setCollapse( true );
5391 t2.getNode( "d" ).setCollapse( true );
5392 t2.getNode( "e" ).setCollapse( true );
5393 t2.getNode( "gh" ).setCollapse( true );
5394 n = t2.getNode( "ab" );
5395 ext = new ArrayList<PhylogenyNode>();
5396 while ( n != null ) {
5398 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5400 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5403 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5406 if ( !ext.get( 2 ).getName().equals( "f" ) ) {
5409 if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
5415 final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5416 final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
5417 t3.getNode( "ab" ).setCollapse( true );
5418 t3.getNode( "cd" ).setCollapse( true );
5419 t3.getNode( "cde" ).setCollapse( true );
5420 t3.getNode( "c" ).setCollapse( true );
5421 t3.getNode( "d" ).setCollapse( true );
5422 t3.getNode( "e" ).setCollapse( true );
5423 t3.getNode( "gh" ).setCollapse( true );
5424 t3.getNode( "fgh" ).setCollapse( true );
5425 n = t3.getNode( "ab" );
5426 ext = new ArrayList<PhylogenyNode>();
5427 while ( n != null ) {
5429 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5431 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5434 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5437 if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
5443 final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5444 final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
5445 t4.getNode( "ab" ).setCollapse( true );
5446 t4.getNode( "cd" ).setCollapse( true );
5447 t4.getNode( "cde" ).setCollapse( true );
5448 t4.getNode( "c" ).setCollapse( true );
5449 t4.getNode( "d" ).setCollapse( true );
5450 t4.getNode( "e" ).setCollapse( true );
5451 t4.getNode( "gh" ).setCollapse( true );
5452 t4.getNode( "fgh" ).setCollapse( true );
5453 t4.getNode( "abcdefgh" ).setCollapse( true );
5454 n = t4.getNode( "abcdefgh" );
5455 if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
5460 final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5461 final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
5463 n = t5.getFirstExternalNode();
5464 while ( n != null ) {
5466 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5468 if ( ext.size() != 8 ) {
5471 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5474 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5477 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5480 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5483 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5486 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5489 if ( !ext.get( 6 ).getName().equals( "g" ) ) {
5492 if ( !ext.get( 7 ).getName().equals( "h" ) ) {
5497 final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5498 final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
5500 t6.getNode( "ab" ).setCollapse( true );
5501 n = t6.getNode( "ab" );
5502 while ( n != null ) {
5504 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5506 if ( ext.size() != 7 ) {
5509 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5512 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5515 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5518 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5521 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5524 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5527 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5532 final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5533 final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
5535 t7.getNode( "cd" ).setCollapse( true );
5536 n = t7.getNode( "a" );
5537 while ( n != null ) {
5539 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5541 if ( ext.size() != 7 ) {
5544 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5547 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5550 if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
5553 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5556 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5559 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5562 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5567 final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
5568 final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
5570 t8.getNode( "cd" ).setCollapse( true );
5571 t8.getNode( "c" ).setCollapse( true );
5572 t8.getNode( "d" ).setCollapse( true );
5573 n = t8.getNode( "a" );
5574 while ( n != null ) {
5576 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5578 if ( ext.size() != 7 ) {
5581 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5584 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5587 if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
5588 System.out.println( "2 fail" );
5591 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5594 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
5597 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
5600 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
5605 final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5606 final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
5608 t9.getNode( "gh" ).setCollapse( true );
5609 n = t9.getNode( "a" );
5610 while ( n != null ) {
5612 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5614 if ( ext.size() != 7 ) {
5617 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5620 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5623 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5626 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5629 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5632 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5635 if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
5640 final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5641 final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
5643 t10.getNode( "gh" ).setCollapse( true );
5644 t10.getNode( "g" ).setCollapse( true );
5645 t10.getNode( "h" ).setCollapse( true );
5646 n = t10.getNode( "a" );
5647 while ( n != null ) {
5649 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5651 if ( ext.size() != 7 ) {
5654 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5657 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5660 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5663 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5666 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5669 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
5672 if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
5677 final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5678 final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
5680 t11.getNode( "gh" ).setCollapse( true );
5681 t11.getNode( "fgh" ).setCollapse( true );
5682 n = t11.getNode( "a" );
5683 while ( n != null ) {
5685 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5687 if ( ext.size() != 6 ) {
5690 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5693 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5696 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5699 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5702 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5705 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
5710 final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5711 final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
5713 t12.getNode( "gh" ).setCollapse( true );
5714 t12.getNode( "fgh" ).setCollapse( true );
5715 t12.getNode( "g" ).setCollapse( true );
5716 t12.getNode( "h" ).setCollapse( true );
5717 t12.getNode( "f" ).setCollapse( true );
5718 n = t12.getNode( "a" );
5719 while ( n != null ) {
5721 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5723 if ( ext.size() != 6 ) {
5726 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
5729 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
5732 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
5735 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
5738 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
5741 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
5746 final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
5747 final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
5749 t13.getNode( "ab" ).setCollapse( true );
5750 t13.getNode( "b" ).setCollapse( true );
5751 t13.getNode( "fgh" ).setCollapse( true );
5752 t13.getNode( "gh" ).setCollapse( true );
5753 n = t13.getNode( "ab" );
5754 while ( n != null ) {
5756 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5758 if ( ext.size() != 5 ) {
5761 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5764 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5767 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5770 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5773 if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
5778 final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
5779 final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
5781 t14.getNode( "ab" ).setCollapse( true );
5782 t14.getNode( "a" ).setCollapse( true );
5783 t14.getNode( "fgh" ).setCollapse( true );
5784 t14.getNode( "gh" ).setCollapse( true );
5785 n = t14.getNode( "ab" );
5786 while ( n != null ) {
5788 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5790 if ( ext.size() != 5 ) {
5793 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5796 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5799 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5802 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5805 if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
5810 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" );
5811 final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
5813 t15.getNode( "ab" ).setCollapse( true );
5814 t15.getNode( "a" ).setCollapse( true );
5815 t15.getNode( "fgh" ).setCollapse( true );
5816 t15.getNode( "gh" ).setCollapse( true );
5817 n = t15.getNode( "ab" );
5818 while ( n != null ) {
5820 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5822 if ( ext.size() != 6 ) {
5825 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5828 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
5831 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
5834 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
5837 if ( !ext.get( 4 ).getName().equals( "x" ) ) {
5840 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
5845 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" );
5846 final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
5848 t16.getNode( "ab" ).setCollapse( true );
5849 t16.getNode( "a" ).setCollapse( true );
5850 t16.getNode( "fgh" ).setCollapse( true );
5851 t16.getNode( "gh" ).setCollapse( true );
5852 t16.getNode( "cd" ).setCollapse( true );
5853 t16.getNode( "cde" ).setCollapse( true );
5854 t16.getNode( "d" ).setCollapse( true );
5855 t16.getNode( "x" ).setCollapse( true );
5856 n = t16.getNode( "ab" );
5857 while ( n != null ) {
5859 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
5861 if ( ext.size() != 4 ) {
5864 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
5867 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
5870 if ( !ext.get( 2 ).getName().equals( "x" ) ) {
5873 if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
5877 catch ( final Exception e ) {
5878 e.printStackTrace( System.out );
5884 private static boolean testNexusCharactersParsing() {
5886 final NexusCharactersParser parser = new NexusCharactersParser();
5887 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
5889 String[] labels = parser.getCharStateLabels();
5890 if ( labels.length != 7 ) {
5893 if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5896 if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5899 if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5902 if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5905 if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
5908 if ( !labels[ 5 ].equals( "3-HAO" ) ) {
5911 if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
5914 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
5916 labels = parser.getCharStateLabels();
5917 if ( labels.length != 7 ) {
5920 if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5923 if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5926 if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5929 if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5932 if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
5935 if ( !labels[ 5 ].equals( "3-HAO" ) ) {
5938 if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
5942 catch ( final Exception e ) {
5943 e.printStackTrace( System.out );
5949 private static boolean testNexusMatrixParsing() {
5951 final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
5952 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
5954 final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
5955 if ( m.getNumberOfCharacters() != 9 ) {
5958 if ( m.getNumberOfIdentifiers() != 5 ) {
5961 if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
5964 if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
5967 if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
5970 if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
5973 if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
5976 if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
5979 if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
5982 // if ( labels.length != 7 ) {
5985 // if ( !labels[ 0 ].equals( "14-3-3" ) ) {
5988 // if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
5991 // if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
5994 // if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
5997 // if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6000 // if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6003 // if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6006 // parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
6008 // labels = parser.getCharStateLabels();
6009 // if ( labels.length != 7 ) {
6012 // if ( !labels[ 0 ].equals( "14-3-3" ) ) {
6015 // if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
6018 // if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
6021 // if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
6024 // if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
6027 // if ( !labels[ 5 ].equals( "3-HAO" ) ) {
6030 // if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
6034 catch ( final Exception e ) {
6035 e.printStackTrace( System.out );
6041 private static boolean testNexusTreeParsing() {
6043 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6044 final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
6045 Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
6046 if ( phylogenies.length != 1 ) {
6049 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
6052 if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6056 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
6057 if ( phylogenies.length != 1 ) {
6060 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6063 if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
6067 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
6068 if ( phylogenies.length != 1 ) {
6071 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6074 if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
6077 if ( phylogenies[ 0 ].isRooted() ) {
6081 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
6082 if ( phylogenies.length != 18 ) {
6085 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
6088 if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
6091 if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
6094 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
6097 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6100 if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
6103 if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
6106 if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
6109 if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
6112 if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
6115 if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
6118 if ( phylogenies[ 8 ].isRooted() ) {
6121 if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
6124 if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
6127 if ( !phylogenies[ 9 ].isRooted() ) {
6130 if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
6133 if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
6136 if ( !phylogenies[ 10 ].isRooted() ) {
6139 if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
6142 if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
6145 if ( phylogenies[ 11 ].isRooted() ) {
6148 if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
6151 if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
6154 if ( !phylogenies[ 12 ].isRooted() ) {
6157 if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
6160 if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
6163 if ( !phylogenies[ 13 ].isRooted() ) {
6166 if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
6169 if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
6172 if ( !phylogenies[ 14 ].isRooted() ) {
6175 if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
6178 if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
6181 if ( phylogenies[ 15 ].isRooted() ) {
6184 if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
6187 if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
6190 if ( !phylogenies[ 16 ].isRooted() ) {
6193 if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
6196 if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
6199 if ( phylogenies[ 17 ].isRooted() ) {
6202 if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
6206 catch ( final Exception e ) {
6207 e.printStackTrace( System.out );
6213 private static boolean testNexusTreeParsingIterating() {
6215 final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
6216 p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
6217 if ( !p.hasNext() ) {
6220 Phylogeny phy = p.next();
6221 if ( phy == null ) {
6224 if ( phy.getNumberOfExternalNodes() != 25 ) {
6227 if ( !phy.getName().equals( "" ) ) {
6230 if ( p.hasNext() ) {
6234 if ( phy != null ) {
6239 if ( !p.hasNext() ) {
6243 if ( phy == null ) {
6246 if ( phy.getNumberOfExternalNodes() != 25 ) {
6249 if ( !phy.getName().equals( "" ) ) {
6252 if ( p.hasNext() ) {
6256 if ( phy != null ) {
6260 p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
6261 if ( !p.hasNext() ) {
6265 if ( phy == null ) {
6268 if ( phy.getNumberOfExternalNodes() != 10 ) {
6271 if ( !phy.getName().equals( "name" ) ) {
6274 if ( p.hasNext() ) {
6278 if ( phy != null ) {
6283 if ( !p.hasNext() ) {
6287 if ( phy == null ) {
6290 if ( phy.getNumberOfExternalNodes() != 10 ) {
6293 if ( !phy.getName().equals( "name" ) ) {
6296 if ( p.hasNext() ) {
6300 if ( phy != null ) {
6304 p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
6305 if ( !p.hasNext() ) {
6309 if ( phy == null ) {
6312 if ( phy.getNumberOfExternalNodes() != 3 ) {
6315 if ( !phy.getName().equals( "" ) ) {
6318 if ( phy.isRooted() ) {
6321 if ( p.hasNext() ) {
6325 if ( phy != null ) {
6330 if ( !p.hasNext() ) {
6334 if ( phy == null ) {
6337 if ( phy.getNumberOfExternalNodes() != 3 ) {
6340 if ( !phy.getName().equals( "" ) ) {
6343 if ( p.hasNext() ) {
6347 if ( phy != null ) {
6351 p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
6352 // if ( phylogenies.length != 18 ) {
6356 if ( !p.hasNext() ) {
6360 if ( phy == null ) {
6363 if ( phy.getNumberOfExternalNodes() != 10 ) {
6366 if ( !phy.getName().equals( "tree 0" ) ) {
6370 if ( !p.hasNext() ) {
6374 if ( phy == null ) {
6377 if ( phy.getNumberOfExternalNodes() != 10 ) {
6380 if ( !phy.getName().equals( "tree 1" ) ) {
6384 if ( !p.hasNext() ) {
6388 if ( phy == null ) {
6391 if ( phy.getNumberOfExternalNodes() != 3 ) {
6394 if ( !phy.getName().equals( "" ) ) {
6397 if ( phy.isRooted() ) {
6401 if ( !p.hasNext() ) {
6405 if ( phy == null ) {
6408 if ( phy.getNumberOfExternalNodes() != 4 ) {
6411 if ( !phy.getName().equals( "" ) ) {
6414 if ( !phy.isRooted() ) {
6418 if ( !p.hasNext() ) {
6422 if ( phy == null ) {
6425 if ( phy.getNumberOfExternalNodes() != 5 ) {
6426 System.out.println( phy.getNumberOfExternalNodes() );
6429 if ( !phy.getName().equals( "" ) ) {
6432 if ( !phy.isRooted() ) {
6436 if ( !p.hasNext() ) {
6440 if ( phy == null ) {
6443 if ( phy.getNumberOfExternalNodes() != 3 ) {
6446 if ( !phy.getName().equals( "" ) ) {
6449 if ( phy.isRooted() ) {
6453 if ( !p.hasNext() ) {
6457 if ( phy == null ) {
6460 if ( phy.getNumberOfExternalNodes() != 2 ) {
6463 if ( !phy.getName().equals( "" ) ) {
6466 if ( !phy.isRooted() ) {
6470 if ( !p.hasNext() ) {
6474 if ( phy.getNumberOfExternalNodes() != 3 ) {
6477 if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6480 if ( !phy.isRooted() ) {
6484 if ( !p.hasNext() ) {
6488 if ( phy.getNumberOfExternalNodes() != 3 ) {
6491 if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
6494 if ( !phy.getName().equals( "tree 8" ) ) {
6498 if ( !p.hasNext() ) {
6502 if ( phy.getNumberOfExternalNodes() != 3 ) {
6505 if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
6508 if ( !phy.getName().equals( "tree 9" ) ) {
6512 if ( !p.hasNext() ) {
6516 if ( phy.getNumberOfExternalNodes() != 3 ) {
6519 if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6522 if ( !phy.getName().equals( "tree 10" ) ) {
6525 if ( !phy.isRooted() ) {
6529 if ( !p.hasNext() ) {
6533 if ( phy.getNumberOfExternalNodes() != 3 ) {
6536 if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
6539 if ( !phy.getName().equals( "tree 11" ) ) {
6542 if ( phy.isRooted() ) {
6546 if ( !p.hasNext() ) {
6550 if ( phy.getNumberOfExternalNodes() != 3 ) {
6553 if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
6556 if ( !phy.getName().equals( "tree 12" ) ) {
6559 if ( !phy.isRooted() ) {
6563 if ( !p.hasNext() ) {
6567 if ( phy.getNumberOfExternalNodes() != 3 ) {
6570 if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
6573 if ( !phy.getName().equals( "tree 13" ) ) {
6576 if ( !phy.isRooted() ) {
6580 if ( !p.hasNext() ) {
6584 if ( phy.getNumberOfExternalNodes() != 10 ) {
6585 System.out.println( phy.getNumberOfExternalNodes() );
6590 .equals( "(1:0.212481,8:0.297838,(9:0.222729,((6:0.201563,7:0.194547):0.282035,(4:1.146091,(3:1.008881,(10:0.384105,(2:0.235682,5:0.353432):0.32368):0.103875):0.41354):0.254687):0.095341):0.079254):0.0;" ) ) {
6591 System.out.println( phy.toNewHampshire() );
6594 if ( !phy.getName().equals( "tree 14" ) ) {
6597 if ( !phy.isRooted() ) {
6601 if ( !p.hasNext() ) {
6605 if ( phy.getNumberOfExternalNodes() != 10 ) {
6606 System.out.println( phy.getNumberOfExternalNodes() );
6611 .equals( "(1:0.212481,8:0.297838,(9:0.222729,((6:0.201563,7:0.194547):0.282035,(4:1.146091,(3:1.008881,(10:0.384105,(2:0.235682,5:0.353432):0.32368):0.103875):0.41354):0.254687):0.095341):0.079254):0.0;" ) ) {
6612 System.out.println( phy.toNewHampshire() );
6615 if ( !phy.getName().equals( "tree 15" ) ) {
6618 if ( phy.isRooted() ) {
6622 if ( !p.hasNext() ) {
6626 if ( phy.getNumberOfExternalNodes() != 10 ) {
6627 System.out.println( phy.getNumberOfExternalNodes() );
6632 .equals( "(1:0.212481,8:0.297838,(9:0.222729,((6:0.201563,7:0.194547):0.282035,(4:1.146091,(3:1.008881,(10:0.384105,(2:0.235682,5:0.353432):0.32368):0.103875):0.41354):0.254687):0.095341):0.079254):0.0;" ) ) {
6633 System.out.println( phy.toNewHampshire() );
6636 if ( !phy.getName().equals( "tree 16" ) ) {
6639 if ( !phy.isRooted() ) {
6643 if ( !p.hasNext() ) {
6647 if ( phy.getNumberOfExternalNodes() != 10 ) {
6648 System.out.println( phy.getNumberOfExternalNodes() );
6653 .equals( "(1:0.212481,8:0.297838,(9:0.222729,((6:0.201563,7:0.194547):0.282035,(4:1.146091,(3:1.008881,(10:0.384105,(2:0.235682,5:0.353432):0.32368):0.103875):0.41354):0.254687):0.095341):0.079254):0.0;" ) ) {
6654 System.out.println( phy.toNewHampshire() );
6657 if ( !phy.getName().equals( "tree 17" ) ) {
6660 if ( phy.isRooted() ) {
6664 if ( p.hasNext() ) {
6668 if ( phy != null ) {
6673 if ( !p.hasNext() ) {
6677 if ( phy == null ) {
6680 if ( phy.getNumberOfExternalNodes() != 10 ) {
6683 if ( !phy.getName().equals( "tree 0" ) ) {
6687 if ( !p.hasNext() ) {
6691 if ( phy == null ) {
6694 if ( phy.getNumberOfExternalNodes() != 10 ) {
6697 if ( !phy.getName().equals( "tree 1" ) ) {
6701 if ( !p.hasNext() ) {
6705 if ( phy == null ) {
6708 if ( phy.getNumberOfExternalNodes() != 3 ) {
6711 if ( !phy.getName().equals( "" ) ) {
6714 if ( phy.isRooted() ) {
6718 if ( !p.hasNext() ) {
6722 if ( phy == null ) {
6725 if ( phy.getNumberOfExternalNodes() != 4 ) {
6728 if ( !phy.getName().equals( "" ) ) {
6731 if ( !phy.isRooted() ) {
6735 if ( !p.hasNext() ) {
6739 if ( phy == null ) {
6742 if ( phy.getNumberOfExternalNodes() != 5 ) {
6743 System.out.println( phy.getNumberOfExternalNodes() );
6746 if ( !phy.getName().equals( "" ) ) {
6749 if ( !phy.isRooted() ) {
6753 if ( !p.hasNext() ) {
6757 if ( phy == null ) {
6760 if ( phy.getNumberOfExternalNodes() != 3 ) {
6763 if ( !phy.getName().equals( "" ) ) {
6766 if ( phy.isRooted() ) {
6770 catch ( final Exception e ) {
6771 e.printStackTrace( System.out );
6777 private static boolean testNexusTreeParsingTranslating() {
6779 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6780 final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
6781 Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
6782 if ( phylogenies.length != 1 ) {
6785 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6788 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
6791 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6794 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6797 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6798 .equals( "Aranaeus" ) ) {
6802 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
6803 if ( phylogenies.length != 3 ) {
6806 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6809 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
6812 if ( phylogenies[ 0 ].isRooted() ) {
6815 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6818 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6821 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6822 .equals( "Aranaeus" ) ) {
6825 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
6828 if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
6831 if ( phylogenies[ 1 ].isRooted() ) {
6834 if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6837 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6840 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6841 .equals( "Aranaeus" ) ) {
6844 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6847 if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
6850 if ( !phylogenies[ 2 ].isRooted() ) {
6853 if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6856 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6859 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6860 .equals( "Aranaeus" ) ) {
6864 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
6865 if ( phylogenies.length != 3 ) {
6868 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
6871 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
6874 if ( phylogenies[ 0 ].isRooted() ) {
6877 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6880 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6883 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6884 .equals( "Aranaeus" ) ) {
6887 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
6890 if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
6893 if ( phylogenies[ 1 ].isRooted() ) {
6896 if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6899 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6902 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6903 .equals( "Aranaeus" ) ) {
6906 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
6909 if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
6912 if ( !phylogenies[ 2 ].isRooted() ) {
6915 if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
6918 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
6921 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
6922 .equals( "Aranaeus" ) ) {
6926 catch ( final Exception e ) {
6927 e.printStackTrace( System.out );
6933 private static boolean testNHParsing() {
6935 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6936 final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
6937 if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
6940 final NHXParser nhxp = new NHXParser();
6941 nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
6942 nhxp.setReplaceUnderscores( true );
6943 final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
6944 if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A " ) ) {
6947 if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( " B B" ) ) {
6950 final Phylogeny p1b = factory
6951 .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 ",
6952 new NHXParser() )[ 0 ];
6953 if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
6956 if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
6959 final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
6960 final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
6961 final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
6962 final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
6963 final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
6964 final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
6965 final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
6966 final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
6967 final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
6968 final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
6969 final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1 3 ; \n)\t ( \n ;"
6970 + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
6971 + "; ; ( \t\n\r\b; G ;, ;H ;1 3; ) ; ; ;",
6973 if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
6976 if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
6979 if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
6982 if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
6985 final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
6986 final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
6987 final String p16_S = "((A,B),C)";
6988 final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
6989 if ( p16.length != 1 ) {
6992 if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
6995 final String p17_S = "(C,(A,B))";
6996 final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
6997 if ( p17.length != 1 ) {
7000 if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
7003 final String p18_S = "((A,B),(C,D))";
7004 final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
7005 if ( p18.length != 1 ) {
7008 if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
7011 final String p19_S = "(((A,B),C),D)";
7012 final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
7013 if ( p19.length != 1 ) {
7016 if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
7019 final String p20_S = "(A,(B,(C,D)))";
7020 final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
7021 if ( p20.length != 1 ) {
7024 if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
7027 final String p21_S = "(A,(B,(C,(D,E))))";
7028 final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
7029 if ( p21.length != 1 ) {
7032 if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
7035 final String p22_S = "((((A,B),C),D),E)";
7036 final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
7037 if ( p22.length != 1 ) {
7040 if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
7043 final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7044 final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
7045 if ( p23.length != 1 ) {
7046 System.out.println( "xl=" + p23.length );
7050 if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
7053 final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7054 final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
7055 if ( p24.length != 1 ) {
7058 if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
7061 final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7062 final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7063 final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
7064 if ( p241.length != 2 ) {
7067 if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
7070 if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
7073 final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
7074 + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
7075 + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
7076 + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
7077 + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
7078 + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
7079 + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
7080 + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
7081 final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
7082 if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
7085 final String p26_S = "(A,B)ab";
7086 final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
7087 if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
7090 final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7091 final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
7092 if ( p27s.length != 1 ) {
7093 System.out.println( "xxl=" + p27s.length );
7097 if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
7098 System.out.println( p27s[ 0 ].toNewHampshireX() );
7102 final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
7104 if ( p27.length != 1 ) {
7105 System.out.println( "yl=" + p27.length );
7109 if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
7110 System.out.println( p27[ 0 ].toNewHampshireX() );
7114 final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7115 final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7116 final String p28_S3 = "(A,B)ab";
7117 final String p28_S4 = "((((A,B),C),D),;E;)";
7118 final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
7120 if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
7123 if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
7126 if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
7129 if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
7132 if ( p28.length != 4 ) {
7135 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";
7136 final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
7137 if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
7140 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";
7141 final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
7142 if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
7145 final String p32_S = " ; ; \n \t \b \f \r ;;;;;; ";
7146 final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
7147 if ( ( p32.length != 0 ) ) {
7150 final String p33_S = "A";
7151 final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
7152 if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
7155 final String p34_S = "B;";
7156 final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
7157 if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
7160 final String p35_S = "B:0.2";
7161 final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
7162 if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
7165 final String p36_S = "(A)";
7166 final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
7167 if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
7170 final String p37_S = "((A))";
7171 final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
7172 if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
7175 final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
7176 final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
7177 if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
7180 final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
7181 final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
7182 if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
7185 final String p40_S = "(A,B,C)";
7186 final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
7187 if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
7190 final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
7191 final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
7192 if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
7195 final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
7196 final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
7197 if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
7200 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)";
7201 final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
7202 if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
7205 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)))";
7206 final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
7207 if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
7210 final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
7211 final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
7212 if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
7215 final String p46_S = "";
7216 final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
7217 if ( p46.length != 0 ) {
7220 final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
7221 if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7224 final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7225 if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7228 final Phylogeny p49 = factory
7229 .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
7230 new NHXParser() )[ 0 ];
7231 if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
7234 final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7235 if ( p50.getNode( "A" ) == null ) {
7238 if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7239 .equals( "((A,B)ab:2.0[88],C);" ) ) {
7242 if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
7245 if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
7246 .equals( "((A,B)88:2.0,C);" ) ) {
7249 final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7250 if ( p51.getNode( "A(A" ) == null ) {
7253 final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
7254 if ( p52.getNode( "A(A" ) == null ) {
7257 final Phylogeny p53 = factory
7258 .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
7259 new NHXParser() )[ 0 ];
7260 if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
7264 final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
7265 if ( p54.getNode( "A" ) == null ) {
7268 if ( !p54.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
7269 .equals( "((A,B)[88],C);" ) ) {
7273 catch ( final Exception e ) {
7274 e.printStackTrace( System.out );
7280 private static boolean testNHParsingIter() {
7282 final String p0_str = "(A,B);";
7283 final NHXParser p = new NHXParser();
7284 p.setSource( p0_str );
7285 if ( !p.hasNext() ) {
7288 final Phylogeny p0 = p.next();
7289 if ( !p0.toNewHampshire().equals( p0_str ) ) {
7290 System.out.println( p0.toNewHampshire() );
7293 if ( p.hasNext() ) {
7296 if ( p.next() != null ) {
7300 final String p00_str = "(A,B)root;";
7301 p.setSource( p00_str );
7302 final Phylogeny p00 = p.next();
7303 if ( !p00.toNewHampshire().equals( p00_str ) ) {
7304 System.out.println( p00.toNewHampshire() );
7308 final String p000_str = "A;";
7309 p.setSource( p000_str );
7310 final Phylogeny p000 = p.next();
7311 if ( !p000.toNewHampshire().equals( p000_str ) ) {
7312 System.out.println( p000.toNewHampshire() );
7316 final String p0000_str = "A";
7317 p.setSource( p0000_str );
7318 final Phylogeny p0000 = p.next();
7319 if ( !p0000.toNewHampshire().equals( "A;" ) ) {
7320 System.out.println( p0000.toNewHampshire() );
7324 p.setSource( "(A)" );
7325 final Phylogeny p00000 = p.next();
7326 if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
7327 System.out.println( p00000.toNewHampshire() );
7331 final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
7332 p.setSource( p1_str );
7333 if ( !p.hasNext() ) {
7336 final Phylogeny p1_0 = p.next();
7337 if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
7338 System.out.println( p1_0.toNewHampshire() );
7341 if ( !p.hasNext() ) {
7344 final Phylogeny p1_1 = p.next();
7345 if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
7346 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
7349 if ( !p.hasNext() ) {
7352 final Phylogeny p1_2 = p.next();
7353 if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
7354 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
7357 if ( !p.hasNext() ) {
7360 final Phylogeny p1_3 = p.next();
7361 if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
7362 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
7365 if ( p.hasNext() ) {
7368 if ( p.next() != null ) {
7372 final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
7373 p.setSource( p2_str );
7374 if ( !p.hasNext() ) {
7377 Phylogeny p2_0 = p.next();
7378 if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
7379 System.out.println( p2_0.toNewHampshire() );
7382 if ( !p.hasNext() ) {
7385 Phylogeny p2_1 = p.next();
7386 if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
7387 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
7390 if ( !p.hasNext() ) {
7393 Phylogeny p2_2 = p.next();
7394 if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
7395 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
7398 if ( !p.hasNext() ) {
7401 Phylogeny p2_3 = p.next();
7402 if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
7403 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
7406 if ( !p.hasNext() ) {
7409 Phylogeny p2_4 = p.next();
7410 if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
7411 System.out.println( "(X) != " + p2_4.toNewHampshire() );
7414 if ( p.hasNext() ) {
7417 if ( p.next() != null ) {
7422 if ( !p.hasNext() ) {
7426 if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
7427 System.out.println( p2_0.toNewHampshire() );
7430 if ( !p.hasNext() ) {
7434 if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
7435 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
7438 if ( !p.hasNext() ) {
7442 if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
7443 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
7446 if ( !p.hasNext() ) {
7450 if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
7451 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
7454 if ( !p.hasNext() ) {
7458 if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
7459 System.out.println( "(X) != " + p2_4.toNewHampshire() );
7462 if ( p.hasNext() ) {
7465 if ( p.next() != null ) {
7469 final String p3_str = "((A,B),C)abc";
7470 p.setSource( p3_str );
7471 if ( !p.hasNext() ) {
7474 final Phylogeny p3_0 = p.next();
7475 if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
7478 if ( p.hasNext() ) {
7481 if ( p.next() != null ) {
7485 final String p4_str = "((A,B)ab,C)abc";
7486 p.setSource( p4_str );
7487 if ( !p.hasNext() ) {
7490 final Phylogeny p4_0 = p.next();
7491 if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
7494 if ( p.hasNext() ) {
7497 if ( p.next() != null ) {
7501 final String p5_str = "(((A,B)ab,C)abc,D)abcd";
7502 p.setSource( p5_str );
7503 if ( !p.hasNext() ) {
7506 final Phylogeny p5_0 = p.next();
7507 if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
7510 if ( p.hasNext() ) {
7513 if ( p.next() != null ) {
7517 final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
7518 p.setSource( p6_str );
7519 if ( !p.hasNext() ) {
7522 Phylogeny p6_0 = p.next();
7523 if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
7526 if ( p.hasNext() ) {
7529 if ( p.next() != null ) {
7533 if ( !p.hasNext() ) {
7537 if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
7540 if ( p.hasNext() ) {
7543 if ( p.next() != null ) {
7547 final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
7548 p.setSource( p7_str );
7549 if ( !p.hasNext() ) {
7552 Phylogeny p7_0 = p.next();
7553 if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7556 if ( p.hasNext() ) {
7559 if ( p.next() != null ) {
7563 if ( !p.hasNext() ) {
7567 if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7570 if ( p.hasNext() ) {
7573 if ( p.next() != null ) {
7577 final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
7578 p.setSource( p8_str );
7579 if ( !p.hasNext() ) {
7582 Phylogeny p8_0 = p.next();
7583 if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7586 if ( !p.hasNext() ) {
7589 if ( !p.hasNext() ) {
7592 Phylogeny p8_1 = p.next();
7593 if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
7596 if ( p.hasNext() ) {
7599 if ( p.next() != null ) {
7603 if ( !p.hasNext() ) {
7607 if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
7610 if ( !p.hasNext() ) {
7614 if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
7617 if ( p.hasNext() ) {
7620 if ( p.next() != null ) {
7626 if ( p.hasNext() ) {
7630 p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
7631 if ( !p.hasNext() ) {
7634 Phylogeny p_27 = p.next();
7635 if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
7636 System.out.println( p_27.toNewHampshireX() );
7640 if ( p.hasNext() ) {
7643 if ( p.next() != null ) {
7647 if ( !p.hasNext() ) {
7651 if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
7652 System.out.println( p_27.toNewHampshireX() );
7656 if ( p.hasNext() ) {
7659 if ( p.next() != null ) {
7663 catch ( final Exception e ) {
7664 e.printStackTrace( System.out );
7670 private static boolean testNHXconversion() {
7672 final PhylogenyNode n1 = new PhylogenyNode();
7673 final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
7674 final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
7675 final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
7676 final PhylogenyNode n5 = PhylogenyNode
7677 .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
7678 final PhylogenyNode n6 = PhylogenyNode
7679 .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
7680 if ( !n1.toNewHampshireX().equals( "" ) ) {
7683 if ( !n2.toNewHampshireX().equals( "" ) ) {
7686 if ( !n3.toNewHampshireX().equals( "n3" ) ) {
7689 if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
7692 if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
7695 if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
7696 System.out.println( n6.toNewHampshireX() );
7700 catch ( final Exception e ) {
7701 e.printStackTrace( System.out );
7707 private static boolean testNHXNodeParsing() {
7709 final PhylogenyNode n1 = new PhylogenyNode();
7710 final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
7711 final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
7712 final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
7713 final PhylogenyNode n5 = PhylogenyNode
7714 .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]" );
7715 if ( !n3.getName().equals( "n3" ) ) {
7718 if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
7721 if ( n3.isDuplication() ) {
7724 if ( n3.isHasAssignedEvent() ) {
7727 if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
7730 if ( !n4.getName().equals( "n4" ) ) {
7733 if ( n4.getDistanceToParent() != 0.01 ) {
7736 if ( !n5.getName().equals( "n5" ) ) {
7739 if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
7742 if ( n5.getDistanceToParent() != 0.1 ) {
7745 if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
7748 if ( !n5.isDuplication() ) {
7751 if ( !n5.isHasAssignedEvent() ) {
7754 final PhylogenyNode n8 = PhylogenyNode
7755 .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
7756 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7757 if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
7760 if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
7763 final PhylogenyNode n9 = PhylogenyNode
7764 .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
7765 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7766 if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
7769 if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
7772 final PhylogenyNode n10 = PhylogenyNode
7773 .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7774 if ( !n10.getName().equals( "n10.ECOLI" ) ) {
7777 final PhylogenyNode n20 = PhylogenyNode
7778 .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7779 if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
7782 if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
7785 final PhylogenyNode n20x = PhylogenyNode
7786 .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7787 if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
7790 if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
7793 final PhylogenyNode n20xx = PhylogenyNode
7794 .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7795 if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
7798 if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
7801 final PhylogenyNode n20xxx = PhylogenyNode
7802 .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7803 if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
7806 if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
7809 final PhylogenyNode n20xxxx = PhylogenyNode
7810 .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7811 if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
7814 if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
7817 final PhylogenyNode n21 = PhylogenyNode
7818 .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7819 if ( !n21.getName().equals( "N21_PIG" ) ) {
7822 if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
7825 final PhylogenyNode n21x = PhylogenyNode
7826 .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7827 if ( !n21x.getName().equals( "n21_PIG" ) ) {
7830 if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
7833 final PhylogenyNode n22 = PhylogenyNode
7834 .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7835 if ( !n22.getName().equals( "n22/PIG" ) ) {
7838 if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
7841 final PhylogenyNode n23 = PhylogenyNode
7842 .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7843 if ( !n23.getName().equals( "n23/PIG_1" ) ) {
7846 if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
7849 final PhylogenyNode a = PhylogenyNode
7850 .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7851 if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
7854 if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
7857 final PhylogenyNode c1 = PhylogenyNode
7858 .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
7859 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7860 if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
7863 if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
7866 final PhylogenyNode c2 = PhylogenyNode
7867 .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
7868 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7869 if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
7872 if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
7875 final PhylogenyNode e3 = PhylogenyNode
7876 .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7877 if ( !e3.getName().equals( "n10_RAT~" ) ) {
7880 if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
7883 final PhylogenyNode n11 = PhylogenyNode
7884 .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
7885 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7886 if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
7889 if ( n11.getDistanceToParent() != 0.4 ) {
7892 if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
7895 final PhylogenyNode n12 = PhylogenyNode
7896 .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
7897 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7898 if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
7901 if ( n12.getDistanceToParent() != 0.4 ) {
7904 if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
7907 final PhylogenyNode o = PhylogenyNode
7908 .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7909 if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
7912 if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
7915 if ( n1.getName().compareTo( "" ) != 0 ) {
7918 if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
7921 if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
7924 if ( n2.getName().compareTo( "" ) != 0 ) {
7927 if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
7930 if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
7933 final PhylogenyNode n00 = PhylogenyNode
7934 .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
7935 if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
7938 if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
7941 final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
7942 if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
7945 final PhylogenyNode n13 = PhylogenyNode
7946 .createInstanceFromNhxString( "blah_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
7947 if ( !n13.getName().equals( "blah_12345/1-2" ) ) {
7950 if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
7953 if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
7956 if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
7959 final PhylogenyNode n14 = PhylogenyNode
7960 .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7961 if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
7964 if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
7967 final PhylogenyNode n15 = PhylogenyNode
7968 .createInstanceFromNhxString( "something_wicked[123]",
7969 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7970 if ( !n15.getName().equals( "something_wicked" ) ) {
7973 if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
7976 if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
7979 final PhylogenyNode n16 = PhylogenyNode
7980 .createInstanceFromNhxString( "something_wicked2[9]",
7981 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7982 if ( !n16.getName().equals( "something_wicked2" ) ) {
7985 if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
7988 if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
7991 final PhylogenyNode n17 = PhylogenyNode
7992 .createInstanceFromNhxString( "something_wicked3[a]",
7993 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
7994 if ( !n17.getName().equals( "something_wicked3" ) ) {
7997 if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
8000 final PhylogenyNode n18 = PhylogenyNode
8001 .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8002 if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
8005 if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
8008 if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
8011 final PhylogenyNode n19 = PhylogenyNode
8012 .createInstanceFromNhxString( "blah_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8013 if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
8016 if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8019 final PhylogenyNode n30 = PhylogenyNode
8020 .createInstanceFromNhxString( "blah_1234567-roejojoej",
8021 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8022 if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
8025 if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
8028 final PhylogenyNode n31 = PhylogenyNode
8029 .createInstanceFromNhxString( "blah_12345678-roejojoej",
8030 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8031 if ( n31.getNodeData().isHasTaxonomy() ) {
8034 final PhylogenyNode n32 = PhylogenyNode
8035 .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8036 if ( n32.getNodeData().isHasTaxonomy() ) {
8039 final PhylogenyNode n40 = PhylogenyNode
8040 .createInstanceFromNhxString( "bcl2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8041 if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
8044 final PhylogenyNode n41 = PhylogenyNode
8045 .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8046 if ( n41.getNodeData().isHasTaxonomy() ) {
8049 final PhylogenyNode n42 = PhylogenyNode
8050 .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
8051 if ( n42.getNodeData().isHasTaxonomy() ) {
8054 final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
8055 NHXParser.TAXONOMY_EXTRACTION.NO );
8056 if ( n43.getNodeData().isHasTaxonomy() ) {
8059 final PhylogenyNode n44 = PhylogenyNode
8060 .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
8061 if ( n44.getNodeData().isHasTaxonomy() ) {
8065 catch ( final Exception e ) {
8066 e.printStackTrace( System.out );
8072 private static boolean testNHXParsing() {
8074 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8075 final Phylogeny p1 = factory.create( "(A [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
8076 if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
8079 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]";
8080 final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
8081 if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8084 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]";
8085 final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
8086 if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
8089 final Phylogeny[] p3 = factory
8090 .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]",
8092 if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8095 final Phylogeny[] p4 = factory
8096 .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(]",
8098 if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8101 final Phylogeny[] p5 = factory
8102 .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(((]",
8104 if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
8107 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)";
8108 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)";
8109 final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
8110 if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
8113 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)))";
8114 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)))";
8115 final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
8116 if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
8119 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]) ))[,,, ])))))))";
8120 final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
8121 final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
8122 if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
8125 final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
8126 if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
8129 final Phylogeny p10 = factory
8130 .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]",
8131 new NHXParser() )[ 0 ];
8132 if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
8136 catch ( final Exception e ) {
8137 e.printStackTrace( System.out );
8143 private static boolean testNHXParsingMB() {
8145 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8146 final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
8147 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8148 + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
8149 + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
8150 + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
8151 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8152 + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
8153 + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
8154 + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
8155 if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
8158 if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
8161 if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
8162 0.1100000000000000e+00 ) ) {
8165 if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
8168 if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
8171 final Phylogeny p2 = factory
8172 .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
8173 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8174 + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
8175 + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
8176 + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
8177 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
8178 + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
8179 + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
8180 + "7.369400000000000e-02}])",
8181 new NHXParser() )[ 0 ];
8182 if ( p2.getNode( "1" ) == null ) {
8185 if ( p2.getNode( "2" ) == null ) {
8189 catch ( final Exception e ) {
8190 e.printStackTrace( System.out );
8197 private static boolean testNHXParsingQuotes() {
8199 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8200 final NHXParser p = new NHXParser();
8201 final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
8202 if ( phylogenies_0.length != 5 ) {
8205 final Phylogeny phy = phylogenies_0[ 4 ];
8206 if ( phy.getNumberOfExternalNodes() != 7 ) {
8209 if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
8212 if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
8215 if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
8216 .getScientificName().equals( "hsapiens" ) ) {
8219 if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
8222 if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
8225 if ( phy.getNodes( "double quotes inside single quotes" ).size() != 1 ) {
8228 if ( phy.getNodes( "noquotes" ).size() != 1 ) {
8231 if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
8234 final NHXParser p1p = new NHXParser();
8235 p1p.setIgnoreQuotes( true );
8236 final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
8237 if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
8240 final NHXParser p2p = new NHXParser();
8241 p1p.setIgnoreQuotes( false );
8242 final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
8243 if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
8246 final NHXParser p3p = new NHXParser();
8247 p3p.setIgnoreQuotes( false );
8248 final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
8249 if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
8252 final NHXParser p4p = new NHXParser();
8253 p4p.setIgnoreQuotes( false );
8254 final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
8255 if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
8258 final Phylogeny p10 = factory
8259 .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]",
8260 new NHXParser() )[ 0 ];
8261 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]";
8262 if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
8265 final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
8266 if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
8270 final Phylogeny p12 = factory
8271 .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]",
8272 new NHXParser() )[ 0 ];
8273 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]";
8274 if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
8277 final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
8278 if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
8281 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;";
8282 if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
8285 final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
8286 if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
8290 catch ( final Exception e ) {
8291 e.printStackTrace( System.out );
8297 private static boolean testNodeRemoval() {
8299 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8300 final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
8301 PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
8302 if ( !t0.toNewHampshire().equals( "(a);" ) ) {
8305 final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
8306 PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
8307 if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
8310 final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
8311 PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
8312 if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
8316 catch ( final Exception e ) {
8317 e.printStackTrace( System.out );
8323 private static boolean testPhylogenyBranch() {
8325 final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
8326 final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
8327 final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
8328 final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
8329 if ( !a1b1.equals( a1b1 ) ) {
8332 if ( !a1b1.equals( b1a1 ) ) {
8335 if ( !b1a1.equals( a1b1 ) ) {
8338 final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
8339 final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
8340 final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
8341 if ( a1_b1.equals( b1_a1 ) ) {
8344 if ( a1_b1.equals( a1_b1_ ) ) {
8347 final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
8348 if ( !a1_b1.equals( b1_a1_ ) ) {
8351 if ( a1_b1_.equals( b1_a1_ ) ) {
8354 if ( !a1_b1_.equals( b1_a1 ) ) {
8358 catch ( final Exception e ) {
8359 e.printStackTrace( System.out );
8365 private static boolean testPhyloXMLparsingOfDistributionElement() {
8367 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8368 PhyloXmlParser xml_parser = null;
8370 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
8372 catch ( final Exception e ) {
8373 // Do nothing -- means were not running from jar.
8375 if ( xml_parser == null ) {
8376 xml_parser = new PhyloXmlParser();
8377 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
8378 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
8381 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
8384 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
8386 if ( xml_parser.getErrorCount() > 0 ) {
8387 System.out.println( xml_parser.getErrorMessages().toString() );
8390 if ( phylogenies_0.length != 1 ) {
8393 final Phylogeny t1 = phylogenies_0[ 0 ];
8394 PhylogenyNode n = null;
8395 Distribution d = null;
8396 n = t1.getNode( "root node" );
8397 if ( !n.getNodeData().isHasDistribution() ) {
8400 if ( n.getNodeData().getDistributions().size() != 1 ) {
8403 d = n.getNodeData().getDistribution();
8404 if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
8407 if ( d.getPoints().size() != 1 ) {
8410 if ( d.getPolygons() != null ) {
8413 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
8416 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8419 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8422 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
8425 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
8428 n = t1.getNode( "node a" );
8429 if ( !n.getNodeData().isHasDistribution() ) {
8432 if ( n.getNodeData().getDistributions().size() != 2 ) {
8435 d = n.getNodeData().getDistribution( 1 );
8436 if ( !d.getDesc().equals( "San Diego" ) ) {
8439 if ( d.getPoints().size() != 1 ) {
8442 if ( d.getPolygons() != null ) {
8445 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
8448 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8451 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8454 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
8457 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
8460 n = t1.getNode( "node bb" );
8461 if ( !n.getNodeData().isHasDistribution() ) {
8464 if ( n.getNodeData().getDistributions().size() != 1 ) {
8467 d = n.getNodeData().getDistribution( 0 );
8468 if ( d.getPoints().size() != 3 ) {
8471 if ( d.getPolygons().size() != 2 ) {
8474 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
8477 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
8480 if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
8483 if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
8486 if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
8489 if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
8492 Polygon p = d.getPolygons().get( 0 );
8493 if ( p.getPoints().size() != 3 ) {
8496 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
8499 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
8502 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8505 if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
8508 if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
8511 if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
8514 p = d.getPolygons().get( 1 );
8515 if ( p.getPoints().size() != 3 ) {
8518 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
8521 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
8524 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8528 final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
8529 final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
8530 if ( rt.length != 1 ) {
8533 final Phylogeny t1_rt = rt[ 0 ];
8534 n = t1_rt.getNode( "root node" );
8535 if ( !n.getNodeData().isHasDistribution() ) {
8538 if ( n.getNodeData().getDistributions().size() != 1 ) {
8541 d = n.getNodeData().getDistribution();
8542 if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
8545 if ( d.getPoints().size() != 1 ) {
8548 if ( d.getPolygons() != null ) {
8551 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
8554 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8557 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8560 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
8563 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
8566 n = t1_rt.getNode( "node a" );
8567 if ( !n.getNodeData().isHasDistribution() ) {
8570 if ( n.getNodeData().getDistributions().size() != 2 ) {
8573 d = n.getNodeData().getDistribution( 1 );
8574 if ( !d.getDesc().equals( "San Diego" ) ) {
8577 if ( d.getPoints().size() != 1 ) {
8580 if ( d.getPolygons() != null ) {
8583 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
8586 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
8589 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
8592 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
8595 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
8598 n = t1_rt.getNode( "node bb" );
8599 if ( !n.getNodeData().isHasDistribution() ) {
8602 if ( n.getNodeData().getDistributions().size() != 1 ) {
8605 d = n.getNodeData().getDistribution( 0 );
8606 if ( d.getPoints().size() != 3 ) {
8609 if ( d.getPolygons().size() != 2 ) {
8612 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
8615 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
8618 if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
8621 if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
8624 if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
8627 if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
8630 p = d.getPolygons().get( 0 );
8631 if ( p.getPoints().size() != 3 ) {
8634 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
8637 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
8640 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8643 if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
8646 if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
8649 if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
8652 p = d.getPolygons().get( 1 );
8653 if ( p.getPoints().size() != 3 ) {
8656 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
8659 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
8662 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
8666 catch ( final Exception e ) {
8667 e.printStackTrace( System.out );
8673 private static boolean testPostOrderIterator() {
8675 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8676 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
8677 PhylogenyNodeIterator it0;
8678 for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
8681 for( it0.reset(); it0.hasNext(); ) {
8684 final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
8685 final PhylogenyNodeIterator it = t1.iteratorPostorder();
8686 if ( !it.next().getName().equals( "A" ) ) {
8689 if ( !it.next().getName().equals( "B" ) ) {
8692 if ( !it.next().getName().equals( "ab" ) ) {
8695 if ( !it.next().getName().equals( "C" ) ) {
8698 if ( !it.next().getName().equals( "D" ) ) {
8701 if ( !it.next().getName().equals( "cd" ) ) {
8704 if ( !it.next().getName().equals( "abcd" ) ) {
8707 if ( !it.next().getName().equals( "E" ) ) {
8710 if ( !it.next().getName().equals( "F" ) ) {
8713 if ( !it.next().getName().equals( "ef" ) ) {
8716 if ( !it.next().getName().equals( "G" ) ) {
8719 if ( !it.next().getName().equals( "H" ) ) {
8722 if ( !it.next().getName().equals( "gh" ) ) {
8725 if ( !it.next().getName().equals( "efgh" ) ) {
8728 if ( !it.next().getName().equals( "r" ) ) {
8731 if ( it.hasNext() ) {
8735 catch ( final Exception e ) {
8736 e.printStackTrace( System.out );
8742 private static boolean testPreOrderIterator() {
8744 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8745 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
8746 PhylogenyNodeIterator it0;
8747 for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
8750 for( it0.reset(); it0.hasNext(); ) {
8753 PhylogenyNodeIterator it = t0.iteratorPreorder();
8754 if ( !it.next().getName().equals( "r" ) ) {
8757 if ( !it.next().getName().equals( "ab" ) ) {
8760 if ( !it.next().getName().equals( "A" ) ) {
8763 if ( !it.next().getName().equals( "B" ) ) {
8766 if ( !it.next().getName().equals( "cd" ) ) {
8769 if ( !it.next().getName().equals( "C" ) ) {
8772 if ( !it.next().getName().equals( "D" ) ) {
8775 if ( it.hasNext() ) {
8778 final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
8779 it = t1.iteratorPreorder();
8780 if ( !it.next().getName().equals( "r" ) ) {
8783 if ( !it.next().getName().equals( "abcd" ) ) {
8786 if ( !it.next().getName().equals( "ab" ) ) {
8789 if ( !it.next().getName().equals( "A" ) ) {
8792 if ( !it.next().getName().equals( "B" ) ) {
8795 if ( !it.next().getName().equals( "cd" ) ) {
8798 if ( !it.next().getName().equals( "C" ) ) {
8801 if ( !it.next().getName().equals( "D" ) ) {
8804 if ( !it.next().getName().equals( "efgh" ) ) {
8807 if ( !it.next().getName().equals( "ef" ) ) {
8810 if ( !it.next().getName().equals( "E" ) ) {
8813 if ( !it.next().getName().equals( "F" ) ) {
8816 if ( !it.next().getName().equals( "gh" ) ) {
8819 if ( !it.next().getName().equals( "G" ) ) {
8822 if ( !it.next().getName().equals( "H" ) ) {
8825 if ( it.hasNext() ) {
8829 catch ( final Exception e ) {
8830 e.printStackTrace( System.out );
8836 private static boolean testPropertiesMap() {
8838 final PropertiesMap pm = new PropertiesMap();
8839 final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
8840 final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
8841 final Property p2 = new Property( "something:else",
8843 "improbable:research",
8846 pm.addProperty( p0 );
8847 pm.addProperty( p1 );
8848 pm.addProperty( p2 );
8849 if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
8852 if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
8855 if ( pm.getProperties().size() != 3 ) {
8858 if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
8861 if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
8864 if ( pm.getProperties().size() != 3 ) {
8867 pm.removeProperty( "dimensions:diameter" );
8868 if ( pm.getProperties().size() != 2 ) {
8871 if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
8874 if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
8878 catch ( final Exception e ) {
8879 e.printStackTrace( System.out );
8885 private static boolean testProteinId() {
8887 final ProteinId id1 = new ProteinId( "a" );
8888 final ProteinId id2 = new ProteinId( "a" );
8889 final ProteinId id3 = new ProteinId( "A" );
8890 final ProteinId id4 = new ProteinId( "b" );
8891 if ( !id1.equals( id1 ) ) {
8894 if ( id1.getId().equals( "x" ) ) {
8897 if ( id1.getId().equals( null ) ) {
8900 if ( !id1.equals( id2 ) ) {
8903 if ( id1.equals( id3 ) ) {
8906 if ( id1.hashCode() != id1.hashCode() ) {
8909 if ( id1.hashCode() != id2.hashCode() ) {
8912 if ( id1.hashCode() == id3.hashCode() ) {
8915 if ( id1.compareTo( id1 ) != 0 ) {
8918 if ( id1.compareTo( id2 ) != 0 ) {
8921 if ( id1.compareTo( id3 ) != 0 ) {
8924 if ( id1.compareTo( id4 ) >= 0 ) {
8927 if ( id4.compareTo( id1 ) <= 0 ) {
8930 if ( !id4.getId().equals( "b" ) ) {
8933 final ProteinId id5 = new ProteinId( " C " );
8934 if ( !id5.getId().equals( "C" ) ) {
8937 if ( id5.equals( id1 ) ) {
8941 catch ( final Exception e ) {
8942 e.printStackTrace( System.out );
8948 private static boolean testReIdMethods() {
8950 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8951 final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
8952 final long count = PhylogenyNode.getNodeCount();
8954 if ( p.getNode( "r" ).getId() != count ) {
8957 if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
8960 if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
8963 if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
8966 if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
8969 if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
8972 if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
8975 if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
8978 if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
8981 if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
8984 if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
8987 if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
8990 if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
8993 if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
8996 if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
9000 catch ( final Exception e ) {
9001 e.printStackTrace( System.out );
9007 private static boolean testRerooting() {
9009 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9010 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",
9011 new NHXParser() )[ 0 ];
9012 if ( !t1.isRooted() ) {
9015 t1.reRoot( t1.getNode( "D" ) );
9016 t1.reRoot( t1.getNode( "CD" ) );
9017 t1.reRoot( t1.getNode( "A" ) );
9018 t1.reRoot( t1.getNode( "B" ) );
9019 t1.reRoot( t1.getNode( "AB" ) );
9020 t1.reRoot( t1.getNode( "D" ) );
9021 t1.reRoot( t1.getNode( "C" ) );
9022 t1.reRoot( t1.getNode( "CD" ) );
9023 t1.reRoot( t1.getNode( "A" ) );
9024 t1.reRoot( t1.getNode( "B" ) );
9025 t1.reRoot( t1.getNode( "AB" ) );
9026 t1.reRoot( t1.getNode( "D" ) );
9027 t1.reRoot( t1.getNode( "D" ) );
9028 t1.reRoot( t1.getNode( "C" ) );
9029 t1.reRoot( t1.getNode( "A" ) );
9030 t1.reRoot( t1.getNode( "B" ) );
9031 t1.reRoot( t1.getNode( "AB" ) );
9032 t1.reRoot( t1.getNode( "C" ) );
9033 t1.reRoot( t1.getNode( "D" ) );
9034 t1.reRoot( t1.getNode( "CD" ) );
9035 t1.reRoot( t1.getNode( "D" ) );
9036 t1.reRoot( t1.getNode( "A" ) );
9037 t1.reRoot( t1.getNode( "B" ) );
9038 t1.reRoot( t1.getNode( "AB" ) );
9039 t1.reRoot( t1.getNode( "C" ) );
9040 t1.reRoot( t1.getNode( "D" ) );
9041 t1.reRoot( t1.getNode( "CD" ) );
9042 t1.reRoot( t1.getNode( "D" ) );
9043 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
9046 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
9049 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
9052 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
9055 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
9058 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
9061 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",
9062 new NHXParser() )[ 0 ];
9063 t2.reRoot( t2.getNode( "A" ) );
9064 t2.reRoot( t2.getNode( "D" ) );
9065 t2.reRoot( t2.getNode( "ABC" ) );
9066 t2.reRoot( t2.getNode( "A" ) );
9067 t2.reRoot( t2.getNode( "B" ) );
9068 t2.reRoot( t2.getNode( "D" ) );
9069 t2.reRoot( t2.getNode( "C" ) );
9070 t2.reRoot( t2.getNode( "ABC" ) );
9071 t2.reRoot( t2.getNode( "A" ) );
9072 t2.reRoot( t2.getNode( "B" ) );
9073 t2.reRoot( t2.getNode( "AB" ) );
9074 t2.reRoot( t2.getNode( "AB" ) );
9075 t2.reRoot( t2.getNode( "D" ) );
9076 t2.reRoot( t2.getNode( "C" ) );
9077 t2.reRoot( t2.getNode( "B" ) );
9078 t2.reRoot( t2.getNode( "AB" ) );
9079 t2.reRoot( t2.getNode( "D" ) );
9080 t2.reRoot( t2.getNode( "D" ) );
9081 t2.reRoot( t2.getNode( "ABC" ) );
9082 t2.reRoot( t2.getNode( "A" ) );
9083 t2.reRoot( t2.getNode( "B" ) );
9084 t2.reRoot( t2.getNode( "AB" ) );
9085 t2.reRoot( t2.getNode( "D" ) );
9086 t2.reRoot( t2.getNode( "C" ) );
9087 t2.reRoot( t2.getNode( "ABC" ) );
9088 t2.reRoot( t2.getNode( "A" ) );
9089 t2.reRoot( t2.getNode( "B" ) );
9090 t2.reRoot( t2.getNode( "AB" ) );
9091 t2.reRoot( t2.getNode( "D" ) );
9092 t2.reRoot( t2.getNode( "D" ) );
9093 t2.reRoot( t2.getNode( "C" ) );
9094 t2.reRoot( t2.getNode( "A" ) );
9095 t2.reRoot( t2.getNode( "B" ) );
9096 t2.reRoot( t2.getNode( "AB" ) );
9097 t2.reRoot( t2.getNode( "C" ) );
9098 t2.reRoot( t2.getNode( "D" ) );
9099 t2.reRoot( t2.getNode( "ABC" ) );
9100 t2.reRoot( t2.getNode( "D" ) );
9101 t2.reRoot( t2.getNode( "A" ) );
9102 t2.reRoot( t2.getNode( "B" ) );
9103 t2.reRoot( t2.getNode( "AB" ) );
9104 t2.reRoot( t2.getNode( "C" ) );
9105 t2.reRoot( t2.getNode( "D" ) );
9106 t2.reRoot( t2.getNode( "ABC" ) );
9107 t2.reRoot( t2.getNode( "D" ) );
9108 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9111 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9114 t2.reRoot( t2.getNode( "ABC" ) );
9115 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9118 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9121 t2.reRoot( t2.getNode( "AB" ) );
9122 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9125 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9128 if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9131 t2.reRoot( t2.getNode( "AB" ) );
9132 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9135 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9138 if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9141 t2.reRoot( t2.getNode( "D" ) );
9142 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9145 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9148 t2.reRoot( t2.getNode( "ABC" ) );
9149 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
9152 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
9155 final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
9156 new NHXParser() )[ 0 ];
9157 t3.reRoot( t3.getNode( "B" ) );
9158 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9161 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9164 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9167 t3.reRoot( t3.getNode( "B" ) );
9168 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9171 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9174 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9177 t3.reRoot( t3.getRoot() );
9178 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9181 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
9184 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
9188 catch ( final Exception e ) {
9189 e.printStackTrace( System.out );
9195 private static boolean testSDIse() {
9197 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9198 final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
9199 final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
9200 gene1.setRooted( true );
9201 species1.setRooted( true );
9202 final SDI sdi = new SDI( gene1, species1 );
9203 if ( !gene1.getRoot().isDuplication() ) {
9206 final Phylogeny species2 = factory
9207 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9208 new NHXParser() )[ 0 ];
9209 final Phylogeny gene2 = factory
9210 .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9211 new NHXParser() )[ 0 ];
9212 species2.setRooted( true );
9213 gene2.setRooted( true );
9214 final SDI sdi2 = new SDI( gene2, species2 );
9215 if ( sdi2.getDuplicationsSum() != 0 ) {
9218 if ( !gene2.getNode( "ab" ).isSpeciation() ) {
9221 if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
9224 if ( !gene2.getNode( "abc" ).isSpeciation() ) {
9227 if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
9230 if ( !gene2.getNode( "r" ).isSpeciation() ) {
9233 if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
9236 final Phylogeny species3 = factory
9237 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9238 new NHXParser() )[ 0 ];
9239 final Phylogeny gene3 = factory
9240 .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9241 new NHXParser() )[ 0 ];
9242 species3.setRooted( true );
9243 gene3.setRooted( true );
9244 final SDI sdi3 = new SDI( gene3, species3 );
9245 if ( sdi3.getDuplicationsSum() != 1 ) {
9248 if ( !gene3.getNode( "aa" ).isDuplication() ) {
9251 if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
9254 final Phylogeny species4 = factory
9255 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9256 new NHXParser() )[ 0 ];
9257 final Phylogeny gene4 = factory
9258 .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9259 new NHXParser() )[ 0 ];
9260 species4.setRooted( true );
9261 gene4.setRooted( true );
9262 final SDI sdi4 = new SDI( gene4, species4 );
9263 if ( sdi4.getDuplicationsSum() != 1 ) {
9266 if ( !gene4.getNode( "ac" ).isSpeciation() ) {
9269 if ( !gene4.getNode( "abc" ).isDuplication() ) {
9272 if ( gene4.getNode( "abcd" ).isDuplication() ) {
9275 if ( species4.getNumberOfExternalNodes() != 6 ) {
9278 if ( gene4.getNumberOfExternalNodes() != 6 ) {
9281 final Phylogeny species5 = factory
9282 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9283 new NHXParser() )[ 0 ];
9284 final Phylogeny gene5 = factory
9285 .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
9286 new NHXParser() )[ 0 ];
9287 species5.setRooted( true );
9288 gene5.setRooted( true );
9289 final SDI sdi5 = new SDI( gene5, species5 );
9290 if ( sdi5.getDuplicationsSum() != 2 ) {
9293 if ( !gene5.getNode( "ad" ).isSpeciation() ) {
9296 if ( !gene5.getNode( "adc" ).isDuplication() ) {
9299 if ( !gene5.getNode( "abcd" ).isDuplication() ) {
9302 if ( species5.getNumberOfExternalNodes() != 6 ) {
9305 if ( gene5.getNumberOfExternalNodes() != 6 ) {
9308 // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
9309 // Conjecture for Comparing Molecular Phylogenies"
9310 // J. of Comput Bio. Vol. 4, No 2, pp.177-187
9311 final Phylogeny species6 = factory
9312 .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,"
9313 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9314 new NHXParser() )[ 0 ];
9315 final Phylogeny gene6 = factory
9316 .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,"
9317 + "((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,"
9318 + "(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;",
9319 new NHXParser() )[ 0 ];
9320 species6.setRooted( true );
9321 gene6.setRooted( true );
9322 final SDI sdi6 = new SDI( gene6, species6 );
9323 if ( sdi6.getDuplicationsSum() != 3 ) {
9326 if ( !gene6.getNode( "r" ).isDuplication() ) {
9329 if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
9332 if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
9335 if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
9338 if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
9341 if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
9344 if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
9347 if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
9350 sdi6.computeMappingCostL();
9351 if ( sdi6.computeMappingCostL() != 17 ) {
9354 if ( species6.getNumberOfExternalNodes() != 9 ) {
9357 if ( gene6.getNumberOfExternalNodes() != 9 ) {
9360 final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
9361 + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
9362 + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
9363 + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
9364 + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
9365 species7.setRooted( true );
9366 final Phylogeny gene7_1 = Test
9367 .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])" );
9368 gene7_1.setRooted( true );
9369 final SDI sdi7 = new SDI( gene7_1, species7 );
9370 if ( sdi7.getDuplicationsSum() != 0 ) {
9373 if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
9376 if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
9379 if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
9382 if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
9385 if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
9388 if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
9391 if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
9394 if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
9397 final Phylogeny gene7_2 = Test
9398 .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])" );
9399 gene7_2.setRooted( true );
9400 final SDI sdi7_2 = new SDI( gene7_2, species7 );
9401 if ( sdi7_2.getDuplicationsSum() != 1 ) {
9404 if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
9407 if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
9410 if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
9413 if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
9416 if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
9419 if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
9422 if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
9425 if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
9428 if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
9432 catch ( final Exception e ) {
9438 private static boolean testSDIunrooted() {
9440 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9441 final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
9442 final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
9443 final Iterator<PhylogenyBranch> iter = l.iterator();
9444 PhylogenyBranch br = iter.next();
9445 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
9448 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
9452 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
9455 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
9459 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
9462 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
9466 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9469 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9473 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9476 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9480 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
9483 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
9487 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9490 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9494 if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9497 if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9501 if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9504 if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9508 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
9511 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
9515 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
9518 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
9522 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
9525 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
9529 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
9532 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
9536 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
9539 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
9543 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
9546 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
9549 if ( iter.hasNext() ) {
9552 final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
9553 final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
9554 final Iterator<PhylogenyBranch> iter1 = l1.iterator();
9556 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
9559 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
9563 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9566 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9570 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9573 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9576 if ( iter1.hasNext() ) {
9579 final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
9580 final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
9581 final Iterator<PhylogenyBranch> iter2 = l2.iterator();
9583 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
9586 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
9590 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
9593 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
9597 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
9600 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
9603 if ( iter2.hasNext() ) {
9606 final Phylogeny species0 = factory
9607 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
9608 new NHXParser() )[ 0 ];
9609 final Phylogeny gene1 = factory
9610 .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])",
9611 new NHXParser() )[ 0 ];
9612 species0.setRooted( true );
9613 gene1.setRooted( true );
9614 final SDIR sdi_unrooted = new SDIR();
9615 sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
9616 if ( sdi_unrooted.getCount() != 1 ) {
9619 if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
9622 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
9625 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
9628 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9631 final Phylogeny gene2 = factory
9632 .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])",
9633 new NHXParser() )[ 0 ];
9634 gene2.setRooted( true );
9635 sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
9636 if ( sdi_unrooted.getCount() != 1 ) {
9639 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9642 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9645 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
9648 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9651 final Phylogeny species6 = factory
9652 .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,"
9653 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9654 new NHXParser() )[ 0 ];
9655 final Phylogeny gene6 = factory
9656 .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],"
9657 + "(((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],"
9658 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
9659 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
9660 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
9661 new NHXParser() )[ 0 ];
9662 species6.setRooted( true );
9663 gene6.setRooted( true );
9664 Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
9665 if ( sdi_unrooted.getCount() != 1 ) {
9668 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9671 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
9674 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9677 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9680 if ( !p6[ 0 ].getRoot().isDuplication() ) {
9683 if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
9686 if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
9689 if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
9692 if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
9695 if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
9698 if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
9701 if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
9705 final Phylogeny species7 = factory
9706 .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,"
9707 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9708 new NHXParser() )[ 0 ];
9709 final Phylogeny gene7 = factory
9710 .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],"
9711 + "(((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],"
9712 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
9713 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
9714 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
9715 new NHXParser() )[ 0 ];
9716 species7.setRooted( true );
9717 gene7.setRooted( true );
9718 Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
9719 if ( sdi_unrooted.getCount() != 1 ) {
9722 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9725 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
9728 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9731 if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
9734 if ( !p7[ 0 ].getRoot().isDuplication() ) {
9737 if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
9740 if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
9743 if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
9746 if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
9749 if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
9752 if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
9755 if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
9759 final Phylogeny species8 = factory
9760 .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,"
9761 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
9762 new NHXParser() )[ 0 ];
9763 final Phylogeny gene8 = factory
9764 .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],"
9765 + "(((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],"
9766 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
9767 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
9768 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
9769 new NHXParser() )[ 0 ];
9770 species8.setRooted( true );
9771 gene8.setRooted( true );
9772 Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
9773 if ( sdi_unrooted.getCount() != 1 ) {
9776 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
9779 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
9782 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
9785 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
9788 if ( !p8[ 0 ].getRoot().isDuplication() ) {
9791 if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
9794 if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
9797 if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
9800 if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
9803 if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
9806 if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
9809 if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
9814 catch ( final Exception e ) {
9815 e.printStackTrace( System.out );
9821 private static boolean testSequenceIdParsing() {
9823 Identifier id = SequenceIdParser.parse( "gb_ADF31344_segmented_worms_" );
9824 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9825 || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
9827 System.out.println( "value =" + id.getValue() );
9828 System.out.println( "provider=" + id.getProvider() );
9833 id = SequenceIdParser.parse( "segmented worms|gb_ADF31344" );
9834 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9835 || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
9837 System.out.println( "value =" + id.getValue() );
9838 System.out.println( "provider=" + id.getProvider() );
9843 id = SequenceIdParser.parse( "segmented worms gb_ADF31344 and more" );
9844 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9845 || !id.getValue().equals( "ADF31344" ) || !id.getProvider().equals( "ncbi" ) ) {
9847 System.out.println( "value =" + id.getValue() );
9848 System.out.println( "provider=" + id.getProvider() );
9853 id = SequenceIdParser.parse( "gb_AAA96518_1" );
9854 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9855 || !id.getValue().equals( "AAA96518" ) || !id.getProvider().equals( "ncbi" ) ) {
9857 System.out.println( "value =" + id.getValue() );
9858 System.out.println( "provider=" + id.getProvider() );
9863 id = SequenceIdParser.parse( "gb_EHB07727_1_rodents_" );
9864 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9865 || !id.getValue().equals( "EHB07727" ) || !id.getProvider().equals( "ncbi" ) ) {
9867 System.out.println( "value =" + id.getValue() );
9868 System.out.println( "provider=" + id.getProvider() );
9873 id = SequenceIdParser.parse( "dbj_BAF37827_1_turtles_" );
9874 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9875 || !id.getValue().equals( "BAF37827" ) || !id.getProvider().equals( "ncbi" ) ) {
9877 System.out.println( "value =" + id.getValue() );
9878 System.out.println( "provider=" + id.getProvider() );
9883 id = SequenceIdParser.parse( "emb_CAA73223_1_primates_" );
9884 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9885 || !id.getValue().equals( "CAA73223" ) || !id.getProvider().equals( "ncbi" ) ) {
9887 System.out.println( "value =" + id.getValue() );
9888 System.out.println( "provider=" + id.getProvider() );
9893 id = SequenceIdParser.parse( "mites|ref_XP_002434188_1" );
9894 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9895 || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
9897 System.out.println( "value =" + id.getValue() );
9898 System.out.println( "provider=" + id.getProvider() );
9903 id = SequenceIdParser.parse( "mites_ref_XP_002434188_1_bla_XP_12345" );
9904 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9905 || !id.getValue().equals( "XP_002434188" ) || !id.getProvider().equals( "refseq" ) ) {
9907 System.out.println( "value =" + id.getValue() );
9908 System.out.println( "provider=" + id.getProvider() );
9913 id = SequenceIdParser.parse( "P4A123" );
9914 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9915 || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
9917 System.out.println( "value =" + id.getValue() );
9918 System.out.println( "provider=" + id.getProvider() );
9923 id = SequenceIdParser.parse( "pllf[pok P4A123_osdjfosnqo035-9233332904i000490 vf tmv x45" );
9924 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getProvider() )
9925 || !id.getValue().equals( "P4A123" ) || !id.getProvider().equals( "sp" ) ) {
9927 System.out.println( "value =" + id.getValue() );
9928 System.out.println( "provider=" + id.getProvider() );
9933 id = SequenceIdParser.parse( "XP_12345" );
9935 System.out.println( "value =" + id.getValue() );
9936 System.out.println( "provider=" + id.getProvider() );
9939 // lcl_91970_unknown_
9941 catch ( final Exception e ) {
9942 e.printStackTrace( System.out );
9948 private static boolean testSequenceWriter() {
9950 final String n = ForesterUtil.LINE_SEPARATOR;
9951 if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
9954 if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
9957 if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
9960 if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
9963 if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
9964 .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
9967 if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
9968 .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
9972 catch ( final Exception e ) {
9973 e.printStackTrace();
9979 private static boolean testSpecies() {
9981 final Species s1 = new BasicSpecies( "a" );
9982 final Species s2 = new BasicSpecies( "a" );
9983 final Species s3 = new BasicSpecies( "A" );
9984 final Species s4 = new BasicSpecies( "b" );
9985 if ( !s1.equals( s1 ) ) {
9988 if ( s1.getSpeciesId().equals( "x" ) ) {
9991 if ( s1.getSpeciesId().equals( null ) ) {
9994 if ( !s1.equals( s2 ) ) {
9997 if ( s1.equals( s3 ) ) {
10000 if ( s1.hashCode() != s1.hashCode() ) {
10003 if ( s1.hashCode() != s2.hashCode() ) {
10006 if ( s1.hashCode() == s3.hashCode() ) {
10009 if ( s1.compareTo( s1 ) != 0 ) {
10012 if ( s1.compareTo( s2 ) != 0 ) {
10015 if ( s1.compareTo( s3 ) != 0 ) {
10018 if ( s1.compareTo( s4 ) >= 0 ) {
10021 if ( s4.compareTo( s1 ) <= 0 ) {
10024 if ( !s4.getSpeciesId().equals( "b" ) ) {
10027 final Species s5 = new BasicSpecies( " C " );
10028 if ( !s5.getSpeciesId().equals( "C" ) ) {
10031 if ( s5.equals( s1 ) ) {
10035 catch ( final Exception e ) {
10036 e.printStackTrace( System.out );
10042 private static boolean testSplit() {
10044 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10045 final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
10046 //Archaeopteryx.createApplication( p0 );
10047 final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
10048 ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10049 ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10050 ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10051 ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10052 ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10053 ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10054 ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10055 ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10056 ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10057 final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
10058 // System.out.println( s0.toString() );
10060 Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
10061 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10062 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10063 if ( s0.match( query_nodes ) ) {
10066 query_nodes = new HashSet<PhylogenyNode>();
10067 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10068 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10069 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10070 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10071 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10072 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10073 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10074 if ( !s0.match( query_nodes ) ) {
10078 query_nodes = new HashSet<PhylogenyNode>();
10079 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10080 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10081 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10082 if ( !s0.match( query_nodes ) ) {
10086 query_nodes = new HashSet<PhylogenyNode>();
10087 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10088 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10089 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10090 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10091 if ( !s0.match( query_nodes ) ) {
10095 query_nodes = new HashSet<PhylogenyNode>();
10096 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10097 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10098 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10099 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10100 if ( !s0.match( query_nodes ) ) {
10104 query_nodes = new HashSet<PhylogenyNode>();
10105 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10106 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10107 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10108 if ( !s0.match( query_nodes ) ) {
10112 query_nodes = new HashSet<PhylogenyNode>();
10113 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10114 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10115 if ( !s0.match( query_nodes ) ) {
10119 query_nodes = new HashSet<PhylogenyNode>();
10120 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10121 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10122 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10123 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10124 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10125 if ( !s0.match( query_nodes ) ) {
10129 query_nodes = new HashSet<PhylogenyNode>();
10130 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10131 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10132 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10133 if ( !s0.match( query_nodes ) ) {
10137 query_nodes = new HashSet<PhylogenyNode>();
10138 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10139 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10140 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10141 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10142 if ( !s0.match( query_nodes ) ) {
10146 query_nodes = new HashSet<PhylogenyNode>();
10147 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10148 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10149 if ( s0.match( query_nodes ) ) {
10153 query_nodes = new HashSet<PhylogenyNode>();
10154 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10155 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10156 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10157 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10158 if ( s0.match( query_nodes ) ) {
10162 query_nodes = new HashSet<PhylogenyNode>();
10163 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10164 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10165 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10166 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10167 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10168 if ( s0.match( query_nodes ) ) {
10172 query_nodes = new HashSet<PhylogenyNode>();
10173 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10174 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10175 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10176 if ( s0.match( query_nodes ) ) {
10180 query_nodes = new HashSet<PhylogenyNode>();
10181 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10182 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10183 if ( s0.match( query_nodes ) ) {
10187 query_nodes = new HashSet<PhylogenyNode>();
10188 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10189 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10190 if ( s0.match( query_nodes ) ) {
10194 query_nodes = new HashSet<PhylogenyNode>();
10195 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10196 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10197 if ( s0.match( query_nodes ) ) {
10201 query_nodes = new HashSet<PhylogenyNode>();
10202 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10203 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10204 if ( s0.match( query_nodes ) ) {
10208 query_nodes = new HashSet<PhylogenyNode>();
10209 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10210 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10211 if ( s0.match( query_nodes ) ) {
10215 query_nodes = new HashSet<PhylogenyNode>();
10216 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10217 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10218 if ( s0.match( query_nodes ) ) {
10222 query_nodes = new HashSet<PhylogenyNode>();
10223 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10224 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10225 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10226 if ( s0.match( query_nodes ) ) {
10230 query_nodes = new HashSet<PhylogenyNode>();
10231 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10232 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10233 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10234 if ( s0.match( query_nodes ) ) {
10238 query_nodes = new HashSet<PhylogenyNode>();
10239 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10240 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10241 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10242 if ( s0.match( query_nodes ) ) {
10246 query_nodes = new HashSet<PhylogenyNode>();
10247 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10248 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10249 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10250 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10251 if ( s0.match( query_nodes ) ) {
10255 // query_nodes = new HashSet<PhylogenyNode>();
10256 // query_nodes.add( new PhylogenyNode( "X" ) );
10257 // query_nodes.add( new PhylogenyNode( "Y" ) );
10258 // query_nodes.add( new PhylogenyNode( "A" ) );
10259 // query_nodes.add( new PhylogenyNode( "B" ) );
10260 // query_nodes.add( new PhylogenyNode( "C" ) );
10261 // query_nodes.add( new PhylogenyNode( "D" ) );
10262 // query_nodes.add( new PhylogenyNode( "E" ) );
10263 // query_nodes.add( new PhylogenyNode( "F" ) );
10264 // query_nodes.add( new PhylogenyNode( "G" ) );
10265 // if ( !s0.match( query_nodes ) ) {
10268 // query_nodes = new HashSet<PhylogenyNode>();
10269 // query_nodes.add( new PhylogenyNode( "X" ) );
10270 // query_nodes.add( new PhylogenyNode( "Y" ) );
10271 // query_nodes.add( new PhylogenyNode( "A" ) );
10272 // query_nodes.add( new PhylogenyNode( "B" ) );
10273 // query_nodes.add( new PhylogenyNode( "C" ) );
10274 // if ( !s0.match( query_nodes ) ) {
10278 // query_nodes = new HashSet<PhylogenyNode>();
10279 // query_nodes.add( new PhylogenyNode( "X" ) );
10280 // query_nodes.add( new PhylogenyNode( "Y" ) );
10281 // query_nodes.add( new PhylogenyNode( "D" ) );
10282 // query_nodes.add( new PhylogenyNode( "E" ) );
10283 // query_nodes.add( new PhylogenyNode( "F" ) );
10284 // query_nodes.add( new PhylogenyNode( "G" ) );
10285 // if ( !s0.match( query_nodes ) ) {
10289 // query_nodes = new HashSet<PhylogenyNode>();
10290 // query_nodes.add( new PhylogenyNode( "X" ) );
10291 // query_nodes.add( new PhylogenyNode( "Y" ) );
10292 // query_nodes.add( new PhylogenyNode( "A" ) );
10293 // query_nodes.add( new PhylogenyNode( "B" ) );
10294 // query_nodes.add( new PhylogenyNode( "C" ) );
10295 // query_nodes.add( new PhylogenyNode( "D" ) );
10296 // if ( !s0.match( query_nodes ) ) {
10300 // query_nodes = new HashSet<PhylogenyNode>();
10301 // query_nodes.add( new PhylogenyNode( "X" ) );
10302 // query_nodes.add( new PhylogenyNode( "Y" ) );
10303 // query_nodes.add( new PhylogenyNode( "E" ) );
10304 // query_nodes.add( new PhylogenyNode( "F" ) );
10305 // query_nodes.add( new PhylogenyNode( "G" ) );
10306 // if ( !s0.match( query_nodes ) ) {
10310 // query_nodes = new HashSet<PhylogenyNode>();
10311 // query_nodes.add( new PhylogenyNode( "X" ) );
10312 // query_nodes.add( new PhylogenyNode( "Y" ) );
10313 // query_nodes.add( new PhylogenyNode( "F" ) );
10314 // query_nodes.add( new PhylogenyNode( "G" ) );
10315 // if ( !s0.match( query_nodes ) ) {
10319 query_nodes = new HashSet<PhylogenyNode>();
10320 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10321 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10322 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10323 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10324 if ( s0.match( query_nodes ) ) {
10328 query_nodes = new HashSet<PhylogenyNode>();
10329 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10330 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10331 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10332 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10333 if ( s0.match( query_nodes ) ) {
10336 ///////////////////////////
10338 query_nodes = new HashSet<PhylogenyNode>();
10339 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10340 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10341 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10342 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10343 if ( s0.match( query_nodes ) ) {
10347 query_nodes = new HashSet<PhylogenyNode>();
10348 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10349 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10350 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10351 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10352 if ( s0.match( query_nodes ) ) {
10356 query_nodes = new HashSet<PhylogenyNode>();
10357 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10358 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10359 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10360 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10361 if ( s0.match( query_nodes ) ) {
10365 query_nodes = new HashSet<PhylogenyNode>();
10366 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10367 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10368 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10369 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10370 if ( s0.match( query_nodes ) ) {
10374 query_nodes = new HashSet<PhylogenyNode>();
10375 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10376 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10377 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10378 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10379 if ( s0.match( query_nodes ) ) {
10383 query_nodes = new HashSet<PhylogenyNode>();
10384 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10385 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10386 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10387 if ( s0.match( query_nodes ) ) {
10391 query_nodes = new HashSet<PhylogenyNode>();
10392 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10393 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10394 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10395 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10396 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10397 if ( s0.match( query_nodes ) ) {
10401 query_nodes = new HashSet<PhylogenyNode>();
10402 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10403 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10404 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10405 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10406 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10407 if ( s0.match( query_nodes ) ) {
10411 query_nodes = new HashSet<PhylogenyNode>();
10412 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10413 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10414 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10415 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10416 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10417 if ( s0.match( query_nodes ) ) {
10421 query_nodes = new HashSet<PhylogenyNode>();
10422 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
10423 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
10424 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10425 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10426 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10427 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10428 if ( s0.match( query_nodes ) ) {
10432 catch ( final Exception e ) {
10433 e.printStackTrace();
10439 private static boolean testSplitStrict() {
10441 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10442 final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
10443 final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
10444 ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10445 ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10446 ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10447 ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10448 ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10449 ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10450 ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10451 final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
10452 Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
10453 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10454 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10455 if ( s0.match( query_nodes ) ) {
10458 query_nodes = new HashSet<PhylogenyNode>();
10459 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10460 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10461 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10462 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10463 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10464 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10465 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10466 if ( !s0.match( query_nodes ) ) {
10470 query_nodes = new HashSet<PhylogenyNode>();
10471 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10472 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10473 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10474 if ( !s0.match( query_nodes ) ) {
10478 query_nodes = new HashSet<PhylogenyNode>();
10479 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10480 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10481 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10482 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10483 if ( !s0.match( query_nodes ) ) {
10487 query_nodes = new HashSet<PhylogenyNode>();
10488 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10489 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10490 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10491 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10492 if ( !s0.match( query_nodes ) ) {
10496 query_nodes = new HashSet<PhylogenyNode>();
10497 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10498 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10499 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10500 if ( !s0.match( query_nodes ) ) {
10504 query_nodes = new HashSet<PhylogenyNode>();
10505 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10506 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10507 if ( !s0.match( query_nodes ) ) {
10511 query_nodes = new HashSet<PhylogenyNode>();
10512 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10513 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10514 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10515 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10516 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10517 if ( !s0.match( query_nodes ) ) {
10521 query_nodes = new HashSet<PhylogenyNode>();
10522 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10523 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10524 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10525 if ( !s0.match( query_nodes ) ) {
10529 query_nodes = new HashSet<PhylogenyNode>();
10530 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10531 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10532 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10533 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10534 if ( !s0.match( query_nodes ) ) {
10538 query_nodes = new HashSet<PhylogenyNode>();
10539 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10540 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10541 if ( s0.match( query_nodes ) ) {
10545 query_nodes = new HashSet<PhylogenyNode>();
10546 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10547 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10548 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10549 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10550 if ( s0.match( query_nodes ) ) {
10554 query_nodes = new HashSet<PhylogenyNode>();
10555 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10556 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10557 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10558 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10559 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10560 if ( s0.match( query_nodes ) ) {
10564 query_nodes = new HashSet<PhylogenyNode>();
10565 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10566 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10567 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10568 if ( s0.match( query_nodes ) ) {
10572 query_nodes = new HashSet<PhylogenyNode>();
10573 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10574 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10575 if ( s0.match( query_nodes ) ) {
10579 query_nodes = new HashSet<PhylogenyNode>();
10580 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10581 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10582 if ( s0.match( query_nodes ) ) {
10586 query_nodes = new HashSet<PhylogenyNode>();
10587 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10588 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
10589 if ( s0.match( query_nodes ) ) {
10593 query_nodes = new HashSet<PhylogenyNode>();
10594 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10595 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10596 if ( s0.match( query_nodes ) ) {
10600 query_nodes = new HashSet<PhylogenyNode>();
10601 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10602 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10603 if ( s0.match( query_nodes ) ) {
10607 query_nodes = new HashSet<PhylogenyNode>();
10608 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10609 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10610 if ( s0.match( query_nodes ) ) {
10614 query_nodes = new HashSet<PhylogenyNode>();
10615 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10616 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
10617 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10618 if ( s0.match( query_nodes ) ) {
10622 query_nodes = new HashSet<PhylogenyNode>();
10623 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10624 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
10625 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10626 if ( s0.match( query_nodes ) ) {
10630 query_nodes = new HashSet<PhylogenyNode>();
10631 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10632 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10633 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10634 if ( s0.match( query_nodes ) ) {
10638 query_nodes = new HashSet<PhylogenyNode>();
10639 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
10640 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
10641 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
10642 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
10643 if ( s0.match( query_nodes ) ) {
10647 catch ( final Exception e ) {
10648 e.printStackTrace();
10654 private static boolean testSubtreeDeletion() {
10656 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10657 final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
10658 t1.deleteSubtree( t1.getNode( "A" ), false );
10659 if ( t1.getNumberOfExternalNodes() != 5 ) {
10662 t1.toNewHampshireX();
10663 t1.deleteSubtree( t1.getNode( "E" ), false );
10664 if ( t1.getNumberOfExternalNodes() != 4 ) {
10667 t1.toNewHampshireX();
10668 t1.deleteSubtree( t1.getNode( "F" ), false );
10669 if ( t1.getNumberOfExternalNodes() != 3 ) {
10672 t1.toNewHampshireX();
10673 t1.deleteSubtree( t1.getNode( "D" ), false );
10674 t1.toNewHampshireX();
10675 if ( t1.getNumberOfExternalNodes() != 3 ) {
10678 t1.deleteSubtree( t1.getNode( "def" ), false );
10679 t1.toNewHampshireX();
10680 if ( t1.getNumberOfExternalNodes() != 2 ) {
10683 t1.deleteSubtree( t1.getNode( "B" ), false );
10684 t1.toNewHampshireX();
10685 if ( t1.getNumberOfExternalNodes() != 1 ) {
10688 t1.deleteSubtree( t1.getNode( "C" ), false );
10689 t1.toNewHampshireX();
10690 if ( t1.getNumberOfExternalNodes() != 1 ) {
10693 t1.deleteSubtree( t1.getNode( "abc" ), false );
10694 t1.toNewHampshireX();
10695 if ( t1.getNumberOfExternalNodes() != 1 ) {
10698 t1.deleteSubtree( t1.getNode( "r" ), false );
10699 if ( t1.getNumberOfExternalNodes() != 0 ) {
10702 if ( !t1.isEmpty() ) {
10705 final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
10706 t2.deleteSubtree( t2.getNode( "A" ), false );
10707 t2.toNewHampshireX();
10708 if ( t2.getNumberOfExternalNodes() != 5 ) {
10711 t2.deleteSubtree( t2.getNode( "abc" ), false );
10712 t2.toNewHampshireX();
10713 if ( t2.getNumberOfExternalNodes() != 3 ) {
10716 t2.deleteSubtree( t2.getNode( "def" ), false );
10717 t2.toNewHampshireX();
10718 if ( t2.getNumberOfExternalNodes() != 1 ) {
10722 catch ( final Exception e ) {
10723 e.printStackTrace( System.out );
10729 private static boolean testSupportCount() {
10731 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10732 final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
10733 final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
10734 + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
10735 + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
10736 + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
10737 + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
10739 SupportCount.count( t0_1, phylogenies_1, true, false );
10740 final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
10741 final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
10742 + "(((((A,B),C),D),E),((F,G),X))"
10743 + "(((((A,Y),B),C),D),((F,G),E))"
10744 + "(((((A,B),C),D),E),(F,G))"
10745 + "(((((A,B),C),D),E),(F,G))"
10746 + "(((((A,B),C),D),E),(F,G))"
10747 + "(((((A,B),C),D),E),(F,G),Z)"
10748 + "(((((A,B),C),D),E),(F,G))"
10749 + "((((((A,B),C),D),E),F),G)"
10750 + "(((((X,Y),F,G),E),((A,B),C)),D)",
10752 SupportCount.count( t0_2, phylogenies_2, true, false );
10753 final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
10754 while ( it.hasNext() ) {
10755 final PhylogenyNode n = it.next();
10756 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
10760 final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
10761 final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
10762 + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
10763 SupportCount.count( t0_3, phylogenies_3, true, false );
10764 t0_3.reRoot( t0_3.getNode( "def" ).getId() );
10765 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
10768 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
10771 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
10774 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
10777 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
10780 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
10783 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
10786 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
10789 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
10792 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
10795 final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10796 final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
10797 + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
10798 SupportCount.count( t0_4, phylogenies_4, true, false );
10799 t0_4.reRoot( t0_4.getNode( "F" ).getId() );
10800 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
10803 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
10806 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
10809 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
10812 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
10815 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
10818 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
10821 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
10824 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
10827 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
10830 Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10831 final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10832 double d = SupportCount.compare( b1, a, true, true, true );
10833 if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
10836 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10837 final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10838 d = SupportCount.compare( b2, a, true, true, true );
10839 if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
10842 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
10843 final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
10844 d = SupportCount.compare( b3, a, true, true, true );
10845 if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
10848 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
10849 final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
10850 d = SupportCount.compare( b4, a, true, true, false );
10851 if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
10855 catch ( final Exception e ) {
10856 e.printStackTrace( System.out );
10862 private static boolean testSupportTransfer() {
10864 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10865 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)",
10866 new NHXParser() )[ 0 ];
10867 final Phylogeny p2 = factory
10868 .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 ];
10869 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
10872 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
10875 support_transfer.moveBranchLengthsToBootstrap( p1 );
10876 support_transfer.transferSupportValues( p1, p2 );
10877 if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
10880 if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
10883 if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
10886 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
10889 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
10892 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
10895 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
10898 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
10902 catch ( final Exception e ) {
10903 e.printStackTrace( System.out );
10909 private static boolean testTaxonomyExtraction() {
10911 final PhylogenyNode n0 = PhylogenyNode
10912 .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10913 if ( n0.getNodeData().isHasTaxonomy() ) {
10916 final PhylogenyNode n1 = PhylogenyNode
10917 .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10918 if ( n1.getNodeData().isHasTaxonomy() ) {
10919 System.out.println( n1.toString() );
10922 final PhylogenyNode n2x = PhylogenyNode
10923 .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10924 if ( n2x.getNodeData().isHasTaxonomy() ) {
10927 final PhylogenyNode n3 = PhylogenyNode
10928 .createInstanceFromNhxString( "blag_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10929 if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
10930 System.out.println( n3.toString() );
10933 final PhylogenyNode n4 = PhylogenyNode
10934 .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10935 if ( n4.getNodeData().isHasTaxonomy() ) {
10936 System.out.println( n4.toString() );
10939 final PhylogenyNode n5 = PhylogenyNode
10940 .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10941 if ( n5.getNodeData().isHasTaxonomy() ) {
10942 System.out.println( n5.toString() );
10945 final PhylogenyNode n6 = PhylogenyNode
10946 .createInstanceFromNhxString( "blag-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10947 if ( n6.getNodeData().isHasTaxonomy() ) {
10948 System.out.println( n6.toString() );
10951 final PhylogenyNode n7 = PhylogenyNode
10952 .createInstanceFromNhxString( "blag-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10953 if ( n7.getNodeData().isHasTaxonomy() ) {
10954 System.out.println( n7.toString() );
10957 final PhylogenyNode n8 = PhylogenyNode
10958 .createInstanceFromNhxString( "blag_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10959 if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
10960 System.out.println( n8.toString() );
10963 final PhylogenyNode n9 = PhylogenyNode
10964 .createInstanceFromNhxString( "blag_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10965 if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
10966 System.out.println( n9.toString() );
10969 final PhylogenyNode n10x = PhylogenyNode
10970 .createInstanceFromNhxString( "blag_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10971 if ( n10x.getNodeData().isHasTaxonomy() ) {
10972 System.out.println( n10x.toString() );
10975 final PhylogenyNode n10xx = PhylogenyNode
10976 .createInstanceFromNhxString( "blag_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10977 if ( n10xx.getNodeData().isHasTaxonomy() ) {
10978 System.out.println( n10xx.toString() );
10981 final PhylogenyNode n10 = PhylogenyNode
10982 .createInstanceFromNhxString( "blag_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
10983 if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
10984 System.out.println( n10.toString() );
10987 final PhylogenyNode n11 = PhylogenyNode
10988 .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
10989 if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
10990 System.out.println( n11.toString() );
10993 final PhylogenyNode n12 = PhylogenyNode
10994 .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
10995 NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
10996 if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
10997 System.out.println( n12.toString() );
11000 final PhylogenyNode n13 = PhylogenyNode
11001 .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
11002 if ( n13.getNodeData().isHasTaxonomy() ) {
11003 System.out.println( n13.toString() );
11007 catch ( final Exception e ) {
11008 e.printStackTrace( System.out );
11014 private static boolean testTreeMethods() {
11016 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11017 final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
11018 PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
11019 if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
11020 System.out.println( t0.toNewHampshireX() );
11023 final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
11024 PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
11025 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
11028 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
11031 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
11035 catch ( final Exception e ) {
11036 e.printStackTrace( System.out );
11042 private static boolean testUniprotEntryRetrieval() {
11044 final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 200 );
11045 if ( !entry.getAccession().equals( "P12345" ) ) {
11048 if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
11051 if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
11054 if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
11058 catch ( final IOException e ) {
11059 System.out.println();
11060 System.out.println( "the following might be due to absence internet connection:" );
11061 e.printStackTrace( System.out );
11064 catch ( final Exception e ) {
11070 private static boolean testUniprotTaxonomySearch() {
11072 List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
11074 if ( results.size() != 1 ) {
11077 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11080 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11083 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11086 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11089 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11093 results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
11094 if ( results.size() != 1 ) {
11097 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11100 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11103 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11106 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11109 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11113 results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
11114 if ( results.size() != 1 ) {
11117 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11120 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11123 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11126 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11129 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11133 results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
11134 if ( results.size() != 1 ) {
11137 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
11140 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
11143 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
11146 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
11149 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
11152 if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
11155 if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
11158 if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
11159 .equals( "Nematostella vectensis" ) ) {
11160 System.out.println( results.get( 0 ).getLineage() );
11164 catch ( final IOException e ) {
11165 System.out.println();
11166 System.out.println( "the following might be due to absence internet connection:" );
11167 e.printStackTrace( System.out );
11170 catch ( final Exception e ) {
11176 private static boolean testWabiTxSearch() {
11178 String result = "";
11179 result = TxSearch.searchSimple( "nematostella" );
11180 result = TxSearch.getTxId( "nematostella" );
11181 if ( !result.equals( "45350" ) ) {
11184 result = TxSearch.getTxName( "45350" );
11185 if ( !result.equals( "Nematostella" ) ) {
11188 result = TxSearch.getTxId( "nematostella vectensis" );
11189 if ( !result.equals( "45351" ) ) {
11192 result = TxSearch.getTxName( "45351" );
11193 if ( !result.equals( "Nematostella vectensis" ) ) {
11196 result = TxSearch.getTxId( "Bacillus subtilis subsp. subtilis str. N170" );
11197 if ( !result.equals( "536089" ) ) {
11200 result = TxSearch.getTxName( "536089" );
11201 if ( !result.equals( "Bacillus subtilis subsp. subtilis str. N170" ) ) {
11204 final List<String> queries = new ArrayList<String>();
11205 queries.add( "Campylobacter coli" );
11206 queries.add( "Escherichia coli" );
11207 queries.add( "Arabidopsis" );
11208 queries.add( "Trichoplax" );
11209 queries.add( "Samanea saman" );
11210 queries.add( "Kluyveromyces marxianus" );
11211 queries.add( "Bacillus subtilis subsp. subtilis str. N170" );
11212 queries.add( "Bornavirus parrot/PDD/2008" );
11213 final List<RANKS> ranks = new ArrayList<RANKS>();
11214 ranks.add( RANKS.SUPERKINGDOM );
11215 ranks.add( RANKS.KINGDOM );
11216 ranks.add( RANKS.FAMILY );
11217 ranks.add( RANKS.GENUS );
11218 ranks.add( RANKS.TRIBE );
11219 result = TxSearch.searchLineage( queries, ranks );
11220 result = TxSearch.searchParam( "Homo sapiens", TAX_NAME_CLASS.ALL, TAX_RANK.SPECIES, 10, true );
11221 result = TxSearch.searchParam( "Samanea saman", TAX_NAME_CLASS.SCIENTIFIC_NAME, TAX_RANK.ALL, 10, true );
11223 catch ( final Exception e ) {
11224 System.out.println();
11225 System.out.println( "the following might be due to absence internet connection:" );
11226 e.printStackTrace( System.out );