use of uk.ac.ebi.spot.goci.model.RestResponseResult in project goci by EBISPOT.
the class GeneCheckingRestService method checkGeneSymbolIsValid.
/**
* Check gene name returns a response
*
* @param gene Gene name to check
* @return Error message
*/
public String checkGeneSymbolIsValid(String gene, String eRelease) {
String error = null;
try {
RestResponseResult geneDataApiResult = ensemblRestcallHistoryService.getEnsemblRestCallByTypeAndParamAndVersion("lookup_symbol", gene, eRelease);
if (geneDataApiResult == null) {
geneDataApiResult = ensemblRestTemplateService.getRestCall(getEndpoint(), gene, "");
ensemblRestcallHistoryService.create(geneDataApiResult, "lookup_symbol", gene, eRelease);
}
if (geneDataApiResult.hasErorr()) {
error = geneDataApiResult.getError();
} else {
if (geneDataApiResult.getRestResult().getObject().has("object_type")) {
String objectType = geneDataApiResult.getRestResult().getObject().get("object_type").toString();
if (!(objectType.compareToIgnoreCase("gene") == 0)) {
error = "Gene symbol ".concat(gene).concat(" is not valid");
}
}
}
}// The query returns a 400 error if response returns an error
catch (Exception e) {
error = "Gene symbol ".concat(gene).concat(" was not retrieved by Ensembl Mapping. Contact Admin.");
getLog().error("Gene Symbol".concat(gene).concat(" : was not retrieved. (exception)"), e);
}
return error;
}
use of uk.ac.ebi.spot.goci.model.RestResponseResult in project goci by EBISPOT.
the class EnsemblMappingPipeline method checkReportedGenes.
/**
* Check that the reported gene symbols exist and that they are located in the same chromosome as the variant
*
* @param reportedGenes
* @param locations
*/
private void checkReportedGenes(Collection<String> reportedGenes, Collection<Location> locations, String eRelease) throws EnsemblRestIOException {
for (String reportedGene : reportedGenes) {
// Remove extra spaces
reportedGene = reportedGene.replaceAll(" ", "");
// Skip the iteration if the gene name is in the "gene-to-ignore" list
if (!getReportedGenesToIgnore().contains(reportedGene)) {
String webservice = "lookup_symbol";
RestResponseResult reportedGeneApiResult = ensemblRestcallHistoryService.getEnsemblRestCallByTypeAndParamAndVersion("lookup_symbol", reportedGene, eRelease);
if (reportedGeneApiResult == null) {
reportedGeneApiResult = ensemblRestTemplateService.getRestCall(webservice, reportedGene, "");
ensemblRestcallHistoryService.create(reportedGeneApiResult, "lookup_symbol", reportedGene, eRelease);
}
// Check for errors
if (reportedGeneApiResult.getError() != null && !reportedGeneApiResult.getError().isEmpty()) {
getEnsemblMappingResult().addPipelineErrors(reportedGeneApiResult.getError());
}
if (reportedGeneApiResult.getRestResult() != null) {
JSONObject reported_gene_result = reportedGeneApiResult.getRestResult().getObject();
// Check if the gene is in the same chromosome as the variant
if (reported_gene_result.has("seq_region_name")) {
if (locations.size() > 0) {
String gene_chromosome = reported_gene_result.getString("seq_region_name");
int same_chromosome = 0;
for (Location location : locations) {
String snp_chromosome = location.getChromosomeName();
if (gene_chromosome.equals(snp_chromosome)) {
same_chromosome = 1;
break;
}
}
if (same_chromosome == 0) {
getEnsemblMappingResult().addPipelineErrors("Reported gene " + reportedGene + " is on a different chromosome (chr" + gene_chromosome + ")");
}
} else {
getEnsemblMappingResult().addPipelineErrors("Can't compare the " + reportedGene + " location in Ensembl: no mapping available for the variant");
}
} else // No gene location found
{
getEnsemblMappingResult().addPipelineErrors("Can't find a location in Ensembl for the reported gene " + reportedGene);
}
} else {
getLog().error("Reported gene check for " + reportedGene + " returned no result");
}
}
}
}
use of uk.ac.ebi.spot.goci.model.RestResponseResult in project goci by EBISPOT.
the class EnsemblMappingPipeline method run_pipeline.
// Run the pipeline for a given SNP
public synchronized EnsemblMappingResult run_pipeline(String rsId, Collection<String> reportedGenes, String eRelease) throws EnsemblRestIOException {
// Create our result object
setEnsemblMappingResult(new EnsemblMappingResult());
getEnsemblMappingResult().setRsId(rsId);
// Variation call
RestResponseResult variationDataApiResult = ensemblRestcallHistoryService.getEnsemblRestCallByTypeAndParamAndVersion("snp", rsId, eRelease);
if (variationDataApiResult == null) {
variationDataApiResult = ensemblRestTemplateService.getRestCall("variation", rsId, "");
ensemblRestcallHistoryService.create(variationDataApiResult, "snp", rsId, eRelease);
}
String restApiError = variationDataApiResult.getError();
// Check for any errors
if (restApiError != null && !restApiError.isEmpty()) {
getEnsemblMappingResult().addPipelineErrors(restApiError);
}
if (variationDataApiResult.getRestResult() != null) {
JSONObject variationResult = variationDataApiResult.getRestResult().getObject();
if (variationResult.has("error")) {
checkError(variationResult, "variation", "Variant " + rsId + " is not found in Ensembl");
} else if (variationResult.length() > 0) {
// Merged SNP
String currentRsId = variationResult.getString("name");
getEnsemblMappingResult().setMerged((currentRsId.equals(rsId)) ? 0 : 1);
if (getEnsemblMappingResult().getMerged() == 1) {
getEnsemblMappingResult().setCurrentSnpId(currentRsId);
}
// Mapping errors
if (variationResult.has("failed")) {
getEnsemblMappingResult().addPipelineErrors(variationResult.getString("failed"));
}
// Mapping and genomic context calls
JSONArray mappings = variationResult.getJSONArray("mappings");
Collection<Location> locations = getMappings(mappings, eRelease);
getEnsemblMappingResult().setLocations(locations);
// Add genomic context
if (locations.size() > 0) {
// This implies there is at least one variant location.
if (variationResult.has("most_severe_consequence")) {
getEnsemblMappingResult().setFunctionalClass(variationResult.getString("most_severe_consequence"));
}
// Genomic context (loop over the "locations" object)
for (Location snp_location : locations) {
getAllGenomicContexts(snp_location, eRelease);
}
}
}
} else {
getLog().error("Variation call for SNP " + rsId + " returned no result");
}
// Reported genes checks
if (reportedGenes.size() > 0) {
checkReportedGenes(reportedGenes, getEnsemblMappingResult().getLocations(), eRelease);
}
return getEnsemblMappingResult();
}
use of uk.ac.ebi.spot.goci.model.RestResponseResult in project goci by EBISPOT.
the class EnsemblRestTemplateService method getRestCall.
public RestResponseResult getRestCall(String endpoint_type, String data, String rest_parameters) {
String endpoint = getEndpoints().get(endpoint_type);
URL url = null;
RestResponseResult restResponseResult = new RestResponseResult();
try {
// 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 = fetch(url.toString());
} catch (InterruptedException | MalformedURLException 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 EnsemblRestTemplateService method fetch.
public RestResponseResult fetch(String url) throws InterruptedException {
ResponseEntity<String> out;
Boolean ensemblDone = false;
int maxTries = 0;
RestResponseResult ensembl = new RestResponseResult();
while ((!ensemblDone) && (maxTries < 5)) {
ensembl = this.exec(url);
if (ensembl.getStatus() == 429) {
maxTries = maxTries + 1;
Thread.sleep(ensembl.getWaitSeconds() * 1000);
} else {
ensemblDone = true;
}
}
if (maxTries > 4) {
getLog().debug("Failed to obtain a result from from '" + url + "' after after " + maxTries + " attempts");
String extendedError = "Failed to obtain a result from from '" + url + "' after after " + maxTries + " attempts";
ensembl.setError(extendedError);
}
return ensembl;
}
Aggregations