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;
}
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);
}
}
}
Aggregations