Clover icon

Coverage Report

  1. Project Clover database Thu Nov 7 2024 10:11:34 GMT
  2. Package jalview.ext.paradise

File Annotate3D.java

 

Coverage histogram

../../../img/srcFileCovDistChart0.png
60% of files have more coverage

Code metrics

4
46
20
2
276
177
24
0.52
2.3
10
1.2

Classes

Class Line # Actions
Annotate3D 58 30 14
0.00%
RvalsIterator 190 16 10
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.ext.paradise;
22   
23    import java.io.BufferedReader;
24    import java.io.IOException;
25    import java.io.InputStreamReader;
26    import java.io.Reader;
27    import java.io.StringReader;
28    import java.net.URL;
29    import java.util.ArrayList;
30    import java.util.Iterator;
31    import java.util.List;
32    import java.util.Map;
33   
34    import org.apache.http.NameValuePair;
35    import org.apache.http.message.BasicNameValuePair;
36    import org.json.simple.parser.ContentHandler;
37    import org.json.simple.parser.ParseException;
38   
39    import jalview.util.HttpUtils;
40    import jalview.util.JSONUtils;
41    import jalview.util.MessageManager;
42    import jalview.ws.HttpClientUtils;
43   
44    /**
45    * simple methods for calling the various paradise RNA tools
46    *
47    * @author jimp
48    *
49    * @version v1.0 revised from original due to refactoring of
50    * paradise-ubmc.u-strasbg.fr/webservices/annotate3d to
51    * http://arn-ibmc.in2p3.fr/api/compute/2d?tool=rnaview <br/>
52    * See also testing URL from fjossinet:<br/>
53    * http://charn2-ibmc.u-strasbg.fr:8080/api/compute/2d <br/>
54    * If in doubt, check against the REST client at:
55    * https://github.com/fjossinet/RNA-Science
56    * -Toolbox/blob/master/pyrna/restclient.py
57    */
 
58    public class Annotate3D
59    {
60    // also test with
61    // "http://charn2-ibmc.u-strasbg.fr:8080/api/compute/2d";
62    private static String twoDtoolsURL = "http://arn-ibmc.in2p3.fr/api/compute/2d?tool=rnaview";
63   
 
64  0 toggle private static ContentHandler createContentHandler()
65    {
66  0 ContentHandler ch = new ContentHandler()
67    {
68   
 
69  0 toggle @Override
70    public void startJSON() throws ParseException, IOException
71    {
72    // TODO Auto-generated method stub
73   
74    }
75   
 
76  0 toggle @Override
77    public void endJSON() throws ParseException, IOException
78    {
79    // TODO Auto-generated method stub
80   
81    }
82   
 
83  0 toggle @Override
84    public boolean startObject() throws ParseException, IOException
85    {
86    // TODO Auto-generated method stub
87  0 return false;
88    }
89   
 
90  0 toggle @Override
91    public boolean endObject() throws ParseException, IOException
92    {
93    // TODO Auto-generated method stub
94  0 return false;
95    }
96   
 
97  0 toggle @Override
98    public boolean startObjectEntry(String key)
99    throws ParseException, IOException
100    {
101    // TODO Auto-generated method stub
102  0 return false;
103    }
104   
 
105  0 toggle @Override
106    public boolean endObjectEntry() throws ParseException, IOException
107    {
108    // TODO Auto-generated method stub
109  0 return false;
110    }
111   
 
112  0 toggle @Override
113    public boolean startArray() throws ParseException, IOException
114    {
115    // TODO Auto-generated method stub
116  0 return false;
117    }
118   
 
119  0 toggle @Override
120    public boolean endArray() throws ParseException, IOException
121    {
122    // TODO Auto-generated method stub
123  0 return false;
124    }
125   
 
126  0 toggle @Override
127    public boolean primitive(Object value)
128    throws ParseException, IOException
129    {
130    // TODO Auto-generated method stub
131  0 return false;
132    }
133   
134    };
135  0 return ch;
136    }
137   
 
138  0 toggle public static Iterator<Reader> getRNAMLForPDBFileAsString(String pdbfile)
139    throws Exception
140    {
141  0 List<NameValuePair> vals = new ArrayList<>();
142  0 vals.add(new BasicNameValuePair("tool", "rnaview"));
143  0 vals.add(new BasicNameValuePair("data", pdbfile));
144  0 vals.add(new BasicNameValuePair("output", "rnaml"));
145    // return processJsonResponseFor(HttpClientUtils.doHttpUrlPost(twoDtoolsURL,
146    // vals));
147  0 ArrayList<Reader> readers = new ArrayList<>();
148  0 final BufferedReader postResponse = HttpClientUtils
149    .doHttpUrlPost(twoDtoolsURL, vals, 0, 0);
150  0 readers.add(postResponse);
151  0 return readers.iterator();
152   
153    }
154   
 
155  0 toggle public static Iterator<Reader> processJsonResponseFor(Reader respons)
156    throws Exception
157    {
158  0 org.json.simple.parser.JSONParser jp = new org.json.simple.parser.JSONParser();
159  0 try
160    {
161  0 final RvalsIterator rvals = new RvalsIterator(respons);
162  0 return rvals;
163    } catch (Exception foo)
164    {
165  0 throw new Exception(MessageManager.getString(
166    "exception.couldnt_parse_responde_from_annotated3d_server"),
167    foo);
168    }
169   
170    }
171   
 
172  0 toggle public static Iterator<Reader> getRNAMLForPDBId(String pdbid)
173    throws Exception
174    {
175  0 List<NameValuePair> vals = new ArrayList<>();
176  0 vals.add(new BasicNameValuePair("tool", "rnaview"));
177  0 vals.add(new BasicNameValuePair("pdbid", pdbid));
178  0 vals.add(new BasicNameValuePair("output", "rnaml"));
179  0 java.net.URL geturl = new URL(twoDtoolsURL + "?tool=rnaview&pdbid="
180    + pdbid + "&output=rnaml");
181    // return processJsonResponseFor(new
182    // InputStreamReader(geturl.openStream()));
183  0 ArrayList<Reader> readers = new ArrayList<>();
184  0 readers.add(new InputStreamReader(HttpUtils.openStream(geturl)));
185  0 return readers.iterator();
186    }
187   
188    }
189   
 
