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.HashMap;
10 import java.util.Iterator;
11 import java.util.List;
15 import org.json.simple.JSONArray;
16 import org.json.simple.parser.JSONParser;
17 import org.json.simple.parser.ParseException;
19 public class EnsemblInfo extends EnsemblRestClient
23 * cached upper-cased results of REST /info/divisions service,
24 * currently (from April 2019)
25 * { "ENSEMBLFUNGI", "http://rest.ensembl.org",
26 * "ENSEMBLBACTERIA", "http://rest.ensembl.org",
27 * "ENSEMBLPROTISTS", "http://rest.ensembl.org",
28 * "ENSEMBLMETAZOA", "http://rest.ensembl.org",
29 * "ENSEMBLPLANTS", "http://rest.ensembl.org",
30 * "ENSEMBL", "http://rest.ensembl.org" }
33 private static Map<String, String> divisions;
44 public String getDbName()
50 public AlignmentI getSequenceRecords(String queries) throws Exception
56 protected URL getUrl(List<String> ids) throws MalformedURLException
62 protected boolean useGetRequest()
68 * Answers the domain (e.g. http://rest.ensembl.org) for the given division,
69 * or null if not recognised by Ensembl
74 public String getDomain(String division)
76 if (divisions == null)
80 return divisions.get(division.toUpperCase());
84 * On first request only, populate the lookup map by fetching the list of
85 * divisions known to Ensembl
89 divisions = new HashMap<>();
91 BufferedReader br = null;
94 URL url = getDivisionsUrl();
97 br = getHttpResponse(url, null);
100 } catch (IOException e)
110 } catch (IOException e)
119 * Parses the JSON response to /info/divisions, and add each to the lookup map
123 void parseResponse(BufferedReader br)
125 JSONParser jp = new JSONParser();
129 JSONArray parsed = (JSONArray) jp.parse(br);
130 String domain = getDomain();
132 Iterator rvals = parsed.iterator();
133 while (rvals.hasNext())
135 String division = rvals.next().toString();
136 divisions.put(division.toUpperCase(), domain);
138 } catch (IOException | ParseException | NumberFormatException e)
145 * Constructs the URL for the Ensembl /info/divisions REST service
148 * @throws MalformedURLException
150 URL getDivisionsUrl() throws MalformedURLException
154 + "/info/divisions?content-type=application/json");
158 * Returns the set of 'divisions' recognised by Ensembl
162 public Set<String> getDivisions() {
163 if (divisions == null)
168 return divisions.keySet();