+ }
+ return species;
+ }
+
+ /**
+ * Calls the /lookup/id rest service and returns the response as a Map<String, Object>,
+ * or null if any error
+ *
+ * @param identifier
+ * @param objectType
+ * (optional)
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ protected Map<String, Object> getResult(String identifier, String objectType)
+ {
+ List<String> ids = Arrays.asList(new String[] { identifier });
+
+ try
+ {
+ return (Map<String, Object>) getJSON(getUrl(identifier, objectType), ids, -1, MODE_MAP, null);
+ }
+ catch (IOException | ParseException e)
+ {
+ System.err.println("Error parsing " + identifier + " lookup response "
+ + e.getMessage());
+ return null;
+ }
+ }
+
+ /**
+ * Calls the /lookup/id rest service for the given id, and if successful,
+ * parses and returns the gene's chromosomal coordinates
+ *
+ * @param geneId
+ * @return
+ */
+ public GeneLociI getGeneLoci(String geneId)
+ {
+ return parseGeneLoci(getResult(geneId, OBJECT_TYPE_GENE));
+ }
+
+ /**
+ * Parses the /lookup/id response for species, asssembly_name,
+ * seq_region_name, start, end and returns an object that wraps them, or null
+ * if unsuccessful
+ *
+ * @param json
+ * @return
+ */
+ GeneLociI parseGeneLoci(Map<String, Object> json)
+ {
+ if (json == null)
+ {
+ return null;
+ }
+
+ try
+ {
+ final String species = json.get("species").toString();
+ final String assembly = json.get("assembly_name").toString();
+ final String chromosome = json.get("seq_region_name").toString();
+ String strand = json.get("strand").toString();
+ int start = Integer.parseInt(json.get("start").toString());
+ int end = Integer.parseInt(json.get("end").toString());
+ int fromEnd = end - start + 1;
+ boolean reverseStrand = "-1".equals(strand);
+ int toStart = reverseStrand ? end : start;
+ int toEnd = reverseStrand ? start : end;
+ List<int[]> fromRange = Collections.singletonList(new int[] { 1,
+ fromEnd });
+ List<int[]> toRange = Collections.singletonList(new int[] { toStart,
+ toEnd });
+ final MapList map = new MapList(fromRange, toRange, 1, 1);
+ return new GeneLociI()