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 java.util.Locale;
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.DBRefSource;
27 import jalview.util.JSONUtils;
29 import java.io.BufferedReader;
30 import java.io.IOException;
31 import java.net.MalformedURLException;
33 import java.util.HashMap;
34 import java.util.Iterator;
35 import java.util.List;
39 import org.json.simple.parser.ParseException;
41 public class EnsemblInfo extends EnsemblRestClient
45 * cached results of REST /info/divisions service, currently
48 * { "ENSEMBLFUNGI", "http://rest.ensemblgenomes.org"},
49 * "ENSEMBLBACTERIA", "http://rest.ensemblgenomes.org"},
50 * "ENSEMBLPROTISTS", "http://rest.ensemblgenomes.org"},
51 * "ENSEMBLMETAZOA", "http://rest.ensemblgenomes.org"},
52 * "ENSEMBLPLANTS", "http://rest.ensemblgenomes.org"},
53 * "ENSEMBL", "http://rest.ensembl.org" }
56 * The values for EnsemblGenomes are retrieved by a REST call, that for
57 * Ensembl is added programmatically for convenience of lookup
59 private static Map<String, String> divisions;
62 public String getDbName()
68 public AlignmentI getSequenceRecords(String queries) throws Exception
74 protected URL getUrl(List<String> ids) throws MalformedURLException
80 protected boolean useGetRequest()
86 * Answers the domain (http://rest.ensembl.org or
87 * http://rest.ensemblgenomes.org) for the given division, or null if not
88 * recognised by Ensembl.
93 public String getDomain(String division)
95 if (divisions == null)
99 return divisions.get(division.toUpperCase(Locale.ROOT));
103 * On first request only, populate the lookup map by fetching the list of
104 * divisions known to EnsemblGenomes.
106 void fetchDivisions()
108 divisions = new HashMap<>();
111 * for convenience, pre-fill ensembl.org as the domain for "ENSEMBL"
113 divisions.put(DBRefSource.ENSEMBL.toUpperCase(Locale.ROOT),
117 @SuppressWarnings("unchecked")
118 Iterator<Object> rvals = (Iterator<Object>) getJSON(
119 getDivisionsUrl(ensemblGenomesDomain), null, -1,
120 MODE_ITERATOR, null);
123 while (rvals.hasNext())
125 String division = rvals.next().toString();
126 divisions.put(division.toUpperCase(Locale.ROOT),
127 ensemblGenomesDomain);
129 } catch (IOException | ParseException | NumberFormatException e)
136 * Constructs the URL for the EnsemblGenomes /info/divisions REST service
142 * @throws MalformedURLException
144 URL getDivisionsUrl(String domain) throws MalformedURLException
147 domain + "/info/divisions?content-type=application/json");
151 * Returns the set of 'divisions' recognised by Ensembl or EnsemblGenomes
155 public Set<String> getDivisions()
157 if (divisions == null)
162 return divisions.keySet();