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.ArrayList;
27 import java.util.Iterator;
28 import java.util.List;
31 import org.json.simple.parser.ParseException;
34 * A client for the Ensembl xrefs/symbol REST service;
36 * @see http://rest.ensembl.org/documentation/info/xref_external
40 public class EnsemblSymbol extends EnsemblXref
42 private static final String GENE = "gene";
44 private static final String TYPE = "type";
47 * Constructor given the target domain to fetch data from
53 public EnsemblSymbol(String domain, String dbName, String dbVersion)
55 super(domain, dbName, dbVersion);
59 // * Returns the first "id" value in gene identifier format from the JSON
60 // * response, or null if none found
64 // * @throws IOException
66 // @SuppressWarnings("unchecked")
67 // protected String parseSymbolResponse(BufferedReader br) throws IOException
72 * Constructs the URL for the REST symbol endpoint
75 * the accession id (Ensembl or external)
77 * a species name recognisable by Ensembl
79 * an optional type to filter the response (gene, transcript,
83 protected URL getUrl(String id, Species species, String... type)
85 StringBuilder sb = new StringBuilder();
86 sb.append(getDomain()).append("/xrefs/symbol/")
87 .append(species.toString()).append("/").append(id)
88 .append(CONTENT_TYPE_JSON);
91 sb.append("&object_type=").append(t);
95 String url = sb.toString();
97 } catch (MalformedURLException e)
104 * Calls the Ensembl xrefs REST 'symbol' endpoint and retrieves any gene ids
105 * for the given identifier, for any known model organisms
110 @SuppressWarnings("unchecked")
111 public List<String> getGeneIds(String identifier)
113 List<String> result = new ArrayList<String>();
114 List<String> ids = new ArrayList<String>();
117 String[] queries = identifier.split(getAccessionSeparator());
120 for (String query : queries)
122 for (Species taxon : Species.getModelOrganisms())
124 String geneId = null;/// parseSymbolResponse(br);
127 Iterator<Object> rvals = (Iterator<Object>) getJSON(
128 getUrl(query, taxon, GENE), ids, -1, MODE_ITERATOR,
132 while (rvals.hasNext())
134 Map<String, Object> val = (Map<String, Object>) rvals.next();
135 String id = val.get(JSON_ID).toString();
136 String type = val.get(TYPE).toString();
137 if (id != null && GENE.equals(type))
143 } catch (ParseException e)
148 if (geneId != null && !result.contains(geneId))
154 } catch (IOException e)