2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ext.paradise;
23 import jalview.util.MessageManager;
24 import jalview.ws.HttpClientUtils;
26 import java.io.BufferedReader;
27 import java.io.IOException;
28 import java.io.InputStreamReader;
29 import java.io.Reader;
30 import java.io.StringReader;
32 import java.util.ArrayList;
33 import java.util.Iterator;
34 import java.util.List;
36 import org.apache.http.NameValuePair;
37 import org.apache.http.message.BasicNameValuePair;
38 import org.json.simple.JSONArray;
39 import org.json.simple.JSONObject;
40 import org.json.simple.parser.ContentHandler;
41 import org.json.simple.parser.ParseException;
44 * simple methods for calling the various paradise RNA tools
48 * @version v1.0 revised from original due to refactoring of
49 * paradise-ubmc.u-strasbg.fr/webservices/annotate3d to
50 * http://arn-ibmc.in2p3.fr/api/compute/2d?tool=rnaview <br/>
51 * See also testing URL from fjossinet:<br/>
52 * http://charn2-ibmc.u-strasbg.fr:8080/api/compute/2d <br/>
53 * If in doubt, check against the REST client at:
54 * https://github.com/fjossinet/RNA-Science
55 * -Toolbox/blob/master/pyrna/restclient.py
57 public class Annotate3D
60 // "http://charn2-ibmc.u-strasbg.fr:8080/api/compute/2d";
61 private static String twoDtoolsURL = "http://arn-ibmc.in2p3.fr/api/compute/2d?tool=rnaview";
63 private static ContentHandler createContentHandler()
65 ContentHandler ch = new ContentHandler()
69 public void startJSON() throws ParseException, IOException
71 // TODO Auto-generated method stub
76 public void endJSON() throws ParseException, IOException
78 // TODO Auto-generated method stub
83 public boolean startObject() throws ParseException, IOException
85 // TODO Auto-generated method stub
90 public boolean endObject() throws ParseException, IOException
92 // TODO Auto-generated method stub
97 public boolean startObjectEntry(String key)
98 throws ParseException, IOException
100 // TODO Auto-generated method stub
105 public boolean endObjectEntry() throws ParseException, IOException
107 // TODO Auto-generated method stub
112 public boolean startArray() throws ParseException, IOException
114 // TODO Auto-generated method stub
119 public boolean endArray() throws ParseException, IOException
121 // TODO Auto-generated method stub
126 public boolean primitive(Object value)
127 throws ParseException, IOException
129 // TODO Auto-generated method stub
137 public static Iterator<Reader> getRNAMLForPDBFileAsString(String pdbfile)
140 List<NameValuePair> vals = new ArrayList<NameValuePair>();
141 vals.add(new BasicNameValuePair("tool", "rnaview"));
142 vals.add(new BasicNameValuePair("data", pdbfile));
143 vals.add(new BasicNameValuePair("output", "rnaml"));
144 // return processJsonResponseFor(HttpClientUtils.doHttpUrlPost(twoDtoolsURL,
146 ArrayList<Reader> readers = new ArrayList<Reader>();
147 final BufferedReader postResponse = HttpClientUtils
148 .doHttpUrlPost(twoDtoolsURL, vals, 0, 0);
149 readers.add(postResponse);
150 return readers.iterator();
154 public static Iterator<Reader> processJsonResponseFor(Reader respons)
157 org.json.simple.parser.JSONParser jp = new org.json.simple.parser.JSONParser();
160 final JSONArray responses = (JSONArray) jp.parse(respons);
161 final Iterator rvals = responses.iterator();
162 return new Iterator<Reader>()
165 public boolean hasNext()
167 return rvals.hasNext();
173 JSONObject val = (JSONObject) rvals.next();
178 sval = val.get("2D");
179 } catch (Exception x)
187 "DEVELOPER WARNING: Annotate3d didn't return a '2D' tag in its response. Consider checking output of server. Response was :"
192 return new StringReader((sval instanceof JSONObject)
193 ? ((JSONObject) sval).toString()
202 MessageManager.getString("error.not_implemented_remove"));
207 protected Object clone() throws CloneNotSupportedException
209 throw new CloneNotSupportedException(
210 MessageManager.getString("error.not_implemented_clone"));
214 public boolean equals(Object obj)
216 return super.equals(obj);
220 protected void finalize() throws Throwable
222 while (rvals.hasNext())
229 } catch (Exception foo)
231 throw new Exception(MessageManager.getString(
232 "exception.couldnt_parse_responde_from_annotated3d_server"),
238 public static Iterator<Reader> getRNAMLForPDBId(String pdbid)
241 List<NameValuePair> vals = new ArrayList<NameValuePair>();
242 vals.add(new BasicNameValuePair("tool", "rnaview"));
243 vals.add(new BasicNameValuePair("pdbid", pdbid));
244 vals.add(new BasicNameValuePair("output", "rnaml"));
245 java.net.URL geturl = new URL(twoDtoolsURL + "?tool=rnaview&pdbid="
246 + pdbid + "&output=rnaml");
247 // return processJsonResponseFor(new
248 // InputStreamReader(geturl.openStream()));
249 ArrayList<Reader> readers = new ArrayList<Reader>();
250 readers.add(new InputStreamReader(geturl.openStream()));
251 return readers.iterator();