use of uk.ac.ebi.spot.goci.curation.model.AssociationValidationView 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.checkSnpAssociationInteractionFormErrors(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.AssociationValidationView in project goci by EBISPOT.
the class AssociationController method addMultiSnps.
@RequestMapping(value = "/studies/{studyId}/associations/add_multi", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST)
public String addMultiSnps(@ModelAttribute("form") @Valid SnpAssociationStandardMultiForm snpAssociationStandardMultiForm, BindingResult bindingResult, @PathVariable Long studyId, Model model, @RequestParam(required = true) String measurementType, HttpServletRequest request) throws EnsemblMappingException {
Study study = studyRepository.findOne(studyId);
model.addAttribute("study", study);
model.addAttribute("measurementType", measurementType);
// Binding vs Validator issue. File: messages.properties
if (bindingResult.hasErrors()) {
model.addAttribute("form", snpAssociationStandardMultiForm);
return "add_multi_snp_association";
}
// Check for errors in form that would prevent saving an association
List<AssociationValidationView> rowErrors = associationOperationsService.checkSnpAssociationFormErrors(snpAssociationStandardMultiForm, measurementType);
if (!rowErrors.isEmpty()) {
model.addAttribute("errors", rowErrors);
model.addAttribute("form", snpAssociationStandardMultiForm);
model.addAttribute("criticalErrorsFound", true);
return "add_multi_snp_association";
} else {
// Create an association object from details in returned form
Association newAssociation = singleSnpMultiSnpAssociationService.createAssociation(snpAssociationStandardMultiForm);
// Save and validate form
String eRelease = ensemblRestTemplateService.getRelease();
Collection<AssociationValidationView> errors = null;
try {
errors = associationOperationsService.saveAssociationCreatedFromForm(study, newAssociation, currentUserDetailsService.getUserFromRequest(request), eRelease);
} catch (EnsemblMappingException e) {
return "ensembl_mapping_failure";
}
// Determine if we have any errors rather than warnings
long errorCount = errors.stream().filter(validationError -> !validationError.getWarning()).count();
if (errorCount > 0) {
model.addAttribute("errors", errors);
model.addAttribute("form", snpAssociationStandardMultiForm);
model.addAttribute("criticalErrorsFound", true);
return "add_multi_snp_association";
} else {
return "redirect:/associations/" + newAssociation.getId();
}
}
}
use of uk.ac.ebi.spot.goci.curation.model.AssociationValidationView in project goci by EBISPOT.
the class AssociationController method validateUnapproved.
/**
- * Run mapping pipeline on all SNPs in a study
- *
- * @param studyId Study ID in database
- * @param redirectAttributes attributes for a redirect scenario
- */
@RequestMapping(value = "/studies/{studyId}/associations/validate_unapproved", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET)
public String validateUnapproved(@PathVariable Long studyId, RedirectAttributes redirectAttributes, Model model, HttpServletRequest request) throws // @RequestParam(required = false) Long associationId)
EnsemblMappingException {
Study study = studyRepository.findOne(studyId);
// For the study get all associations
Collection<Association> studyAssociations = associationRepository.findByStudyId(studyId);
for (Association associationToValidate : studyAssociations) {
if (!associationToValidate.getSnpApproved()) {
String measurementType = associationOperationsService.determineIfAssociationIsOrType(associationToValidate);
List<AssociationValidationView> criticalErrors = new ArrayList<>();
if (associationToValidate.getSnpInteraction()) {
criticalErrors = associationOperationsService.checkSnpAssociationInteractionFormErrors((SnpAssociationInteractionForm) associationOperationsService.generateForm(associationToValidate), measurementType);
} else {
criticalErrors = associationOperationsService.checkSnpAssociationFormErrors((SnpAssociationStandardMultiForm) associationOperationsService.generateForm(associationToValidate), measurementType);
}
//if an association has critical errors, go straight to that association
if (!criticalErrors.isEmpty()) {
model.addAttribute("study", study);
model.addAttribute("measurementType", measurementType);
// Get mapping details
model.addAttribute("mappingDetails", associationOperationsService.createMappingDetails(associationToValidate));
// Return any association errors
model.addAttribute("errors", criticalErrors);
model.addAttribute("criticalErrorsFound", true);
if (associationToValidate.getSnpInteraction()) {
model.addAttribute("form", associationOperationsService.generateForm(associationToValidate));
return "redirect:/associations/" + associationToValidate.getId();
// return "edit_snp_interaction_association";
} else {
model.addAttribute("form", associationOperationsService.generateForm(associationToValidate));
// Determine view
if (associationToValidate.getMultiSnpHaplotype()) {
return "redirect:/associations/" + associationToValidate.getId();
// return "edit_multi_snp_association";
} else {
// return "edit_standard_snp_association";
return "redirect:/associations/" + associationToValidate.getId();
}
}
} else // if there are no criticial errors, save the validation and go to the next association
{
// Save and validate form
String eRelease = ensemblRestTemplateService.getRelease();
Collection<AssociationValidationView> errors = associationOperationsService.validateAndSaveAssociation(study, associationToValidate, currentUserDetailsService.getUserFromRequest(request), eRelease);
// Determine if we have any errors rather than warnings
long errorCount = errors.stream().filter(validationError -> !validationError.getWarning()).count();
//if there are errors rather than warnings, go straight to the page to edit
if (errorCount > 0) {
model.addAttribute("study", study);
model.addAttribute("measurementType", measurementType);
// Get mapping details for association we're editing
model.addAttribute("mappingDetails", associationOperationsService.createMappingDetails(associationToValidate));
model.addAttribute("errors", errors);
model.addAttribute("criticalErrorsFound", true);
if (associationToValidate.getSnpInteraction()) {
model.addAttribute("form", associationOperationsService.generateForm(associationToValidate));
// return "edit_snp_interaction_association";
return "redirect:/associations/" + associationToValidate.getId();
} else {
model.addAttribute("form", associationOperationsService.generateForm(associationToValidate));
// Determine view
if (associationToValidate.getMultiSnpHaplotype()) {
// return "edit_multi_snp_association";
return "redirect:/associations/" + associationToValidate.getId();
} else {
// return "edit_standard_snp_association";
return "redirect:/associations/" + associationToValidate.getId();
}
}
}
}
}
}
String message = "Mapping complete, please check for any errors displayed in the 'Errors' column";
redirectAttributes.addFlashAttribute("mappingComplete", message);
return "redirect:/studies/" + studyId + "/associations";
}
use of uk.ac.ebi.spot.goci.curation.model.AssociationValidationView in project goci by EBISPOT.
the class AssociationOperationsService method saveEditedAssociationFromForm.
/**
* Save edited association
*
* @param study Study to assign association to
* @param association Association to validate and save
* @param associationId existing association Id
* @param user
*/
public Collection<AssociationValidationView> saveEditedAssociationFromForm(Study study, Association association, Long associationId, SecureUser user, String eRelease) throws EnsemblMappingException {
// Validate association
Collection<ValidationError> associationValidationErrors = validationService.runAssociationValidation(association, "full", eRelease);
// Create errors view that will be returned via controller
Collection<AssociationValidationView> associationValidationViews = processAssociationValidationErrors(associationValidationErrors);
// Validation returns warnings and errors, errors prevent a save action
long errorCount = associationValidationErrors.parallelStream().filter(validationError -> !validationError.getWarning()).count();
if (errorCount == 0) {
// Set ID of new association to the ID of the association we're currently editing
association.setId(associationId);
// Check for existing loci, when editing delete any existing loci and risk alleles
// They will be recreated as part of the save method
Association associationUserIsEditing = associationRepository.findOne(associationId);
lociAttributesService.deleteLocusAndRiskAlleles(associationUserIsEditing);
// Add events
association.setEvents(associationUserIsEditing.getEvents());
// Add update event and save
createAssociationUpdateEvent(association, user);
saveAssociation(association, study, associationValidationErrors);
// Run mapping on association
// runMapping(study.getHousekeeping().getCurator(), association, user);
}
return associationValidationViews;
}
use of uk.ac.ebi.spot.goci.curation.model.AssociationValidationView in project goci by EBISPOT.
the class AssociationController method addStandardSnps.
// Add new standard association/snp information to a study
@RequestMapping(value = "/studies/{studyId}/associations/add_standard", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST)
public String addStandardSnps(@ModelAttribute("form") @Valid SnpAssociationStandardMultiForm snpAssociationStandardMultiForm, BindingResult bindingResult, @PathVariable Long studyId, Model model, @RequestParam(required = true) String measurementType, HttpServletRequest request) throws EnsemblMappingException {
Study study = studyRepository.findOne(studyId);
model.addAttribute("study", study);
model.addAttribute("measurementType", measurementType);
// Binding vs Validator issue. File: messages.properties
if (bindingResult.hasErrors()) {
model.addAttribute("form", snpAssociationStandardMultiForm);
return "add_standard_snp_association";
}
// Check for errors in form that would prevent saving an association
List<AssociationValidationView> rowErrors = associationOperationsService.checkSnpAssociationFormErrors(snpAssociationStandardMultiForm, measurementType);
if (!rowErrors.isEmpty()) {
model.addAttribute("errors", rowErrors);
model.addAttribute("form", snpAssociationStandardMultiForm);
model.addAttribute("criticalErrorsFound", true);
return "add_standard_snp_association";
} else {
// Create an association object from details in returned form
Association newAssociation = singleSnpMultiSnpAssociationService.createAssociation(snpAssociationStandardMultiForm);
// Save and validate form
String eRelease = ensemblRestTemplateService.getRelease();
Collection<AssociationValidationView> errors = null;
try {
errors = associationOperationsService.saveAssociationCreatedFromForm(study, newAssociation, currentUserDetailsService.getUserFromRequest(request), eRelease);
} catch (EnsemblMappingException e) {
return "ensembl_mapping_failure";
}
// Determine if we have any errors rather than warnings
long errorCount = errors.stream().filter(validationError -> !validationError.getWarning()).count();
if (errorCount > 0) {
model.addAttribute("errors", errors);
model.addAttribute("form", snpAssociationStandardMultiForm);
model.addAttribute("criticalErrorsFound", true);
return "add_standard_snp_association";
} else {
return "redirect:/associations/" + newAssociation.getId();
}
}
}
Aggregations