2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.ws.HttpClientUtils;
25 import java.io.IOException;
26 import java.io.InputStreamReader;
27 import java.io.Reader;
28 import java.io.StringReader;
30 import java.util.ArrayList;
31 import java.util.Collection;
32 import java.util.Iterator;
33 import java.util.List;
35 import org.apache.http.NameValuePair;
36 import org.apache.http.message.BasicNameValuePair;
37 import org.json.simple.JSONArray;
38 import org.json.simple.JSONObject;
39 import org.json.simple.JSONStreamAware;
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 * History: 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
52 public class Annotate3D
54 private static String twoDtoolsURL = "http://arn-ibmc.in2p3.fr/api/compute/2d";
56 private static ContentHandler createContentHandler()
58 ContentHandler ch = new ContentHandler()
62 public void startJSON() throws ParseException, IOException
64 // TODO Auto-generated method stub
69 public void endJSON() throws ParseException, IOException
71 // TODO Auto-generated method stub
76 public boolean startObject() throws ParseException, IOException
78 // TODO Auto-generated method stub
83 public boolean endObject() throws ParseException, IOException
85 // TODO Auto-generated method stub
90 public boolean startObjectEntry(String key) throws ParseException,
93 // TODO Auto-generated method stub
98 public boolean endObjectEntry() throws ParseException, IOException
100 // TODO Auto-generated method stub
105 public boolean startArray() throws ParseException, IOException
107 // TODO Auto-generated method stub
112 public boolean endArray() throws ParseException, IOException
114 // TODO Auto-generated method stub
119 public boolean primitive(Object value) throws ParseException,
122 // TODO Auto-generated method stub
130 public static Iterator<Reader> getRNAMLForPDBFileAsString(String pdbfile)
133 List<NameValuePair> vals = new ArrayList<NameValuePair>();
134 vals.add(new BasicNameValuePair("tool", "rnaview"));
135 vals.add(new BasicNameValuePair("data", pdbfile));
136 vals.add(new BasicNameValuePair("output", "rnaml"));
137 // return processJsonResponseFor(HttpClientUtils.doHttpUrlPost(twoDtoolsURL,
139 ArrayList<Reader> readers = new ArrayList<Reader>();
140 readers.add(HttpClientUtils.doHttpUrlPost(twoDtoolsURL, vals));
141 return readers.iterator();
145 public static Iterator<Reader> processJsonResponseFor(Reader respons)
148 org.json.simple.parser.JSONParser jp = new org.json.simple.parser.JSONParser();
151 final JSONArray responses = (JSONArray) jp.parse(respons);
152 final Iterator rvals = responses.iterator();
153 return new Iterator<Reader>()
156 public boolean hasNext()
158 return rvals.hasNext();
164 JSONObject val = (JSONObject) rvals.next();
169 sval = val.get("2D");
170 } catch (Exception x)
178 .println("DEVELOPER WARNING: Annotate3d didn't return a '2D' tag in its response. Consider checking output of server. Response was :"
183 return new StringReader(
184 (sval instanceof JSONObject) ? ((JSONObject) sval)
185 .toString() : sval.toString());
192 throw new Error("Remove: Not implemented");
197 protected Object clone() throws CloneNotSupportedException
199 throw new CloneNotSupportedException("Clone: Not implemented");
203 public boolean equals(Object obj)
205 return super.equals(obj);
209 protected void finalize() throws Throwable
211 while (rvals.hasNext())
218 } catch (Exception foo)
221 "Couldn't parse response from Annotate3d server.", foo);
226 public static Iterator<Reader> getRNAMLForPDBId(String pdbid)
229 List<NameValuePair> vals = new ArrayList<NameValuePair>();
230 vals.add(new BasicNameValuePair("tool", "rnaview"));
231 vals.add(new BasicNameValuePair("pdbid", pdbid));
232 vals.add(new BasicNameValuePair("output", "rnaml"));
233 java.net.URL geturl = new URL(twoDtoolsURL + "?tool=rnaview&pdbid="
234 + pdbid + "&output=rnaml");
235 // return processJsonResponseFor(new
236 // InputStreamReader(geturl.openStream()));
237 ArrayList<Reader> readers = new ArrayList<Reader>();
238 readers.add(new InputStreamReader(geturl.openStream()));
239 return readers.iterator();