1 package jalview.ext.ensembl;
3 import jalview.datamodel.AlignmentI;
4 import jalview.datamodel.DBRefSource;
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.parser.ParseException;
17 public class EnsemblInfo extends EnsemblRestClient
21 * cached results of REST /info/divisions service, currently
25 * "ENSEMBLFUNGI", "http://rest.ensemblgenomes.org"},
26 * "ENSEMBLBACTERIA", "http://rest.ensemblgenomes.org"},
27 * "ENSEMBLPROTISTS", "http://rest.ensemblgenomes.org"},
28 * "ENSEMBLMETAZOA", "http://rest.ensemblgenomes.org"},
29 * "ENSEMBLPLANTS", "http://rest.ensemblgenomes.org"},
30 * "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(
96 getDivisionsUrl(ensemblGenomesDomain), null, -1,
102 while (rvals.hasNext())
104 String division = rvals.next().toString();
105 divisions.put(division.toUpperCase(), ensemblGenomesDomain);
107 } catch (IOException | ParseException | NumberFormatException e)
114 * Constructs the URL for the EnsemblGenomes /info/divisions REST service
118 * @throws MalformedURLException
120 URL getDivisionsUrl(String domain) throws MalformedURLException
122 return new URL(domain
123 + "/info/divisions?content-type=application/json");
127 * Returns the set of 'divisions' recognised by Ensembl or EnsemblGenomes
131 public Set<String> getDivisions()
133 if (divisions == null)
138 return divisions.keySet();