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";
43 private static final String TYPE = "type";
45 * Constructor given the target domain to fetch data from
51 public EnsemblSymbol(String domain, String dbName, String dbVersion)
53 super(domain, dbName, dbVersion);
57 // * Returns the first "id" value in gene identifier format from the JSON
58 // * response, or null if none found
62 // * @throws IOException
64 // @SuppressWarnings("unchecked")
65 //protected String parseSymbolResponse(BufferedReader br) throws IOException
70 * Constructs the URL for the REST symbol endpoint
73 * the accession id (Ensembl or external)
75 * a species name recognisable by Ensembl
77 * an optional type to filter the response (gene, transcript,
81 protected URL getUrl(String id, Species species, String... type)
83 StringBuilder sb = new StringBuilder();
84 sb.append(getDomain()).append("/xrefs/symbol/")
85 .append(species.toString()).append("/").append(id)
86 .append(CONTENT_TYPE_JSON);
89 sb.append("&object_type=").append(t);
93 String url = sb.toString();
95 } catch (MalformedURLException e)
102 * Calls the Ensembl xrefs REST 'symbol' endpoint and retrieves any gene ids
103 * for the given identifier, for any known model organisms
108 @SuppressWarnings("unchecked")
109 public List<String> getGeneIds(String identifier)
111 List<String> result = new ArrayList<String>();
112 List<String> ids = new ArrayList<String>();
115 String[] queries = identifier.split(getAccessionSeparator());
118 for (String query : queries)
120 for (Species taxon : Species.getModelOrganisms())
122 String geneId = null;///parseSymbolResponse(br);
125 Iterator<Object> rvals = (Iterator<Object>) getJSON(getUrl(query, taxon, GENE), ids, -1, MODE_ITERATOR, null);
128 while (rvals.hasNext())
130 Map<String, Object> val = (Map<String, Object>) rvals.next();
131 String id = val.get(JSON_ID).toString();
132 String type = val.get(TYPE).toString();
133 if (id != null && GENE.equals(type))
139 } catch (ParseException e)
144 if (geneId != null && !result.contains(geneId))
150 } catch (IOException e)