use of uk.ac.ebi.spot.goci.model.RestResponseResult in project goci by EBISPOT.
the class EnsemblRestService method getRestCall.
/**
* Simple generic Ensembl REST API call method.
*
* @param endpoint_type the endpoint name
* @param data the data/id/symbol we want to query
* @param rest_parameters rest parameters
* @return the corresponding result
*/
public RestResponseResult getRestCall(String endpoint_type, String data, String rest_parameters) throws EnsemblRestIOException {
String endpoint = getEndpoints().get(endpoint_type);
URL url = null;
RestResponseResult restResponseResult = new RestResponseResult();
try {
rateLimit();
// Build URL
if (!Objects.equals(rest_parameters, "")) {
Matcher matcher = Pattern.compile("^\\?").matcher(rest_parameters);
if (!matcher.matches()) {
rest_parameters = '?' + rest_parameters;
}
}
url = new URL(getServer() + endpoint + data + rest_parameters);
restResponseResult = fetchJson(url.toString());
} catch (InterruptedException | MalformedURLException | UnirestException e) {
getLog().error("Encountered a " + e.getClass().getSimpleName() + " whilst trying to run mapping of SNP", e);
throw new EnsemblRestIOException("Encountered a " + e.getClass().getSimpleName() + " whilst trying to run mapping of SNP", e);
}
return restResponseResult;
}
use of uk.ac.ebi.spot.goci.model.RestResponseResult in project goci by EBISPOT.
the class EnsemblMappingPipeline method getOverlapRegionCalls.
/**
* Ensembl REST API call for the overlap region endpoint
*
* @param chromosome the chromosome name
* @param position1 the 5' position of the region
* @param position2 the 3' position of the region
* @param rest_opt the extra parameters to add at the end of the REST call url (inherited from other methods)
* @return A JSONArray object containing a list of JSONObjects corresponding to the genes overlapping the region
*/
private JSONArray getOverlapRegionCalls(String chromosome, Integer position1, Integer position2, String rest_opt, String eRelease) throws EnsemblRestIOException {
String data = chromosome + ":" + position1 + "-" + position2;
String param = data.concat("?").concat(rest_opt);
RestResponseResult restResponseResult = ensemblRestcallHistoryService.getEnsemblRestCallByTypeAndParamAndVersion("overlap_region", param, eRelease);
if (restResponseResult == null) {
restResponseResult = ensemblRestTemplateService.getRestCall("overlap_region", data, rest_opt);
ensemblRestcallHistoryService.create(restResponseResult, "overlap_region", param, eRelease);
}
JsonNode result = restResponseResult.getRestResult();
JSONArray overlap_result = new JSONArray();
if (result.isArray()) {
overlap_result = result.getArray();
} else {
// Errors
getEnsemblMappingResult().addPipelineErrors(restResponseResult.getError());
overlap_result = new JSONArray("[{\"overlap_error\":\"1\"}]");
}
return overlap_result;
}
use of uk.ac.ebi.spot.goci.model.RestResponseResult in project goci by EBISPOT.
the class EnsemblMappingPipeline method getChromosomeEnd.
/**
* Get the end position of a given chromosome, using an Ensembl REST API call
*
* @param chromosome the chromosome name
* @return the position of the end of the chromosome
*/
private int getChromosomeEnd(String chromosome, String eRelease) throws EnsemblRestIOException {
int chr_end = 0;
String webservice = "info_assembly";
RestResponseResult restResponseResult = ensemblRestcallHistoryService.getEnsemblRestCallByTypeAndParamAndVersion("info_assembly", chromosome, eRelease);
if (restResponseResult == null) {
restResponseResult = ensemblRestTemplateService.getRestCall(webservice, chromosome, "");
ensemblRestcallHistoryService.create(restResponseResult, "info_assembly", chromosome, eRelease);
}
JSONObject info_result = restResponseResult.getRestResult().getObject();
if (info_result.length() > 0) {
if (info_result.has("length")) {
chr_end = info_result.getInt("length");
}
}
return chr_end;
}
use of uk.ac.ebi.spot.goci.model.RestResponseResult in project goci by EBISPOT.
the class EnsemblRestcallHistoryService method getEnsemblRestCallByTypeAndParamAndVersion.
// BEWARE:If the Ensembl release is valid, the system can try to retrieve the data from the table
public RestResponseResult getEnsemblRestCallByTypeAndParamAndVersion(String type, String param, String eRelease) {
RestResponseResult restResponseResult = null;
// Without release it is pointless stores the info.
if (eRelease != null) {
if (!(eRelease.isEmpty())) {
try {
Collection<EnsemblRestcallHistory> urls = ensemblRestcallHistoryRepository.findByRequestTypeAndEnsemblParamAndEnsemblVersion(type, param, eRelease);
if (urls.size() > 0) {
EnsemblRestcallHistory result = urls.iterator().next();
restResponseResult = new RestResponseResult();
restResponseResult.setUrl(result.getEnsemblUrl());
String restApiError = result.getEnsemblError();
if (restApiError != null && !restApiError.isEmpty()) {
restResponseResult.setError(restApiError);
} else {
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.convertValue(result.getEnsemblResponse().toString(), JsonNode.class);
restResponseResult.setRestResult(jsonNode);
}
}
} catch (Exception e) {
// BEWARE: the following code MUST NOT block Ensembl Rest API Call
}
}
}
return restResponseResult;
}
Aggregations