use of uk.ac.ebi.spot.goci.model.Location in project goci by EBISPOT.
the class AssociationService method loadAssociatedData.
public void loadAssociatedData(Association association) {
int traitCount = association.getEfoTraits().size();
Study study = studyService.fetchOne(association.getStudy());
AtomicInteger reportedGeneCount = new AtomicInteger();
Collection<SingleNucleotidePolymorphism> snps = 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 (mappedGeneEntrezIds.containsKey(geneName)) {
for (EntrezGene entrezGene : geneEntrezGeneIds) {
mappedGeneEntrezIds.get(geneName).add(entrezGene.getEntrezGeneId());
}
} else {
Set<String> entrezIds = new HashSet<>();
for (EntrezGene entrezGene : geneEntrezGeneIds) {
entrezIds.add(entrezGene.getEntrezGeneId());
}
mappedGeneEntrezIds.put(geneName, entrezIds);
}
if (mappedGeneEnsemblIds.containsKey(geneName)) {
for (EnsemblGene ensemblGene : geneEnsemblGeneIds) {
mappedGeneEnsemblIds.get(geneName).add(ensemblGene.getEnsemblGeneId());
}
} else {
Set<String> ensemblIds = new HashSet<>();
for (EnsemblGene ensemblGene : geneEnsemblGeneIds) {
ensemblIds.add(ensemblGene.getEnsemblGeneId());
}
mappedGeneEntrezIds.put(geneName, ensemblIds);
}
});
snps.add(snp);
});
snps.addAll(locus.getStrongestRiskAlleles().stream().map(RiskAllele::getSnp).collect(Collectors.toList()));
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.");
}
use of uk.ac.ebi.spot.goci.model.Location in project goci by EBISPOT.
the class SingleSnpMultiSnpAssociationService method createForm.
// Creates form which we can then return to view for editing etc.
@Override
public SnpAssociationForm createForm(Association association) {
SnpAssociationStandardMultiForm form = new SnpAssociationStandardMultiForm();
// Set association ID
form.setAssociationId(association.getId());
// Set simple string and float association attributes
form.setRiskFrequency(association.getRiskFrequency());
form.setPvalueDescription(association.getPvalueDescription());
form.setSnpType(association.getSnpType());
form.setMultiSnpHaplotype(association.getMultiSnpHaplotype());
form.setSnpApproved(association.getSnpApproved());
form.setPvalueMantissa(association.getPvalueMantissa());
form.setPvalueExponent(association.getPvalueExponent());
form.setStandardError(association.getStandardError());
form.setRange(association.getRange());
form.setDescription(association.getDescription());
// Set OR/Beta values
form.setOrPerCopyNum(association.getOrPerCopyNum());
form.setOrPerCopyRecip(association.getOrPerCopyRecip());
form.setOrPerCopyRecipRange(association.getOrPerCopyRecipRange());
form.setBetaNum(association.getBetaNum());
form.setBetaUnit(association.getBetaUnit());
form.setBetaDirection(association.getBetaDirection());
// Add collection of Efo traits
form.setEfoTraits(association.getEfoTraits());
// For each locus get genes and risk alleles
Collection<Locus> loci = association.getLoci();
Collection<Gene> locusGenes = new ArrayList<>();
Collection<RiskAllele> locusRiskAlleles = new ArrayList<RiskAllele>();
// For multi-snp and standard snps we assume their is only one locus
for (Locus locus : loci) {
locusGenes.addAll(locus.getAuthorReportedGenes());
locusRiskAlleles.addAll(locus.getStrongestRiskAlleles().stream().sorted((v1, v2) -> Long.compare(v1.getId(), v2.getId())).collect(Collectors.toList()));
// There should only be one locus thus should be safe to set these here
form.setMultiSnpHaplotypeNum(locus.getHaplotypeSnpCount());
form.setMultiSnpHaplotypeDescr(locus.getDescription());
}
// Get name of gene and add to form
Collection<String> authorReportedGenes = new ArrayList<>();
for (Gene locusGene : locusGenes) {
authorReportedGenes.add(locusGene.getGeneName());
}
form.setAuthorReportedGenes(authorReportedGenes);
// Handle snp rows
Collection<GenomicContext> snpGenomicContexts = new ArrayList<GenomicContext>();
Collection<SingleNucleotidePolymorphism> snps = new ArrayList<>();
List<SnpFormRow> snpFormRows = new ArrayList<SnpFormRow>();
List<SnpMappingForm> snpMappingForms = new ArrayList<SnpMappingForm>();
for (RiskAllele riskAllele : locusRiskAlleles) {
SnpFormRow snpFormRow = new SnpFormRow();
snpFormRow.setStrongestRiskAllele(riskAllele.getRiskAlleleName());
SingleNucleotidePolymorphism snp = riskAllele.getSnp();
snps.add(snp);
String rsID = snp.getRsId();
snpFormRow.setSnp(rsID);
Collection<Location> locations = snp.getLocations();
for (Location location : locations) {
SnpMappingForm snpMappingForm = new SnpMappingForm(rsID, location);
snpMappingForms.add(snpMappingForm);
}
// Set proxy if one is present
Collection<String> proxySnps = new ArrayList<>();
if (riskAllele.getProxySnps() != null) {
for (SingleNucleotidePolymorphism riskAlleleProxySnp : riskAllele.getProxySnps()) {
proxySnps.add(riskAlleleProxySnp.getRsId());
}
}
snpFormRow.setProxySnps(proxySnps);
snpGenomicContexts.addAll(genomicContextRepository.findBySnpId(snp.getId()));
snpFormRows.add(snpFormRow);
}
form.setSnpMappingForms(snpMappingForms);
form.setGenomicContexts(snpGenomicContexts);
form.setSnps(snps);
form.setSnpFormRows(snpFormRows);
return form;
}
use of uk.ac.ebi.spot.goci.model.Location in project goci by EBISPOT.
the class SnpInteractionAssociationService method createForm.
// Create a form to return to view from Association model object
@Override
public SnpAssociationForm createForm(Association association) {
// Create form
SnpAssociationInteractionForm form = new SnpAssociationInteractionForm();
// Set simple string and boolean values
form.setAssociationId(association.getId());
form.setPvalueDescription(association.getPvalueDescription());
form.setSnpType(association.getSnpType());
form.setSnpApproved(association.getSnpApproved());
form.setPvalueMantissa(association.getPvalueMantissa());
form.setPvalueExponent(association.getPvalueExponent());
form.setStandardError(association.getStandardError());
form.setRange(association.getRange());
form.setDescription(association.getDescription());
form.setRiskFrequency(association.getRiskFrequency());
// Set OR/Beta values
form.setOrPerCopyNum(association.getOrPerCopyNum());
form.setOrPerCopyRecip(association.getOrPerCopyRecip());
form.setOrPerCopyRecipRange(association.getOrPerCopyRecipRange());
form.setBetaNum(association.getBetaNum());
form.setBetaUnit(association.getBetaUnit());
form.setBetaDirection(association.getBetaDirection());
// Add collection of Efo traits
form.setEfoTraits(association.getEfoTraits());
// Create form columns
List<SnpFormColumn> snpFormColumns = new ArrayList<>();
// For each locus get genes and risk alleles
Collection<Locus> loci = association.getLoci();
Collection<GenomicContext> snpGenomicContexts = new ArrayList<GenomicContext>();
Collection<SingleNucleotidePolymorphism> snps = new ArrayList<SingleNucleotidePolymorphism>();
List<SnpMappingForm> snpMappingForms = new ArrayList<SnpMappingForm>();
// Create a column per locus
if (loci != null && !loci.isEmpty()) {
for (Locus locus : loci) {
SnpFormColumn snpFormColumn = new SnpFormColumn();
// Set genes
Collection<String> authorReportedGenes = new ArrayList<>();
for (Gene gene : locus.getAuthorReportedGenes()) {
authorReportedGenes.add(gene.getGeneName());
}
snpFormColumn.setAuthorReportedGenes(authorReportedGenes);
// Set risk allele
Collection<RiskAllele> locusRiskAlleles = locus.getStrongestRiskAlleles();
String strongestRiskAllele = null;
String snp = null;
Collection<String> proxySnps = new ArrayList<>();
Boolean genomeWide = false;
Boolean limitedList = false;
String riskFrequency = null;
// For snp x snp interaction studies should only have one risk allele per locus
if (locusRiskAlleles != null && locusRiskAlleles.size() == 1) {
for (RiskAllele riskAllele : locusRiskAlleles) {
strongestRiskAllele = riskAllele.getRiskAlleleName();
snp = riskAllele.getSnp().getRsId();
SingleNucleotidePolymorphism snp_obj = riskAllele.getSnp();
snps.add(snp_obj);
Collection<Location> locations = snp_obj.getLocations();
for (Location location : locations) {
SnpMappingForm snpMappingForm = new SnpMappingForm(snp, location);
snpMappingForms.add(snpMappingForm);
}
snpGenomicContexts.addAll(genomicContextRepository.findBySnpId(snp_obj.getId()));
// Set proxy
if (riskAllele.getProxySnps() != null) {
for (SingleNucleotidePolymorphism riskAlleleProxySnp : riskAllele.getProxySnps()) {
proxySnps.add(riskAlleleProxySnp.getRsId());
}
}
if (riskAllele.getGenomeWide() != null && riskAllele.getGenomeWide()) {
genomeWide = true;
}
if (riskAllele.getLimitedList() != null && riskAllele.getLimitedList()) {
limitedList = true;
}
riskFrequency = riskAllele.getRiskFrequency();
}
} else {
throw new RuntimeException("More than one risk allele found for locus " + locus.getId() + ", this is not supported yet for SNP interaction associations");
}
// Set column attributes
snpFormColumn.setStrongestRiskAllele(strongestRiskAllele);
snpFormColumn.setSnp(snp);
snpFormColumn.setProxySnps(proxySnps);
snpFormColumn.setGenomeWide(genomeWide);
snpFormColumn.setLimitedList(limitedList);
snpFormColumn.setRiskFrequency(riskFrequency);
snpFormColumns.add(snpFormColumn);
}
}
form.setSnpMappingForms(snpMappingForms);
form.setGenomicContexts(snpGenomicContexts);
form.setSnps(snps);
form.setSnpFormColumns(snpFormColumns);
form.setNumOfInteractions(snpFormColumns.size());
return form;
}
use of uk.ac.ebi.spot.goci.model.Location 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.Location in project goci by EBISPOT.
the class MappingService method doMapping.
private void doMapping(Association association, String eRelease) throws EnsemblMappingException {
getLog().info("Mapping association: " + association.getId());
// Map to store returned location data, this is used in
// snpLocationMappingService to process all locations linked
// to a single snp in one go
Map<String, Set<Location>> snpToLocationsMap = new HashMap<>();
// Collection to store all genomic contexts
Collection<GenomicContext> allGenomicContexts = new ArrayList<>();
// Collection to store all errors for one association
Collection<String> associationPipelineErrors = new ArrayList<>();
// For each loci get the SNP and author reported genes
Collection<Locus> studyAssociationLoci = association.getLoci();
for (Locus associationLocus : studyAssociationLoci) {
Long locusId = associationLocus.getId();
Collection<SingleNucleotidePolymorphism> snpsLinkedToLocus = singleNucleotidePolymorphismQueryService.findByRiskAllelesLociId(locusId);
Collection<Gene> authorReportedGenesLinkedToSnp = associationLocus.getAuthorReportedGenes();
// Get gene names
Collection<String> authorReportedGeneNamesLinkedToSnp = new ArrayList<>();
for (Gene authorReportedGeneLinkedToSnp : authorReportedGenesLinkedToSnp) {
authorReportedGeneNamesLinkedToSnp.add(authorReportedGeneLinkedToSnp.getGeneName().trim());
}
// Pass rs_id and author reported genes to mapping component
for (SingleNucleotidePolymorphism snpLinkedToLocus : snpsLinkedToLocus) {
String snpRsId = snpLinkedToLocus.getRsId();
EnsemblMappingResult ensemblMappingResult = new EnsemblMappingResult();
// Try to map supplied data
try {
getLog().debug("Running mapping....");
ensemblMappingResult = ensemblMappingPipeline.run_pipeline(snpRsId, authorReportedGeneNamesLinkedToSnp, eRelease);
} catch (Exception e) {
getLog().error("Encountered a " + e.getClass().getSimpleName() + " whilst trying to run mapping of SNP " + snpRsId + ", found in association: " + association.getId(), e);
throw new EnsemblMappingException();
}
getLog().debug("Mapping complete");
// First remove old locations and genomic contexts
snpLocationMappingService.removeExistingSnpLocations(snpLinkedToLocus);
snpGenomicContextMappingService.removeExistingGenomicContexts(snpLinkedToLocus);
Collection<Location> locations = ensemblMappingResult.getLocations();
Collection<GenomicContext> snpGenomicContexts = ensemblMappingResult.getGenomicContexts();
ArrayList<String> pipelineErrors = ensemblMappingResult.getPipelineErrors();
// Update functional class
snpLinkedToLocus.setFunctionalClass(ensemblMappingResult.getFunctionalClass());
snpLinkedToLocus.setLastUpdateDate(new Date());
snpLinkedToLocus.setMerged(Long.valueOf(ensemblMappingResult.getMerged()));
// Update the merge table
if (ensemblMappingResult.getMerged() == 1) {
String currentSnpId = ensemblMappingResult.getCurrentSnpId();
SingleNucleotidePolymorphism currentSnp = singleNucleotidePolymorphismRepository.findByRsId(currentSnpId);
// Add the current SingleNucleotidePolymorphism to the "merged" rsID
if (currentSnp == null) {
currentSnp = new SingleNucleotidePolymorphism();
currentSnp.setRsId(currentSnpId);
currentSnp.setFunctionalClass(snpLinkedToLocus.getFunctionalClass());
singleNucleotidePolymorphismRepository.save(currentSnp);
currentSnp = singleNucleotidePolymorphismRepository.findByRsId(currentSnpId);
}
snpLinkedToLocus.setCurrentSnp(currentSnp);
}
singleNucleotidePolymorphismRepository.save(snpLinkedToLocus);
// Store location information for SNP
if (!locations.isEmpty()) {
for (Location location : locations) {
// This would only occur is SNP has multiple locations
if (snpToLocationsMap.containsKey(snpRsId)) {
snpToLocationsMap.get(snpRsId).add(location);
} else // First time we see a SNP store the location
{
Set<Location> snpLocation = new HashSet<>();
snpLocation.add(location);
snpToLocationsMap.put(snpRsId, snpLocation);
}
}
} else {
getLog().warn("Attempt to map SNP: " + snpRsId + " returned no location details");
pipelineErrors.add("Attempt to map SNP: " + snpRsId + " returned no location details");
}
// Store genomic context data for snp
if (!snpGenomicContexts.isEmpty()) {
allGenomicContexts.addAll(snpGenomicContexts);
} else {
getLog().warn("Attempt to map SNP: " + snpRsId + " returned no mapped genes");
pipelineErrors.add("Attempt to map SNP: " + snpRsId + " returned no mapped genes");
}
if (!pipelineErrors.isEmpty()) {
associationPipelineErrors.addAll(pipelineErrors);
}
}
}
// Create association report based on whether there is errors or not
if (!associationPipelineErrors.isEmpty()) {
associationReportService.processAssociationErrors(association, associationPipelineErrors);
} else {
associationReportService.updateAssociationReportDetails(association);
}
// Save data
if (!snpToLocationsMap.isEmpty()) {
getLog().debug("Updating location details ...");
snpLocationMappingService.storeSnpLocation(snpToLocationsMap);
getLog().debug("Updating location details complete");
}
if (!allGenomicContexts.isEmpty()) {
getLog().debug("Updating genomic context details ...");
snpGenomicContextMappingService.processGenomicContext(allGenomicContexts);
getLog().debug("Updating genomic context details complete");
}
}
Aggregations