*/
package jalview.ext.ensembl;
-import jalview.datamodel.AlignmentI;
-import jalview.datamodel.DBRefEntry;
-import jalview.util.DBRefUtils;
-
-import java.io.BufferedReader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
-import org.json.simple.JSONArray;
-import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.DBRefEntry;
+import jalview.util.DBRefUtils;
+
/**
* A class to fetch cross-references from Ensembl by calling the /xrefs REST
* service
return true;
}
- @Override
- protected String getRequestMimeType(boolean multipleIds)
- {
- return "application/json";
- }
-
- @Override
- protected String getResponseMimeType()
- {
- return "application/json";
- }
-
/**
* Calls the Ensembl xrefs REST endpoint and retrieves any cross-references
* ("primary_id") for the given identifier (Ensembl accession id) and database
* an Ensembl stable identifier
* @return
*/
+ @SuppressWarnings("unchecked")
public List<DBRefEntry> getCrossReferences(String identifier)
{
- List<DBRefEntry> result = new ArrayList<DBRefEntry>();
- List<String> ids = new ArrayList<String>();
+ List<DBRefEntry> result = new ArrayList<>();
+ List<String> ids = new ArrayList<>();
ids.add(identifier);
- BufferedReader br = null;
- try
- {
- URL url = getUrl(identifier);
- if (url != null)
- {
- br = getHttpResponse(url, ids);
- if (br != null)
- {
- result = parseResponse(br);
- }
- }
- } catch (IOException e)
- {
- // ignore
- } finally
- {
- if (br != null)
- {
- try
- {
- br.close();
- } catch (IOException e)
- {
- // ignore
- }
- }
- }
-
- return result;
- }
-
- /**
- * Parses "primary_id" and "dbname" values from the JSON response and
- * constructs a DBRefEntry. Returns a list of the DBRefEntry created. Note we
- * don't parse "synonyms" as they appear to be either redirected or obsolete
- * in Uniprot.
- *
- * @param br
- * @return
- * @throws IOException
- */
- protected List<DBRefEntry> parseResponse(BufferedReader br)
- throws IOException
- {
- JSONParser jp = new JSONParser();
- List<DBRefEntry> result = new ArrayList<DBRefEntry>();
try
{
- JSONArray responses = (JSONArray) jp.parse(br);
- Iterator rvals = responses.iterator();
+ Iterator<Object> rvals = (Iterator<Object>) getJSON(
+ getUrl(identifier), ids, -1, MODE_ITERATOR, null);
while (rvals.hasNext())
{
- JSONObject val = (JSONObject) rvals.next();
+ Map<String, Object> val = (Map<String, Object>) rvals.next();
String db = val.get("dbname").toString();
String id = val.get("primary_id").toString();
- if (db != null && id != null
- && !GO_GENE_ONTOLOGY.equals(db))
+ if (db != null && id != null && !GO_GENE_ONTOLOGY.equals(db))
{
db = DBRefUtils.getCanonicalName(db);
DBRefEntry dbref = new DBRefEntry(db, getXRefVersion(), id);
result.add(dbref);
}
}
- } catch (ParseException e)
+ } catch (ParseException | IOException e)
{
// ignore
}
return result;
}
+ // /**
+ // * Parses "primary_id" and "dbname" values from the JSON response and
+ // * constructs a DBRefEntry. Returns a list of the DBRefEntry created. Note
+ // we
+ // * don't parse "synonyms" as they appear to be either redirected or obsolete
+ // * in Uniprot.
+ // *
+ // * @param br
+ // * @return
+ // * @throws IOException
+ // */
+ // @SuppressWarnings("unchecked")
+ // protected List<DBRefEntry> parseResponse(BufferedReader br)
+ // throws IOException
+ // {
+ // return result;
+ // }
+ //
private String xrefVersion = "ENSEMBL:0";
/**
*/
protected URL getUrl(String identifier)
{
- String url = getDomain() + "/xrefs/id/" + identifier
- + CONTENT_TYPE_JSON + "&all_levels=1";
+ String url = getDomain() + "/xrefs/id/" + identifier + CONTENT_TYPE_JSON
+ + "&all_levels=1";
try
{
return new URL(url);