use of uk.ac.ebi.spot.goci.model.GenomicContext in project goci by EBISPOT.
the class GenomicContextCreationService method createGenomicContext.
/**
* Method to create genomic context
*
* @param isIntergenic
* @param isUpstream
* @param isDownstream
* @param distance
* @param source
* @param mappingMethod
* @param geneName
* @param snpIdInDatabase
* @param isClosestGene
* @param location
*/
public GenomicContext createGenomicContext(Boolean isIntergenic, Boolean isUpstream, Boolean isDownstream, Long distance, String source, String mappingMethod, String geneName, SingleNucleotidePolymorphism snpIdInDatabase, Boolean isClosestGene, Location location) {
GenomicContext genomicContext = new GenomicContext();
// Find gene, ignoreCase query is not used here as we want to
// only create a genomic context for
// the exact gene name returned from mapping
Gene gene = geneRepository.findByGeneName(geneName);
genomicContext.setGene(gene);
genomicContext.setIsIntergenic(isIntergenic);
genomicContext.setIsDownstream(isDownstream);
genomicContext.setIsUpstream(isUpstream);
genomicContext.setDistance(distance);
genomicContext.setSource(source);
genomicContext.setMappingMethod(mappingMethod);
genomicContext.setSnp(snpIdInDatabase);
genomicContext.setIsClosestGene(isClosestGene);
genomicContext.setLocation(location);
// Save genomic context
genomicContextRepository.save(genomicContext);
return genomicContext;
}
use of uk.ac.ebi.spot.goci.model.GenomicContext in project goci by EBISPOT.
the class EnsemblMappingPipeline method addGenomicContext.
/**
* Create GenomicContext objects from the JSONObjects and add them to the class variable "genomic_contexts" (list of
* "GenomicContext" classes)
*
* @param json_gene_list the list of overlapping genes in JSONObject format
* @param snp_location an instance of the Location class (chromosome name and position)
* @param source the source of the data (Ensembl or NCBI)
* @param type the type of genomic context (i.e. overlap, upstream, downstream)
* @return boolean to indicate whether a closest gene has been found or not (only relevant for upstream and
* downstream gene)
*/
private boolean addGenomicContext(JSONArray json_gene_list, Location snp_location, String source, String type) {
String closest_gene = "";
int closest_distance = 0;
boolean intergenic = (type.equals("overlap")) ? false : true;
boolean upstream = (type.equals("upstream")) ? true : false;
boolean downstream = (type.equals("downstream")) ? true : false;
Integer position = snp_location.getChromosomePosition();
SingleNucleotidePolymorphism snp_tmp = new SingleNucleotidePolymorphism();
snp_tmp.setRsId(getEnsemblMappingResult().getRsId());
if (getEnsemblMappingResult().getRsId() == null) {
throw new IllegalArgumentException("error, no RS ID found for location " + snp_location.getId());
}
// Get closest gene
if (intergenic) {
int pos = position;
for (int i = 0; i < json_gene_list.length(); ++i) {
JSONObject json_gene = json_gene_list.getJSONObject(i);
String gene_name = json_gene.getString("external_name");
// If the source is NCBI, we parse the ID from the description:
String gene_id = source.equals(getNcbiSource()) ? parseNCBIid(json_gene.getString("description"), gene_name) : json_gene.getString("id");
if (source.equals(getNcbiSource())) {
if ((gene_name != null && getEnsemblMappingResult().getNcbiOverlappingGene().contains(gene_name)) || gene_name == null) {
// Skip overlapping genes which also overlap upstream and/or downstream of the variant
continue;
}
} else {
if ((gene_name != null && getEnsemblMappingResult().getEnsemblOverlappingGene().contains(gene_name)) || gene_name == null) {
// Skip overlapping genes which also overlap upstream and/or downstream of the variant
continue;
}
}
int distance = 0;
if (type.equals("upstream")) {
distance = pos - json_gene.getInt("end");
} else if (type.equals("downstream")) {
distance = json_gene.getInt("start") - pos;
}
if ((distance < closest_distance && distance > 0) || closest_distance == 0) {
closest_gene = gene_id;
closest_distance = distance;
}
}
}
for (int i = 0; i < json_gene_list.length(); ++i) {
JSONObject json_gene = json_gene_list.getJSONObject(i);
String gene_name = json_gene.getString("external_name");
// If the source is NCBI, we parse the ID from the description:
String gene_id = source.equals(getNcbiSource()) ? parseNCBIid(json_gene.getString("description"), gene_name) : json_gene.getString("id");
String ncbi_id = (source.equals("NCBI")) ? gene_id : null;
String ensembl_id = (source.equals("Ensembl")) ? gene_id : null;
int distance = 0;
if (intergenic) {
if (source.equals(getNcbiSource())) {
if ((gene_name != null && getEnsemblMappingResult().getNcbiOverlappingGene().contains(gene_name)) || gene_name == null) {
// Skip overlapping genes which also overlap upstream and/or downstream of the variant
continue;
}
} else {
if ((gene_name != null && getEnsemblMappingResult().getEnsemblOverlappingGene().contains(gene_name)) || gene_name == null) {
// Skip overlapping genes which also overlap upstream and/or downstream of the variant
continue;
}
}
int pos = position;
if (type.equals("upstream")) {
distance = pos - json_gene.getInt("end");
} else if (type.equals("downstream")) {
distance = json_gene.getInt("start") - pos;
}
}
Long dist = (long) distance;
EntrezGene entrezGene = new EntrezGene();
entrezGene.setEntrezGeneId(ncbi_id);
Collection<EntrezGene> entrezGenes = new ArrayList<>();
entrezGenes.add(entrezGene);
EnsemblGene ensemblGene = new EnsemblGene();
ensemblGene.setEnsemblGeneId(ensembl_id);
Collection<EnsemblGene> ensemblGenes = new ArrayList<>();
ensemblGenes.add(ensemblGene);
Gene gene_object = new Gene(gene_name, entrezGenes, ensemblGenes);
// Check if the gene corresponds to the closest gene
boolean is_closest_gene = (closest_gene.equals(gene_id) && closest_gene != "") ? true : false;
GenomicContext gc = new GenomicContext(intergenic, upstream, downstream, dist, snp_tmp, gene_object, snp_location, source, getMappingMethod(), is_closest_gene);
getEnsemblMappingResult().addGenomicContext(gc);
}
return (closest_gene != "") ? true : false;
}
use of uk.ac.ebi.spot.goci.model.GenomicContext in project goci by EBISPOT.
the class SnpGenomicContextMappingService method removeExistingGenomicContexts.
/**
* Method to remove the existing genomic contexts linked to a SNP
*
* @param snp SNP from which to remove the associated genomic contexts
*/
public void removeExistingGenomicContexts(SingleNucleotidePolymorphism snp) {
// Get a list of locations currently genomic context
Collection<GenomicContext> snpGenomicContexts = snp.getGenomicContexts();
if (snpGenomicContexts != null && !snpGenomicContexts.isEmpty()) {
// Remove old genomic contexts, as these will be updated with latest mapping
snp.setGenomicContexts(new ArrayList<>());
singleNucleotidePolymorphismRepository.save(snp);
Set<Long> oldSnpLocationIds = new HashSet<>();
for (GenomicContext snpGenomicContext : snpGenomicContexts) {
if (snpGenomicContext.getLocation() != null) {
oldSnpLocationIds.add(snpGenomicContext.getLocation().getId());
}
}
genomicContextRepository.delete(snpGenomicContexts);
for (Long oldSnpLocationId : oldSnpLocationIds) {
cleanUpLocations(oldSnpLocationId);
}
}
}
use of uk.ac.ebi.spot.goci.model.GenomicContext in project goci by EBISPOT.
the class SnpGenomicContextMappingService method storeSnpGenomicContext.
/**
* Saves genomic context information to database
*
* @param snpToGenomicContextMap map of rs_id and all genomic context details returned from current mapping run
*/
private void storeSnpGenomicContext(Map<String, Set<GenomicContext>> snpToGenomicContextMap) {
List<SingleNucleotidePolymorphism> updatedSnps = new ArrayList<>();
// Go through each rs_id and its associated genomic contexts returned from the mapping pipeline
for (String snpRsId : snpToGenomicContextMap.keySet()) {
getLog().debug("Storing genomic context for " + snpRsId);
Set<GenomicContext> genomicContextsFromMapping = snpToGenomicContextMap.get(snpRsId);
// Check if the SNP exists
SingleNucleotidePolymorphism snpInDatabase = singleNucleotidePolymorphismRepository.findByRsId(snpRsId);
if (snpInDatabase == null) {
snpInDatabase = singleNucleotidePolymorphismQueryService.findByRsIdIgnoreCase(snpRsId);
}
if (snpInDatabase != null) {
Collection<GenomicContext> newSnpGenomicContexts = new ArrayList<>();
for (GenomicContext genomicContextFromMapping : genomicContextsFromMapping) {
// Gene should already have been created
String geneName = genomicContextFromMapping.getGene().getGeneName().trim();
if (!geneName.equalsIgnoreCase("undefined")) {
// Create new genomic context
Boolean isIntergenic = genomicContextFromMapping.getIsIntergenic();
Boolean isUpstream = genomicContextFromMapping.getIsUpstream();
Boolean isDownstream = genomicContextFromMapping.getIsDownstream();
Long distance = genomicContextFromMapping.getDistance();
String source = genomicContextFromMapping.getSource();
String mappingMethod = genomicContextFromMapping.getMappingMethod();
Boolean isClosestGene = genomicContextFromMapping.getIsClosestGene();
// Location details
String chromosomeName = genomicContextFromMapping.getLocation().getChromosomeName();
Integer chromosomePosition = genomicContextFromMapping.getLocation().getChromosomePosition();
Region regionFromMapping = genomicContextFromMapping.getLocation().getRegion();
String regionName = null;
if (regionFromMapping.getName() != null) {
regionName = regionFromMapping.getName().trim();
}
// Check if location already exists
Location location = locationRepository.findByChromosomeNameAndChromosomePositionAndRegionName(chromosomeName, chromosomePosition, regionName);
if (location == null) {
location = locationCreationService.createLocation(chromosomeName, chromosomePosition, regionName);
}
GenomicContext genomicContext = genomicContextCreationService.createGenomicContext(isIntergenic, isUpstream, isDownstream, distance, source, mappingMethod, geneName, snpInDatabase, isClosestGene, location);
newSnpGenomicContexts.add(genomicContext);
} else {
getLog().warn("Gene name returned from mapping pipeline is 'undefined' for SNP" + snpInDatabase.getRsId());
}
}
// Save latest mapped information
snpInDatabase.setGenomicContexts(newSnpGenomicContexts);
// Update the last update date
snpInDatabase.setLastUpdateDate(new Date());
// singleNucleotidePolymorphismRepository.save(snpInDatabase);
updatedSnps.add(snpInDatabase);
} 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 genomic context for SNP not found in database, RS_ID:" + snpRsId);
throw new RuntimeException("Adding genomic context for SNP not found in database, RS_ID: " + snpRsId);
}
}
singleNucleotidePolymorphismRepository.save(updatedSnps);
}
use of uk.ac.ebi.spot.goci.model.GenomicContext 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.setAssociationExtension(association.getAssociationExtension());
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;
}
Aggregations