2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2014 Christian M. Zmasek
6 // Copyright (C) 2014 Sanford-Burnham Medical Research Institute
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 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
25 package org.forester.test;
27 import java.io.ByteArrayInputStream;
29 import java.io.FileInputStream;
30 import java.io.IOException;
31 import java.io.StringWriter;
32 import java.io.Writer;
34 import java.util.ArrayList;
35 import java.util.Date;
36 import java.util.HashSet;
37 import java.util.Iterator;
38 import java.util.List;
39 import java.util.Locale;
41 import java.util.SortedSet;
43 import javax.net.ssl.HttpsURLConnection;
44 import javax.net.ssl.SSLContext;
46 import org.forester.application.support_transfer;
47 import org.forester.archaeopteryx.AptxUtil;
48 import org.forester.archaeopteryx.TreePanelUtil;
49 import org.forester.archaeopteryx.webservices.WebserviceUtil;
50 import org.forester.development.DevelopmentTools;
51 import org.forester.evoinference.TestPhylogenyReconstruction;
52 import org.forester.evoinference.matrix.character.CharacterStateMatrix;
53 import org.forester.evoinference.matrix.character.CharacterStateMatrix.BinaryStates;
54 import org.forester.go.TestGo;
55 import org.forester.io.parsers.FastaParser;
56 import org.forester.io.parsers.GeneralMsaParser;
57 import org.forester.io.parsers.HmmscanPerDomainTableParser;
58 import org.forester.io.parsers.HmmscanPerDomainTableParser.INDIVIDUAL_SCORE_CUTOFF;
59 import org.forester.io.parsers.nexus.NexusBinaryStatesMatrixParser;
60 import org.forester.io.parsers.nexus.NexusCharactersParser;
61 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
62 import org.forester.io.parsers.nhx.NHXParser;
63 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
64 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
65 import org.forester.io.parsers.tol.TolParser;
66 import org.forester.io.parsers.util.ParserUtils;
67 import org.forester.io.writers.PhylogenyWriter;
68 import org.forester.io.writers.SequenceWriter;
69 import org.forester.msa.BasicMsa;
70 import org.forester.msa.DeleteableMsa;
71 import org.forester.msa.Mafft;
72 import org.forester.msa.Msa;
73 import org.forester.msa.Msa.MSA_FORMAT;
74 import org.forester.msa.MsaInferrer;
75 import org.forester.msa.MsaMethods;
76 import org.forester.pccx.TestPccx;
77 import org.forester.phylogeny.Phylogeny;
78 import org.forester.phylogeny.PhylogenyBranch;
79 import org.forester.phylogeny.PhylogenyMethods;
80 import org.forester.phylogeny.PhylogenyNode;
81 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
82 import org.forester.phylogeny.data.Accession;
83 import org.forester.phylogeny.data.Accession.Source;
84 import org.forester.phylogeny.data.BinaryCharacters;
85 import org.forester.phylogeny.data.BranchWidth;
86 import org.forester.phylogeny.data.Confidence;
87 import org.forester.phylogeny.data.Distribution;
88 import org.forester.phylogeny.data.DomainArchitecture;
89 import org.forester.phylogeny.data.Event;
90 import org.forester.phylogeny.data.Identifier;
91 import org.forester.phylogeny.data.PhylogenyData;
92 import org.forester.phylogeny.data.PhylogenyDataUtil;
93 import org.forester.phylogeny.data.Polygon;
94 import org.forester.phylogeny.data.PropertiesMap;
95 import org.forester.phylogeny.data.Property;
96 import org.forester.phylogeny.data.Property.AppliesTo;
97 import org.forester.phylogeny.data.ProteinDomain;
98 import org.forester.phylogeny.data.Taxonomy;
99 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
100 import org.forester.phylogeny.factories.PhylogenyFactory;
101 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
102 import org.forester.protein.BasicDomain;
103 import org.forester.protein.BasicProtein;
104 import org.forester.protein.Domain;
105 import org.forester.protein.Protein;
106 import org.forester.protein.ProteinId;
107 import org.forester.rio.TestRIO;
108 import org.forester.sdi.SDI;
109 import org.forester.sdi.SDIR;
110 import org.forester.sdi.TestGSDI;
111 import org.forester.sequence.BasicSequence;
112 import org.forester.sequence.MolecularSequence;
113 import org.forester.species.BasicSpecies;
114 import org.forester.species.Species;
115 import org.forester.surfacing.TestSurfacing;
116 import org.forester.tools.ConfidenceAssessor;
117 import org.forester.tools.SupportCount;
118 import org.forester.tools.TreeSplitMatrix;
119 import org.forester.util.AsciiHistogram;
120 import org.forester.util.BasicDescriptiveStatistics;
121 import org.forester.util.BasicTable;
122 import org.forester.util.BasicTableParser;
123 import org.forester.util.DescriptiveStatistics;
124 import org.forester.util.ForesterConstants;
125 import org.forester.util.ForesterUtil;
126 import org.forester.util.GeneralTable;
127 import org.forester.util.SequenceAccessionTools;
128 import org.forester.util.TrustManager;
129 import org.forester.ws.seqdb.SequenceDatabaseEntry;
130 import org.forester.ws.seqdb.SequenceDbWsTools;
131 import org.forester.ws.seqdb.UniProtTaxonomy;
134 @SuppressWarnings( "unused")
135 public final class Test {
137 private final static String PATH_TO_RESOURCES = System.getProperty( "user.dir" )
138 + ForesterUtil.getFileSeparator() + "resources"
139 + ForesterUtil.getFileSeparator();
140 private final static String PATH_TO_TEST_DATA = System.getProperty( "user.dir" )
141 + ForesterUtil.getFileSeparator() + "test_data"
142 + ForesterUtil.getFileSeparator();
143 private final static boolean PERFORM_DB_TESTS = true;
144 private static final boolean PERFORM_WEB_TREE_ACCESS = true;
145 private static final String PHYLOXML_LOCAL_XSD = PATH_TO_RESOURCES + "phyloxml_schema/"
146 + ForesterConstants.PHYLO_XML_VERSION + "/"
147 + ForesterConstants.PHYLO_XML_XSD;
148 private static final String PHYLOXML_REMOTE_XSD = ForesterConstants.PHYLO_XML_LOCATION + "/"
149 + ForesterConstants.PHYLO_XML_VERSION + "/"
150 + ForesterConstants.PHYLO_XML_XSD;
151 private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
152 private final static double ZERO_DIFF = 1.0E-9;
154 private static boolean isEqual( final double a, final double b ) {
155 return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
158 public static void main( final String[] args ) {
159 System.out.println( "[Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]" );
160 System.out.println( "[OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " " + ForesterUtil.OS_VERSION
162 Locale.setDefault( Locale.US );
163 System.out.println( "[Locale: " + Locale.getDefault() + "]" );
166 System.out.print( "[Test if directory with files for testing exists/is readable: " );
167 if ( Test.testDir( PATH_TO_TEST_DATA ) ) {
168 System.out.println( "OK.]" );
171 System.out.println( "could not find/read from directory \"" + PATH_TO_TEST_DATA + "\".]" );
172 System.out.println( "Testing aborted." );
175 System.out.print( "[Test if resources directory exists/is readable: " );
176 if ( testDir( PATH_TO_RESOURCES ) ) {
177 System.out.println( "OK.]" );
180 System.out.println( "could not find/read from directory \"" + Test.PATH_TO_RESOURCES + "\".]" );
181 System.out.println( "Testing aborted." );
184 final long start_time = new Date().getTime();
188 System.out.print( "TreeBase acccess: " );
189 if ( Test.testTreeBaseReading() ) {
190 System.out.println( "OK." );
194 System.out.println( "failed." );
202 System.out.print( "Basic node methods: " );
203 if ( Test.testBasicNodeMethods() ) {
204 System.out.println( "OK." );
208 System.out.println( "failed." );
211 System.out.print( "Protein id: " );
212 if ( !testProteinId() ) {
213 System.out.println( "failed." );
219 System.out.println( "OK." );
220 System.out.print( "Species: " );
221 if ( !testSpecies() ) {
222 System.out.println( "failed." );
228 System.out.println( "OK." );
229 System.out.print( "Basic domain: " );
230 if ( !testBasicDomain() ) {
231 System.out.println( "failed." );
237 System.out.println( "OK." );
238 System.out.print( "Basic protein: " );
239 if ( !testBasicProtein() ) {
240 System.out.println( "failed." );
246 System.out.println( "OK." );
247 System.out.print( "Sequence writer: " );
248 if ( testSequenceWriter() ) {
249 System.out.println( "OK." );
253 System.out.println( "failed." );
256 System.out.print( "Sequence id parsing: " );
257 if ( testSequenceIdParsing() ) {
258 System.out.println( "OK." );
262 System.out.println( "failed." );
265 System.out.print( "UniProtKB id extraction: " );
266 if ( Test.testExtractUniProtKbProteinSeqIdentifier() ) {
267 System.out.println( "OK." );
271 System.out.println( "failed." );
274 System.out.print( "Sequence DB tools 1: " );
275 if ( testSequenceDbWsTools1() ) {
276 System.out.println( "OK." );
280 System.out.println( "failed." );
283 System.out.print( "Hmmscan output parser: " );
284 if ( testHmmscanOutputParser() ) {
285 System.out.println( "OK." );
289 System.out.println( "failed." );
292 System.out.print( "Overlap removal: " );
293 if ( !org.forester.test.Test.testOverlapRemoval() ) {
294 System.out.println( "failed." );
300 System.out.println( "OK." );
301 System.out.print( "Engulfing overlap removal: " );
302 if ( !Test.testEngulfingOverlapRemoval() ) {
303 System.out.println( "failed." );
309 System.out.println( "OK." );
310 System.out.print( "Taxonomy data extraction: " );
311 if ( Test.testExtractTaxonomyDataFromNodeName() ) {
312 System.out.println( "OK." );
316 System.out.println( "failed." );
319 System.out.print( "Taxonomy code extraction: " );
320 if ( Test.testExtractTaxonomyCodeFromNodeName() ) {
321 System.out.println( "OK." );
325 System.out.println( "failed." );
328 System.out.print( "SN extraction: " );
329 if ( Test.testExtractSNFromNodeName() ) {
330 System.out.println( "OK." );
334 System.out.println( "failed." );
337 System.out.print( "Taxonomy extraction (general): " );
338 if ( Test.testTaxonomyExtraction() ) {
339 System.out.println( "OK." );
343 System.out.println( "failed." );
346 System.out.print( "Uri for Aptx web sequence accession: " );
347 if ( Test.testCreateUriForSeqWeb() ) {
348 System.out.println( "OK." );
352 System.out.println( "failed." );
355 System.out.print( "Basic node construction and parsing of NHX (node level): " );
356 if ( Test.testNHXNodeParsing() ) {
357 System.out.println( "OK." );
361 System.out.println( "failed." );
364 System.out.print( "NHX parsing iterating: " );
365 if ( Test.testNHParsingIter() ) {
366 System.out.println( "OK." );
370 System.out.println( "failed." );
373 System.out.print( "NH parsing: " );
374 if ( Test.testNHParsing() ) {
375 System.out.println( "OK." );
379 System.out.println( "failed." );
382 System.out.print( "Conversion to NHX (node level): " );
383 if ( Test.testNHXconversion() ) {
384 System.out.println( "OK." );
388 System.out.println( "failed." );
391 System.out.print( "NHX parsing: " );
392 if ( Test.testNHXParsing() ) {
393 System.out.println( "OK." );
397 System.out.println( "failed." );
400 System.out.print( "NHX parsing with quotes: " );
401 if ( Test.testNHXParsingQuotes() ) {
402 System.out.println( "OK." );
406 System.out.println( "failed." );
409 System.out.print( "NHX parsing (MrBayes): " );
410 if ( Test.testNHXParsingMB() ) {
411 System.out.println( "OK." );
415 System.out.println( "failed." );
418 System.out.print( "Nexus characters parsing: " );
419 if ( Test.testNexusCharactersParsing() ) {
420 System.out.println( "OK." );
424 System.out.println( "failed." );
427 System.out.print( "Nexus tree parsing iterating: " );
428 if ( Test.testNexusTreeParsingIterating() ) {
429 System.out.println( "OK." );
433 System.out.println( "failed." );
436 System.out.print( "Nexus tree parsing: " );
437 if ( Test.testNexusTreeParsing() ) {
438 System.out.println( "OK." );
442 System.out.println( "failed." );
445 System.out.print( "Nexus tree parsing (translating): " );
446 if ( Test.testNexusTreeParsingTranslating() ) {
447 System.out.println( "OK." );
451 System.out.println( "failed." );
454 System.out.print( "Nexus matrix parsing: " );
455 if ( Test.testNexusMatrixParsing() ) {
456 System.out.println( "OK." );
460 System.out.println( "failed." );
463 System.out.print( "Basic phyloXML parsing: " );
464 if ( Test.testBasicPhyloXMLparsing() ) {
465 System.out.println( "OK." );
469 System.out.println( "failed." );
472 System.out.print( "Basic phyloXML parsing (validating against schema): " );
473 if ( testBasicPhyloXMLparsingValidating() ) {
474 System.out.println( "OK." );
478 System.out.println( "failed." );
481 System.out.print( "Roundtrip phyloXML parsing (validating against schema): " );
482 if ( Test.testBasicPhyloXMLparsingRoundtrip() ) {
483 System.out.println( "OK." );
487 System.out.println( "failed." );
490 System.out.print( "phyloXML Distribution Element: " );
491 if ( Test.testPhyloXMLparsingOfDistributionElement() ) {
492 System.out.println( "OK." );
496 System.out.println( "failed." );
499 System.out.print( "Tol XML parsing: " );
500 if ( Test.testBasicTolXMLparsing() ) {
501 System.out.println( "OK." );
505 System.out.println( "failed." );
508 System.out.print( "Copying of node data: " );
509 if ( Test.testCopyOfNodeData() ) {
510 System.out.println( "OK." );
514 System.out.println( "failed." );
517 System.out.print( "Tree copy: " );
518 if ( Test.testTreeCopy() ) {
519 System.out.println( "OK." );
523 System.out.println( "failed." );
526 System.out.print( "Basic tree methods: " );
527 if ( Test.testBasicTreeMethods() ) {
528 System.out.println( "OK." );
532 System.out.println( "failed." );
535 System.out.print( "Tree methods: " );
536 if ( Test.testTreeMethods() ) {
537 System.out.println( "OK." );
541 System.out.println( "failed." );
544 System.out.print( "Postorder Iterator: " );
545 if ( Test.testPostOrderIterator() ) {
546 System.out.println( "OK." );
550 System.out.println( "failed." );
553 System.out.print( "Preorder Iterator: " );
554 if ( Test.testPreOrderIterator() ) {
555 System.out.println( "OK." );
559 System.out.println( "failed." );
562 System.out.print( "Levelorder Iterator: " );
563 if ( Test.testLevelOrderIterator() ) {
564 System.out.println( "OK." );
568 System.out.println( "failed." );
571 System.out.print( "Re-id methods: " );
572 if ( Test.testReIdMethods() ) {
573 System.out.println( "OK." );
577 System.out.println( "failed." );
580 System.out.print( "Methods on last external nodes: " );
581 if ( Test.testLastExternalNodeMethods() ) {
582 System.out.println( "OK." );
586 System.out.println( "failed." );
589 System.out.print( "Methods on external nodes: " );
590 if ( Test.testExternalNodeRelatedMethods() ) {
591 System.out.println( "OK." );
595 System.out.println( "failed." );
598 System.out.print( "Deletion of external nodes: " );
599 if ( Test.testDeletionOfExternalNodes() ) {
600 System.out.println( "OK." );
604 System.out.println( "failed." );
607 System.out.print( "Subtree deletion: " );
608 if ( Test.testSubtreeDeletion() ) {
609 System.out.println( "OK." );
613 System.out.println( "failed." );
616 System.out.print( "Phylogeny branch: " );
617 if ( Test.testPhylogenyBranch() ) {
618 System.out.println( "OK." );
622 System.out.println( "failed." );
625 System.out.print( "Rerooting: " );
626 if ( Test.testRerooting() ) {
627 System.out.println( "OK." );
631 System.out.println( "failed." );
634 System.out.print( "Mipoint rooting: " );
635 if ( Test.testMidpointrooting() ) {
636 System.out.println( "OK." );
640 System.out.println( "failed." );
643 System.out.print( "Node removal: " );
644 if ( Test.testNodeRemoval() ) {
645 System.out.println( "OK." );
649 System.out.println( "failed." );
652 System.out.print( "Support count: " );
653 if ( Test.testSupportCount() ) {
654 System.out.println( "OK." );
658 System.out.println( "failed." );
661 System.out.print( "Support transfer: " );
662 if ( Test.testSupportTransfer() ) {
663 System.out.println( "OK." );
667 System.out.println( "failed." );
670 System.out.print( "Finding of LCA: " );
671 if ( Test.testGetLCA() ) {
672 System.out.println( "OK." );
676 System.out.println( "failed." );
679 System.out.print( "Finding of LCA 2: " );
680 if ( Test.testGetLCA2() ) {
681 System.out.println( "OK." );
685 System.out.println( "failed." );
688 System.out.print( "Calculation of distance between nodes: " );
689 if ( Test.testGetDistance() ) {
690 System.out.println( "OK." );
694 System.out.println( "failed." );
697 System.out.print( "Descriptive statistics: " );
698 if ( Test.testDescriptiveStatistics() ) {
699 System.out.println( "OK." );
703 System.out.println( "failed." );
706 System.out.print( "Data objects and methods: " );
707 if ( Test.testDataObjects() ) {
708 System.out.println( "OK." );
712 System.out.println( "failed." );
715 System.out.print( "Properties map: " );
716 if ( Test.testPropertiesMap() ) {
717 System.out.println( "OK." );
721 System.out.println( "failed." );
724 System.out.print( "SDIse: " );
725 if ( Test.testSDIse() ) {
726 System.out.println( "OK." );
730 System.out.println( "failed." );
733 System.out.print( "SDIunrooted: " );
734 if ( Test.testSDIunrooted() ) {
735 System.out.println( "OK." );
739 System.out.println( "failed." );
742 System.out.print( "GSDI: " );
743 if ( TestGSDI.test() ) {
744 System.out.println( "OK." );
748 System.out.println( "failed." );
751 System.out.print( "RIO: " );
752 if ( TestRIO.test() ) {
753 System.out.println( "OK." );
757 System.out.println( "failed." );
760 System.out.print( "Phylogeny reconstruction:" );
761 System.out.println();
762 if ( TestPhylogenyReconstruction.test( new File( PATH_TO_TEST_DATA ) ) ) {
763 System.out.println( "OK." );
767 System.out.println( "failed." );
770 System.out.print( "Analysis of domain architectures: " );
771 System.out.println();
772 if ( TestSurfacing.test( new File( PATH_TO_TEST_DATA ) ) ) {
773 System.out.println( "OK." );
777 System.out.println( "failed." );
780 System.out.print( "GO: " );
781 System.out.println();
782 if ( TestGo.test( new File( PATH_TO_TEST_DATA ) ) ) {
783 System.out.println( "OK." );
787 System.out.println( "failed." );
790 System.out.print( "Modeling tools: " );
791 if ( TestPccx.test() ) {
792 System.out.println( "OK." );
796 System.out.println( "failed." );
799 System.out.print( "Split Matrix strict: " );
800 if ( Test.testSplitStrict() ) {
801 System.out.println( "OK." );
805 System.out.println( "failed." );
808 System.out.print( "Split Matrix: " );
809 if ( Test.testSplit() ) {
810 System.out.println( "OK." );
814 System.out.println( "failed." );
817 System.out.print( "Confidence Assessor: " );
818 if ( Test.testConfidenceAssessor() ) {
819 System.out.println( "OK." );
823 System.out.println( "failed." );
826 System.out.print( "Basic table: " );
827 if ( Test.testBasicTable() ) {
828 System.out.println( "OK." );
832 System.out.println( "failed." );
835 System.out.print( "General table: " );
836 if ( Test.testGeneralTable() ) {
837 System.out.println( "OK." );
841 System.out.println( "failed." );
844 System.out.print( "Amino acid sequence: " );
845 if ( Test.testAminoAcidSequence() ) {
846 System.out.println( "OK." );
850 System.out.println( "failed." );
853 System.out.print( "General MSA parser: " );
854 if ( Test.testGeneralMsaParser() ) {
855 System.out.println( "OK." );
859 System.out.println( "failed." );
862 System.out.print( "Fasta parser for msa: " );
863 if ( Test.testFastaParser() ) {
864 System.out.println( "OK." );
868 System.out.println( "failed." );
871 System.out.print( "Creation of balanced phylogeny: " );
872 if ( Test.testCreateBalancedPhylogeny() ) {
873 System.out.println( "OK." );
877 System.out.println( "failed." );
880 System.out.print( "Genbank accessor parsing: " );
881 if ( Test.testGenbankAccessorParsing() ) {
882 System.out.println( "OK." );
886 System.out.println( "failed." );
890 final String os = ForesterUtil.OS_NAME.toLowerCase();
891 if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) {
892 path = "/usr/local/bin/mafft";
894 else if ( os.indexOf( "win" ) >= 0 ) {
895 path = "C:\\Program Files\\mafft-win\\mafft.bat";
899 if ( !MsaInferrer.isInstalled( path ) ) {
900 path = "/usr/bin/mafft";
902 if ( !MsaInferrer.isInstalled( path ) ) {
903 path = "/usr/local/bin/mafft";
906 if ( MsaInferrer.isInstalled( path ) ) {
907 System.out.print( "MAFFT (external program): " );
908 if ( Test.testMafft( path ) ) {
909 System.out.println( "OK." );
913 System.out.println( "failed [will not count towards failed tests]" );
916 System.out.print( "Next nodes with collapsed: " );
917 if ( Test.testNextNodeWithCollapsing() ) {
918 System.out.println( "OK." );
922 System.out.println( "failed." );
925 System.out.print( "Simple MSA quality: " );
926 if ( Test.testMsaQualityMethod() ) {
927 System.out.println( "OK." );
931 System.out.println( "failed." );
934 System.out.print( "Deleteable MSA: " );
935 if ( Test.testDeleteableMsa() ) {
936 System.out.println( "OK." );
940 System.out.println( "failed." );
943 System.out.print( "MSA entropy: " );
944 if ( Test.testMsaEntropy() ) {
945 System.out.println( "OK." );
949 System.out.println( "failed." );
952 if ( PERFORM_DB_TESTS ) {
953 System.out.print( "Uniprot Entry Retrieval: " );
954 if ( Test.testUniprotEntryRetrieval() ) {
955 System.out.println( "OK." );
959 System.out.println( "failed." );
962 System.out.print( "Ebi Entry Retrieval: " );
963 if ( Test.testEbiEntryRetrieval() ) {
964 System.out.println( "OK." );
968 System.out.println( "failed." );
971 System.out.print( "Sequence DB tools 2: " );
972 if ( testSequenceDbWsTools2() ) {
973 System.out.println( "OK." );
977 System.out.println( "failed." );
981 System.out.print( "Uniprot Taxonomy Search: " );
982 if ( Test.testUniprotTaxonomySearch() ) {
983 System.out.println( "OK." );
987 System.out.println( "failed." );
991 if ( PERFORM_WEB_TREE_ACCESS ) {
992 System.out.print( "NHX parsing from URL: " );
993 if ( Test.testNHXparsingFromURL() ) {
994 System.out.println( "OK." );
998 System.out.println( "failed." );
1001 System.out.print( "NHX parsing from URL 2: " );
1002 if ( Test.testNHXparsingFromURL2() ) {
1003 System.out.println( "OK." );
1007 System.out.println( "failed." );
1010 System.out.print( "phyloXML parsing from URL: " );
1011 if ( Test.testPhyloXMLparsingFromURL() ) {
1012 System.out.println( "OK." );
1016 System.out.println( "failed." );
1019 System.out.print( "TreeBase acccess: " );
1020 if ( Test.testTreeBaseReading() ) {
1021 System.out.println( "OK." );
1025 System.out.println( "failed." );
1028 System.out.print( "ToL access: " );
1029 if ( Test.testToLReading() ) {
1030 System.out.println( "OK." );
1034 System.out.println( "failed." );
1038 System.out.print( "TreeFam access: " );
1039 if ( Test.testTreeFamReading() ) {
1040 System.out.println( "OK." );
1044 System.out.println( "failed." );
1049 System.out.print( "Pfam tree access: " );
1050 if ( Test.testPfamTreeReading() ) {
1051 System.out.println( "OK." );
1055 System.out.println( "failed." );
1059 System.out.println();
1060 final Runtime rt = java.lang.Runtime.getRuntime();
1061 final long free_memory = rt.freeMemory() / 1000000;
1062 final long total_memory = rt.totalMemory() / 1000000;
1063 System.out.println( "Running time : " + ( new Date().getTime() - start_time ) + "ms " + "(free memory: "
1064 + free_memory + "MB, total memory: " + total_memory + "MB)" );
1065 System.out.println();
1066 System.out.println( "Successful tests: " + succeeded );
1067 System.out.println( "Failed tests: " + failed );
1068 System.out.println();
1070 System.out.println( "OK." );
1073 System.out.println( "Not OK." );
1077 private static boolean testEngulfingOverlapRemoval() {
1079 final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1080 final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
1081 final Domain d2 = new BasicDomain( "d2", 0, 2, ( short ) 1, ( short ) 1, 0.1, 1 );
1082 final Domain d3 = new BasicDomain( "d3", 7, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1083 final Domain d4 = new BasicDomain( "d4", 7, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1084 final Domain d5 = new BasicDomain( "d4", 0, 9, ( short ) 1, ( short ) 1, 0.1, 1 );
1085 final Domain d6 = new BasicDomain( "d4", 4, 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1086 final List<Boolean> covered = new ArrayList<Boolean>();
1087 covered.add( true ); // 0
1088 covered.add( false ); // 1
1089 covered.add( true ); // 2
1090 covered.add( false ); // 3
1091 covered.add( true ); // 4
1092 covered.add( true ); // 5
1093 covered.add( false ); // 6
1094 covered.add( true ); // 7
1095 covered.add( true ); // 8
1096 if ( ForesterUtil.isEngulfed( d0, covered ) ) {
1099 if ( ForesterUtil.isEngulfed( d1, covered ) ) {
1102 if ( ForesterUtil.isEngulfed( d2, covered ) ) {
1105 if ( !ForesterUtil.isEngulfed( d3, covered ) ) {
1108 if ( ForesterUtil.isEngulfed( d4, covered ) ) {
1111 if ( ForesterUtil.isEngulfed( d5, covered ) ) {
1114 if ( !ForesterUtil.isEngulfed( d6, covered ) ) {
1117 final Domain a = new BasicDomain( "a", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1118 final Domain b = new BasicDomain( "b", 8, 20, ( short ) 1, ( short ) 1, 0.2, 1 );
1119 final Domain c = new BasicDomain( "c", 15, 16, ( short ) 1, ( short ) 1, 0.3, 1 );
1120 final Protein abc = new BasicProtein( "abc", "nemve", 0 );
1121 abc.addProteinDomain( a );
1122 abc.addProteinDomain( b );
1123 abc.addProteinDomain( c );
1124 final Protein abc_r1 = ForesterUtil.removeOverlappingDomains( 3, false, abc );
1125 final Protein abc_r2 = ForesterUtil.removeOverlappingDomains( 3, true, abc );
1126 if ( abc.getNumberOfProteinDomains() != 3 ) {
1129 if ( abc_r1.getNumberOfProteinDomains() != 3 ) {
1132 if ( abc_r2.getNumberOfProteinDomains() != 2 ) {
1135 if ( !abc_r2.getProteinDomain( 0 ).getDomainId().equals( "a" ) ) {
1138 if ( !abc_r2.getProteinDomain( 1 ).getDomainId().equals( "b" ) ) {
1141 final Domain d = new BasicDomain( "d", 0, 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1142 final Domain e = new BasicDomain( "e", 8, 20, ( short ) 1, ( short ) 1, 0.3, 1 );
1143 final Domain f = new BasicDomain( "f", 15, 16, ( short ) 1, ( short ) 1, 0.2, 1 );
1144 final Protein def = new BasicProtein( "def", "nemve", 0 );
1145 def.addProteinDomain( d );
1146 def.addProteinDomain( e );
1147 def.addProteinDomain( f );
1148 final Protein def_r1 = ForesterUtil.removeOverlappingDomains( 5, false, def );
1149 final Protein def_r2 = ForesterUtil.removeOverlappingDomains( 5, true, def );
1150 if ( def.getNumberOfProteinDomains() != 3 ) {
1153 if ( def_r1.getNumberOfProteinDomains() != 3 ) {
1156 if ( def_r2.getNumberOfProteinDomains() != 3 ) {
1159 if ( !def_r2.getProteinDomain( 0 ).getDomainId().equals( "d" ) ) {
1162 if ( !def_r2.getProteinDomain( 1 ).getDomainId().equals( "f" ) ) {
1165 if ( !def_r2.getProteinDomain( 2 ).getDomainId().equals( "e" ) ) {
1169 catch ( final Exception e ) {
1170 e.printStackTrace( System.out );
1176 private static final boolean testNHXparsingFromURL2() {
1178 final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1179 final Phylogeny phys[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1183 TAXONOMY_EXTRACTION.NO,
1185 if ( ( phys == null ) || ( phys.length != 5 ) ) {
1188 if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1189 System.out.println( phys[ 0 ].toNewHampshire() );
1192 if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1193 System.out.println( phys[ 1 ].toNewHampshire() );
1196 final Phylogeny phys2[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
1200 TAXONOMY_EXTRACTION.NO,
1202 if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1205 if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1206 System.out.println( phys2[ 0 ].toNewHampshire() );
1209 if ( !phys2[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1210 System.out.println( phys2[ 1 ].toNewHampshire() );
1213 final Phylogeny phys3[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1214 + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1215 if ( ( phys3 == null ) || ( phys3.length != 1 ) ) {
1220 .equals( "((((POP23a_CIOIN_ENSCING00000016202,POP23b_CIOIN_ENSCING00000016169),POP23_CIOSA_ENSCSAVG00000000248),((POP23a_BRAFL_C3ZMF1,POP23b_BRAFL_121417),(((POP3_ORYLA_ENSORLG00000019669,POP3_GASAC_ENSGACG00000014023,POP3_DANRE_Q6JWW1),(POP3_XENTR_B1H1F6,(POP3_CHICK_Q9DG25,(POP3_ORNAN_ENSOANG00000004179,POP3_MONDO_ENSMODG00000018033,((POP3_MOUSE_Q9ES81,POP3_RAT_Q3BCU3),POP3_RABIT_ENSOCUG00000025973,POP3_MACMU_ENSMMUG00000014473,POP3_HUMAN_Q9HBV1))))),(((POP2_GASAC_ENSGACG00000001420,POP2_ORYLA_ENSORLG00000008627,POP2_TAKRU_ENSTRUG00000015933),POP2_DANRE_ENSDARG00000069922),POP2_XENTR_ENSXETG00000018064,(((POP2_TAEGU_ENSTGUG00000013383,POP2_CHICK_Q6T9Z5),POP2_ANOCA_ENSACAG00000003557),((POP2_MACEU_ENSMEUG00000015825,POP2_MONDO_ENSMODG00000018205),((POP2_RABIT_ENSOCUG00000009515,(POP2_RAT_Q6P722,POP2_MOUSE_Q9ES82)),(POP2_MACMU_ENSMMUG00000000905,POP2_HUMAN_Q9HBU9)))))))),((POP1_CIOSA_ENSCSAVG00000000247,POP1_CIOIN_ENSCING00000000496),((POP1_DANRE_Q5PQZ7,(POP1_ORYLA_ENSORLG00000019663,POP1_GASAC_ENSGACG00000014015,POP1_TAKRU_ENSORLG00000019663)),(POP1_XENTR_B1H1G2,(POP1_ANOCA_ENSACAG00000003910,(POP1_TAEGU_ENSTGUG00000012218,POP1_CHICK_Q9DG23)),POP1_ORNAN_ENSOANG00000004180,POP1_MONDO_ENSMODG00000018034,(POP1_RABIT_ENSOCUG00000016944,(POP1_RAT_Q3BCU4,POP1_MOUSE_Q9ES83),(POP1_HUMAN_Q8NE79,POP1_MACMU_ENSMMUG00000014471))))));" ) ) {
1221 System.out.println( phys3[ 0 ].toNewHampshire() );
1224 final Phylogeny phys4[] = AptxUtil.readPhylogeniesFromUrl( new URL( "http://swisstree.vital-it.ch:80/"
1225 + "SwissTree/ST001/consensus_tree.nhx" ), false, false, false, TAXONOMY_EXTRACTION.NO, false );
1226 if ( ( phys4 == null ) || ( phys4.length != 1 ) ) {
1231 .equals( "((((POP23a_CIOIN_ENSCING00000016202,POP23b_CIOIN_ENSCING00000016169),POP23_CIOSA_ENSCSAVG00000000248),((POP23a_BRAFL_C3ZMF1,POP23b_BRAFL_121417),(((POP3_ORYLA_ENSORLG00000019669,POP3_GASAC_ENSGACG00000014023,POP3_DANRE_Q6JWW1),(POP3_XENTR_B1H1F6,(POP3_CHICK_Q9DG25,(POP3_ORNAN_ENSOANG00000004179,POP3_MONDO_ENSMODG00000018033,((POP3_MOUSE_Q9ES81,POP3_RAT_Q3BCU3),POP3_RABIT_ENSOCUG00000025973,POP3_MACMU_ENSMMUG00000014473,POP3_HUMAN_Q9HBV1))))),(((POP2_GASAC_ENSGACG00000001420,POP2_ORYLA_ENSORLG00000008627,POP2_TAKRU_ENSTRUG00000015933),POP2_DANRE_ENSDARG00000069922),POP2_XENTR_ENSXETG00000018064,(((POP2_TAEGU_ENSTGUG00000013383,POP2_CHICK_Q6T9Z5),POP2_ANOCA_ENSACAG00000003557),((POP2_MACEU_ENSMEUG00000015825,POP2_MONDO_ENSMODG00000018205),((POP2_RABIT_ENSOCUG00000009515,(POP2_RAT_Q6P722,POP2_MOUSE_Q9ES82)),(POP2_MACMU_ENSMMUG00000000905,POP2_HUMAN_Q9HBU9)))))))),((POP1_CIOSA_ENSCSAVG00000000247,POP1_CIOIN_ENSCING00000000496),((POP1_DANRE_Q5PQZ7,(POP1_ORYLA_ENSORLG00000019663,POP1_GASAC_ENSGACG00000014015,POP1_TAKRU_ENSORLG00000019663)),(POP1_XENTR_B1H1G2,(POP1_ANOCA_ENSACAG00000003910,(POP1_TAEGU_ENSTGUG00000012218,POP1_CHICK_Q9DG23)),POP1_ORNAN_ENSOANG00000004180,POP1_MONDO_ENSMODG00000018034,(POP1_RABIT_ENSOCUG00000016944,(POP1_RAT_Q3BCU4,POP1_MOUSE_Q9ES83),(POP1_HUMAN_Q8NE79,POP1_MACMU_ENSMMUG00000014471))))));" ) ) {
1232 System.out.println( phys4[ 0 ].toNewHampshire() );
1236 catch ( final Exception e ) {
1237 e.printStackTrace();
1243 private static final boolean testNHXparsingFromURL() {
1245 final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
1246 final URL u = new URL( s );
1247 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1248 final Phylogeny[] phys = factory.create( u, new NHXParser() );
1249 if ( ( phys == null ) || ( phys.length != 5 ) ) {
1252 if ( !phys[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1253 System.out.println( phys[ 0 ].toNewHampshire() );
1256 if ( !phys[ 1 ].toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1257 System.out.println( phys[ 1 ].toNewHampshire() );
1260 final URL u2 = new URL( s );
1261 final Phylogeny[] phys2 = factory.create( u2.openStream(), new NHXParser() );
1262 if ( ( phys2 == null ) || ( phys2.length != 5 ) ) {
1265 if ( !phys2[ 0 ].toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1266 System.out.println( phys2[ 0 ].toNewHampshire() );
1269 final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1270 final NHXParser p = new NHXParser();
1271 final URL u3 = new URL( s );
1273 if ( !p.hasNext() ) {
1276 if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1279 if ( !p.hasNext() ) {
1283 if ( !p.hasNext() ) {
1286 if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1289 if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1293 if ( !p.hasNext() ) {
1296 if ( !p.next().toNewHampshire().equals( "((((A,B),C),D),(E,F));" ) ) {
1299 if ( !p.next().toNewHampshire().equals( "((1,2,3),(4,5,6),(7,8,9));" ) ) {
1303 catch ( final Exception e ) {
1304 System.out.println( e.toString() );
1305 e.printStackTrace();
1311 private static boolean testOverlapRemoval() {
1313 final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
1314 final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1315 final Domain d2 = new BasicDomain( "d2", ( short ) 0, ( short ) 20, ( short ) 1, ( short ) 1, 0.1, 1 );
1316 final Domain d3 = new BasicDomain( "d3", ( short ) 9, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
1317 final Domain d4 = new BasicDomain( "d4", ( short ) 7, ( short ) 8, ( short ) 1, ( short ) 1, 0.1, 1 );
1318 final List<Boolean> covered = new ArrayList<Boolean>();
1319 covered.add( true ); // 0
1320 covered.add( false ); // 1
1321 covered.add( true ); // 2
1322 covered.add( false ); // 3
1323 covered.add( true ); // 4
1324 covered.add( true ); // 5
1325 covered.add( false ); // 6
1326 covered.add( true ); // 7
1327 covered.add( true ); // 8
1328 if ( ForesterUtil.calculateOverlap( d0, covered ) != 3 ) {
1331 if ( ForesterUtil.calculateOverlap( d1, covered ) != 2 ) {
1334 if ( ForesterUtil.calculateOverlap( d2, covered ) != 6 ) {
1337 if ( ForesterUtil.calculateOverlap( d3, covered ) != 0 ) {
1340 if ( ForesterUtil.calculateOverlap( d4, covered ) != 2 ) {
1343 final Domain a = new BasicDomain( "a", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 1, -1 );
1344 final Domain b = new BasicDomain( "b", ( short ) 2, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, -1 );
1345 final Protein ab = new BasicProtein( "ab", "varanus", 0 );
1346 ab.addProteinDomain( a );
1347 ab.addProteinDomain( b );
1348 final Protein ab_s0 = ForesterUtil.removeOverlappingDomains( 3, false, ab );
1349 if ( ab.getNumberOfProteinDomains() != 2 ) {
1352 if ( ab_s0.getNumberOfProteinDomains() != 1 ) {
1355 if ( !ab_s0.getProteinDomain( 0 ).getDomainId().equals( "b" ) ) {
1358 final Protein ab_s1 = ForesterUtil.removeOverlappingDomains( 4, false, ab );
1359 if ( ab.getNumberOfProteinDomains() != 2 ) {
1362 if ( ab_s1.getNumberOfProteinDomains() != 2 ) {
1365 final Domain c = new BasicDomain( "c", ( short ) 20000, ( short ) 20500, ( short ) 1, ( short ) 1, 10, 1 );
1366 final Domain d = new BasicDomain( "d",
1373 final Domain e = new BasicDomain( "e", ( short ) 5000, ( short ) 5500, ( short ) 1, ( short ) 1, 0.0001, 1 );
1374 final Protein cde = new BasicProtein( "cde", "varanus", 0 );
1375 cde.addProteinDomain( c );
1376 cde.addProteinDomain( d );
1377 cde.addProteinDomain( e );
1378 final Protein cde_s0 = ForesterUtil.removeOverlappingDomains( 0, false, cde );
1379 if ( cde.getNumberOfProteinDomains() != 3 ) {
1382 if ( cde_s0.getNumberOfProteinDomains() != 3 ) {
1385 final Domain f = new BasicDomain( "f", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1386 final Domain g = new BasicDomain( "g", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1387 final Domain h = new BasicDomain( "h", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1388 final Domain i = new BasicDomain( "i", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.5, 1 );
1389 final Domain i2 = new BasicDomain( "i", ( short ) 5, ( short ) 30, ( short ) 1, ( short ) 1, 0.5, 10 );
1390 final Protein fghi = new BasicProtein( "fghi", "varanus", 0 );
1391 fghi.addProteinDomain( f );
1392 fghi.addProteinDomain( g );
1393 fghi.addProteinDomain( h );
1394 fghi.addProteinDomain( i );
1395 fghi.addProteinDomain( i );
1396 fghi.addProteinDomain( i );
1397 fghi.addProteinDomain( i2 );
1398 final Protein fghi_s0 = ForesterUtil.removeOverlappingDomains( 10, false, fghi );
1399 if ( fghi.getNumberOfProteinDomains() != 7 ) {
1402 if ( fghi_s0.getNumberOfProteinDomains() != 1 ) {
1405 if ( !fghi_s0.getProteinDomain( 0 ).getDomainId().equals( "h" ) ) {
1408 final Protein fghi_s1 = ForesterUtil.removeOverlappingDomains( 11, false, fghi );
1409 if ( fghi.getNumberOfProteinDomains() != 7 ) {
1412 if ( fghi_s1.getNumberOfProteinDomains() != 7 ) {
1415 final Domain j = new BasicDomain( "j", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 10, 1 );
1416 final Domain k = new BasicDomain( "k", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.01, 1 );
1417 final Domain l = new BasicDomain( "l", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 1, 0.0001, 1 );
1418 final Domain m = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 1, ( short ) 4, 0.5, 1 );
1419 final Domain m0 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 2, ( short ) 4, 0.5, 1 );
1420 final Domain m1 = new BasicDomain( "m", ( short ) 10, ( short ) 20, ( short ) 3, ( short ) 4, 0.5, 1 );
1421 final Domain m2 = new BasicDomain( "m", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1422 final Protein jklm = new BasicProtein( "jklm", "varanus", 0 );
1423 jklm.addProteinDomain( j );
1424 jklm.addProteinDomain( k );
1425 jklm.addProteinDomain( l );
1426 jklm.addProteinDomain( m );
1427 jklm.addProteinDomain( m0 );
1428 jklm.addProteinDomain( m1 );
1429 jklm.addProteinDomain( m2 );
1430 final Protein jklm_s0 = ForesterUtil.removeOverlappingDomains( 10, false, jklm );
1431 if ( jklm.getNumberOfProteinDomains() != 7 ) {
1434 if ( jklm_s0.getNumberOfProteinDomains() != 1 ) {
1437 if ( !jklm_s0.getProteinDomain( 0 ).getDomainId().equals( "l" ) ) {
1440 final Protein jklm_s1 = ForesterUtil.removeOverlappingDomains( 11, false, jklm );
1441 if ( jklm.getNumberOfProteinDomains() != 7 ) {
1444 if ( jklm_s1.getNumberOfProteinDomains() != 7 ) {
1447 final Domain only = new BasicDomain( "only", ( short ) 5, ( short ) 30, ( short ) 4, ( short ) 4, 0.5, 10 );
1448 final Protein od = new BasicProtein( "od", "varanus", 0 );
1449 od.addProteinDomain( only );
1450 final Protein od_s0 = ForesterUtil.removeOverlappingDomains( 0, false, od );
1451 if ( od.getNumberOfProteinDomains() != 1 ) {
1454 if ( od_s0.getNumberOfProteinDomains() != 1 ) {
1458 catch ( final Exception e ) {
1459 e.printStackTrace( System.out );
1465 private static final boolean testPfamTreeReading() {
1467 final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
1468 final NHXParser parser = new NHXParser();
1469 parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1470 parser.setReplaceUnderscores( false );
1471 parser.setGuessRootedness( true );
1472 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1473 final Phylogeny[] phys = factory.create( u.openStream(), parser );
1474 if ( ( phys == null ) || ( phys.length != 1 ) ) {
1477 if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1481 catch ( final Exception e ) {
1482 e.printStackTrace();
1487 private static final boolean testPhyloXMLparsingFromURL() {
1489 final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
1490 final URL u = new URL( s );
1491 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1492 final Phylogeny[] phys = factory.create( u.openStream(), PhyloXmlParser.createPhyloXmlParser() );
1493 if ( ( phys == null ) || ( phys.length != 2 ) ) {
1497 catch ( final Exception e ) {
1498 e.printStackTrace();
1503 private static final boolean testToLReading() {
1505 final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
1506 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1507 final Phylogeny[] phys = factory.create( u.openStream(), new TolParser() );
1508 if ( ( phys == null ) || ( phys.length != 1 ) ) {
1511 if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) {
1514 if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Protacanthopterygii" ) ) {
1517 if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) {
1521 catch ( final Exception e ) {
1522 e.printStackTrace();
1527 private static final boolean testTreeBaseReading() {
1529 final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "72557?format=nexus" );
1530 System.out.println( u.toString() );
1532 final HttpsURLConnection con = TrustManager.makeHttpsURLConnection( u );
1534 final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
1535 parser.setReplaceUnderscores( true );
1536 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1539 final Phylogeny[] phys = factory.create( con.getInputStream(), parser );
1540 if ( ( phys == null ) || ( phys.length < 1 ) ) {
1543 final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
1544 final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser();
1545 parser2.setReplaceUnderscores( true );
1546 final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
1547 final Phylogeny[] phys2 = factory2.create( u2.openStream(), parser2 );
1548 if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
1552 catch ( final Exception e ) {
1553 e.printStackTrace();
1558 private static final boolean testTreeFamReading() {
1560 final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
1561 final NHXParser parser = new NHXParser();
1562 parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
1563 parser.setReplaceUnderscores( false );
1564 parser.setGuessRootedness( true );
1565 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1566 final Phylogeny[] phys = factory.create( u.openStream(), parser );
1567 if ( ( phys == null ) || ( phys.length != 1 ) ) {
1570 if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) {
1574 catch ( final Exception e ) {
1575 e.printStackTrace();
1580 private final static Phylogeny createPhylogeny( final String nhx ) throws IOException {
1581 final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ];
1585 private final static Event getEvent( final Phylogeny p, final String n1, final String n2 ) {
1586 return PhylogenyMethods.calculateLCA( p.getNode( n1 ), p.getNode( n2 ) ).getNodeData().getEvent();
1589 private static boolean testAminoAcidSequence() {
1591 final MolecularSequence aa1 = BasicSequence.createAaSequence( "aa1", "aAklm-?xX*z$#" );
1592 if ( aa1.getLength() != 13 ) {
1595 if ( aa1.getResidueAt( 0 ) != 'A' ) {
1598 if ( aa1.getResidueAt( 2 ) != 'K' ) {
1601 if ( !new String( aa1.getMolecularSequence() ).equals( "AAKLM-XXX*ZXX" ) ) {
1604 final MolecularSequence aa2 = BasicSequence.createAaSequence( "aa3", "ARNDCQEGHILKMFPSTWYVX*-BZOJU" );
1605 if ( !new String( aa2.getMolecularSequence() ).equals( "ARNDCQEGHILKMFPSTWYVX*-BZOXU" ) ) {
1608 final MolecularSequence dna1 = BasicSequence.createDnaSequence( "dna1", "ACGTUX*-?RYMKWSN" );
1609 if ( !new String( dna1.getMolecularSequence() ).equals( "ACGTNN*-NRYMKWSN" ) ) {
1612 final MolecularSequence rna1 = BasicSequence.createRnaSequence( "rna1", "..ACGUTX*-?RYMKWSN" );
1613 if ( !new String( rna1.getMolecularSequence() ).equals( "--ACGUNN*-NRYMKWSN" ) ) {
1617 catch ( final Exception e ) {
1618 e.printStackTrace();
1624 private static boolean testBasicDomain() {
1626 final Domain pd = new BasicDomain( "id", 23, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
1627 if ( !pd.getDomainId().equals( "id" ) ) {
1630 if ( pd.getNumber() != 1 ) {
1633 if ( pd.getTotalCount() != 4 ) {
1636 if ( !pd.equals( new BasicDomain( "id", 22, 111, ( short ) 1, ( short ) 4, 0.2, -12 ) ) ) {
1639 final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1640 final BasicDomain a1_copy = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1641 final BasicDomain a1_equal = new BasicDomain( "a", 524, 743994, ( short ) 1, ( short ) 300, 3.0005, 230 );
1642 final BasicDomain a2 = new BasicDomain( "a", 1, 10, ( short ) 2, ( short ) 4, 0.1, -12 );
1643 final BasicDomain a3 = new BasicDomain( "A", 1, 10, ( short ) 1, ( short ) 4, 0.1, -12 );
1644 if ( !a1.equals( a1 ) ) {
1647 if ( !a1.equals( a1_copy ) ) {
1650 if ( !a1.equals( a1_equal ) ) {
1653 if ( !a1.equals( a2 ) ) {
1656 if ( a1.equals( a3 ) ) {
1659 if ( a1.compareTo( a1 ) != 0 ) {
1662 if ( a1.compareTo( a1_copy ) != 0 ) {
1665 if ( a1.compareTo( a1_equal ) != 0 ) {
1668 if ( a1.compareTo( a2 ) != 0 ) {
1671 if ( a1.compareTo( a3 ) == 0 ) {
1675 catch ( final Exception e ) {
1676 e.printStackTrace( System.out );
1682 private static boolean testBasicNodeMethods() {
1684 if ( PhylogenyNode.getNodeCount() != 0 ) {
1687 final PhylogenyNode n1 = new PhylogenyNode();
1688 final PhylogenyNode n2 = PhylogenyNode
1689 .createInstanceFromNhxString( "", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1690 final PhylogenyNode n3 = PhylogenyNode
1691 .createInstanceFromNhxString( "n3", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1692 final PhylogenyNode n4 = PhylogenyNode
1693 .createInstanceFromNhxString( "n4:0.01", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1694 if ( n1.isHasAssignedEvent() ) {
1697 if ( PhylogenyNode.getNodeCount() != 4 ) {
1700 if ( n3.getIndicator() != 0 ) {
1703 if ( n3.getNumberOfExternalNodes() != 1 ) {
1706 if ( !n3.isExternal() ) {
1709 if ( !n3.isRoot() ) {
1712 if ( !n4.getName().equals( "n4" ) ) {
1716 catch ( final Exception e ) {
1717 e.printStackTrace( System.out );
1723 private static boolean testBasicPhyloXMLparsing() {
1725 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1726 final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1727 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1729 if ( xml_parser.getErrorCount() > 0 ) {
1730 System.out.println( xml_parser.getErrorMessages().toString() );
1733 if ( phylogenies_0.length != 4 ) {
1736 final Phylogeny t1 = phylogenies_0[ 0 ];
1737 final Phylogeny t2 = phylogenies_0[ 1 ];
1738 final Phylogeny t3 = phylogenies_0[ 2 ];
1739 final Phylogeny t4 = phylogenies_0[ 3 ];
1740 if ( t1.getNumberOfExternalNodes() != 1 ) {
1743 if ( !t1.isRooted() ) {
1746 if ( t1.isRerootable() ) {
1749 if ( !t1.getType().equals( "gene_tree" ) ) {
1752 if ( t2.getNumberOfExternalNodes() != 2 ) {
1755 if ( !isEqual( t2.getNode( "node a" ).getDistanceToParent(), 1.0 ) ) {
1758 if ( !isEqual( t2.getNode( "node b" ).getDistanceToParent(), 2.0 ) ) {
1761 if ( t2.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1764 if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1767 if ( !t2.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1770 if ( t2.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1773 if ( !t2.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1774 .startsWith( "actgtgggggt" ) ) {
1777 if ( !t2.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1778 .startsWith( "ctgtgatgcat" ) ) {
1781 if ( t3.getNumberOfExternalNodes() != 4 ) {
1784 if ( !t1.getName().equals( "t1" ) ) {
1787 if ( !t2.getName().equals( "t2" ) ) {
1790 if ( !t3.getName().equals( "t3" ) ) {
1793 if ( !t4.getName().equals( "t4" ) ) {
1796 if ( !t3.getIdentifier().getValue().equals( "1-1" ) ) {
1799 if ( !t3.getIdentifier().getProvider().equals( "treebank" ) ) {
1802 if ( !t3.getNode( "root node" ).isDuplication() ) {
1805 if ( !t3.getNode( "node a" ).isDuplication() ) {
1808 if ( t3.getNode( "node a" ).isSpeciation() ) {
1811 if ( t3.getNode( "node bc" ).isDuplication() ) {
1814 if ( !t3.getNode( "node bc" ).isSpeciation() ) {
1817 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
1820 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getName()
1821 .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
1824 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
1827 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
1830 if ( !t3.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource().equals( "UniProtKB" ) ) {
1833 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1834 .equals( "apoptosis" ) ) {
1837 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
1838 .equals( "GO:0006915" ) ) {
1841 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
1842 .equals( "UniProtKB" ) ) {
1845 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
1846 .equals( "experimental" ) ) {
1849 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
1850 .equals( "function" ) ) {
1853 if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1854 .getValue() != 1 ) {
1857 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
1858 .getType().equals( "ml" ) ) {
1861 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
1862 .equals( "apoptosis" ) ) {
1865 if ( ( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1866 .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
1869 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1870 .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
1873 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1874 .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
1877 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1878 .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
1881 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1882 .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
1885 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
1886 .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
1889 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
1890 .equals( "GO:0005829" ) ) {
1893 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
1894 .equals( "intracellular organelle" ) ) {
1897 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
1900 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
1901 .equals( "UniProt link" ) ) ) {
1904 if ( !( t3.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
1907 final SortedSet<Accession> x = t3.getNode( "root node" ).getNodeData().getSequence().getCrossReferences();
1908 if ( x.size() != 4 ) {
1912 for( final Accession acc : x ) {
1914 if ( !acc.getSource().equals( "KEGG" ) ) {
1917 if ( !acc.getValue().equals( "hsa:596" ) ) {
1924 catch ( final Exception e ) {
1925 e.printStackTrace( System.out );
1931 private static boolean testBasicPhyloXMLparsingRoundtrip() {
1933 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
1934 final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParser();
1935 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
1936 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
1939 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
1941 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
1943 if ( xml_parser.getErrorCount() > 0 ) {
1944 System.out.println( xml_parser.getErrorMessages().toString() );
1947 if ( phylogenies_0.length != 4 ) {
1950 final StringBuffer t1_sb = new StringBuffer( phylogenies_0[ 0 ].toPhyloXML( 0 ) );
1951 final Phylogeny[] phylogenies_t1 = factory.create( t1_sb, xml_parser );
1952 if ( phylogenies_t1.length != 1 ) {
1955 final Phylogeny t1_rt = phylogenies_t1[ 0 ];
1956 if ( !t1_rt.getDistanceUnit().equals( "cc" ) ) {
1959 if ( !t1_rt.isRooted() ) {
1962 if ( t1_rt.isRerootable() ) {
1965 if ( !t1_rt.getType().equals( "gene_tree" ) ) {
1968 final StringBuffer t2_sb = new StringBuffer( phylogenies_0[ 1 ].toPhyloXML( 0 ) );
1969 final Phylogeny[] phylogenies_t2 = factory.create( t2_sb, xml_parser );
1970 final Phylogeny t2_rt = phylogenies_t2[ 0 ];
1971 if ( t2_rt.getNode( "node a" ).getNodeData().getTaxonomies().size() != 2 ) {
1974 if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 0 ).getCommonName().equals( "some parasite" ) ) {
1977 if ( !t2_rt.getNode( "node a" ).getNodeData().getTaxonomy( 1 ).getCommonName().equals( "the host" ) ) {
1980 if ( t2_rt.getNode( "node a" ).getNodeData().getSequences().size() != 2 ) {
1983 if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 0 ).getMolecularSequence()
1984 .startsWith( "actgtgggggt" ) ) {
1987 if ( !t2_rt.getNode( "node a" ).getNodeData().getSequence( 1 ).getMolecularSequence()
1988 .startsWith( "ctgtgatgcat" ) ) {
1991 final StringBuffer t3_sb_0 = new StringBuffer( phylogenies_0[ 2 ].toPhyloXML( 0 ) );
1992 final Phylogeny[] phylogenies_1_0 = factory.create( t3_sb_0, xml_parser );
1993 final StringBuffer t3_sb = new StringBuffer( phylogenies_1_0[ 0 ].toPhyloXML( 0 ) );
1994 final Phylogeny[] phylogenies_1 = factory.create( t3_sb, xml_parser );
1995 if ( phylogenies_1.length != 1 ) {
1998 final Phylogeny t3_rt = phylogenies_1[ 0 ];
1999 if ( !t3_rt.getName().equals( "t3" ) ) {
2002 if ( t3_rt.getNumberOfExternalNodes() != 4 ) {
2005 if ( !t3_rt.getIdentifier().getValue().equals( "1-1" ) ) {
2008 if ( !t3_rt.getIdentifier().getProvider().equals( "treebank" ) ) {
2011 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getType().equals( "protein" ) ) {
2014 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getName()
2015 .equals( "Apoptosis facilitator Bcl-2-like 14 protein" ) ) {
2018 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getSymbol().equals( "BCL2L14" ) ) {
2021 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getValue().equals( "Q9BZR8" ) ) {
2024 if ( !t3_rt.getNode( "root node" ).getNodeData().getSequence().getAccession().getSource()
2025 .equals( "UniProtKB" ) ) {
2028 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2029 .equals( "apoptosis" ) ) {
2032 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getRef()
2033 .equals( "GO:0006915" ) ) {
2036 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getSource()
2037 .equals( "UniProtKB" ) ) {
2040 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getEvidence()
2041 .equals( "experimental" ) ) {
2044 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getType()
2045 .equals( "function" ) ) {
2048 if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2049 .getValue() != 1 ) {
2052 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getConfidence()
2053 .getType().equals( "ml" ) ) {
2056 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getDesc()
2057 .equals( "apoptosis" ) ) {
2060 if ( ( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2061 .getProperty( "AFFY:expression" ).getAppliesTo() != AppliesTo.ANNOTATION ) {
2064 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2065 .getProperty( "AFFY:expression" ).getDataType().equals( "xsd:double" ) ) {
2068 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2069 .getProperty( "AFFY:expression" ).getRef().equals( "AFFY:expression" ) ) {
2072 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2073 .getProperty( "AFFY:expression" ).getUnit().equals( "AFFY:x" ) ) {
2076 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2077 .getProperty( "AFFY:expression" ).getValue().equals( "0.2" ) ) {
2080 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 2 ) ).getProperties()
2081 .getProperty( "MED:disease" ).getValue().equals( "lymphoma" ) ) {
2084 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 1 ) ).getRef()
2085 .equals( "GO:0005829" ) ) {
2088 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getAnnotation( 0 ) ).getDesc()
2089 .equals( "intracellular organelle" ) ) {
2092 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getType().equals( "source" ) ) ) {
2095 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getUri( 0 ).getDescription()
2096 .equals( "UniProt link" ) ) ) {
2099 if ( !( t3_rt.getNode( "root node" ).getNodeData().getSequence().getLocation().equals( "12p13-p12" ) ) ) {
2102 if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDoi().equals( "10.1038/387489a0" ) ) ) {
2105 if ( !( t3_rt.getNode( "root node" ).getNodeData().getReference().getDescription()
2106 .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." ) ) ) {
2109 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getTaxonomyCode().equals( "ECDYS" ) ) {
2112 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getScientificName().equals( "ecdysozoa" ) ) {
2115 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getCommonName().equals( "molting animals" ) ) {
2118 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
2121 if ( !t3_rt.getNode( "root node" ).getNodeData().getTaxonomy().getIdentifier().getProvider()
2122 .equals( "ncbi" ) ) {
2125 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getTotalLength() != 124 ) {
2128 if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2129 .getName().equals( "B" ) ) {
2132 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2133 .getFrom() != 21 ) {
2136 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getTo() != 44 ) {
2139 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2140 .getLength() != 24 ) {
2143 if ( t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 )
2144 .getConfidence() != 0 ) {
2147 if ( !t3_rt.getNode( "node bc" ).getNodeData().getSequence().getDomainArchitecture().getDomain( 0 ).getId()
2148 .equals( "pfam" ) ) {
2151 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 3 ) {
2154 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2157 if ( t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 1 ) {
2160 if ( !t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().getType().equals( "domains" ) ) {
2163 final Taxonomy taxbb = t3_rt.getNode( "node bb" ).getNodeData().getTaxonomy();
2164 if ( !taxbb.getAuthority().equals( "Stephenson, 1935" ) ) {
2167 if ( !taxbb.getCommonName().equals( "starlet sea anemone" ) ) {
2170 if ( !taxbb.getIdentifier().getProvider().equals( "EOL" ) ) {
2173 if ( !taxbb.getIdentifier().getValue().equals( "704294" ) ) {
2176 if ( !taxbb.getTaxonomyCode().equals( "NEMVE" ) ) {
2179 if ( !taxbb.getScientificName().equals( "Nematostella vectensis" ) ) {
2182 if ( taxbb.getSynonyms().size() != 2 ) {
2185 if ( !taxbb.getSynonyms().contains( "Nematostella vectensis Stephenson1935" ) ) {
2188 if ( !taxbb.getSynonyms().contains( "See Anemone" ) ) {
2191 if ( !taxbb.getUri( 0 ).getDescription().equals( "EOL" ) ) {
2194 if ( !taxbb.getUri( 0 ).getType().equals( "linkout" ) ) {
2197 if ( !taxbb.getUri( 0 ).getValue().toString().equals( "http://www.eol.org/pages/704294" ) ) {
2200 if ( ( ( BinaryCharacters ) t3_rt.getNode( "node bb" ).getNodeData().getBinaryCharacters().copy() )
2201 .getLostCount() != BinaryCharacters.COUNT_DEFAULT ) {
2204 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCount() != 1 ) {
2207 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getGainedCharacters().size() != 1 ) {
2210 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCount() != 3 ) {
2213 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getLostCharacters().size() != 3 ) {
2216 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCount() != 2 ) {
2219 if ( t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getPresentCharacters().size() != 2 ) {
2222 if ( !t3_rt.getNode( "node b" ).getNodeData().getBinaryCharacters().getType().equals( "characters" ) ) {
2225 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getDesc().equals( "Silurian" ) ) {
2228 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getValue().toPlainString()
2229 .equalsIgnoreCase( "435" ) ) {
2232 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMin().toPlainString().equalsIgnoreCase( "416" ) ) {
2235 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getMax().toPlainString()
2236 .equalsIgnoreCase( "443.7" ) ) {
2239 if ( !t3_rt.getNode( "node ba" ).getNodeData().getDate().getUnit().equals( "mya" ) ) {
2242 if ( !t3_rt.getNode( "node bb" ).getNodeData().getDate().getDesc().equals( "Triassic" ) ) {
2245 if ( !t3_rt.getNode( "node bc" ).getNodeData().getDate().getValue().toPlainString()
2246 .equalsIgnoreCase( "433" ) ) {
2249 final SortedSet<Accession> x = t3_rt.getNode( "root node" ).getNodeData().getSequence()
2250 .getCrossReferences();
2251 if ( x.size() != 4 ) {
2255 for( final Accession acc : x ) {
2257 if ( !acc.getSource().equals( "KEGG" ) ) {
2260 if ( !acc.getValue().equals( "hsa:596" ) ) {
2267 catch ( final Exception e ) {
2268 e.printStackTrace( System.out );
2274 private static boolean testBasicPhyloXMLparsingValidating() {
2276 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2277 PhyloXmlParser xml_parser = null;
2279 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
2281 catch ( final Exception e ) {
2282 // Do nothing -- means were not running from jar.
2284 if ( xml_parser == null ) {
2285 xml_parser = PhyloXmlParser.createPhyloXmlParser();
2286 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
2287 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
2290 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
2293 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml",
2295 if ( xml_parser.getErrorCount() > 0 ) {
2296 System.out.println( xml_parser.getErrorMessages().toString() );
2299 if ( phylogenies_0.length != 4 ) {
2302 final Phylogeny t1 = phylogenies_0[ 0 ];
2303 final Phylogeny t2 = phylogenies_0[ 1 ];
2304 final Phylogeny t3 = phylogenies_0[ 2 ];
2305 final Phylogeny t4 = phylogenies_0[ 3 ];
2306 if ( !t1.getName().equals( "t1" ) ) {
2309 if ( !t2.getName().equals( "t2" ) ) {
2312 if ( !t3.getName().equals( "t3" ) ) {
2315 if ( !t4.getName().equals( "t4" ) ) {
2318 if ( t1.getNumberOfExternalNodes() != 1 ) {
2321 if ( t2.getNumberOfExternalNodes() != 2 ) {
2324 if ( t3.getNumberOfExternalNodes() != 4 ) {
2327 final String x2 = Test.PATH_TO_TEST_DATA + "phyloxml_test_t1.xml";
2328 final Phylogeny[] phylogenies_1 = factory.create( x2, xml_parser );
2329 if ( xml_parser.getErrorCount() > 0 ) {
2330 System.out.println( "errors:" );
2331 System.out.println( xml_parser.getErrorMessages().toString() );
2334 if ( phylogenies_1.length != 4 ) {
2337 final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t3.xml",
2339 if ( xml_parser.getErrorCount() > 0 ) {
2340 System.out.println( "errors:" );
2341 System.out.println( xml_parser.getErrorMessages().toString() );
2344 if ( phylogenies_2.length != 1 ) {
2347 if ( phylogenies_2[ 0 ].getNumberOfExternalNodes() != 2 ) {
2350 final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_test_t4.xml",
2352 if ( xml_parser.getErrorCount() > 0 ) {
2353 System.out.println( xml_parser.getErrorMessages().toString() );
2356 if ( phylogenies_3.length != 2 ) {
2359 final Phylogeny a = phylogenies_3[ 0 ];
2360 if ( !a.getName().equals( "tree 4" ) ) {
2363 if ( a.getNumberOfExternalNodes() != 3 ) {
2366 if ( !a.getNode( "node b1" ).getNodeData().getSequence().getName().equals( "b1 gene" ) ) {
2369 if ( !a.getNode( "node b1" ).getNodeData().getTaxonomy().getCommonName().equals( "b1 species" ) ) {
2372 final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "special_characters.xml",
2374 if ( xml_parser.getErrorCount() > 0 ) {
2375 System.out.println( xml_parser.getErrorMessages().toString() );
2378 if ( phylogenies_4.length != 1 ) {
2381 final Phylogeny s = phylogenies_4[ 0 ];
2382 if ( s.getNumberOfExternalNodes() != 6 ) {
2385 s.getNode( "first" );
2387 s.getNode( "\"<a'b&c'd\">\"" );
2388 s.getNode( "'''\"" );
2389 s.getNode( "\"\"\"" );
2390 s.getNode( "dick & doof" );
2392 catch ( final Exception e ) {
2393 e.printStackTrace( System.out );
2399 private static boolean testBasicProtein() {
2401 final BasicProtein p0 = new BasicProtein( "p0", "owl", 0 );
2402 final Domain a = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2403 final Domain b = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2404 final Domain c = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2405 final Domain d = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2406 final Domain e = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2407 final Domain x = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2408 final Domain y = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2409 p0.addProteinDomain( y );
2410 p0.addProteinDomain( e );
2411 p0.addProteinDomain( b );
2412 p0.addProteinDomain( c );
2413 p0.addProteinDomain( d );
2414 p0.addProteinDomain( a );
2415 p0.addProteinDomain( x );
2416 if ( !p0.toDomainArchitectureString( "~" ).equals( "a~b~c~d~e~x~y" ) ) {
2419 if ( !p0.toDomainArchitectureString( "~", 3, "=" ).equals( "a~b~c~d~e~x~y" ) ) {
2423 final BasicProtein aa0 = new BasicProtein( "aa", "owl", 0 );
2424 final Domain a1 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2425 aa0.addProteinDomain( a1 );
2426 if ( !aa0.toDomainArchitectureString( "~" ).equals( "a" ) ) {
2429 if ( !aa0.toDomainArchitectureString( "~", 3, "" ).equals( "a" ) ) {
2433 final BasicProtein aa1 = new BasicProtein( "aa", "owl", 0 );
2434 final Domain a11 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2435 final Domain a12 = new BasicDomain( "a", 2, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2436 aa1.addProteinDomain( a11 );
2437 aa1.addProteinDomain( a12 );
2438 if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a" ) ) {
2441 if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "a~a" ) ) {
2444 aa1.addProteinDomain( new BasicDomain( "a", 20, 30, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2445 if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a" ) ) {
2448 if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2451 if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "a~a~a" ) ) {
2454 aa1.addProteinDomain( new BasicDomain( "a", 30, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2455 if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a" ) ) {
2458 if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa" ) ) {
2461 if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa" ) ) {
2464 if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a" ) ) {
2467 aa1.addProteinDomain( new BasicDomain( "b", 32, 40, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2468 if ( !aa1.toDomainArchitectureString( "~" ).equals( "a~a~a~a~b" ) ) {
2471 if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "aaa~b" ) ) {
2474 if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "aaa~b" ) ) {
2477 if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "a~a~a~a~b" ) ) {
2480 aa1.addProteinDomain( new BasicDomain( "c", 1, 2, ( short ) 1, ( short ) 5, 0.1, -12 ) );
2481 if ( !aa1.toDomainArchitectureString( "~" ).equals( "c~a~a~a~a~b" ) ) {
2484 if ( !aa1.toDomainArchitectureString( "~", 3, "" ).equals( "c~aaa~b" ) ) {
2487 if ( !aa1.toDomainArchitectureString( "~", 4, "" ).equals( "c~aaa~b" ) ) {
2490 if ( !aa1.toDomainArchitectureString( "~", 5, "" ).equals( "c~a~a~a~a~b" ) ) {
2494 final BasicProtein p00 = new BasicProtein( "p0", "owl", 0 );
2495 final Domain a0 = new BasicDomain( "a", 1, 10, ( short ) 1, ( short ) 5, 0.1, -12 );
2496 final Domain b0 = new BasicDomain( "b", 11, 20, ( short ) 1, ( short ) 5, 0.1, -12 );
2497 final Domain c0 = new BasicDomain( "c", 9, 23, ( short ) 1, ( short ) 5, 0.1, -12 );
2498 final Domain d0 = new BasicDomain( "d", 15, 30, ( short ) 1, ( short ) 5, 0.1, -12 );
2499 final Domain e0 = new BasicDomain( "e", 60, 70, ( short ) 1, ( short ) 5, 0.1, -12 );
2500 final Domain e1 = new BasicDomain( "e", 61, 71, ( short ) 1, ( short ) 5, 0.1, -12 );
2501 final Domain e2 = new BasicDomain( "e", 62, 72, ( short ) 1, ( short ) 5, 0.1, -12 );
2502 final Domain e3 = new BasicDomain( "e", 63, 73, ( short ) 1, ( short ) 5, 0.1, -12 );
2503 final Domain e4 = new BasicDomain( "e", 64, 74, ( short ) 1, ( short ) 5, 0.1, -12 );
2504 final Domain e5 = new BasicDomain( "e", 65, 75, ( short ) 1, ( short ) 5, 0.1, -12 );
2505 final Domain x0 = new BasicDomain( "x", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2506 final Domain y0 = new BasicDomain( "y", 100, 110, ( short ) 1, ( short ) 5, 0.1, -12 );
2507 final Domain y1 = new BasicDomain( "y", 120, 130, ( short ) 1, ( short ) 5, 0.1, -12 );
2508 final Domain y2 = new BasicDomain( "y", 140, 150, ( short ) 1, ( short ) 5, 0.1, -12 );
2509 final Domain y3 = new BasicDomain( "y", 160, 170, ( short ) 1, ( short ) 5, 0.1, -12 );
2510 final Domain z0 = new BasicDomain( "z", 200, 210, ( short ) 1, ( short ) 5, 0.1, -12 );
2511 final Domain z1 = new BasicDomain( "z", 300, 310, ( short ) 1, ( short ) 5, 0.1, -12 );
2512 final Domain z2 = new BasicDomain( "z", 400, 410, ( short ) 1, ( short ) 5, 0.1, -12 );
2513 final Domain zz0 = new BasicDomain( "Z", 500, 510, ( short ) 1, ( short ) 5, 0.1, -12 );
2514 final Domain zz1 = new BasicDomain( "Z", 600, 610, ( short ) 1, ( short ) 5, 0.1, -12 );
2515 p00.addProteinDomain( y0 );
2516 p00.addProteinDomain( e0 );
2517 p00.addProteinDomain( b0 );
2518 p00.addProteinDomain( c0 );
2519 p00.addProteinDomain( d0 );
2520 p00.addProteinDomain( a0 );
2521 p00.addProteinDomain( x0 );
2522 p00.addProteinDomain( y1 );
2523 p00.addProteinDomain( y2 );
2524 p00.addProteinDomain( y3 );
2525 p00.addProteinDomain( e1 );
2526 p00.addProteinDomain( e2 );
2527 p00.addProteinDomain( e3 );
2528 p00.addProteinDomain( e4 );
2529 p00.addProteinDomain( e5 );
2530 p00.addProteinDomain( z0 );
2531 p00.addProteinDomain( z1 );
2532 p00.addProteinDomain( z2 );
2533 p00.addProteinDomain( zz0 );
2534 p00.addProteinDomain( zz1 );
2535 if ( !p00.toDomainArchitectureString( "~", 3, "" ).equals( "a~b~c~d~eee~x~yyy~zzz~Z~Z" ) ) {
2538 if ( !p00.toDomainArchitectureString( "~", 4, "" ).equals( "a~b~c~d~eee~x~yyy~z~z~z~Z~Z" ) ) {
2541 if ( !p00.toDomainArchitectureString( "~", 5, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2544 if ( !p00.toDomainArchitectureString( "~", 6, "" ).equals( "a~b~c~d~eee~x~y~y~y~y~z~z~z~Z~Z" ) ) {
2547 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" ) ) {
2550 // A0 A10 B15 A20 B25 A30 B35 B40 C50 A60 C70 D80
2551 final Domain A0 = new BasicDomain( "A", 0, 25, ( short ) 1, ( short ) 4, 0.1, -12 );
2552 final Domain A10 = new BasicDomain( "A", 10, 11, ( short ) 1, ( short ) 4, 0.1, -12 );
2553 final Domain B15 = new BasicDomain( "B", 11, 16, ( short ) 1, ( short ) 4, 0.1, -12 );
2554 final Domain A20 = new BasicDomain( "A", 20, 100, ( short ) 1, ( short ) 4, 0.1, -12 );
2555 final Domain B25 = new BasicDomain( "B", 25, 26, ( short ) 1, ( short ) 4, 0.1, -12 );
2556 final Domain A30 = new BasicDomain( "A", 30, 31, ( short ) 1, ( short ) 4, 0.1, -12 );
2557 final Domain B35 = new BasicDomain( "B", 31, 40, ( short ) 1, ( short ) 4, 0.1, -12 );
2558 final Domain B40 = new BasicDomain( "B", 40, 600, ( short ) 1, ( short ) 4, 0.1, -12 );
2559 final Domain C50 = new BasicDomain( "C", 50, 59, ( short ) 1, ( short ) 4, 0.1, -12 );
2560 final Domain A60 = new BasicDomain( "A", 60, 395, ( short ) 1, ( short ) 4, 0.1, -12 );
2561 final Domain C70 = new BasicDomain( "C", 70, 71, ( short ) 1, ( short ) 4, 0.1, -12 );
2562 final Domain D80 = new BasicDomain( "D", 80, 81, ( short ) 1, ( short ) 4, 0.1, -12 );
2563 final BasicProtein p = new BasicProtein( "p", "owl", 0 );
2564 p.addProteinDomain( B15 );
2565 p.addProteinDomain( C50 );
2566 p.addProteinDomain( A60 );
2567 p.addProteinDomain( A30 );
2568 p.addProteinDomain( C70 );
2569 p.addProteinDomain( B35 );
2570 p.addProteinDomain( B40 );
2571 p.addProteinDomain( A0 );
2572 p.addProteinDomain( A10 );
2573 p.addProteinDomain( A20 );
2574 p.addProteinDomain( B25 );
2575 p.addProteinDomain( D80 );
2576 List<String> domains_ids = new ArrayList<String>();
2577 domains_ids.add( "A" );
2578 domains_ids.add( "B" );
2579 domains_ids.add( "C" );
2580 if ( !p.contains( domains_ids, false ) ) {
2583 if ( !p.contains( domains_ids, true ) ) {
2586 domains_ids.add( "X" );
2587 if ( p.contains( domains_ids, false ) ) {
2590 if ( p.contains( domains_ids, true ) ) {
2593 domains_ids = new ArrayList<String>();
2594 domains_ids.add( "A" );
2595 domains_ids.add( "C" );
2596 domains_ids.add( "D" );
2597 if ( !p.contains( domains_ids, false ) ) {
2600 if ( !p.contains( domains_ids, true ) ) {
2603 domains_ids = new ArrayList<String>();
2604 domains_ids.add( "A" );
2605 domains_ids.add( "D" );
2606 domains_ids.add( "C" );
2607 if ( !p.contains( domains_ids, false ) ) {
2610 if ( p.contains( domains_ids, true ) ) {
2613 domains_ids = new ArrayList<String>();
2614 domains_ids.add( "A" );
2615 domains_ids.add( "A" );
2616 domains_ids.add( "B" );
2617 if ( !p.contains( domains_ids, false ) ) {
2620 if ( !p.contains( domains_ids, true ) ) {
2623 domains_ids = new ArrayList<String>();
2624 domains_ids.add( "A" );
2625 domains_ids.add( "A" );
2626 domains_ids.add( "A" );
2627 domains_ids.add( "B" );
2628 domains_ids.add( "B" );
2629 if ( !p.contains( domains_ids, false ) ) {
2632 if ( !p.contains( domains_ids, true ) ) {
2635 domains_ids = new ArrayList<String>();
2636 domains_ids.add( "A" );
2637 domains_ids.add( "A" );
2638 domains_ids.add( "B" );
2639 domains_ids.add( "A" );
2640 domains_ids.add( "B" );
2641 domains_ids.add( "B" );
2642 domains_ids.add( "A" );
2643 domains_ids.add( "B" );
2644 domains_ids.add( "C" );
2645 domains_ids.add( "A" );
2646 domains_ids.add( "C" );
2647 domains_ids.add( "D" );
2648 if ( !p.contains( domains_ids, false ) ) {
2651 if ( p.contains( domains_ids, true ) ) {
2655 catch ( final Exception e ) {
2656 e.printStackTrace( System.out );
2662 private static boolean testBasicTable() {
2664 final BasicTable<String> t0 = new BasicTable<String>();
2665 if ( t0.getNumberOfColumns() != 0 ) {
2668 if ( t0.getNumberOfRows() != 0 ) {
2671 t0.setValue( 3, 2, "23" );
2672 t0.setValue( 10, 1, "error" );
2673 t0.setValue( 10, 1, "110" );
2674 t0.setValue( 9, 1, "19" );
2675 t0.setValue( 1, 10, "101" );
2676 t0.setValue( 10, 10, "1010" );
2677 t0.setValue( 100, 10, "10100" );
2678 t0.setValue( 0, 0, "00" );
2679 if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
2682 if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
2685 if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
2688 if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
2691 if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
2694 if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
2697 if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
2700 if ( t0.getNumberOfColumns() != 101 ) {
2703 if ( t0.getNumberOfRows() != 11 ) {
2706 if ( t0.getValueAsString( 49, 4 ) != null ) {
2709 final String l = ForesterUtil.getLineSeparator();
2710 final StringBuffer source = new StringBuffer();
2711 source.append( "" + l );
2712 source.append( "# 1 1 1 1 1 1 1 1" + l );
2713 source.append( " 00 01 02 03" + l );
2714 source.append( " 10 11 12 13 " + l );
2715 source.append( "20 21 22 23 " + l );
2716 source.append( " 30 31 32 33" + l );
2717 source.append( "40 41 42 43" + l );
2718 source.append( " # 1 1 1 1 1 " + l );
2719 source.append( "50 51 52 53 54" + l );
2720 final BasicTable<String> t1 = BasicTableParser.parse( source.toString(), ' ' );
2721 if ( t1.getNumberOfColumns() != 5 ) {
2724 if ( t1.getNumberOfRows() != 6 ) {
2727 if ( !t1.getValueAsString( 0, 0 ).equals( "00" ) ) {
2730 if ( !t1.getValueAsString( 1, 0 ).equals( "01" ) ) {
2733 if ( !t1.getValueAsString( 3, 0 ).equals( "03" ) ) {
2736 if ( !t1.getValueAsString( 4, 5 ).equals( "54" ) ) {
2739 final StringBuffer source1 = new StringBuffer();
2740 source1.append( "" + l );
2741 source1.append( "# 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2742 source1.append( " 00; 01 ;02;03" + l );
2743 source1.append( " 10; 11; 12; 13 " + l );
2744 source1.append( "20; 21; 22; 23 " + l );
2745 source1.append( " 30; 31; 32; 33" + l );
2746 source1.append( "40;41;42;43" + l );
2747 source1.append( " # 1 1 1 1 1 " + l );
2748 source1.append( ";;;50 ; ;52; 53;;54 " + l );
2749 final BasicTable<String> t2 = BasicTableParser.parse( source1.toString(), ';' );
2750 if ( t2.getNumberOfColumns() != 5 ) {
2753 if ( t2.getNumberOfRows() != 6 ) {
2756 if ( !t2.getValueAsString( 0, 0 ).equals( "00" ) ) {
2759 if ( !t2.getValueAsString( 1, 0 ).equals( "01" ) ) {
2762 if ( !t2.getValueAsString( 3, 0 ).equals( "03" ) ) {
2765 if ( !t2.getValueAsString( 3, 3 ).equals( "33" ) ) {
2768 if ( !t2.getValueAsString( 3, 5 ).equals( "53" ) ) {
2771 if ( !t2.getValueAsString( 1, 5 ).equals( "" ) ) {
2774 final StringBuffer source2 = new StringBuffer();
2775 source2.append( "" + l );
2776 source2.append( "comment: 1; 1; 1; 1 ;1 ;1; 1 ;1;" + l );
2777 source2.append( " 00; 01 ;02;03" + l );
2778 source2.append( " 10; 11; 12; 13 " + l );
2779 source2.append( "20; 21; 22; 23 " + l );
2780 source2.append( " " + l );
2781 source2.append( " 30; 31; 32; 33" + l );
2782 source2.append( "40;41;42;43" + l );
2783 source2.append( " comment: 1 1 1 1 1 " + l );
2784 source2.append( ";;;50 ; 52; 53;;54 " + l );
2785 final List<BasicTable<String>> tl = BasicTableParser.parse( source2.toString(),
2791 if ( tl.size() != 2 ) {
2794 final BasicTable<String> t3 = tl.get( 0 );
2795 final BasicTable<String> t4 = tl.get( 1 );
2796 if ( t3.getNumberOfColumns() != 4 ) {
2799 if ( t3.getNumberOfRows() != 3 ) {
2802 if ( t4.getNumberOfColumns() != 4 ) {
2805 if ( t4.getNumberOfRows() != 3 ) {
2808 if ( !t3.getValueAsString( 0, 0 ).equals( "00" ) ) {
2811 if ( !t4.getValueAsString( 0, 0 ).equals( "30" ) ) {
2815 catch ( final Exception e ) {
2816 e.printStackTrace( System.out );
2822 private static boolean testBasicTolXMLparsing() {
2824 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2825 final TolParser parser = new TolParser();
2826 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2484.tol", parser );
2827 if ( parser.getErrorCount() > 0 ) {
2828 System.out.println( parser.getErrorMessages().toString() );
2831 if ( phylogenies_0.length != 1 ) {
2834 final Phylogeny t1 = phylogenies_0[ 0 ];
2835 if ( t1.getNumberOfExternalNodes() != 5 ) {
2838 if ( !t1.isRooted() ) {
2841 if ( !t1.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Mesozoa" ) ) {
2844 if ( !t1.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2484" ) ) {
2847 if ( !t1.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Rhombozoa" ) ) {
2850 if ( t1.getRoot().getChildNode( 0 ).getNumberOfDescendants() != 3 ) {
2853 final Phylogeny[] phylogenies_1 = factory.create( Test.PATH_TO_TEST_DATA + "tol_2.tol", parser );
2854 if ( parser.getErrorCount() > 0 ) {
2855 System.out.println( parser.getErrorMessages().toString() );
2858 if ( phylogenies_1.length != 1 ) {
2861 final Phylogeny t2 = phylogenies_1[ 0 ];
2862 if ( t2.getNumberOfExternalNodes() != 664 ) {
2865 if ( !t2.isRooted() ) {
2868 if ( !t2.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Eubacteria" ) ) {
2871 if ( !t2.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "2" ) ) {
2874 if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2877 if ( t2.getRoot().getNumberOfDescendants() != 24 ) {
2880 if ( !t2.getRoot().getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName().equals( "Aquificae" ) ) {
2883 if ( !t2.getRoot().getChildNode( 0 ).getChildNode( 0 ).getNodeData().getTaxonomy().getScientificName()
2884 .equals( "Aquifex" ) ) {
2887 final Phylogeny[] phylogenies_2 = factory.create( Test.PATH_TO_TEST_DATA + "tol_5.tol", parser );
2888 if ( parser.getErrorCount() > 0 ) {
2889 System.out.println( parser.getErrorMessages().toString() );
2892 if ( phylogenies_2.length != 1 ) {
2895 final Phylogeny t3 = phylogenies_2[ 0 ];
2896 if ( t3.getNumberOfExternalNodes() != 184 ) {
2899 if ( !t3.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Viruses" ) ) {
2902 if ( !t3.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "5" ) ) {
2905 if ( t3.getRoot().getNumberOfDescendants() != 6 ) {
2908 final Phylogeny[] phylogenies_3 = factory.create( Test.PATH_TO_TEST_DATA + "tol_4567.tol", parser );
2909 if ( parser.getErrorCount() > 0 ) {
2910 System.out.println( parser.getErrorMessages().toString() );
2913 if ( phylogenies_3.length != 1 ) {
2916 final Phylogeny t4 = phylogenies_3[ 0 ];
2917 if ( t4.getNumberOfExternalNodes() != 1 ) {
2920 if ( !t4.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Marpissa decorata" ) ) {
2923 if ( !t4.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "4567" ) ) {
2926 if ( t4.getRoot().getNumberOfDescendants() != 0 ) {
2929 final Phylogeny[] phylogenies_4 = factory.create( Test.PATH_TO_TEST_DATA + "tol_16299.tol", parser );
2930 if ( parser.getErrorCount() > 0 ) {
2931 System.out.println( parser.getErrorMessages().toString() );
2934 if ( phylogenies_4.length != 1 ) {
2937 final Phylogeny t5 = phylogenies_4[ 0 ];
2938 if ( t5.getNumberOfExternalNodes() != 13 ) {
2941 if ( !t5.getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Hominidae" ) ) {
2944 if ( !t5.getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "16299" ) ) {
2947 if ( t5.getRoot().getNumberOfDescendants() != 2 ) {
2951 catch ( final Exception e ) {
2952 e.printStackTrace( System.out );
2958 private static boolean testBasicTreeMethods() {
2960 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
2961 final Phylogeny t2 = factory.create( "((A:1,B:2)AB:1,(C:3,D:5)CD:3)ABCD:0.5", new NHXParser() )[ 0 ];
2962 if ( t2.getNumberOfExternalNodes() != 4 ) {
2965 if ( t2.getHeight() != 8.5 ) {
2968 if ( !t2.isCompletelyBinary() ) {
2971 if ( t2.isEmpty() ) {
2974 final Phylogeny t3 = factory.create( "((A:1,B:2,C:10)ABC:1,(D:3,E:5)DE:3)", new NHXParser() )[ 0 ];
2975 if ( t3.getNumberOfExternalNodes() != 5 ) {
2978 if ( t3.getHeight() != 11 ) {
2981 if ( t3.isCompletelyBinary() ) {
2984 final PhylogenyNode n = t3.getNode( "ABC" );
2985 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 ];
2986 if ( t4.getNumberOfExternalNodes() != 9 ) {
2989 if ( t4.getHeight() != 11 ) {
2992 if ( t4.isCompletelyBinary() ) {
2995 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)" );
2996 final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
2997 if ( t5.getNumberOfExternalNodes() != 8 ) {
3000 if ( t5.getHeight() != 15 ) {
3003 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)" );
3004 final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
3005 if ( t6.getHeight() != 15 ) {
3008 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)" );
3009 final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
3010 if ( t7.getHeight() != 15 ) {
3013 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)" );
3014 final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
3015 if ( t8.getNumberOfExternalNodes() != 10 ) {
3018 if ( t8.getHeight() != 15 ) {
3021 final char[] a9 = new char[] { 'a' };
3022 final Phylogeny t9 = factory.create( a9, new NHXParser() )[ 0 ];
3023 if ( t9.getHeight() != 0 ) {
3026 final char[] a10 = new char[] { 'a', ':', '6' };
3027 final Phylogeny t10 = factory.create( a10, new NHXParser() )[ 0 ];
3028 if ( t10.getHeight() != 6 ) {
3032 catch ( final Exception e ) {
3033 e.printStackTrace( System.out );
3039 private static boolean testConfidenceAssessor() {
3041 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3042 final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3043 final Phylogeny[] ev0 = factory
3044 .create( "((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);((((A,B),C),D),E);",
3046 ConfidenceAssessor.evaluate( "bootstrap", ev0, t0, false, 1, 0, 2 );
3047 if ( !isEqual( t0.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3050 if ( !isEqual( t0.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 3 ) ) {
3053 final Phylogeny t1 = factory.create( "((((A,B)ab[&&NHX:B=50],C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3054 final Phylogeny[] ev1 = factory
3055 .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)));",
3057 ConfidenceAssessor.evaluate( "bootstrap", ev1, t1, false, 1 );
3058 if ( !isEqual( t1.getNode( "ab" ).getBranchData().getConfidence( 1 ).getValue(), 7 ) ) {
3061 if ( !isEqual( t1.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3064 final Phylogeny t_b = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3065 final Phylogeny[] ev_b = factory
3066 .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",
3068 ConfidenceAssessor.evaluate( "bootstrap", ev_b, t_b, false, 1 );
3069 if ( !isEqual( t_b.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 4 ) ) {
3072 if ( !isEqual( t_b.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3076 final Phylogeny t1x = factory.create( "((((A,B)ab,C)abc,D)abcd,E)abcde", new NHXParser() )[ 0 ];
3077 final Phylogeny[] ev1x = factory
3078 .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)));",
3080 ConfidenceAssessor.evaluate( "bootstrap", ev1x, t1x, true, 1 );
3081 if ( !isEqual( t1x.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3084 if ( !isEqual( t1x.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 7 ) ) {
3087 final Phylogeny t_bx = factory.create( "((((A,C)ac,D)acd,E)acde,B)abcde", new NHXParser() )[ 0 ];
3088 final Phylogeny[] ev_bx = factory
3089 .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",
3091 ConfidenceAssessor.evaluate( "bootstrap", ev_bx, t_bx, true, 1 );
3092 if ( !isEqual( t_bx.getNode( "ac" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3095 if ( !isEqual( t_bx.getNode( "acd" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3098 final Phylogeny[] t2 = factory
3099 .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);",
3101 final Phylogeny[] ev2 = factory
3102 .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);",
3104 for( final Phylogeny target : t2 ) {
3105 ConfidenceAssessor.evaluate( "bootstrap", ev2, target, false, 1 );
3107 final Phylogeny t4 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,G)abcdefg",
3108 new NHXParser() )[ 0 ];
3109 final Phylogeny[] ev4 = factory.create( "(((A,B),C),(X,Y));((F,G),((A,B,C),(D,E)))", new NHXParser() );
3110 ConfidenceAssessor.evaluate( "bootstrap", ev4, t4, false, 1 );
3111 if ( !isEqual( t4.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3114 if ( !isEqual( t4.getNode( "abc" ).getBranchData().getConfidence( 0 ).getValue(), 2 ) ) {
3117 if ( !isEqual( t4.getNode( "abcde" ).getBranchData().getConfidence( 0 ).getValue(), 1 ) ) {
3121 catch ( final Exception e ) {
3122 e.printStackTrace();
3128 private static boolean testCopyOfNodeData() {
3130 final PhylogenyNode n1 = PhylogenyNode
3131 .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]" );
3132 final PhylogenyNode n2 = n1.copyNodeData();
3133 if ( !n1.toNewHampshireX().equals( n2.toNewHampshireX() ) ) {
3137 catch ( final Exception e ) {
3138 e.printStackTrace();
3144 private static boolean testCreateBalancedPhylogeny() {
3146 final Phylogeny p0 = DevelopmentTools.createBalancedPhylogeny( 6, 5 );
3147 if ( p0.getRoot().getNumberOfDescendants() != 5 ) {
3150 if ( p0.getNumberOfExternalNodes() != 15625 ) {
3153 final Phylogeny p1 = DevelopmentTools.createBalancedPhylogeny( 2, 10 );
3154 if ( p1.getRoot().getNumberOfDescendants() != 10 ) {
3157 if ( p1.getNumberOfExternalNodes() != 100 ) {
3161 catch ( final Exception e ) {
3162 e.printStackTrace();
3168 private static boolean testCreateUriForSeqWeb() {
3170 final PhylogenyNode n = new PhylogenyNode();
3171 n.setName( "tr|B3RJ64" );
3172 if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B3RJ64" ) ) {
3175 n.setName( "B0LM41_HUMAN" );
3176 if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "B0LM41_HUMAN" ) ) {
3179 n.setName( "NP_001025424" );
3180 if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "NP_001025424" ) ) {
3183 n.setName( "_NM_001030253-" );
3184 if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "NM_001030253" ) ) {
3187 n.setName( "XM_002122186" );
3188 if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_NUCCORE + "XM_002122186" ) ) {
3191 n.setName( "dgh_AAA34956_gdg" );
3192 if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3195 n.setName( "AAA34956" );
3196 if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_PROTEIN + "AAA34956" ) ) {
3199 n.setName( "GI:394892" );
3200 if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3201 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3204 n.setName( "gi_394892" );
3205 if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3206 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3209 n.setName( "gi6335_gi_394892_56635_Gi_43" );
3210 if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.NCBI_GI + "394892" ) ) {
3211 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3214 n.setName( "P12345" );
3215 if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3216 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3219 n.setName( "gi_fdgjmn-3jk5-243 mnefmn fg023-0 P12345 4395jtmnsrg02345m1ggi92450jrg890j4t0j240" );
3220 if ( !TreePanelUtil.createUriForSeqWeb( n, null, null ).equals( ForesterUtil.UNIPROT_KB + "P12345" ) ) {
3221 System.out.println( TreePanelUtil.createUriForSeqWeb( n, null, null ) );
3225 catch ( final Exception e ) {
3226 e.printStackTrace( System.out );
3232 private static boolean testDataObjects() {
3234 final Confidence s0 = new Confidence();
3235 final Confidence s1 = new Confidence();
3236 if ( !s0.isEqual( s1 ) ) {
3239 final Confidence s2 = new Confidence( 0.23, "bootstrap" );
3240 final Confidence s3 = new Confidence( 0.23, "bootstrap" );
3241 if ( s2.isEqual( s1 ) ) {
3244 if ( !s2.isEqual( s3 ) ) {
3247 final Confidence s4 = ( Confidence ) s3.copy();
3248 if ( !s4.isEqual( s3 ) ) {
3255 final Taxonomy t1 = new Taxonomy();
3256 final Taxonomy t2 = new Taxonomy();
3257 final Taxonomy t3 = new Taxonomy();
3258 final Taxonomy t4 = new Taxonomy();
3259 final Taxonomy t5 = new Taxonomy();
3260 t1.setIdentifier( new Identifier( "ecoli" ) );
3261 t1.setTaxonomyCode( "ECOLI" );
3262 t1.setScientificName( "E. coli" );
3263 t1.setCommonName( "coli" );
3264 final Taxonomy t0 = ( Taxonomy ) t1.copy();
3265 if ( !t1.isEqual( t0 ) ) {
3268 t2.setIdentifier( new Identifier( "ecoli" ) );
3269 t2.setTaxonomyCode( "OTHER" );
3270 t2.setScientificName( "what" );
3271 t2.setCommonName( "something" );
3272 if ( !t1.isEqual( t2 ) ) {
3275 t2.setIdentifier( new Identifier( "nemve" ) );
3276 if ( t1.isEqual( t2 ) ) {
3279 t1.setIdentifier( null );
3280 t3.setTaxonomyCode( "ECOLI" );
3281 t3.setScientificName( "what" );
3282 t3.setCommonName( "something" );
3283 if ( !t1.isEqual( t3 ) ) {
3286 t1.setIdentifier( null );
3287 t1.setTaxonomyCode( "" );
3288 t4.setScientificName( "E. ColI" );
3289 t4.setCommonName( "something" );
3290 if ( !t1.isEqual( t4 ) ) {
3293 t4.setScientificName( "B. subtilis" );
3294 t4.setCommonName( "something" );
3295 if ( t1.isEqual( t4 ) ) {
3298 t1.setIdentifier( null );
3299 t1.setTaxonomyCode( "" );
3300 t1.setScientificName( "" );
3301 t5.setCommonName( "COLI" );
3302 if ( !t1.isEqual( t5 ) ) {
3305 t5.setCommonName( "vibrio" );
3306 if ( t1.isEqual( t5 ) ) {
3311 final Identifier id0 = new Identifier( "123", "pfam" );
3312 final Identifier id1 = ( Identifier ) id0.copy();
3313 if ( !id1.isEqual( id1 ) ) {
3316 if ( !id1.isEqual( id0 ) ) {
3319 if ( !id0.isEqual( id1 ) ) {
3326 final ProteinDomain pd0 = new ProteinDomain( "abc", 100, 200 );
3327 final ProteinDomain pd1 = ( ProteinDomain ) pd0.copy();
3328 if ( !pd1.isEqual( pd1 ) ) {
3331 if ( !pd1.isEqual( pd0 ) ) {
3336 final ProteinDomain pd2 = new ProteinDomain( pd0.getName(), pd0.getFrom(), pd0.getTo(), "id" );
3337 final ProteinDomain pd3 = ( ProteinDomain ) pd2.copy();
3338 if ( !pd3.isEqual( pd3 ) ) {
3341 if ( !pd2.isEqual( pd3 ) ) {
3344 if ( !pd0.isEqual( pd3 ) ) {
3349 // DomainArchitecture
3350 // ------------------
3351 final ProteinDomain d0 = new ProteinDomain( "domain0", 10, 20 );
3352 final ProteinDomain d1 = new ProteinDomain( "domain1", 30, 40 );
3353 final ProteinDomain d2 = new ProteinDomain( "domain2", 50, 60 );
3354 final ProteinDomain d3 = new ProteinDomain( "domain3", 70, 80 );
3355 final ProteinDomain d4 = new ProteinDomain( "domain4", 90, 100 );
3356 final ArrayList<PhylogenyData> domains0 = new ArrayList<PhylogenyData>();
3361 final DomainArchitecture ds0 = new DomainArchitecture( domains0, 110 );
3362 if ( ds0.getNumberOfDomains() != 4 ) {
3365 final DomainArchitecture ds1 = ( DomainArchitecture ) ds0.copy();
3366 if ( !ds0.isEqual( ds0 ) ) {
3369 if ( !ds0.isEqual( ds1 ) ) {
3372 if ( ds1.getNumberOfDomains() != 4 ) {
3375 final ArrayList<PhylogenyData> domains1 = new ArrayList<PhylogenyData>();
3380 final DomainArchitecture ds2 = new DomainArchitecture( domains1, 200 );
3381 if ( ds0.isEqual( ds2 ) ) {
3387 final DomainArchitecture ds3 = new DomainArchitecture( "120>30>40>0.9>b>50>60>0.4>c>10>20>0.1>a" );
3388 if ( !ds3.toNHX().toString().equals( ":DS=120>10>20>0.1>a>30>40>0.9>b>50>60>0.4>c" ) ) {
3389 System.out.println( ds3.toNHX() );
3392 if ( ds3.getNumberOfDomains() != 3 ) {
3397 final Event e1 = new Event( Event.EventType.fusion );
3398 if ( e1.isDuplication() ) {
3401 if ( !e1.isFusion() ) {
3404 if ( !e1.asText().toString().equals( "fusion" ) ) {
3407 if ( !e1.asSimpleText().toString().equals( "fusion" ) ) {
3410 final Event e11 = new Event( Event.EventType.fusion );
3411 if ( !e11.isEqual( e1 ) ) {
3414 if ( !e11.toNHX().toString().equals( "" ) ) {
3417 final Event e2 = new Event( Event.EventType.speciation_or_duplication );
3418 if ( e2.isDuplication() ) {
3421 if ( !e2.isSpeciationOrDuplication() ) {
3424 if ( !e2.asText().toString().equals( "speciation_or_duplication" ) ) {
3427 if ( !e2.asSimpleText().toString().equals( "?" ) ) {
3430 if ( !e2.toNHX().toString().equals( ":D=?" ) ) {
3433 if ( e11.isEqual( e2 ) ) {
3436 final Event e2c = ( Event ) e2.copy();
3437 if ( !e2c.isEqual( e2 ) ) {
3440 Event e3 = new Event( 1, 2, 3 );
3441 if ( e3.isDuplication() ) {
3444 if ( e3.isSpeciation() ) {
3447 if ( e3.isGeneLoss() ) {
3450 if ( !e3.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3453 final Event e3c = ( Event ) e3.copy();
3454 final Event e3cc = ( Event ) e3c.copy();
3455 if ( !e3c.asSimpleText().toString().equals( "D2S3L" ) ) {
3459 if ( !e3c.isEqual( e3cc ) ) {
3462 Event e4 = new Event( 1, 2, 3 );
3463 if ( !e4.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3466 if ( !e4.asSimpleText().toString().equals( "D2S3L" ) ) {
3469 final Event e4c = ( Event ) e4.copy();
3471 final Event e4cc = ( Event ) e4c.copy();
3472 if ( !e4cc.asText().toString().equals( "duplications [1] speciations [2] gene-losses [3]" ) ) {
3475 if ( !e4c.isEqual( e4cc ) ) {
3478 final Event e5 = new Event();
3479 if ( !e5.isUnassigned() ) {
3482 if ( !e5.asText().toString().equals( "unassigned" ) ) {
3485 if ( !e5.asSimpleText().toString().equals( "" ) ) {
3488 final Event e6 = new Event( 1, 0, 0 );
3489 if ( !e6.asText().toString().equals( "duplication" ) ) {
3492 if ( !e6.asSimpleText().toString().equals( "D" ) ) {
3495 final Event e7 = new Event( 0, 1, 0 );
3496 if ( !e7.asText().toString().equals( "speciation" ) ) {
3499 if ( !e7.asSimpleText().toString().equals( "S" ) ) {
3502 final Event e8 = new Event( 0, 0, 1 );
3503 if ( !e8.asText().toString().equals( "gene-loss" ) ) {
3506 if ( !e8.asSimpleText().toString().equals( "L" ) ) {
3510 catch ( final Exception e ) {
3511 e.printStackTrace( System.out );
3517 private static boolean testDeletionOfExternalNodes() {
3519 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
3520 final Phylogeny t0 = factory.create( "A", new NHXParser() )[ 0 ];
3521 final PhylogenyWriter w = new PhylogenyWriter();
3522 if ( t0.isEmpty() ) {
3525 if ( t0.getNumberOfExternalNodes() != 1 ) {
3528 t0.deleteSubtree( t0.getNode( "A" ), false );
3529 if ( t0.getNumberOfExternalNodes() != 0 ) {
3532 if ( !t0.isEmpty() ) {
3535 final Phylogeny t1 = factory.create( "(A,B)r", new NHXParser() )[ 0 ];
3536 if ( t1.getNumberOfExternalNodes() != 2 ) {
3539 t1.deleteSubtree( t1.getNode( "A" ), false );
3540 if ( t1.getNumberOfExternalNodes() != 1 ) {
3543 if ( !t1.getNode( "B" ).getName().equals( "B" ) ) {
3546 t1.deleteSubtree( t1.getNode( "B" ), false );
3547 if ( t1.getNumberOfExternalNodes() != 1 ) {
3550 t1.deleteSubtree( t1.getNode( "r" ), false );
3551 if ( !t1.isEmpty() ) {
3554 final Phylogeny t2 = factory.create( "((A,B),C)", new NHXParser() )[ 0 ];
3555 if ( t2.getNumberOfExternalNodes() != 3 ) {
3558 t2.deleteSubtree( t2.getNode( "B" ), false );
3559 if ( t2.getNumberOfExternalNodes() != 2 ) {
3562 t2.toNewHampshireX();
3563 PhylogenyNode n = t2.getNode( "A" );
3564 if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3567 t2.deleteSubtree( t2.getNode( "A" ), false );
3568 if ( t2.getNumberOfExternalNodes() != 2 ) {
3571 t2.deleteSubtree( t2.getNode( "C" ), true );
3572 if ( t2.getNumberOfExternalNodes() != 1 ) {
3575 final Phylogeny t3 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
3576 if ( t3.getNumberOfExternalNodes() != 4 ) {
3579 t3.deleteSubtree( t3.getNode( "B" ), true );
3580 if ( t3.getNumberOfExternalNodes() != 3 ) {
3583 n = t3.getNode( "A" );
3584 if ( !n.getNextExternalNode().getName().equals( "C" ) ) {
3587 n = n.getNextExternalNode();
3588 if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3591 t3.deleteSubtree( t3.getNode( "A" ), true );
3592 if ( t3.getNumberOfExternalNodes() != 2 ) {
3595 n = t3.getNode( "C" );
3596 if ( !n.getNextExternalNode().getName().equals( "D" ) ) {
3599 t3.deleteSubtree( t3.getNode( "C" ), true );
3600 if ( t3.getNumberOfExternalNodes() != 1 ) {
3603 t3.deleteSubtree( t3.getNode( "D" ), true );
3604 if ( t3.getNumberOfExternalNodes() != 0 ) {
3607 final Phylogeny t4 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3608 if ( t4.getNumberOfExternalNodes() != 6 ) {
3611 t4.deleteSubtree( t4.getNode( "B2" ), true );
3612 if ( t4.getNumberOfExternalNodes() != 5 ) {
3615 String s = w.toNewHampshire( t4, true ).toString();
3616 if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3619 t4.deleteSubtree( t4.getNode( "B11" ), true );
3620 if ( t4.getNumberOfExternalNodes() != 4 ) {
3623 t4.deleteSubtree( t4.getNode( "C" ), true );
3624 if ( t4.getNumberOfExternalNodes() != 3 ) {
3627 n = t4.getNode( "A" );
3628 n = n.getNextExternalNode();
3629 if ( !n.getName().equals( "B12" ) ) {
3632 n = n.getNextExternalNode();
3633 if ( !n.getName().equals( "D" ) ) {
3636 s = w.toNewHampshire( t4, true ).toString();
3637 if ( !s.equals( "((A,B12),D);" ) ) {
3640 final Phylogeny t5 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3641 t5.deleteSubtree( t5.getNode( "A" ), true );
3642 if ( t5.getNumberOfExternalNodes() != 5 ) {
3645 s = w.toNewHampshire( t5, true ).toString();
3646 if ( !s.equals( "(((B11,B12),B2),(C,D));" ) ) {
3649 final Phylogeny t6 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3650 t6.deleteSubtree( t6.getNode( "B11" ), true );
3651 if ( t6.getNumberOfExternalNodes() != 5 ) {
3654 s = w.toNewHampshire( t6, false ).toString();
3655 if ( !s.equals( "((A,(B12,B2)),(C,D));" ) ) {
3658 final Phylogeny t7 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3659 t7.deleteSubtree( t7.getNode( "B12" ), true );
3660 if ( t7.getNumberOfExternalNodes() != 5 ) {
3663 s = w.toNewHampshire( t7, true ).toString();
3664 if ( !s.equals( "((A,(B11,B2)),(C,D));" ) ) {
3667 final Phylogeny t8 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3668 t8.deleteSubtree( t8.getNode( "B2" ), true );
3669 if ( t8.getNumberOfExternalNodes() != 5 ) {
3672 s = w.toNewHampshire( t8, false ).toString();
3673 if ( !s.equals( "((A,(B11,B12)),(C,D));" ) ) {
3676 final Phylogeny t9 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3677 t9.deleteSubtree( t9.getNode( "C" ), true );
3678 if ( t9.getNumberOfExternalNodes() != 5 ) {
3681 s = w.toNewHampshire( t9, true ).toString();
3682 if ( !s.equals( "((A,((B11,B12),B2)),D);" ) ) {
3685 final Phylogeny t10 = factory.create( "((A,((B11,B12),B2)),(C,D))", new NHXParser() )[ 0 ];
3686 t10.deleteSubtree( t10.getNode( "D" ), true );
3687 if ( t10.getNumberOfExternalNodes() != 5 ) {
3690 s = w.toNewHampshire( t10, true ).toString();
3691 if ( !s.equals( "((A,((B11,B12),B2)),C);" ) ) {
3694 final Phylogeny t11 = factory.create( "(A,B,C)", new NHXParser() )[ 0 ];
3695 t11.deleteSubtree( t11.getNode( "A" ), true );
3696 if ( t11.getNumberOfExternalNodes() != 2 ) {
3699 s = w.toNewHampshire( t11, true ).toString();
3700 if ( !s.equals( "(B,C);" ) ) {
3703 t11.deleteSubtree( t11.getNode( "C" ), true );
3704 if ( t11.getNumberOfExternalNodes() != 1 ) {
3707 s = w.toNewHampshire( t11, false ).toString();
3708 if ( !s.equals( "B;" ) ) {
3711 final Phylogeny t12 = factory.create( "((A1,A2,A3),(B1,B2,B3),(C1,C2,C3))", new NHXParser() )[ 0 ];
3712 t12.deleteSubtree( t12.getNode( "B2" ), true );
3713 if ( t12.getNumberOfExternalNodes() != 8 ) {
3716 s = w.toNewHampshire( t12, true ).toString();
3717 if ( !s.equals( "((A1,A2,A3),(B1,B3),(C1,C2,C3));" ) ) {
3720 t12.deleteSubtree( t12.getNode( "B3" ), true );
3721 if ( t12.getNumberOfExternalNodes() != 7 ) {
3724 s = w.toNewHampshire( t12, true ).toString();
3725 if ( !s.equals( "((A1,A2,A3),B1,(C1,C2,C3));" ) ) {
3728 t12.deleteSubtree( t12.getNode( "C3" ), true );
3729 if ( t12.getNumberOfExternalNodes() != 6 ) {
3732 s = w.toNewHampshire( t12, true ).toString();
3733 if ( !s.equals( "((A1,A2,A3),B1,(C1,C2));" ) ) {
3736 t12.deleteSubtree( t12.getNode( "A1" ), true );
3737 if ( t12.getNumberOfExternalNodes() != 5 ) {
3740 s = w.toNewHampshire( t12, true ).toString();
3741 if ( !s.equals( "((A2,A3),B1,(C1,C2));" ) ) {
3744 t12.deleteSubtree( t12.getNode( "B1" ), true );
3745 if ( t12.getNumberOfExternalNodes() != 4 ) {
3748 s = w.toNewHampshire( t12, true ).toString();
3749 if ( !s.equals( "((A2,A3),(C1,C2));" ) ) {
3752 t12.deleteSubtree( t12.getNode( "A3" ), true );
3753 if ( t12.getNumberOfExternalNodes() != 3 ) {
3756 s = w.toNewHampshire( t12, true ).toString();
3757 if ( !s.equals( "(A2,(C1,C2));" ) ) {
3760 t12.deleteSubtree( t12.getNode( "A2" ), true );
3761 if ( t12.getNumberOfExternalNodes() != 2 ) {
3764 s = w.toNewHampshire( t12, true ).toString();
3765 if ( !s.equals( "(C1,C2);" ) ) {
3768 final Phylogeny t13 = factory.create( "(A,B,C,(D:1.0,E:2.0):3.0)", new NHXParser() )[ 0 ];
3769 t13.deleteSubtree( t13.getNode( "D" ), true );
3770 if ( t13.getNumberOfExternalNodes() != 4 ) {
3773 s = w.toNewHampshire( t13, true ).toString();
3774 if ( !s.equals( "(A,B,C,E:5.0);" ) ) {
3777 final Phylogeny t14 = factory.create( "((A,B,C,(D:0.1,E:0.4):1.0),F)", new NHXParser() )[ 0 ];
3778 t14.deleteSubtree( t14.getNode( "E" ), true );
3779 if ( t14.getNumberOfExternalNodes() != 5 ) {
3782 s = w.toNewHampshire( t14, true ).toString();
3783 if ( !s.equals( "((A,B,C,D:1.1),F);" ) ) {
3786 final Phylogeny t15 = factory.create( "((A1,A2,A3,A4),(B1,B2,B3,B4),(C1,C2,C3,C4))", new NHXParser() )[ 0 ];
3787 t15.deleteSubtree( t15.getNode( "B2" ), true );
3788 if ( t15.getNumberOfExternalNodes() != 11 ) {
3791 t15.deleteSubtree( t15.getNode( "B1" ), true );
3792 if ( t15.getNumberOfExternalNodes() != 10 ) {
3795 t15.deleteSubtree( t15.getNode( "B3" ), true );
3796 if ( t15.getNumberOfExternalNodes() != 9 ) {
3799 t15.deleteSubtree( t15.getNode( "B4" ), true );
3800 if ( t15.getNumberOfExternalNodes() != 8 ) {
3803 t15.deleteSubtree( t15.getNode( "A1" ), true );
3804 if ( t15.getNumberOfExternalNodes() != 7 ) {
3807 t15.deleteSubtree( t15.getNode( "C4" ), true );
3808 if ( t15.getNumberOfExternalNodes() != 6 ) {
3812 catch ( final Exception e ) {
3813 e.printStackTrace( System.out );
3819 private static boolean testDescriptiveStatistics() {
3821 final DescriptiveStatistics dss1 = new BasicDescriptiveStatistics();
3822 dss1.addValue( 82 );
3823 dss1.addValue( 78 );
3824 dss1.addValue( 70 );
3825 dss1.addValue( 58 );
3826 dss1.addValue( 42 );
3827 if ( dss1.getN() != 5 ) {
3830 if ( !Test.isEqual( dss1.getMin(), 42 ) ) {
3833 if ( !Test.isEqual( dss1.getMax(), 82 ) ) {
3836 if ( !Test.isEqual( dss1.arithmeticMean(), 66 ) ) {
3839 if ( !Test.isEqual( dss1.sampleStandardDeviation(), 16.24807680927192 ) ) {
3842 if ( !Test.isEqual( dss1.median(), 70 ) ) {
3845 if ( !Test.isEqual( dss1.midrange(), 62 ) ) {
3848 if ( !Test.isEqual( dss1.sampleVariance(), 264 ) ) {
3851 if ( !Test.isEqual( dss1.pearsonianSkewness(), -0.7385489458759964 ) ) {
3854 if ( !Test.isEqual( dss1.coefficientOfVariation(), 0.24618298195866547 ) ) {
3857 if ( !Test.isEqual( dss1.sampleStandardUnit( 66 - 16.24807680927192 ), -1.0 ) ) {
3860 if ( !Test.isEqual( dss1.getValue( 1 ), 78 ) ) {
3863 dss1.addValue( 123 );
3864 if ( !Test.isEqual( dss1.arithmeticMean(), 75.5 ) ) {
3867 if ( !Test.isEqual( dss1.getMax(), 123 ) ) {
3870 if ( !Test.isEqual( dss1.standardErrorOfMean(), 11.200446419674531 ) ) {
3873 final DescriptiveStatistics dss2 = new BasicDescriptiveStatistics();
3874 dss2.addValue( -1.85 );
3875 dss2.addValue( 57.5 );
3876 dss2.addValue( 92.78 );
3877 dss2.addValue( 57.78 );
3878 if ( !Test.isEqual( dss2.median(), 57.64 ) ) {
3881 if ( !Test.isEqual( dss2.sampleStandardDeviation(), 39.266984753946495 ) ) {
3884 final double[] a = dss2.getDataAsDoubleArray();
3885 if ( !Test.isEqual( a[ 3 ], 57.78 ) ) {
3888 dss2.addValue( -100 );
3889 if ( !Test.isEqual( dss2.sampleStandardDeviation(), 75.829111296388 ) ) {
3892 if ( !Test.isEqual( dss2.sampleVariance(), 5750.05412 ) ) {
3895 final double[] ds = new double[ 14 ];
3910 final int[] bins = BasicDescriptiveStatistics.performBinning( ds, 0, 40, 4 );
3911 if ( bins.length != 4 ) {
3914 if ( bins[ 0 ] != 2 ) {
3917 if ( bins[ 1 ] != 3 ) {
3920 if ( bins[ 2 ] != 4 ) {
3923 if ( bins[ 3 ] != 5 ) {
3926 final double[] ds1 = new double[ 9 ];
3936 final int[] bins1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 4 );
3937 if ( bins1.length != 4 ) {
3940 if ( bins1[ 0 ] != 2 ) {
3943 if ( bins1[ 1 ] != 3 ) {
3946 if ( bins1[ 2 ] != 0 ) {
3949 if ( bins1[ 3 ] != 4 ) {
3952 final int[] bins1_1 = BasicDescriptiveStatistics.performBinning( ds1, 0, 40, 3 );
3953 if ( bins1_1.length != 3 ) {
3956 if ( bins1_1[ 0 ] != 3 ) {
3959 if ( bins1_1[ 1 ] != 2 ) {
3962 if ( bins1_1[ 2 ] != 4 ) {
3965 final int[] bins1_2 = BasicDescriptiveStatistics.performBinning( ds1, 1, 39, 3 );
3966 if ( bins1_2.length != 3 ) {
3969 if ( bins1_2[ 0 ] != 2 ) {
3972 if ( bins1_2[ 1 ] != 2 ) {
3975 if ( bins1_2[ 2 ] != 2 ) {
3978 final DescriptiveStatistics dss3 = new BasicDescriptiveStatistics();
3992 dss3.addValue( 10 );
3993 dss3.addValue( 10 );
3994 dss3.addValue( 10 );
3995 final AsciiHistogram histo = new AsciiHistogram( dss3 );
3996 histo.toStringBuffer( 10, '=', 40, 5 );
3997 histo.toStringBuffer( 3, 8, 10, '=', 40, 5, null );
3999 catch ( final Exception e ) {
4000 e.printStackTrace( System.out );
4006 private static boolean testDir( final String file ) {
4008 final File f = new File( file );
4009 if ( !f.exists() ) {
4012 if ( !f.isDirectory() ) {
4015 if ( !f.canRead() ) {
4019 catch ( final Exception e ) {
4025 private static boolean testEbiEntryRetrieval() {
4027 final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainEntry( "AAK41263" );
4028 if ( !entry.getAccession().equals( "AAK41263" ) ) {
4029 System.out.println( entry.getAccession() );
4032 if ( !entry.getTaxonomyScientificName().equals( "Sulfolobus solfataricus P2" ) ) {
4033 System.out.println( entry.getTaxonomyScientificName() );
4036 if ( !entry.getSequenceName()
4037 .equals( "Sulfolobus solfataricus P2 Glycogen debranching enzyme, hypothetical (treX-like)" ) ) {
4038 System.out.println( entry.getSequenceName() );
4041 if ( !entry.getGeneName().equals( "treX-like" ) ) {
4042 System.out.println( entry.getGeneName() );
4045 if ( !entry.getTaxonomyIdentifier().equals( "273057" ) ) {
4046 System.out.println( entry.getTaxonomyIdentifier() );
4049 if ( !entry.getAnnotations().first().getRefValue().equals( "3.2.1.33" ) ) {
4050 System.out.println( entry.getAnnotations().first().getRefValue() );
4053 if ( !entry.getAnnotations().first().getRefSource().equals( "EC" ) ) {
4054 System.out.println( entry.getAnnotations().first().getRefSource() );
4057 if ( entry.getCrossReferences().size() < 1 ) {
4060 final SequenceDatabaseEntry entry1 = SequenceDbWsTools.obtainEntry( "ABJ16409" );
4061 if ( !entry1.getAccession().equals( "ABJ16409" ) ) {
4064 if ( !entry1.getTaxonomyScientificName().equals( "Felis catus" ) ) {
4065 System.out.println( entry1.getTaxonomyScientificName() );
4068 if ( !entry1.getSequenceName().equals( "Felis catus (domestic cat) partial BCL2" ) ) {
4069 System.out.println( entry1.getSequenceName() );
4072 if ( !entry1.getTaxonomyIdentifier().equals( "9685" ) ) {
4073 System.out.println( entry1.getTaxonomyIdentifier() );
4076 if ( !entry1.getGeneName().equals( "BCL2" ) ) {
4077 System.out.println( entry1.getGeneName() );
4080 if ( entry1.getCrossReferences().size() < 1 ) {
4083 final SequenceDatabaseEntry entry2 = SequenceDbWsTools.obtainEntry( "NM_184234" );
4084 if ( !entry2.getAccession().equals( "NM_184234" ) ) {
4087 if ( !entry2.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4088 System.out.println( entry2.getTaxonomyScientificName() );
4091 if ( !entry2.getSequenceName()
4092 .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
4093 System.out.println( entry2.getSequenceName() );
4096 if ( !entry2.getTaxonomyIdentifier().equals( "9606" ) ) {
4097 System.out.println( entry2.getTaxonomyIdentifier() );
4100 if ( !entry2.getGeneName().equals( "RBM39" ) ) {
4101 System.out.println( entry2.getGeneName() );
4104 if ( entry2.getCrossReferences().size() < 1 ) {
4107 if ( !entry2.getChromosome().equals( "20" ) ) {
4110 if ( !entry2.getMap().equals( "20q11.22" ) ) {
4113 final SequenceDatabaseEntry entry3 = SequenceDbWsTools.obtainEntry( "HM043801" );
4114 if ( !entry3.getAccession().equals( "HM043801" ) ) {
4117 if ( !entry3.getTaxonomyScientificName().equals( "Bursaphelenchus xylophilus" ) ) {
4118 System.out.println( entry3.getTaxonomyScientificName() );
4121 if ( !entry3.getSequenceName().equals( "Bursaphelenchus xylophilus RAF gene, complete cds" ) ) {
4122 System.out.println( entry3.getSequenceName() );
4125 if ( !entry3.getTaxonomyIdentifier().equals( "6326" ) ) {
4126 System.out.println( entry3.getTaxonomyIdentifier() );
4129 if ( !entry3.getSequenceSymbol().equals( "RAF" ) ) {
4130 System.out.println( entry3.getSequenceSymbol() );
4133 if ( !ForesterUtil.isEmpty( entry3.getGeneName() ) ) {
4136 if ( entry3.getCrossReferences().size() < 1 ) {
4139 final SequenceDatabaseEntry entry4 = SequenceDbWsTools.obtainEntry( "AAA36557.1" );
4140 if ( !entry4.getAccession().equals( "AAA36557" ) ) {
4143 if ( !entry4.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4144 System.out.println( entry4.getTaxonomyScientificName() );
4147 if ( !entry4.getSequenceName().equals( "Homo sapiens (human) ras protein" ) ) {
4148 System.out.println( entry4.getSequenceName() );
4151 if ( !entry4.getTaxonomyIdentifier().equals( "9606" ) ) {
4152 System.out.println( entry4.getTaxonomyIdentifier() );
4155 if ( !entry4.getGeneName().equals( "ras" ) ) {
4156 System.out.println( entry4.getGeneName() );
4159 final SequenceDatabaseEntry entry5 = SequenceDbWsTools.obtainEntry( "AAZ45343.1" );
4160 if ( !entry5.getAccession().equals( "AAZ45343" ) ) {
4163 if ( !entry5.getTaxonomyScientificName().equals( "Dechloromonas aromatica RCB" ) ) {
4164 System.out.println( entry5.getTaxonomyScientificName() );
4167 if ( !entry5.getSequenceName().equals( "Dechloromonas aromatica RCB 1,4-alpha-glucan branching enzyme" ) ) {
4168 System.out.println( entry5.getSequenceName() );
4171 if ( !entry5.getTaxonomyIdentifier().equals( "159087" ) ) {
4172 System.out.println( entry5.getTaxonomyIdentifier() );
4175 final SequenceDatabaseEntry entry6 = SequenceDbWsTools.obtainEntry( "M30539" );
4176 if ( !entry6.getAccession().equals( "M30539" ) ) {
4179 if ( !entry6.getGeneName().equals( "ras" ) ) {
4182 if ( !entry6.getSequenceName().equals( "Human SK2 c-Ha-ras-1 oncogene-encoded protein gene, exon 1" ) ) {
4185 if ( !entry6.getTaxonomyIdentifier().equals( "9606" ) ) {
4188 if ( !entry6.getTaxonomyScientificName().equals( "Homo sapiens" ) ) {
4191 if ( entry6.getCrossReferences().size() < 1 ) {
4195 catch ( final IOException e ) {
4196 System.out.println();
4197 System.out.println( "the following might be due to absence internet connection:" );
4198 e.printStackTrace( System.out );
4201 catch ( final Exception e ) {
4202 e.printStackTrace();
4208 private static boolean testExternalNodeRelatedMethods() {
4210 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
4211 final Phylogeny t1 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4212 PhylogenyNode n = t1.getNode( "A" );
4213 n = n.getNextExternalNode();
4214 if ( !n.getName().equals( "B" ) ) {
4217 n = n.getNextExternalNode();
4218 if ( !n.getName().equals( "C" ) ) {
4221 n = n.getNextExternalNode();
4222 if ( !n.getName().equals( "D" ) ) {
4225 n = t1.getNode( "B" );
4226 while ( !n.isLastExternalNode() ) {
4227 n = n.getNextExternalNode();
4229 final Phylogeny t2 = factory.create( "(((A,B),C),D)", new NHXParser() )[ 0 ];
4230 n = t2.getNode( "A" );
4231 n = n.getNextExternalNode();
4232 if ( !n.getName().equals( "B" ) ) {
4235 n = n.getNextExternalNode();
4236 if ( !n.getName().equals( "C" ) ) {
4239 n = n.getNextExternalNode();
4240 if ( !n.getName().equals( "D" ) ) {
4243 n = t2.getNode( "B" );
4244 while ( !n.isLastExternalNode() ) {
4245 n = n.getNextExternalNode();
4247 final Phylogeny t3 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4248 n = t3.getNode( "A" );
4249 n = n.getNextExternalNode();
4250 if ( !n.getName().equals( "B" ) ) {
4253 n = n.getNextExternalNode();
4254 if ( !n.getName().equals( "C" ) ) {
4257 n = n.getNextExternalNode();
4258 if ( !n.getName().equals( "D" ) ) {
4261 n = n.getNextExternalNode();
4262 if ( !n.getName().equals( "E" ) ) {
4265 n = n.getNextExternalNode();
4266 if ( !n.getName().equals( "F" ) ) {
4269 n = n.getNextExternalNode();
4270 if ( !n.getName().equals( "G" ) ) {
4273 n = n.getNextExternalNode();
4274 if ( !n.getName().equals( "H" ) ) {
4277 n = t3.getNode( "B" );
4278 while ( !n.isLastExternalNode() ) {
4279 n = n.getNextExternalNode();
4281 final Phylogeny t4 = factory.create( "((A,B),(C,D))", new NHXParser() )[ 0 ];
4282 for( final PhylogenyNodeIterator iter = t4.iteratorExternalForward(); iter.hasNext(); ) {
4283 final PhylogenyNode node = iter.next();
4285 final Phylogeny t5 = factory.create( "(((A,B),(C,D)),((E,F),(G,H)))", new NHXParser() )[ 0 ];
4286 for( final PhylogenyNodeIterator iter = t5.iteratorExternalForward(); iter.hasNext(); ) {
4287 final PhylogenyNode node = iter.next();
4289 final Phylogeny t6 = factory.create( "((((((A))),(((B))),((C)),((((D)))),E)),((F)))", new NHXParser() )[ 0 ];
4290 final PhylogenyNodeIterator iter = t6.iteratorExternalForward();
4291 if ( !iter.next().getName().equals( "A" ) ) {
4294 if ( !iter.next().getName().equals( "B" ) ) {
4297 if ( !iter.next().getName().equals( "C" ) ) {
4300 if ( !iter.next().getName().equals( "D" ) ) {
4303 if ( !iter.next().getName().equals( "E" ) ) {
4306 if ( !iter.next().getName().equals( "F" ) ) {
4309 if ( iter.hasNext() ) {
4313 catch ( final Exception e ) {
4314 e.printStackTrace( System.out );
4320 private static boolean testExtractSNFromNodeName() {
4322 if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2_Mus_musculus" ).equals( "Mus musculus" ) ) {
4325 if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus" ).equals( "Mus musculus" ) ) {
4328 if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCDO2" ).equals( "Mus musculus" ) ) {
4331 if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus musculus BCDO2" )
4332 .equals( "Mus musculus musculus" ) ) {
4335 if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_BCDO2" )
4336 .equals( "Mus musculus musculus" ) ) {
4339 if ( !ParserUtils.extractScientificNameFromNodeName( "BCDO2 Mus musculus musculus" )
4340 .equals( "Mus musculus musculus" ) ) {
4343 if ( !ParserUtils.extractScientificNameFromNodeName( "Bcl Mus musculus musculus" )
4344 .equals( "Mus musculus musculus" ) ) {
4347 if ( ParserUtils.extractScientificNameFromNodeName( "vcl Mus musculus musculus" ) != null ) {
4350 if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_BCDO2" )
4351 .equals( "Mus musculus musculus" ) ) {
4354 if ( !ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_Musculus" )
4355 .equals( "Mus musculus musculus" ) ) {
4358 if ( ParserUtils.extractScientificNameFromNodeName( "could_be_anything_Mus_musculus_musculus_musculus" ) != null ) {
4361 if ( ParserUtils.extractScientificNameFromNodeName( "musculus" ) != null ) {
4364 if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus" ) != null ) {
4367 if ( ParserUtils.extractScientificNameFromNodeName( "mus_musculus_musculus" ) != null ) {
4370 if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_1" )
4371 .equals( "Mus musculus musculus" ) ) {
4374 if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_1" ).equals( "Mus musculus" ) ) {
4377 if ( ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_bcl" ) != null ) {
4380 if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_BCL" ).equals( "Mus musculus" ) ) {
4383 if ( ParserUtils.extractScientificNameFromNodeName( "Mus musculus bcl" ) != null ) {
4386 if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus BCL" ).equals( "Mus musculus" ) ) {
4389 if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus xBCL" ).equals( "Mus musculus" ) ) {
4392 if ( !ParserUtils.extractScientificNameFromNodeName( "Mus musculus x1" ).equals( "Mus musculus" ) ) {
4395 if ( !ParserUtils.extractScientificNameFromNodeName( " -XS12_Mus_musculus_12" ).equals( "Mus musculus" ) ) {
4398 if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12 affrre e" )
4399 .equals( "Mus musculus" ) ) {
4402 if ( !ParserUtils.extractScientificNameFromNodeName( " -1234_Mus_musculus_12_affrre_e" )
4403 .equals( "Mus musculus" ) ) {
4406 if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus" ).equals( "Mus musculus" ) ) {
4409 if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4410 .equals( "Mus musculus musculus" ) ) {
4413 if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_2bcl2" )
4414 .equals( "Mus musculus musculus" ) ) {
4417 if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_musculus_bcl2" )
4418 .equals( "Mus musculus musculus" ) ) {
4421 if ( !ParserUtils.extractScientificNameFromNodeName( "Mus_musculus_123" ).equals( "Mus musculus" ) ) {
4424 if ( !ParserUtils.extractScientificNameFromNodeName( "Pilostyles mexicana Mexico Breedlove 27233" )
4425 .equals( "Pilostyles mexicana" ) ) {
4428 if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_strain_K12/DH10B" )
4429 .equals( "Escherichia coli strain K12/DH10B" ) ) {
4432 if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K12/DH10B" )
4433 .equals( "Escherichia coli str. K12/DH10B" ) ) {
4436 if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K12/DH10B" )
4437 .equals( "Escherichia coli str. K12/DH10B" ) ) {
4440 if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis_lyrata_subsp_lyrata" )
4441 .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4444 if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata" )
4445 .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4448 if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata 395" )
4449 .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4452 if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp. lyrata bcl2" )
4453 .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4456 if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subsp lyrata bcl2" )
4457 .equals( "Arabidopsis lyrata subsp. lyrata" ) ) {
4460 if ( !ParserUtils.extractScientificNameFromNodeName( "Arabidopsis lyrata subspecies lyrata bcl2" )
4461 .equals( "Arabidopsis lyrata subspecies lyrata" ) ) {
4464 if ( !ParserUtils.extractScientificNameFromNodeName( "Verbascum sinuatum var. adenosepalum bcl2" )
4465 .equals( "Verbascum sinuatum var. adenosepalum" ) ) {
4468 if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12)" )
4469 .equals( "Escherichia coli (strain K12)" ) ) {
4472 if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (strain K12) bcl2" )
4473 .equals( "Escherichia coli (strain K12)" ) ) {
4476 if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12)" )
4477 .equals( "Escherichia coli (str. K12)" ) ) {
4480 if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str K12)" )
4481 .equals( "Escherichia coli (str. K12)" ) ) {
4484 if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (str. K12) bcl2" )
4485 .equals( "Escherichia coli (str. K12)" ) ) {
4488 if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli (var K12) bcl2" )
4489 .equals( "Escherichia coli (var. K12)" ) ) {
4492 if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str. K-12 substr. MG1655star" )
4493 .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4496 if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star" )
4497 .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4501 .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star" )
4502 .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4505 if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia coli str K-12 substr MG1655star gene1" )
4506 .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4510 .extractScientificNameFromNodeName( "could be anything Escherichia coli str K-12 substr MG1655star GENE1" )
4511 .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4514 if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4515 .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4518 if ( !ParserUtils.extractScientificNameFromNodeName( "Escherichia_coli_str_K-12_substr_MG1655star" )
4519 .equals( "Escherichia coli str. K-12 substr. MG1655star" ) ) {
4522 if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp." ).equals( "Macrocera sp." ) ) {
4525 if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. 123" ).equals( "Macrocera sp." ) ) {
4528 if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp. K12" ).equals( "Macrocera sp." ) ) {
4531 if ( !ParserUtils.extractScientificNameFromNodeName( "something Macrocera sp. K12" )
4532 .equals( "Macrocera sp." ) ) {
4535 if ( !ParserUtils.extractScientificNameFromNodeName( "Macrocera sp" ).equals( "Macrocera sp." ) ) {
4538 if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp merenskyanum 07 48" )
4539 .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4542 if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum ssp. merenskyanum" )
4543 .equals( "Sesamum rigidum subsp. merenskyanum" ) ) {
4546 if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp. merenskyanum)" )
4547 .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4550 if ( !ParserUtils.extractScientificNameFromNodeName( "Sesamum rigidum (ssp merenskyanum)" )
4551 .equals( "Sesamum rigidum (subsp. merenskyanum)" ) ) {
4555 catch ( final Exception e ) {
4556 e.printStackTrace( System.out );
4562 private static boolean testExtractTaxonomyDataFromNodeName() {
4564 PhylogenyNode n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN" );
4565 if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4568 n = new PhylogenyNode( "tr|B1AM49|B1AM49_HUMAN~1-2" );
4569 if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4572 n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN" );
4573 if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4576 n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN|" );
4577 if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4580 n = new PhylogenyNode( "tr|B1AM49|HNRPR_HUMAN~12" );
4581 if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4584 n = new PhylogenyNode( "HNRPR_HUMAN" );
4585 if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4588 n = new PhylogenyNode( "HNRPR_HUMAN_X" );
4589 if ( !ParserUtils.extractTaxonomyDataFromNodeName( n, TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "HUMAN" ) ) {
4593 catch ( final Exception e ) {
4594 e.printStackTrace( System.out );
4600 private static boolean testExtractTaxonomyCodeFromNodeName() {
4602 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "MOUSE", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4605 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4606 .equals( "SOYBN" ) ) {
4609 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4610 .equals( "ARATH" ) ) {
4613 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " ARATH ", TAXONOMY_EXTRACTION.AGGRESSIVE )
4614 .equals( "ARATH" ) ) {
4617 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4620 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "RAT", TAXONOMY_EXTRACTION.AGGRESSIVE ).equals( "RAT" ) ) {
4623 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "RAT1", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4626 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( " _SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4627 .equals( "SOYBN" ) ) {
4630 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4631 .equals( "SOYBN" ) ) {
4634 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4635 .equals( "SOYBN" ) ) {
4638 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "qwerty_SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4639 .equals( "SOYBN" ) ) {
4642 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "ABCD_SOYBN ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4643 .equals( "SOYBN" ) ) {
4646 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "SOYBN", TAXONOMY_EXTRACTION.AGGRESSIVE )
4647 .equals( "SOYBN" ) ) {
4650 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( ",SOYBN,", TAXONOMY_EXTRACTION.AGGRESSIVE )
4651 .equals( "SOYBN" ) ) {
4654 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "xxx,SOYBN,xxx", TAXONOMY_EXTRACTION.AGGRESSIVE )
4655 .equals( "SOYBN" ) ) {
4658 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "xxxSOYBNxxx", TAXONOMY_EXTRACTION.AGGRESSIVE ) != null ) {
4661 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "-SOYBN~", TAXONOMY_EXTRACTION.AGGRESSIVE )
4662 .equals( "SOYBN" ) ) {
4665 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "NNN8_ECOLI/1-2:0.01",
4666 TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ).equals( "ECOLI" ) ) {
4669 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "blag_9YX45-blag", TAXONOMY_EXTRACTION.AGGRESSIVE )
4670 .equals( "9YX45" ) ) {
4673 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE function = 23445",
4674 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4675 .equals( "MOUSE" ) ) {
4678 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE+function = 23445",
4679 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4680 .equals( "MOUSE" ) ) {
4683 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE|function = 23445",
4684 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4685 .equals( "MOUSE" ) ) {
4688 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEfunction = 23445",
4689 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4692 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSEFunction = 23445",
4693 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4696 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4697 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4700 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT function = 23445",
4701 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4704 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT|function = 23445",
4705 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ).equals( "RAT" ) ) {
4708 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATfunction = 23445",
4709 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4712 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RATFunction = 23445",
4713 TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4716 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_RAT/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4717 .equals( "RAT" ) ) {
4720 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_PIG/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4721 .equals( "PIG" ) ) {
4725 .extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED )
4726 .equals( "MOUSE" ) ) {
4729 if ( !ParserUtils.extractTaxonomyCodeFromNodeName( "BCL2_MOUSE/1-3", TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT )
4730 .equals( "MOUSE" ) ) {
4733 if ( ParserUtils.extractTaxonomyCodeFromNodeName( "_MOUSE ", TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED ) != null ) {
4737 catch ( final Exception e ) {
4738 e.printStackTrace( System.out );
4744 private static boolean testExtractUniProtKbProteinSeqIdentifier() {
4746 PhylogenyNode n = new PhylogenyNode();
4747 n.setName( "tr|B3RJ64" );
4748 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4751 n.setName( "tr.B3RJ64" );
4752 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4755 n.setName( "tr=B3RJ64" );
4756 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4759 n.setName( "tr-B3RJ64" );
4760 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4763 n.setName( "tr/B3RJ64" );
4764 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4767 n.setName( "tr\\B3RJ64" );
4768 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4771 n.setName( "tr_B3RJ64" );
4772 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4775 n.setName( " tr|B3RJ64 " );
4776 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4779 n.setName( "-tr|B3RJ64-" );
4780 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4783 n.setName( "-tr=B3RJ64-" );
4784 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4787 n.setName( "_tr=B3RJ64_" );
4788 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4791 n.setName( " tr_tr|B3RJ64_sp|123 " );
4792 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4795 n.setName( "B3RJ64" );
4796 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4799 n.setName( "sp|B3RJ64" );
4800 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4803 n.setName( "sp|B3RJ64C" );
4804 if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4807 n.setName( "sp B3RJ64" );
4808 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4811 n.setName( "sp|B3RJ6X" );
4812 if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4815 n.setName( "sp|B3RJ6" );
4816 if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4819 n.setName( "K1PYK7_CRAGI" );
4820 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4823 n.setName( "K1PYK7_PEA" );
4824 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PEA" ) ) {
4827 n.setName( "K1PYK7_RAT" );
4828 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_RAT" ) ) {
4831 n.setName( "K1PYK7_PIG" );
4832 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4835 n.setName( "~K1PYK7_PIG~" );
4836 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_PIG" ) ) {
4839 n.setName( "123456_ECOLI-K1PYK7_CRAGI-sp" );
4840 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4843 n.setName( "K1PYKX_CRAGI" );
4844 if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4847 n.setName( "XXXXX_CRAGI" );
4848 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "XXXXX_CRAGI" ) ) {
4851 n.setName( "tr|H3IB65|H3IB65_STRPU~2-2" );
4852 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "H3IB65" ) ) {
4855 n.setName( "jgi|Lacbi2|181470|Lacbi1.estExt_GeneWisePlus_human.C_10729~2-3" );
4856 if ( SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ) != null ) {
4859 n.setName( "sp|Q86U06|RBM23_HUMAN~2-2" );
4860 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "Q86U06" ) ) {
4863 n = new PhylogenyNode();
4864 org.forester.phylogeny.data.Sequence seq = new org.forester.phylogeny.data.Sequence();
4865 seq.setSymbol( "K1PYK7_CRAGI" );
4866 n.getNodeData().addSequence( seq );
4867 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4870 seq.setSymbol( "tr|B3RJ64" );
4871 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4874 n = new PhylogenyNode();
4875 seq = new org.forester.phylogeny.data.Sequence();
4876 seq.setName( "K1PYK7_CRAGI" );
4877 n.getNodeData().addSequence( seq );
4878 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK7_CRAGI" ) ) {
4881 seq.setName( "tr|B3RJ64" );
4882 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4885 n = new PhylogenyNode();
4886 seq = new org.forester.phylogeny.data.Sequence();
4887 seq.setAccession( new Accession( "K1PYK8_CRAGI", "?" ) );
4888 n.getNodeData().addSequence( seq );
4889 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "K1PYK8_CRAGI" ) ) {
4892 n = new PhylogenyNode();
4893 seq = new org.forester.phylogeny.data.Sequence();
4894 seq.setAccession( new Accession( "tr|B3RJ64", "?" ) );
4895 n.getNodeData().addSequence( seq );
4896 if ( !SequenceAccessionTools.obtainUniProtAccessorFromDataFields( n ).equals( "B3RJ64" ) ) {
4900 n = new PhylogenyNode();
4901 n.setName( "ACP19736" );
4902 if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4905 n = new PhylogenyNode();
4906 n.setName( "|ACP19736|" );
4907 if ( !SequenceAccessionTools.obtainGenbankAccessorFromDataFields( n ).equals( "ACP19736" ) ) {
4911 catch ( final Exception e ) {
4912 e.printStackTrace( System.out );
4918 private static boolean testFastaParser() {
4920 if ( !FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) ) ) {
4923 if ( FastaParser.isLikelyFasta( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) ) ) {
4926 final Msa msa_0 = FastaParser.parseMsa( new FileInputStream( PATH_TO_TEST_DATA + "fasta_0.fasta" ) );
4927 if ( !msa_0.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "ACGTGKXFMFDMXEXXXSFMFMF" ) ) {
4930 if ( !msa_0.getIdentifier( 0 ).equals( "one dumb" ) ) {
4933 if ( !msa_0.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "DKXASDFXSFXFKFKSXDFKSLX" ) ) {
4936 if ( !msa_0.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "SXDFKSXLFSFPWEXPROWXERR" ) ) {
4939 if ( !msa_0.getSequenceAsString( 3 ).toString().equalsIgnoreCase( "AAAAAAAAAAAAAAAAAAAAAAA" ) ) {
4942 if ( !msa_0.getSequenceAsString( 4 ).toString().equalsIgnoreCase( "DDDDDDDDDDDDDDDDDDDDAXF" ) ) {
4946 catch ( final Exception e ) {
4947 e.printStackTrace();
4953 private static boolean testGenbankAccessorParsing() {
4954 //The format for GenBank Accession numbers are:
4955 //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals
4956 //Protein: 3 letters + 5 numerals
4957 //http://www.ncbi.nlm.nih.gov/Sequin/acc.html
4958 if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "AY423861" ).equals( "AY423861" ) ) {
4961 if ( !SequenceAccessionTools.parseGenbankAccessorFromString( ".AY423861.2" ).equals( "AY423861.2" ) ) {
4964 if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "345_.AY423861.24_345" ).equals( "AY423861.24" ) ) {
4967 if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY423861" ) != null ) {
4970 if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AY4238612" ) != null ) {
4973 if ( SequenceAccessionTools.parseGenbankAccessorFromString( "AAY4238612" ) != null ) {
4976 if ( SequenceAccessionTools.parseGenbankAccessorFromString( "Y423861" ) != null ) {
4979 if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "S12345" ).equals( "S12345" ) ) {
4982 if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "|S12345|" ).equals( "S12345" ) ) {
4985 if ( SequenceAccessionTools.parseGenbankAccessorFromString( "|S123456" ) != null ) {
4988 if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABC123456" ) != null ) {
4991 if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "ABC12345" ).equals( "ABC12345" ) ) {
4994 if ( !SequenceAccessionTools.parseGenbankAccessorFromString( "&ABC12345&" ).equals( "ABC12345" ) ) {
4997 if ( SequenceAccessionTools.parseGenbankAccessorFromString( "ABCD12345" ) != null ) {
5003 private static boolean testGeneralMsaParser() {
5005 final String msa_str_0 = "seq1 abcd\n\nseq2 efgh\n";
5006 final Msa msa_0 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_0.getBytes() ) );
5007 final String msa_str_1 = "seq1 abc\nseq2 ghi\nseq1 def\nseq2 jkm\n";
5008 final Msa msa_1 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_1.getBytes() ) );
5009 final String msa_str_2 = "seq1 abc\nseq2 ghi\n\ndef\njkm\n";
5010 final Msa msa_2 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_2.getBytes() ) );
5011 final String msa_str_3 = "seq1 abc\n def\nseq2 ghi\n jkm\n";
5012 final Msa msa_3 = GeneralMsaParser.parse( new ByteArrayInputStream( msa_str_3.getBytes() ) );
5013 if ( !msa_1.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5016 if ( !msa_1.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5019 if ( !msa_1.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5022 if ( !msa_1.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5025 if ( !msa_2.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5028 if ( !msa_2.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5031 if ( !msa_2.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5034 if ( !msa_2.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5037 if ( !msa_3.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdef" ) ) {
5040 if ( !msa_3.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "ghixkm" ) ) {
5043 if ( !msa_3.getIdentifier( 0 ).toString().equals( "seq1" ) ) {
5046 if ( !msa_3.getIdentifier( 1 ).toString().equals( "seq2" ) ) {
5049 final Msa msa_4 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_1.txt" ) );
5050 if ( !msa_4.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5053 if ( !msa_4.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5056 if ( !msa_4.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5059 final Msa msa_5 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_2.txt" ) );
5060 if ( !msa_5.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefxx" ) ) {
5063 if ( !msa_5.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixyy" ) ) {
5066 if ( !msa_5.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxpzz" ) ) {
5069 final Msa msa_6 = GeneralMsaParser.parse( new FileInputStream( PATH_TO_TEST_DATA + "msa_3.txt" ) );
5070 if ( !msa_6.getSequenceAsString( 0 ).toString().equalsIgnoreCase( "abcdefeeeeeeeexx" ) ) {
5073 if ( !msa_6.getSequenceAsString( 1 ).toString().equalsIgnoreCase( "efghixffffffffyy" ) ) {
5076 if ( !msa_6.getSequenceAsString( 2 ).toString().equalsIgnoreCase( "klmnxphhhhhhhhzz" ) ) {
5080 catch ( final Exception e ) {
5081 e.printStackTrace();
5087 private static boolean testGeneralTable() {
5089 final GeneralTable<Integer, String> t0 = new GeneralTable<Integer, String>();
5090 t0.setValue( 3, 2, "23" );
5091 t0.setValue( 10, 1, "error" );
5092 t0.setValue( 10, 1, "110" );
5093 t0.setValue( 9, 1, "19" );
5094 t0.setValue( 1, 10, "101" );
5095 t0.setValue( 10, 10, "1010" );
5096 t0.setValue( 100, 10, "10100" );
5097 t0.setValue( 0, 0, "00" );
5098 if ( !t0.getValue( 3, 2 ).equals( "23" ) ) {
5101 if ( !t0.getValue( 10, 1 ).equals( "110" ) ) {
5104 if ( !t0.getValueAsString( 1, 10 ).equals( "101" ) ) {
5107 if ( !t0.getValueAsString( 10, 10 ).equals( "1010" ) ) {
5110 if ( !t0.getValueAsString( 100, 10 ).equals( "10100" ) ) {
5113 if ( !t0.getValueAsString( 9, 1 ).equals( "19" ) ) {
5116 if ( !t0.getValueAsString( 0, 0 ).equals( "00" ) ) {
5119 if ( !t0.getValueAsString( 49, 4 ).equals( "" ) ) {
5122 if ( !t0.getValueAsString( 22349, 3434344 ).equals( "" ) ) {
5125 final GeneralTable<String, String> t1 = new GeneralTable<String, String>();
5126 t1.setValue( "3", "2", "23" );
5127 t1.setValue( "10", "1", "error" );
5128 t1.setValue( "10", "1", "110" );
5129 t1.setValue( "9", "1", "19" );
5130 t1.setValue( "1", "10", "101" );
5131 t1.setValue( "10", "10", "1010" );
5132 t1.setValue( "100", "10", "10100" );
5133 t1.setValue( "0", "0", "00" );
5134 t1.setValue( "qwerty", "zxcvbnm", "asdef" );
5135 if ( !t1.getValue( "3", "2" ).equals( "23" ) ) {
5138 if ( !t1.getValue( "10", "1" ).equals( "110" ) ) {
5141 if ( !t1.getValueAsString( "1", "10" ).equals( "101" ) ) {
5144 if ( !t1.getValueAsString( "10", "10" ).equals( "1010" ) ) {
5147 if ( !t1.getValueAsString( "100", "10" ).equals( "10100" ) ) {
5150 if ( !t1.getValueAsString( "9", "1" ).equals( "19" ) ) {
5153 if ( !t1.getValueAsString( "0", "0" ).equals( "00" ) ) {
5156 if ( !t1.getValueAsString( "qwerty", "zxcvbnm" ).equals( "asdef" ) ) {
5159 if ( !t1.getValueAsString( "49", "4" ).equals( "" ) ) {
5162 if ( !t1.getValueAsString( "22349", "3434344" ).equals( "" ) ) {
5166 catch ( final Exception e ) {
5167 e.printStackTrace( System.out );
5173 private static boolean testGetDistance() {
5175 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5176 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",
5177 new NHXParser() )[ 0 ];
5178 if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "C" ) ) != 0 ) {
5181 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "def" ) ) != 0 ) {
5184 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ef" ) ) != 0 ) {
5187 if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "r" ) ) != 0 ) {
5190 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "A" ) ) != 0 ) {
5193 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "B" ) ) != 3 ) {
5196 if ( PhylogenyMethods.calculateDistance( p1.getNode( "B" ), p1.getNode( "A" ) ) != 3 ) {
5199 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "C" ) ) != 8 ) {
5202 if ( PhylogenyMethods.calculateDistance( p1.getNode( "C" ), p1.getNode( "A" ) ) != 8 ) {
5205 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "D" ) ) != 22 ) {
5208 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "E" ) ) != 32 ) {
5211 if ( PhylogenyMethods.calculateDistance( p1.getNode( "E" ), p1.getNode( "A" ) ) != 32 ) {
5214 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "F" ) ) != 33 ) {
5217 if ( PhylogenyMethods.calculateDistance( p1.getNode( "F" ), p1.getNode( "A" ) ) != 33 ) {
5220 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ab" ) ) != 1 ) {
5223 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "A" ) ) != 1 ) {
5226 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "abc" ) ) != 4 ) {
5229 if ( PhylogenyMethods.calculateDistance( p1.getNode( "abc" ), p1.getNode( "A" ) ) != 4 ) {
5232 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "r" ) ) != 9 ) {
5235 if ( PhylogenyMethods.calculateDistance( p1.getNode( "r" ), p1.getNode( "A" ) ) != 9 ) {
5238 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "def" ) ) != 15 ) {
5241 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "A" ) ) != 15 ) {
5244 if ( PhylogenyMethods.calculateDistance( p1.getNode( "A" ), p1.getNode( "ef" ) ) != 23 ) {
5247 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "A" ) ) != 23 ) {
5250 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "def" ) ) != 8 ) {
5253 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "ef" ) ) != 8 ) {
5256 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "r" ) ) != 14 ) {
5259 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "abc" ) ) != 19 ) {
5262 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ef" ), p1.getNode( "ab" ) ) != 22 ) {
5265 if ( PhylogenyMethods.calculateDistance( p1.getNode( "ab" ), p1.getNode( "ef" ) ) != 22 ) {
5268 if ( PhylogenyMethods.calculateDistance( p1.getNode( "def" ), p1.getNode( "abc" ) ) != 11 ) {
5271 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",
5272 new NHXParser() )[ 0 ];
5273 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "B" ) ) != 9 ) {
5276 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "C" ) ) != 10 ) {
5279 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "D" ) ) != 14 ) {
5282 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "ghi" ) ) != 8 ) {
5285 if ( PhylogenyMethods.calculateDistance( p2.getNode( "A" ), p2.getNode( "I" ) ) != 20 ) {
5288 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "ghi" ) ) != 10 ) {
5291 if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "r" ) ) != 0 ) {
5294 if ( PhylogenyMethods.calculateDistance( p2.getNode( "r" ), p2.getNode( "G" ) ) != 13 ) {
5297 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "r" ) ) != 13 ) {
5300 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "H" ) ) != 21 ) {
5303 if ( PhylogenyMethods.calculateDistance( p2.getNode( "G" ), p2.getNode( "I" ) ) != 22 ) {
5307 catch ( final Exception e ) {
5308 e.printStackTrace( System.out );
5314 private static boolean testGetLCA() {
5316 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5317 final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5318 new NHXParser() )[ 0 ];
5319 final PhylogenyNode A = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "A" ) );
5320 if ( !A.getName().equals( "A" ) ) {
5323 final PhylogenyNode gh = PhylogenyMethods.calculateLCA( p1.getNode( "gh" ), p1.getNode( "gh" ) );
5324 if ( !gh.getName().equals( "gh" ) ) {
5327 final PhylogenyNode ab = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "B" ) );
5328 if ( !ab.getName().equals( "ab" ) ) {
5331 final PhylogenyNode ab2 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "A" ) );
5332 if ( !ab2.getName().equals( "ab" ) ) {
5335 final PhylogenyNode gh2 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "G" ) );
5336 if ( !gh2.getName().equals( "gh" ) ) {
5339 final PhylogenyNode gh3 = PhylogenyMethods.calculateLCA( p1.getNode( "G" ), p1.getNode( "H" ) );
5340 if ( !gh3.getName().equals( "gh" ) ) {
5343 final PhylogenyNode abc = PhylogenyMethods.calculateLCA( p1.getNode( "C" ), p1.getNode( "A" ) );
5344 if ( !abc.getName().equals( "abc" ) ) {
5347 final PhylogenyNode abc2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "C" ) );
5348 if ( !abc2.getName().equals( "abc" ) ) {
5351 final PhylogenyNode abcd = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "D" ) );
5352 if ( !abcd.getName().equals( "abcd" ) ) {
5355 final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCA( p1.getNode( "D" ), p1.getNode( "A" ) );
5356 if ( !abcd2.getName().equals( "abcd" ) ) {
5359 final PhylogenyNode abcdef = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "F" ) );
5360 if ( !abcdef.getName().equals( "abcdef" ) ) {
5363 final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "A" ) );
5364 if ( !abcdef2.getName().equals( "abcdef" ) ) {
5367 final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "F" ) );
5368 if ( !abcdef3.getName().equals( "abcdef" ) ) {
5371 final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCA( p1.getNode( "F" ), p1.getNode( "ab" ) );
5372 if ( !abcdef4.getName().equals( "abcdef" ) ) {
5375 final PhylogenyNode abcde = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "E" ) );
5376 if ( !abcde.getName().equals( "abcde" ) ) {
5379 final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "A" ) );
5380 if ( !abcde2.getName().equals( "abcde" ) ) {
5383 final PhylogenyNode r = PhylogenyMethods.calculateLCA( p1.getNode( "abcdefgh" ), p1.getNode( "abcdefgh" ) );
5384 if ( !r.getName().equals( "abcdefgh" ) ) {
5387 final PhylogenyNode r2 = PhylogenyMethods.calculateLCA( p1.getNode( "A" ), p1.getNode( "H" ) );
5388 if ( !r2.getName().equals( "abcdefgh" ) ) {
5391 final PhylogenyNode r3 = PhylogenyMethods.calculateLCA( p1.getNode( "H" ), p1.getNode( "A" ) );
5392 if ( !r3.getName().equals( "abcdefgh" ) ) {
5395 final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCA( p1.getNode( "E" ), p1.getNode( "abcde" ) );
5396 if ( !abcde3.getName().equals( "abcde" ) ) {
5399 final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCA( p1.getNode( "abcde" ), p1.getNode( "E" ) );
5400 if ( !abcde4.getName().equals( "abcde" ) ) {
5403 final PhylogenyNode ab3 = PhylogenyMethods.calculateLCA( p1.getNode( "ab" ), p1.getNode( "B" ) );
5404 if ( !ab3.getName().equals( "ab" ) ) {
5407 final PhylogenyNode ab4 = PhylogenyMethods.calculateLCA( p1.getNode( "B" ), p1.getNode( "ab" ) );
5408 if ( !ab4.getName().equals( "ab" ) ) {
5411 final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5412 final PhylogenyNode cd = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "d" ) );
5413 if ( !cd.getName().equals( "cd" ) ) {
5416 final PhylogenyNode cd2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "c" ) );
5417 if ( !cd2.getName().equals( "cd" ) ) {
5420 final PhylogenyNode cde = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "e" ) );
5421 if ( !cde.getName().equals( "cde" ) ) {
5424 final PhylogenyNode cde2 = PhylogenyMethods.calculateLCA( p2.getNode( "e" ), p2.getNode( "c" ) );
5425 if ( !cde2.getName().equals( "cde" ) ) {
5428 final PhylogenyNode cdef = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "f" ) );
5429 if ( !cdef.getName().equals( "cdef" ) ) {
5432 final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCA( p2.getNode( "d" ), p2.getNode( "f" ) );
5433 if ( !cdef2.getName().equals( "cdef" ) ) {
5436 final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCA( p2.getNode( "f" ), p2.getNode( "d" ) );
5437 if ( !cdef3.getName().equals( "cdef" ) ) {
5440 final PhylogenyNode rt = PhylogenyMethods.calculateLCA( p2.getNode( "c" ), p2.getNode( "a" ) );
5441 if ( !rt.getName().equals( "r" ) ) {
5444 final Phylogeny p3 = factory
5445 .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5446 new NHXParser() )[ 0 ];
5447 final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCA( p3.getNode( "b" ), p3.getNode( "c" ) );
5448 if ( !bc_3.getName().equals( "bc" ) ) {
5451 final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "c" ) );
5452 if ( !ac_3.getName().equals( "abc" ) ) {
5455 final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "d" ) );
5456 if ( !ad_3.getName().equals( "abcde" ) ) {
5459 final PhylogenyNode af_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "f" ) );
5460 if ( !af_3.getName().equals( "abcdef" ) ) {
5463 final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "g" ) );
5464 if ( !ag_3.getName().equals( "" ) ) {
5467 if ( !ag_3.isRoot() ) {
5470 final PhylogenyNode al_3 = PhylogenyMethods.calculateLCA( p3.getNode( "a" ), p3.getNode( "l" ) );
5471 if ( !al_3.getName().equals( "" ) ) {
5474 if ( !al_3.isRoot() ) {
5477 final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "k" ), p3.getNode( "l" ) );
5478 if ( !kl_3.getName().equals( "" ) ) {
5481 if ( !kl_3.isRoot() ) {
5484 final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCA( p3.getNode( "f" ), p3.getNode( "l" ) );
5485 if ( !fl_3.getName().equals( "" ) ) {
5488 if ( !fl_3.isRoot() ) {
5491 final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCA( p3.getNode( "g" ), p3.getNode( "k" ) );
5492 if ( !gk_3.getName().equals( "ghijk" ) ) {
5495 final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5496 final PhylogenyNode r_4 = PhylogenyMethods.calculateLCA( p4.getNode( "b" ), p4.getNode( "c" ) );
5497 if ( !r_4.getName().equals( "r" ) ) {
5500 final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5501 final PhylogenyNode r_5 = PhylogenyMethods.calculateLCA( p5.getNode( "a" ), p5.getNode( "c" ) );
5502 if ( !r_5.getName().equals( "root" ) ) {
5505 final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5506 final PhylogenyNode r_6 = PhylogenyMethods.calculateLCA( p6.getNode( "c" ), p6.getNode( "a" ) );
5507 if ( !r_6.getName().equals( "rot" ) ) {
5510 final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5511 final PhylogenyNode r_7 = PhylogenyMethods.calculateLCA( p7.getNode( "a" ), p7.getNode( "e" ) );
5512 if ( !r_7.getName().equals( "rott" ) ) {
5516 catch ( final Exception e ) {
5517 e.printStackTrace( System.out );
5523 private static boolean testGetLCA2() {
5525 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5526 // final Phylogeny p_a = factory.create( "(a)", new NHXParser() )[ 0 ];
5527 final Phylogeny p_a = NHXParser.parse( "(a)" )[ 0 ];
5528 PhylogenyMethods.preOrderReId( p_a );
5529 final PhylogenyNode p_a_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_a.getNode( "a" ),
5530 p_a.getNode( "a" ) );
5531 if ( !p_a_1.getName().equals( "a" ) ) {
5534 final Phylogeny p_b = NHXParser.parse( "((a)b)" )[ 0 ];
5535 PhylogenyMethods.preOrderReId( p_b );
5536 final PhylogenyNode p_b_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "b" ),
5537 p_b.getNode( "a" ) );
5538 if ( !p_b_1.getName().equals( "b" ) ) {
5541 final PhylogenyNode p_b_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_b.getNode( "a" ),
5542 p_b.getNode( "b" ) );
5543 if ( !p_b_2.getName().equals( "b" ) ) {
5546 final Phylogeny p_c = factory.create( "(((a)b)c)", new NHXParser() )[ 0 ];
5547 PhylogenyMethods.preOrderReId( p_c );
5548 final PhylogenyNode p_c_1 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "b" ),
5549 p_c.getNode( "a" ) );
5550 if ( !p_c_1.getName().equals( "b" ) ) {
5553 final PhylogenyNode p_c_2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5554 p_c.getNode( "c" ) );
5555 if ( !p_c_2.getName().equals( "c" ) ) {
5556 System.out.println( p_c_2.getName() );
5560 final PhylogenyNode p_c_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "a" ),
5561 p_c.getNode( "b" ) );
5562 if ( !p_c_3.getName().equals( "b" ) ) {
5565 final PhylogenyNode p_c_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p_c.getNode( "c" ),
5566 p_c.getNode( "a" ) );
5567 if ( !p_c_4.getName().equals( "c" ) ) {
5570 final Phylogeny p1 = factory.create( "((((((A,B)ab,C)abc,D)abcd,E)abcde,F)abcdef,(G,H)gh)abcdefgh",
5571 new NHXParser() )[ 0 ];
5572 PhylogenyMethods.preOrderReId( p1 );
5573 final PhylogenyNode A = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5574 p1.getNode( "A" ) );
5575 if ( !A.getName().equals( "A" ) ) {
5578 final PhylogenyNode gh = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "gh" ),
5579 p1.getNode( "gh" ) );
5580 if ( !gh.getName().equals( "gh" ) ) {
5583 final PhylogenyNode ab = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5584 p1.getNode( "B" ) );
5585 if ( !ab.getName().equals( "ab" ) ) {
5588 final PhylogenyNode ab2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5589 p1.getNode( "A" ) );
5590 if ( !ab2.getName().equals( "ab" ) ) {
5593 final PhylogenyNode gh2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5594 p1.getNode( "G" ) );
5595 if ( !gh2.getName().equals( "gh" ) ) {
5598 final PhylogenyNode gh3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "G" ),
5599 p1.getNode( "H" ) );
5600 if ( !gh3.getName().equals( "gh" ) ) {
5603 final PhylogenyNode abc = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "C" ),
5604 p1.getNode( "A" ) );
5605 if ( !abc.getName().equals( "abc" ) ) {
5608 final PhylogenyNode abc2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5609 p1.getNode( "C" ) );
5610 if ( !abc2.getName().equals( "abc" ) ) {
5613 final PhylogenyNode abcd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5614 p1.getNode( "D" ) );
5615 if ( !abcd.getName().equals( "abcd" ) ) {
5618 final PhylogenyNode abcd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "D" ),
5619 p1.getNode( "A" ) );
5620 if ( !abcd2.getName().equals( "abcd" ) ) {
5623 final PhylogenyNode abcdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5624 p1.getNode( "F" ) );
5625 if ( !abcdef.getName().equals( "abcdef" ) ) {
5628 final PhylogenyNode abcdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5629 p1.getNode( "A" ) );
5630 if ( !abcdef2.getName().equals( "abcdef" ) ) {
5633 final PhylogenyNode abcdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5634 p1.getNode( "F" ) );
5635 if ( !abcdef3.getName().equals( "abcdef" ) ) {
5638 final PhylogenyNode abcdef4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "F" ),
5639 p1.getNode( "ab" ) );
5640 if ( !abcdef4.getName().equals( "abcdef" ) ) {
5643 final PhylogenyNode abcde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5644 p1.getNode( "E" ) );
5645 if ( !abcde.getName().equals( "abcde" ) ) {
5648 final PhylogenyNode abcde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5649 p1.getNode( "A" ) );
5650 if ( !abcde2.getName().equals( "abcde" ) ) {
5653 final PhylogenyNode r = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcdefgh" ),
5654 p1.getNode( "abcdefgh" ) );
5655 if ( !r.getName().equals( "abcdefgh" ) ) {
5658 final PhylogenyNode r2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "A" ),
5659 p1.getNode( "H" ) );
5660 if ( !r2.getName().equals( "abcdefgh" ) ) {
5663 final PhylogenyNode r3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "H" ),
5664 p1.getNode( "A" ) );
5665 if ( !r3.getName().equals( "abcdefgh" ) ) {
5668 final PhylogenyNode abcde3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "E" ),
5669 p1.getNode( "abcde" ) );
5670 if ( !abcde3.getName().equals( "abcde" ) ) {
5673 final PhylogenyNode abcde4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "abcde" ),
5674 p1.getNode( "E" ) );
5675 if ( !abcde4.getName().equals( "abcde" ) ) {
5678 final PhylogenyNode ab3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "ab" ),
5679 p1.getNode( "B" ) );
5680 if ( !ab3.getName().equals( "ab" ) ) {
5683 final PhylogenyNode ab4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p1.getNode( "B" ),
5684 p1.getNode( "ab" ) );
5685 if ( !ab4.getName().equals( "ab" ) ) {
5688 final Phylogeny p2 = factory.create( "(a,b,(((c,d)cd,e)cde,f)cdef)r", new NHXParser() )[ 0 ];
5689 PhylogenyMethods.preOrderReId( p2 );
5690 final PhylogenyNode cd = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5691 p2.getNode( "d" ) );
5692 if ( !cd.getName().equals( "cd" ) ) {
5695 final PhylogenyNode cd2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5696 p2.getNode( "c" ) );
5697 if ( !cd2.getName().equals( "cd" ) ) {
5700 final PhylogenyNode cde = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5701 p2.getNode( "e" ) );
5702 if ( !cde.getName().equals( "cde" ) ) {
5705 final PhylogenyNode cde2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "e" ),
5706 p2.getNode( "c" ) );
5707 if ( !cde2.getName().equals( "cde" ) ) {
5710 final PhylogenyNode cdef = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5711 p2.getNode( "f" ) );
5712 if ( !cdef.getName().equals( "cdef" ) ) {
5715 final PhylogenyNode cdef2 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "d" ),
5716 p2.getNode( "f" ) );
5717 if ( !cdef2.getName().equals( "cdef" ) ) {
5720 final PhylogenyNode cdef3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "f" ),
5721 p2.getNode( "d" ) );
5722 if ( !cdef3.getName().equals( "cdef" ) ) {
5725 final PhylogenyNode rt = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p2.getNode( "c" ),
5726 p2.getNode( "a" ) );
5727 if ( !rt.getName().equals( "r" ) ) {
5730 final Phylogeny p3 = factory
5731 .create( "((((a,(b,c)bc)abc,(d,e)de)abcde,f)abcdef,(((g,h)gh,(i,j)ij)ghij,k)ghijk,l)",
5732 new NHXParser() )[ 0 ];
5733 PhylogenyMethods.preOrderReId( p3 );
5734 final PhylogenyNode bc_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "b" ),
5735 p3.getNode( "c" ) );
5736 if ( !bc_3.getName().equals( "bc" ) ) {
5739 final PhylogenyNode ac_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5740 p3.getNode( "c" ) );
5741 if ( !ac_3.getName().equals( "abc" ) ) {
5744 final PhylogenyNode ad_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5745 p3.getNode( "d" ) );
5746 if ( !ad_3.getName().equals( "abcde" ) ) {
5749 final PhylogenyNode af_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5750 p3.getNode( "f" ) );
5751 if ( !af_3.getName().equals( "abcdef" ) ) {
5754 final PhylogenyNode ag_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5755 p3.getNode( "g" ) );
5756 if ( !ag_3.getName().equals( "" ) ) {
5759 if ( !ag_3.isRoot() ) {
5762 final PhylogenyNode al_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "a" ),
5763 p3.getNode( "l" ) );
5764 if ( !al_3.getName().equals( "" ) ) {
5767 if ( !al_3.isRoot() ) {
5770 final PhylogenyNode kl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "k" ),
5771 p3.getNode( "l" ) );
5772 if ( !kl_3.getName().equals( "" ) ) {
5775 if ( !kl_3.isRoot() ) {
5778 final PhylogenyNode fl_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "f" ),
5779 p3.getNode( "l" ) );
5780 if ( !fl_3.getName().equals( "" ) ) {
5783 if ( !fl_3.isRoot() ) {
5786 final PhylogenyNode gk_3 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p3.getNode( "g" ),
5787 p3.getNode( "k" ) );
5788 if ( !gk_3.getName().equals( "ghijk" ) ) {
5791 final Phylogeny p4 = factory.create( "(a,b,c)r", new NHXParser() )[ 0 ];
5792 PhylogenyMethods.preOrderReId( p4 );
5793 final PhylogenyNode r_4 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p4.getNode( "b" ),
5794 p4.getNode( "c" ) );
5795 if ( !r_4.getName().equals( "r" ) ) {
5798 final Phylogeny p5 = factory.create( "((a,b),c,d)root", new NHXParser() )[ 0 ];
5799 PhylogenyMethods.preOrderReId( p5 );
5800 final PhylogenyNode r_5 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p5.getNode( "a" ),
5801 p5.getNode( "c" ) );
5802 if ( !r_5.getName().equals( "root" ) ) {
5805 final Phylogeny p6 = factory.create( "((a,b),c,d)rot", new NHXParser() )[ 0 ];
5806 PhylogenyMethods.preOrderReId( p6 );
5807 final PhylogenyNode r_6 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p6.getNode( "c" ),
5808 p6.getNode( "a" ) );
5809 if ( !r_6.getName().equals( "rot" ) ) {
5812 final Phylogeny p7 = factory.create( "(((a,b)x,c)x,d,e)rott", new NHXParser() )[ 0 ];
5813 PhylogenyMethods.preOrderReId( p7 );
5814 final PhylogenyNode r_7 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "a" ),
5815 p7.getNode( "e" ) );
5816 if ( !r_7.getName().equals( "rott" ) ) {
5819 final PhylogenyNode r_71 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5820 p7.getNode( "a" ) );
5821 if ( !r_71.getName().equals( "rott" ) ) {
5824 final PhylogenyNode r_72 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5825 p7.getNode( "rott" ) );
5826 if ( !r_72.getName().equals( "rott" ) ) {
5829 final PhylogenyNode r_73 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5830 p7.getNode( "a" ) );
5831 if ( !r_73.getName().equals( "rott" ) ) {
5834 final PhylogenyNode r_74 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "rott" ),
5835 p7.getNode( "rott" ) );
5836 if ( !r_74.getName().equals( "rott" ) ) {
5839 final PhylogenyNode r_75 = PhylogenyMethods.calculateLCAonTreeWithIdsInPreOrder( p7.getNode( "e" ),
5840 p7.getNode( "e" ) );
5841 if ( !r_75.getName().equals( "e" ) ) {
5845 catch ( final Exception e ) {
5846 e.printStackTrace( System.out );
5852 private static boolean testHmmscanOutputParser() {
5853 final String test_dir = Test.PATH_TO_TEST_DATA;
5855 final HmmscanPerDomainTableParser parser1 = new HmmscanPerDomainTableParser( new File( test_dir
5856 + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_1" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5858 final HmmscanPerDomainTableParser parser2 = new HmmscanPerDomainTableParser( new File( test_dir
5859 + ForesterUtil.getFileSeparator() + "hmmscan30b3_output_2" ), "MONBR", INDIVIDUAL_SCORE_CUTOFF.NONE );
5860 final List<Protein> proteins = parser2.parse();
5861 if ( parser2.getProteinsEncountered() != 4 ) {
5864 if ( proteins.size() != 4 ) {
5867 if ( parser2.getDomainsEncountered() != 69 ) {
5870 if ( parser2.getDomainsIgnoredDueToDuf() != 0 ) {
5873 if ( parser2.getDomainsIgnoredDueToFsEval() != 0 ) {
5876 if ( parser2.getDomainsIgnoredDueToIEval() != 0 ) {
5879 final Protein p1 = proteins.get( 0 );
5880 if ( p1.getNumberOfProteinDomains() != 15 ) {
5883 if ( p1.getLength() != 850 ) {
5886 final Protein p2 = proteins.get( 1 );
5887 if ( p2.getNumberOfProteinDomains() != 51 ) {
5890 if ( p2.getLength() != 1291 ) {
5893 final Protein p3 = proteins.get( 2 );
5894 if ( p3.getNumberOfProteinDomains() != 2 ) {
5897 final Protein p4 = proteins.get( 3 );
5898 if ( p4.getNumberOfProteinDomains() != 1 ) {
5901 if ( !p4.getProteinDomain( 0 ).getDomainId().toString().equals( "DNA_pol_B_new" ) ) {
5904 if ( p4.getProteinDomain( 0 ).getFrom() != 51 ) {
5907 if ( p4.getProteinDomain( 0 ).getTo() != 395 ) {
5910 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainEvalue(), 1.2e-39 ) ) {
5913 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getPerDomainScore(), 135.7 ) ) {
5916 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getNumber(), 1 ) ) {
5919 if ( !Test.isEqual( p4.getProteinDomain( 0 ).getTotalCount(), 1 ) ) {
5923 catch ( final Exception e ) {
5924 e.printStackTrace( System.out );
5930 private static boolean testLastExternalNodeMethods() {
5932 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5933 final char[] a0 = { '(', '(', 'A', ',', 'B', ')', ',', '(', 'C', ',', 'D', ')', ')', };
5934 final Phylogeny t0 = factory.create( a0, new NHXParser() )[ 0 ];
5935 final PhylogenyNode n1 = t0.getNode( "A" );
5936 if ( n1.isLastExternalNode() ) {
5939 final PhylogenyNode n2 = t0.getNode( "B" );
5940 if ( n2.isLastExternalNode() ) {
5943 final PhylogenyNode n3 = t0.getNode( "C" );
5944 if ( n3.isLastExternalNode() ) {
5947 final PhylogenyNode n4 = t0.getNode( "D" );
5948 if ( !n4.isLastExternalNode() ) {
5952 catch ( final Exception e ) {
5953 e.printStackTrace( System.out );
5959 private static boolean testLevelOrderIterator() {
5961 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
5962 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
5963 PhylogenyNodeIterator it0;
5964 for( it0 = t0.iteratorLevelOrder(); it0.hasNext(); ) {
5967 for( it0.reset(); it0.hasNext(); ) {
5970 final PhylogenyNodeIterator it = t0.iteratorLevelOrder();
5971 if ( !it.next().getName().equals( "r" ) ) {
5974 if ( !it.next().getName().equals( "ab" ) ) {
5977 if ( !it.next().getName().equals( "cd" ) ) {
5980 if ( !it.next().getName().equals( "A" ) ) {
5983 if ( !it.next().getName().equals( "B" ) ) {
5986 if ( !it.next().getName().equals( "C" ) ) {
5989 if ( !it.next().getName().equals( "D" ) ) {
5992 if ( it.hasNext() ) {
5995 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",
5996 new NHXParser() )[ 0 ];
5997 PhylogenyNodeIterator it2;
5998 for( it2 = t2.iteratorLevelOrder(); it2.hasNext(); ) {
6001 for( it2.reset(); it2.hasNext(); ) {
6004 final PhylogenyNodeIterator it3 = t2.iteratorLevelOrder();
6005 if ( !it3.next().getName().equals( "r" ) ) {
6008 if ( !it3.next().getName().equals( "abc" ) ) {
6011 if ( !it3.next().getName().equals( "defg" ) ) {
6014 if ( !it3.next().getName().equals( "A" ) ) {
6017 if ( !it3.next().getName().equals( "B" ) ) {
6020 if ( !it3.next().getName().equals( "C" ) ) {
6023 if ( !it3.next().getName().equals( "D" ) ) {
6026 if ( !it3.next().getName().equals( "E" ) ) {
6029 if ( !it3.next().getName().equals( "F" ) ) {
6032 if ( !it3.next().getName().equals( "G" ) ) {
6035 if ( !it3.next().getName().equals( "1" ) ) {
6038 if ( !it3.next().getName().equals( "2" ) ) {
6041 if ( !it3.next().getName().equals( "3" ) ) {
6044 if ( !it3.next().getName().equals( "4" ) ) {
6047 if ( !it3.next().getName().equals( "5" ) ) {
6050 if ( !it3.next().getName().equals( "6" ) ) {
6053 if ( !it3.next().getName().equals( "f1" ) ) {
6056 if ( !it3.next().getName().equals( "f2" ) ) {
6059 if ( !it3.next().getName().equals( "f3" ) ) {
6062 if ( !it3.next().getName().equals( "a" ) ) {
6065 if ( !it3.next().getName().equals( "b" ) ) {
6068 if ( !it3.next().getName().equals( "f21" ) ) {
6071 if ( !it3.next().getName().equals( "X" ) ) {
6074 if ( !it3.next().getName().equals( "Y" ) ) {
6077 if ( !it3.next().getName().equals( "Z" ) ) {
6080 if ( it3.hasNext() ) {
6083 final Phylogeny t4 = factory.create( "((((D)C)B)A)r", new NHXParser() )[ 0 ];
6084 PhylogenyNodeIterator it4;
6085 for( it4 = t4.iteratorLevelOrder(); it4.hasNext(); ) {
6088 for( it4.reset(); it4.hasNext(); ) {
6091 final PhylogenyNodeIterator it5 = t4.iteratorLevelOrder();
6092 if ( !it5.next().getName().equals( "r" ) ) {
6095 if ( !it5.next().getName().equals( "A" ) ) {
6098 if ( !it5.next().getName().equals( "B" ) ) {
6101 if ( !it5.next().getName().equals( "C" ) ) {
6104 if ( !it5.next().getName().equals( "D" ) ) {
6107 final Phylogeny t5 = factory.create( "A", new NHXParser() )[ 0 ];
6108 PhylogenyNodeIterator it6;
6109 for( it6 = t5.iteratorLevelOrder(); it6.hasNext(); ) {
6112 for( it6.reset(); it6.hasNext(); ) {
6115 final PhylogenyNodeIterator it7 = t5.iteratorLevelOrder();
6116 if ( !it7.next().getName().equals( "A" ) ) {
6119 if ( it.hasNext() ) {
6123 catch ( final Exception e ) {
6124 e.printStackTrace( System.out );
6130 private static boolean testMafft( final String path ) {
6132 final List<String> opts = new ArrayList<String>();
6133 opts.add( "--maxiterate" );
6135 opts.add( "--localpair" );
6136 opts.add( "--quiet" );
6138 final MsaInferrer mafft = Mafft.createInstance( path );
6139 msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts );
6140 if ( ( msa == null ) || ( msa.getLength() < 20 ) || ( msa.getNumberOfSequences() != 19 ) ) {
6143 if ( !msa.getIdentifier( 0 ).toString().equals( "a" ) ) {
6147 catch ( final Exception e ) {
6148 e.printStackTrace( System.out );
6154 private static boolean testMidpointrooting() {
6156 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6157 final Phylogeny t0 = factory.create( "(A:1,B:4,C:2,D:2,E:6,F:1,G:1,H:1)", new NHXParser() )[ 0 ];
6158 PhylogenyMethods.midpointRoot( t0 );
6159 if ( !isEqual( t0.getNode( "E" ).getDistanceToParent(), 5 ) ) {
6162 if ( !isEqual( t0.getNode( "B" ).getDistanceToParent(), 4 ) ) {
6165 if ( !isEqual( PhylogenyMethods.calculateLCA( t0.getNode( "F" ), t0.getNode( "G" ) ).getDistanceToParent(),
6169 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",
6170 new NHXParser() )[ 0 ];
6171 if ( !t1.isRooted() ) {
6174 PhylogenyMethods.midpointRoot( t1 );
6175 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6178 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6181 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6184 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6187 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6190 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6193 t1.reRoot( t1.getNode( "A" ) );
6194 PhylogenyMethods.midpointRoot( t1 );
6195 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
6198 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
6201 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
6204 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 4 ) ) {
6207 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 1 ) ) {
6211 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 3 ) ) {
6215 catch ( final Exception e ) {
6216 e.printStackTrace( System.out );
6222 private static boolean testMsaQualityMethod() {
6224 final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "ABAXEFGHIJJE-" );
6225 final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "ABBXEFGHIJJBB" );
6226 final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AXCXEFGHIJJ--" );
6227 final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AXDDEFGHIJ---" );
6228 final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6233 final Msa msa = BasicMsa.createInstance( l );
6234 if ( !isEqual( 1, MsaMethods.calculateIdentityRatio( msa, 0 ) ) ) {
6237 if ( !isEqual( 0.5, MsaMethods.calculateIdentityRatio( msa, 1 ) ) ) {
6240 if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 2 ) ) ) {
6243 if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 3 ) ) ) {
6246 if ( !isEqual( 0.75, MsaMethods.calculateIdentityRatio( msa, 10 ) ) ) {
6249 if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 11 ) ) ) {
6252 if ( !isEqual( 0.25, MsaMethods.calculateIdentityRatio( msa, 12 ) ) ) {
6256 catch ( final Exception e ) {
6257 e.printStackTrace( System.out );
6263 private static boolean testMsaEntropy() {
6265 final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAAAAA" );
6266 final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "AAAIACC" );
6267 final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "AAIIIIF" );
6268 final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "AIIIVVW" );
6269 final List<MolecularSequence> l = new ArrayList<MolecularSequence>();
6274 final Msa msa = BasicMsa.createInstance( l );
6275 //TODO need to DO the tests!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6277 // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 0 ) );
6278 // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 1 ) );
6279 // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 2 ) );
6280 // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 3 ) );
6281 // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 4 ) );
6282 // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 5 ) );
6283 // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa, 6 ) );
6284 // System.out.println();
6285 // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 0 ) );
6286 // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 1 ) );
6287 // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 2 ) );
6288 // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 3 ) );
6289 // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 4 ) );
6290 // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 5 ) );
6291 // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 6, msa, 6 ) );
6292 final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6293 l2.add( BasicSequence.createAaSequence( "1", "AAAAAAA" ) );
6294 l2.add( BasicSequence.createAaSequence( "2", "AAAIACC" ) );
6295 l2.add( BasicSequence.createAaSequence( "3", "AAIIIIF" ) );
6296 l2.add( BasicSequence.createAaSequence( "4", "AIIIVVW" ) );
6297 l2.add( BasicSequence.createAaSequence( "5", "AAAAAAA" ) );
6298 l2.add( BasicSequence.createAaSequence( "6", "AAAIACC" ) );
6299 l2.add( BasicSequence.createAaSequence( "7", "AAIIIIF" ) );
6300 l2.add( BasicSequence.createAaSequence( "8", "AIIIVVW" ) );
6301 l2.add( BasicSequence.createAaSequence( "9", "AAAAAAA" ) );
6302 l2.add( BasicSequence.createAaSequence( "10", "AAAIACC" ) );
6303 l2.add( BasicSequence.createAaSequence( "11", "AAIIIIF" ) );
6304 l2.add( BasicSequence.createAaSequence( "12", "AIIIVVW" ) );
6305 l2.add( BasicSequence.createAaSequence( "13", "AAIIIIF" ) );
6306 l2.add( BasicSequence.createAaSequence( "14", "AIIIVVW" ) );
6307 l2.add( BasicSequence.createAaSequence( "15", "AAAAAAA" ) );
6308 l2.add( BasicSequence.createAaSequence( "16", "AAAIACC" ) );
6309 l2.add( BasicSequence.createAaSequence( "17", "AAIIIIF" ) );
6310 l2.add( BasicSequence.createAaSequence( "18", "AIIIVVW" ) );
6311 l2.add( BasicSequence.createAaSequence( "19", "AAAAAAA" ) );
6312 l2.add( BasicSequence.createAaSequence( "20", "AAAIACC" ) );
6313 l2.add( BasicSequence.createAaSequence( "21", "AAIIIIF" ) );
6314 l2.add( BasicSequence.createAaSequence( "22", "AIIIVVW" ) );
6315 final Msa msa2 = BasicMsa.createInstance( l2 );
6316 // System.out.println();
6317 // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 0 ) );
6318 // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 1 ) );
6319 // System.out.println( MsaMethods.calcNormalizedShannonsEntropy( 20, msa2, 2 ) );
6321 catch ( final Exception e ) {
6322 e.printStackTrace( System.out );
6328 private static boolean testDeleteableMsa() {
6330 final MolecularSequence s0 = BasicSequence.createAaSequence( "a", "AAAA" );
6331 final MolecularSequence s1 = BasicSequence.createAaSequence( "b", "BAAA" );
6332 final MolecularSequence s2 = BasicSequence.createAaSequence( "c", "CAAA" );
6333 final MolecularSequence s3 = BasicSequence.createAaSequence( "d", "DAAA" );
6334 final MolecularSequence s4 = BasicSequence.createAaSequence( "e", "EAAA" );
6335 final MolecularSequence s5 = BasicSequence.createAaSequence( "f", "FAAA" );
6336 final List<MolecularSequence> l0 = new ArrayList<MolecularSequence>();
6343 final DeleteableMsa dmsa0 = DeleteableMsa.createInstance( l0 );
6344 dmsa0.deleteRow( "b", false );
6345 if ( !dmsa0.getIdentifier( 1 ).equals( "c" ) ) {
6348 dmsa0.deleteRow( "e", false );
6349 dmsa0.deleteRow( "a", false );
6350 dmsa0.deleteRow( "f", false );
6351 if ( dmsa0.getLength() != 4 ) {
6354 if ( dmsa0.getNumberOfSequences() != 2 ) {
6357 if ( !dmsa0.getIdentifier( 0 ).equals( "c" ) ) {
6360 if ( !dmsa0.getIdentifier( 1 ).equals( "d" ) ) {
6363 if ( dmsa0.getResidueAt( 0, 0 ) != 'C' ) {
6366 if ( !dmsa0.getSequenceAsString( 0 ).toString().equals( "CAAA" ) ) {
6369 if ( dmsa0.getColumnAt( 0 ).size() != 2 ) {
6372 dmsa0.deleteRow( "c", false );
6373 dmsa0.deleteRow( "d", false );
6374 if ( dmsa0.getNumberOfSequences() != 0 ) {
6378 final MolecularSequence s_0 = BasicSequence.createAaSequence( "a", "--A---B-C--X----" );
6379 final MolecularSequence s_1 = BasicSequence.createAaSequence( "b", "--B-----C-------" );
6380 final MolecularSequence s_2 = BasicSequence.createAaSequence( "c", "--C--AB-C------Z" );
6381 final MolecularSequence s_3 = BasicSequence.createAaSequence( "d", "--D--AA-C-------" );
6382 final MolecularSequence s_4 = BasicSequence.createAaSequence( "e", "--E--AA-C-------" );
6383 final MolecularSequence s_5 = BasicSequence.createAaSequence( "f", "--F--AB-CD--Y---" );
6384 final List<MolecularSequence> l1 = new ArrayList<MolecularSequence>();
6391 final DeleteableMsa dmsa1 = DeleteableMsa.createInstance( l1 );
6392 dmsa1.deleteGapOnlyColumns();
6393 dmsa1.deleteRow( "a", false );
6394 dmsa1.deleteRow( "f", false );
6395 dmsa1.deleteRow( "d", false );
6396 dmsa1.deleteGapOnlyColumns();
6397 if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C-" ) ) {
6400 if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "CABCZ" ) ) {
6403 if ( !dmsa1.getSequenceAsString( 2 ).toString().equals( "EAAC-" ) ) {
6406 dmsa1.deleteRow( "c", false );
6407 dmsa1.deleteGapOnlyColumns();
6408 final Writer w0 = new StringWriter();
6409 dmsa1.write( w0, MSA_FORMAT.FASTA );
6410 final Writer w1 = new StringWriter();
6411 dmsa1.write( w1, MSA_FORMAT.PHYLIP );
6412 if ( !dmsa1.getSequenceAsString( 0 ).toString().equals( "B--C" ) ) {
6415 if ( !dmsa1.getSequenceAsString( 1 ).toString().equals( "EAAC" ) ) {
6418 final MolecularSequence s__0 = BasicSequence.createAaSequence( "a", "A------" );
6419 final MolecularSequence s__1 = BasicSequence.createAaSequence( "b", "BB-----" );
6420 final MolecularSequence s__2 = BasicSequence.createAaSequence( "c", "CCC----" );
6421 final MolecularSequence s__3 = BasicSequence.createAaSequence( "d", "DDDD---" );
6422 final MolecularSequence s__4 = BasicSequence.createAaSequence( "e", "EEEEE--" );
6423 final MolecularSequence s__5 = BasicSequence.createAaSequence( "f", "FFFFFF-" );
6424 final List<MolecularSequence> l2 = new ArrayList<MolecularSequence>();
6431 final DeleteableMsa dmsa2 = DeleteableMsa.createInstance( l2 );
6432 dmsa2.deleteGapColumns( 0.5 );
6433 if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A---" ) ) {
6436 if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB--" ) ) {
6439 if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CCC-" ) ) {
6442 dmsa2.deleteGapColumns( 0.2 );
6443 if ( !dmsa2.getSequenceAsString( 0 ).toString().equals( "A-" ) ) {
6446 if ( !dmsa2.getSequenceAsString( 1 ).toString().equals( "BB" ) ) {
6449 if ( !dmsa2.getSequenceAsString( 2 ).toString().equals( "CC" ) ) {
6452 dmsa2.deleteGapColumns( 0 );
6453 dmsa2.deleteRow( "a", false );
6454 dmsa2.deleteRow( "b", false );
6455 dmsa2.deleteRow( "f", false );
6456 dmsa2.deleteRow( "e", false );
6457 dmsa2.setIdentifier( 0, "new_c" );
6458 dmsa2.setIdentifier( 1, "new_d" );
6459 dmsa2.setResidueAt( 0, 0, 'x' );
6460 final MolecularSequence s = dmsa2.deleteRow( "new_d", true );
6461 if ( !s.getMolecularSequenceAsString().equals( "D" ) ) {
6464 final Writer w = new StringWriter();
6465 dmsa2.write( w, MSA_FORMAT.PHYLIP );
6466 final String phylip = w.toString();
6467 if ( !phylip.equals( "1 1" + ForesterUtil.LINE_SEPARATOR + "new_c x" + ForesterUtil.LINE_SEPARATOR ) ) {
6468 System.out.println( phylip );
6471 final Writer w2 = new StringWriter();
6472 dmsa2.write( w2, MSA_FORMAT.FASTA );
6473 final String fasta = w2.toString();
6474 if ( !fasta.equals( ">new_c" + ForesterUtil.LINE_SEPARATOR + "x" + ForesterUtil.LINE_SEPARATOR ) ) {
6475 System.out.println( fasta );
6479 catch ( final Exception e ) {
6480 e.printStackTrace( System.out );
6486 private static boolean testNextNodeWithCollapsing() {
6488 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
6490 List<PhylogenyNode> ext = new ArrayList<PhylogenyNode>();
6491 final StringBuffer sb0 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6492 final Phylogeny t0 = factory.create( sb0, new NHXParser() )[ 0 ];
6493 t0.getNode( "cd" ).setCollapse( true );
6494 t0.getNode( "cde" ).setCollapse( true );
6495 n = t0.getFirstExternalNode();
6496 while ( n != null ) {
6498 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6500 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6503 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6506 if ( !ext.get( 2 ).getName().equals( "cde" ) ) {
6509 if ( !ext.get( 3 ).getName().equals( "f" ) ) {
6512 if ( !ext.get( 4 ).getName().equals( "g" ) ) {
6515 if ( !ext.get( 5 ).getName().equals( "h" ) ) {
6519 final StringBuffer sb1 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6520 final Phylogeny t1 = factory.create( sb1, new NHXParser() )[ 0 ];
6521 t1.getNode( "ab" ).setCollapse( true );
6522 t1.getNode( "cd" ).setCollapse( true );
6523 t1.getNode( "cde" ).setCollapse( true );
6524 n = t1.getNode( "ab" );
6525 ext = new ArrayList<PhylogenyNode>();
6526 while ( n != null ) {
6528 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6530 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6533 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6536 if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6539 if ( !ext.get( 3 ).getName().equals( "g" ) ) {
6542 if ( !ext.get( 4 ).getName().equals( "h" ) ) {
6546 final StringBuffer sb2 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6547 final Phylogeny t2 = factory.create( sb2, new NHXParser() )[ 0 ];
6548 t2.getNode( "ab" ).setCollapse( true );
6549 t2.getNode( "cd" ).setCollapse( true );
6550 t2.getNode( "cde" ).setCollapse( true );
6551 t2.getNode( "c" ).setCollapse( true );
6552 t2.getNode( "d" ).setCollapse( true );
6553 t2.getNode( "e" ).setCollapse( true );
6554 t2.getNode( "gh" ).setCollapse( true );
6555 n = t2.getNode( "ab" );
6556 ext = new ArrayList<PhylogenyNode>();
6557 while ( n != null ) {
6559 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6561 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6564 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6567 if ( !ext.get( 2 ).getName().equals( "f" ) ) {
6570 if ( !ext.get( 3 ).getName().equals( "gh" ) ) {
6574 final StringBuffer sb3 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6575 final Phylogeny t3 = factory.create( sb3, new NHXParser() )[ 0 ];
6576 t3.getNode( "ab" ).setCollapse( true );
6577 t3.getNode( "cd" ).setCollapse( true );
6578 t3.getNode( "cde" ).setCollapse( true );
6579 t3.getNode( "c" ).setCollapse( true );
6580 t3.getNode( "d" ).setCollapse( true );
6581 t3.getNode( "e" ).setCollapse( true );
6582 t3.getNode( "gh" ).setCollapse( true );
6583 t3.getNode( "fgh" ).setCollapse( true );
6584 n = t3.getNode( "ab" );
6585 ext = new ArrayList<PhylogenyNode>();
6586 while ( n != null ) {
6588 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6590 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6593 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
6596 if ( !ext.get( 2 ).getName().equals( "fgh" ) ) {
6600 final StringBuffer sb4 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6601 final Phylogeny t4 = factory.create( sb4, new NHXParser() )[ 0 ];
6602 t4.getNode( "ab" ).setCollapse( true );
6603 t4.getNode( "cd" ).setCollapse( true );
6604 t4.getNode( "cde" ).setCollapse( true );
6605 t4.getNode( "c" ).setCollapse( true );
6606 t4.getNode( "d" ).setCollapse( true );
6607 t4.getNode( "e" ).setCollapse( true );
6608 t4.getNode( "gh" ).setCollapse( true );
6609 t4.getNode( "fgh" ).setCollapse( true );
6610 t4.getNode( "abcdefgh" ).setCollapse( true );
6611 n = t4.getNode( "abcdefgh" );
6612 if ( n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() != null ) {
6615 final StringBuffer sb5 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6616 final Phylogeny t5 = factory.create( sb5, new NHXParser() )[ 0 ];
6618 n = t5.getFirstExternalNode();
6619 while ( n != null ) {
6621 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6623 if ( ext.size() != 8 ) {
6626 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6629 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6632 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6635 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6638 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6641 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6644 if ( !ext.get( 6 ).getName().equals( "g" ) ) {
6647 if ( !ext.get( 7 ).getName().equals( "h" ) ) {
6650 final StringBuffer sb6 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6651 final Phylogeny t6 = factory.create( sb6, new NHXParser() )[ 0 ];
6653 t6.getNode( "ab" ).setCollapse( true );
6654 n = t6.getNode( "ab" );
6655 while ( n != null ) {
6657 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6659 if ( ext.size() != 7 ) {
6662 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6665 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6668 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6671 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6674 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6677 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6680 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6683 final StringBuffer sb7 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6684 final Phylogeny t7 = factory.create( sb7, new NHXParser() )[ 0 ];
6686 t7.getNode( "cd" ).setCollapse( true );
6687 n = t7.getNode( "a" );
6688 while ( n != null ) {
6690 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6692 if ( ext.size() != 7 ) {
6695 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6698 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6701 if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6704 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6707 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6710 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6713 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6716 final StringBuffer sb8 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h))fgh)cdefgh)abcdefgh" );
6717 final Phylogeny t8 = factory.create( sb8, new NHXParser() )[ 0 ];
6719 t8.getNode( "cd" ).setCollapse( true );
6720 t8.getNode( "c" ).setCollapse( true );
6721 t8.getNode( "d" ).setCollapse( true );
6722 n = t8.getNode( "a" );
6723 while ( n != null ) {
6725 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6727 if ( ext.size() != 7 ) {
6730 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6733 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6736 if ( !ext.get( 2 ).getName().equals( "cd" ) ) {
6737 System.out.println( "2 fail" );
6740 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6743 if ( !ext.get( 4 ).getName().equals( "f" ) ) {
6746 if ( !ext.get( 5 ).getName().equals( "g" ) ) {
6749 if ( !ext.get( 6 ).getName().equals( "h" ) ) {
6752 final StringBuffer sb9 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6753 final Phylogeny t9 = factory.create( sb9, new NHXParser() )[ 0 ];
6755 t9.getNode( "gh" ).setCollapse( true );
6756 n = t9.getNode( "a" );
6757 while ( n != null ) {
6759 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6761 if ( ext.size() != 7 ) {
6764 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6767 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6770 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6773 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6776 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6779 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6782 if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6785 final StringBuffer sb10 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6786 final Phylogeny t10 = factory.create( sb10, new NHXParser() )[ 0 ];
6788 t10.getNode( "gh" ).setCollapse( true );
6789 t10.getNode( "g" ).setCollapse( true );
6790 t10.getNode( "h" ).setCollapse( true );
6791 n = t10.getNode( "a" );
6792 while ( n != null ) {
6794 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6796 if ( ext.size() != 7 ) {
6799 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6802 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6805 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6808 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6811 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6814 if ( !ext.get( 5 ).getName().equals( "f" ) ) {
6817 if ( !ext.get( 6 ).getName().equals( "gh" ) ) {
6820 final StringBuffer sb11 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6821 final Phylogeny t11 = factory.create( sb11, new NHXParser() )[ 0 ];
6823 t11.getNode( "gh" ).setCollapse( true );
6824 t11.getNode( "fgh" ).setCollapse( true );
6825 n = t11.getNode( "a" );
6826 while ( n != null ) {
6828 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6830 if ( ext.size() != 6 ) {
6833 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6836 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6839 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6842 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6845 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6848 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6851 final StringBuffer sb12 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6852 final Phylogeny t12 = factory.create( sb12, new NHXParser() )[ 0 ];
6854 t12.getNode( "gh" ).setCollapse( true );
6855 t12.getNode( "fgh" ).setCollapse( true );
6856 t12.getNode( "g" ).setCollapse( true );
6857 t12.getNode( "h" ).setCollapse( true );
6858 t12.getNode( "f" ).setCollapse( true );
6859 n = t12.getNode( "a" );
6860 while ( n != null ) {
6862 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6864 if ( ext.size() != 6 ) {
6867 if ( !ext.get( 0 ).getName().equals( "a" ) ) {
6870 if ( !ext.get( 1 ).getName().equals( "b" ) ) {
6873 if ( !ext.get( 2 ).getName().equals( "c" ) ) {
6876 if ( !ext.get( 3 ).getName().equals( "d" ) ) {
6879 if ( !ext.get( 4 ).getName().equals( "e" ) ) {
6882 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6885 final StringBuffer sb13 = new StringBuffer( "((a,b)ab,(((c,d)cd,e)cde,(f,(g,h)gh)fgh)cdefgh)abcdefgh" );
6886 final Phylogeny t13 = factory.create( sb13, new NHXParser() )[ 0 ];
6888 t13.getNode( "ab" ).setCollapse( true );
6889 t13.getNode( "b" ).setCollapse( true );
6890 t13.getNode( "fgh" ).setCollapse( true );
6891 t13.getNode( "gh" ).setCollapse( true );
6892 n = t13.getNode( "ab" );
6893 while ( n != null ) {
6895 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6897 if ( ext.size() != 5 ) {
6900 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6903 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6906 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6909 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6912 if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6915 final StringBuffer sb14 = new StringBuffer( "((a,b,0)ab,(((c,d)cd,e)cde,(f,(g,h,1,2)gh,0)fgh)cdefgh)abcdefgh" );
6916 final Phylogeny t14 = factory.create( sb14, new NHXParser() )[ 0 ];
6918 t14.getNode( "ab" ).setCollapse( true );
6919 t14.getNode( "a" ).setCollapse( true );
6920 t14.getNode( "fgh" ).setCollapse( true );
6921 t14.getNode( "gh" ).setCollapse( true );
6922 n = t14.getNode( "ab" );
6923 while ( n != null ) {
6925 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6927 if ( ext.size() != 5 ) {
6930 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6933 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6936 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6939 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6942 if ( !ext.get( 4 ).getName().equals( "fgh" ) ) {
6945 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" );
6946 final Phylogeny t15 = factory.create( sb15, new NHXParser() )[ 0 ];
6948 t15.getNode( "ab" ).setCollapse( true );
6949 t15.getNode( "a" ).setCollapse( true );
6950 t15.getNode( "fgh" ).setCollapse( true );
6951 t15.getNode( "gh" ).setCollapse( true );
6952 n = t15.getNode( "ab" );
6953 while ( n != null ) {
6955 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6957 if ( ext.size() != 6 ) {
6960 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
6963 if ( !ext.get( 1 ).getName().equals( "c" ) ) {
6966 if ( !ext.get( 2 ).getName().equals( "d" ) ) {
6969 if ( !ext.get( 3 ).getName().equals( "e" ) ) {
6972 if ( !ext.get( 4 ).getName().equals( "x" ) ) {
6975 if ( !ext.get( 5 ).getName().equals( "fgh" ) ) {
6980 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" );
6981 final Phylogeny t16 = factory.create( sb16, new NHXParser() )[ 0 ];
6983 t16.getNode( "ab" ).setCollapse( true );
6984 t16.getNode( "a" ).setCollapse( true );
6985 t16.getNode( "fgh" ).setCollapse( true );
6986 t16.getNode( "gh" ).setCollapse( true );
6987 t16.getNode( "cd" ).setCollapse( true );
6988 t16.getNode( "cde" ).setCollapse( true );
6989 t16.getNode( "d" ).setCollapse( true );
6990 t16.getNode( "x" ).setCollapse( true );
6991 n = t16.getNode( "ab" );
6992 while ( n != null ) {
6994 n = n.getNextExternalNodeWhileTakingIntoAccountCollapsedNodes();
6996 if ( ext.size() != 4 ) {
6999 if ( !ext.get( 0 ).getName().equals( "ab" ) ) {
7002 if ( !ext.get( 1 ).getName().equals( "cde" ) ) {
7005 if ( !ext.get( 2 ).getName().equals( "x" ) ) {
7008 if ( !ext.get( 3 ).getName().equals( "fgh" ) ) {
7012 catch ( final Exception e ) {
7013 e.printStackTrace( System.out );
7019 private static boolean testNexusCharactersParsing() {
7021 final NexusCharactersParser parser = new NexusCharactersParser();
7022 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex" ) );
7024 String[] labels = parser.getCharStateLabels();
7025 if ( labels.length != 7 ) {
7028 if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7031 if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7034 if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7037 if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7040 if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7043 if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7046 if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7049 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7051 labels = parser.getCharStateLabels();
7052 if ( labels.length != 7 ) {
7055 if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7058 if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7061 if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7064 if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7067 if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7070 if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7073 if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7077 catch ( final Exception e ) {
7078 e.printStackTrace( System.out );
7084 private static boolean testNexusMatrixParsing() {
7086 final NexusBinaryStatesMatrixParser parser = new NexusBinaryStatesMatrixParser();
7087 parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_9.nex" ) );
7089 final CharacterStateMatrix<BinaryStates> m = parser.getMatrix();
7090 if ( m.getNumberOfCharacters() != 9 ) {
7093 if ( m.getNumberOfIdentifiers() != 5 ) {
7096 if ( m.getState( 0, 0 ) != BinaryStates.PRESENT ) {
7099 if ( m.getState( 0, 1 ) != BinaryStates.ABSENT ) {
7102 if ( m.getState( 1, 0 ) != BinaryStates.PRESENT ) {
7105 if ( m.getState( 2, 0 ) != BinaryStates.ABSENT ) {
7108 if ( m.getState( 4, 8 ) != BinaryStates.PRESENT ) {
7111 if ( !m.getIdentifier( 0 ).equals( "MOUSE" ) ) {
7114 if ( !m.getIdentifier( 4 ).equals( "ARATH" ) ) {
7117 // if ( labels.length != 7 ) {
7120 // if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7123 // if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7126 // if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7129 // if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7132 // if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7135 // if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7138 // if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7141 // parser.setSource( new File( Test.PATH_TO_TEST_DATA + "nexus_test_8.nex" ) );
7143 // labels = parser.getCharStateLabels();
7144 // if ( labels.length != 7 ) {
7147 // if ( !labels[ 0 ].equals( "14-3-3" ) ) {
7150 // if ( !labels[ 1 ].equals( "2-Hacid_dh" ) ) {
7153 // if ( !labels[ 2 ].equals( "2-Hacid_dh_C" ) ) {
7156 // if ( !labels[ 3 ].equals( "2-oxoacid_dh" ) ) {
7159 // if ( !labels[ 4 ].equals( "2OG-FeII_Oxy" ) ) {
7162 // if ( !labels[ 5 ].equals( "3-HAO" ) ) {
7165 // if ( !labels[ 6 ].equals( "3_5_exonuc" ) ) {
7169 catch ( final Exception e ) {
7170 e.printStackTrace( System.out );
7176 private static boolean testNexusTreeParsing() {
7178 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
7179 final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
7180 Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex", parser );
7181 if ( phylogenies.length != 1 ) {
7184 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 25 ) {
7187 if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7191 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex", parser );
7192 if ( phylogenies.length != 1 ) {
7195 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7198 if ( !phylogenies[ 0 ].getName().equals( "name" ) ) {
7202 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex", parser );
7203 if ( phylogenies.length != 1 ) {
7206 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
7209 if ( !phylogenies[ 0 ].getName().equals( "" ) ) {
7212 if ( phylogenies[ 0 ].isRooted() ) {
7216 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_4.nex", parser );
7217 if ( phylogenies.length != 18 ) {
7220 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 10 ) {
7223 if ( !phylogenies[ 0 ].getName().equals( "tree 0" ) ) {
7226 if ( !phylogenies[ 1 ].getName().equals( "tree 1" ) ) {
7229 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 10 ) {
7232 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
7235 if ( phylogenies[ 3 ].getNumberOfExternalNodes() != 3 ) {
7238 if ( phylogenies[ 4 ].getNumberOfExternalNodes() != 3 ) {
7241 if ( phylogenies[ 5 ].getNumberOfExternalNodes() != 3 ) {
7244 if ( phylogenies[ 6 ].getNumberOfExternalNodes() != 3 ) {
7247 if ( phylogenies[ 7 ].getNumberOfExternalNodes() != 3 ) {
7250 if ( !phylogenies[ 8 ].getName().equals( "tree 8" ) ) {
7253 if ( phylogenies[ 8 ].isRooted() ) {
7256 if ( phylogenies[ 8 ].getNumberOfExternalNodes() != 3 ) {
7259 if ( !phylogenies[ 9 ].getName().equals( "tree 9" ) ) {
7262 if ( !phylogenies[ 9 ].isRooted() ) {
7265 if ( phylogenies[ 9 ].getNumberOfExternalNodes() != 3 ) {
7268 if ( !phylogenies[ 10 ].getName().equals( "tree 10" ) ) {
7271 if ( !phylogenies[ 10 ].isRooted() ) {
7274 if ( phylogenies[ 10 ].getNumberOfExternalNodes() != 3 ) {
7277 if ( !phylogenies[ 11 ].getName().equals( "tree 11" ) ) {
7280 if ( phylogenies[ 11 ].isRooted() ) {
7283 if ( phylogenies[ 11 ].getNumberOfExternalNodes() != 3 ) {
7286 if ( !phylogenies[ 12 ].getName().equals( "tree 12" ) ) {
7289 if ( !phylogenies[ 12 ].isRooted() ) {
7292 if ( phylogenies[ 12 ].getNumberOfExternalNodes() != 3 ) {
7295 if ( !phylogenies[ 13 ].getName().equals( "tree 13" ) ) {
7298 if ( !phylogenies[ 13 ].isRooted() ) {
7301 if ( phylogenies[ 13 ].getNumberOfExternalNodes() != 3 ) {
7304 if ( !phylogenies[ 14 ].getName().equals( "tree 14" ) ) {
7307 if ( !phylogenies[ 14 ].isRooted() ) {
7310 if ( phylogenies[ 14 ].getNumberOfExternalNodes() != 10 ) {
7313 if ( !phylogenies[ 15 ].getName().equals( "tree 15" ) ) {
7316 if ( phylogenies[ 15 ].isRooted() ) {
7319 if ( phylogenies[ 15 ].getNumberOfExternalNodes() != 10 ) {
7322 if ( !phylogenies[ 16 ].getName().equals( "tree 16" ) ) {
7325 if ( !phylogenies[ 16 ].isRooted() ) {
7328 if ( phylogenies[ 16 ].getNumberOfExternalNodes() != 10 ) {
7331 if ( !phylogenies[ 17 ].getName().equals( "tree 17" ) ) {
7334 if ( phylogenies[ 17 ].isRooted() ) {
7337 if ( phylogenies[ 17 ].getNumberOfExternalNodes() != 10 ) {
7340 final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7342 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S15613.nex", p2 );
7343 if ( phylogenies.length != 9 ) {
7346 if ( !isEqual( 0.48039661496919533, phylogenies[ 0 ].getNode( "Diadocidia_spinosula" )
7347 .getDistanceToParent() ) ) {
7350 if ( !isEqual( 0.3959796191512233, phylogenies[ 0 ].getNode( "Diadocidia_stanfordensis" )
7351 .getDistanceToParent() ) ) {
7354 if ( !phylogenies[ 0 ].getName().equals( "Family Diadocidiidae MLT (Imported_tree_0)" ) ) {
7357 if ( !phylogenies[ 1 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7360 if ( !phylogenies[ 2 ].getName().equals( "Family Diadocidiidae BAT (con_50_majrule)" ) ) {
7363 if ( !isEqual( 0.065284, phylogenies[ 7 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7366 if ( !isEqual( 0.065284, phylogenies[ 8 ].getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7370 catch ( final Exception e ) {
7371 e.printStackTrace( System.out );
7377 private static boolean testNexusTreeParsingIterating() {
7379 final NexusPhylogeniesParser p = new NexusPhylogeniesParser();
7380 p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_1.nex" );
7381 if ( !p.hasNext() ) {
7384 Phylogeny phy = p.next();
7385 if ( phy == null ) {
7388 if ( phy.getNumberOfExternalNodes() != 25 ) {
7391 if ( !phy.getName().equals( "" ) ) {
7394 if ( p.hasNext() ) {
7398 if ( phy != null ) {
7402 if ( !p.hasNext() ) {
7406 if ( phy == null ) {
7409 if ( phy.getNumberOfExternalNodes() != 25 ) {
7412 if ( !phy.getName().equals( "" ) ) {
7415 if ( p.hasNext() ) {
7419 if ( phy != null ) {
7422 p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_2.nex" );
7423 if ( !p.hasNext() ) {
7427 if ( phy == null ) {
7430 if ( phy.getNumberOfExternalNodes() != 10 ) {
7433 if ( !phy.getName().equals( "name" ) ) {
7436 if ( p.hasNext() ) {
7440 if ( phy != null ) {
7444 if ( !p.hasNext() ) {
7448 if ( phy == null ) {
7451 if ( phy.getNumberOfExternalNodes() != 10 ) {
7454 if ( !phy.getName().equals( "name" ) ) {
7457 if ( p.hasNext() ) {
7461 if ( phy != null ) {
7464 p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_3.nex" );
7465 if ( !p.hasNext() ) {
7469 if ( phy == null ) {
7472 if ( phy.getNumberOfExternalNodes() != 3 ) {
7475 if ( !phy.getName().equals( "" ) ) {
7478 if ( phy.isRooted() ) {
7481 if ( p.hasNext() ) {
7485 if ( phy != null ) {
7490 if ( !p.hasNext() ) {
7494 if ( phy == null ) {
7497 if ( phy.getNumberOfExternalNodes() != 3 ) {
7500 if ( !phy.getName().equals( "" ) ) {
7503 if ( p.hasNext() ) {
7507 if ( phy != null ) {
7511 p.setSource( Test.PATH_TO_TEST_DATA + "nexus_test_4_1.nex" );
7512 if ( !p.hasNext() ) {
7517 if ( phy == null ) {
7520 if ( phy.getNumberOfExternalNodes() != 10 ) {
7523 if ( !phy.getName().equals( "tree 0" ) ) {
7527 if ( !p.hasNext() ) {
7531 if ( phy == null ) {
7534 if ( phy.getNumberOfExternalNodes() != 10 ) {
7537 if ( !phy.getName().equals( "tree 1" ) ) {
7541 if ( !p.hasNext() ) {
7545 if ( phy == null ) {
7548 if ( phy.getNumberOfExternalNodes() != 3 ) {
7549 System.out.println( phy.toString() );
7552 if ( !phy.getName().equals( "" ) ) {
7555 if ( phy.isRooted() ) {
7559 if ( !p.hasNext() ) {
7563 if ( phy == null ) {
7566 if ( phy.getNumberOfExternalNodes() != 4 ) {
7569 if ( !phy.getName().equals( "" ) ) {
7572 if ( !phy.isRooted() ) {
7576 if ( !p.hasNext() ) {
7580 if ( phy == null ) {
7583 if ( phy.getNumberOfExternalNodes() != 5 ) {
7584 System.out.println( phy.getNumberOfExternalNodes() );
7587 if ( !phy.getName().equals( "" ) ) {
7590 if ( !phy.isRooted() ) {
7594 if ( !p.hasNext() ) {
7598 if ( phy == null ) {
7601 if ( phy.getNumberOfExternalNodes() != 3 ) {
7604 if ( !phy.getName().equals( "" ) ) {
7607 if ( phy.isRooted() ) {
7611 if ( !p.hasNext() ) {
7615 if ( phy == null ) {
7618 if ( phy.getNumberOfExternalNodes() != 2 ) {
7621 if ( !phy.getName().equals( "" ) ) {
7624 if ( !phy.isRooted() ) {
7628 if ( !p.hasNext() ) {
7632 if ( phy.getNumberOfExternalNodes() != 3 ) {
7635 if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7638 if ( !phy.isRooted() ) {
7642 if ( !p.hasNext() ) {
7646 if ( phy.getNumberOfExternalNodes() != 3 ) {
7649 if ( !phy.toNewHampshire().equals( "((AA,BB),CC);" ) ) {
7652 if ( !phy.getName().equals( "tree 8" ) ) {
7656 if ( !p.hasNext() ) {
7660 if ( phy.getNumberOfExternalNodes() != 3 ) {
7663 if ( !phy.toNewHampshire().equals( "((a,b),cc);" ) ) {
7666 if ( !phy.getName().equals( "tree 9" ) ) {
7670 if ( !p.hasNext() ) {
7674 if ( phy.getNumberOfExternalNodes() != 3 ) {
7677 if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7680 if ( !phy.getName().equals( "tree 10" ) ) {
7683 if ( !phy.isRooted() ) {
7687 if ( !p.hasNext() ) {
7691 if ( phy.getNumberOfExternalNodes() != 3 ) {
7694 if ( !phy.toNewHampshire().equals( "((1,2),3);" ) ) {
7697 if ( !phy.getName().equals( "tree 11" ) ) {
7700 if ( phy.isRooted() ) {
7704 if ( !p.hasNext() ) {
7708 if ( phy.getNumberOfExternalNodes() != 3 ) {
7711 if ( !phy.toNewHampshire().equals( "((aa,bb),cc);" ) ) {
7714 if ( !phy.getName().equals( "tree 12" ) ) {
7717 if ( !phy.isRooted() ) {
7721 if ( !p.hasNext() ) {
7725 if ( phy.getNumberOfExternalNodes() != 3 ) {
7728 if ( !phy.toNewHampshire().equals( "((a,b),c);" ) ) {
7731 if ( !phy.getName().equals( "tree 13" ) ) {
7734 if ( !phy.isRooted() ) {
7738 if ( !p.hasNext() ) {
7742 if ( phy.getNumberOfExternalNodes() != 10 ) {
7743 System.out.println( phy.getNumberOfExternalNodes() );
7748 .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;" ) ) {
7749 System.out.println( phy.toNewHampshire() );
7752 if ( !phy.getName().equals( "tree 14" ) ) {
7755 if ( !phy.isRooted() ) {
7759 if ( !p.hasNext() ) {
7763 if ( phy.getNumberOfExternalNodes() != 10 ) {
7764 System.out.println( phy.getNumberOfExternalNodes() );
7769 .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;" ) ) {
7770 System.out.println( phy.toNewHampshire() );
7773 if ( !phy.getName().equals( "tree 15" ) ) {
7776 if ( phy.isRooted() ) {
7780 if ( !p.hasNext() ) {
7784 if ( phy.getNumberOfExternalNodes() != 10 ) {
7785 System.out.println( phy.getNumberOfExternalNodes() );
7790 .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;" ) ) {
7791 System.out.println( phy.toNewHampshire() );
7794 if ( !phy.getName().equals( "tree 16" ) ) {
7797 if ( !phy.isRooted() ) {
7801 if ( !p.hasNext() ) {
7805 if ( phy.getNumberOfExternalNodes() != 10 ) {
7806 System.out.println( phy.getNumberOfExternalNodes() );
7811 .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;" ) ) {
7812 System.out.println( phy.toNewHampshire() );
7815 if ( !phy.getName().equals( "tree 17" ) ) {
7818 if ( phy.isRooted() ) {
7822 if ( p.hasNext() ) {
7826 if ( phy != null ) {
7831 if ( !p.hasNext() ) {
7835 if ( phy == null ) {
7838 if ( phy.getNumberOfExternalNodes() != 10 ) {
7841 if ( !phy.getName().equals( "tree 0" ) ) {
7845 if ( !p.hasNext() ) {
7849 if ( phy == null ) {
7852 if ( phy.getNumberOfExternalNodes() != 10 ) {
7855 if ( !phy.getName().equals( "tree 1" ) ) {
7859 if ( !p.hasNext() ) {
7863 if ( phy == null ) {
7866 if ( phy.getNumberOfExternalNodes() != 3 ) {
7869 if ( !phy.getName().equals( "" ) ) {
7872 if ( phy.isRooted() ) {
7876 if ( !p.hasNext() ) {
7880 if ( phy == null ) {
7883 if ( phy.getNumberOfExternalNodes() != 4 ) {
7886 if ( !phy.getName().equals( "" ) ) {
7889 if ( !phy.isRooted() ) {
7893 if ( !p.hasNext() ) {
7897 if ( phy == null ) {
7900 if ( phy.getNumberOfExternalNodes() != 5 ) {
7901 System.out.println( phy.getNumberOfExternalNodes() );
7904 if ( !phy.getName().equals( "" ) ) {
7907 if ( !phy.isRooted() ) {
7911 if ( !p.hasNext() ) {
7915 if ( phy == null ) {
7918 if ( phy.getNumberOfExternalNodes() != 3 ) {
7921 if ( !phy.getName().equals( "" ) ) {
7924 if ( phy.isRooted() ) {
7928 final NexusPhylogeniesParser p2 = new NexusPhylogeniesParser();
7929 p2.setSource( Test.PATH_TO_TEST_DATA + "S15613.nex" );
7931 if ( !p2.hasNext() ) {
7935 if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
7938 if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
7942 if ( !p2.hasNext() ) {
7947 if ( !p2.hasNext() ) {
7952 if ( !p2.hasNext() ) {
7957 if ( !p2.hasNext() ) {
7962 if ( !p2.hasNext() ) {
7967 if ( !p2.hasNext() ) {
7972 if ( !p2.hasNext() ) {
7977 if ( !p2.hasNext() ) {
7981 if ( !isEqual( 0.065284, phy.getNode( "Bradysia_amoena" ).getDistanceToParent() ) ) {
7984 if ( p2.hasNext() ) {
7988 if ( phy != null ) {
7993 if ( !p2.hasNext() ) {
7997 if ( !isEqual( 0.48039661496919533, phy.getNode( "Diadocidia_spinosula" ).getDistanceToParent() ) ) {
8000 if ( !isEqual( 0.3959796191512233, phy.getNode( "Diadocidia_stanfordensis" ).getDistanceToParent() ) ) {
8004 catch ( final Exception e ) {
8005 e.printStackTrace( System.out );
8011 private static boolean testNexusTreeParsingTranslating() {
8013 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8014 final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
8015 Phylogeny[] phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_5.nex", parser );
8016 if ( phylogenies.length != 1 ) {
8019 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8022 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8025 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8028 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8031 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8032 .equals( "Aranaeus" ) ) {
8036 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_6.nex", parser );
8037 if ( phylogenies.length != 3 ) {
8040 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8043 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8046 if ( phylogenies[ 0 ].isRooted() ) {
8049 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8052 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8055 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8056 .equals( "Aranaeus" ) ) {
8059 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8062 if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8065 if ( phylogenies[ 1 ].isRooted() ) {
8068 if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8071 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8074 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8075 .equals( "Aranaeus" ) ) {
8078 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8081 if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8084 if ( !phylogenies[ 2 ].isRooted() ) {
8087 if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8090 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8093 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8094 .equals( "Aranaeus" ) ) {
8098 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "nexus_test_7.nex", parser );
8099 if ( phylogenies.length != 3 ) {
8102 if ( phylogenies[ 0 ].getNumberOfExternalNodes() != 3 ) {
8105 if ( !phylogenies[ 0 ].getName().equals( "Tree0" ) ) {
8108 if ( phylogenies[ 0 ].isRooted() ) {
8111 if ( !phylogenies[ 0 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8114 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8117 if ( !phylogenies[ 0 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8118 .equals( "Aranaeus" ) ) {
8121 if ( phylogenies[ 1 ].getNumberOfExternalNodes() != 3 ) {
8124 if ( !phylogenies[ 1 ].getName().equals( "Tree1" ) ) {
8127 if ( phylogenies[ 1 ].isRooted() ) {
8130 if ( !phylogenies[ 1 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8133 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8136 if ( !phylogenies[ 1 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8137 .equals( "Aranaeus" ) ) {
8140 if ( phylogenies[ 2 ].getNumberOfExternalNodes() != 3 ) {
8143 if ( !phylogenies[ 2 ].getName().equals( "Tree2" ) ) {
8146 if ( !phylogenies[ 2 ].isRooted() ) {
8149 if ( !phylogenies[ 2 ].getFirstExternalNode().getName().equals( "Scarabaeus" ) ) {
8152 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getName().equals( "Drosophila" ) ) {
8155 if ( !phylogenies[ 2 ].getFirstExternalNode().getNextExternalNode().getNextExternalNode().getName()
8156 .equals( "Aranaeus" ) ) {
8159 phylogenies = factory.create( Test.PATH_TO_TEST_DATA + "S14117.nex", parser );
8160 if ( phylogenies.length != 3 ) {
8163 if ( !isEqual( phylogenies[ 2 ].getNode( "Aloysia lycioides 251-76-02169" ).getDistanceToParent(),
8168 catch ( final Exception e ) {
8169 e.printStackTrace( System.out );
8175 private static boolean testNHParsing() {
8177 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
8178 final Phylogeny p1 = factory.create( "(A,B1)", new NHXParser() )[ 0 ];
8179 if ( !p1.toNewHampshireX().equals( "(A,B1)" ) ) {
8182 final NHXParser nhxp = new NHXParser();
8183 nhxp.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO );
8184 nhxp.setReplaceUnderscores( true );
8185 final Phylogeny uc0 = factory.create( "(A__A_,_B_B)", nhxp )[ 0 ];
8186 if ( !uc0.getRoot().getChildNode( 0 ).getName().equals( "A A" ) ) {
8189 if ( !uc0.getRoot().getChildNode( 1 ).getName().equals( "B B" ) ) {
8192 final Phylogeny p1b = factory
8193 .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 ",
8194 new NHXParser() )[ 0 ];
8195 if ( !p1b.toNewHampshireX().equals( "(';A;',';B;1;')" ) ) {
8198 if ( !p1b.toNewHampshire().equals( "(';A;',';B;1;');" ) ) {
8201 final Phylogeny p2 = factory.create( new StringBuffer( "(A,B2)" ), new NHXParser() )[ 0 ];
8202 final Phylogeny p3 = factory.create( new char[] { '(', 'A', ',', 'B', '3', ')' }, new NHXParser() )[ 0 ];
8203 final Phylogeny p4 = factory.create( "(A,B4);", new NHXParser() )[ 0 ];
8204 final Phylogeny p5 = factory.create( new StringBuffer( "(A,B5);" ), new NHXParser() )[ 0 ];
8205 final Phylogeny[] p7 = factory.create( "(A,B7);(C,D7)", new NHXParser() );
8206 final Phylogeny[] p8 = factory.create( "(A,B8) (C,D8)", new NHXParser() );
8207 final Phylogeny[] p9 = factory.create( "(A,B9)\n(C,D9)", new NHXParser() );
8208 final Phylogeny[] p10 = factory.create( "(A,B10);(C,D10);", new NHXParser() );
8209 final Phylogeny[] p11 = factory.create( "(A,B11);(C,D11) (E,F11)\t(G,H11)", new NHXParser() );
8210 final Phylogeny[] p12 = factory.create( "(A,B12) (C,D12) (E,F12) (G,H12)", new NHXParser() );
8211 final Phylogeny[] p13 = factory.create( " ; (;A; , ; B ; 1 3 ; \n)\t ( \n ;"
8212 + " C ; ,; D;13;);;;;;;(;E;,;F;13 ;) ; "
8213 + "; ; ( \t\n\r\b; G ;, ;H ;1 3; ) ; ; ;",
8215 if ( !p13[ 0 ].toNewHampshireX().equals( "(';A;',';B;13;')" ) ) {
8218 if ( !p13[ 1 ].toNewHampshireX().equals( "(';C;',';D;13;')" ) ) {
8221 if ( !p13[ 2 ].toNewHampshireX().equals( "(';E;',';F;13;')" ) ) {
8224 if ( !p13[ 3 ].toNewHampshireX().equals( "(';G;',';H;13;')" ) ) {
8227 final Phylogeny[] p14 = factory.create( "(A,B14)ab", new NHXParser() );
8228 final Phylogeny[] p15 = factory.create( "(A,B15)ab;", new NHXParser() );
8229 final String p16_S = "((A,B),C)";
8230 final Phylogeny[] p16 = factory.create( p16_S, new NHXParser() );
8231 if ( p16.length != 1 ) {
8234 if ( !p16[ 0 ].toNewHampshireX().equals( p16_S ) ) {
8237 final String p17_S = "(C,(A,B))";
8238 final Phylogeny[] p17 = factory.create( p17_S, new NHXParser() );
8239 if ( p17.length != 1 ) {
8242 if ( !p17[ 0 ].toNewHampshireX().equals( p17_S ) ) {
8245 final String p18_S = "((A,B),(C,D))";
8246 final Phylogeny[] p18 = factory.create( p18_S, new NHXParser() );
8247 if ( p18.length != 1 ) {
8250 if ( !p18[ 0 ].toNewHampshireX().equals( p18_S ) ) {
8253 final String p19_S = "(((A,B),C),D)";
8254 final Phylogeny[] p19 = factory.create( p19_S, new NHXParser() );
8255 if ( p19.length != 1 ) {
8258 if ( !p19[ 0 ].toNewHampshireX().equals( p19_S ) ) {
8261 final String p20_S = "(A,(B,(C,D)))";
8262 final Phylogeny[] p20 = factory.create( p20_S, new NHXParser() );
8263 if ( p20.length != 1 ) {
8266 if ( !p20[ 0 ].toNewHampshireX().equals( p20_S ) ) {
8269 final String p21_S = "(A,(B,(C,(D,E))))";
8270 final Phylogeny[] p21 = factory.create( p21_S, new NHXParser() );
8271 if ( p21.length != 1 ) {
8274 if ( !p21[ 0 ].toNewHampshireX().equals( p21_S ) ) {
8277 final String p22_S = "((((A,B),C),D),E)";
8278 final Phylogeny[] p22 = factory.create( p22_S, new NHXParser() );
8279 if ( p22.length != 1 ) {
8282 if ( !p22[ 0 ].toNewHampshireX().equals( p22_S ) ) {
8285 final String p23_S = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8286 final Phylogeny[] p23 = factory.create( p23_S, new NHXParser() );
8287 if ( p23.length != 1 ) {
8288 System.out.println( "xl=" + p23.length );
8292 if ( !p23[ 0 ].toNewHampshireX().equals( p23_S ) ) {
8295 final String p24_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8296 final Phylogeny[] p24 = factory.create( p24_S, new NHXParser() );
8297 if ( p24.length != 1 ) {
8300 if ( !p24[ 0 ].toNewHampshireX().equals( p24_S ) ) {
8303 final String p241_S1 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8304 final String p241_S2 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8305 final Phylogeny[] p241 = factory.create( p241_S1 + p241_S2, new NHXParser() );
8306 if ( p241.length != 2 ) {
8309 if ( !p241[ 0 ].toNewHampshireX().equals( p241_S1 ) ) {
8312 if ( !p241[ 1 ].toNewHampshireX().equals( p241_S2 ) ) {
8315 final String p25_S = "((((((((((((((A,B)ab,C)abc,D)abcd,E)"
8316 + "abcde,(B,(C,(D,E)de)cde)bcde)abcde,(B,((A,(B,(C,(D,"
8317 + "E)de)cde)bcde)abcde,(D,E)de)cde)bcde)abcde,B)ab,C)"
8318 + "abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde,"
8319 + "((((A,((((((((A,B)ab,C)abc,((((A,B)ab,C)abc,D)abcd,"
8320 + "E)abcde)abcd,E)abcde,((((A,B)ab,C)abc,D)abcd,E)abcde)"
8321 + "ab,C)abc,((((A,B)ab,C)abc,D)abcd,E)abcde)abcd,E)abcde"
8322 + ")ab,C)abc,D)abcd,E)abcde)ab,C)abc,((((A,B)ab,C)abc,D)" + "abcd,E)abcde)abcd,E)abcde";
8323 final Phylogeny[] p25 = factory.create( p25_S, new NHXParser() );
8324 if ( !p25[ 0 ].toNewHampshireX().equals( p25_S ) ) {
8327 final String p26_S = "(A,B)ab";
8328 final Phylogeny[] p26 = factory.create( p26_S, new NHXParser() );
8329 if ( !p26[ 0 ].toNewHampshireX().equals( p26_S ) ) {
8332 final String p27_S = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8333 final Phylogeny[] p27s = factory.create( p27_S, new NHXParser() );
8334 if ( p27s.length != 1 ) {
8335 System.out.println( "xxl=" + p27s.length );
8339 if ( !p27s[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8340 System.out.println( p27s[ 0 ].toNewHampshireX() );
8344 final Phylogeny[] p27 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ),
8346 if ( p27.length != 1 ) {
8347 System.out.println( "yl=" + p27.length );
8351 if ( !p27[ 0 ].toNewHampshireX().equals( p27_S ) ) {
8352 System.out.println( p27[ 0 ].toNewHampshireX() );
8356 final String p28_S1 = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8357 final String p28_S2 = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8358 final String p28_S3 = "(A,B)ab";
8359 final String p28_S4 = "((((A,B),C),D),;E;)";
8360 final Phylogeny[] p28 = factory.create( new File( Test.PATH_TO_TEST_DATA + "phylogeny28.nhx" ),
8362 if ( !p28[ 0 ].toNewHampshireX().equals( p28_S1 ) ) {
8365 if ( !p28[ 1 ].toNewHampshireX().equals( p28_S2 ) ) {
8368 if ( !p28[ 2 ].toNewHampshireX().equals( p28_S3 ) ) {
8371 if ( !p28[ 3 ].toNewHampshireX().equals( "((((A,B),C),D),';E;')" ) ) {
8374 if ( p28.length != 4 ) {
8377 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";
8378 final Phylogeny[] p29 = factory.create( p29_S, new NHXParser() );
8379 if ( !p29[ 0 ].toNewHampshireX().equals( p29_S ) ) {
8382 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";
8383 final Phylogeny[] p30 = factory.create( p30_S, new NHXParser() );
8384 if ( !p30[ 0 ].toNewHampshireX().equals( p30_S ) ) {
8387 final String p32_S = " ; ; \n \t \b \f \r ;;;;;; ";
8388 final Phylogeny[] p32 = factory.create( p32_S, new NHXParser() );
8389 if ( ( p32.length != 0 ) ) {
8392 final String p33_S = "A";
8393 final Phylogeny[] p33 = factory.create( p33_S, new NHXParser() );
8394 if ( !p33[ 0 ].toNewHampshireX().equals( p33_S ) ) {
8397 final String p34_S = "B;";
8398 final Phylogeny[] p34 = factory.create( p34_S, new NHXParser() );
8399 if ( !p34[ 0 ].toNewHampshireX().equals( "B" ) ) {
8402 final String p35_S = "B:0.2";
8403 final Phylogeny[] p35 = factory.create( p35_S, new NHXParser() );
8404 if ( !p35[ 0 ].toNewHampshireX().equals( p35_S ) ) {
8407 final String p36_S = "(A)";
8408 final Phylogeny[] p36 = factory.create( p36_S, new NHXParser() );
8409 if ( !p36[ 0 ].toNewHampshireX().equals( p36_S ) ) {
8412 final String p37_S = "((A))";
8413 final Phylogeny[] p37 = factory.create( p37_S, new NHXParser() );
8414 if ( !p37[ 0 ].toNewHampshireX().equals( p37_S ) ) {
8417 final String p38_S = "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8418 final Phylogeny[] p38 = factory.create( p38_S, new NHXParser() );
8419 if ( !p38[ 0 ].toNewHampshireX().equals( p38_S ) ) {
8422 final String p39_S = "(((B,((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8";
8423 final Phylogeny[] p39 = factory.create( p39_S, new NHXParser() );
8424 if ( !p39[ 0 ].toNewHampshireX().equals( p39_S ) ) {
8427 final String p40_S = "(A,B,C)";
8428 final Phylogeny[] p40 = factory.create( p40_S, new NHXParser() );
8429 if ( !p40[ 0 ].toNewHampshireX().equals( p40_S ) ) {
8432 final String p41_S = "(A,B,C,D,E,F,G,H,I,J,K)";
8433 final Phylogeny[] p41 = factory.create( p41_S, new NHXParser() );
8434 if ( !p41[ 0 ].toNewHampshireX().equals( p41_S ) ) {
8437 final String p42_S = "(A,B,(X,Y,Z),D,E,F,G,H,I,J,K)";
8438 final Phylogeny[] p42 = factory.create( p42_S, new NHXParser() );
8439 if ( !p42[ 0 ].toNewHampshireX().equals( p42_S ) ) {
8442 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)";
8443 final Phylogeny[] p43 = factory.create( p43_S, new NHXParser() );
8444 if ( !p43[ 0 ].toNewHampshireX().equals( p43_S ) ) {
8447 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)))";
8448 final Phylogeny[] p44 = factory.create( p44_S, new NHXParser() );
8449 if ( !p44[ 0 ].toNewHampshireX().equals( p44_S ) ) {
8452 final String p45_S = "((((((((((A))))))))),(((((((((B))))))))),(((((((((C))))))))))";
8453 final Phylogeny[] p45 = factory.create( p45_S, new NHXParser() );
8454 if ( !p45[ 0 ].toNewHampshireX().equals( p45_S ) ) {
8457 final String p46_S = "";
8458 final Phylogeny[] p46 = factory.create( p46_S, new NHXParser() );
8459 if ( p46.length != 0 ) {
8462 final Phylogeny p47 = factory.create( new StringBuffer( "((A,B)ab:2[0.44],C)" ), new NHXParser() )[ 0 ];
8463 if ( !isEqual( 0.44, p47.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8466 final Phylogeny p48 = factory.create( new StringBuffer( "((A,B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8467 if ( !isEqual( 88, p48.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8470 final Phylogeny p49 = factory
8471 .create( new StringBuffer( "((A,B)a[comment:a,b;(a)]b:2[0.44][comment(a,b,b);],C)" ),
8472 new NHXParser() )[ 0 ];
8473 if ( !isEqual( 0.44, p49.getNode( "ab" ).getBranchData().getConfidence( 0 ).getValue() ) ) {
8476 final Phylogeny p50 = factory.create( new StringBuffer( "((\"A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8477 if ( p50.getNode( "A" ) == null ) {
8480 if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
8481 .equals( "((A,B)ab:2.0[88],C);" ) ) {
8484 if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
8487 if ( !p50.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
8488 .equals( "((A,B)88:2.0,C);" ) ) {
8491 final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8492 if ( p51.getNode( "A(A" ) == null ) {
8495 final Phylogeny p52 = factory.create( new StringBuffer( "(('A(A',B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
8496 if ( p52.getNode( "A(A" ) == null ) {
8499 final Phylogeny p53 = factory
8500 .create( new StringBuffer( "(('A(A',\"B (x (a' ,b) f(x);\"[com])[ment]ab:2[88],C)" ),
8501 new NHXParser() )[ 0 ];
8502 if ( p53.getNode( "B (x (a' ,b) f(x);" ) == null ) {
8505 final Phylogeny p54 = factory.create( new StringBuffer( "((A,B):[88],C)" ), new NHXParser() )[ 0 ];
8506 if ( p54.getNode( "A" ) == null ) {
8509 if ( !p54.toNewHampshire( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ).equals( "((A,B)[88],C);" ) ) {
8512 final Phylogeny p55 = factory
8513 .create( new StringBuffer( "((\"lcl|HPV32_L1.:1 s\":0.195593,\"lcl|HPV30_L1.1|;a\":0.114237):0.0359322,\"lcl|HPV56_L1.1|,d\":0.0727412,\"lcl|HPV66_L1.1x\":0.0798012);" ),
8514 new NHXParser() )[ 0 ];
8517 .equals( "(('lcl|HPV32_L1.:1 s':0.195593,'lcl|HPV30_L1.1|;a':0.114237):0.0359322,'lcl|HPV56_L1.1|,d':0.0727412,lcl|HPV66_L1.1x:0.0798012);" ) ) {
8518 System.out.println( p55.toNewHampshire() );
8521 final Phylogeny p56 = factory
8522 .create( new StringBuffer( "((\"lcl|HPV32_L1.:1 s\":0.195593,\"lcl|HPV30_L1.1|;a\":0.114\n237):0.0359322,\"lcl|HPV56_L1.1|,d\":0.0727412,\"lcl|HPV66_L1.1:x\":0.0798012);" ),
8523 new NHXParser() )[ 0 ];
8526 .equals( "(('lcl|HPV32_L1.:1 s':0.195593,'lcl|HPV30_L1.1|;a':0.114237):0.0359322,'lcl|HPV56_L1.1|,d':0.0727412,'lcl|HPV66_L1.1:x':0.0798012);" ) ) {
8527 System.out.println( p56.toNewHampshire() );
8530 final Phylogeny p57 = factory
8531 .create( new StringBuffer( "((\"lcl|HPV32_L1.:1 s\":0.195593,\"lcl|HPV30_L1.1|;a\":0.114\n237):0.0359322,\"lcl|HPV56_L1.1|,d\":0.0727412,\"lcl|HPV66_L1.1:x\":0.0798012);" ),
8532 new NHXParser() )[ 0 ];
8535 .equals( "(('lcl|HPV32_L1.:1 s':0.195593,'lcl|HPV30_L1.1|;a':0.114237):0.0359322,'lcl|HPV56_L1.1|,d':0.0727412,'lcl|HPV66_L1.1:x':0.0798012);" ) ) {
8536 System.out.println( p56.toNewHampshire() );
8539 final String s58 = "('Homo \"man\" sapiens:1',\"Homo 'man' sapiens;\")';root \"1_ )';";
8540 final Phylogeny p58 = factory.create( new StringBuffer( s58 ), new NHXParser() )[ 0 ];
8541 if ( !p58.toNewHampshire().equals( s58 ) ) {
8542 System.out.println( p58.toNewHampshire() );
8545 final String s59 = "('Homo \"man sapiens:1',\"Homo 'man sapiens\")\"root; '1_ )\";";
8546 final Phylogeny p59 = factory.create( new StringBuffer( s59 ), new NHXParser() )[ 0 ];
8547 if ( !p59.toNewHampshire().equals( s59 ) ) {
8548 System.out.println( p59.toNewHampshire() );
8551 final String s60 = "('\" ;,:\":\"',\"'abc def' g's_\",'=:0.45+,.:%~`!@#$%^&*()_-+={} | ;,');";
8552 final Phylogeny p60 = factory.create( new StringBuffer( s60 ), new NHXParser() )[ 0 ];
8553 if ( !p60.toNewHampshire().equals( s60 ) ) {
8554 System.out.println( p60.toNewHampshire() );
8557 final String s61 = "('H[omo] \"man\" sapiens:1',\"H[omo] 'man' sapiens;\",H[omo] sapiens)';root \"1_ )';";
8558 final Phylogeny p61 = factory.create( new StringBuffer( s61 ), new NHXParser() )[ 0 ];
8559 if ( !p61.toNewHampshire()
8560 .equals( "('H{omo} \"man\" sapiens:1',\"H{omo} 'man' sapiens;\",Hsapiens)';root \"1_ )';" ) ) {
8561 System.out.println( p61.toNewHampshire() );
8565 catch ( final Exception e ) {
8566 e.printStackTrace( System.out );
8572 private static boolean testNHParsingIter() {
8574 final String p0_str = "(A,B);";
8575 final NHXParser p = new NHXParser();
8576 p.setSource( p0_str );
8577 if ( !p.hasNext() ) {
8580 final Phylogeny p0 = p.next();
8581 if ( !p0.toNewHampshire().equals( p0_str ) ) {
8582 System.out.println( p0.toNewHampshire() );
8585 if ( p.hasNext() ) {
8588 if ( p.next() != null ) {
8592 final String p00_str = "(A,B)root;";
8593 p.setSource( p00_str );
8594 final Phylogeny p00 = p.next();
8595 if ( !p00.toNewHampshire().equals( p00_str ) ) {
8596 System.out.println( p00.toNewHampshire() );
8600 final String p000_str = "A;";
8601 p.setSource( p000_str );
8602 final Phylogeny p000 = p.next();
8603 if ( !p000.toNewHampshire().equals( p000_str ) ) {
8604 System.out.println( p000.toNewHampshire() );
8608 final String p0000_str = "A";
8609 p.setSource( p0000_str );
8610 final Phylogeny p0000 = p.next();
8611 if ( !p0000.toNewHampshire().equals( "A;" ) ) {
8612 System.out.println( p0000.toNewHampshire() );
8616 p.setSource( "(A)" );
8617 final Phylogeny p00000 = p.next();
8618 if ( !p00000.toNewHampshire().equals( "(A);" ) ) {
8619 System.out.println( p00000.toNewHampshire() );
8623 final String p1_str = "(A,B)(C,D)(E,F)(G,H)";
8624 p.setSource( p1_str );
8625 if ( !p.hasNext() ) {
8628 final Phylogeny p1_0 = p.next();
8629 if ( !p1_0.toNewHampshire().equals( "(A,B);" ) ) {
8630 System.out.println( p1_0.toNewHampshire() );
8633 if ( !p.hasNext() ) {
8636 final Phylogeny p1_1 = p.next();
8637 if ( !p1_1.toNewHampshire().equals( "(C,D);" ) ) {
8638 System.out.println( "(C,D) != " + p1_1.toNewHampshire() );
8641 if ( !p.hasNext() ) {
8644 final Phylogeny p1_2 = p.next();
8645 if ( !p1_2.toNewHampshire().equals( "(E,F);" ) ) {
8646 System.out.println( "(E,F) != " + p1_2.toNewHampshire() );
8649 if ( !p.hasNext() ) {
8652 final Phylogeny p1_3 = p.next();
8653 if ( !p1_3.toNewHampshire().equals( "(G,H);" ) ) {
8654 System.out.println( "(G,H) != " + p1_3.toNewHampshire() );
8657 if ( p.hasNext() ) {
8660 if ( p.next() != null ) {
8664 final String p2_str = "((1,2,3),B);(C,D) (E,F)root;(G,H); ;(X)";
8665 p.setSource( p2_str );
8666 if ( !p.hasNext() ) {
8669 Phylogeny p2_0 = p.next();
8670 if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8671 System.out.println( p2_0.toNewHampshire() );
8674 if ( !p.hasNext() ) {
8677 Phylogeny p2_1 = p.next();
8678 if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8679 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8682 if ( !p.hasNext() ) {
8685 Phylogeny p2_2 = p.next();
8686 if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8687 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8690 if ( !p.hasNext() ) {
8693 Phylogeny p2_3 = p.next();
8694 if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8695 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8698 if ( !p.hasNext() ) {
8701 Phylogeny p2_4 = p.next();
8702 if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8703 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8706 if ( p.hasNext() ) {
8709 if ( p.next() != null ) {
8714 if ( !p.hasNext() ) {
8718 if ( !p2_0.toNewHampshire().equals( "((1,2,3),B);" ) ) {
8719 System.out.println( p2_0.toNewHampshire() );
8722 if ( !p.hasNext() ) {
8726 if ( !p2_1.toNewHampshire().equals( "(C,D);" ) ) {
8727 System.out.println( "(C,D) != " + p2_1.toNewHampshire() );
8730 if ( !p.hasNext() ) {
8734 if ( !p2_2.toNewHampshire().equals( "(E,F)root;" ) ) {
8735 System.out.println( "(E,F)root != " + p2_2.toNewHampshire() );
8738 if ( !p.hasNext() ) {
8742 if ( !p2_3.toNewHampshire().equals( "(G,H);" ) ) {
8743 System.out.println( "(G,H) != " + p2_3.toNewHampshire() );
8746 if ( !p.hasNext() ) {
8750 if ( !p2_4.toNewHampshire().equals( "(X);" ) ) {
8751 System.out.println( "(X) != " + p2_4.toNewHampshire() );
8754 if ( p.hasNext() ) {
8757 if ( p.next() != null ) {
8761 final String p3_str = "((A,B),C)abc";
8762 p.setSource( p3_str );
8763 if ( !p.hasNext() ) {
8766 final Phylogeny p3_0 = p.next();
8767 if ( !p3_0.toNewHampshire().equals( "((A,B),C)abc;" ) ) {
8770 if ( p.hasNext() ) {
8773 if ( p.next() != null ) {
8777 final String p4_str = "((A,B)ab,C)abc";
8778 p.setSource( p4_str );
8779 if ( !p.hasNext() ) {
8782 final Phylogeny p4_0 = p.next();
8783 if ( !p4_0.toNewHampshire().equals( "((A,B)ab,C)abc;" ) ) {
8786 if ( p.hasNext() ) {
8789 if ( p.next() != null ) {
8793 final String p5_str = "(((A,B)ab,C)abc,D)abcd";
8794 p.setSource( p5_str );
8795 if ( !p.hasNext() ) {
8798 final Phylogeny p5_0 = p.next();
8799 if ( !p5_0.toNewHampshire().equals( "(((A,B)ab,C)abc,D)abcd;" ) ) {
8802 if ( p.hasNext() ) {
8805 if ( p.next() != null ) {
8809 final String p6_str = "(A,(B,(C,(D,E)de)cde)bcde)abcde";
8810 p.setSource( p6_str );
8811 if ( !p.hasNext() ) {
8814 Phylogeny p6_0 = p.next();
8815 if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8818 if ( p.hasNext() ) {
8821 if ( p.next() != null ) {
8825 if ( !p.hasNext() ) {
8829 if ( !p6_0.toNewHampshire().equals( "(A,(B,(C,(D,E)de)cde)bcde)abcde;" ) ) {
8832 if ( p.hasNext() ) {
8835 if ( p.next() != null ) {
8839 final String p7_str = "((((A,B)ab,C)abc,D)abcd,E)abcde";
8840 p.setSource( p7_str );
8841 if ( !p.hasNext() ) {
8844 Phylogeny p7_0 = p.next();
8845 if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8848 if ( p.hasNext() ) {
8851 if ( p.next() != null ) {
8855 if ( !p.hasNext() ) {
8859 if ( !p7_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8862 if ( p.hasNext() ) {
8865 if ( p.next() != null ) {
8869 final String p8_str = "((((A,B)ab,C)abc,D)abcd,E)abcde ((((a,b)ab,c)abc,d)abcd,e)abcde";
8870 p.setSource( p8_str );
8871 if ( !p.hasNext() ) {
8874 Phylogeny p8_0 = p.next();
8875 if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8878 if ( !p.hasNext() ) {
8881 if ( !p.hasNext() ) {
8884 Phylogeny p8_1 = p.next();
8885 if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8888 if ( p.hasNext() ) {
8891 if ( p.next() != null ) {
8895 if ( !p.hasNext() ) {
8899 if ( !p8_0.toNewHampshire().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde;" ) ) {
8902 if ( !p.hasNext() ) {
8906 if ( !p8_1.toNewHampshire().equals( "((((a,b)ab,c)abc,d)abcd,e)abcde;" ) ) {
8909 if ( p.hasNext() ) {
8912 if ( p.next() != null ) {
8918 if ( p.hasNext() ) {
8922 p.setSource( new File( Test.PATH_TO_TEST_DATA + "phylogeny27.nhx" ) );
8923 if ( !p.hasNext() ) {
8926 Phylogeny p_27 = p.next();
8927 if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8928 System.out.println( p_27.toNewHampshireX() );
8932 if ( p.hasNext() ) {
8935 if ( p.next() != null ) {
8939 if ( !p.hasNext() ) {
8943 if ( !p_27.toNewHampshireX().equals( "((((A,B)ab,C)abc,D)abcd,E)abcde" ) ) {
8944 System.out.println( p_27.toNewHampshireX() );
8948 if ( p.hasNext() ) {
8951 if ( p.next() != null ) {
8955 final String p30_str = "(A,B);(C,D)";
8956 final NHXParser p30 = new NHXParser();
8957 p30.setSource( p30_str );
8958 if ( !p30.hasNext() ) {
8961 Phylogeny phy30 = p30.next();
8962 if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8963 System.out.println( phy30.toNewHampshire() );
8966 if ( !p30.hasNext() ) {
8969 Phylogeny phy301 = p30.next();
8970 if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
8971 System.out.println( phy301.toNewHampshire() );
8974 if ( p30.hasNext() ) {
8977 if ( p30.hasNext() ) {
8980 if ( p30.next() != null ) {
8983 if ( p30.next() != null ) {
8987 if ( !p30.hasNext() ) {
8991 if ( !phy30.toNewHampshire().equals( "(A,B);" ) ) {
8992 System.out.println( phy30.toNewHampshire() );
8995 if ( !p30.hasNext() ) {
8998 phy301 = p30.next();
8999 if ( !phy301.toNewHampshire().equals( "(C,D);" ) ) {
9000 System.out.println( phy301.toNewHampshire() );
9003 if ( p30.hasNext() ) {
9006 if ( p30.hasNext() ) {
9009 if ( p30.next() != null ) {
9012 if ( p30.next() != null ) {
9016 catch ( final Exception e ) {
9017 e.printStackTrace( System.out );
9023 private static boolean testNHXconversion() {
9025 final PhylogenyNode n1 = new PhylogenyNode();
9026 final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9027 final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9028 final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9029 final PhylogenyNode n5 = PhylogenyNode
9030 .createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:E=1.1.1.1:D=Y:Co=Y:B=56:T=1]" );
9031 final PhylogenyNode n6 = PhylogenyNode
9032 .createInstanceFromNhxString( "n6:0.000001[&&NHX:S=Ecoli:E=1.1.1.1:D=N:Co=N:B=100:T=1]" );
9033 if ( !n1.toNewHampshireX().equals( "" ) ) {
9036 if ( !n2.toNewHampshireX().equals( "" ) ) {
9039 if ( !n3.toNewHampshireX().equals( "n3" ) ) {
9042 if ( !n4.toNewHampshireX().equals( "n4:0.01" ) ) {
9045 if ( !n5.toNewHampshireX().equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:B=56]" ) ) {
9048 if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:B=100]" ) ) {
9049 System.out.println( n6.toNewHampshireX() );
9052 final PhylogenyNode n7 = new PhylogenyNode();
9053 n7.setName( " gks:dr-m4 \" ' `@:[]sadq04 " );
9054 if ( !n7.toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
9055 .equals( "'gks:dr-m4 \" ` `@:[]sadq04'" ) ) {
9056 System.out.println( n7
9057 .toNewHampshire( true, PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) );
9061 catch ( final Exception e ) {
9062 e.printStackTrace( System.out );
9068 private static boolean testNHXNodeParsing() {
9070 final PhylogenyNode n1 = new PhylogenyNode();
9071 final PhylogenyNode n2 = PhylogenyNode.createInstanceFromNhxString( "" );
9072 final PhylogenyNode n3 = PhylogenyNode.createInstanceFromNhxString( "n3" );
9073 final PhylogenyNode n4 = PhylogenyNode.createInstanceFromNhxString( "n4:0.01" );
9074 final PhylogenyNode n5 = PhylogenyNode
9075 .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]" );
9076 if ( !n3.getName().equals( "n3" ) ) {
9079 if ( n3.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9082 if ( n3.isDuplication() ) {
9085 if ( n3.isHasAssignedEvent() ) {
9088 if ( PhylogenyMethods.getBranchWidthValue( n3 ) != BranchWidth.BRANCH_WIDTH_DEFAULT_VALUE ) {
9091 if ( !n4.getName().equals( "n4" ) ) {
9094 if ( n4.getDistanceToParent() != 0.01 ) {
9097 if ( !n5.getName().equals( "n5" ) ) {
9100 if ( PhylogenyMethods.getConfidenceValue( n5 ) != 56 ) {
9103 if ( n5.getDistanceToParent() != 0.1 ) {
9106 if ( !PhylogenyMethods.getSpecies( n5 ).equals( "Ecoli" ) ) {
9109 if ( !n5.isDuplication() ) {
9112 if ( !n5.isHasAssignedEvent() ) {
9115 final PhylogenyNode n8 = PhylogenyNode
9116 .createInstanceFromNhxString( "ABCD_ECOLI/1-2:0.01",
9117 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9118 if ( !n8.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9121 if ( !PhylogenyMethods.getSpecies( n8 ).equals( "ECOLI" ) ) {
9124 final PhylogenyNode n9 = PhylogenyNode
9125 .createInstanceFromNhxString( "ABCD_ECOLI/1-12:0.01",
9126 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9127 if ( !n9.getName().equals( "ABCD_ECOLI/1-12" ) ) {
9130 if ( !PhylogenyMethods.getSpecies( n9 ).equals( "ECOLI" ) ) {
9133 final PhylogenyNode n10 = PhylogenyNode
9134 .createInstanceFromNhxString( "n10.ECOLI", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9135 if ( !n10.getName().equals( "n10.ECOLI" ) ) {
9138 final PhylogenyNode n20 = PhylogenyNode
9139 .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9140 if ( !n20.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9143 if ( !PhylogenyMethods.getSpecies( n20 ).equals( "ECOLI" ) ) {
9146 final PhylogenyNode n20x = PhylogenyNode
9147 .createInstanceFromNhxString( "N20_ECOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9148 if ( !n20x.getName().equals( "N20_ECOL1/1-2" ) ) {
9151 if ( !PhylogenyMethods.getSpecies( n20x ).equals( "ECOL1" ) ) {
9154 final PhylogenyNode n20xx = PhylogenyNode
9155 .createInstanceFromNhxString( "N20_eCOL1/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9156 if ( !n20xx.getName().equals( "N20_eCOL1/1-2" ) ) {
9159 if ( PhylogenyMethods.getSpecies( n20xx ).length() > 0 ) {
9162 final PhylogenyNode n20xxx = PhylogenyNode
9163 .createInstanceFromNhxString( "n20_ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9164 if ( !n20xxx.getName().equals( "n20_ecoli/1-2" ) ) {
9167 if ( PhylogenyMethods.getSpecies( n20xxx ).length() > 0 ) {
9170 final PhylogenyNode n20xxxx = PhylogenyNode
9171 .createInstanceFromNhxString( "n20_Ecoli/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9172 if ( !n20xxxx.getName().equals( "n20_Ecoli/1-2" ) ) {
9175 if ( PhylogenyMethods.getSpecies( n20xxxx ).length() > 0 ) {
9178 final PhylogenyNode n21 = PhylogenyNode
9179 .createInstanceFromNhxString( "N21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9180 if ( !n21.getName().equals( "N21_PIG" ) ) {
9183 if ( !PhylogenyMethods.getSpecies( n21 ).equals( "PIG" ) ) {
9186 final PhylogenyNode n21x = PhylogenyNode
9187 .createInstanceFromNhxString( "n21_PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9188 if ( !n21x.getName().equals( "n21_PIG" ) ) {
9191 if ( PhylogenyMethods.getSpecies( n21x ).length() > 0 ) {
9194 final PhylogenyNode n22 = PhylogenyNode
9195 .createInstanceFromNhxString( "n22/PIG", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9196 if ( !n22.getName().equals( "n22/PIG" ) ) {
9199 if ( PhylogenyMethods.getSpecies( n22 ).length() > 0 ) {
9202 final PhylogenyNode n23 = PhylogenyNode
9203 .createInstanceFromNhxString( "n23/PIG_1", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9204 if ( !n23.getName().equals( "n23/PIG_1" ) ) {
9207 if ( PhylogenyMethods.getSpecies( n23 ).length() > 0 ) {
9210 final PhylogenyNode a = PhylogenyNode
9211 .createInstanceFromNhxString( "ABCD_ECOLI/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9212 if ( !a.getName().equals( "ABCD_ECOLI/1-2" ) ) {
9215 if ( !PhylogenyMethods.getSpecies( a ).equals( "ECOLI" ) ) {
9218 final PhylogenyNode c1 = PhylogenyNode
9219 .createInstanceFromNhxString( "n10_BOVIN/1000-2000",
9220 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9221 if ( !c1.getName().equals( "n10_BOVIN/1000-2000" ) ) {
9224 if ( !PhylogenyMethods.getSpecies( c1 ).equals( "BOVIN" ) ) {
9227 final PhylogenyNode c2 = PhylogenyNode
9228 .createInstanceFromNhxString( "N10_Bovin_1/1000-2000",
9229 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9230 if ( !c2.getName().equals( "N10_Bovin_1/1000-2000" ) ) {
9233 if ( PhylogenyMethods.getSpecies( c2 ).length() > 0 ) {
9236 final PhylogenyNode e3 = PhylogenyNode
9237 .createInstanceFromNhxString( "n10_RAT~", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9238 if ( !e3.getName().equals( "n10_RAT~" ) ) {
9241 if ( !PhylogenyMethods.getSpecies( e3 ).equals( "RAT" ) ) {
9244 final PhylogenyNode n11 = PhylogenyNode
9245 .createInstanceFromNhxString( "N111111_ECOLI/1-2:0.4",
9246 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9247 if ( !n11.getName().equals( "N111111_ECOLI/1-2" ) ) {
9250 if ( n11.getDistanceToParent() != 0.4 ) {
9253 if ( !PhylogenyMethods.getSpecies( n11 ).equals( "ECOLI" ) ) {
9256 final PhylogenyNode n12 = PhylogenyNode
9257 .createInstanceFromNhxString( "N111111-ECOLI---/jdj:0.4",
9258 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9259 if ( !n12.getName().equals( "N111111-ECOLI---/jdj" ) ) {
9262 if ( n12.getDistanceToParent() != 0.4 ) {
9265 if ( PhylogenyMethods.getSpecies( n12 ).length() > 0 ) {
9268 final PhylogenyNode o = PhylogenyNode
9269 .createInstanceFromNhxString( "ABCD_MOUSE", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9270 if ( !o.getName().equals( "ABCD_MOUSE" ) ) {
9273 if ( !PhylogenyMethods.getSpecies( o ).equals( "MOUSE" ) ) {
9276 if ( n1.getName().compareTo( "" ) != 0 ) {
9279 if ( PhylogenyMethods.getConfidenceValue( n1 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9282 if ( n1.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9285 if ( n2.getName().compareTo( "" ) != 0 ) {
9288 if ( PhylogenyMethods.getConfidenceValue( n2 ) != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
9291 if ( n2.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
9294 final PhylogenyNode n00 = PhylogenyNode
9295 .createInstanceFromNhxString( "n7:0.000001[&&NHX:GN=gene_name:AC=accession123:S=Ecoli:D=N:Co=N:B=100:T=1]" );
9296 if ( !n00.getNodeData().getSequence().getName().equals( "gene_name" ) ) {
9299 if ( !n00.getNodeData().getSequence().getAccession().getValue().equals( "accession123" ) ) {
9302 final PhylogenyNode nx = PhylogenyNode.createInstanceFromNhxString( "n5:0.1[&&NHX:S=Ecoli:GN=gene_1]" );
9303 if ( !nx.getNodeData().getSequence().getName().equals( "gene_1" ) ) {
9306 final PhylogenyNode n13 = PhylogenyNode
9307 .createInstanceFromNhxString( "BLAH_12345/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9308 if ( !n13.getName().equals( "BLAH_12345/1-2" ) ) {
9311 if ( PhylogenyMethods.getSpecies( n13 ).equals( "12345" ) ) {
9314 if ( !n13.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9317 if ( !n13.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9320 final PhylogenyNode n14 = PhylogenyNode
9321 .createInstanceFromNhxString( "BLA1_9QX45/1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9322 if ( !n14.getName().equals( "BLA1_9QX45/1-2" ) ) {
9325 if ( !PhylogenyMethods.getSpecies( n14 ).equals( "9QX45" ) ) {
9328 final PhylogenyNode n15 = PhylogenyNode
9329 .createInstanceFromNhxString( "something_wicked[123]",
9330 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9331 if ( !n15.getName().equals( "something_wicked" ) ) {
9334 if ( n15.getBranchData().getNumberOfConfidences() != 1 ) {
9337 if ( !isEqual( n15.getBranchData().getConfidence( 0 ).getValue(), 123 ) ) {
9340 final PhylogenyNode n16 = PhylogenyNode
9341 .createInstanceFromNhxString( "something_wicked2[9]",
9342 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9343 if ( !n16.getName().equals( "something_wicked2" ) ) {
9346 if ( n16.getBranchData().getNumberOfConfidences() != 1 ) {
9349 if ( !isEqual( n16.getBranchData().getConfidence( 0 ).getValue(), 9 ) ) {
9352 final PhylogenyNode n17 = PhylogenyNode
9353 .createInstanceFromNhxString( "something_wicked3[a]",
9354 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9355 if ( !n17.getName().equals( "something_wicked3" ) ) {
9358 if ( n17.getBranchData().getNumberOfConfidences() != 0 ) {
9361 final PhylogenyNode n18 = PhylogenyNode
9362 .createInstanceFromNhxString( ":0.5[91]", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9363 if ( !isEqual( n18.getDistanceToParent(), 0.5 ) ) {
9366 if ( n18.getBranchData().getNumberOfConfidences() != 1 ) {
9369 if ( !isEqual( n18.getBranchData().getConfidence( 0 ).getValue(), 91 ) ) {
9372 final PhylogenyNode n19 = PhylogenyNode
9373 .createInstanceFromNhxString( "BLAH_1-roejojoej", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9374 if ( !n19.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1" ) ) {
9377 if ( !n19.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9380 final PhylogenyNode n30 = PhylogenyNode
9381 .createInstanceFromNhxString( "BLAH_1234567-roejojoej",
9382 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9383 if ( !n30.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "1234567" ) ) {
9386 if ( !n30.getNodeData().getTaxonomy().getIdentifier().getProvider().equals( "uniprot" ) ) {
9389 final PhylogenyNode n31 = PhylogenyNode
9390 .createInstanceFromNhxString( "BLAH_12345678-roejojoej",
9391 NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9392 if ( n31.getNodeData().isHasTaxonomy() ) {
9395 final PhylogenyNode n32 = PhylogenyNode
9396 .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9397 if ( n32.getNodeData().isHasTaxonomy() ) {
9400 final PhylogenyNode n40 = PhylogenyNode
9401 .createInstanceFromNhxString( "BCL2_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9402 if ( !n40.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
9405 final PhylogenyNode n41 = PhylogenyNode
9406 .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9407 if ( n41.getNodeData().isHasTaxonomy() ) {
9410 final PhylogenyNode n42 = PhylogenyNode
9411 .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
9412 if ( n42.getNodeData().isHasTaxonomy() ) {
9415 final PhylogenyNode n43 = PhylogenyNode.createInstanceFromNhxString( "12345",
9416 NHXParser.TAXONOMY_EXTRACTION.NO );
9417 if ( n43.getNodeData().isHasTaxonomy() ) {
9420 final PhylogenyNode n44 = PhylogenyNode
9421 .createInstanceFromNhxString( "12345~1-2", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
9422 if ( n44.getNodeData().isHasTaxonomy() ) {
9426 catch ( final Exception e ) {
9427 e.printStackTrace( System.out );
9433 private static boolean testNHXParsing() {
9435 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9436 final Phylogeny p1 = factory.create( "(A [&&NHX:S=a_species],B1[&&NHX:S=b_species])", new NHXParser() )[ 0 ];
9437 if ( !p1.toNewHampshireX().equals( "(A[&&NHX:S=a_species],B1[&&NHX:S=b_species])" ) ) {
9440 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]";
9441 final Phylogeny[] p2 = factory.create( p2_S, new NHXParser() );
9442 if ( !p2[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9445 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]";
9446 final Phylogeny[] p2b = factory.create( p2b_S, new NHXParser() );
9447 if ( !p2b[ 0 ].toNewHampshireX().equals( "(((((((A:0.2):0.2):0.3):0.4):0.5):0.6):0.7):0.8" ) ) {
9450 final Phylogeny[] p3 = factory
9451 .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]",
9453 if ( !p3[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9456 final Phylogeny[] p4 = factory
9457 .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(]",
9459 if ( !p4[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9462 final Phylogeny[] p5 = factory
9463 .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(((]",
9465 if ( !p5[ 0 ].toNewHampshireX().equals( p2_S ) ) {
9468 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)";
9469 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)";
9470 final Phylogeny[] p6 = factory.create( p6_S_C, new NHXParser() );
9471 if ( !p6[ 0 ].toNewHampshireX().equals( p6_S_WO_C ) ) {
9474 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)))";
9475 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)))";
9476 final Phylogeny[] p7 = factory.create( p7_S_C, new NHXParser() );
9477 if ( !p7[ 0 ].toNewHampshireX().equals( p7_S_WO_C ) ) {
9480 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]) ))[,,, ])))))))";
9481 final String p8_S_WO_C = "((((((((((A[&&NHX:S=a]))))))))),(((((((((B[&&NHX:S=b]))))))))),(((((((((C[&&NHX:S=c]))))))))))";
9482 final Phylogeny[] p8 = factory.create( p8_S_C, new NHXParser() );
9483 if ( !p8[ 0 ].toNewHampshireX().equals( p8_S_WO_C ) ) {
9486 final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
9487 if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9490 final Phylogeny p10 = factory
9491 .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]",
9492 new NHXParser() )[ 0 ];
9493 if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9496 final Phylogeny p11 = factory
9497 .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]",
9498 new NHXParser() )[ 0 ];
9499 if ( !p11.toNewHampshireX().equals( "(('A: \"':0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9502 final Phylogeny p12 = factory.create( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]",
9503 new NHXParser() )[ 0 ];
9504 if ( !p12.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
9508 catch ( final Exception e ) {
9509 e.printStackTrace( System.out );
9515 private static boolean testNHXParsingMB() {
9517 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9518 final Phylogeny p1 = factory.create( "(1[&prob=0.9500000000000000e+00,prob_stddev=0.1100000000000000e+00,"
9519 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9520 + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9521 + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9522 + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9523 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9524 + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9525 + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9526 + "7.369400000000000e-02}])", new NHXParser() )[ 0 ];
9527 if ( !isEqual( p1.getNode( "1" ).getDistanceToParent(), 4.129e-02 ) ) {
9530 if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getValue(), 0.9500000000000000e+00 ) ) {
9533 if ( !isEqual( p1.getNode( "1" ).getBranchData().getConfidence( 0 ).getStandardDeviation(),
9534 0.1100000000000000e+00 ) ) {
9537 if ( !isEqual( p1.getNode( "2" ).getDistanceToParent(), 6.375699999999999e-02 ) ) {
9540 if ( !isEqual( p1.getNode( "2" ).getBranchData().getConfidence( 0 ).getValue(), 0.810000000000000e+00 ) ) {
9543 final Phylogeny p2 = factory
9544 .create( "(1[something_else(?)s,prob=0.9500000000000000e+00{}(((,p)rob_stddev=0.110000000000e+00,"
9545 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9546 + "prob+-sd=\"100+-0\"]:4.129000000000000e-02[&length_mean=4.153987461671767e-02,"
9547 + "length_median=4.129000000000000e-02,length_95%HPD={3.217800000000000e-02,"
9548 + "5.026800000000000e-02}],2[&prob=0.810000000000000e+00,prob_stddev=0.000000000000000e+00,"
9549 + "prob_range={1.000000000000000e+00,1.000000000000000e+00},prob(percent)=\"100\","
9550 + "prob+-sd=\"100+-0\"]:6.375699999999999e-02[&length_mean=6.395210411945065e-02,"
9551 + "length_median=6.375699999999999e-02,length_95%HPD={5.388600000000000e-02,"
9552 + "7.369400000000000e-02}])",
9553 new NHXParser() )[ 0 ];
9554 if ( p2.getNode( "1" ) == null ) {
9557 if ( p2.getNode( "2" ) == null ) {
9561 catch ( final Exception e ) {
9562 e.printStackTrace( System.out );
9569 private static boolean testNHXParsingQuotes() {
9571 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9572 final NHXParser p = new NHXParser();
9573 final Phylogeny[] phylogenies_0 = factory.create( new File( Test.PATH_TO_TEST_DATA + "quotes.nhx" ), p );
9574 if ( phylogenies_0.length != 5 ) {
9577 final Phylogeny phy = phylogenies_0[ 4 ];
9578 if ( phy.getNumberOfExternalNodes() != 7 ) {
9581 if ( phy.getNodes( "a name in double quotes from tree ((a,b),c)" ).size() != 1 ) {
9584 if ( phy.getNodes( "charles darwin 'origin of species'" ).size() != 1 ) {
9587 if ( !phy.getNodes( "charles darwin 'origin of species'" ).get( 0 ).getNodeData().getTaxonomy()
9588 .getScientificName().equals( "hsapiens" ) ) {
9591 if ( phy.getNodes( "shouldbetogether single quotes" ).size() != 1 ) {
9594 if ( phy.getNodes( "'single quotes' inside double quotes" ).size() != 1 ) {
9597 if ( phy.getNodes( "\"double quotes\" inside single quotes" ).size() != 1 ) {
9600 if ( phy.getNodes( "noquotes" ).size() != 1 ) {
9603 if ( phy.getNodes( "A ( B C '" ).size() != 1 ) {
9606 final NHXParser p1p = new NHXParser();
9607 p1p.setIgnoreQuotes( true );
9608 final Phylogeny p1 = factory.create( "(\"A\",'B1')", p1p )[ 0 ];
9609 if ( !p1.toNewHampshire().equals( "(A,B1);" ) ) {
9612 final NHXParser p2p = new NHXParser();
9613 p1p.setIgnoreQuotes( false );
9614 final Phylogeny p2 = factory.create( "(\"A\",'B1')", p2p )[ 0 ];
9615 if ( !p2.toNewHampshire().equals( "(A,B1);" ) ) {
9618 final NHXParser p3p = new NHXParser();
9619 p3p.setIgnoreQuotes( false );
9620 final Phylogeny p3 = factory.create( "(\"A)\",'B1')", p3p )[ 0 ];
9621 if ( !p3.toNewHampshire().equals( "('A)',B1);" ) ) {
9624 final NHXParser p4p = new NHXParser();
9625 p4p.setIgnoreQuotes( false );
9626 final Phylogeny p4 = factory.create( "(\"A)\",'B(),; x')", p4p )[ 0 ];
9627 if ( !p4.toNewHampshire().equals( "('A)','B(),; x');" ) ) {
9630 final Phylogeny p10 = factory
9631 .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]",
9632 new NHXParser() )[ 0 ];
9633 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]";
9634 if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
9637 final Phylogeny p11 = factory.create( p10.toNewHampshireX(), new NHXParser() )[ 0 ];
9638 if ( !p11.toNewHampshireX().equals( p10_clean_str ) ) {
9641 final Phylogeny p12 = factory
9642 .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]",
9643 new NHXParser() )[ 0 ];
9644 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]";
9645 if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
9648 final Phylogeny p13 = factory.create( p12.toNewHampshireX(), new NHXParser() )[ 0 ];
9649 if ( !p13.toNewHampshireX().equals( p12_clean_str ) ) {
9652 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;";
9653 if ( !p13.toNewHampshire().equals( p12_clean_str_nh ) ) {
9656 final Phylogeny p14 = factory.create( p13.toNewHampshire(), new NHXParser() )[ 0 ];
9657 if ( !p14.toNewHampshire().equals( p12_clean_str_nh ) ) {
9661 catch ( final Exception e ) {
9662 e.printStackTrace( System.out );
9668 private static boolean testNodeRemoval() {
9670 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9671 final Phylogeny t0 = factory.create( "((a)b)", new NHXParser() )[ 0 ];
9672 PhylogenyMethods.removeNode( t0.getNode( "b" ), t0 );
9673 if ( !t0.toNewHampshire().equals( "(a);" ) ) {
9676 final Phylogeny t1 = factory.create( "((a:2)b:4)", new NHXParser() )[ 0 ];
9677 PhylogenyMethods.removeNode( t1.getNode( "b" ), t1 );
9678 if ( !t1.toNewHampshire().equals( "(a:6.0);" ) ) {
9681 final Phylogeny t2 = factory.create( "((a,b),c)", new NHXParser() )[ 0 ];
9682 PhylogenyMethods.removeNode( t2.getNode( "b" ), t2 );
9683 if ( !t2.toNewHampshire().equals( "((a),c);" ) ) {
9687 catch ( final Exception e ) {
9688 e.printStackTrace( System.out );
9694 private static boolean testPhylogenyBranch() {
9696 final PhylogenyNode a1 = PhylogenyNode.createInstanceFromNhxString( "a" );
9697 final PhylogenyNode b1 = PhylogenyNode.createInstanceFromNhxString( "b" );
9698 final PhylogenyBranch a1b1 = new PhylogenyBranch( a1, b1 );
9699 final PhylogenyBranch b1a1 = new PhylogenyBranch( b1, a1 );
9700 if ( !a1b1.equals( a1b1 ) ) {
9703 if ( !a1b1.equals( b1a1 ) ) {
9706 if ( !b1a1.equals( a1b1 ) ) {
9709 final PhylogenyBranch a1_b1 = new PhylogenyBranch( a1, b1, true );
9710 final PhylogenyBranch b1_a1 = new PhylogenyBranch( b1, a1, true );
9711 final PhylogenyBranch a1_b1_ = new PhylogenyBranch( a1, b1, false );
9712 if ( a1_b1.equals( b1_a1 ) ) {
9715 if ( a1_b1.equals( a1_b1_ ) ) {
9718 final PhylogenyBranch b1_a1_ = new PhylogenyBranch( b1, a1, false );
9719 if ( !a1_b1.equals( b1_a1_ ) ) {
9722 if ( a1_b1_.equals( b1_a1_ ) ) {
9725 if ( !a1_b1_.equals( b1_a1 ) ) {
9729 catch ( final Exception e ) {
9730 e.printStackTrace( System.out );
9736 private static boolean testPhyloXMLparsingOfDistributionElement() {
9738 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
9739 PhyloXmlParser xml_parser = null;
9741 xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
9743 catch ( final Exception e ) {
9744 // Do nothing -- means were not running from jar.
9746 if ( xml_parser == null ) {
9747 xml_parser = PhyloXmlParser.createPhyloXmlParser();
9748 if ( USE_LOCAL_PHYLOXML_SCHEMA ) {
9749 xml_parser.setValidateAgainstSchema( PHYLOXML_LOCAL_XSD );
9752 xml_parser.setValidateAgainstSchema( PHYLOXML_REMOTE_XSD );
9755 final Phylogeny[] phylogenies_0 = factory.create( Test.PATH_TO_TEST_DATA + "phyloxml_distribution.xml",
9757 if ( xml_parser.getErrorCount() > 0 ) {
9758 System.out.println( xml_parser.getErrorMessages().toString() );
9761 if ( phylogenies_0.length != 1 ) {
9764 final Phylogeny t1 = phylogenies_0[ 0 ];
9765 PhylogenyNode n = null;
9766 Distribution d = null;
9767 n = t1.getNode( "root node" );
9768 if ( !n.getNodeData().isHasDistribution() ) {
9771 if ( n.getNodeData().getDistributions().size() != 1 ) {
9774 d = n.getNodeData().getDistribution();
9775 if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9778 if ( d.getPoints().size() != 1 ) {
9781 if ( d.getPolygons() != null ) {
9784 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9787 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9790 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9793 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9796 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9799 n = t1.getNode( "node a" );
9800 if ( !n.getNodeData().isHasDistribution() ) {
9803 if ( n.getNodeData().getDistributions().size() != 2 ) {
9806 d = n.getNodeData().getDistribution( 1 );
9807 if ( !d.getDesc().equals( "San Diego" ) ) {
9810 if ( d.getPoints().size() != 1 ) {
9813 if ( d.getPolygons() != null ) {
9816 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9819 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9822 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9825 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9828 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9831 n = t1.getNode( "node bb" );
9832 if ( !n.getNodeData().isHasDistribution() ) {
9835 if ( n.getNodeData().getDistributions().size() != 1 ) {
9838 d = n.getNodeData().getDistribution( 0 );
9839 if ( d.getPoints().size() != 3 ) {
9842 if ( d.getPolygons().size() != 2 ) {
9845 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9848 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9851 if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9854 if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9857 if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9860 if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
9863 Polygon p = d.getPolygons().get( 0 );
9864 if ( p.getPoints().size() != 3 ) {
9867 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
9870 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
9873 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9876 if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
9879 if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
9882 if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
9885 p = d.getPolygons().get( 1 );
9886 if ( p.getPoints().size() != 3 ) {
9889 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
9892 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
9895 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
9899 final StringBuffer t1_sb = new StringBuffer( t1.toPhyloXML( 0 ) );
9900 final Phylogeny[] rt = factory.create( t1_sb, xml_parser );
9901 if ( rt.length != 1 ) {
9904 final Phylogeny t1_rt = rt[ 0 ];
9905 n = t1_rt.getNode( "root node" );
9906 if ( !n.getNodeData().isHasDistribution() ) {
9909 if ( n.getNodeData().getDistributions().size() != 1 ) {
9912 d = n.getNodeData().getDistribution();
9913 if ( !d.getDesc().equals( "Hirschweg 38" ) ) {
9916 if ( d.getPoints().size() != 1 ) {
9919 if ( d.getPolygons() != null ) {
9922 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "472" ) ) {
9925 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9928 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9931 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "47.48148427110029" ) ) {
9934 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "8.768951296806335" ) ) {
9937 n = t1_rt.getNode( "node a" );
9938 if ( !n.getNodeData().isHasDistribution() ) {
9941 if ( n.getNodeData().getDistributions().size() != 2 ) {
9944 d = n.getNodeData().getDistribution( 1 );
9945 if ( !d.getDesc().equals( "San Diego" ) ) {
9948 if ( d.getPoints().size() != 1 ) {
9951 if ( d.getPolygons() != null ) {
9954 if ( !d.getPoints().get( 0 ).getAltitude().toString().equals( "104" ) ) {
9957 if ( !d.getPoints().get( 0 ).getAltiudeUnit().equals( "m" ) ) {
9960 if ( !d.getPoints().get( 0 ).getGeodeticDatum().equals( "WGS84" ) ) {
9963 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "32.880933" ) ) {
9966 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "-117.217543" ) ) {
9969 n = t1_rt.getNode( "node bb" );
9970 if ( !n.getNodeData().isHasDistribution() ) {
9973 if ( n.getNodeData().getDistributions().size() != 1 ) {
9976 d = n.getNodeData().getDistribution( 0 );
9977 if ( d.getPoints().size() != 3 ) {
9980 if ( d.getPolygons().size() != 2 ) {
9983 if ( !d.getPoints().get( 0 ).getLatitude().toString().equals( "1" ) ) {
9986 if ( !d.getPoints().get( 0 ).getLongitude().toString().equals( "2" ) ) {
9989 if ( !d.getPoints().get( 1 ).getLatitude().toString().equals( "3" ) ) {
9992 if ( !d.getPoints().get( 1 ).getLongitude().toString().equals( "4" ) ) {
9995 if ( !d.getPoints().get( 2 ).getLatitude().toString().equals( "5" ) ) {
9998 if ( !d.getPoints().get( 2 ).getLongitude().toString().equals( "6" ) ) {
10001 p = d.getPolygons().get( 0 );
10002 if ( p.getPoints().size() != 3 ) {
10005 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "0.1" ) ) {
10008 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "0.2" ) ) {
10011 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10014 if ( !p.getPoints().get( 2 ).getLatitude().toString().equals( "0.5" ) ) {
10017 if ( !p.getPoints().get( 2 ).getLongitude().toString().equals( "0.6" ) ) {
10020 if ( !p.getPoints().get( 2 ).getAltitude().toString().equals( "30" ) ) {
10023 p = d.getPolygons().get( 1 );
10024 if ( p.getPoints().size() != 3 ) {
10027 if ( !p.getPoints().get( 0 ).getLatitude().toString().equals( "1.49348902489947473" ) ) {
10030 if ( !p.getPoints().get( 0 ).getLongitude().toString().equals( "2.567489393947847492" ) ) {
10033 if ( !p.getPoints().get( 0 ).getAltitude().toString().equals( "10" ) ) {
10037 catch ( final Exception e ) {
10038 e.printStackTrace( System.out );
10044 private static boolean testPostOrderIterator() {
10046 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10047 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10048 PhylogenyNodeIterator it0;
10049 for( it0 = t0.iteratorPostorder(); it0.hasNext(); ) {
10052 for( it0.reset(); it0.hasNext(); ) {
10055 final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10056 final PhylogenyNodeIterator it = t1.iteratorPostorder();
10057 if ( !it.next().getName().equals( "A" ) ) {
10060 if ( !it.next().getName().equals( "B" ) ) {
10063 if ( !it.next().getName().equals( "ab" ) ) {
10066 if ( !it.next().getName().equals( "C" ) ) {
10069 if ( !it.next().getName().equals( "D" ) ) {
10072 if ( !it.next().getName().equals( "cd" ) ) {
10075 if ( !it.next().getName().equals( "abcd" ) ) {
10078 if ( !it.next().getName().equals( "E" ) ) {
10081 if ( !it.next().getName().equals( "F" ) ) {
10084 if ( !it.next().getName().equals( "ef" ) ) {
10087 if ( !it.next().getName().equals( "G" ) ) {
10090 if ( !it.next().getName().equals( "H" ) ) {
10093 if ( !it.next().getName().equals( "gh" ) ) {
10096 if ( !it.next().getName().equals( "efgh" ) ) {
10099 if ( !it.next().getName().equals( "r" ) ) {
10102 if ( it.hasNext() ) {
10106 catch ( final Exception e ) {
10107 e.printStackTrace( System.out );
10113 private static boolean testPreOrderIterator() {
10115 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10116 final Phylogeny t0 = factory.create( "((A,B)ab,(C,D)cd)r", new NHXParser() )[ 0 ];
10117 PhylogenyNodeIterator it0;
10118 for( it0 = t0.iteratorPreorder(); it0.hasNext(); ) {
10121 for( it0.reset(); it0.hasNext(); ) {
10124 PhylogenyNodeIterator it = t0.iteratorPreorder();
10125 if ( !it.next().getName().equals( "r" ) ) {
10128 if ( !it.next().getName().equals( "ab" ) ) {
10131 if ( !it.next().getName().equals( "A" ) ) {
10134 if ( !it.next().getName().equals( "B" ) ) {
10137 if ( !it.next().getName().equals( "cd" ) ) {
10140 if ( !it.next().getName().equals( "C" ) ) {
10143 if ( !it.next().getName().equals( "D" ) ) {
10146 if ( it.hasNext() ) {
10149 final Phylogeny t1 = factory.create( "(((A,B)ab,(C,D)cd)abcd,((E,F)ef,(G,H)gh)efgh)r", new NHXParser() )[ 0 ];
10150 it = t1.iteratorPreorder();
10151 if ( !it.next().getName().equals( "r" ) ) {
10154 if ( !it.next().getName().equals( "abcd" ) ) {
10157 if ( !it.next().getName().equals( "ab" ) ) {
10160 if ( !it.next().getName().equals( "A" ) ) {
10163 if ( !it.next().getName().equals( "B" ) ) {
10166 if ( !it.next().getName().equals( "cd" ) ) {
10169 if ( !it.next().getName().equals( "C" ) ) {
10172 if ( !it.next().getName().equals( "D" ) ) {
10175 if ( !it.next().getName().equals( "efgh" ) ) {
10178 if ( !it.next().getName().equals( "ef" ) ) {
10181 if ( !it.next().getName().equals( "E" ) ) {
10184 if ( !it.next().getName().equals( "F" ) ) {
10187 if ( !it.next().getName().equals( "gh" ) ) {
10190 if ( !it.next().getName().equals( "G" ) ) {
10193 if ( !it.next().getName().equals( "H" ) ) {
10196 if ( it.hasNext() ) {
10200 catch ( final Exception e ) {
10201 e.printStackTrace( System.out );
10207 private static boolean testPropertiesMap() {
10209 final PropertiesMap pm = new PropertiesMap();
10210 final Property p0 = new Property( "dimensions:diameter", "1", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10211 final Property p1 = new Property( "dimensions:length", "2", "metric:mm", "xsd:decimal", AppliesTo.NODE );
10212 final Property p2 = new Property( "something:else",
10214 "improbable:research",
10217 pm.addProperty( p0 );
10218 pm.addProperty( p1 );
10219 pm.addProperty( p2 );
10220 if ( !pm.getProperty( "dimensions:diameter" ).getValue().equals( "1" ) ) {
10223 if ( !pm.getProperty( "dimensions:length" ).getValue().equals( "2" ) ) {
10226 if ( pm.getProperties().size() != 3 ) {
10229 if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 2 ) {
10232 if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10235 if ( pm.getProperties().size() != 3 ) {
10238 pm.removeProperty( "dimensions:diameter" );
10239 if ( pm.getProperties().size() != 2 ) {
10242 if ( pm.getPropertiesWithGivenReferencePrefix( "dimensions" ).size() != 1 ) {
10245 if ( pm.getPropertiesWithGivenReferencePrefix( "something" ).size() != 1 ) {
10249 catch ( final Exception e ) {
10250 e.printStackTrace( System.out );
10256 private static boolean testProteinId() {
10258 final ProteinId id1 = new ProteinId( "a" );
10259 final ProteinId id2 = new ProteinId( "a" );
10260 final ProteinId id3 = new ProteinId( "A" );
10261 final ProteinId id4 = new ProteinId( "b" );
10262 if ( !id1.equals( id1 ) ) {
10265 if ( id1.getId().equals( "x" ) ) {
10268 if ( id1.getId().equals( null ) ) {
10271 if ( !id1.equals( id2 ) ) {
10274 if ( id1.equals( id3 ) ) {
10277 if ( id1.hashCode() != id1.hashCode() ) {
10280 if ( id1.hashCode() != id2.hashCode() ) {
10283 if ( id1.hashCode() == id3.hashCode() ) {
10286 if ( id1.compareTo( id1 ) != 0 ) {
10289 if ( id1.compareTo( id2 ) != 0 ) {
10292 if ( id1.compareTo( id3 ) != 0 ) {
10295 if ( id1.compareTo( id4 ) >= 0 ) {
10298 if ( id4.compareTo( id1 ) <= 0 ) {
10301 if ( !id4.getId().equals( "b" ) ) {
10304 final ProteinId id5 = new ProteinId( " C " );
10305 if ( !id5.getId().equals( "C" ) ) {
10308 if ( id5.equals( id1 ) ) {
10312 catch ( final Exception e ) {
10313 e.printStackTrace( System.out );
10319 private static boolean testReIdMethods() {
10321 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10322 final Phylogeny p = factory.create( "((1,2)A,(((X,Y,Z)a,b)3)B,(4,5,6)C)r", new NHXParser() )[ 0 ];
10323 final long count = PhylogenyNode.getNodeCount();
10324 p.levelOrderReID();
10325 if ( p.getNode( "r" ).getId() != count ) {
10328 if ( p.getNode( "A" ).getId() != ( count + 1 ) ) {
10331 if ( p.getNode( "B" ).getId() != ( count + 1 ) ) {
10334 if ( p.getNode( "C" ).getId() != ( count + 1 ) ) {
10337 if ( p.getNode( "1" ).getId() != ( count + 2 ) ) {
10340 if ( p.getNode( "2" ).getId() != ( count + 2 ) ) {
10343 if ( p.getNode( "3" ).getId() != ( count + 2 ) ) {
10346 if ( p.getNode( "4" ).getId() != ( count + 2 ) ) {
10349 if ( p.getNode( "5" ).getId() != ( count + 2 ) ) {
10352 if ( p.getNode( "6" ).getId() != ( count + 2 ) ) {
10355 if ( p.getNode( "a" ).getId() != ( count + 3 ) ) {
10358 if ( p.getNode( "b" ).getId() != ( count + 3 ) ) {
10361 if ( p.getNode( "X" ).getId() != ( count + 4 ) ) {
10364 if ( p.getNode( "Y" ).getId() != ( count + 4 ) ) {
10367 if ( p.getNode( "Z" ).getId() != ( count + 4 ) ) {
10371 catch ( final Exception e ) {
10372 e.printStackTrace( System.out );
10378 private static boolean testRerooting() {
10380 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10381 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",
10382 new NHXParser() )[ 0 ];
10383 if ( !t1.isRooted() ) {
10386 t1.reRoot( t1.getNode( "D" ) );
10387 t1.reRoot( t1.getNode( "CD" ) );
10388 t1.reRoot( t1.getNode( "A" ) );
10389 t1.reRoot( t1.getNode( "B" ) );
10390 t1.reRoot( t1.getNode( "AB" ) );
10391 t1.reRoot( t1.getNode( "D" ) );
10392 t1.reRoot( t1.getNode( "C" ) );
10393 t1.reRoot( t1.getNode( "CD" ) );
10394 t1.reRoot( t1.getNode( "A" ) );
10395 t1.reRoot( t1.getNode( "B" ) );
10396 t1.reRoot( t1.getNode( "AB" ) );
10397 t1.reRoot( t1.getNode( "D" ) );
10398 t1.reRoot( t1.getNode( "D" ) );
10399 t1.reRoot( t1.getNode( "C" ) );
10400 t1.reRoot( t1.getNode( "A" ) );
10401 t1.reRoot( t1.getNode( "B" ) );
10402 t1.reRoot( t1.getNode( "AB" ) );
10403 t1.reRoot( t1.getNode( "C" ) );
10404 t1.reRoot( t1.getNode( "D" ) );
10405 t1.reRoot( t1.getNode( "CD" ) );
10406 t1.reRoot( t1.getNode( "D" ) );
10407 t1.reRoot( t1.getNode( "A" ) );
10408 t1.reRoot( t1.getNode( "B" ) );
10409 t1.reRoot( t1.getNode( "AB" ) );
10410 t1.reRoot( t1.getNode( "C" ) );
10411 t1.reRoot( t1.getNode( "D" ) );
10412 t1.reRoot( t1.getNode( "CD" ) );
10413 t1.reRoot( t1.getNode( "D" ) );
10414 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 1 ) ) {
10417 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 2 ) ) {
10420 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 3 ) ) {
10423 if ( !isEqual( t1.getNode( "D" ).getDistanceToParent(), 2.5 ) ) {
10426 if ( !isEqual( t1.getNode( "CD" ).getDistanceToParent(), 2.5 ) ) {
10429 if ( !isEqual( t1.getNode( "AB" ).getDistanceToParent(), 4 ) ) {
10432 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",
10433 new NHXParser() )[ 0 ];
10434 t2.reRoot( t2.getNode( "A" ) );
10435 t2.reRoot( t2.getNode( "D" ) );
10436 t2.reRoot( t2.getNode( "ABC" ) );
10437 t2.reRoot( t2.getNode( "A" ) );
10438 t2.reRoot( t2.getNode( "B" ) );
10439 t2.reRoot( t2.getNode( "D" ) );
10440 t2.reRoot( t2.getNode( "C" ) );
10441 t2.reRoot( t2.getNode( "ABC" ) );
10442 t2.reRoot( t2.getNode( "A" ) );
10443 t2.reRoot( t2.getNode( "B" ) );
10444 t2.reRoot( t2.getNode( "AB" ) );
10445 t2.reRoot( t2.getNode( "AB" ) );
10446 t2.reRoot( t2.getNode( "D" ) );
10447 t2.reRoot( t2.getNode( "C" ) );
10448 t2.reRoot( t2.getNode( "B" ) );
10449 t2.reRoot( t2.getNode( "AB" ) );
10450 t2.reRoot( t2.getNode( "D" ) );
10451 t2.reRoot( t2.getNode( "D" ) );
10452 t2.reRoot( t2.getNode( "ABC" ) );
10453 t2.reRoot( t2.getNode( "A" ) );
10454 t2.reRoot( t2.getNode( "B" ) );
10455 t2.reRoot( t2.getNode( "AB" ) );
10456 t2.reRoot( t2.getNode( "D" ) );
10457 t2.reRoot( t2.getNode( "C" ) );
10458 t2.reRoot( t2.getNode( "ABC" ) );
10459 t2.reRoot( t2.getNode( "A" ) );
10460 t2.reRoot( t2.getNode( "B" ) );
10461 t2.reRoot( t2.getNode( "AB" ) );
10462 t2.reRoot( t2.getNode( "D" ) );
10463 t2.reRoot( t2.getNode( "D" ) );
10464 t2.reRoot( t2.getNode( "C" ) );
10465 t2.reRoot( t2.getNode( "A" ) );
10466 t2.reRoot( t2.getNode( "B" ) );
10467 t2.reRoot( t2.getNode( "AB" ) );
10468 t2.reRoot( t2.getNode( "C" ) );
10469 t2.reRoot( t2.getNode( "D" ) );
10470 t2.reRoot( t2.getNode( "ABC" ) );
10471 t2.reRoot( t2.getNode( "D" ) );
10472 t2.reRoot( t2.getNode( "A" ) );
10473 t2.reRoot( t2.getNode( "B" ) );
10474 t2.reRoot( t2.getNode( "AB" ) );
10475 t2.reRoot( t2.getNode( "C" ) );
10476 t2.reRoot( t2.getNode( "D" ) );
10477 t2.reRoot( t2.getNode( "ABC" ) );
10478 t2.reRoot( t2.getNode( "D" ) );
10479 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10482 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10485 t2.reRoot( t2.getNode( "ABC" ) );
10486 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10489 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10492 t2.reRoot( t2.getNode( "AB" ) );
10493 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10496 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10499 if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10502 t2.reRoot( t2.getNode( "AB" ) );
10503 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10506 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10509 if ( !isEqual( t2.getNode( "D" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10512 t2.reRoot( t2.getNode( "D" ) );
10513 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10516 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10519 t2.reRoot( t2.getNode( "ABC" ) );
10520 if ( !isEqual( t2.getNode( "AB" ).getBranchData().getConfidence( 0 ).getValue(), 55 ) ) {
10523 if ( !isEqual( t2.getNode( "ABC" ).getBranchData().getConfidence( 0 ).getValue(), 33 ) ) {
10526 final Phylogeny t3 = factory.create( "(A[&&NHX:B=10],B[&&NHX:B=20],C[&&NHX:B=30],D[&&NHX:B=40])",
10527 new NHXParser() )[ 0 ];
10528 t3.reRoot( t3.getNode( "B" ) );
10529 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10532 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10535 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10538 t3.reRoot( t3.getNode( "B" ) );
10539 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10542 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10545 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10548 t3.reRoot( t3.getRoot() );
10549 if ( t3.getNode( "B" ).getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10552 if ( t3.getNode( "A" ).getParent().getBranchData().getConfidence( 0 ).getValue() != 20 ) {
10555 if ( t3.getNode( "A" ).getParent().getNumberOfDescendants() != 3 ) {
10559 catch ( final Exception e ) {
10560 e.printStackTrace( System.out );
10566 private static boolean testSDIse() {
10568 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10569 final Phylogeny species1 = factory.create( "[&&NHX:S=yeast]", new NHXParser() )[ 0 ];
10570 final Phylogeny gene1 = factory.create( "(A1[&&NHX:S=yeast],A2[&&NHX:S=yeast])", new NHXParser() )[ 0 ];
10571 gene1.setRooted( true );
10572 species1.setRooted( true );
10573 final SDI sdi = new SDI( gene1, species1 );
10574 if ( !gene1.getRoot().isDuplication() ) {
10577 final Phylogeny species2 = factory
10578 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10579 new NHXParser() )[ 0 ];
10580 final Phylogeny gene2 = factory
10581 .create( "(((([&&NHX:S=A],[&&NHX:S=B])ab,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10582 new NHXParser() )[ 0 ];
10583 species2.setRooted( true );
10584 gene2.setRooted( true );
10585 final SDI sdi2 = new SDI( gene2, species2 );
10586 if ( sdi2.getDuplicationsSum() != 0 ) {
10589 if ( !gene2.getNode( "ab" ).isSpeciation() ) {
10592 if ( !gene2.getNode( "ab" ).isHasAssignedEvent() ) {
10595 if ( !gene2.getNode( "abc" ).isSpeciation() ) {
10598 if ( !gene2.getNode( "abc" ).isHasAssignedEvent() ) {
10601 if ( !gene2.getNode( "r" ).isSpeciation() ) {
10604 if ( !gene2.getNode( "r" ).isHasAssignedEvent() ) {
10607 final Phylogeny species3 = factory
10608 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10609 new NHXParser() )[ 0 ];
10610 final Phylogeny gene3 = factory
10611 .create( "(((([&&NHX:S=A],[&&NHX:S=A])aa,[&&NHX:S=C])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10612 new NHXParser() )[ 0 ];
10613 species3.setRooted( true );
10614 gene3.setRooted( true );
10615 final SDI sdi3 = new SDI( gene3, species3 );
10616 if ( sdi3.getDuplicationsSum() != 1 ) {
10619 if ( !gene3.getNode( "aa" ).isDuplication() ) {
10622 if ( !gene3.getNode( "aa" ).isHasAssignedEvent() ) {
10625 final Phylogeny species4 = factory
10626 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10627 new NHXParser() )[ 0 ];
10628 final Phylogeny gene4 = factory
10629 .create( "(((([&&NHX:S=A],[&&NHX:S=C])ac,[&&NHX:S=B])abc,[&&NHX:S=D])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10630 new NHXParser() )[ 0 ];
10631 species4.setRooted( true );
10632 gene4.setRooted( true );
10633 final SDI sdi4 = new SDI( gene4, species4 );
10634 if ( sdi4.getDuplicationsSum() != 1 ) {
10637 if ( !gene4.getNode( "ac" ).isSpeciation() ) {
10640 if ( !gene4.getNode( "abc" ).isDuplication() ) {
10643 if ( gene4.getNode( "abcd" ).isDuplication() ) {
10646 if ( species4.getNumberOfExternalNodes() != 6 ) {
10649 if ( gene4.getNumberOfExternalNodes() != 6 ) {
10652 final Phylogeny species5 = factory
10653 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10654 new NHXParser() )[ 0 ];
10655 final Phylogeny gene5 = factory
10656 .create( "(((([&&NHX:S=A],[&&NHX:S=D])ad,[&&NHX:S=C])adc,[&&NHX:S=B])abcd,([&&NHX:S=E],[&&NHX:S=F])ef)r",
10657 new NHXParser() )[ 0 ];
10658 species5.setRooted( true );
10659 gene5.setRooted( true );
10660 final SDI sdi5 = new SDI( gene5, species5 );
10661 if ( sdi5.getDuplicationsSum() != 2 ) {
10664 if ( !gene5.getNode( "ad" ).isSpeciation() ) {
10667 if ( !gene5.getNode( "adc" ).isDuplication() ) {
10670 if ( !gene5.getNode( "abcd" ).isDuplication() ) {
10673 if ( species5.getNumberOfExternalNodes() != 6 ) {
10676 if ( gene5.getNumberOfExternalNodes() != 6 ) {
10679 // Trees from Louxin Zhang 1997 "On a Mirkin-Muchnik-Smith
10680 // Conjecture for Comparing Molecular Phylogenies"
10681 // J. of Comput Bio. Vol. 4, No 2, pp.177-187
10682 final Phylogeny species6 = factory
10683 .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,"
10684 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
10685 new NHXParser() )[ 0 ];
10686 final Phylogeny gene6 = factory
10687 .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,"
10688 + "((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,"
10689 + "(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;",
10690 new NHXParser() )[ 0 ];
10691 species6.setRooted( true );
10692 gene6.setRooted( true );
10693 final SDI sdi6 = new SDI( gene6, species6 );
10694 if ( sdi6.getDuplicationsSum() != 3 ) {
10697 if ( !gene6.getNode( "r" ).isDuplication() ) {
10700 if ( !gene6.getNode( "4-5-6" ).isDuplication() ) {
10703 if ( !gene6.getNode( "7-8-9" ).isDuplication() ) {
10706 if ( !gene6.getNode( "1-2" ).isSpeciation() ) {
10709 if ( !gene6.getNode( "1-2-3" ).isSpeciation() ) {
10712 if ( !gene6.getNode( "5-6" ).isSpeciation() ) {
10715 if ( !gene6.getNode( "8-9" ).isSpeciation() ) {
10718 if ( !gene6.getNode( "4-5-6-7-8-9" ).isSpeciation() ) {
10721 sdi6.computeMappingCostL();
10722 if ( sdi6.computeMappingCostL() != 17 ) {
10725 if ( species6.getNumberOfExternalNodes() != 9 ) {
10728 if ( gene6.getNumberOfExternalNodes() != 9 ) {
10731 final Phylogeny species7 = Test.createPhylogeny( "(((((((" + "([&&NHX:S=a1],[&&NHX:S=a2]),"
10732 + "([&&NHX:S=b1],[&&NHX:S=b2])" + "),[&&NHX:S=x]),(" + "([&&NHX:S=m1],[&&NHX:S=m2]),"
10733 + "([&&NHX:S=n1],[&&NHX:S=n2])" + ")),(" + "([&&NHX:S=i1],[&&NHX:S=i2]),"
10734 + "([&&NHX:S=j1],[&&NHX:S=j2])" + ")),(" + "([&&NHX:S=e1],[&&NHX:S=e2]),"
10735 + "([&&NHX:S=f1],[&&NHX:S=f2])" + ")),[&&NHX:S=y]),[&&NHX:S=z])" );
10736 species7.setRooted( true );
10737 final Phylogeny gene7_1 = Test
10738 .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])" );
10739 gene7_1.setRooted( true );
10740 final SDI sdi7 = new SDI( gene7_1, species7 );
10741 if ( sdi7.getDuplicationsSum() != 0 ) {
10744 if ( !Test.getEvent( gene7_1, "a1", "a2" ).isSpeciation() ) {
10747 if ( !Test.getEvent( gene7_1, "a1", "b1" ).isSpeciation() ) {
10750 if ( !Test.getEvent( gene7_1, "a1", "x" ).isSpeciation() ) {
10753 if ( !Test.getEvent( gene7_1, "a1", "m1" ).isSpeciation() ) {
10756 if ( !Test.getEvent( gene7_1, "a1", "i1" ).isSpeciation() ) {
10759 if ( !Test.getEvent( gene7_1, "a1", "e1" ).isSpeciation() ) {
10762 if ( !Test.getEvent( gene7_1, "a1", "y" ).isSpeciation() ) {
10765 if ( !Test.getEvent( gene7_1, "a1", "z" ).isSpeciation() ) {
10768 final Phylogeny gene7_2 = Test
10769 .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])" );
10770 gene7_2.setRooted( true );
10771 final SDI sdi7_2 = new SDI( gene7_2, species7 );
10772 if ( sdi7_2.getDuplicationsSum() != 1 ) {
10775 if ( !Test.getEvent( gene7_2, "a1", "a2" ).isSpeciation() ) {
10778 if ( !Test.getEvent( gene7_2, "a1", "b1" ).isSpeciation() ) {
10781 if ( !Test.getEvent( gene7_2, "a1", "x" ).isSpeciation() ) {
10784 if ( !Test.getEvent( gene7_2, "a1", "m1" ).isSpeciation() ) {
10787 if ( !Test.getEvent( gene7_2, "a1", "i1" ).isSpeciation() ) {
10790 if ( !Test.getEvent( gene7_2, "a1", "j2" ).isDuplication() ) {
10793 if ( !Test.getEvent( gene7_2, "a1", "e1" ).isSpeciation() ) {
10796 if ( !Test.getEvent( gene7_2, "a1", "y" ).isSpeciation() ) {
10799 if ( !Test.getEvent( gene7_2, "a1", "z" ).isSpeciation() ) {
10803 catch ( final Exception e ) {
10809 private static boolean testSDIunrooted() {
10811 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
10812 final Phylogeny p0 = factory.create( "((((A,B)ab,(C1,C2)cc)abc,D)abcd,(E,F)ef)abcdef", new NHXParser() )[ 0 ];
10813 final List<PhylogenyBranch> l = SDIR.getBranchesInPreorder( p0 );
10814 final Iterator<PhylogenyBranch> iter = l.iterator();
10815 PhylogenyBranch br = iter.next();
10816 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "ef" ) ) {
10819 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "ef" ) ) {
10823 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10826 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10830 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "ab" ) ) {
10833 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "ab" ) ) {
10837 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10840 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10844 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10847 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10851 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "abc" ) ) {
10854 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "abc" ) ) {
10858 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10861 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10865 if ( !br.getFirstNode().getName().equals( "C1" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10868 if ( !br.getSecondNode().getName().equals( "C1" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10872 if ( !br.getFirstNode().getName().equals( "C2" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10875 if ( !br.getSecondNode().getName().equals( "C2" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10879 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "cc" ) ) {
10882 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "cc" ) ) {
10886 if ( !br.getFirstNode().getName().equals( "abc" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10889 if ( !br.getSecondNode().getName().equals( "abc" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10893 if ( !br.getFirstNode().getName().equals( "abcd" ) && !br.getFirstNode().getName().equals( "D" ) ) {
10896 if ( !br.getSecondNode().getName().equals( "abcd" ) && !br.getSecondNode().getName().equals( "D" ) ) {
10900 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "abcd" ) ) {
10903 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "abcd" ) ) {
10907 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "E" ) ) {
10910 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "E" ) ) {
10914 if ( !br.getFirstNode().getName().equals( "ef" ) && !br.getFirstNode().getName().equals( "F" ) ) {
10917 if ( !br.getSecondNode().getName().equals( "ef" ) && !br.getSecondNode().getName().equals( "F" ) ) {
10920 if ( iter.hasNext() ) {
10923 final Phylogeny p1 = factory.create( "(C,(A,B)ab)abc", new NHXParser() )[ 0 ];
10924 final List<PhylogenyBranch> l1 = SDIR.getBranchesInPreorder( p1 );
10925 final Iterator<PhylogenyBranch> iter1 = l1.iterator();
10927 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10930 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10934 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10937 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10941 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10944 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10947 if ( iter1.hasNext() ) {
10950 final Phylogeny p2 = factory.create( "((A,B)ab,C)abc", new NHXParser() )[ 0 ];
10951 final List<PhylogenyBranch> l2 = SDIR.getBranchesInPreorder( p2 );
10952 final Iterator<PhylogenyBranch> iter2 = l2.iterator();
10954 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "C" ) ) {
10957 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "C" ) ) {
10961 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "A" ) ) {
10964 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "A" ) ) {
10968 if ( !br.getFirstNode().getName().equals( "ab" ) && !br.getFirstNode().getName().equals( "B" ) ) {
10971 if ( !br.getSecondNode().getName().equals( "ab" ) && !br.getSecondNode().getName().equals( "B" ) ) {
10974 if ( iter2.hasNext() ) {
10977 final Phylogeny species0 = factory
10978 .create( "(((([&&NHX:S=A],[&&NHX:S=B]),[&&NHX:S=C]),[&&NHX:S=D]),([&&NHX:S=E],[&&NHX:S=F]))",
10979 new NHXParser() )[ 0 ];
10980 final Phylogeny gene1 = factory
10981 .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])",
10982 new NHXParser() )[ 0 ];
10983 species0.setRooted( true );
10984 gene1.setRooted( true );
10985 final SDIR sdi_unrooted = new SDIR();
10986 sdi_unrooted.infer( gene1, species0, false, true, true, true, 10 );
10987 if ( sdi_unrooted.getCount() != 1 ) {
10990 if ( sdi_unrooted.getMinimalDuplications() != 0 ) {
10993 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.4 ) ) {
10996 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 1.0 ) ) {
10999 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11002 final Phylogeny gene2 = factory
11003 .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])",
11004 new NHXParser() )[ 0 ];
11005 gene2.setRooted( true );
11006 sdi_unrooted.infer( gene2, species0, false, false, true, true, 10 );
11007 if ( sdi_unrooted.getCount() != 1 ) {
11010 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11013 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11016 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 2.0 ) ) {
11019 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11022 final Phylogeny species6 = factory
11023 .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,"
11024 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11025 new NHXParser() )[ 0 ];
11026 final Phylogeny gene6 = factory
11027 .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],"
11028 + "(((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],"
11029 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11030 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11031 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11032 new NHXParser() )[ 0 ];
11033 species6.setRooted( true );
11034 gene6.setRooted( true );
11035 Phylogeny[] p6 = sdi_unrooted.infer( gene6, species6, false, true, true, true, 10 );
11036 if ( sdi_unrooted.getCount() != 1 ) {
11039 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11042 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11045 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11048 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11051 if ( !p6[ 0 ].getRoot().isDuplication() ) {
11054 if ( !p6[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11057 if ( !p6[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11060 if ( p6[ 0 ].getNode( "1-2" ).isDuplication() ) {
11063 if ( p6[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11066 if ( p6[ 0 ].getNode( "5-6" ).isDuplication() ) {
11069 if ( p6[ 0 ].getNode( "8-9" ).isDuplication() ) {
11072 if ( p6[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11076 final Phylogeny species7 = factory
11077 .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,"
11078 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11079 new NHXParser() )[ 0 ];
11080 final Phylogeny gene7 = factory
11081 .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],"
11082 + "(((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],"
11083 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11084 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11085 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11086 new NHXParser() )[ 0 ];
11087 species7.setRooted( true );
11088 gene7.setRooted( true );
11089 Phylogeny[] p7 = sdi_unrooted.infer( gene7, species7, true, true, true, true, 10 );
11090 if ( sdi_unrooted.getCount() != 1 ) {
11093 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11096 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11099 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11102 if ( sdi_unrooted.getMinimalMappingCost() != 17 ) {
11105 if ( !p7[ 0 ].getRoot().isDuplication() ) {
11108 if ( !p7[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11111 if ( !p7[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11114 if ( p7[ 0 ].getNode( "1-2" ).isDuplication() ) {
11117 if ( p7[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11120 if ( p7[ 0 ].getNode( "5-6" ).isDuplication() ) {
11123 if ( p7[ 0 ].getNode( "8-9" ).isDuplication() ) {
11126 if ( p7[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11130 final Phylogeny species8 = factory
11131 .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,"
11132 + "((9:[&&NHX:S=9],3:[&&NHX:S=3])9-3,(8:[&&NHX:S=8],7:[&&NHX:S=7])8-7)9-3-8-7)",
11133 new NHXParser() )[ 0 ];
11134 final Phylogeny gene8 = factory
11135 .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],"
11136 + "(((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],"
11137 + "(7:0.1[&&NHX:S=7],(8:0.1[&&NHX:S=8],"
11138 + "9:0.1[&&NHX:S=9])8-9:0.1[&&NHX:S=9])7-8-9:0.1[&&NHX:S=8])"
11139 + "4-5-6-7-8-9:0.1[&&NHX:S=5])4-5-6:0.05[&&NHX:S=5])",
11140 new NHXParser() )[ 0 ];
11141 species8.setRooted( true );
11142 gene8.setRooted( true );
11143 Phylogeny[] p8 = sdi_unrooted.infer( gene8, species8, false, false, true, true, 10 );
11144 if ( sdi_unrooted.getCount() != 1 ) {
11147 if ( !Test.isEqual( sdi_unrooted.getMinimalDiffInSubTreeHeights(), 0.0 ) ) {
11150 if ( !Test.isEqual( sdi_unrooted.getMinimalTreeHeight(), 0.375 ) ) {
11153 if ( sdi_unrooted.getMinimalDuplications() != 3 ) {
11156 if ( sdi_unrooted.getMinimalMappingCost() != Integer.MAX_VALUE ) {
11159 if ( !p8[ 0 ].getRoot().isDuplication() ) {
11162 if ( !p8[ 0 ].getNode( "4-5-6" ).isDuplication() ) {
11165 if ( !p8[ 0 ].getNode( "7-8-9" ).isDuplication() ) {
11168 if ( p8[ 0 ].getNode( "1-2" ).isDuplication() ) {
11171 if ( p8[ 0 ].getNode( "1-2-3" ).isDuplication() ) {
11174 if ( p8[ 0 ].getNode( "5-6" ).isDuplication() ) {
11177 if ( p8[ 0 ].getNode( "8-9" ).isDuplication() ) {
11180 if ( p8[ 0 ].getNode( "4-5-6-7-8-9" ).isDuplication() ) {
11185 catch ( final Exception e ) {
11186 e.printStackTrace( System.out );
11192 private static boolean testSequenceDbWsTools1() {
11194 final PhylogenyNode n = new PhylogenyNode();
11195 n.setName( "NP_001025424" );
11196 Accession acc = SequenceDbWsTools.obtainSeqAccession( n );
11197 if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11198 || !acc.getValue().equals( "NP_001025424" ) ) {
11201 n.setName( "340 0559 -- _NP_001025424_dsfdg15 05" );
11202 acc = SequenceDbWsTools.obtainSeqAccession( n );
11203 if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11204 || !acc.getValue().equals( "NP_001025424" ) ) {
11207 n.setName( "NP_001025424.1" );
11208 acc = SequenceDbWsTools.obtainSeqAccession( n );
11209 if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11210 || !acc.getValue().equals( "NP_001025424" ) ) {
11213 n.setName( "NM_001030253" );
11214 acc = SequenceDbWsTools.obtainSeqAccession( n );
11215 if ( ( acc == null ) || !acc.getSource().equals( Source.REFSEQ.toString() )
11216 || !acc.getValue().equals( "NM_001030253" ) ) {
11219 n.setName( "BCL2_HUMAN" );
11220 acc = SequenceDbWsTools.obtainSeqAccession( n );
11221 if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11222 || !acc.getValue().equals( "BCL2_HUMAN" ) ) {
11223 System.out.println( acc.toString() );
11226 n.setName( "P10415" );
11227 acc = SequenceDbWsTools.obtainSeqAccession( n );
11228 if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11229 || !acc.getValue().equals( "P10415" ) ) {
11230 System.out.println( acc.toString() );
11233 n.setName( " P10415 " );
11234 acc = SequenceDbWsTools.obtainSeqAccession( n );
11235 if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11236 || !acc.getValue().equals( "P10415" ) ) {
11237 System.out.println( acc.toString() );
11240 n.setName( "_P10415|" );
11241 acc = SequenceDbWsTools.obtainSeqAccession( n );
11242 if ( ( acc == null ) || !acc.getSource().equals( Source.UNIPROT.toString() )
11243 || !acc.getValue().equals( "P10415" ) ) {
11244 System.out.println( acc.toString() );
11247 n.setName( "AY695820" );
11248 acc = SequenceDbWsTools.obtainSeqAccession( n );
11249 if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11250 || !acc.getValue().equals( "AY695820" ) ) {
11251 System.out.println( acc.toString() );
11254 n.setName( "_AY695820_" );
11255 acc = SequenceDbWsTools.obtainSeqAccession( n );
11256 if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11257 || !acc.getValue().equals( "AY695820" ) ) {
11258 System.out.println( acc.toString() );
11261 n.setName( "AAA59452" );
11262 acc = SequenceDbWsTools.obtainSeqAccession( n );
11263 if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11264 || !acc.getValue().equals( "AAA59452" ) ) {
11265 System.out.println( acc.toString() );
11268 n.setName( "_AAA59452_" );
11269 acc = SequenceDbWsTools.obtainSeqAccession( n );
11270 if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11271 || !acc.getValue().equals( "AAA59452" ) ) {
11272 System.out.println( acc.toString() );
11275 n.setName( "AAA59452.1" );
11276 acc = SequenceDbWsTools.obtainSeqAccession( n );
11277 if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11278 || !acc.getValue().equals( "AAA59452.1" ) ) {
11279 System.out.println( acc.toString() );
11282 n.setName( "_AAA59452.1_" );
11283 acc = SequenceDbWsTools.obtainSeqAccession( n );
11284 if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11285 || !acc.getValue().equals( "AAA59452.1" ) ) {
11286 System.out.println( acc.toString() );
11289 n.setName( "GI:94894583" );
11290 acc = SequenceDbWsTools.obtainSeqAccession( n );
11291 if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11292 || !acc.getValue().equals( "94894583" ) ) {
11293 System.out.println( acc.toString() );
11296 n.setName( "gi|71845847|1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11297 acc = SequenceDbWsTools.obtainSeqAccession( n );
11298 if ( ( acc == null ) || !acc.getSource().equals( Source.GI.toString() )
11299 || !acc.getValue().equals( "71845847" ) ) {
11300 System.out.println( acc.toString() );
11303 n.setName( "gi|71845847|gb|AAZ45343.1| 1,4-alpha-glucan branching enzyme [Dechloromonas aromatica RCB]" );
11304 acc = SequenceDbWsTools.obtainSeqAccession( n );
11305 if ( ( acc == null ) || !acc.getSource().equals( Source.NCBI.toString() )
11306 || !acc.getValue().equals( "AAZ45343.1" ) ) {
11307 System.out.println( acc.toString() );
11311 catch ( final Exception e ) {
11317 private static boolean testSequenceDbWsTools2() {
11319 final PhylogenyNode n1 = new PhylogenyNode( "NP_001025424" );
11320 SequenceDbWsTools.obtainSeqInformation( n1 );
11321 if ( !n1.getNodeData().getSequence().getName().equals( "Bcl2" ) ) {
11324 if ( !n1.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11327 if ( !n1.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11330 if ( !n1.getNodeData().getSequence().getAccession().getValue().equals( "NP_001025424" ) ) {
11333 final PhylogenyNode n2 = new PhylogenyNode( "NM_001030253" );
11334 SequenceDbWsTools.obtainSeqInformation( n2 );
11335 if ( !n2.getNodeData().getSequence().getName().equals( "Danio rerio B-cell CLL/lymphoma 2a (bcl2a), mRNA" ) ) {
11338 if ( !n2.getNodeData().getTaxonomy().getScientificName().equals( "Danio rerio" ) ) {
11341 if ( !n2.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11344 if ( !n2.getNodeData().getSequence().getAccession().getValue().equals( "NM_001030253" ) ) {
11347 final PhylogenyNode n3 = new PhylogenyNode( "NM_184234.2" );
11348 SequenceDbWsTools.obtainSeqInformation( n3 );
11349 if ( !n3.getNodeData().getSequence().getName()
11350 .equals( "Homo sapiens RNA binding motif protein 39 (RBM39), transcript variant 1, mRNA" ) ) {
11353 if ( !n3.getNodeData().getTaxonomy().getScientificName().equals( "Homo sapiens" ) ) {
11356 if ( !n3.getNodeData().getSequence().getAccession().getSource().equals( Source.REFSEQ.toString() ) ) {
11359 if ( !n3.getNodeData().getSequence().getAccession().getValue().equals( "NM_184234" ) ) {
11363 catch ( final IOException e ) {
11364 System.out.println();
11365 System.out.println( "the following might be due to absence internet connection:" );
11366 e.printStackTrace( System.out );
11369 catch ( final Exception e ) {
11370 e.printStackTrace();
11376 private static boolean testSequenceIdParsing() {
11378 Accession id = SequenceAccessionTools.parseAccessorFromString( "gb_ADF31344_segmented_worms_" );
11379 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11380 || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11381 if ( id != null ) {
11382 System.out.println( "value =" + id.getValue() );
11383 System.out.println( "provider=" + id.getSource() );
11387 id = SequenceAccessionTools.parseAccessorFromString( "segmented worms|gb_ADF31344" );
11388 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11389 || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11390 if ( id != null ) {
11391 System.out.println( "value =" + id.getValue() );
11392 System.out.println( "provider=" + id.getSource() );
11396 id = SequenceAccessionTools.parseAccessorFromString( "segmented worms gb_ADF31344 and more" );
11397 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11398 || !id.getValue().equals( "ADF31344" ) || !id.getSource().equals( "ncbi" ) ) {
11399 if ( id != null ) {
11400 System.out.println( "value =" + id.getValue() );
11401 System.out.println( "provider=" + id.getSource() );
11405 id = SequenceAccessionTools.parseAccessorFromString( "gb_AAA96518_1" );
11406 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11407 || !id.getValue().equals( "AAA96518" ) || !id.getSource().equals( "ncbi" ) ) {
11408 if ( id != null ) {
11409 System.out.println( "value =" + id.getValue() );
11410 System.out.println( "provider=" + id.getSource() );
11414 id = SequenceAccessionTools.parseAccessorFromString( "gb_EHB07727_1_rodents_" );
11415 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11416 || !id.getValue().equals( "EHB07727" ) || !id.getSource().equals( "ncbi" ) ) {
11417 if ( id != null ) {
11418 System.out.println( "value =" + id.getValue() );
11419 System.out.println( "provider=" + id.getSource() );
11423 id = SequenceAccessionTools.parseAccessorFromString( "dbj_BAF37827_1_turtles_" );
11424 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11425 || !id.getValue().equals( "BAF37827" ) || !id.getSource().equals( "ncbi" ) ) {
11426 if ( id != null ) {
11427 System.out.println( "value =" + id.getValue() );
11428 System.out.println( "provider=" + id.getSource() );
11432 id = SequenceAccessionTools.parseAccessorFromString( "emb_CAA73223_1_primates_" );
11433 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11434 || !id.getValue().equals( "CAA73223" ) || !id.getSource().equals( "ncbi" ) ) {
11435 if ( id != null ) {
11436 System.out.println( "value =" + id.getValue() );
11437 System.out.println( "provider=" + id.getSource() );
11441 id = SequenceAccessionTools.parseAccessorFromString( "mites|ref_XP_002434188_1" );
11442 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11443 || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11444 if ( id != null ) {
11445 System.out.println( "value =" + id.getValue() );
11446 System.out.println( "provider=" + id.getSource() );
11450 id = SequenceAccessionTools.parseAccessorFromString( "mites_ref_XP_002434188_1_bla_XP_12345" );
11451 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11452 || !id.getValue().equals( "XP_002434188" ) || !id.getSource().equals( "refseq" ) ) {
11453 if ( id != null ) {
11454 System.out.println( "value =" + id.getValue() );
11455 System.out.println( "provider=" + id.getSource() );
11459 id = SequenceAccessionTools.parseAccessorFromString( "P4A123" );
11460 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11461 || !id.getValue().equals( "P4A123" ) || !id.getSource().equals( "uniprot" ) ) {
11462 if ( id != null ) {
11463 System.out.println( "value =" + id.getValue() );
11464 System.out.println( "provider=" + id.getSource() );
11468 id = SequenceAccessionTools.parseAccessorFromString( "XP_12345" );
11469 if ( id != null ) {
11470 System.out.println( "value =" + id.getValue() );
11471 System.out.println( "provider=" + id.getSource() );
11474 id = SequenceAccessionTools.parseAccessorFromString( "N3B004Z009" );
11475 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11476 || !id.getValue().equals( "N3B004Z009" ) || !id.getSource().equals( "uniprot" ) ) {
11477 if ( id != null ) {
11478 System.out.println( "value =" + id.getValue() );
11479 System.out.println( "provider=" + id.getSource() );
11483 id = SequenceAccessionTools.parseAccessorFromString( "A4CAA4ZBB9" );
11484 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11485 || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
11486 if ( id != null ) {
11487 System.out.println( "value =" + id.getValue() );
11488 System.out.println( "provider=" + id.getSource() );
11492 id = SequenceAccessionTools.parseAccessorFromString( "ecoli_A4CAA4ZBB9_rt" );
11493 if ( ( id == null ) || ForesterUtil.isEmpty( id.getValue() ) || ForesterUtil.isEmpty( id.getSource() )
11494 || !id.getValue().equals( "A4CAA4ZBB9" ) || !id.getSource().equals( "uniprot" ) ) {
11495 if ( id != null ) {
11496 System.out.println( "value =" + id.getValue() );
11497 System.out.println( "provider=" + id.getSource() );
11501 id = SequenceAccessionTools.parseAccessorFromString( "Q4CAA4ZBB9" );
11502 if ( id != null ) {
11503 System.out.println( "value =" + id.getValue() );
11504 System.out.println( "provider=" + id.getSource() );
11508 catch ( final Exception e ) {
11509 e.printStackTrace( System.out );
11515 private static boolean testSequenceWriter() {
11517 final String n = ForesterUtil.LINE_SEPARATOR;
11518 if ( !SequenceWriter.toFasta( "name", "awes", 5 ).toString().equals( ">name" + n + "awes" ) ) {
11521 if ( !SequenceWriter.toFasta( "name", "awes", 4 ).toString().equals( ">name" + n + "awes" ) ) {
11524 if ( !SequenceWriter.toFasta( "name", "awes", 3 ).toString().equals( ">name" + n + "awe" + n + "s" ) ) {
11527 if ( !SequenceWriter.toFasta( "name", "awes", 2 ).toString().equals( ">name" + n + "aw" + n + "es" ) ) {
11530 if ( !SequenceWriter.toFasta( "name", "awes", 1 ).toString()
11531 .equals( ">name" + n + "a" + n + "w" + n + "e" + n + "s" ) ) {
11534 if ( !SequenceWriter.toFasta( "name", "abcdefghij", 3 ).toString()
11535 .equals( ">name" + n + "abc" + n + "def" + n + "ghi" + n + "j" ) ) {
11539 catch ( final Exception e ) {
11540 e.printStackTrace();
11546 private static boolean testSpecies() {
11548 final Species s1 = new BasicSpecies( "a" );
11549 final Species s2 = new BasicSpecies( "a" );
11550 final Species s3 = new BasicSpecies( "A" );
11551 final Species s4 = new BasicSpecies( "b" );
11552 if ( !s1.equals( s1 ) ) {
11555 if ( s1.getSpeciesId().equals( "x" ) ) {
11558 if ( s1.getSpeciesId().equals( null ) ) {
11561 if ( !s1.equals( s2 ) ) {
11564 if ( s1.equals( s3 ) ) {
11567 if ( s1.hashCode() != s1.hashCode() ) {
11570 if ( s1.hashCode() != s2.hashCode() ) {
11573 if ( s1.hashCode() == s3.hashCode() ) {
11576 if ( s1.compareTo( s1 ) != 0 ) {
11579 if ( s1.compareTo( s2 ) != 0 ) {
11582 if ( s1.compareTo( s3 ) != 0 ) {
11585 if ( s1.compareTo( s4 ) >= 0 ) {
11588 if ( s4.compareTo( s1 ) <= 0 ) {
11591 if ( !s4.getSpeciesId().equals( "b" ) ) {
11594 final Species s5 = new BasicSpecies( " C " );
11595 if ( !s5.getSpeciesId().equals( "C" ) ) {
11598 if ( s5.equals( s1 ) ) {
11602 catch ( final Exception e ) {
11603 e.printStackTrace( System.out );
11609 private static boolean testSplit() {
11611 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11612 final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11613 //Archaeopteryx.createApplication( p0 );
11614 final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11615 ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11616 ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11617 ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11618 ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11619 ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11620 ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11621 ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11622 ex.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11623 ex.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11624 final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, false, ex );
11625 // System.out.println( s0.toString() );
11627 Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
11628 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11629 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11630 if ( s0.match( query_nodes ) ) {
11633 query_nodes = new HashSet<PhylogenyNode>();
11634 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11635 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11636 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11637 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11638 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11639 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11640 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11641 if ( !s0.match( query_nodes ) ) {
11645 query_nodes = new HashSet<PhylogenyNode>();
11646 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11647 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11648 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11649 if ( !s0.match( query_nodes ) ) {
11653 query_nodes = new HashSet<PhylogenyNode>();
11654 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11655 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11656 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11657 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11658 if ( !s0.match( query_nodes ) ) {
11662 query_nodes = new HashSet<PhylogenyNode>();
11663 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11664 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11665 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11666 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11667 if ( !s0.match( query_nodes ) ) {
11671 query_nodes = new HashSet<PhylogenyNode>();
11672 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11673 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11674 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11675 if ( !s0.match( query_nodes ) ) {
11678 query_nodes = new HashSet<PhylogenyNode>();
11679 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11680 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11681 if ( !s0.match( query_nodes ) ) {
11684 query_nodes = new HashSet<PhylogenyNode>();
11685 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11686 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11687 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11688 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11689 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11690 if ( !s0.match( query_nodes ) ) {
11693 query_nodes = new HashSet<PhylogenyNode>();
11694 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11695 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11696 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11697 if ( !s0.match( query_nodes ) ) {
11700 query_nodes = new HashSet<PhylogenyNode>();
11701 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11702 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11703 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11704 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11705 if ( !s0.match( query_nodes ) ) {
11708 query_nodes = new HashSet<PhylogenyNode>();
11709 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11710 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11711 if ( s0.match( query_nodes ) ) {
11714 query_nodes = new HashSet<PhylogenyNode>();
11715 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11716 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11717 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11718 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11719 if ( s0.match( query_nodes ) ) {
11722 query_nodes = new HashSet<PhylogenyNode>();
11723 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11724 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11725 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11726 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11727 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11728 if ( s0.match( query_nodes ) ) {
11731 query_nodes = new HashSet<PhylogenyNode>();
11732 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11733 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11734 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11735 if ( s0.match( query_nodes ) ) {
11738 query_nodes = new HashSet<PhylogenyNode>();
11739 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11740 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11741 if ( s0.match( query_nodes ) ) {
11744 query_nodes = new HashSet<PhylogenyNode>();
11745 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11746 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11747 if ( s0.match( query_nodes ) ) {
11750 query_nodes = new HashSet<PhylogenyNode>();
11751 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11752 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11753 if ( s0.match( query_nodes ) ) {
11756 query_nodes = new HashSet<PhylogenyNode>();
11757 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11758 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11759 if ( s0.match( query_nodes ) ) {
11762 query_nodes = new HashSet<PhylogenyNode>();
11763 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11764 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11765 if ( s0.match( query_nodes ) ) {
11768 query_nodes = new HashSet<PhylogenyNode>();
11769 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11770 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11771 if ( s0.match( query_nodes ) ) {
11774 query_nodes = new HashSet<PhylogenyNode>();
11775 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11776 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11777 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11778 if ( s0.match( query_nodes ) ) {
11781 query_nodes = new HashSet<PhylogenyNode>();
11782 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11783 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11784 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11785 if ( s0.match( query_nodes ) ) {
11788 query_nodes = new HashSet<PhylogenyNode>();
11789 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11790 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11791 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11792 if ( s0.match( query_nodes ) ) {
11795 query_nodes = new HashSet<PhylogenyNode>();
11796 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11797 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11798 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11799 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11800 if ( s0.match( query_nodes ) ) {
11804 // query_nodes = new HashSet<PhylogenyNode>();
11805 // query_nodes.add( new PhylogenyNode( "X" ) );
11806 // query_nodes.add( new PhylogenyNode( "Y" ) );
11807 // query_nodes.add( new PhylogenyNode( "A" ) );
11808 // query_nodes.add( new PhylogenyNode( "B" ) );
11809 // query_nodes.add( new PhylogenyNode( "C" ) );
11810 // query_nodes.add( new PhylogenyNode( "D" ) );
11811 // query_nodes.add( new PhylogenyNode( "E" ) );
11812 // query_nodes.add( new PhylogenyNode( "F" ) );
11813 // query_nodes.add( new PhylogenyNode( "G" ) );
11814 // if ( !s0.match( query_nodes ) ) {
11817 // query_nodes = new HashSet<PhylogenyNode>();
11818 // query_nodes.add( new PhylogenyNode( "X" ) );
11819 // query_nodes.add( new PhylogenyNode( "Y" ) );
11820 // query_nodes.add( new PhylogenyNode( "A" ) );
11821 // query_nodes.add( new PhylogenyNode( "B" ) );
11822 // query_nodes.add( new PhylogenyNode( "C" ) );
11823 // if ( !s0.match( query_nodes ) ) {
11827 // query_nodes = new HashSet<PhylogenyNode>();
11828 // query_nodes.add( new PhylogenyNode( "X" ) );
11829 // query_nodes.add( new PhylogenyNode( "Y" ) );
11830 // query_nodes.add( new PhylogenyNode( "D" ) );
11831 // query_nodes.add( new PhylogenyNode( "E" ) );
11832 // query_nodes.add( new PhylogenyNode( "F" ) );
11833 // query_nodes.add( new PhylogenyNode( "G" ) );
11834 // if ( !s0.match( query_nodes ) ) {
11838 // query_nodes = new HashSet<PhylogenyNode>();
11839 // query_nodes.add( new PhylogenyNode( "X" ) );
11840 // query_nodes.add( new PhylogenyNode( "Y" ) );
11841 // query_nodes.add( new PhylogenyNode( "A" ) );
11842 // query_nodes.add( new PhylogenyNode( "B" ) );
11843 // query_nodes.add( new PhylogenyNode( "C" ) );
11844 // query_nodes.add( new PhylogenyNode( "D" ) );
11845 // if ( !s0.match( query_nodes ) ) {
11849 // query_nodes = new HashSet<PhylogenyNode>();
11850 // query_nodes.add( new PhylogenyNode( "X" ) );
11851 // query_nodes.add( new PhylogenyNode( "Y" ) );
11852 // query_nodes.add( new PhylogenyNode( "E" ) );
11853 // query_nodes.add( new PhylogenyNode( "F" ) );
11854 // query_nodes.add( new PhylogenyNode( "G" ) );
11855 // if ( !s0.match( query_nodes ) ) {
11859 // query_nodes = new HashSet<PhylogenyNode>();
11860 // query_nodes.add( new PhylogenyNode( "X" ) );
11861 // query_nodes.add( new PhylogenyNode( "Y" ) );
11862 // query_nodes.add( new PhylogenyNode( "F" ) );
11863 // query_nodes.add( new PhylogenyNode( "G" ) );
11864 // if ( !s0.match( query_nodes ) ) {
11868 query_nodes = new HashSet<PhylogenyNode>();
11869 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11870 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11871 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11872 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11873 if ( s0.match( query_nodes ) ) {
11877 query_nodes = new HashSet<PhylogenyNode>();
11878 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11879 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11880 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11881 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11882 if ( s0.match( query_nodes ) ) {
11885 ///////////////////////////
11887 query_nodes = new HashSet<PhylogenyNode>();
11888 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11889 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11890 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11891 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11892 if ( s0.match( query_nodes ) ) {
11896 query_nodes = new HashSet<PhylogenyNode>();
11897 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11898 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11899 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11900 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11901 if ( s0.match( query_nodes ) ) {
11905 query_nodes = new HashSet<PhylogenyNode>();
11906 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11907 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11908 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11909 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11910 if ( s0.match( query_nodes ) ) {
11914 query_nodes = new HashSet<PhylogenyNode>();
11915 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11916 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11917 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11918 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11919 if ( s0.match( query_nodes ) ) {
11923 query_nodes = new HashSet<PhylogenyNode>();
11924 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11925 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11926 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11927 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11928 if ( s0.match( query_nodes ) ) {
11932 query_nodes = new HashSet<PhylogenyNode>();
11933 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11934 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11935 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11936 if ( s0.match( query_nodes ) ) {
11940 query_nodes = new HashSet<PhylogenyNode>();
11941 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11942 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11943 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11944 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11945 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11946 if ( s0.match( query_nodes ) ) {
11950 query_nodes = new HashSet<PhylogenyNode>();
11951 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11952 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11953 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11954 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11955 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11956 if ( s0.match( query_nodes ) ) {
11960 query_nodes = new HashSet<PhylogenyNode>();
11961 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11962 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11963 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11964 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11965 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11966 if ( s0.match( query_nodes ) ) {
11970 query_nodes = new HashSet<PhylogenyNode>();
11971 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "X" ) );
11972 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "Y" ) );
11973 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11974 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11975 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11976 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
11977 if ( s0.match( query_nodes ) ) {
11981 catch ( final Exception e ) {
11982 e.printStackTrace();
11988 private static boolean testSplitStrict() {
11990 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
11991 final Phylogeny p0 = factory.create( "(((A,B,C),D),(E,(F,G)))R", new NHXParser() )[ 0 ];
11992 final Set<PhylogenyNode> ex = new HashSet<PhylogenyNode>();
11993 ex.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
11994 ex.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
11995 ex.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
11996 ex.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
11997 ex.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
11998 ex.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
11999 ex.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12000 final TreeSplitMatrix s0 = new TreeSplitMatrix( p0, true, ex );
12001 Set<PhylogenyNode> query_nodes = new HashSet<PhylogenyNode>();
12002 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12003 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12004 if ( s0.match( query_nodes ) ) {
12007 query_nodes = new HashSet<PhylogenyNode>();
12008 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12009 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12010 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12011 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12012 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12013 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12014 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12015 if ( !s0.match( query_nodes ) ) {
12019 query_nodes = new HashSet<PhylogenyNode>();
12020 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12021 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12022 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12023 if ( !s0.match( query_nodes ) ) {
12027 query_nodes = new HashSet<PhylogenyNode>();
12028 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12029 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12030 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12031 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12032 if ( !s0.match( query_nodes ) ) {
12036 query_nodes = new HashSet<PhylogenyNode>();
12037 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12038 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12039 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12040 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12041 if ( !s0.match( query_nodes ) ) {
12045 query_nodes = new HashSet<PhylogenyNode>();
12046 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12047 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12048 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12049 if ( !s0.match( query_nodes ) ) {
12053 query_nodes = new HashSet<PhylogenyNode>();
12054 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12055 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12056 if ( !s0.match( query_nodes ) ) {
12060 query_nodes = new HashSet<PhylogenyNode>();
12061 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12062 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12063 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12064 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12065 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12066 if ( !s0.match( query_nodes ) ) {
12070 query_nodes = new HashSet<PhylogenyNode>();
12071 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12072 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12073 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12074 if ( !s0.match( query_nodes ) ) {
12078 query_nodes = new HashSet<PhylogenyNode>();
12079 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12080 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12081 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12082 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12083 if ( !s0.match( query_nodes ) ) {
12087 query_nodes = new HashSet<PhylogenyNode>();
12088 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12089 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12090 if ( s0.match( query_nodes ) ) {
12094 query_nodes = new HashSet<PhylogenyNode>();
12095 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12096 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12097 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12098 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12099 if ( s0.match( query_nodes ) ) {
12103 query_nodes = new HashSet<PhylogenyNode>();
12104 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12105 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12106 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12107 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12108 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12109 if ( s0.match( query_nodes ) ) {
12113 query_nodes = new HashSet<PhylogenyNode>();
12114 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12115 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12116 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12117 if ( s0.match( query_nodes ) ) {
12121 query_nodes = new HashSet<PhylogenyNode>();
12122 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12123 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12124 if ( s0.match( query_nodes ) ) {
12128 query_nodes = new HashSet<PhylogenyNode>();
12129 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12130 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12131 if ( s0.match( query_nodes ) ) {
12135 query_nodes = new HashSet<PhylogenyNode>();
12136 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12137 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "C" ) );
12138 if ( s0.match( query_nodes ) ) {
12142 query_nodes = new HashSet<PhylogenyNode>();
12143 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12144 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12145 if ( s0.match( query_nodes ) ) {
12149 query_nodes = new HashSet<PhylogenyNode>();
12150 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12151 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12152 if ( s0.match( query_nodes ) ) {
12156 query_nodes = new HashSet<PhylogenyNode>();
12157 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12158 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12159 if ( s0.match( query_nodes ) ) {
12163 query_nodes = new HashSet<PhylogenyNode>();
12164 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12165 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "F" ) );
12166 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12167 if ( s0.match( query_nodes ) ) {
12171 query_nodes = new HashSet<PhylogenyNode>();
12172 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12173 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "B" ) );
12174 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12175 if ( s0.match( query_nodes ) ) {
12179 query_nodes = new HashSet<PhylogenyNode>();
12180 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12181 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12182 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12183 if ( s0.match( query_nodes ) ) {
12187 query_nodes = new HashSet<PhylogenyNode>();
12188 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "E" ) );
12189 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "D" ) );
12190 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "A" ) );
12191 query_nodes.add( PhylogenyNode.createInstanceFromNhxString( "G" ) );
12192 if ( s0.match( query_nodes ) ) {
12196 catch ( final Exception e ) {
12197 e.printStackTrace();
12203 private static boolean testSubtreeDeletion() {
12205 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12206 final Phylogeny t1 = factory.create( "((A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12207 t1.deleteSubtree( t1.getNode( "A" ), false );
12208 if ( t1.getNumberOfExternalNodes() != 5 ) {
12211 t1.toNewHampshireX();
12212 t1.deleteSubtree( t1.getNode( "E" ), false );
12213 if ( t1.getNumberOfExternalNodes() != 4 ) {
12216 t1.toNewHampshireX();
12217 t1.deleteSubtree( t1.getNode( "F" ), false );
12218 if ( t1.getNumberOfExternalNodes() != 3 ) {
12221 t1.toNewHampshireX();
12222 t1.deleteSubtree( t1.getNode( "D" ), false );
12223 t1.toNewHampshireX();
12224 if ( t1.getNumberOfExternalNodes() != 3 ) {
12227 t1.deleteSubtree( t1.getNode( "def" ), false );
12228 t1.toNewHampshireX();
12229 if ( t1.getNumberOfExternalNodes() != 2 ) {
12232 t1.deleteSubtree( t1.getNode( "B" ), false );
12233 t1.toNewHampshireX();
12234 if ( t1.getNumberOfExternalNodes() != 1 ) {
12237 t1.deleteSubtree( t1.getNode( "C" ), false );
12238 t1.toNewHampshireX();
12239 if ( t1.getNumberOfExternalNodes() != 1 ) {
12242 t1.deleteSubtree( t1.getNode( "abc" ), false );
12243 t1.toNewHampshireX();
12244 if ( t1.getNumberOfExternalNodes() != 1 ) {
12247 t1.deleteSubtree( t1.getNode( "r" ), false );
12248 if ( t1.getNumberOfExternalNodes() != 0 ) {
12251 if ( !t1.isEmpty() ) {
12254 final Phylogeny t2 = factory.create( "(((1,2,3)A,B,C)abc,(D,E,F)def)r", new NHXParser() )[ 0 ];
12255 t2.deleteSubtree( t2.getNode( "A" ), false );
12256 t2.toNewHampshireX();
12257 if ( t2.getNumberOfExternalNodes() != 5 ) {
12260 t2.deleteSubtree( t2.getNode( "abc" ), false );
12261 t2.toNewHampshireX();
12262 if ( t2.getNumberOfExternalNodes() != 3 ) {
12265 t2.deleteSubtree( t2.getNode( "def" ), false );
12266 t2.toNewHampshireX();
12267 if ( t2.getNumberOfExternalNodes() != 1 ) {
12271 catch ( final Exception e ) {
12272 e.printStackTrace( System.out );
12278 private static boolean testSupportCount() {
12280 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12281 final Phylogeny t0_1 = factory.create( "(((A,B),C),(D,E))", new NHXParser() )[ 0 ];
12282 final Phylogeny[] phylogenies_1 = factory.create( "(((A,B),C),(D,E)) " + "(((C,B),A),(D,E))"
12283 + "(((A,B),C),(D,E)) " + "(((A,B),C),(D,E))"
12284 + "(((A,B),C),(D,E))" + "(((C,B),A),(D,E))"
12285 + "(((E,B),D),(C,A))" + "(((C,B),A),(D,E))"
12286 + "(((A,B),C),(D,E))" + "(((A,B),C),(D,E))",
12288 SupportCount.count( t0_1, phylogenies_1, true, false );
12289 final Phylogeny t0_2 = factory.create( "(((((A,B),C),D),E),(F,G))", new NHXParser() )[ 0 ];
12290 final Phylogeny[] phylogenies_2 = factory.create( "(((((A,B),C),D),E),(F,G))"
12291 + "(((((A,B),C),D),E),((F,G),X))"
12292 + "(((((A,Y),B),C),D),((F,G),E))"
12293 + "(((((A,B),C),D),E),(F,G))"
12294 + "(((((A,B),C),D),E),(F,G))"
12295 + "(((((A,B),C),D),E),(F,G))"
12296 + "(((((A,B),C),D),E),(F,G),Z)"
12297 + "(((((A,B),C),D),E),(F,G))"
12298 + "((((((A,B),C),D),E),F),G)"
12299 + "(((((X,Y),F,G),E),((A,B),C)),D)",
12301 SupportCount.count( t0_2, phylogenies_2, true, false );
12302 final PhylogenyNodeIterator it = t0_2.iteratorPostorder();
12303 while ( it.hasNext() ) {
12304 final PhylogenyNode n = it.next();
12305 if ( !n.isExternal() && ( PhylogenyMethods.getConfidenceValue( n ) != 10 ) ) {
12309 final Phylogeny t0_3 = factory.create( "(((A,B)ab,C)abc,((D,E)de,F)def)", new NHXParser() )[ 0 ];
12310 final Phylogeny[] phylogenies_3 = factory.create( "(((A,B),C),((D,E),F))" + "(((A,C),B),((D,F),E))"
12311 + "(((C,A),B),((F,D),E))" + "(((A,B),F),((D,E),C))" + "(((((A,B),C),D),E),F)", new NHXParser() );
12312 SupportCount.count( t0_3, phylogenies_3, true, false );
12313 t0_3.reRoot( t0_3.getNode( "def" ).getId() );
12314 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "ab" ) ) != 3 ) {
12317 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "abc" ) ) != 4 ) {
12320 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "def" ) ) != 4 ) {
12323 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "de" ) ) != 2 ) {
12326 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "A" ) ) != 5 ) {
12329 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "B" ) ) != 5 ) {
12332 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "C" ) ) != 5 ) {
12335 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "D" ) ) != 5 ) {
12338 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "E" ) ) != 5 ) {
12341 if ( PhylogenyMethods.getConfidenceValue( t0_3.getNode( "F" ) ) != 5 ) {
12344 final Phylogeny t0_4 = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12345 final Phylogeny[] phylogenies_4 = factory.create( "((((((A,X),C),B),D),E),F) "
12346 + "(((A,B,Z),C,Q),(((D,Y),E),F))", new NHXParser() );
12347 SupportCount.count( t0_4, phylogenies_4, true, false );
12348 t0_4.reRoot( t0_4.getNode( "F" ).getId() );
12349 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "1" ) ) != 1 ) {
12352 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "2" ) ) != 2 ) {
12355 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "3" ) ) != 1 ) {
12358 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "4" ) ) != 2 ) {
12361 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "A" ) ) != 2 ) {
12364 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "B" ) ) != 2 ) {
12367 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "C" ) ) != 2 ) {
12370 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "D" ) ) != 2 ) {
12373 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "E" ) ) != 2 ) {
12376 if ( PhylogenyMethods.getConfidenceValue( t0_4.getNode( "F" ) ) != 2 ) {
12379 Phylogeny a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12380 final Phylogeny b1 = factory.create( "(((((B,A)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12381 double d = SupportCount.compare( b1, a, true, true, true );
12382 if ( !Test.isEqual( d, 5.0 / 5.0 ) ) {
12385 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12386 final Phylogeny b2 = factory.create( "(((((C,B)1,A)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12387 d = SupportCount.compare( b2, a, true, true, true );
12388 if ( !Test.isEqual( d, 4.0 / 5.0 ) ) {
12391 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)", new NHXParser() )[ 0 ];
12392 final Phylogeny b3 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)", new NHXParser() )[ 0 ];
12393 d = SupportCount.compare( b3, a, true, true, true );
12394 if ( !Test.isEqual( d, 2.0 / 5.0 ) ) {
12397 a = factory.create( "(((((A,B)1,C)2,D)3,E)4,F)r", new NHXParser() )[ 0 ];
12398 final Phylogeny b4 = factory.create( "(((((F,C)1,A)2,B)3,D)4,E)r", new NHXParser() )[ 0 ];
12399 d = SupportCount.compare( b4, a, true, true, false );
12400 if ( !Test.isEqual( d, 1.0 / 5.0 ) ) {
12404 catch ( final Exception e ) {
12405 e.printStackTrace( System.out );
12411 private static boolean testSupportTransfer() {
12413 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12414 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)",
12415 new NHXParser() )[ 0 ];
12416 final Phylogeny p2 = factory
12417 .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 ];
12418 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) >= 0.0 ) {
12421 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) >= 0.0 ) {
12424 support_transfer.moveBranchLengthsToBootstrap( p1 );
12425 support_transfer.transferSupportValues( p1, p2 );
12426 if ( p2.getNode( "ab" ).getDistanceToParent() != 0.4 ) {
12429 if ( p2.getNode( "abc" ).getDistanceToParent() != 0.5 ) {
12432 if ( p2.getNode( "hi" ).getDistanceToParent() != 0.59 ) {
12435 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "ab" ) ) != 97 ) {
12438 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "abc" ) ) != 57 ) {
12441 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "de" ) ) != 10 ) {
12444 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "fg" ) ) != 50 ) {
12447 if ( PhylogenyMethods.getConfidenceValue( p2.getNode( "hi" ) ) != 64 ) {
12451 catch ( final Exception e ) {
12452 e.printStackTrace( System.out );
12458 private static boolean testTaxonomyExtraction() {
12460 final PhylogenyNode n0 = PhylogenyNode
12461 .createInstanceFromNhxString( "sd_12345678", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12462 if ( n0.getNodeData().isHasTaxonomy() ) {
12465 final PhylogenyNode n1 = PhylogenyNode
12466 .createInstanceFromNhxString( "sd_12345x", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12467 if ( n1.getNodeData().isHasTaxonomy() ) {
12468 System.out.println( n1.toString() );
12471 final PhylogenyNode n2x = PhylogenyNode
12472 .createInstanceFromNhxString( "12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12473 if ( n2x.getNodeData().isHasTaxonomy() ) {
12476 final PhylogenyNode n3 = PhylogenyNode
12477 .createInstanceFromNhxString( "BLAG_12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12478 if ( !n3.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12479 System.out.println( n3.toString() );
12482 final PhylogenyNode n4 = PhylogenyNode
12483 .createInstanceFromNhxString( "blag-12345", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12484 if ( n4.getNodeData().isHasTaxonomy() ) {
12485 System.out.println( n4.toString() );
12488 final PhylogenyNode n5 = PhylogenyNode
12489 .createInstanceFromNhxString( "12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12490 if ( n5.getNodeData().isHasTaxonomy() ) {
12491 System.out.println( n5.toString() );
12494 final PhylogenyNode n6 = PhylogenyNode
12495 .createInstanceFromNhxString( "BLAG-12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12496 if ( n6.getNodeData().isHasTaxonomy() ) {
12497 System.out.println( n6.toString() );
12500 final PhylogenyNode n7 = PhylogenyNode
12501 .createInstanceFromNhxString( "BLAG-12345_blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12502 if ( n7.getNodeData().isHasTaxonomy() ) {
12503 System.out.println( n7.toString() );
12506 final PhylogenyNode n8 = PhylogenyNode
12507 .createInstanceFromNhxString( "BLAG_12345-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12508 if ( !n8.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12509 System.out.println( n8.toString() );
12512 final PhylogenyNode n9 = PhylogenyNode
12513 .createInstanceFromNhxString( "BLAG_12345/blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12514 if ( !n9.getNodeData().getTaxonomy().getIdentifier().getValue().equals( "12345" ) ) {
12515 System.out.println( n9.toString() );
12518 final PhylogenyNode n10x = PhylogenyNode
12519 .createInstanceFromNhxString( "BLAG_12X45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12520 if ( n10x.getNodeData().isHasTaxonomy() ) {
12521 System.out.println( n10x.toString() );
12524 final PhylogenyNode n10xx = PhylogenyNode
12525 .createInstanceFromNhxString( "BLAG_1YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12526 if ( n10xx.getNodeData().isHasTaxonomy() ) {
12527 System.out.println( n10xx.toString() );
12530 final PhylogenyNode n10 = PhylogenyNode
12531 .createInstanceFromNhxString( "BLAG_9YX45-blag", NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
12532 if ( !n10.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9YX45" ) ) {
12533 System.out.println( n10.toString() );
12536 final PhylogenyNode n11 = PhylogenyNode
12537 .createInstanceFromNhxString( "BLAG_Mus_musculus", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12538 if ( !n11.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12539 System.out.println( n11.toString() );
12542 final PhylogenyNode n12 = PhylogenyNode
12543 .createInstanceFromNhxString( "BLAG_Mus_musculus_musculus",
12544 NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12545 if ( !n12.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12546 System.out.println( n12.toString() );
12549 final PhylogenyNode n13 = PhylogenyNode
12550 .createInstanceFromNhxString( "BLAG_Mus_musculus1", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12551 if ( n13.getNodeData().isHasTaxonomy() ) {
12552 System.out.println( n13.toString() );
12555 final PhylogenyNode n14 = PhylogenyNode
12556 .createInstanceFromNhxString( "Mus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12557 if ( !n14.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12558 System.out.println( n14.toString() );
12561 final PhylogenyNode n15 = PhylogenyNode
12562 .createInstanceFromNhxString( "Mus_musculus_K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12563 if ( !n15.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12564 System.out.println( n15.toString() );
12567 final PhylogenyNode n16 = PhylogenyNode
12568 .createInstanceFromNhxString( "Mus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12569 if ( !n16.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12570 System.out.println( n16.toString() );
12573 final PhylogenyNode n17 = PhylogenyNode
12574 .createInstanceFromNhxString( "Mus musculus K392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12575 if ( !n17.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus" ) ) {
12576 System.out.println( n17.toString() );
12579 final PhylogenyNode n18 = PhylogenyNode
12580 .createInstanceFromNhxString( "Mus_musculus_musculus_392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12581 if ( !n18.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12582 System.out.println( n18.toString() );
12585 final PhylogenyNode n19 = PhylogenyNode
12586 .createInstanceFromNhxString( "Mus_musculus_musculus_K392",
12587 NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12588 if ( !n19.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12589 System.out.println( n19.toString() );
12592 final PhylogenyNode n20 = PhylogenyNode
12593 .createInstanceFromNhxString( "Mus musculus musculus 392", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12594 if ( !n20.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12595 System.out.println( n20.toString() );
12598 final PhylogenyNode n21 = PhylogenyNode
12599 .createInstanceFromNhxString( "Mus musculus musculus K392",
12600 NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12601 if ( !n21.getNodeData().getTaxonomy().getScientificName().equals( "Mus musculus musculus" ) ) {
12602 System.out.println( n21.toString() );
12605 final PhylogenyNode n23 = PhylogenyNode
12606 .createInstanceFromNhxString( "9EMVE_Nematostella_vectensis",
12607 NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12608 if ( !n23.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12609 System.out.println( n23.toString() );
12612 final PhylogenyNode n24 = PhylogenyNode
12613 .createInstanceFromNhxString( "9EMVE_Nematostella", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12614 if ( !n24.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12615 System.out.println( n24.toString() );
12619 final PhylogenyNode n25 = PhylogenyNode
12620 .createInstanceFromNhxString( "Nematostella_vectensis_NEMVE",
12621 NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12622 if ( !n25.getNodeData().getTaxonomy().getTaxonomyCode().equals( "NEMVE" ) ) {
12623 System.out.println( n25.toString() );
12626 final PhylogenyNode n26 = PhylogenyNode
12627 .createInstanceFromNhxString( "Nematostella_vectensis_9EMVE",
12628 NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12629 if ( !n26.getNodeData().getTaxonomy().getScientificName().equals( "Nematostella vectensis" ) ) {
12630 System.out.println( n26.toString() );
12633 final PhylogenyNode n27 = PhylogenyNode
12634 .createInstanceFromNhxString( "Nematostella_9EMVE", NHXParser.TAXONOMY_EXTRACTION.AGGRESSIVE );
12635 if ( !n27.getNodeData().getTaxonomy().getTaxonomyCode().equals( "9EMVE" ) ) {
12636 System.out.println( n27.toString() );
12640 catch ( final Exception e ) {
12641 e.printStackTrace( System.out );
12647 private static boolean testTreeCopy() {
12649 final String str_0 = "((((a,b),c),d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=animals]";
12650 final Phylogeny t0 = Phylogeny.createInstanceFromNhxString( str_0 );
12651 final Phylogeny t1 = t0.copy();
12652 if ( !t1.toNewHampshireX().equals( t0.toNewHampshireX() ) ) {
12655 if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12658 t0.deleteSubtree( t0.getNode( "c" ), true );
12659 t0.deleteSubtree( t0.getNode( "a" ), true );
12660 t0.getRoot().getNodeData().getTaxonomy().setScientificName( "metazoa" );
12661 t0.getNode( "b" ).setName( "Bee" );
12662 if ( !t0.toNewHampshireX().equals( "((Bee,d)[&&NHX:S=lizards],e[&&NHX:S=reptiles])r[&&NHX:S=metazoa]" ) ) {
12665 if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12668 t0.deleteSubtree( t0.getNode( "e" ), true );
12669 t0.deleteSubtree( t0.getNode( "Bee" ), true );
12670 t0.deleteSubtree( t0.getNode( "d" ), true );
12671 if ( !t1.toNewHampshireX().equals( str_0 ) ) {
12675 catch ( final Exception e ) {
12676 e.printStackTrace();
12682 private static boolean testTreeMethods() {
12684 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
12685 final Phylogeny t0 = factory.create( "((((A,B)ab,C)abc,D)abcd,E)", new NHXParser() )[ 0 ];
12686 PhylogenyMethods.collapseSubtreeStructure( t0.getNode( "abcd" ) );
12687 if ( !t0.toNewHampshireX().equals( "((A,B,C,D)abcd,E)" ) ) {
12688 System.out.println( t0.toNewHampshireX() );
12691 final Phylogeny t1 = factory.create( "((((A:0.1,B)ab:0.2,C)abc:0.3,D)abcd:0.4,E)", new NHXParser() )[ 0 ];
12692 PhylogenyMethods.collapseSubtreeStructure( t1.getNode( "abcd" ) );
12693 if ( !isEqual( t1.getNode( "A" ).getDistanceToParent(), 0.6 ) ) {
12696 if ( !isEqual( t1.getNode( "B" ).getDistanceToParent(), 0.5 ) ) {
12699 if ( !isEqual( t1.getNode( "C" ).getDistanceToParent(), 0.3 ) ) {
12703 catch ( final Exception e ) {
12704 e.printStackTrace( System.out );
12710 private static boolean testUniprotEntryRetrieval() {
12712 final SequenceDatabaseEntry entry = SequenceDbWsTools.obtainUniProtEntry( "P12345", 5000 );
12713 if ( !entry.getAccession().equals( "P12345" ) ) {
12716 if ( !entry.getTaxonomyScientificName().equals( "Oryctolagus cuniculus" ) ) {
12719 if ( !entry.getSequenceName().equals( "Aspartate aminotransferase, mitochondrial" ) ) {
12722 if ( !entry.getSequenceSymbol().equals( "mAspAT" ) ) {
12725 if ( !entry.getGeneName().equals( "GOT2" ) ) {
12728 if ( !entry.getTaxonomyIdentifier().equals( "9986" ) ) {
12731 if ( entry.getMolecularSequence() == null ) {
12735 .getMolecularSequence()
12736 .getMolecularSequenceAsString()
12737 .startsWith( "MALLHSARVLSGVASAFHPGLAAAASARASSWWAHVEMGPPDPILGVTEAYKRDTNSKKMNLGVGAYRDDNGKPYVLPSVRKAEAQIAAKGLDKEYLPIGGLAEFCRASAELALGENSEV" )
12738 || !entry.getMolecularSequence().getMolecularSequenceAsString().endsWith( "LAHAIHQVTK" ) ) {
12739 System.out.println( "got: " + entry.getMolecularSequence().getMolecularSequenceAsString() );
12740 System.out.println( "expected something else." );
12744 catch ( final IOException e ) {
12745 System.out.println();
12746 System.out.println( "the following might be due to absence internet connection:" );
12747 e.printStackTrace( System.out );
12750 catch ( final NullPointerException f ) {
12751 f.printStackTrace( System.out );
12754 catch ( final Exception e ) {
12760 private static boolean testUniprotTaxonomySearch() {
12762 List<UniProtTaxonomy> results = SequenceDbWsTools.getTaxonomiesFromCommonNameStrict( "starlet sea anemone",
12764 if ( results.size() != 1 ) {
12767 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12770 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12773 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12776 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12779 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12783 results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Nematostella vectensis", 10 );
12784 if ( results.size() != 1 ) {
12787 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12790 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12793 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12796 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12799 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12803 results = SequenceDbWsTools.getTaxonomiesFromId( "45351", 10 );
12804 if ( results.size() != 1 ) {
12807 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12810 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12813 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12816 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12819 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12823 results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "NEMVE", 10 );
12824 if ( results.size() != 1 ) {
12827 if ( !results.get( 0 ).getCode().equals( "NEMVE" ) ) {
12830 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "starlet sea anemone" ) ) {
12833 if ( !results.get( 0 ).getId().equalsIgnoreCase( "45351" ) ) {
12836 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12839 if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
12842 if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
12845 if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
12848 if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12849 .equals( "Nematostella vectensis" ) ) {
12850 System.out.println( results.get( 0 ).getLineage() );
12855 results = SequenceDbWsTools.getTaxonomiesFromScientificNameStrict( "Xenopus tropicalis", 10 );
12856 if ( results.size() != 1 ) {
12859 if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12862 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12865 if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12868 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12871 if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12874 if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12875 .equals( "Xenopus tropicalis" ) ) {
12876 System.out.println( results.get( 0 ).getLineage() );
12881 results = SequenceDbWsTools.getTaxonomiesFromId( "8364", 10 );
12882 if ( results.size() != 1 ) {
12885 if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12888 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12891 if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12894 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12897 if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12900 if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12901 .equals( "Xenopus tropicalis" ) ) {
12902 System.out.println( results.get( 0 ).getLineage() );
12907 results = SequenceDbWsTools.getTaxonomiesFromTaxonomyCode( "XENTR", 10 );
12908 if ( results.size() != 1 ) {
12911 if ( !results.get( 0 ).getCode().equals( "XENTR" ) ) {
12914 if ( !results.get( 0 ).getCommonName().equalsIgnoreCase( "Western clawed frog" ) ) {
12917 if ( !results.get( 0 ).getId().equalsIgnoreCase( "8364" ) ) {
12920 if ( !results.get( 0 ).getRank().equalsIgnoreCase( "species" ) ) {
12923 if ( !results.get( 0 ).getScientificName().equals( "Xenopus tropicalis" ) ) {
12926 if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
12927 .equals( "Xenopus tropicalis" ) ) {
12928 System.out.println( results.get( 0 ).getLineage() );
12932 catch ( final IOException e ) {
12933 System.out.println();
12934 System.out.println( "the following might be due to absence internet connection:" );
12935 e.printStackTrace( System.out );
12938 catch ( final Exception e ) {