From e3360786172820521b5f7f4f0af14846930d8666 Mon Sep 17 00:00:00 2001 From: "cmzmasek@gmail.com" Date: Tue, 8 Apr 2014 19:03:56 +0000 Subject: [PATCH] inprogress --- .../archaeopteryx/webservices/WebserviceUtil.java | 38 +-- .../evoinference/TestPhylogenyReconstruction.java | 5 +- forester/java/src/org/forester/test/Test.java | 318 +++++++++++++------- 3 files changed, 231 insertions(+), 130 deletions(-) diff --git a/forester/java/src/org/forester/archaeopteryx/webservices/WebserviceUtil.java b/forester/java/src/org/forester/archaeopteryx/webservices/WebserviceUtil.java index 5efee81..ea6ff4f 100644 --- a/forester/java/src/org/forester/archaeopteryx/webservices/WebserviceUtil.java +++ b/forester/java/src/org/forester/archaeopteryx/webservices/WebserviceUtil.java @@ -43,25 +43,29 @@ import org.forester.util.SequenceAccessionTools; public final class WebserviceUtil { - public static final String PFAM_INST = "pfam"; - public static final String PFAM_NAME = "Pfam"; - public static final String PFAM_SERVER = "http://pfam.janelia.org"; - public static final String TOL_NAME = "Tree of Life"; - public static final String TOL_WEBSERVER = "http://tolweb.org/onlinecontributors/app?service=external&page=xml/TreeStructureService&node_id=" - + PhylogeniesWebserviceClient.QUERY_PLACEHOLDER; - public static final String TREE_BASE_DESC = "This data set was downloaded from TreeBASE, a relational database of phylogenetic knowledge. TreeBASE has been supported by the NSF, Harvard University, Yale University, SDSC and UC Davis. Please do not remove this acknowledgment."; - public static final String TREE_BASE_INST = "treebase"; - public static final String TREE_BASE_NAME = "TreeBASE"; - public static final String TREE_FAM_INST = "tree_fam"; - public static final String TREE_FAM_NAME = "TreeFam"; + public static final String PFAM_INST = "pfam"; + public static final String PFAM_NAME = "Pfam"; + public static final String PFAM_SERVER = "http://pfam.janelia.org"; + public static final String TOL_NAME = "Tree of Life (ToL)"; + public static final String TOL_URL_BASE = "http://tolweb.org/onlinecontributors/app?service=external&page=xml/TreeStructureService&node_id="; + public static final String TOL_WEBSERVER = TOL_URL_BASE + + PhylogeniesWebserviceClient.QUERY_PLACEHOLDER; + public static final String TREE_BASE_DESC = "This data set was downloaded from TreeBASE, a relational database of phylogenetic knowledge. TreeBASE has been supported by the NSF, Harvard University, Yale University, SDSC and UC Davis. Please do not remove this acknowledgment."; + public static final String TREE_BASE_INST = "treebase"; + public static final String TREE_BASE_NAME = "TreeBASE"; + public static final String TREE_FAM_INST = "tree_fam"; + public static final String TREE_FAM_NAME = "TreeFam"; + public static final String TREE_FAM_URL_BASE = "http://www.treefam.org/family/TF"; + public static final String TREEBASE_PHYLOWS_STUDY_URL_BASE = "http://purl.org/phylo/treebase/phylows/study/TB2:S"; + public static final String TREEBASE_PHYLOWS_TREE_URL_BASE = "http://purl.org/phylo/treebase/phylows/tree/TB2:Tr"; public static List createDefaultClients() { final List clients = new ArrayList(); clients.add( new BasicPhylogeniesWebserviceClient( TOL_NAME, - "Read Tree from Tree of Life...", + "Read Tree from Tree of Life (ToL)...", "Use ToL webservice to obtain a evolutionary tree", "Please enter a Tree of Life node identifier\n(Examples: " - + "19386 for Cephalopoda, 2461 for Cnidaria, 2466 for Deuterostomia)", + + "14923 for ray-finned fishes, 19386 for Cephalopoda, 2461 for Cnidaria)", WsPhylogenyFormat.TOL_XML_RESPONSE, PhylogenyMethods.PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME, WebserviceUtil.TOL_WEBSERVER, @@ -69,12 +73,12 @@ public final class WebserviceUtil { "http://tolweb.org", null ) ); clients.add( new BasicPhylogeniesWebserviceClient( TREE_BASE_NAME, - "Read Tree(s) from TreeBASE Study...", + "Read Tree(s) from TreeBASE study...", "Use TreeBASE to obtain evolutionary tree(s) from a study", "Please enter a TreeBASE study (\"S\") identifier (without the \"S\")\n(Examples: 15613, 15632, 14525, 14909)", WsPhylogenyFormat.TREEBASE_STUDY, null, - "http://purl.org/phylo/treebase/phylows/study/TB2:S" + TREEBASE_PHYLOWS_STUDY_URL_BASE + PhylogeniesWebserviceClient.QUERY_PLACEHOLDER + "?format=nexus", true, @@ -86,7 +90,7 @@ public final class WebserviceUtil { "Please enter a TreeBASE tree (\"Tr\") identifier (without the \"Tr\")\n(Examples: 422, 2654, 825, 4931, 2518, 2406, 4934)", WsPhylogenyFormat.TREEBASE_TREE, null, - "http://purl.org/phylo/treebase/phylows/tree/TB2:Tr" + TREEBASE_PHYLOWS_TREE_URL_BASE + PhylogeniesWebserviceClient.QUERY_PLACEHOLDER + "?format=nexus", true, @@ -110,7 +114,7 @@ public final class WebserviceUtil { "Please enter a TreeFam (TF) accession number\n(Examples: 101004 for Cyclin D, 315938 for Hox, 105310 for Wnt)", WsPhylogenyFormat.NHX, null, - "http://www.treefam.org/family/TF" + TREE_FAM_URL_BASE + PhylogeniesWebserviceClient.QUERY_PLACEHOLDER + "/tree/newick", true, diff --git a/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java b/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java index 71f418a..52d97d3 100644 --- a/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java +++ b/forester/java/src/org/forester/evoinference/TestPhylogenyReconstruction.java @@ -34,7 +34,6 @@ import java.util.Date; import java.util.List; import java.util.Set; -import org.forester.archaeopteryx.Archaeopteryx; import org.forester.evoinference.distance.NeighborJoining; import org.forester.evoinference.distance.NeighborJoiningF; import org.forester.evoinference.distance.NeighborJoiningR; @@ -2082,7 +2081,7 @@ public class TestPhylogenyReconstruction { //NeighborJoiningR njr = NeighborJoiningR.createInstance( true, 6 ); nj = NeighborJoining.createInstance( true, 6 ); final Phylogeny p2 = nj.execute( m ); - Archaeopteryx.createApplication( p2 ); + //Archaeopteryx.createApplication( p2 ); p2.reRoot( p2.getNode( "Bovine" ) ); if ( isUnequal( p2.getNode( "Chimp" ).getDistanceToParent(), 0.151675 ) ) { return false; @@ -2629,7 +2628,7 @@ public class TestPhylogenyReconstruction { m2.setRow( "1.59050 1.46290 0.55830 0.47100 0.30830 0.26920 0.00000", 6 ); final NeighborJoiningR nj2 = NeighborJoiningR.createInstance( true, 6 ); final Phylogeny p2 = nj2.execute( m2 ); - Archaeopteryx.createApplication( p2 ); + // Archaeopteryx.createApplication( p2 ); p2.reRoot( p2.getNode( "Bovine" ) ); if ( isUnequal( p2.getNode( "Chimp" ).getDistanceToParent(), 0.151675 ) ) { System.out.println( p2.getNode( "Chimp" ).getDistanceToParent() ); diff --git a/forester/java/src/org/forester/test/Test.java b/forester/java/src/org/forester/test/Test.java index a7a7c8c..8f32df5 100644 --- a/forester/java/src/org/forester/test/Test.java +++ b/forester/java/src/org/forester/test/Test.java @@ -41,6 +41,7 @@ import java.util.SortedSet; import org.forester.application.support_transfer; import org.forester.archaeopteryx.TreePanelUtil; +import org.forester.archaeopteryx.webservices.WebserviceUtil; import org.forester.development.DevelopmentTools; import org.forester.evoinference.TestPhylogenyReconstruction; import org.forester.evoinference.matrix.character.CharacterStateMatrix; @@ -135,6 +136,7 @@ public final class Test { + ForesterUtil.getFileSeparator() + "test_data" + ForesterUtil.getFileSeparator(); private final static boolean PERFORM_DB_TESTS = false; + private static final boolean PERFORM_WEB_TREE_ACCESS = true; private static final String PHYLOXML_LOCAL_XSD = PATH_TO_RESOURCES + "phyloxml_schema/" + ForesterConstants.PHYLO_XML_VERSION + "/" + ForesterConstants.PHYLO_XML_XSD; @@ -256,31 +258,6 @@ public final class Test { System.out.println( "failed." ); failed++; } - if ( PERFORM_DB_TESTS ) { - System.out.print( "Ebi Entry Retrieval: " ); - if ( Test.testEbiEntryRetrieval() ) { - System.out.println( "OK." ); - succeeded++; - } - else { - System.out.println( "failed." ); - failed++; - } - } - // System.exit( 0 ); - if ( PERFORM_DB_TESTS ) { - System.out.print( "Sequence DB tools 2: " ); - if ( testSequenceDbWsTools2() ) { - System.out.println( "OK." ); - succeeded++; - } - else { - System.out.println( "failed." ); - failed++; - System.exit( -1 ); - } - } - // System.exit( 0 ); System.out.print( "Hmmscan output parser: " ); if ( testHmmscanOutputParser() ) { System.out.println( "OK." ); @@ -290,7 +267,6 @@ public final class Test { System.out.println( "failed." ); failed++; } - // System.out.print( "Overlap removal: " ); if ( !org.forester.test.Test.testOverlapRemoval() ) { System.out.println( "failed." ); @@ -309,7 +285,6 @@ public final class Test { succeeded++; } System.out.println( "OK." ); - // System.out.print( "Taxonomy code extraction: " ); if ( Test.testExtractTaxonomyCodeFromNodeName() ) { System.out.println( "OK." ); @@ -880,29 +855,6 @@ public final class Test { System.out.println( "failed." ); failed++; } - if ( PERFORM_DB_TESTS ) { - System.out.print( "Uniprot Entry Retrieval: " ); - if ( Test.testUniprotEntryRetrieval() ) { - System.out.println( "OK." ); - succeeded++; - } - else { - System.out.println( "failed." ); - failed++; - } - } - if ( PERFORM_DB_TESTS ) { - System.out.print( "Uniprot Taxonomy Search: " ); - if ( Test.testUniprotTaxonomySearch() ) { - System.out.println( "OK." ); - succeeded++; - } - else { - System.out.println( "failed." ); - failed++; - } - } - //---- String path = ""; final String os = ForesterUtil.OS_NAME.toLowerCase(); if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) { @@ -930,7 +882,6 @@ public final class Test { System.out.println( "failed [will not count towards failed tests]" ); } } - //---- System.out.print( "Next nodes with collapsed: " ); if ( Test.testNextNodeWithCollapsing() ) { System.out.println( "OK." ); @@ -949,32 +900,104 @@ public final class Test { System.out.println( "failed." ); failed++; } - System.out.print( "NHX parsing from URL: " ); - if ( Test.testNHXparsingFromURL() ) { - System.out.println( "OK." ); - succeeded++; - } - else { - System.out.println( "failed." ); - failed++; - } - System.out.print( "phyloXML parsing from URL: " ); - if ( Test.testPhyloXMLparsingFromURL() ) { - System.out.println( "OK." ); - succeeded++; - } - else { - System.out.println( "failed." ); - failed++; - } - System.out.print( "TreeBase parsing from URL: " ); - if ( Test.testTreeBaseReading() ) { - System.out.println( "OK." ); - succeeded++; + if ( PERFORM_DB_TESTS ) { + System.out.print( "Uniprot Entry Retrieval: " ); + if ( Test.testUniprotEntryRetrieval() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } + System.out.print( "Ebi Entry Retrieval: " ); + if ( Test.testEbiEntryRetrieval() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } + System.out.print( "Sequence DB tools 2: " ); + if ( testSequenceDbWsTools2() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + System.exit( -1 ); + } + System.out.print( "Uniprot Taxonomy Search: " ); + if ( Test.testUniprotTaxonomySearch() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } } - else { - System.out.println( "failed." ); - failed++; + if ( PERFORM_WEB_TREE_ACCESS ) { + System.out.print( "NHX parsing from URL: " ); + if ( Test.testNHXparsingFromURL() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } + System.out.print( "phyloXML parsing from URL: " ); + if ( Test.testPhyloXMLparsingFromURL() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } + System.out.print( "TreeBase acccess: " ); + if ( Test.testTreeBaseReading() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } + // + System.out.print( "ToL access: " ); + if ( Test.testToLReading() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } + // + System.out.print( "TreeFam access: " ); + if ( Test.testTreeFamReading() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } + // + // + System.out.print( "Pfam tree access: " ); + if ( Test.testPfamTreeReading() ) { + System.out.println( "OK." ); + succeeded++; + } + else { + System.out.println( "failed." ); + failed++; + } } System.out.println(); final Runtime rt = java.lang.Runtime.getRuntime(); @@ -1093,40 +1116,6 @@ public final class Test { return true; } - public static final boolean testPhyloXMLparsingFromURL() { - try { - final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml"; - final URL u = new URL( s ); - final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); - final Phylogeny[] phys = factory.create( u.openStream(), PhyloXmlParser.createPhyloXmlParser() ); - if ( ( phys == null ) || ( phys.length != 2 ) ) { - return false; - } - } - catch ( final Exception e ) { - e.printStackTrace(); - } - return true; - } - - public static final boolean testTreeBaseReading() { - try { - final String s = "http://purl.org/phylo/treebase/phylows/tree/TB2:Tr825?format=nexus"; - final URL u = new URL( s ); - final NexusPhylogeniesParser parser = new NexusPhylogeniesParser(); - parser.setReplaceUnderscores( true ); - final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); - final Phylogeny[] phys = factory.create( u.openStream(), parser ); - if ( ( phys == null ) || ( phys.length != 1 ) ) { - return false; - } - } - catch ( final Exception e ) { - e.printStackTrace(); - } - return true; - } - public static final boolean testNHXparsingFromURL() { try { final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh"; @@ -1346,6 +1335,115 @@ public final class Test { return true; } + public static final boolean testPfamTreeReading() { + try { + final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" ); + final NHXParser parser = new NHXParser(); + parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT ); + parser.setReplaceUnderscores( false ); + parser.setGuessRootedness( true ); + final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); + final Phylogeny[] phys = factory.create( u.openStream(), parser ); + if ( ( phys == null ) || ( phys.length != 1 ) ) { + return false; + } + if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) { + return false; + } + } + catch ( final Exception e ) { + e.printStackTrace(); + } + return true; + } + + public static final boolean testPhyloXMLparsingFromURL() { + try { + final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml"; + final URL u = new URL( s ); + final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); + final Phylogeny[] phys = factory.create( u.openStream(), PhyloXmlParser.createPhyloXmlParser() ); + if ( ( phys == null ) || ( phys.length != 2 ) ) { + return false; + } + } + catch ( final Exception e ) { + e.printStackTrace(); + } + return true; + } + + public static final boolean testToLReading() { + try { + final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" ); + final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); + final Phylogeny[] phys = factory.create( u.openStream(), new TolParser() ); + if ( ( phys == null ) || ( phys.length != 1 ) ) { + return false; + } + if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getIdentifier().getValue().equals( "15079" ) ) { + return false; + } + if ( !phys[ 0 ].getRoot().getNodeData().getTaxonomy().getScientificName().equals( "Protacanthopterygii" ) ) { + return false; + } + if ( phys[ 0 ].getNumberOfExternalNodes() < 5 ) { + return false; + } + } + catch ( final Exception e ) { + e.printStackTrace(); + } + return true; + } + + public static final boolean testTreeBaseReading() { + try { + final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" ); + final NexusPhylogeniesParser parser = new NexusPhylogeniesParser(); + parser.setReplaceUnderscores( true ); + final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); + final Phylogeny[] phys = factory.create( u.openStream(), parser ); + if ( ( phys == null ) || ( phys.length != 1 ) ) { + return false; + } + final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" ); + final NexusPhylogeniesParser parser2 = new NexusPhylogeniesParser(); + parser2.setReplaceUnderscores( true ); + final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance(); + final Phylogeny[] phys2 = factory2.create( u2.openStream(), parser2 ); + if ( ( phys2 == null ) || ( phys2.length != 9 ) ) { + return false; + } + } + catch ( final Exception e ) { + e.printStackTrace(); + } + return true; + } + + public static final boolean testTreeFamReading() { + try { + final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" ); + final NHXParser parser = new NHXParser(); + parser.setTaxonomyExtraction( NHXParser.TAXONOMY_EXTRACTION.NO ); + parser.setReplaceUnderscores( false ); + parser.setGuessRootedness( true ); + final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); + final Phylogeny[] phys = factory.create( u.openStream(), parser ); + if ( ( phys == null ) || ( phys.length != 1 ) ) { + return false; + } + if ( phys[ 0 ].getNumberOfExternalNodes() < 10 ) { + return false; + } + } + catch ( final Exception e ) { + e.printStackTrace(); + } + return true; + } + private final static Phylogeny createPhylogeny( final String nhx ) throws IOException { final Phylogeny p = ParserBasedPhylogenyFactory.getInstance().create( nhx, new NHXParser() )[ 0 ]; return p; -- 1.7.10.2