use of uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism in project goci by EBISPOT.
the class SingleSnpMultiSnpAssociationService method createAssociation.
public Association createAssociation(SnpAssociationStandardMultiForm form) {
// Set common string, boolean and float association attributes
Association association = setCommonAssociationElements(form);
association.setSnpInteraction(false);
// Add loci to association, for multi-snp and standard snps we assume their is only one locus
Collection<Locus> loci = new ArrayList<>();
Locus locus = new Locus();
// Set locus description and haplotype count
// Set this number to the number of rows entered by curator
Integer numberOfRows = form.getSnpFormRows().size();
if (numberOfRows > 1) {
locus.setHaplotypeSnpCount(numberOfRows);
association.setMultiSnpHaplotype(true);
}
if (form.getMultiSnpHaplotypeDescr() != null && !form.getMultiSnpHaplotypeDescr().isEmpty()) {
locus.setDescription(form.getMultiSnpHaplotypeDescr());
} else {
if (numberOfRows > 1) {
locus.setDescription(numberOfRows + "-SNP haplotype");
} else {
locus.setDescription("Single variant");
}
}
// Create gene from each string entered, may sure to check pre-existence
Collection<String> authorReportedGenes = form.getAuthorReportedGenes();
Collection<Gene> locusGenes = lociAttributesService.createGene(authorReportedGenes);
// Set locus genes
locus.setAuthorReportedGenes(locusGenes);
// Handle rows entered for haplotype by curator
Collection<SnpFormRow> rows = form.getSnpFormRows();
Collection<RiskAllele> locusRiskAlleles = new ArrayList<>();
for (SnpFormRow row : rows) {
// Create snps from row information
String curatorEnteredSNP = row.getSnp();
SingleNucleotidePolymorphism snp = lociAttributesService.createSnp(curatorEnteredSNP);
// Get the curator entered risk allele
String curatorEnteredRiskAllele = row.getStrongestRiskAllele();
// Create a new risk allele and assign newly created snp
RiskAllele riskAllele = lociAttributesService.createRiskAllele(curatorEnteredRiskAllele, snp);
// If association is not a multi-snp haplotype save frequency to risk allele
if (!form.getMultiSnpHaplotype()) {
riskAllele.setRiskFrequency(form.getRiskFrequency());
}
// Check for proxies and if we have one create a proxy snps
if (row.getProxySnps() != null && !row.getProxySnps().isEmpty()) {
Collection<SingleNucleotidePolymorphism> riskAlleleProxySnps = new ArrayList<>();
for (String curatorEnteredProxySnp : row.getProxySnps()) {
SingleNucleotidePolymorphism proxySnp = lociAttributesService.createSnp(curatorEnteredProxySnp);
riskAlleleProxySnps.add(proxySnp);
}
riskAllele.setProxySnps(riskAlleleProxySnps);
}
locusRiskAlleles.add(riskAllele);
}
// Assign all created risk alleles to locus
locus.setStrongestRiskAlleles(locusRiskAlleles);
// Add locus to collection and link to our association
loci.add(locus);
association.setLoci(loci);
return association;
}
use of uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism in project goci by EBISPOT.
the class SnpInteractionAssociationService method createAssociation.
public Association createAssociation(SnpAssociationInteractionForm form) {
// Set simple string, boolean and float association attributes
Association association = setCommonAssociationElements(form);
// Set multi-snp and snp interaction checkboxes
association.setMultiSnpHaplotype(false);
association.setSnpInteraction(true);
// For each column create a loci
Collection<Locus> loci = new ArrayList<>();
for (SnpFormColumn col : form.getSnpFormColumns()) {
Locus locus = new Locus();
locus.setDescription("SNP x SNP interaction");
// Set locus genes
Collection<String> authorReportedGenes = col.getAuthorReportedGenes();
Collection<Gene> locusGenes = lociAttributesService.createGene(authorReportedGenes);
locus.setAuthorReportedGenes(locusGenes);
// Create SNP
String curatorEnteredSNP = col.getSnp();
SingleNucleotidePolymorphism snp = lociAttributesService.createSnp(curatorEnteredSNP);
// One risk allele per locus
String curatorEnteredRiskAllele = col.getStrongestRiskAllele();
RiskAllele riskAllele = lociAttributesService.createRiskAllele(curatorEnteredRiskAllele, snp);
Collection<RiskAllele> locusRiskAlleles = new ArrayList<>();
// Set risk allele attributes
riskAllele.setGenomeWide(col.getGenomeWide());
riskAllele.setLimitedList(col.getLimitedList());
riskAllele.setRiskFrequency(col.getRiskFrequency());
// Check for a proxy and if we have one create a proxy snp
Collection<String> curatorEnteredProxySnps = col.getProxySnps();
if (curatorEnteredProxySnps != null && !curatorEnteredProxySnps.isEmpty()) {
Collection<SingleNucleotidePolymorphism> riskAlleleProxySnps = new ArrayList<>();
for (String curatorEnteredProxySnp : curatorEnteredProxySnps) {
SingleNucleotidePolymorphism proxySnp = lociAttributesService.createSnp(curatorEnteredProxySnp);
riskAlleleProxySnps.add(proxySnp);
}
riskAllele.setProxySnps(riskAlleleProxySnps);
}
// Link risk allele to locus
locusRiskAlleles.add(riskAllele);
locus.setStrongestRiskAlleles(locusRiskAlleles);
// Add locus to collection and link to our association
loci.add(locus);
}
association.setLoci(loci);
return association;
}
use of uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism in project goci by EBISPOT.
the class AssociationDownloadService method extractGeneticData.
private void extractGeneticData(Association association, StringBuilder line) {
final StringBuilder strongestAllele = new StringBuilder();
final StringBuilder reportedGenes = new StringBuilder();
final StringBuilder rsId = new StringBuilder();
final StringBuilder proxySnpsRsIds = new StringBuilder();
final StringBuilder riskAlleleFrequency = new StringBuilder();
// Set our delimiter for download spreadsheet
final String delimiter;
if (association.getSnpInteraction() != null && association.getSnpInteraction()) {
delimiter = " x ";
} else {
delimiter = "; ";
}
// Interaction specific values
if (association.getSnpInteraction() != null && association.getSnpInteraction()) {
association.getLoci().forEach(locus -> {
Collection<RiskAllele> ra = locus.getStrongestRiskAlleles().stream().sorted((v1, v2) -> Long.compare(v1.getId(), v2.getId())).collect(Collectors.toList());
ra.forEach(riskAllele -> {
if (riskAllele.getRiskFrequency() != null && !riskAllele.getRiskFrequency().isEmpty()) {
String frequency = riskAllele.getRiskFrequency();
setOrAppend(riskAlleleFrequency, frequency, delimiter);
} else {
setOrAppend(riskAlleleFrequency, "NR", delimiter);
}
});
Collection<String> currentLocusGenes = new ArrayList<>();
String commaSeparatedGenes = "";
locus.getAuthorReportedGenes().forEach(gene -> {
currentLocusGenes.add(gene.getGeneName().trim());
});
if (!currentLocusGenes.isEmpty()) {
commaSeparatedGenes = String.join(", ", currentLocusGenes);
setOrAppend(reportedGenes, commaSeparatedGenes, delimiter);
} else {
setOrAppend(reportedGenes, "NR", delimiter);
}
});
} else {
// Single study or a haplotype
association.getLoci().forEach(locus -> {
Collection<RiskAllele> ra = locus.getStrongestRiskAlleles().stream().sorted((v1, v2) -> Long.compare(v1.getId(), v2.getId())).collect(Collectors.toList());
ra.forEach(riskAllele -> {
setOrAppend(riskAlleleFrequency, "", "");
});
locus.getAuthorReportedGenes().forEach(gene -> {
setOrAppend(reportedGenes, gene.getGeneName().trim(), ", ");
});
});
}
// Set attributes common to all associations
association.getLoci().forEach(locus -> {
Collection<RiskAllele> ra = locus.getStrongestRiskAlleles().stream().sorted((v1, v2) -> Long.compare(v1.getId(), v2.getId())).collect(Collectors.toList());
ra.forEach(riskAllele -> {
setOrAppend(strongestAllele, riskAllele.getRiskAlleleName(), delimiter);
SingleNucleotidePolymorphism snp = riskAllele.getSnp();
setOrAppend(rsId, snp.getRsId(), delimiter);
Collection<String> currentLocusProxies = new ArrayList<>();
String colonSeparatedProxies = "";
if (riskAllele.getProxySnps() != null) {
for (SingleNucleotidePolymorphism proxySnp : riskAllele.getProxySnps()) {
currentLocusProxies.add(proxySnp.getRsId());
}
}
if (!currentLocusProxies.isEmpty()) {
colonSeparatedProxies = String.join(", ", currentLocusProxies);
setOrAppend(proxySnpsRsIds, colonSeparatedProxies, delimiter);
} else {
setOrAppend(proxySnpsRsIds, "NR", delimiter);
}
});
});
line.append(reportedGenes.toString());
line.append("\t");
line.append(strongestAllele.toString());
line.append("\t");
line.append(rsId.toString());
line.append("\t");
line.append(proxySnpsRsIds.toString());
line.append("\t");
line.append(riskAlleleFrequency.toString());
line.append("\t");
}
use of uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism in project goci by EBISPOT.
the class AssociationEventsViewService method createViews.
@Override
public List<EventView> createViews(Long studyId) {
List<EventView> views = new ArrayList<>();
Collection<Association> associations = studyRepository.findOne(studyId).getAssociations();
if (!associations.isEmpty()) {
// For each association gather up the events into a collection of views
associations.forEach(association -> {
Collection<Event> events = association.getEvents();
Long associationId = association.getId();
Collection<SingleNucleotidePolymorphism> snps = singleNucleotidePolymorphismRepository.findByRiskAllelesLociAssociationId(associationId);
String associationSummary;
StringJoiner snpJoiner = new StringJoiner(", ");
snps.forEach(singleNucleotidePolymorphism -> {
snpJoiner.add(singleNucleotidePolymorphism.getRsId());
});
associationSummary = snpJoiner.toString();
events.forEach(event -> {
String eventName = eventTypeService.translateEventByEventType(event.getEventType());
EventView eventView = new AssociationEventView(eventName, event.getEventDate(), associationId, event.getUser().getEmail(), associationSummary);
views.add(eventView);
});
});
}
return views;
}
Aggregations