| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 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 |
|
|
| 46 |
|
|
| 47 |
|
@author |
| 48 |
|
|
| 49 |
|
@version |
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| |
|
| 0% |
Uncovered Elements: 43 (43) |
Complexity: 14 |
Complexity Density: 0.47 |
|
| 58 |
|
public class Annotate3D |
| 59 |
|
{ |
| 60 |
|
|
| 61 |
|
|
| 62 |
|
private static String twoDtoolsURL = "http://arn-ibmc.in2p3.fr/api/compute/2d?tool=rnaview"; |
| 63 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 64 |
0 |
private static ContentHandler createContentHandler()... |
| 65 |
|
{ |
| 66 |
0 |
ContentHandler ch = new ContentHandler() |
| 67 |
|
{ |
| 68 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 69 |
0 |
@Override... |
| 70 |
|
public void startJSON() throws ParseException, IOException |
| 71 |
|
{ |
| 72 |
|
|
| 73 |
|
|
| 74 |
|
} |
| 75 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 76 |
0 |
@Override... |
| 77 |
|
public void endJSON() throws ParseException, IOException |
| 78 |
|
{ |
| 79 |
|
|
| 80 |
|
|
| 81 |
|
} |
| 82 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 83 |
0 |
@Override... |
| 84 |
|
public boolean startObject() throws ParseException, IOException |
| 85 |
|
{ |
| 86 |
|
|
| 87 |
0 |
return false; |
| 88 |
|
} |
| 89 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 90 |
0 |
@Override... |
| 91 |
|
public boolean endObject() throws ParseException, IOException |
| 92 |
|
{ |
| 93 |
|
|
| 94 |
0 |
return false; |
| 95 |
|
} |
| 96 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 97 |
0 |
@Override... |
| 98 |
|
public boolean startObjectEntry(String key) |
| 99 |
|
throws ParseException, IOException |
| 100 |
|
{ |
| 101 |
|
|
| 102 |
0 |
return false; |
| 103 |
|
} |
| 104 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 105 |
0 |
@Override... |
| 106 |
|
public boolean endObjectEntry() throws ParseException, IOException |
| 107 |
|
{ |
| 108 |
|
|
| 109 |
0 |
return false; |
| 110 |
|
} |
| 111 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 112 |
0 |
@Override... |
| 113 |
|
public boolean startArray() throws ParseException, IOException |
| 114 |
|
{ |
| 115 |
|
|
| 116 |
0 |
return false; |
| 117 |
|
} |
| 118 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 119 |
0 |
@Override... |
| 120 |
|
public boolean endArray() throws ParseException, IOException |
| 121 |
|
{ |
| 122 |
|
|
| 123 |
0 |
return false; |
| 124 |
|
} |
| 125 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 126 |
0 |
@Override... |
| 127 |
|
public boolean primitive(Object value) |
| 128 |
|
throws ParseException, IOException |
| 129 |
|
{ |
| 130 |
|
|
| 131 |
0 |
return false; |
| 132 |
|
} |
| 133 |
|
|
| 134 |
|
}; |
| 135 |
0 |
return ch; |
| 136 |
|
} |
| 137 |
|
|
| |
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
| 138 |
0 |
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 |
|
|
| 146 |
|
|
| 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 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 155 |
0 |
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 |
|
|
| |
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
| 172 |
0 |
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 |
|
|
| 182 |
|
|
| 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 |
|
|
| |
|
| 0% |
Uncovered Elements: 27 (27) |
Complexity: 10 |
Complexity Density: 0.62 |
|
| 190 |
|
class RvalsIterator implements Iterator, AutoCloseable |
| 191 |
|
{ |
| 192 |
|
private Iterator<Object> rvals; |
| 193 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 194 |
0 |
@SuppressWarnings("unchecked")... |
| 195 |
|
protected RvalsIterator(Reader respons) throws IOException, ParseException |
| 196 |
|
{ |
| 197 |
|
|
| 198 |
|
|
| 199 |
|
|
| 200 |
|
|
| 201 |
|
|
| 202 |
|
|
| 203 |
|
|
| 204 |
|
|
| 205 |
|
|
| 206 |
0 |
this.rvals = ((List<Object>) JSONUtils.parse(respons)).iterator(); |
| 207 |
|
} |
| 208 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 209 |
0 |
@Override... |
| 210 |
|
public boolean hasNext() |
| 211 |
|
{ |
| 212 |
0 |
return rvals.hasNext(); |
| 213 |
|
} |
| 214 |
|
|
| |
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.33 |
|
| 215 |
0 |
@Override... |
| 216 |
|
public Reader next() |
| 217 |
|
{ |
| 218 |
|
|
| 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 |
|
|
| 240 |
|
|
| 241 |
|
|
| 242 |
|
|
| 243 |
0 |
return new StringReader(sval.toString()); |
| 244 |
|
|
| 245 |
|
} |
| 246 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 247 |
0 |
@Override... |
| 248 |
|
public void remove() |
| 249 |
|
{ |
| 250 |
0 |
throw new Error( |
| 251 |
|
MessageManager.getString("error.not_implemented_remove")); |
| 252 |
|
|
| 253 |
|
} |
| 254 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 255 |
0 |
@Override... |
| 256 |
|
protected Object clone() throws CloneNotSupportedException |
| 257 |
|
{ |
| 258 |
0 |
throw new CloneNotSupportedException( |
| 259 |
|
MessageManager.getString("error.not_implemented_clone")); |
| 260 |
|
} |
| 261 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 262 |
0 |
@Override... |
| 263 |
|
public boolean equals(Object obj) |
| 264 |
|
{ |
| 265 |
0 |
return super.equals(obj); |
| 266 |
|
} |
| 267 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 268 |
0 |
@Override... |
| 269 |
|
public void close() |
| 270 |
|
{ |
| 271 |
0 |
while (rvals.hasNext()) |
| 272 |
|
{ |
| 273 |
0 |
rvals.next(); |
| 274 |
|
} |
| 275 |
|
} |
| 276 |
|
} |