Search in sources :

Example 1 with Location

use of uk.ac.ebi.spot.goci.model.Location 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");
            }
        }
    }
}
Also used : JSONObject(org.json.JSONObject) RestResponseResult(uk.ac.ebi.spot.goci.model.RestResponseResult) Location(uk.ac.ebi.spot.goci.model.Location)

Example 2 with Location

use of uk.ac.ebi.spot.goci.model.Location 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();
}
Also used : EnsemblMappingResult(uk.ac.ebi.spot.goci.model.EnsemblMappingResult) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Collection(java.util.Collection) RestResponseResult(uk.ac.ebi.spot.goci.model.RestResponseResult) Location(uk.ac.ebi.spot.goci.model.Location)

Example 3 with Location

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

the class EnsemblMappingPipeline method getMappings.

/**
     * Get the mappings data ( chromosome, position and cytogenetic band). Store the location information in the class
     * variable "locations" (list of "Location" classes)
     *
     * @param mappings A JSONArray object containing the list the variant locations
     */
private Collection<Location> getMappings(JSONArray mappings, String eRelease) throws EnsemblRestIOException {
    Collection<Location> locations = new ArrayList<>();
    for (int i = 0; i < mappings.length(); ++i) {
        JSONObject mapping = mappings.getJSONObject(i);
        if (!mapping.has("seq_region_name")) {
            continue;
        }
        String chromosome = mapping.getString("seq_region_name");
        Integer position = Integer.valueOf(mapping.getInt("start"));
        Region cytogeneticBand = getRegion(chromosome, position, eRelease);
        Location location = new Location(chromosome, position, cytogeneticBand);
        locations.add(location);
    }
    return locations;
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) Region(uk.ac.ebi.spot.goci.model.Region) Location(uk.ac.ebi.spot.goci.model.Location)

Example 4 with Location

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

the class SnpGenomicContextMappingService method storeSnpGenomicContext.

/**
     * Saves genomic context information to database
     *
     * @param snpToGenomicContextMap map of rs_id and all genomic context details returned from current mapping run
     */
