package jalview.fts.service.threedbeacons;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
+import org.json.JSONArray;
+import org.json.JSONObject;
+
import jalview.fts.api.FTSDataColumnI;
import jalview.fts.api.FTSRestClientI;
import jalview.fts.core.FTSRestRequest;
public class TDBeaconsFTSPanel extends GFTSPanel
{
private static String defaultFTSFrameTitle = MessageManager
- .getString("label.threedb_sequence_fetcher");
+ .getString("label.pdb_sequence_fetcher");
private static Map<String, Integer> tempUserPrefs = new HashMap<>();
private static final String THREEDB_AUTOSEARCH = "FTS.THREEDB.AUTOSEARCH";
+ private static HttpURLConnection connection;
+
public TDBeaconsFTSPanel(SequenceFetcher fetcher)
{
super(fetcher);
this.progressIndicator = (fetcher == null) ? null
: fetcher.getProgressIndicator();
}
+
+ public int TDBeaconsFTSPanel2(String result)
+ {
+ int seqlength = executeParse(result);
+ return seqlength;
+ }
+
+ public static int executeParse(String query) {
+ BufferedReader reader;
+ String line;
+ StringBuffer responseContent = new StringBuffer();
+ try {
+ URL url = new URL("https://wwwdev.ebi.ac.uk/pdbe/pdbe-kb/3dbeacons-hub-api/uniprot/summary/" + query + ".json");
+ connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("GET");
+ connection.setConnectTimeout(5000); // <=>5seconds
+ connection.setReadTimeout(5000);
+ // Status check up, 200 = connection succesful
+ int status = connection.getResponseCode();
+ // System.out.println(status);
+
+ if (status > 299) {
+ reader = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
+ while ((line = reader.readLine()) != null) {
+ responseContent.append(line);
+ }
+ reader.close();
+ } else {
+ reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+ while ((line = reader.readLine()) != null) {
+ responseContent.append(line);
+ }
+ reader.close();
+ }
+ //System.out.println(responseContent.toString());
+ int seq = parse(responseContent.toString());
+ return seq;
+
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ connection.disconnect();
+ }
+ return (Integer) null;
+
+ }
+
+ public static int parse(String jsonString) {
+ JSONObject entry = new JSONObject(jsonString);
+ System.out.println(entry);
+ int length = entry.getJSONObject("uniprot_entry").getInt("sequence_length");
+ String ac = entry.getJSONObject("uniprot_entry").getString("ac");
+
+ JSONArray structures = entry.getJSONArray("structures");
+ for (int i=0 ; i < structures.length() ; i++) {
+ String id = structures.getJSONObject(i).getString("model_identifier");
+ System.out.println("identifier num " + i + " : " + id);
+ }
+ System.out.println("length : " + length + "; access name : " + ac);
+ return length;
+
+}
@Override
public void searchAction(boolean isFreshSearch)
System.out.println("No help implemented yet.");
}
-
+
+ public static String decodeSearchTerm(String enteredText) {
+ // no multiple query support yet
+ return enteredText;
+ }
}