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;
17 * A client for the Ensembl lookup REST endpoint; used to find the Parent gene
18 * identifier given a transcript identifier.
23 public class EnsemblLookup extends EnsemblRestClient
27 * Default constructor (to use rest.ensembl.org)
29 public EnsemblLookup()
35 * Constructor given the target domain to fetch data from
39 public EnsemblLookup(String d)
45 public String getDbName()
51 public AlignmentI getSequenceRecords(String queries) throws Exception
57 protected URL getUrl(List<String> ids) throws MalformedURLException
59 String identifier = ids.get(0);
60 return getUrl(identifier);
67 protected URL getUrl(String identifier)
69 String url = getDomain() + "/lookup/id/" + identifier
70 + "?content-type=application/json";
74 } catch (MalformedURLException e)
81 protected boolean useGetRequest()
87 protected String getRequestMimeType(boolean multipleIds)
89 return "application/json";
93 protected String getResponseMimeType()
95 return "application/json";
99 * Calls the Ensembl lookup REST endpoint and retrieves the 'Parent' for the
100 * given identifier, or null if not found
105 public String getParent(String identifier)
107 List<String> ids = Arrays.asList(new String[] { identifier });
109 BufferedReader br = null;
112 URL url = getUrl(identifier);
115 br = getHttpResponse(url, ids);
117 return (parseResponse(br));
118 } catch (IOException e)
129 } catch (IOException e)
138 * Parses "Parent" from the JSON response and returns the value, or null if
143 * @throws IOException
145 protected String parseResponse(BufferedReader br) throws IOException
147 String parent = null;
148 JSONParser jp = new JSONParser();
151 JSONObject val = (JSONObject) jp.parse(br);
152 parent = val.get("Parent").toString();
153 } catch (ParseException e)