Search in sources :

Example 6 with Region

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

the class LocationCreationService method createLocation.

public Location createLocation(String chromosomeName, Integer chromosomePosition, String regionName) {
    Region region = null;
    region = regionRepository.findByName(regionName);
    // If the region doesn't exist, save it
    if (region == null) {
        Region newRegion = new Region();
        newRegion.setName(regionName);
        region = regionRepository.save(newRegion);
    }
    Location newLocation = new Location();
    newLocation.setChromosomeName(chromosomeName);
    newLocation.setChromosomePosition(chromosomePosition);
    newLocation.setRegion(region);
    // Save location
    locationRepository.save(newLocation);
    return newLocation;
}
Also used : Region(uk.ac.ebi.spot.goci.model.Region) Location(uk.ac.ebi.spot.goci.model.Location)

Example 7 with Region

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

the class SnpLocationMappingService method storeSnpLocation.

public void storeSnpLocation(Map<String, Set<Location>> snpToLocations) {
    // Go through each rs_id and its associated locations returned from the mapping pipeline
    for (String snpRsId : snpToLocations.keySet()) {
        Set<Location> snpLocationsFromMapping = snpToLocations.get(snpRsId);
        // Check if the SNP exists
        SingleNucleotidePolymorphism snpInDatabase = singleNucleotidePolymorphismRepository.findByRsId(snpRsId);
        if (snpInDatabase == null) {
            snpInDatabase = singleNucleotidePolymorphismQueryService.findByRsIdIgnoreCase(snpRsId);
        }
        if (snpInDatabase != null) {
            // Store all new location objects
            Collection<Location> newSnpLocations = new ArrayList<>();
            for (Location snpLocationFromMapping : snpLocationsFromMapping) {
                String chromosomeNameFromMapping = snpLocationFromMapping.getChromosomeName();
                if (chromosomeNameFromMapping != null) {
                    chromosomeNameFromMapping = chromosomeNameFromMapping.trim();
                }
                Integer chromosomePositionFromMapping = snpLocationFromMapping.getChromosomePosition();
                // if (chromosomePositionFromMapping != null) {
                // chromosomePositionFromMapping = chromosomePositionFromMapping.trim();
                // }
                Region regionFromMapping = snpLocationFromMapping.getRegion();
                String regionNameFromMapping = null;
                if (regionFromMapping != null) {
                    if (regionFromMapping.getName() != null) {
                        regionNameFromMapping = regionFromMapping.getName().trim();
                    }
                }
                // Check if location already exists
                Location existingLocation = locationRepository.findByChromosomeNameAndChromosomePositionAndRegionName(chromosomeNameFromMapping, chromosomePositionFromMapping, regionNameFromMapping);
                if (existingLocation != null) {
                    newSnpLocations.add(existingLocation);
                } else // Create new location
                {
                    Location newLocation = locationCreationService.createLocation(chromosomeNameFromMapping, chromosomePositionFromMapping, regionNameFromMapping);
                    newSnpLocations.add(newLocation);
                }
            }
            // If we have new locations then link to snp and save
            if (newSnpLocations.size() > 0) {
                // Set new location details
                snpInDatabase.setLocations(newSnpLocations);
                // Update the last update date
                snpInDatabase.setLastUpdateDate(new Date());
                singleNucleotidePolymorphismRepository.save(snpInDatabase);
            } else {
                getLog().warn("No new locations to add to " + snpRsId);
            }
        } 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 location for SNP not found in database, RS_ID:" + snpRsId);
            throw new RuntimeException("Adding location for SNP not found in database, RS_ID: " + snpRsId);
        }
    }
}
Also used : SingleNucleotidePolymorphism(uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism) ArrayList(java.util.ArrayList) Region(uk.ac.ebi.spot.goci.model.Region) Date(java.util.Date) 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