use of uk.ac.ebi.spot.goci.curation.model.SnpFormRow in project goci by EBISPOT.
the class AssociationController method editAssociation.
// Edit existing association
// We tried to remap if the snp or genes changed.
// TODO : implement something for SNP:SNP iteration. Actually we remap.
@RequestMapping(value = "/associations/{associationId}", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST)
public // TODO COULD REFACTOR TO JUST USE SUPERCLASS AS METHOD PARAMETER
String editAssociation(@ModelAttribute SnpAssociationStandardMultiForm snpAssociationStandardMultiForm, @ModelAttribute SnpAssociationInteractionForm snpAssociationInteractionForm, @PathVariable Long associationId, @RequestParam(value = "associationtype", required = true) String associationType, Model model, HttpServletRequest request, RedirectAttributes redirectAttributes) throws EnsemblMappingException {
// Establish study and association we are editing
Collection<String> previousAuthorReportedGenes = new HashSet<>();
Collection<String> authorReportedGenes = new HashSet<>();
Collection<String> previousSnps = new HashSet<>();
Collection<String> snps = new HashSet<>();
String isToRemapping = "yes";
Association associationToEdit = associationRepository.findOne(associationId);
Long studyId = associationToEdit.getStudy().getId();
Study study = studyRepository.findOne(studyId);
model.addAttribute("study", study);
AssociationReport oldAssociationReport = associationToEdit.getAssociationReport();
previousAuthorReportedGenes = associationOperationsService.getGenesIds(associationToEdit.getLoci());
previousSnps = associationOperationsService.getSpnsName(associationToEdit.getSnps());
// Determine if association is an OR or BETA type
String measurementType = associationOperationsService.determineIfAssociationIsOrType(associationToEdit);
model.addAttribute("measurementType", measurementType);
// Validate returned form depending on association type
List<AssociationValidationView> criticalErrors = new ArrayList<>();
if (associationType.equalsIgnoreCase("interaction")) {
criticalErrors = associationOperationsService.checkSnpAssociationInteractionFormErrorsForView(snpAssociationInteractionForm, measurementType);
} else {
criticalErrors = associationOperationsService.checkSnpAssociationFormErrors(snpAssociationStandardMultiForm, measurementType);
}
// If errors found then return the edit form with all information entered by curator preserved
if (!criticalErrors.isEmpty()) {
// Get mapping details
model.addAttribute("mappingDetails", associationOperationsService.createMappingDetails(associationToEdit));
// Return any association errors
model.addAttribute("errors", criticalErrors);
model.addAttribute("criticalErrorsFound", true);
if (associationType.equalsIgnoreCase("interaction")) {
model.addAttribute("form", snpAssociationInteractionForm);
return "edit_snp_interaction_association";
} else {
model.addAttribute("form", snpAssociationStandardMultiForm);
// Determine view
if (associationToEdit.getMultiSnpHaplotype()) {
return "edit_multi_snp_association";
} else {
return "edit_standard_snp_association";
}
}
} else {
// Create association
Association editedAssociation;
// Request parameter determines how to process form and also which form to process
if (associationType.equalsIgnoreCase("interaction")) {
editedAssociation = snpInteractionAssociationService.createAssociation(snpAssociationInteractionForm);
} else {
editedAssociation = singleSnpMultiSnpAssociationService.createAssociation(snpAssociationStandardMultiForm);
// New snps to compare with the previousSnps.
Collection<SnpFormRow> newSnpsList = snpAssociationStandardMultiForm.getSnpFormRows();
if (newSnpsList != null && !newSnpsList.isEmpty()) {
for (SnpFormRow snp : newSnpsList) {
snps.add(snp.getSnp());
}
}
}
authorReportedGenes = associationOperationsService.getGenesIds(editedAssociation.getLoci());
if (oldAssociationReport != null) {
if ((previousAuthorReportedGenes.size() == authorReportedGenes.size()) && (snps.size() == snps.size())) {
// check the values
if ((authorReportedGenes.equals(previousAuthorReportedGenes)) && (snps.equals(previousSnps))) {
editedAssociation.setLastMappingDate(associationToEdit.getLastMappingDate());
editedAssociation.setLastMappingPerformedBy(associationToEdit.getLastMappingPerformedBy());
editedAssociation.setAssociationReport(oldAssociationReport);
isToRemapping = "no";
}
}
}
if ((oldAssociationReport != null) && (isToRemapping.compareTo("yes") == 0)) {
associationOperationsService.deleteAssocationReport(associationToEdit.getAssociationReport().getId());
}
// Save and validate form
String eRelease = ensemblRestTemplateService.getRelease();
Collection<AssociationValidationView> errors = associationOperationsService.saveEditedAssociationFromForm(study, editedAssociation, associationId, currentUserDetailsService.getUserFromRequest(request), eRelease);
// Determine if we have any errors rather than warnings
long errorCount = errors.stream().filter(validationError -> !validationError.getWarning()).count();
if (errorCount > 0) {
// Get mapping details for association we're editing
model.addAttribute("mappingDetails", associationOperationsService.createMappingDetails(associationToEdit));
model.addAttribute("errors", errors);
model.addAttribute("criticalErrorsFound", true);
if (associationType.equalsIgnoreCase("interaction")) {
model.addAttribute("form", snpAssociationInteractionForm);
return "edit_snp_interaction_association";
} else {
model.addAttribute("form", snpAssociationStandardMultiForm);
// Determine view
if (associationToEdit.getMultiSnpHaplotype()) {
return "edit_multi_snp_association";
} else {
return "edit_standard_snp_association";
}
}
} else {
redirectAttributes.addFlashAttribute("isToRemapping", isToRemapping);
return "redirect:/associations/" + associationId;
}
}
}
use of uk.ac.ebi.spot.goci.curation.model.SnpFormRow in project goci by EBISPOT.
the class SingleSnpMultiSnpAssociationServiceTest method testCreateMultiForm.
@Test
public void testCreateMultiForm() throws Exception {
assertThat(snpAssociationFormService.createForm(OR_MULTI_ASSOCIATION)).isInstanceOf(SnpAssociationStandardMultiForm.class);
SnpAssociationStandardMultiForm form = (SnpAssociationStandardMultiForm) snpAssociationFormService.createForm(OR_MULTI_ASSOCIATION);
// Check values we would expect in form
assertThat(form.getAssociationId()).as("Check form ID").isEqualTo(OR_MULTI_ASSOCIATION.getId());
assertThat(form.getSnpType()).as("Check form SNP TYPE").isEqualTo(OR_MULTI_ASSOCIATION.getSnpType());
assertThat(form.getMultiSnpHaplotype()).as("Check form MULTI SNP HAPLOTYPE").isEqualTo(OR_MULTI_ASSOCIATION.getMultiSnpHaplotype());
assertThat(form.getSnpApproved()).as("Check form SNP APPROVED").isEqualTo(OR_MULTI_ASSOCIATION.getSnpApproved());
assertThat(form.getPvalueExponent()).as("Check form PVALUE EXPONENT").isEqualTo(OR_MULTI_ASSOCIATION.getPvalueExponent());
assertThat(form.getPvalueMantissa()).as("Check form PVALUE MANTISSA").isEqualTo(OR_MULTI_ASSOCIATION.getPvalueMantissa());
assertThat(form.getStandardError()).as("Check form STANDARD ERROR").isEqualTo(OR_MULTI_ASSOCIATION.getStandardError());
assertThat(form.getRange()).as("Check form RANGE").isEqualTo(OR_MULTI_ASSOCIATION.getRange());
assertThat(form.getPvalueDescription()).as("Check form PVALUE DESCRIPTION").isEqualTo(OR_MULTI_ASSOCIATION.getPvalueDescription());
assertThat(form.getRiskFrequency()).as("Check form RISK FREQUENCY").isEqualTo(OR_MULTI_ASSOCIATION.getRiskFrequency());
assertThat(form.getDescription()).as("Check form DESCRIPTION").isEqualTo(OR_MULTI_ASSOCIATION.getDescription());
// Check EFO traits
assertThat(form.getEfoTraits()).extracting("id", "trait", "uri").contains(tuple(988L, "atrophic rhinitis", "http://www.ebi.ac.uk/efo/EFO_0007159"), tuple(989L, "HeLa", "http://www.ebi.ac.uk/efo/EFO_0001185"));
// Check null values
assertNull(form.getBetaDirection());
assertNull(form.getBetaNum());
assertNull(form.getBetaUnit());
// Test locus attributes
assertThat(form.getMultiSnpHaplotypeDescr()).as("Check form MULTI HAPLOTYPE DESCRIPTION").isEqualTo("2-SNP haplotype");
assertThat(form.getMultiSnpHaplotypeNum()).as("Check form MULTI HAPLOTYPE NUMBER").isEqualTo(2);
assertThat(form.getAuthorReportedGenes()).isInstanceOf(Collection.class);
assertThat(form.getAuthorReportedGenes()).containsOnly("ELF1");
// Test the row values
Collection<SnpFormRow> rows = form.getSnpFormRows();
assertThat(rows).hasSize(2);
assertThat(rows).extracting("snp", "strongestRiskAllele", "proxySnps").contains(tuple("rs9533090", "rs9533090-?", Collections.singletonList("rs7329174")), tuple("rs114205691", "rs114205691-?", Collections.singletonList("rs1234567")));
}
use of uk.ac.ebi.spot.goci.curation.model.SnpFormRow 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());
form.setAssociationExtension(association.getAssociationExtension());
// 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.curation.model.SnpFormRow in project goci by EBISPOT.
the class AssociationOperationsService method checkSnpAssociationFormErrors.
/**
* Check a standard SNP association form for errors, these are critical errors that would prevent creating an
* association
*
* @param form The form to validate
* @param measurementType Determine if user has selected and populated essential value on the form
*/
public List<AssociationValidationView> checkSnpAssociationFormErrors(SnpAssociationStandardMultiForm form, String measurementType) {
Collection<ValidationError> errors = new ArrayList<>();
for (SnpFormRow row : form.getSnpFormRows()) {
errors.add(errorCreationService.checkSnpValueIsPresent(row.getSnp()));
errors.add(errorCreationService.checkStrongestAlleleValueIsPresent(row.getStrongestRiskAllele()));
}
// Ensure user has entered required information on the form
if (measurementType.equals("or")) {
errors.add(errorCreationService.checkOrIsPresent(form.getOrPerCopyNum()));
}
if (measurementType.equals("beta")) {
errors.add(errorCreationService.checkBetaIsPresentAndIsNotNegative(form.getBetaNum()));
}
Collection<ValidationError> updatedError = ErrorProcessingService.checkForValidErrors(errors);
return processAssociationValidationErrors(updatedError);
}
use of uk.ac.ebi.spot.goci.curation.model.SnpFormRow 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;
}
Aggregations