X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fext%2Fensembl%2FEnsemblXref.java;h=4eeb97780e137c6b521941695371779137967daf;hb=57738a1f3c19b1c3a00bd3ac5108f8cd0af32f99;hp=77768a6fa94243a7b354545010333b6547370e36;hpb=da31d3e5aebfcdbb1ae7084bbc75bbc3539ee2e6;p=jalview.git diff --git a/src/jalview/ext/ensembl/EnsemblXref.java b/src/jalview/ext/ensembl/EnsemblXref.java index 77768a6..4eeb977 100644 --- a/src/jalview/ext/ensembl/EnsemblXref.java +++ b/src/jalview/ext/ensembl/EnsemblXref.java @@ -23,6 +23,7 @@ package jalview.ext.ensembl; import jalview.datamodel.AlignmentI; import jalview.datamodel.DBRefEntry; import jalview.util.DBRefUtils; +import jalview.util.JSONUtils; import java.io.BufferedReader; import java.io.IOException; @@ -31,10 +32,8 @@ 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; /** @@ -99,83 +98,54 @@ class EnsemblXref extends EnsemblRestClient * an Ensembl stable identifier * @return */ + @SuppressWarnings("unchecked") public List getCrossReferences(String identifier) { List result = new ArrayList<>(); List 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 parseResponse(BufferedReader br) - throws IOException - { - JSONParser jp = new JSONParser(); - List result = new ArrayList<>(); - try - { - JSONArray responses = (JSONArray) jp.parse(br); - Iterator rvals = responses.iterator(); + Iterator rvals = (Iterator) getJSON( + getUrl(identifier), ids, -1, MODE_ITERATOR, null); while (rvals.hasNext()) { - JSONObject val = (JSONObject) rvals.next(); + Map val = (Map) 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 parseResponse(BufferedReader br) + // throws IOException + // { + // return result; + // } + // private String xrefVersion = "ENSEMBL:0"; /** @@ -198,8 +168,8 @@ class EnsemblXref extends EnsemblRestClient */ 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);