2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 import java.util.Enumeration;
23 import java.util.Hashtable;
24 import java.util.StringTokenizer;
26 import org.apache.axis.client.*;
27 import org.apache.axis.encoding.XMLType;
29 import javax.xml.namespace.QName;
30 import javax.xml.rpc.ParameterMode;
39 public class EBIFetchClient
42 String format = "default";
46 * Creates a new EBIFetchClient object.
48 public EBIFetchClient()
52 call = (Call) new Service().createCall();
53 call.setTargetEndpointAddress(new java.net.URL(
54 "http://www.ebi.ac.uk/ws/services/Dbfetch"));
64 * @return DOCUMENT ME!
66 public String[] getSupportedDBs()
70 call.setOperationName(new QName("urn:Dbfetch", "getSupportedDBs"));
71 call.setReturnType(XMLType.SOAP_ARRAY);
73 return (String[]) call.invoke(new Object[] { });
84 * @return DOCUMENT ME!
86 public String[] getSupportedFormats()
90 call.setOperationName(new QName("urn:Dbfetch", "getSupportedFormats"));
91 call.setReturnType(XMLType.SOAP_ARRAY);
93 return (String[]) call.invoke(new Object[] { });
104 * @return DOCUMENT ME!
106 public String[] getSupportedStyles()
110 call.setOperationName(new QName("urn:Dbfetch", "getSupportedStyles"));
111 call.setReturnType(XMLType.SOAP_ARRAY);
113 return (String[]) call.invoke(new Object[] { });
121 public static void main (String [] args)
123 EBIFetchClient ebi = new EBIFetchClient();
124 String[] result = ebi.fetchData("uniprot:25KD_SARPE;G6PD_HUMAN",
128 java.io.PrintWriter out = new java.io.PrintWriter(
129 new java.io.FileWriter("out.xml"));
132 for(int i=0; i<result.length; i++)
134 out.println(result[i]);
137 }catch(Exception ex){ex.printStackTrace();}
142 public File fetchDataAsFile(String ids, String f, String s)
144 String [] data = fetchData(ids, f, s);
147 outFile = File.createTempFile("jalview", ".xml");
148 outFile.deleteOnExit();
149 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
151 while( index < data.length )
153 out.println(data[index]);
157 }catch(Exception ex){}
162 * Single DB multiple record retrieval
164 * @param ids db:query1;query2;query3
168 * @return Raw string array result of query set
170 public String[] fetchData(String ids, String f, String s)
173 // ids of the form uniprot:25KD_SARPE;ADHR_DROPS;
175 StringTokenizer queries=new StringTokenizer(ids,";");
177 StringBuffer querystring=null;
178 while (queries.hasMoreTokens()) {
179 String query=queries.nextToken();
181 if ((p=query.indexOf(':'))>-1 && (p+3<query.length())) {
182 db = query.substring(0,p);
183 query = query.substring(p+1);
185 if (querystring==null) {
186 querystring = new StringBuffer(query);
188 querystring.append(","+query);
192 System.err.println("Invalid Query string : '"+ids+"'\nShould be of form 'dbname:q1;q2;q3;q4'");
194 return fetchBatch(querystring.toString(), db, f, s);
196 public String[] fetchBatch(String ids, String db, String f, String s) {
197 // max 50 ids can be added at one time
200 //call.setOperationName(new QName("urn:Dbfetch", "fetchData"));
201 call.setOperationName(new QName("urn:Dbfetch", "fetchBatch"));
202 call.addParameter("ids", XMLType.XSD_STRING, ParameterMode.IN);
203 call.addParameter("db", XMLType.XSD_STRING, ParameterMode.IN);
204 call.addParameter("format", XMLType.XSD_STRING, ParameterMode.IN);
205 call.addParameter("style", XMLType.XSD_STRING, ParameterMode.IN);
206 call.setReturnType(XMLType.SOAP_ARRAY);
219 return (String[]) call.invoke(new Object[]
220 {ids.toLowerCase(), db.toLowerCase(), format, style});
221 }catch(OutOfMemoryError er)
223 System.out.println("OUT OF MEMORY DOWNLOADING QUERY FROM "+db+":\n"+ids);
229 if (ex.getMessage().startsWith("uk.ac.ebi.jdbfetch.exceptions.DbfNoEntryFoundException"))
231 System.err.println("Unexpected exception when retrieving from "+db+"\nQuery was : '"+ids+"'");
232 ex.printStackTrace(System.err);