1 package jalview.ext.ensembl;
3 import jalview.bin.ApplicationSingletonProvider;
4 import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
5 import jalview.datamodel.AlignmentI;
6 import jalview.datamodel.DBRefSource;
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 implements ApplicationSingletonI
23 * On first request only, populate the lookup map by fetching the list of
24 * divisions known to EnsemblGenomes
27 private static EnsemblInfo getInstance()
29 return (EnsemblInfo) ApplicationSingletonProvider.getInstance(EnsemblInfo.class);
37 * for convenience, pre-fill ensembl.org as the domain for "ENSEMBL"
39 divisions.put(DBRefSource.ENSEMBL.toUpperCase(), ensemblDomain);
42 @SuppressWarnings("unchecked")
43 Iterator<Object> rvals = (Iterator<Object>) getJSON(
44 getDivisionsUrl(ensemblGenomesDomain), null, -1,
50 while (rvals.hasNext())
52 String division = rvals.next().toString();
53 divisions.put(division.toUpperCase(), ensemblGenomesDomain);
55 } catch (IOException | ParseException | NumberFormatException e)
62 * cached results of REST /info/divisions service, currently
65 * { "ENSEMBLFUNGI", "http://rest.ensemblgenomes.org"},
66 * "ENSEMBLBACTERIA", "http://rest.ensemblgenomes.org"},
67 * "ENSEMBLPROTISTS", "http://rest.ensemblgenomes.org"},
68 * "ENSEMBLMETAZOA", "http://rest.ensemblgenomes.org"},
69 * "ENSEMBLPLANTS", "http://rest.ensemblgenomes.org"},
70 * "ENSEMBL", "http://rest.ensembl.org" }
73 * The values for EnsemblGenomes are retrieved by a REST call, that for
74 * Ensembl is added programmatically for convenience of lookup
76 private Map<String, String> divisions = new HashMap<>();
79 public String getDbName()
85 public AlignmentI getSequenceRecords(String queries) throws Exception
91 protected URL getUrl(List<String> ids) throws MalformedURLException
97 protected boolean useGetRequest()
103 * Answers the domain (http://rest.ensembl.org or
104 * http://rest.ensemblgenomes.org) for the given division, or null if not
105 * recognised by Ensembl.
110 public static String getDomain(String division)
112 return getInstance().divisions.get(division.toUpperCase());
116 * Constructs the URL for the EnsemblGenomes /info/divisions REST service
120 * @throws MalformedURLException
122 URL getDivisionsUrl(String domain) throws MalformedURLException
124 return new URL(domain
125 + "/info/divisions?content-type=application/json");
129 * Returns the set of 'divisions' recognised by Ensembl or EnsemblGenomes
133 public static Set<String> getDivisions()
135 return getInstance().divisions.keySet();