2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ext.ensembl;
23 import jalview.datamodel.AlignmentI;
24 import jalview.datamodel.DBRefSource;
25 import jalview.util.JSONUtils;
27 import java.io.BufferedReader;
28 import java.io.IOException;
29 import java.net.MalformedURLException;
31 import java.util.HashMap;
32 import java.util.Iterator;
33 import java.util.List;
37 import org.json.simple.parser.ParseException;
39 public class EnsemblInfo extends EnsemblRestClient
43 * cached results of REST /info/divisions service, currently
46 * { "ENSEMBLFUNGI", "http://rest.ensemblgenomes.org"},
47 * "ENSEMBLBACTERIA", "http://rest.ensemblgenomes.org"},
48 * "ENSEMBLPROTISTS", "http://rest.ensemblgenomes.org"},
49 * "ENSEMBLMETAZOA", "http://rest.ensemblgenomes.org"},
50 * "ENSEMBLPLANTS", "http://rest.ensemblgenomes.org"},
51 * "ENSEMBL", "http://rest.ensembl.org" }
54 * The values for EnsemblGenomes are retrieved by a REST call, that for
55 * Ensembl is added programmatically for convenience of lookup
57 private static Map<String, String> divisions;
60 public String getDbName()
66 public AlignmentI getSequenceRecords(String queries) throws Exception
72 protected URL getUrl(List<String> ids) throws MalformedURLException
78 protected boolean useGetRequest()
84 * Answers the domain (http://rest.ensembl.org or
85 * http://rest.ensemblgenomes.org) for the given division, or null if not
86 * recognised by Ensembl.
91 public String getDomain(String division)
93 if (divisions == null)
97 return divisions.get(division.toUpperCase());
101 * On first request only, populate the lookup map by fetching the list of
102 * divisions known to EnsemblGenomes.
104 void fetchDivisions()
106 divisions = new HashMap<>();
109 * for convenience, pre-fill ensembl.org as the domain for "ENSEMBL"
111 divisions.put(DBRefSource.ENSEMBL.toUpperCase(), ensemblDomain);
114 @SuppressWarnings("unchecked")
115 Iterator<Object> rvals = (Iterator<Object>) getJSON(getDivisionsUrl(ensemblGenomesDomain), null, -1, MODE_ITERATOR, null);
118 while (rvals.hasNext())
120 String division = rvals.next().toString();
121 divisions.put(division.toUpperCase(), ensemblGenomesDomain);
123 } catch (IOException | ParseException | NumberFormatException e)
130 * Constructs the URL for the EnsemblGenomes /info/divisions REST service
134 * @throws MalformedURLException
136 URL getDivisionsUrl(String domain) throws MalformedURLException
138 return new URL(domain
139 + "/info/divisions?content-type=application/json");
143 * Returns the set of 'divisions' recognised by Ensembl or EnsemblGenomes
147 public Set<String> getDivisions() {
148 if (divisions == null)
153 return divisions.keySet();