Search in sources :

Example 1 with Region

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

the class EnsemblMappingPipeline method getRegion.

/**
 * Get the cytogenetic band from a given location
 *
 * @param chromosome the chromosome name
 * @param position   the position of the variant
 * @return Region object only containing a region name
 */
private Region getRegion(String chromosome, Integer position, String eRelease) throws EnsemblRestIOException {
    // Default value
    String band = null;
    String rest_opt = "feature=band";
    // REST Call
    JSONArray cytogenetic_band_result = getOverlapRegionCalls(chromosome, position, position, rest_opt, eRelease);
    // EnsemblDbService.FeatureType.BAND).getRestResult().getArray();
    if (cytogenetic_band_result.length() != 0 && !cytogenetic_band_result.getJSONObject(0).has("overlap_error")) {
        String cytogenetic_band = cytogenetic_band_result.getJSONObject(0).getString("id");
        // Chromosomes
        Matcher matcher1 = Pattern.compile("^[0-9]+|[XY]$").matcher(chromosome);
        // Mitochondria
        Matcher matcher2 = Pattern.compile("^MT$").matcher(chromosome);
        if (matcher1.matches() || matcher2.matches()) {
            band = chromosome + cytogenetic_band;
        }
    }
    return new Region(band);
}
Also used : Matcher(java.util.regex.Matcher) JSONArray(org.json.JSONArray) Region(uk.ac.ebi.spot.goci.model.Region)

Example 2 with Region

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

use of uk.ac.ebi.spot.goci.model.Region 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) {
    List<SingleNucleotidePolymorphism> updatedSnps = new ArrayList<>();
    // 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 = singleNucleotidePolymorphismRepository.findByRsId(snpRsId);
        if (snpInDatabase == null) {
            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);
            updatedSnps.add(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);
        }
    }
    singleNucleotidePolymorphismRepository.save(updatedSnps);
}
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 4 with Region

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

the class AssociationService method loadAssociatedData.

@Transactional(readOnly = true)
public void loadAssociatedData(Association association) {
    int traitCount = association.getEfoTraits().size();
    // Study study = studyService.fetchOne(association.getStudy());
    Study study = association.getStudy();
    AtomicInteger reportedGeneCount = new AtomicInteger();
    Collection<SingleNucleotidePolymorphism> snps = new HashSet<>();
    Collection<SingleNucleotidePolymorphism> proxySnps = new HashSet<>();
    Collection<Region> regions = new HashSet<>();
    Collection<Gene> mappedGenes = new HashSet<>();
    // Map<String, Set<String>> mappedGeneEntrezIds = new HashMap<>();
    Map<String, Set<String>> mappedGeneEnsemblIds = new HashMap<>();
    association.getLoci().forEach(locus -> {
        locus.getStrongestRiskAlleles().stream().map(RiskAllele::getSnp).forEach(snp -> {
            Collection<Location> snpLocations = snp.getLocations();
            for (Location location : snpLocations) {
                regions.add(location.getRegion());
            }
            snp.getGenomicContexts().forEach(context -> {
                mappedGenes.add(context.getGene());
                String geneName = context.getGene().getGeneName();
                Collection<EntrezGene> geneEntrezGeneIds = context.getGene().getEntrezGeneIds();
                Collection<EnsemblGene> geneEnsemblGeneIds = context.getGene().getEnsemblGeneIds();
                if (mappedGeneEnsemblIds.containsKey(geneName)) {
                    for (EnsemblGene ensemblGene : geneEnsemblGeneIds) {
                        mappedGeneEnsemblIds.get(geneName).add(ensemblGene.getEnsemblGeneId());
                    }
                } else // First time we see a SNP store the location
                {
                    Set<String> ensemblIds = new HashSet<>();
                    for (EnsemblGene ensemblGene : geneEnsemblGeneIds) {
                        ensemblIds.add(ensemblGene.getEnsemblGeneId());
                    }
                    // mappedGeneEntrezIds.put(geneName,
                    // ensemblIds);
                    mappedGeneEnsemblIds.put(geneName, ensemblIds);
                }
            });
            snps.add(snp);
        });
        snps.addAll(locus.getStrongestRiskAlleles().stream().map(RiskAllele::getSnp).collect(Collectors.toList()));
        locus.getStrongestRiskAlleles().forEach(riskAllele -> {
            if (riskAllele.getProxySnps() != null) {
                proxySnps.addAll(riskAllele.getProxySnps());
            }
        });
        reportedGeneCount.addAndGet(locus.getAuthorReportedGenes().size());
        locus.getAuthorReportedGenes().forEach(authorReportedGene -> {
            authorReportedGene.getEnsemblGeneIds().size();
        // authorReportedGene.getEntrezGeneIds().size();
        });
    });
    getLog().trace("Association '" + association.getId() + "' is mapped to " + "" + traitCount + " EFO traits where study id = " + study.getId() + " " + "(author reported " + reportedGeneCount + " gene(s)); " + "this reports on " + snps.size() + " SNPs in " + regions.size() + " regions, " + "mapped to " + mappedGenes.size() + " genes.");
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) EntrezGene(uk.ac.ebi.spot.goci.model.EntrezGene) RiskAllele(uk.ac.ebi.spot.goci.model.RiskAllele) EnsemblGene(uk.ac.ebi.spot.goci.model.EnsemblGene) EntrezGene(uk.ac.ebi.spot.goci.model.EntrezGene) EnsemblGene(uk.ac.ebi.spot.goci.model.EnsemblGene) Gene(uk.ac.ebi.spot.goci.model.Gene) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SingleNucleotidePolymorphism(uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism) Region(uk.ac.ebi.spot.goci.model.Region) HashSet(java.util.HashSet) Location(uk.ac.ebi.spot.goci.model.Location) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Region

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

the class DefaultGWASOWLConverter method convertSNP.

protected void convertSNP(SingleNucleotidePolymorphism snp, OWLOntology ontology) {
    log.debug("converting snp: " + snp.getId() + ", rsid: " + snp.getRsId());
    // 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

Region (uk.ac.ebi.spot.goci.model.Region)7 Location (uk.ac.ebi.spot.goci.model.Location)6 ArrayList (java.util.ArrayList)3 SingleNucleotidePolymorphism (uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism)3 Date (java.util.Date)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Matcher (java.util.regex.Matcher)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1 AddAxiom (org.semanticweb.owlapi.model.AddAxiom)1 OWLAnnotationAssertionAxiom (org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom)1 OWLAnnotationProperty (org.semanticweb.owlapi.model.OWLAnnotationProperty)1 OWLClass (org.semanticweb.owlapi.model.OWLClass)1 OWLClassAssertionAxiom (org.semanticweb.owlapi.model.OWLClassAssertionAxiom)1 OWLDataProperty (org.semanticweb.owlapi.model.OWLDataProperty)1 OWLDataPropertyAssertionAxiom (org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom)1 OWLLiteral (org.semanticweb.owlapi.model.OWLLiteral)1