use of uk.ac.ebi.spot.goci.model.RiskAllele in project goci by EBISPOT.
the class AssociationRowProcessor method createLoci.
private Collection<Locus> createLoci(AssociationUploadRow row, Boolean snpInteraction, Boolean multiSnpHaplotype) {
String delimiter;
Collection<Locus> loci = new ArrayList<>();
if (snpInteraction) {
delimiter = "x";
// For SNP interaction studies we need to create a locus per risk allele
// Handle curator entered risk allele
Collection<RiskAllele> locusRiskAlleles = createLocusRiskAlleles(row.getStrongestAllele(), row.getSnp(), row.getProxy(), row.getRiskFrequency(), row.getSnpStatus(), delimiter);
// Deal with genes for each interaction which should be
// separated by 'x'
String[] separatedGenes = row.getAuthorReportedGene().split(delimiter);
int geneIndex = 0;
for (RiskAllele riskAllele : locusRiskAlleles) {
Locus locus = new Locus();
// Set risk alleles, assume one locus per risk allele
Collection<RiskAllele> currentLocusRiskAlleles = new ArrayList<>();
currentLocusRiskAlleles.add(riskAllele);
locus.setStrongestRiskAlleles(currentLocusRiskAlleles);
// Set gene
String interactionGene = separatedGenes[geneIndex];
Collection<Gene> locusGenes = associationAttributeService.createLocusGenes(interactionGene, ",");
locus.setAuthorReportedGenes(locusGenes);
geneIndex++;
// Set description
locus.setDescription("SNP x SNP interaction");
loci.add(locus);
}
} else // Handle multi-snp and standard snp
{
delimiter = ";";
// For multi-snp and standard snps we assume their is only one locus
Locus locus = new Locus();
// Handle curator entered genes, for haplotype they are separated by a comma
if (row.getAuthorReportedGene() != null && !row.getAuthorReportedGene().isEmpty()) {
Collection<Gene> locusGenes = associationAttributeService.createLocusGenes(row.getAuthorReportedGene(), ",");
locus.setAuthorReportedGenes(locusGenes);
}
// Handle curator entered risk allele
Collection<RiskAllele> locusRiskAlleles = createLocusRiskAlleles(row.getStrongestAllele(), row.getSnp(), row.getProxy(), row.getRiskFrequency(), row.getSnpStatus(), delimiter);
// For standard associations set the risk allele frequency to the
// same value as the overall association frequency
Collection<RiskAllele> locusRiskAllelesWithRiskFrequencyValues = new ArrayList<>();
if (!multiSnpHaplotype) {
for (RiskAllele riskAllele : locusRiskAlleles) {
riskAllele.setRiskFrequency(row.getAssociationRiskFrequency());
locusRiskAllelesWithRiskFrequencyValues.add(riskAllele);
}
locus.setStrongestRiskAlleles(locusRiskAllelesWithRiskFrequencyValues);
} else {
locus.setStrongestRiskAlleles(locusRiskAlleles);
}
// Set locus attributes
Integer haplotypeCount = locusRiskAlleles.size();
if (haplotypeCount > 1) {
locus.setHaplotypeSnpCount(haplotypeCount);
locus.setDescription(String.valueOf(haplotypeCount) + "-SNP haplotype");
} else {
locus.setDescription("Single variant");
}
loci.add(locus);
}
return loci;
}
use of uk.ac.ebi.spot.goci.model.RiskAllele in project goci by EBISPOT.
the class AssociationRowProcessorTest method testCreateAssociationFromUploadRowSnpInteraction.
@Test
public void testCreateAssociationFromUploadRowSnpInteraction() throws Exception {
// Stubbing mock object behaviour
when(associationAttributeService.createLocusGenes("PMS1 ", ",")).thenReturn(Arrays.asList(GENE_03));
when(associationAttributeService.createLocusGenes(" HIBCH", ",")).thenReturn(Arrays.asList(GENE_04));
when(associationAttributeService.createSnp("rs2562796")).thenReturn(SNP_02);
when(associationAttributeService.createSnp("rs16832404")).thenReturn(SNP_03);
when(associationAttributeService.createRiskAllele("rs2562796-T", SNP_02)).thenReturn(RA_02);
when(associationAttributeService.createRiskAllele("rs16832404-G", SNP_03)).thenReturn(RA_03);
Association association = associationRowProcessor.createAssociationFromUploadRow(SNP_INTERACTION_ROW);
verify(associationCalculationService, never()).reverseCI(SNP_INTERACTION_ROW.getRange());
verify(associationCalculationService, never()).setRange(SNP_INTERACTION_ROW.getStandardError(), SNP_INTERACTION_ROW.getOrPerCopyNum());
verify(associationAttributeService, never()).getEfoTraitsFromRepository(Collections.EMPTY_LIST);
verify(associationAttributeService, times(1)).createLocusGenes("PMS1 ", ",");
verify(associationAttributeService, times(1)).createLocusGenes(" HIBCH", ",");
verify(associationAttributeService, times(1)).createSnp("rs2562796");
verify(associationAttributeService, times(1)).createSnp("rs16832404");
verify(associationAttributeService, times(1)).createRiskAllele("rs2562796-T", SNP_02);
verify(associationAttributeService, times(1)).createRiskAllele("rs16832404-G", SNP_03);
assertThat(association).extracting("id", "riskFrequency", "pvalueDescription", "pvalueMantissa", "pvalueExponent", "multiSnpHaplotype", "snpInteraction", "snpApproved", "snpType", "standardError", "range", "description", "orPerCopyNum", "orPerCopyRecip", "orPerCopyRecipRange", "betaNum", "betaUnit", "betaDirection", "study", "associationReport", "lastMappingDate", "lastMappingPerformedBy", "lastUpdateDate").containsExactly(null, "0.52", null, 2, -7, false, true, false, null, (float) 0.6, "[0.82-0.92]", null, (float) 1.22, null, null, null, null, null, null, null, null, null, null);
assertThat(association.getEfoTraits()).isEmpty();
assertThat(association.getEvents()).isEmpty();
assertThat(association.getStudy()).isNull();
assertThat(association.getLoci()).hasSize(2);
// Check locus attributes
Collection<Gene> locusGenes = new ArrayList<>();
association.getLoci().stream().forEach(locus -> {
locusGenes.addAll(locus.getAuthorReportedGenes());
});
Collection<RiskAllele> locusRiskAlleles = new ArrayList<>();
association.getLoci().stream().forEach(locus -> {
locusRiskAlleles.addAll(locus.getStrongestRiskAlleles());
});
assertThat(association.getLoci()).extracting(Locus::getDescription).containsOnly("SNP x SNP interaction");
assertThat(locusGenes).hasSize(2).contains(GENE_03, GENE_04);
assertThat(locusRiskAlleles).hasSize(2).contains(RA_02, RA_03);
assertThat(locusRiskAlleles).extracting("riskAlleleName", "riskFrequency", "snp.rsId").contains(tuple("rs2562796-T", "0.3", "rs2562796"), tuple("rs16832404-G", "0.4", "rs16832404"));
assertThat(locusRiskAlleles).extracting(RiskAllele::getSnp).containsExactly(SNP_02, SNP_03);
}
use of uk.ac.ebi.spot.goci.model.RiskAllele in project goci by EBISPOT.
the class AssociationRowProcessorTest method testCreateAssociationFromUploadRowHaplotype.
@Test
public void testCreateAssociationFromUploadRowHaplotype() throws Exception {
// Stubbing mock object behaviour
when(associationAttributeService.createSnp("rs456")).thenReturn(SNP_04);
when(associationAttributeService.createSnp("rs678")).thenReturn(SNP_05);
when(associationAttributeService.createRiskAllele("rs456-T", SNP_04)).thenReturn(RA_04);
when(associationAttributeService.createRiskAllele("rs678-?", SNP_05)).thenReturn(RA_05);
when(associationCalculationService.reverseCI("[0.87-0.94]")).thenReturn("[1.06-1.15]");
Association association = associationRowProcessor.createAssociationFromUploadRow(HAPLOTYPE_ROW);
verify(associationCalculationService, times(1)).reverseCI(Matchers.anyString());
verify(associationCalculationService, never()).setRange(Matchers.anyDouble(), Matchers.anyDouble());
verify(associationAttributeService, never()).getEfoTraitsFromRepository(Collections.EMPTY_LIST);
verify(associationAttributeService, never()).createLocusGenes(Matchers.anyString(), Matchers.anyString());
verify(associationAttributeService, times(1)).createSnp("rs456");
verify(associationAttributeService, times(1)).createSnp("rs678");
verify(associationAttributeService, times(1)).createRiskAllele("rs456-T", SNP_04);
verify(associationAttributeService, times(1)).createRiskAllele("rs678-?", SNP_05);
assertThat(association).extracting("id", "riskFrequency", "pvalueDescription", "pvalueMantissa", "pvalueExponent", "multiSnpHaplotype", "snpInteraction", "snpApproved", "snpType", "standardError", "range", "description", "orPerCopyNum", "orPerCopyRecip", "orPerCopyRecipRange", "betaNum", "betaUnit", "betaDirection", "study", "associationReport", "lastMappingDate", "lastMappingPerformedBy", "lastUpdateDate").containsExactly(null, null, "(description)", 2, -7, true, false, false, null, null, "[1.06-1.15]", null, 1.2048193f, 0.83f, "[0.87-0.94]", null, null, null, null, null, null, null, null);
assertThat(association.getEfoTraits()).isEmpty();
assertThat(association.getEvents()).isEmpty();
assertThat(association.getStudy()).isNull();
assertThat(association.getLoci()).hasSize(1);
Collection<RiskAllele> locusRiskAlleles = new ArrayList<>();
association.getLoci().stream().forEach(locus -> {
locusRiskAlleles.addAll(locus.getStrongestRiskAlleles());
});
// Check locus attributes
Collection<Gene> locusGenes = new ArrayList<>();
association.getLoci().stream().forEach(locus -> {
locusGenes.addAll(locus.getAuthorReportedGenes());
});
assertThat(association.getLoci()).extracting(Locus::getDescription).containsOnly("2-SNP haplotype");
assertThat(locusGenes).isEmpty();
assertThat(locusRiskAlleles).hasSize(2).contains(RA_04, RA_05);
assertThat(locusRiskAlleles).extracting(RiskAllele::getRiskFrequency).containsNull();
assertThat(locusRiskAlleles).extracting("riskAlleleName", "riskFrequency", "snp.rsId").contains(tuple("rs456-T", null, "rs456"), tuple("rs678-?", null, "rs678"));
assertThat(locusRiskAlleles).extracting(RiskAllele::getSnp).containsExactly(SNP_04, SNP_05);
}
use of uk.ac.ebi.spot.goci.model.RiskAllele in project goci by EBISPOT.
the class ValidationChecksBuilder method runLociAttributeChecks.
/**
* Run loci attributes checks on association
*
* @param association association to be checked
*/
public Collection<ValidationError> runLociAttributeChecks(Association association, String eRelease) {
Collection<ValidationError> validationErrors = new ArrayList<>();
if (association.getLoci() != null) {
Set<String> associationGenes = new HashSet<>();
Collection<ValidationError> geneErrors = new ArrayList<>();
// Create a unique set of all locus genes
for (Locus locus : association.getLoci()) {
Set<String> locusGenes = new HashSet<>();
if (!locus.getAuthorReportedGenes().isEmpty()) {
locusGenes = locus.getAuthorReportedGenes().stream().map(Gene::getGeneName).collect(Collectors.toSet());
}
associationGenes.addAll(locusGenes);
}
// Check genes
associationGenes.forEach(geneName -> {
getLog().info("Checking gene: ".concat(geneName));
ValidationError geneError = errorCreationService.checkGene(geneName, eRelease);
if (geneError.getError() != null) {
geneErrors.add(geneError);
}
});
if (!geneErrors.isEmpty()) {
validationErrors.addAll(geneErrors);
}
for (Locus locus : association.getLoci()) {
Collection<RiskAllele> riskAlleles = locus.getStrongestRiskAlleles();
// Check risk allele attributes
riskAlleles.forEach(riskAllele -> {
ValidationError riskAlleleError = errorCreationService.checkRiskAllele(riskAllele.getRiskAlleleName());
validationErrors.add(riskAlleleError);
if (geneErrors.isEmpty()) {
Set<String> locusGenes = locus.getAuthorReportedGenes().stream().map(Gene::getGeneName).collect(Collectors.toSet());
locusGenes.forEach(geneName -> {
getLog().info("Checking snp/gene location: ".concat(geneName).concat(" ").concat(riskAllele.getSnp().getRsId()));
ValidationError snpGeneLocationError = errorCreationService.checkSnpGeneLocation(riskAllele.getSnp().getRsId(), geneName, eRelease);
validationErrors.add(snpGeneLocationError);
});
} else {
ValidationError snpError = errorCreationService.checkSnp(riskAllele.getSnp().getRsId(), eRelease);
validationErrors.add(snpError);
}
});
}
}
return ErrorProcessingService.checkForValidErrors(validationErrors);
}
use of uk.ac.ebi.spot.goci.model.RiskAllele in project goci by EBISPOT.
the class AssociationAttributeService method createRiskAllele.
public RiskAllele createRiskAllele(String curatorEnteredRiskAllele, SingleNucleotidePolymorphism snp) {
RiskAllele riskAllele = new RiskAllele();
riskAllele.setRiskAlleleName(StringProcessingService.tidy_curator_entered_string(curatorEnteredRiskAllele));
riskAllele.setSnp(snp);
return riskAllele;
}
Aggregations