X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fext%2Fensembl%2FEnsemblXref.java;h=eedfe970dd4ffa6745aef8d8c0ea0f777d6f43f6;hb=401715f8745eeee967df8d60549b4c5d7f64530f;hp=6a4f369def30e72345fc5fe2a77e86ec7fedfeb0;hpb=a9f0472fe6fd4737b47d7955d198e76923e6aabc;p=jalview.git
diff --git a/src/jalview/ext/ensembl/EnsemblXref.java b/src/jalview/ext/ensembl/EnsemblXref.java
index 6a4f369..eedfe97 100644
--- a/src/jalview/ext/ensembl/EnsemblXref.java
+++ b/src/jalview/ext/ensembl/EnsemblXref.java
@@ -1,8 +1,29 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
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;
@@ -11,19 +32,41 @@ 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;
-public class EnsemblXref extends EnsemblRestClient
+/**
+ * A class to fetch cross-references from Ensembl by calling the /xrefs REST
+ * service
+ *
+ * @author gmcarstairs
+ * @see http://rest.ensembl.org/documentation/info/xref_id
+ */
+class EnsemblXref extends EnsemblRestClient
{
+ private static final String GO_GENE_ONTOLOGY = "GO";
+
+ private String dbName = "ENSEMBL (xref)";
+
+ /**
+ * Constructor given the target domain to fetch data from
+ *
+ * @param d
+ */
+ public EnsemblXref(String d, String dbSource, String version)
+ {
+ super(d);
+ dbName = dbSource;
+ xrefVersion = dbSource + ":" + version;
+
+ }
+
@Override
public String getDbName()
{
- return "ENSEMBL (xref)";
+ return dbName;
}
@Override
@@ -35,8 +78,7 @@ public class EnsemblXref extends EnsemblRestClient
@Override
protected URL getUrl(List ids) throws MalformedURLException
{
- // TODO Auto-generated method stub
- return null;
+ return getUrl(ids.get(0));
}
@Override
@@ -45,114 +87,88 @@ public class EnsemblXref extends EnsemblRestClient
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
- * name. The "dbname" returned by Ensembl is canonicalised to Jalview's
- * standard version, and a DBRefEntry constructed.
+ * names. The "dbname" returned by Ensembl is canonicalised to Jalview's
+ * standard version, and a DBRefEntry constructed. Currently takes all
+ * identifiers apart from GO terms and synonyms.
*
* @param identifier
- * @param database
+ * an Ensembl stable identifier
* @return
*/
- public List getCrossReferences(String identifier,
- String... database)
+ @SuppressWarnings("unchecked")
+ public List getCrossReferences(String identifier)
{
- List result = new ArrayList();
- List ids = new ArrayList();
+ List result = new ArrayList<>();
+ List ids = new ArrayList<>();
ids.add(identifier);
- BufferedReader br = null;
try
{
- for (String db : database)
+ Iterator