1 package jalview.ext.ensembl;
3 import jalview.datamodel.AlignmentI;
5 import java.io.BufferedReader;
6 import java.io.IOException;
7 import java.net.MalformedURLException;
9 import java.util.Arrays;
10 import java.util.List;
12 import org.json.simple.JSONObject;
13 import org.json.simple.parser.JSONParser;
14 import org.json.simple.parser.ParseException;
16 public class EnsemblLookup extends EnsemblRestClient
20 public String getDbName()
26 public AlignmentI getSequenceRecords(String queries) throws Exception
32 protected URL getUrl(List<String> ids) throws MalformedURLException
34 String identifier = ids.get(0);
35 return getUrl(identifier);
42 protected URL getUrl(String identifier)
44 String url = ENSEMBL_REST + "/lookup/id/" + identifier
45 + "?content-type=application/json";
49 } catch (MalformedURLException e)
56 protected boolean useGetRequest()
62 protected String getRequestMimeType(boolean multipleIds)
64 return "application/json";
68 protected String getResponseMimeType()
70 return "application/json";
74 * Calls the Ensembl lookup REST endpoint and retrieves the 'Parent' for the
75 * given identifier, or null if not found
80 public String getParent(String identifier)
82 List<String> ids = Arrays.asList(new String[] { identifier });
84 BufferedReader br = null;
87 URL url = getUrl(identifier);
90 br = getHttpResponse(url, ids);
92 return (parseResponse(br));
93 } catch (IOException e)
104 } catch (IOException e)
113 * Parses "Parent" from the JSON response and returns the value, or null if
118 * @throws IOException
120 protected String parseResponse(BufferedReader br) throws IOException
122 String parent = null;
123 JSONParser jp = new JSONParser();
126 JSONObject val = (JSONObject) jp.parse(br);
127 parent = val.get("Parent").toString();
128 } catch (ParseException e)