use of uk.ac.ebi.spot.goci.model.Gene in project goci by EBISPOT.
the class LociAttributesService method saveGene.
public Collection<Gene> saveGene(Collection<Gene> genes) {
Collection<Gene> locusGenes = new ArrayList<Gene>();
genes.forEach(gene -> {
Gene geneInDatabase = geneRepository.findByGeneName(gene.getGeneName());
if (geneInDatabase != null) {
getLog().debug("Gene " + geneInDatabase.getGeneName() + " already exists in database");
locusGenes.add(geneInDatabase);
} else {
getLog().debug("Gene " + gene.getGeneName() + " not found in database. Creating and saving new gene.");
geneRepository.save(gene);
locusGenes.add(gene);
}
});
return locusGenes;
}
use of uk.ac.ebi.spot.goci.model.Gene 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.Gene in project goci by EBISPOT.
the class SnpAssociationTableViewService method createSnpAssociationTableView.
/**
* Create object, from Association, that will be returned to view
*
* @param association Association object
*/
public SnpAssociationTableView createSnpAssociationTableView(Association association) {
SnpAssociationTableView snpAssociationTableView = new SnpAssociationTableView();
// For SNP interaction studies snp, proxy snps, risk alleles etc
// should be separated by an 'x'
String delimiter = "; ";
if (association.getSnpInteraction()) {
delimiter = " x ";
}
snpAssociationTableView.setAssociationId(association.getId());
// For each locus relevant attributes
Collection<Locus> loci = association.getLoci();
Collection<String> allLociGenes = new ArrayList<>();
Collection<String> allLociRiskAlleles = new ArrayList<String>();
Collection<String> allLociSnps = new ArrayList<String>();
Collection<String> allLociProxySnps = new ArrayList<String>();
Collection<String> allLociRiskAlleleFrequencies = new ArrayList<String>();
Collection<String> allLociSnpStatuses = new ArrayList<String>();
// By looking at each locus in turn we can keep order in view
for (Locus locus : loci) {
// Store gene names, a locus can have a number of genes attached.
// Per locus create a comma separated list and add to an array.
// Further processing will then delimit this list
// either by ; or 'x' depending on association type
Collection<String> currentlocusGenes = new ArrayList<>();
String commaSeparatedGenes = "";
for (Gene gene : locus.getAuthorReportedGenes()) {
currentlocusGenes.add(gene.getGeneName());
}
if (!currentlocusGenes.isEmpty()) {
commaSeparatedGenes = String.join(", ", currentlocusGenes);
allLociGenes.add(commaSeparatedGenes);
} else {
allLociGenes.add("NR");
}
//This sort ensures that haplotype SNPs are displayed in the correct order
Collection<RiskAllele> ra = locus.getStrongestRiskAlleles().stream().sorted((v1, v2) -> Long.compare(v1.getId(), v2.getId())).collect(Collectors.toList());
for (RiskAllele riskAllele : ra) {
allLociRiskAlleles.add(riskAllele.getRiskAlleleName());
// Based on assumption we only have one locus with a single risk allele attached
if (!association.getMultiSnpHaplotype() && !association.getSnpInteraction()) {
if (riskAllele.getRiskFrequency() != null && !riskAllele.getRiskFrequency().isEmpty()) {
allLociRiskAlleleFrequencies.add(riskAllele.getRiskFrequency());
}
}
// SNPs attached to risk allele
SingleNucleotidePolymorphism snp = riskAllele.getSnp();
allLociSnps.add(snp.getRsId());
// Set proxies if present
Collection<String> currentLocusProxies = new ArrayList<>();
String commaSeparatedProxies = "";
if (riskAllele.getProxySnps() != null) {
for (SingleNucleotidePolymorphism proxySnp : riskAllele.getProxySnps()) {
currentLocusProxies.add(proxySnp.getRsId());
}
}
// Comma separate proxies in view
if (!currentLocusProxies.isEmpty()) {
commaSeparatedProxies = String.join(", ", currentLocusProxies);
allLociProxySnps.add(commaSeparatedProxies);
} else {
allLociProxySnps.add("NR");
}
// Only required for SNP interaction studies
if (association.getSnpInteraction() != null) {
if (association.getSnpInteraction()) {
// Genome wide Vs Limited List
Collection<String> snpStatus = new ArrayList<>();
String commaSeparatedSnpStatus = "";
if (riskAllele.getLimitedList() != null) {
if (riskAllele.getLimitedList()) {
snpStatus.add("LL");
}
}
if (riskAllele.getGenomeWide() != null) {
if (riskAllele.getGenomeWide()) {
snpStatus.add("GW");
}
}
if (!snpStatus.isEmpty()) {
commaSeparatedSnpStatus = String.join(", ", snpStatus);
allLociSnpStatuses.add(commaSeparatedSnpStatus);
} else {
allLociSnpStatuses.add("NR");
}
// Allele risk frequency
if (riskAllele.getRiskFrequency() != null && !riskAllele.getRiskFrequency().isEmpty()) {
allLociRiskAlleleFrequencies.add(riskAllele.getRiskFrequency());
} else {
allLociRiskAlleleFrequencies.add("NR");
}
}
}
}
}
// Create delimited strings for view
String authorReportedGenes = null;
if (allLociGenes.size() > 1) {
authorReportedGenes = String.join(delimiter, allLociGenes);
} else {
authorReportedGenes = String.join("", allLociGenes);
}
snpAssociationTableView.setAuthorReportedGenes(authorReportedGenes);
String strongestRiskAlleles = null;
if (allLociRiskAlleles.size() > 1) {
strongestRiskAlleles = String.join(delimiter, allLociRiskAlleles);
} else {
strongestRiskAlleles = String.join("", allLociRiskAlleles);
}
snpAssociationTableView.setStrongestRiskAlleles(strongestRiskAlleles);
String associationSnps = null;
if (allLociSnps.size() > 1) {
associationSnps = String.join(delimiter, allLociSnps);
} else {
associationSnps = String.join("", allLociSnps);
}
snpAssociationTableView.setSnps(associationSnps);
String associationProxies = null;
if (allLociProxySnps.size() > 1) {
associationProxies = String.join(delimiter, allLociProxySnps);
} else {
associationProxies = String.join("", allLociProxySnps);
}
snpAssociationTableView.setProxySnps(associationProxies);
// Set both risk frequencies
String associationRiskAlleleFrequencies = null;
if (allLociRiskAlleleFrequencies.size() > 1) {
associationRiskAlleleFrequencies = String.join(delimiter, allLociRiskAlleleFrequencies);
} else {
associationRiskAlleleFrequencies = String.join("", allLociRiskAlleleFrequencies);
}
snpAssociationTableView.setRiskAlleleFrequencies(associationRiskAlleleFrequencies);
snpAssociationTableView.setAssociationRiskFrequency(association.getRiskFrequency());
String associationSnpStatuses = null;
if (allLociSnpStatuses.size() > 1) {
associationSnpStatuses = String.join(delimiter, allLociSnpStatuses);
} else {
associationSnpStatuses = String.join("", allLociSnpStatuses);
}
snpAssociationTableView.setSnpStatuses(associationSnpStatuses);
snpAssociationTableView.setPvalueMantissa(association.getPvalueMantissa());
snpAssociationTableView.setPvalueExponent(association.getPvalueExponent());
snpAssociationTableView.setPvalueDescription(association.getPvalueDescription());
Collection<String> efoTraits = new ArrayList<>();
for (EfoTrait efoTrait : association.getEfoTraits()) {
efoTraits.add(efoTrait.getTrait());
}
String associationEfoTraits = null;
associationEfoTraits = String.join(", ", efoTraits);
snpAssociationTableView.setEfoTraits(associationEfoTraits);
// Set OR values
snpAssociationTableView.setOrPerCopyNum(association.getOrPerCopyNum());
snpAssociationTableView.setOrPerCopyRecip(association.getOrPerCopyRecip());
snpAssociationTableView.setOrPerCopyRecipRange(association.getOrPerCopyRecipRange());
// Set beta values
snpAssociationTableView.setBetaNum(association.getBetaNum());
snpAssociationTableView.setBetaDirection(association.getBetaDirection());
snpAssociationTableView.setBetaUnit(association.getBetaUnit());
snpAssociationTableView.setRange(association.getRange());
snpAssociationTableView.setDescription(association.getDescription());
snpAssociationTableView.setStandardError(association.getStandardError());
snpAssociationTableView.setAssociationType(association.getSnpType());
if (association.getMultiSnpHaplotype() != null) {
if (association.getMultiSnpHaplotype()) {
snpAssociationTableView.setMultiSnpHaplotype("Yes");
}
if (!association.getMultiSnpHaplotype()) {
snpAssociationTableView.setMultiSnpHaplotype("No");
}
}
if (association.getSnpInteraction() != null) {
if (association.getSnpInteraction()) {
snpAssociationTableView.setSnpInteraction("Yes");
}
if (!association.getSnpInteraction()) {
snpAssociationTableView.setSnpInteraction("No");
}
}
if (association.getSnpApproved() != null) {
if (association.getSnpApproved()) {
snpAssociationTableView.setSnpApproved("Yes");
}
if (!association.getSnpApproved()) {
snpAssociationTableView.setSnpApproved("No");
}
}
// Get validation warnings
snpAssociationTableView.setValidationWarnings(associationValidationReportService.getWarningSet(association.getId()));
// Get mapping details
if (association.getLastMappingPerformedBy() != null) {
snpAssociationTableView.setLastMappingPerformedBy(association.getLastMappingPerformedBy());
}
snpAssociationTableView.setMappingStatus("false");
if (association.getLastMappingDate() != null) {
snpAssociationTableView.setMappingStatus("true");
}
if (association.getLastMappingDate() != null) {
DateFormat df = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
String dateOfLastMapping = df.format(association.getLastMappingDate());
snpAssociationTableView.setLastMappingDate(dateOfLastMapping);
}
return snpAssociationTableView;
}
use of uk.ac.ebi.spot.goci.model.Gene 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.Gene 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