git://source.jalview.org
/
jalview.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
9587a72
)
JAL-2755 add species lookup
author
gmungoc
<g.m.carstairs@dundee.ac.uk>
Thu, 19 Oct 2017 14:00:34 +0000
(15:00 +0100)
committer
gmungoc
<g.m.carstairs@dundee.ac.uk>
Thu, 19 Oct 2017 14:00:34 +0000
(15:00 +0100)
src/jalview/ext/ensembl/EnsemblLookup.java
patch
|
blob
|
history
diff --git
a/src/jalview/ext/ensembl/EnsemblLookup.java
b/src/jalview/ext/ensembl/EnsemblLookup.java
index
eb8f90e
..
0968663
100644
(file)
--- a/
src/jalview/ext/ensembl/EnsemblLookup.java
+++ b/
src/jalview/ext/ensembl/EnsemblLookup.java
@@
-42,6
+42,9
@@
import org.json.simple.parser.ParseException;
*/
public class EnsemblLookup extends EnsemblRestClient
{
*/
public class EnsemblLookup extends EnsemblRestClient
{
+ private static final String SPECIES = "species";
+
+ private static final String PARENT = "Parent";
/**
* Default constructor (to use rest.ensembl.org)
/**
* Default constructor (to use rest.ensembl.org)
@@
-124,6
+127,28
@@
public class EnsemblLookup extends EnsemblRestClient
*/
public String getParent(String identifier)
{
*/
public String getParent(String identifier)
{
+ return getAttribute(identifier, PARENT);
+ }
+
+ /**
+ * Calls the Ensembl lookup REST endpoint and retrieves the 'species' for the
+ * given identifier, or null if not found
+ *
+ * @param identifier
+ * @return
+ */
+ public String getSpecies(String identifier)
+ {
+ return getAttribute(identifier, SPECIES);
+ }
+
+ /**
+ * @param identifier
+ * @param attribute
+ * @return
+ */
+ protected String getAttribute(String identifier, String attribute)
+ {
List<String> ids = Arrays.asList(new String[] { identifier });
BufferedReader br = null;
List<String> ids = Arrays.asList(new String[] { identifier });
BufferedReader br = null;
@@
-134,7
+159,7
@@
public class EnsemblLookup extends EnsemblRestClient
{
br = getHttpResponse(url, ids);
}
{
br = getHttpResponse(url, ids);
}
- return (parseResponse(br));
+ return (parseResponse(br, attribute));
} catch (IOException e)
{
// ignore
} catch (IOException e)
{
// ignore
@@
-155,22
+180,23
@@
public class EnsemblLookup extends EnsemblRestClient
}
/**
}
/**
- * Parses "Parent" from the JSON response and returns the value, or null if
- * not found
+ * Parses the value of 'attribute' from the JSON response and returns the
+ * value, or null if not found
*
* @param br
*
* @param br
+ * @param attribute
* @return
* @throws IOException
*/
* @return
* @throws IOException
*/
- protected String parseResponse(BufferedReader br) throws IOException
+ protected String parseResponse(BufferedReader br, String attribute) throws IOException
{
String parent = null;
JSONParser jp = new JSONParser();
try
{
JSONObject val = (JSONObject) jp.parse(br);
{
String parent = null;
JSONParser jp = new JSONParser();
try
{
JSONObject val = (JSONObject) jp.parse(br);
- parent = val.get("Parent").toString();
- } catch (ParseException e)
+ parent = val.get(attribute).toString();
+ } catch (ParseException | NullPointerException e)
{
// ignore
}
{
// ignore
}