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
20 private static EnsemblInfo instance;
23 * Some question as to whether it is necessary to do this for each applet. IN
24 * PRINCIPLE, applets could set different properties for the origin of Ensembl
25 * data. But I suggest this is unlikely. If we DO care about that possibility,
26 * then we need to set doICare to Platform.isJS();
29 private final static boolean doICare = false;// Platform.isJS();
32 * On first request only, populate the lookup map by fetching the list of
33 * divisions known to EnsemblGenomes.
36 private static EnsemblInfo getInstance()
39 // BH 2019.05.08 need to isolate static fields in JavaScript
41 EnsemblInfo i = instance;
42 @SuppressWarnings("unused")
47 g = Thread.currentThread().getThreadGroup();
49 * @j2sNative i = g._jalviewEnsemblInstance;
55 i = new EnsemblInfo();
60 * @j2sNative g._jalviewEnsemblInstance = i;
73 * cached results of REST /info/divisions service, currently
76 * { "ENSEMBLFUNGI", "http://rest.ensemblgenomes.org"},
77 * "ENSEMBLBACTERIA", "http://rest.ensemblgenomes.org"},
78 * "ENSEMBLPROTISTS", "http://rest.ensemblgenomes.org"},
79 * "ENSEMBLMETAZOA", "http://rest.ensemblgenomes.org"},
80 * "ENSEMBLPLANTS", "http://rest.ensemblgenomes.org"},
81 * "ENSEMBL", "http://rest.ensembl.org" }
84 * The values for EnsemblGenomes are retrieved by a REST call, that for
85 * Ensembl is added programmatically for convenience of lookup
87 private Map<String, String> divisions = new HashMap<>();
93 * for convenience, pre-fill ensembl.org as the domain for "ENSEMBL"
95 divisions.put(DBRefSource.ENSEMBL.toUpperCase(), ensemblDomain);
98 @SuppressWarnings("unchecked")
99 Iterator<Object> rvals = (Iterator<Object>) getJSON(
100 getDivisionsUrl(ensemblGenomesDomain), null, -1,
101 MODE_ITERATOR, null);
106 while (rvals.hasNext())
108 String division = rvals.next().toString();
109 divisions.put(division.toUpperCase(), ensemblGenomesDomain);
111 } catch (IOException | ParseException | NumberFormatException e)
118 public String getDbName()
124 public AlignmentI getSequenceRecords(String queries) throws Exception
130 protected URL getUrl(List<String> ids) throws MalformedURLException
136 protected boolean useGetRequest()
142 * Answers the domain (http://rest.ensembl.org or
143 * http://rest.ensemblgenomes.org) for the given division, or null if not
144 * recognised by Ensembl.
149 public static String getDomain(String division)
151 return getInstance().divisions.get(division.toUpperCase());
155 * Constructs the URL for the EnsemblGenomes /info/divisions REST service
159 * @throws MalformedURLException
161 URL getDivisionsUrl(String domain) throws MalformedURLException
163 return new URL(domain
164 + "/info/divisions?content-type=application/json");
168 * Returns the set of 'divisions' recognised by Ensembl or EnsemblGenomes
172 public static Set<String> getDivisions()
174 return getInstance().divisions.keySet();