private void storeSnpGenomicContext(Map<String, Set<GenomicContext>> snpToGenomicContextMap) {
    // Go through each rs_id and its associated genomic contexts returned from the mapping pipeline
    for (String snpRsId : snpToGenomicContextMap.keySet()) {
        getLog().debug("Storing genomic context for " + snpRsId);
        Set<GenomicContext> genomicContextsFromMapping = snpToGenomicContextMap.get(snpRsId);
        // Check if the SNP exists
        SingleNucleotidePolymorphism snpInDatabase = singleNucleotidePolymorphismQueryService.findByRsIdIgnoreCase(snpRsId);
        if (snpInDatabase != null) {
            Collection<GenomicContext> newSnpGenomicContexts = new ArrayList<>();
            for (GenomicContext genomicContextFromMapping : genomicContextsFromMapping) {
                // Gene should already have been created
                String geneName = genomicContextFromMapping.getGene().getGeneName().trim();
                if (!geneName.equalsIgnoreCase("undefined")) {
                    // Create new genomic context
                    Boolean isIntergenic = genomicContextFromMapping.getIsIntergenic();
                    Boolean isUpstream = genomicContextFromMapping.getIsUpstream();
                    Boolean isDownstream = genomicContextFromMapping.getIsDownstream();
                    Long distance = genomicContextFromMapping.getDistance();
                    String source = genomicContextFromMapping.getSource();
                    String mappingMethod = genomicContextFromMapping.getMappingMethod();
                    Boolean isClosestGene = genomicContextFromMapping.getIsClosestGene();
                    // Location details
                    String chromosomeName = genomicContextFromMapping.getLocation().getChromosomeName();
                    Integer chromosomePosition = genomicContextFromMapping.getLocation().getChromosomePosition();
                    Region regionFromMapping = genomicContextFromMapping.getLocation().getRegion();
                    String regionName = null;
                    if (regionFromMapping.getName() != null) {
                        regionName = regionFromMapping.getName().trim();
                    }
                    // Check if location already exists
                    Location location = locationRepository.findByChromosomeNameAndChromosomePositionAndRegionName(chromosomeName, chromosomePosition, regionName);
                    if (location == null) {
                        location = locationCreationService.createLocation(chromosomeName, chromosomePosition, regionName);
                    }
                    GenomicContext genomicContext = genomicContextCreationService.createGenomicContext(isIntergenic, isUpstream, isDownstream, distance, source, mappingMethod, geneName, snpInDatabase, isClosestGene, location);
                    newSnpGenomicContexts.add(genomicContext);
                } else {
                    getLog().warn("Gene name returned from mapping pipeline is 'undefined' for SNP" + snpInDatabase.getRsId());
                }
            }
            // Save latest mapped information
            snpInDatabase.setGenomicContexts(newSnpGenomicContexts);
            // Update the last update date
            snpInDatabase.setLastUpdateDate(new Date());
            singleNucleotidePolymorphismRepository.save(snpInDatabase);
        } else // SNP doesn't exist, this should be extremely rare as SNP value is a copy
        // of the variant entered by the curator which
        // by the time mapping is started should already have been saved
        {
            // TODO WHAT WILL HAPPEN FOR MERGED SNPS
            getLog().error("Adding genomic context for SNP not found in database, RS_ID:" + snpRsId);
            throw new RuntimeException("Adding genomic context for SNP not found in database, RS_ID: " + snpRsId);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) GenomicContext(uk.ac.ebi.spot.goci.model.GenomicContext) Date(java.util.Date) SingleNucleotidePolymorphism(uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism) Region(uk.ac.ebi.spot.goci.model.Region) Location(uk.ac.ebi.spot.goci.model.Location)

Example 5 with Location

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

the class DefaultGWASOWLConverter method convertSNP.

protected void convertSNP(SingleNucleotidePolymorphism snp, OWLOntology ontology) {
    // get the snp class
    OWLClass snpClass = getDataFactory().getOWLClass(IRI.create(OntologyConstants.SNP_CLASS_IRI));
    // create a new snp instance
    OWLNamedIndividual snpIndiv = getDataFactory().getOWLNamedIndividual(getMinter().mint(OntologyConstants.GWAS_ONTOLOGY_BASE_IRI, snp));
    // assert class membership
    OWLClassAssertionAxiom classAssertion = getDataFactory().getOWLClassAssertionAxiom(snpClass, snpIndiv);
    getManager().addAxiom(ontology, classAssertion);
    // add datatype properties...
    // get datatype relations
    OWLDataProperty has_snp_rsid = getDataFactory().getOWLDataProperty(IRI.create(OntologyConstants.HAS_SNP_REFERENCE_ID_PROPERTY_IRI));
    OWLDataProperty has_bp_pos = getDataFactory().getOWLDataProperty(IRI.create(OntologyConstants.HAS_BP_POSITION_PROPERTY_IRI));
    // get annotation relations
    OWLAnnotationProperty rdfsLabel = getDataFactory().getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI());
    // assert rsid relation
    OWLLiteral rsid = getDataFactory().getOWLLiteral(snp.getRsId());
    OWLDataPropertyAssertionAxiom rsid_relation = getDataFactory().getOWLDataPropertyAssertionAxiom(has_snp_rsid, snpIndiv, rsid);
    AddAxiom add_rsid = new AddAxiom(ontology, rsid_relation);
    getManager().applyChange(add_rsid);
    // assert bp_pos relation
    if (snp.getLocations() != null) {
        for (Location snpLocation : snp.getLocations()) {
            if (snpLocation.getChromosomePosition() != null) {
                OWLLiteral bp_pos = //                            getDataFactory().getOWLLiteral(snpLocation.getChromosomePosition(), OWL2Datatype.XSD_INT);
                getDataFactory().getOWLLiteral(snpLocation.getChromosomePosition());
                OWLDataPropertyAssertionAxiom bp_pos_relation = getDataFactory().getOWLDataPropertyAssertionAxiom(has_bp_pos, snpIndiv, bp_pos);
                AddAxiom add_bp_pos = new AddAxiom(ontology, bp_pos_relation);
                getManager().applyChange(add_bp_pos);
            }
        }
    } else {
        getLog().debug("No SNP location available for SNP " + rsid);
    }
    // assert label
    OWLAnnotationAssertionAxiom snp_label_annotation = getDataFactory().getOWLAnnotationAssertionAxiom(rdfsLabel, snpIndiv.getIRI(), rsid);
    AddAxiom add_snp_label = new AddAxiom(ontology, snp_label_annotation);
    getManager().applyChange(add_snp_label);
    // get the band class
    OWLClass bandClass = getDataFactory().getOWLClass(IRI.create(OntologyConstants.CYTOGENIC_REGION_CLASS_IRI));
    // get datatype relations
    OWLDataProperty has_name = getDataFactory().getOWLDataProperty(IRI.create(OntologyConstants.HAS_NAME_PROPERTY_IRI));
    // get object relations
    OWLObjectProperty located_in = getDataFactory().getOWLObjectProperty(IRI.create(OntologyConstants.LOCATED_IN_PROPERTY_IRI));
    OWLObjectProperty location_of = getDataFactory().getOWLObjectProperty(IRI.create(OntologyConstants.LOCATION_OF_PROPERTY_IRI));
    // get datatype relations
    OWLDataProperty has_chr_name = getDataFactory().getOWLDataProperty(IRI.create(OntologyConstants.HAS_NAME_PROPERTY_IRI));
    // get object properties
    OWLObjectProperty has_part = getDataFactory().getOWLObjectProperty(IRI.create(OntologyConstants.HAS_PART_PROPERTY_IRI));
    OWLObjectProperty part_of = getDataFactory().getOWLObjectProperty(IRI.create(OntologyConstants.PART_OF_PROPERTY_IRI));
    for (Location location : snp.getLocations()) {
        Region region = location.getRegion();
        if (region.getName() != null) {
            // create a new band individual
            OWLNamedIndividual bandIndiv = getDataFactory().getOWLNamedIndividual(getMinter().mint(OntologyConstants.GWAS_ONTOLOGY_BASE_IRI, "CytogeneticRegion", region.getName()));
            // assert class membership
            OWLClassAssertionAxiom bandClassAssertion = getDataFactory().getOWLClassAssertionAxiom(bandClass, bandIndiv);
            getManager().addAxiom(ontology, bandClassAssertion);
            // assert name relation
            OWLLiteral name = getDataFactory().getOWLLiteral(region.getName());
            OWLDataPropertyAssertionAxiom name_relation = getDataFactory().getOWLDataPropertyAssertionAxiom(has_name, bandIndiv, name);
            AddAxiom add_name = new AddAxiom(ontology, name_relation);
            getManager().applyChange(add_name);
            // assert label
            OWLAnnotationAssertionAxiom band_label_annotation = getDataFactory().getOWLAnnotationAssertionAxiom(rdfsLabel, bandIndiv.getIRI(), name);
            AddAxiom add_band_label = new AddAxiom(ontology, band_label_annotation);
            getManager().applyChange(add_band_label);
            // assert located_in relation
            OWLObjectPropertyAssertionAxiom located_in_relation = getDataFactory().getOWLObjectPropertyAssertionAxiom(located_in, snpIndiv, bandIndiv);
            AddAxiom add_located_in = new AddAxiom(ontology, located_in_relation);
            getManager().applyChange(add_located_in);
            // assert location_of relation
            OWLObjectPropertyAssertionAxiom location_of_relation = getDataFactory().getOWLObjectPropertyAssertionAxiom(location_of, bandIndiv, snpIndiv);
            AddAxiom add_location_of = new AddAxiom(ontology, location_of_relation);
            getManager().applyChange(add_location_of);
            // get the appropriate chromosome class given the chromosome name
            OWLClass chrClass = getDataFactory().getOWLClass(IRI.create(OntologyConstants.CHROMOSOME_CLASS_IRI));
            // create a new chromosome individual
            //If a snp has a chromosome name, create the chromosome individual if it doesn't have one (ex : the snp is
            // no mapped any more) then just don't create it.
            String chromName = location.getChromosomeName();
            if (chromName != null) {
                OWLNamedIndividual chrIndiv = getDataFactory().getOWLNamedIndividual(getMinter().mint(OntologyConstants.GWAS_ONTOLOGY_BASE_IRI, "Chromosome", chromName));
                OWLClassAssertionAxiom chrClassAssertion = getDataFactory().getOWLClassAssertionAxiom(chrClass, chrIndiv);
                getManager().addAxiom(ontology, chrClassAssertion);
                // assert chr_name relation
                OWLLiteral chr_name = getDataFactory().getOWLLiteral(chromName);
                OWLDataPropertyAssertionAxiom chr_name_relation = getDataFactory().getOWLDataPropertyAssertionAxiom(has_chr_name, chrIndiv, chr_name);
                AddAxiom add_chr_name = new AddAxiom(ontology, chr_name_relation);
                getManager().applyChange(add_chr_name);
                // assert label
                OWLLiteral chr_label = getDataFactory().getOWLLiteral("Chromosome " + chromName);
                OWLAnnotationAssertionAxiom chr_label_annotation = getDataFactory().getOWLAnnotationAssertionAxiom(rdfsLabel, chrIndiv.getIRI(), chr_label);
                AddAxiom add_chr_label = new AddAxiom(ontology, chr_label_annotation);
                getManager().applyChange(add_chr_label);
                // assert has_part relation
                OWLObjectPropertyAssertionAxiom has_part_relation = getDataFactory().getOWLObjectPropertyAssertionAxiom(has_part, chrIndiv, bandIndiv);
                AddAxiom add_has_part = new AddAxiom(ontology, has_part_relation);
                getManager().applyChange(add_has_part);
                // assert part_of relation
                OWLObjectPropertyAssertionAxiom part_of_relation = getDataFactory().getOWLObjectPropertyAssertionAxiom(part_of, bandIndiv, chrIndiv);
                AddAxiom add_part_of = new AddAxiom(ontology, part_of_relation);
                getManager().applyChange(add_part_of);
            }
        } else {
            getLog().trace("No known region for location on chromosomse " + location.getChromosomeName());
        }
    }
}
Also used : OWLAnnotationAssertionAxiom(org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom) AddAxiom(org.semanticweb.owlapi.model.AddAxiom) OWLObjectProperty(org.semanticweb.owlapi.model.OWLObjectProperty) OWLAnnotationProperty(org.semanticweb.owlapi.model.OWLAnnotationProperty) OWLDataPropertyAssertionAxiom(org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom) OWLDataProperty(org.semanticweb.owlapi.model.OWLDataProperty) OWLLiteral(org.semanticweb.owlapi.model.OWLLiteral) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) OWLObjectPropertyAssertionAxiom(org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom) Region(uk.ac.ebi.spot.goci.model.Region) OWLClass(org.semanticweb.owlapi.model.OWLClass) OWLClassAssertionAxiom(org.semanticweb.owlapi.model.OWLClassAssertionAxiom) Location(uk.ac.ebi.spot.goci.model.Location)

Aggregations

Location (uk.ac.ebi.spot.goci.model.Location)12 Region (uk.ac.ebi.spot.goci.model.Region)6 SingleNucleotidePolymorphism (uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism)6 ArrayList (java.util.ArrayList)5 Gene (uk.ac.ebi.spot.goci.model.Gene)4 GenomicContext (uk.ac.ebi.spot.goci.model.GenomicContext)4 JSONObject (org.json.JSONObject)3 Locus (uk.ac.ebi.spot.goci.model.Locus)3 RiskAllele (uk.ac.ebi.spot.goci.model.RiskAllele)3 Date (java.util.Date)2 HashSet (java.util.HashSet)2 SnpMappingForm (uk.ac.ebi.spot.goci.curation.model.SnpMappingForm)2 EnsemblMappingResult (uk.ac.ebi.spot.goci.model.EnsemblMappingResult)2 RestResponseResult (uk.ac.ebi.spot.goci.model.RestResponseResult)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 JSONArray (org.json.JSONArray)1 AddAxiom (org.semanticweb.owlapi.model.AddAxiom)1