2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 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
23 import javax.xml.namespace.*;
24 import javax.xml.rpc.*;
26 import org.apache.axis.client.Call;
27 import org.apache.axis.client.Service;
28 import org.apache.axis.encoding.*;
36 public class EBIFetchClient
39 String format = "default";
43 * Creates a new EBIFetchClient object.
45 public EBIFetchClient()
49 call = (Call)new Service().createCall();
50 call.setTargetEndpointAddress(new java.net.URL(
51 "http://www.ebi.ac.uk/ws/services/Dbfetch"));
61 * @return DOCUMENT ME!
63 public String[] getSupportedDBs()
67 call.setOperationName(new QName("urn:Dbfetch", "getSupportedDBs"));
68 call.setReturnType(XMLType.SOAP_ARRAY);
70 return (String[]) call.invoke(new Object[]
82 * @return DOCUMENT ME!
84 public String[] getSupportedFormats()
88 call.setOperationName(new QName("urn:Dbfetch", "getSupportedFormats"));
89 call.setReturnType(XMLType.SOAP_ARRAY);
91 return (String[]) call.invoke(new Object[]
103 * @return DOCUMENT ME!
105 public String[] getSupportedStyles()
109 call.setOperationName(new QName("urn:Dbfetch", "getSupportedStyles"));
110 call.setReturnType(XMLType.SOAP_ARRAY);
112 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",
129 java.io.PrintWriter out = new java.io.PrintWriter(
130 new java.io.FileWriter("out.xml"));
132 for (int i = 0; i < result.length; i++)
134 out.println(result[i]);
140 ex.printStackTrace();
145 public File fetchDataAsFile(String ids, String f, String s)
147 String[] data = fetchData(ids, f, s);
151 outFile = File.createTempFile("jalview", ".xml");
152 outFile.deleteOnExit();
153 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
155 while (index < data.length)
157 out.println(data[index]);
168 * Single DB multiple record retrieval
170 * @param ids db:query1;query2;query3
174 * @return Raw string array result of query set
176 public String[] fetchData(String ids, String f, String s)
179 // ids of the form uniprot:25KD_SARPE;ADHR_DROPS;
181 StringTokenizer queries = new StringTokenizer(ids, ";");
183 StringBuffer querystring = null;
184 while (queries.hasMoreTokens())
186 String query = queries.nextToken();
188 if ( (p = query.indexOf(':')) > -1 && (p + 3 < query.length()))
190 db = query.substring(0, p);
191 query = query.substring(p + 1);
193 if (querystring == null)
195 querystring = new StringBuffer(query);
199 querystring.append("," + query);
204 System.err.println("Invalid Query string : '" + ids +
205 "'\nShould be of form 'dbname:q1;q2;q3;q4'");
207 return fetchBatch(querystring.toString(), db, f, s);
210 public String[] fetchBatch(String ids, String db, String f, String s)
212 // max 50 ids can be added at one time
215 //call.setOperationName(new QName("urn:Dbfetch", "fetchData"));
216 call.setOperationName(new QName("urn:Dbfetch", "fetchBatch"));
217 call.addParameter("ids", XMLType.XSD_STRING, ParameterMode.IN);
218 call.addParameter("db", XMLType.XSD_STRING, ParameterMode.IN);
219 call.addParameter("format", XMLType.XSD_STRING, ParameterMode.IN);
220 call.addParameter("style", XMLType.XSD_STRING, ParameterMode.IN);
221 call.setReturnType(XMLType.SOAP_ARRAY);
235 return (String[]) call.invoke(new Object[]
236 {ids.toLowerCase(), db.toLowerCase(),
239 catch (OutOfMemoryError er)
241 System.out.println("OUT OF MEMORY DOWNLOADING QUERY FROM " + db + ":\n" +
248 if (ex.getMessage().startsWith(
249 "uk.ac.ebi.jdbfetch.exceptions.DbfNoEntryFoundException"))
253 System.err.println("Unexpected exception when retrieving from " + db +
254 "\nQuery was : '" + ids + "'");
255 ex.printStackTrace(System.err);