Search in sources :

Example 6 with GenomicContext

use of uk.ac.ebi.spot.goci.model.GenomicContext in project goci by EBISPOT.

the class SnpInteractionAssociationService method createForm.

// Create a form to return to view from Association model object
@Override
public SnpAssociationForm createForm(Association association) {
    // Create form
    SnpAssociationInteractionForm form = new SnpAssociationInteractionForm();
    // Set simple string and boolean values
    form.setAssociationId(association.getId());
    form.setPvalueDescription(association.getPvalueDescription());
    form.setSnpType(association.getSnpType());
    form.setSnpApproved(association.getSnpApproved());
    form.setPvalueMantissa(association.getPvalueMantissa());
    form.setPvalueExponent(association.getPvalueExponent());
    form.setStandardError(association.getStandardError());
    form.setRange(association.getRange());
    form.setDescription(association.getDescription());
    form.setRiskFrequency(association.getRiskFrequency());
    // Set OR/Beta values
    form.setOrPerCopyNum(association.getOrPerCopyNum());
    form.setOrPerCopyRecip(association.getOrPerCopyRecip());
    form.setOrPerCopyRecipRange(association.getOrPerCopyRecipRange());
    form.setBetaNum(association.getBetaNum());
    form.setBetaUnit(association.getBetaUnit());
    form.setBetaDirection(association.getBetaDirection());
    // Add collection of Efo traits
    form.setEfoTraits(association.getEfoTraits());
    // Create form columns
    List<SnpFormColumn> snpFormColumns = new ArrayList<>();
    // For each locus get genes and risk alleles
    Collection<Locus> loci = association.getLoci();
    Collection<GenomicContext> snpGenomicContexts = new ArrayList<GenomicContext>();
    Collection<SingleNucleotidePolymorphism> snps = new ArrayList<SingleNucleotidePolymorphism>();
    List<SnpMappingForm> snpMappingForms = new ArrayList<SnpMappingForm>();
    // Create a column per locus
    if (loci != null && !loci.isEmpty()) {
        for (Locus locus : loci) {
            SnpFormColumn snpFormColumn = new SnpFormColumn();
            // Set genes
            Collection<String> authorReportedGenes = new ArrayList<>();
            for (Gene gene : locus.getAuthorReportedGenes()) {
                authorReportedGenes.add(gene.getGeneName());
            }
            snpFormColumn.setAuthorReportedGenes(authorReportedGenes);
            // Set risk allele
            Collection<RiskAllele> locusRiskAlleles = locus.getStrongestRiskAlleles();
            String strongestRiskAllele = null;
            String snp = null;
            Collection<String> proxySnps = new ArrayList<>();
            Boolean genomeWide = false;
            Boolean limitedList = false;
            String riskFrequency = null;
            // For snp x snp interaction studies should only have one risk allele per locus
            if (locusRiskAlleles != null && locusRiskAlleles.size() == 1) {
                for (RiskAllele riskAllele : locusRiskAlleles) {
                    strongestRiskAllele = riskAllele.getRiskAlleleName();
                    snp = riskAllele.getSnp().getRsId();
                    SingleNucleotidePolymorphism snp_obj = riskAllele.getSnp();
                    snps.add(snp_obj);
                    Collection<Location> locations = snp_obj.getLocations();
                    for (Location location : locations) {
                        SnpMappingForm snpMappingForm = new SnpMappingForm(snp, location);
                        snpMappingForms.add(snpMappingForm);
                    }
                    snpGenomicContexts.addAll(genomicContextRepository.findBySnpId(snp_obj.getId()));
                    // Set proxy
                    if (riskAllele.getProxySnps() != null) {
                        for (SingleNucleotidePolymorphism riskAlleleProxySnp : riskAllele.getProxySnps()) {
                            proxySnps.add(riskAlleleProxySnp.getRsId());
                        }
                    }
                    if (riskAllele.getGenomeWide() != null && riskAllele.getGenomeWide()) {
                        genomeWide = true;
                    }
                    if (riskAllele.getLimitedList() != null && riskAllele.getLimitedList()) {
                        limitedList = true;
                    }
                    riskFrequency = riskAllele.getRiskFrequency();
                }
            } else {
                throw new RuntimeException("More than one risk allele found for locus " + locus.getId() + ", this is not supported yet for SNP interaction associations");
            }
            // Set column attributes
            snpFormColumn.setStrongestRiskAllele(strongestRiskAllele);
            snpFormColumn.setSnp(snp);
            snpFormColumn.setProxySnps(proxySnps);
            snpFormColumn.setGenomeWide(genomeWide);
            snpFormColumn.setLimitedList(limitedList);
            snpFormColumn.setRiskFrequency(riskFrequency);
            snpFormColumns.add(snpFormColumn);
        }
    }
    form.setSnpMappingForms(snpMappingForms);
    form.setGenomicContexts(snpGenomicContexts);
    form.setSnps(snps);
    form.setSnpFormColumns(snpFormColumns);
    form.setNumOfInteractions(snpFormColumns.size());
    return form;
}
Also used : SnpAssociationInteractionForm(uk.ac.ebi.spot.goci.curation.model.SnpAssociationInteractionForm) RiskAllele(uk.ac.ebi.spot.goci.model.RiskAllele) ArrayList(java.util.ArrayList) GenomicContext(uk.ac.ebi.spot.goci.model.GenomicContext) SnpMappingForm(uk.ac.ebi.spot.goci.curation.model.SnpMappingForm) Gene(uk.ac.ebi.spot.goci.model.Gene) SingleNucleotidePolymorphism(uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism) Locus(uk.ac.ebi.spot.goci.model.Locus) SnpFormColumn(uk.ac.ebi.spot.goci.curation.model.SnpFormColumn) Location(uk.ac.ebi.spot.goci.model.Location)

