1 package jalview.ext.ensembl;
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.net.MalformedURLException;
7 import java.util.ArrayList;
8 import java.util.Iterator;
11 import org.json.simple.JSONArray;
12 import org.json.simple.JSONObject;
13 import org.json.simple.parser.JSONParser;
14 import org.json.simple.parser.ParseException;
16 public class EnsemblSymbol extends EnsemblXref
19 * Returns the first "id" value in gene identifier format from the JSON
20 * response, or null if none found
26 protected String parseResponse(BufferedReader br)
29 JSONParser jp = new JSONParser();
33 JSONArray responses = (JSONArray) jp.parse(br);
34 Iterator rvals = responses.iterator();
35 while (rvals.hasNext())
37 JSONObject val = (JSONObject) rvals.next();
38 String id = val.get("id").toString();
39 if (id != null && isGeneIdentifier(id))
45 } catch (ParseException e)
52 protected URL getUrl(String id, Species species)
54 String url = ENSEMBL_REST + "/xrefs/symbol/" + species.toString() + "/"
56 + "?content-type=application/json";
60 } catch (MalformedURLException e)
67 * Calls the Ensembl xrefs REST 'symbol' endpoint and retrieves any gene ids
68 * for the given identifier, for any known model organisms
73 public List<String> getIds(String identifier)
75 List<String> result = new ArrayList<String>();
76 List<String> ids = new ArrayList<String>();
79 String[] queries = identifier.split(getAccessionSeparator());
80 BufferedReader br = null;
83 for (String query : queries)
85 for (Species taxon : Species.values())
87 if (taxon.isModelOrganism())
89 URL url = getUrl(query, taxon);
92 br = getHttpResponse(url, ids);
94 String geneId = parseResponse(br);
102 } catch (IOException e)
112 } catch (IOException e)