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.io.IOException;
24 import java.net.MalformedURLException;
26 import java.util.HashMap;
27 import java.util.Iterator;
28 import java.util.List;
32 import org.json.simple.parser.ParseException;
34 import jalview.datamodel.AlignmentI;
35 import jalview.datamodel.DBRefSource;
37 public class EnsemblInfo extends EnsemblRestClient
41 * cached results of REST /info/divisions service, currently
44 * { "ENSEMBLFUNGI", "http://rest.ensemblgenomes.org"},
45 * "ENSEMBLBACTERIA", "http://rest.ensemblgenomes.org"},
46 * "ENSEMBLPROTISTS", "http://rest.ensemblgenomes.org"},
47 * "ENSEMBLMETAZOA", "http://rest.ensemblgenomes.org"},
48 * "ENSEMBLPLANTS", "http://rest.ensemblgenomes.org"},
49 * "ENSEMBL", "http://rest.ensembl.org" }
52 * The values for EnsemblGenomes are retrieved by a REST call, that for
53 * Ensembl is added programmatically for convenience of lookup
55 private static Map<String, String> divisions;
58 public String getDbName()
64 public AlignmentI getSequenceRecords(String queries) throws Exception
70 protected URL getUrl(List<String> ids) throws MalformedURLException
76 protected boolean useGetRequest()
82 * Answers the domain (http://rest.ensembl.org or
83 * http://rest.ensemblgenomes.org) for the given division, or null if not
84 * recognised by Ensembl.
89 public String getDomain(String division)
91 if (divisions == null)
95 return divisions.get(division.toUpperCase());
99 * On first request only, populate the lookup map by fetching the list of
100 * divisions known to EnsemblGenomes.
102 void fetchDivisions()
104 divisions = new HashMap<>();
107 * for convenience, pre-fill ensembl.org as the domain for "ENSEMBL"
109 divisions.put(DBRefSource.ENSEMBL.toUpperCase(), ensemblDomain);
112 @SuppressWarnings("unchecked")
113 Iterator<Object> rvals = (Iterator<Object>) getJSON(getDivisionsUrl(ensemblGenomesDomain), null, -1, MODE_ITERATOR, null);
116 while (rvals.hasNext())
118 String division = rvals.next().toString();
119 divisions.put(division.toUpperCase(), ensemblGenomesDomain);
121 } catch (IOException | ParseException | NumberFormatException e)
128 * Constructs the URL for the EnsemblGenomes /info/divisions REST service
132 * @throws MalformedURLException
134 URL getDivisionsUrl(String domain) throws MalformedURLException
136 return new URL(domain
137 + "/info/divisions?content-type=application/json");
141 * Returns the set of 'divisions' recognised by Ensembl or EnsemblGenomes
145 public Set<String> getDivisions() {
146 if (divisions == null)
151 return divisions.keySet();