Search in sources :

Example 11 with Location

use of uk.ac.ebi.spot.goci.model.Location 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 = 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)

Example 12 with Location

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

the class SnpLocationMappingService method removeExistingSnpLocations.

/**
     * Method to remove the existing locations linked to a SNP
     *
     * @param snp SNP from which to remove the associated locations
     */
public void removeExistingSnpLocations(SingleNucleotidePolymorphism snp) {
    // Get a list of locations currently linked to SNP
    Collection<Location> oldSnpLocations = snp.getLocations();
    if (oldSnpLocations != null && !oldSnpLocations.isEmpty()) {
        Set<Long> oldSnpLocationIds = new HashSet<>();
        for (Location oldSnpLocation : oldSnpLocations) {
            oldSnpLocationIds.add(oldSnpLocation.getId());
        }
        // Remove old locations
        snp.setLocations(new ArrayList<>());
        singleNucleotidePolymorphismRepository.save(snp);
        // Clean-up old locations that were linked to SNP
        if (oldSnpLocationIds.size() > 0) {
            for (Long oldSnpLocationId : oldSnpLocationIds) {
                cleanUpLocations(oldSnpLocationId);
            }
        }
    }
}
Also used : Location(uk.ac.ebi.spot.goci.model.Location) HashSet(java.util.HashSet)

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