2 // forester -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2010 Christian M. Zmasek
6 // Copyright (C) 2008-2010 Burnham Institute for Medical Research
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 // Contact: phylosoft @ gmail . com
23 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
25 package org.forester.archaeopteryx.webservices;
27 import java.util.ArrayList;
28 import java.util.List;
30 import org.forester.archaeopteryx.webservices.WebservicesManager.WsPhylogenyFormat;
31 import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException;
32 import org.forester.phylogeny.Phylogeny;
33 import org.forester.phylogeny.PhylogenyMethods;
34 import org.forester.phylogeny.PhylogenyNode;
35 import org.forester.phylogeny.data.Accession;
36 import org.forester.phylogeny.data.Identifier;
37 import org.forester.phylogeny.data.Sequence;
38 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
39 import org.forester.phylogeny.iterators.PreorderTreeIterator;
40 import org.forester.util.ForesterUtil;
42 public final class WebserviceUtil {
44 public static final String TREE_FAM_INST = "tree_fam";
45 public static final String PFAM_INST = "pfam";
46 public static final String TOL_WEBSERVER = "http://tolweb.org/onlinecontributors/app?service=external&page=xml/TreeStructureService&node_id="
47 + PhylogeniesWebserviceClient.QUERY_PLACEHOLDER;
48 public static final String TOL_NAME = "Tree of Life";
49 public static final String TREE_BASE_NAME = "TreeBASE";
50 public static final String TREE_FAM_NAME = "TreeFam";
51 public static final String PFAM_NAME = "Pfam";
52 public static final String PFAM_SERVER = "http://pfam.janelia.org";
54 public static List<PhylogeniesWebserviceClient> createDefaultClients() {
55 final List<PhylogeniesWebserviceClient> clients = new ArrayList<PhylogeniesWebserviceClient>();
56 clients.add( new BasicPhylogeniesWebserviceClient( TOL_NAME,
57 "Read Tree from Tree of Life...",
58 "Use ToL webservice to obtain a evolutionary tree",
59 "Please enter a Tree of Life node identifier\n(Examples: "
60 + "19386 for Cephalopoda, 2461 for Cnidaria, 2466 for Deuterostomia)",
61 WsPhylogenyFormat.TOL_XML_RESPONSE,
62 PhylogenyMethods.PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME,
63 WebserviceUtil.TOL_WEBSERVER,
67 clients.add( new BasicPhylogeniesWebserviceClient( TREE_BASE_NAME,
68 "Read Tree from TreeBASE...",
69 "Use TreeBASE to obtain a evolutionary tree",
70 "Please enter a TreeBASE tree identifier\n(Examples: 2654, 825, 4931, 2518, 2406, 4934)",
71 WsPhylogenyFormat.TREEBASE,
73 "http://purl.org/phylo/treebase/phylows/tree/TB2:Tr"
74 + PhylogeniesWebserviceClient.QUERY_PLACEHOLDER
77 "http://www.treebase.org",
79 clients.add( new BasicPhylogeniesWebserviceClient( PFAM_NAME,
80 "Read Gene Tree from Pfam...",
81 "Use Pfam to obtain gene trees for seed alignments",
82 "Please enter a Pfam (PF) accession number\n(Examples: 01849 for NAC, 00452 for Bcl-2, 00046 for Homeobox)",
83 WsPhylogenyFormat.PFAM,
85 PFAM_SERVER + "/family/PF"
86 + PhylogeniesWebserviceClient.QUERY_PLACEHOLDER
91 clients.add( new BasicPhylogeniesWebserviceClient( TREE_FAM_NAME,
92 "Read Gene Tree from TreeFam...",
93 "Use TreeFam to obtain a gene tree",
94 "Please enter a TreeFam (TF) accession number\n(Examples: 101004 for Cyclin D, 315938 for Hox, 105310 for Wnt)",
95 WsPhylogenyFormat.NHX,
97 "http://www.treefam.org/family/TF"
98 + PhylogeniesWebserviceClient.QUERY_PLACEHOLDER
101 "http://www.treefam.org",
106 static void extractSpTremblAccFromNodeName( final Phylogeny phy, final String source ) {
107 final PreorderTreeIterator it = new PreorderTreeIterator( phy );
108 while ( it.hasNext() ) {
109 final PhylogenyNode n = it.next();
110 if ( !ForesterUtil.isEmpty( n.getName() ) ) {
111 final String name = n.getName();
112 final int i = name.lastIndexOf( "/" );
114 final String acc_str = name.substring( 0, i );
115 if ( !ForesterUtil.isEmpty( acc_str ) ) {
116 final Sequence seq = new Sequence();
117 final Accession acc = new Accession( acc_str, source );
118 seq.setAccession( acc );
119 n.getNodeData().setSequence( seq );
126 public static void processInstructions( final PhylogeniesWebserviceClient client, final Phylogeny phylogeny )
127 throws PhyloXmlDataFormatException {
128 if ( client.getProcessingInstructions().equals( WebserviceUtil.TREE_FAM_INST ) ) {
130 WebserviceUtil.processTreeFamTrees( phylogeny );
132 else if ( client.getProcessingInstructions().equals( WebserviceUtil.PFAM_INST ) ) {
133 WebserviceUtil.extractSpTremblAccFromNodeName( phylogeny, "sptrembl" );
134 PhylogenyMethods.transferInternalNodeNamesToConfidence( phylogeny, "bootstrap" ); }
137 static void processTreeFamTrees( final Phylogeny phy ) {
138 final PhylogenyNodeIterator it = phy.iteratorPostorder();
139 while ( it.hasNext() ) {
140 final PhylogenyNode n = it.next();
141 if ( n.isExternal() ) {
142 n.getNodeData().setEvent( null );
145 if ( n.getNodeData().isHasTaxonomy() && ( n.getNodeData().getTaxonomy().getIdentifier() != null ) ) {
148 .setIdentifier( new Identifier( n.getNodeData().getTaxonomy().getIdentifier().getValue(), "ncbi" ) );