use of uk.ac.ebi.spot.goci.model.RiskAllele 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.RiskAllele 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");
}
Aggregations