1 package jalview.ext.ensembl;
3 import jalview.bin.Instance;
4 import jalview.datamodel.AlignmentI;
5 import jalview.datamodel.DBRefSource;
7 import java.io.IOException;
8 import java.net.MalformedURLException;
10 import java.util.HashMap;
11 import java.util.Iterator;
12 import java.util.List;
16 import org.json.simple.parser.ParseException;
18 public class EnsemblInfo extends EnsemblRestClient
22 * On first request only, populate the lookup map by fetching the list of
23 * divisions known to EnsemblGenomes.
26 private static EnsemblInfo getInstance()
28 Instance j = Instance.getInstance();
29 return (j.ensemblInfo == null ? j.ensemblInfo = new EnsemblInfo()
38 * for convenience, pre-fill ensembl.org as the domain for "ENSEMBL"
40 divisions.put(DBRefSource.ENSEMBL.toUpperCase(), ensemblDomain);
43 @SuppressWarnings("unchecked")
44 Iterator<Object> rvals = (Iterator<Object>) getJSON(
45 getDivisionsUrl(ensemblGenomesDomain), null, -1,
51 while (rvals.hasNext())
53 String division = rvals.next().toString();
54 divisions.put(division.toUpperCase(), ensemblGenomesDomain);
56 } catch (IOException | ParseException | NumberFormatException e)
63 * cached results of REST /info/divisions service, currently
66 * { "ENSEMBLFUNGI", "http://rest.ensemblgenomes.org"},
67 * "ENSEMBLBACTERIA", "http://rest.ensemblgenomes.org"},
68 * "ENSEMBLPROTISTS", "http://rest.ensemblgenomes.org"},
69 * "ENSEMBLMETAZOA", "http://rest.ensemblgenomes.org"},
70 * "ENSEMBLPLANTS", "http://rest.ensemblgenomes.org"},
71 * "ENSEMBL", "http://rest.ensembl.org" }
74 * The values for EnsemblGenomes are retrieved by a REST call, that for
75 * Ensembl is added programmatically for convenience of lookup
77 private Map<String, String> divisions = new HashMap<>();
80 public String getDbName()
86 public AlignmentI getSequenceRecords(String queries) throws Exception
92 protected URL getUrl(List<String> ids) throws MalformedURLException
98 protected boolean useGetRequest()
104 * Answers the domain (http://rest.ensembl.org or
105 * http://rest.ensemblgenomes.org) for the given division, or null if not
106 * recognised by Ensembl.
111 public static String getDomain(String division)
113 return getInstance().divisions.get(division.toUpperCase());
117 * Constructs the URL for the EnsemblGenomes /info/divisions REST service
121 * @throws MalformedURLException
123 URL getDivisionsUrl(String domain) throws MalformedURLException
125 return new URL(domain
126 + "/info/divisions?content-type=application/json");
130 * Returns the set of 'divisions' recognised by Ensembl or EnsemblGenomes
134 public static Set<String> getDivisions()
136 return getInstance().divisions.keySet();