Example 7 with GenomicContext

use of uk.ac.ebi.spot.goci.model.GenomicContext 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 8 with GenomicContext

use of uk.ac.ebi.spot.goci.model.GenomicContext in project goci by EBISPOT.

the class SnpGenomicContextMappingService method processGenes.

/**
     * Extract gene information from genomic contexts returned from mapping pipeline
     *
     * @param genomicContexts object holding gene and snp mapping information
     */
private void processGenes(Collection<GenomicContext> genomicContexts) {
    getLog().debug("Processing genes...");
    // Need to flatten down genomic context gene information
    // and create structure linking each gene symbol to its
    // complete set of current Ensembl and Entrez IDs
    Map<String, Set<String>> geneToEnsemblIdMap = new HashMap<>();
    Map<String, Set<String>> geneToEntrezIdMap = new HashMap<>();
    // Loop over each genomic context and store information on external IDs linked to gene symbol
    for (GenomicContext genomicContext : genomicContexts) {
        // Check gene exists
        String geneName = genomicContext.getGene().getGeneName().trim();
        if (!geneName.equalsIgnoreCase("undefined")) {
            // Retrieve the latest Ensembl/Entrez IDs for the named gene from the latest mapping run
            Collection<EnsemblGene> ensemblGeneIds = genomicContext.getGene().getEnsemblGeneIds();
            for (EnsemblGene ensemblGene : ensemblGeneIds) {
                String ensemblId = ensemblGene.getEnsemblGeneId();
                if (ensemblId != null) {
                    if (geneToEnsemblIdMap.containsKey(geneName)) {
                        geneToEnsemblIdMap.get(geneName).add(ensemblId);
                    } else {
                        Set<String> ensemblGeneIdsSet = new HashSet<>();
                        ensemblGeneIdsSet.add(ensemblId);
                        geneToEnsemblIdMap.put(geneName, ensemblGeneIdsSet);
                    }
                }
            }
            Collection<EntrezGene> entrezGeneIds = genomicContext.getGene().getEntrezGeneIds();
            for (EntrezGene entrezGene : entrezGeneIds) {
                String entrezId = entrezGene.getEntrezGeneId();
                if (entrezId != null) {
                    if (geneToEntrezIdMap.containsKey(geneName)) {
                        geneToEntrezIdMap.get(geneName).add(entrezId);
                    } else {
                        Set<String> entrezGeneIdsSet = new HashSet<>();
                        entrezGeneIdsSet.add(entrezId);
                        geneToEntrezIdMap.put(geneName, entrezGeneIdsSet);
                    }
                }
            }
        }
    }
    // Store genes, source is required so we know what table to add them to
    if (geneToEnsemblIdMap.size() > 0) {
        storeGenes(geneToEnsemblIdMap, "Ensembl");
    }
    if (geneToEntrezIdMap.size() > 0) {
        storeGenes(geneToEntrezIdMap, "Entrez");
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) EntrezGene(uk.ac.ebi.spot.goci.model.EntrezGene) GenomicContext(uk.ac.ebi.spot.goci.model.GenomicContext) EnsemblGene(uk.ac.ebi.spot.goci.model.EnsemblGene) HashSet(java.util.HashSet)

Example 9 with GenomicContext

use of uk.ac.ebi.spot.goci.model.GenomicContext in project goci by EBISPOT.

the class SnpGenomicContextMappingService method processGenomicContext.

/**
     * Takes genomic context information returned by mapping pipeline and creates a structure that links an rs_id to all
     * its genomic context objects. This ensures we can do a single update based on latest mapping information.
     *
     * @param genomicContexts object holding gene and snp mapping information
     */
public void processGenomicContext(Collection<GenomicContext> genomicContexts) {
    // Process the gene information first so all IDs can be updated and any new genes created
    processGenes(genomicContexts);
    // Need flatten down genomic context information
    // and create structure linking each RS_ID to its complete set of new mapped data
    getLog().debug("Collate all new genomic context information...");
    Map<String, Set<GenomicContext>> snpToGenomicContextMap = new HashMap<>();
    for (GenomicContext genomicContext : genomicContexts) {
        String snpIdInGenomicContext = genomicContext.getSnp().getRsId();
        // Next time we see SNP, add genomic context to set
        if (snpToGenomicContextMap.containsKey(snpIdInGenomicContext)) {
            snpToGenomicContextMap.get(snpIdInGenomicContext).add(genomicContext);
        } else // First time we see a SNP store the genomic context
        {
            Set<GenomicContext> snpGenomicContext = new HashSet<>();
            snpGenomicContext.add(genomicContext);
            snpToGenomicContextMap.put(snpIdInGenomicContext, snpGenomicContext);
        }
    }
    // Store genomic context information
    getLog().debug("Storing new genomic context information...");
    storeSnpGenomicContext(snpToGenomicContextMap);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) GenomicContext(uk.ac.ebi.spot.goci.model.GenomicContext) HashSet(java.util.HashSet)

Aggregations

GenomicContext (uk.ac.ebi.spot.goci.model.GenomicContext)9 Gene (uk.ac.ebi.spot.goci.model.Gene)5 SingleNucleotidePolymorphism (uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism)5 ArrayList (java.util.ArrayList)4 Location (uk.ac.ebi.spot.goci.model.Location)4 HashSet (java.util.HashSet)3 Locus (uk.ac.ebi.spot.goci.model.Locus)3 HashMap (java.util.HashMap)2 Set (java.util.Set)2 SnpMappingForm (uk.ac.ebi.spot.goci.curation.model.SnpMappingForm)2 EnsemblGene (uk.ac.ebi.spot.goci.model.EnsemblGene)2 EntrezGene (uk.ac.ebi.spot.goci.model.EntrezGene)2 RiskAllele (uk.ac.ebi.spot.goci.model.RiskAllele)2 Date (java.util.Date)1 JSONObject (org.json.JSONObject)1 SnpAssociationInteractionForm (uk.ac.ebi.spot.goci.curation.model.SnpAssociationInteractionForm)1 SnpAssociationStandardMultiForm (uk.ac.ebi.spot.goci.curation.model.SnpAssociationStandardMultiForm)1 SnpFormColumn (uk.ac.ebi.spot.goci.curation.model.SnpFormColumn)1 SnpFormRow (uk.ac.ebi.spot.goci.curation.model.SnpFormRow)1 EnsemblMappingException (uk.ac.ebi.spot.goci.exception.EnsemblMappingException)1