use of uk.ac.ebi.spot.goci.exception.EnsemblMappingException in project goci by EBISPOT.
the class MappingService method validateAndMapAssociation.
/**
* Perform validation and mapping of association
*
* @param association Association to map
* @param performer name of curator/job carrying out the mapping
* @param user
*/
@Transactional(rollbackFor = EnsemblMappingException.class)
public void validateAndMapAssociation(Association association, String performer, SecureUser user) throws EnsemblMappingException {
String eRelease = this.getEnsemblRelease();
try {
doMapping(association, eRelease);
// Update mapping event
trackingOperationService.update(association, user, "ASSOCIATION_MAPPING");
// Once mapping is complete, update mapping record
getLog().debug("Update mapping record");
mappingRecordService.updateAssociationMappingRecord(association, new Date(), performer);
} catch (EnsemblMappingException e) {
throw new EnsemblMappingException("Attempt to map supplied association failed", e);
}
}
use of uk.ac.ebi.spot.goci.exception.EnsemblMappingException in project goci by EBISPOT.
the class MappingService method doMapping.
private void doMapping(Association association, String eRelease) throws EnsemblMappingException {
getLog().info("Mapping association: " + association.getId());
// Map to store returned location data, this is used in
// snpLocationMappingService to process all locations linked
// to a single snp in one go
Map<String, Set<Location>> snpToLocationsMap = new HashMap<>();
// Collection to store all genomic contexts
Collection<GenomicContext> allGenomicContexts = new ArrayList<>();
// Collection to store all errors for one association
Collection<String> associationPipelineErrors = new ArrayList<>();
// For each loci get the SNP and author reported genes
Collection<Locus> studyAssociationLoci = association.getLoci();
for (Locus associationLocus : studyAssociationLoci) {
Long locusId = associationLocus.getId();
Collection<SingleNucleotidePolymorphism> snpsLinkedToLocus = singleNucleotidePolymorphismQueryService.findByRiskAllelesLociId(locusId);
Collection<Gene> authorReportedGenesLinkedToSnp = associationLocus.getAuthorReportedGenes();
// Get gene names
Collection<String> authorReportedGeneNamesLinkedToSnp = new ArrayList<>();
for (Gene authorReportedGeneLinkedToSnp : authorReportedGenesLinkedToSnp) {
authorReportedGeneNamesLinkedToSnp.add(authorReportedGeneLinkedToSnp.getGeneName().trim());
}
// Pass rs_id and author reported genes to mapping component
for (SingleNucleotidePolymorphism snpLinkedToLocus : snpsLinkedToLocus) {
String snpRsId = snpLinkedToLocus.getRsId();
EnsemblMappingResult ensemblMappingResult = new EnsemblMappingResult();
// Try to map supplied data
try {
getLog().debug("Running mapping....");
ensemblMappingResult = ensemblMappingPipeline.run_pipeline(snpRsId, authorReportedGeneNamesLinkedToSnp, eRelease);
} catch (Exception e) {
getLog().error("Encountered a " + e.getClass().getSimpleName() + " whilst trying to run mapping of SNP " + snpRsId + ", found in association: " + association.getId(), e);
throw new EnsemblMappingException();
}
getLog().debug("Mapping complete");
// First remove old locations and genomic contexts
snpLocationMappingService.removeExistingSnpLocations(snpLinkedToLocus);
snpGenomicContextMappingService.removeExistingGenomicContexts(snpLinkedToLocus);
Collection<Location> locations = ensemblMappingResult.getLocations();
Collection<GenomicContext> snpGenomicContexts = ensemblMappingResult.getGenomicContexts();
ArrayList<String> pipelineErrors = ensemblMappingResult.getPipelineErrors();
// Update functional class
snpLinkedToLocus.setFunctionalClass(ensemblMappingResult.getFunctionalClass());
snpLinkedToLocus.setLastUpdateDate(new Date());
snpLinkedToLocus.setMerged(Long.valueOf(ensemblMappingResult.getMerged()));
// Update the merge table
if (ensemblMappingResult.getMerged() == 1) {
String currentSnpId = ensemblMappingResult.getCurrentSnpId();
SingleNucleotidePolymorphism currentSnp = singleNucleotidePolymorphismRepository.findByRsId(currentSnpId);
// Add the current SingleNucleotidePolymorphism to the "merged" rsID
if (currentSnp == null) {
currentSnp = new SingleNucleotidePolymorphism();
currentSnp.setRsId(currentSnpId);
currentSnp.setFunctionalClass(snpLinkedToLocus.getFunctionalClass());
singleNucleotidePolymorphismRepository.save(currentSnp);
currentSnp = singleNucleotidePolymorphismRepository.findByRsId(currentSnpId);
}
snpLinkedToLocus.setCurrentSnp(currentSnp);
}
singleNucleotidePolymorphismRepository.save(snpLinkedToLocus);
// Store location information for SNP
if (!locations.isEmpty()) {
for (Location location : locations) {
// This would only occur is SNP has multiple locations
if (snpToLocationsMap.containsKey(snpRsId)) {
snpToLocationsMap.get(snpRsId).add(location);
} else // First time we see a SNP store the location
{
Set<Location> snpLocation = new HashSet<>();
snpLocation.add(location);
snpToLocationsMap.put(snpRsId, snpLocation);
}
}
} else {
getLog().warn("Attempt to map SNP: " + snpRsId + " returned no location details");
pipelineErrors.add("Attempt to map SNP: " + snpRsId + " returned no location details");
}
// Store genomic context data for snp
if (!snpGenomicContexts.isEmpty()) {
allGenomicContexts.addAll(snpGenomicContexts);
} else {
getLog().warn("Attempt to map SNP: " + snpRsId + " returned no mapped genes");
pipelineErrors.add("Attempt to map SNP: " + snpRsId + " returned no mapped genes");
}
if (!pipelineErrors.isEmpty()) {
associationPipelineErrors.addAll(pipelineErrors);
}
}
}
// Create association report based on whether there is errors or not
if (!associationPipelineErrors.isEmpty()) {
associationReportService.processAssociationErrors(association, associationPipelineErrors);
} else {
associationReportService.updateAssociationReportDetails(association);
}
// Save data
if (!snpToLocationsMap.isEmpty()) {
getLog().debug("Updating location details ...");
snpLocationMappingService.storeSnpLocation(snpToLocationsMap);
getLog().debug("Updating location details complete");
}
if (!allGenomicContexts.isEmpty()) {
getLog().debug("Updating genomic context details ...");
snpGenomicContextMappingService.processGenomicContext(allGenomicContexts);
getLog().debug("Updating genomic context details complete");
}
}
use of uk.ac.ebi.spot.goci.exception.EnsemblMappingException in project goci by EBISPOT.
the class AssociationController method addSnpInteraction.
@RequestMapping(value = "/studies/{studyId}/associations/add_interaction", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST)
public String addSnpInteraction(@ModelAttribute("form") @Valid SnpAssociationInteractionForm snpAssociationInteractionForm, BindingResult bindingResult, @PathVariable Long studyId, Model model, @RequestParam(required = true) String measurementType, HttpServletRequest request) throws EnsemblMappingException {
Study study = studyRepository.findOne(studyId);
model.addAttribute("study", study);
model.addAttribute("measurementType", measurementType);
// Binding vs Validator issue. File: messages.properties
if (bindingResult.hasErrors()) {
model.addAttribute("form", snpAssociationInteractionForm);
return "add_snp_interaction_association";
}
// Check for errors in form that would prevent saving an association
List<AssociationValidationView> colErrors = associationOperationsService.checkSnpAssociationInteractionFormErrors(snpAssociationInteractionForm, measurementType);
if (!colErrors.isEmpty()) {
model.addAttribute("errors", colErrors);
model.addAttribute("form", snpAssociationInteractionForm);
model.addAttribute("criticalErrorsFound", true);
return "add_snp_interaction_association";
} else {
// Create an association object from details in returned form
Association newAssociation = snpInteractionAssociationService.createAssociation(snpAssociationInteractionForm);
// Save and validate form
Collection<AssociationValidationView> errors = null;
String eRelease = ensemblRestTemplateService.getRelease();
try {
errors = associationOperationsService.saveAssociationCreatedFromForm(study, newAssociation, currentUserDetailsService.getUserFromRequest(request), eRelease);
} catch (EnsemblMappingException e) {
return "ensembl_mapping_failure";
}
// Determine if we have any errors rather than warnings
long errorCount = errors.stream().filter(validationError -> !validationError.getWarning()).count();
if (errorCount > 0) {
model.addAttribute("errors", errors);
model.addAttribute("form", snpAssociationInteractionForm);
model.addAttribute("criticalErrorsFound", true);
return "add_snp_interaction_association";
} else {
return "redirect:/associations/" + newAssociation.getId();
}
}
}
Aggregations