1 package jalview.ext.ensembl;
3 import jalview.datamodel.AlignmentI;
4 import jalview.datamodel.DBRefSource;
5 import jalview.util.JSONUtils;
7 import java.io.BufferedReader;
8 import java.io.IOException;
9 import java.net.MalformedURLException;
11 import java.util.HashMap;
12 import java.util.Iterator;
13 import java.util.List;
17 import org.json.simple.parser.ParseException;
19 public class EnsemblInfo extends EnsemblRestClient
23 * cached results of REST /info/divisions service, currently
26 * { "ENSEMBLFUNGI", "http://rest.ensemblgenomes.org"},
27 * "ENSEMBLBACTERIA", "http://rest.ensemblgenomes.org"},
28 * "ENSEMBLPROTISTS", "http://rest.ensemblgenomes.org"},
29 * "ENSEMBLMETAZOA", "http://rest.ensemblgenomes.org"},
30 * "ENSEMBLPLANTS", "http://rest.ensemblgenomes.org"},
31 * "ENSEMBL", "http://rest.ensembl.org" }
34 * The values for EnsemblGenomes are retrieved by a REST call, that for
35 * Ensembl is added programmatically for convenience of lookup
37 private static Map<String, String> divisions;
40 public String getDbName()
46 public AlignmentI getSequenceRecords(String queries) throws Exception
52 protected URL getUrl(List<String> ids) throws MalformedURLException
58 protected boolean useGetRequest()
64 * Answers the domain (http://rest.ensembl.org or
65 * http://rest.ensemblgenomes.org) for the given division, or null if not
66 * recognised by Ensembl.
71 public String getDomain(String division)
73 if (divisions == null)
77 return divisions.get(division.toUpperCase());
81 * On first request only, populate the lookup map by fetching the list of
82 * divisions known to EnsemblGenomes.
86 divisions = new HashMap<>();
89 * for convenience, pre-fill ensembl.org as the domain for "ENSEMBL"
91 divisions.put(DBRefSource.ENSEMBL.toUpperCase(), ensemblDomain);
94 @SuppressWarnings("unchecked")
95 Iterator<Object> rvals = (Iterator<Object>) getJSON(getDivisionsUrl(ensemblGenomesDomain), null, -1, MODE_ITERATOR, null);
98 while (rvals.hasNext())
100 String division = rvals.next().toString();
101 divisions.put(division.toUpperCase(), ensemblGenomesDomain);
103 } catch (IOException | ParseException | NumberFormatException e)
110 * Constructs the URL for the EnsemblGenomes /info/divisions REST service
114 * @throws MalformedURLException
116 URL getDivisionsUrl(String domain) throws MalformedURLException
118 return new URL(domain
119 + "/info/divisions?content-type=application/json");
123 * Returns the set of 'divisions' recognised by Ensembl or EnsemblGenomes
127 public Set<String> getDivisions() {
128 if (divisions == null)
133 return divisions.keySet();