Search in sources :

Example 11 with EnsemblMappingException

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);
    }
}
Also used : EnsemblMappingException(uk.ac.ebi.spot.goci.exception.EnsemblMappingException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with EnsemblMappingException

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");
    }
}
Also used : GenomicContext(uk.ac.ebi.spot.goci.model.GenomicContext) EnsemblMappingException(uk.ac.ebi.spot.goci.exception.EnsemblMappingException) EnsemblMappingResult(uk.ac.ebi.spot.goci.model.EnsemblMappingResult) Gene(uk.ac.ebi.spot.goci.model.Gene) SingleNucleotidePolymorphism(uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism) Locus(uk.ac.ebi.spot.goci.model.Locus) EnsemblMappingException(uk.ac.ebi.spot.goci.exception.EnsemblMappingException) Location(uk.ac.ebi.spot.goci.model.Location)

Example 13 with EnsemblMappingException

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();
        }
    }
}
Also used : FileUploadException(uk.ac.ebi.spot.goci.curation.exception.FileUploadException) java.util(java.util) SnpAssociationTableView(uk.ac.ebi.spot.goci.curation.model.SnpAssociationTableView) LoggerFactory(org.slf4j.LoggerFactory) SnpAssociationInteractionForm(uk.ac.ebi.spot.goci.curation.model.SnpAssociationInteractionForm) Autowired(org.springframework.beans.factory.annotation.Autowired) SimpleDateFormat(java.text.SimpleDateFormat) BindingResult(org.springframework.validation.BindingResult) Controller(org.springframework.stereotype.Controller) SnpAssociationStandardMultiForm(uk.ac.ebi.spot.goci.curation.model.SnpAssociationStandardMultiForm) EfoTraitRepository(uk.ac.ebi.spot.goci.repository.EfoTraitRepository) Value(org.springframework.beans.factory.annotation.Value) Valid(javax.validation.Valid) Model(org.springframework.ui.Model) uk.ac.ebi.spot.goci.curation.service(uk.ac.ebi.spot.goci.curation.service) HttpServletRequest(javax.servlet.http.HttpServletRequest) uk.ac.ebi.spot.goci.model(uk.ac.ebi.spot.goci.model) Qualifier(org.springframework.beans.factory.annotation.Qualifier) StudyRepository(uk.ac.ebi.spot.goci.repository.StudyRepository) Sort(org.springframework.data.domain.Sort) EnsemblRestTemplateService(uk.ac.ebi.spot.goci.service.EnsemblRestTemplateService) DateFormat(java.text.DateFormat) RedirectAttributes(org.springframework.web.servlet.mvc.support.RedirectAttributes) DataIntegrityException(uk.ac.ebi.spot.goci.curation.exception.DataIntegrityException) Logger(org.slf4j.Logger) AssociationRepository(uk.ac.ebi.spot.goci.repository.AssociationRepository) MediaType(org.springframework.http.MediaType) HttpServletResponse(javax.servlet.http.HttpServletResponse) SnpAssociationForm(uk.ac.ebi.spot.goci.curation.model.SnpAssociationForm) EnsemblMappingException(uk.ac.ebi.spot.goci.exception.EnsemblMappingException) SheetProcessingException(uk.ac.ebi.spot.goci.exception.SheetProcessingException) IOException(java.io.IOException) SnpFormColumn(uk.ac.ebi.spot.goci.curation.model.SnpFormColumn) AssociationUploadErrorView(uk.ac.ebi.spot.goci.curation.model.AssociationUploadErrorView) FileNotFoundException(java.io.FileNotFoundException) MapCatalogService(uk.ac.ebi.spot.goci.service.MapCatalogService) GetRequest(com.mashape.unirest.request.GetRequest) SnpFormRow(uk.ac.ebi.spot.goci.curation.model.SnpFormRow) WebDataBinder(org.springframework.web.bind.WebDataBinder) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) LastViewedAssociation(uk.ac.ebi.spot.goci.curation.model.LastViewedAssociation) MultipartFile(org.springframework.web.multipart.MultipartFile) AssociationValidationView(uk.ac.ebi.spot.goci.curation.model.AssociationValidationView) MappingDetails(uk.ac.ebi.spot.goci.curation.model.MappingDetails) LastViewedAssociation(uk.ac.ebi.spot.goci.curation.model.LastViewedAssociation) AssociationValidationView(uk.ac.ebi.spot.goci.curation.model.AssociationValidationView) EnsemblMappingException(uk.ac.ebi.spot.goci.exception.EnsemblMappingException)

Aggregations

EnsemblMappingException (uk.ac.ebi.spot.goci.exception.EnsemblMappingException)13 Autowired (org.springframework.beans.factory.annotation.Autowired)7 Qualifier (org.springframework.beans.factory.annotation.Qualifier)7 IOException (java.io.IOException)6 java.util (java.util)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 MultipartFile (org.springframework.web.multipart.MultipartFile)6 AssociationUploadErrorView (uk.ac.ebi.spot.goci.curation.model.AssociationUploadErrorView)6 AssociationValidationView (uk.ac.ebi.spot.goci.curation.model.AssociationValidationView)6 LastViewedAssociation (uk.ac.ebi.spot.goci.curation.model.LastViewedAssociation)6 MappingDetails (uk.ac.ebi.spot.goci.curation.model.MappingDetails)6 SnpAssociationForm (uk.ac.ebi.spot.goci.curation.model.SnpAssociationForm)6 SnpAssociationInteractionForm (uk.ac.ebi.spot.goci.curation.model.SnpAssociationInteractionForm)6 SnpAssociationStandardMultiForm (uk.ac.ebi.spot.goci.curation.model.SnpAssociationStandardMultiForm)6 SnpFormColumn (uk.ac.ebi.spot.goci.curation.model.SnpFormColumn)6 SnpFormRow (uk.ac.ebi.spot.goci.curation.model.SnpFormRow)6 uk.ac.ebi.spot.goci.model (uk.ac.ebi.spot.goci.model)6 GetRequest (com.mashape.unirest.request.GetRequest)5 FileNotFoundException (java.io.FileNotFoundException)5