190    class RvalsIterator implements Iterator, AutoCloseable
191    {
192    private Iterator<Object> rvals;
193   
 
194  0 toggle @SuppressWarnings("unchecked")
195    protected RvalsIterator(Reader respons) throws IOException, ParseException
196    {
197    /*
198    * as in 2.11.1 (pre-JalviewJS)
199    */
200    // final JSONArray responses = (JSONArray) jp.parse(respons);
201    // this.rvals = responses.iterator();
202   
203    /*
204    * as in JalviewJS (with comment that this code is never called)
205    */
206  0 this.rvals = ((List<Object>) JSONUtils.parse(respons)).iterator();
207    }
208   
 
209  0 toggle @Override
210    public boolean hasNext()
211    {
212  0 return rvals.hasNext();
213    }
214   
 
215  0 toggle @Override
216    public Reader next()
217    {
218    // JSONObject val = (JSONObject) rvals.next(); // 2.11.1
219  0 @SuppressWarnings("unchecked")
220    Map<String, Object> val = (Map<String, Object>) rvals.next();
221   
222  0 Object sval = null;
223  0 try
224    {
225  0 sval = val.get("2D");
226    } catch (Exception x)
227    {
228  0 x.printStackTrace();
229    }
230   
231  0 if (sval == null)
232    {
233  0 jalview.bin.Console.errPrintln(
234    "DEVELOPER WARNING: Annotate3d didn't return a '2D' tag in its response. Consider checking output of server. Response was :"
235    + val.toString());
236   
237  0 sval = "";
238    }
239    // 2.11.1:
240    // return new StringReader(
241    // (sval instanceof JSONObject) ? ((JSONObject) sval).toString()
242    // : sval.toString());
243  0 return new StringReader(sval.toString());
244   
245    }
246   
 
247  0 toggle @Override
248    public void remove()
249    {
250  0 throw new Error(
251    MessageManager.getString("error.not_implemented_remove"));
252   
253    }
254   
 
255  0 toggle @Override
256    protected Object clone() throws CloneNotSupportedException
257    {
258  0 throw new CloneNotSupportedException(
259    MessageManager.getString("error.not_implemented_clone"));
260    }
261   
 
262  0 toggle @Override
263    public boolean equals(Object obj)
264    {
265  0 return super.equals(obj);
266    }
267   
 
268  0 toggle @Override
269    public void close()
270    {
271  0 while (rvals.hasNext())
272    {
273  0 rvals.next();
274    }
275    }
276    }