use of uk.ac.ebi.spot.goci.curation.model.SnpAssociationStandardMultiForm in project goci by EBISPOT.
the class AssociationControllerTest method addMultiSnpsWithRowErrors.
@Test
public void addMultiSnpsWithRowErrors() throws Exception {
AssociationValidationView associationValidationView = new AssociationValidationView("SNP", "Value is empty", false);
List<AssociationValidationView> errors = Collections.singletonList(associationValidationView);
// Stubbing
when(studyRepository.findOne(Matchers.anyLong())).thenReturn(STUDY);
when(associationOperationsService.checkSnpAssociationFormErrors(Matchers.any(SnpAssociationStandardMultiForm.class), Matchers.anyString())).thenReturn(errors);
mockMvc.perform(post("/studies/1234/associations/add_multi").param("measurementType", "or")).andExpect(status().isOk()).andExpect(model().attribute("form", instanceOf(SnpAssociationStandardMultiForm.class))).andExpect(model().attribute("errors", instanceOf(List.class))).andExpect(model().attribute("errors", hasSize(1))).andExpect(model().attributeExists("study")).andExpect(model().attributeExists("measurementType")).andExpect(view().name("add_multi_snp_association"));
// verify properties of bound object
ArgumentCaptor<SnpAssociationStandardMultiForm> formArgumentCaptor = ArgumentCaptor.forClass(SnpAssociationStandardMultiForm.class);
verify(associationOperationsService).checkSnpAssociationFormErrors(formArgumentCaptor.capture(), Matchers.anyString());
verify(studyRepository, times(1)).findOne(Matchers.anyLong());
verifyZeroInteractions(singleSnpMultiSnpAssociationService);
verifyZeroInteractions(currentUserDetailsService);
verify(associationOperationsService, never()).saveAssociationCreatedFromForm(Matchers.any(Study.class), Matchers.any(Association.class), Matchers.any(SecureUser.class), Matchers.anyString());
}
use of uk.ac.ebi.spot.goci.curation.model.SnpAssociationStandardMultiForm in project goci by EBISPOT.
the class AssociationController method addStandardSnpsView.
// Generate a empty form page to add standard snp
@RequestMapping(value = "/studies/{studyId}/associations/add_standard", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET)
public String addStandardSnpsView(Model model, @PathVariable Long studyId, @RequestParam(required = true) String measurementType) {
// Return form object
SnpAssociationStandardMultiForm emptyForm = new SnpAssociationStandardMultiForm();
// Add one row by default and set description
emptyForm.getSnpFormRows().add(new SnpFormRow());
// Measurement type determines whether we render a OR/Beta form
model.addAttribute("form", emptyForm);
model.addAttribute("measurementType", measurementType);
// Also passes back study object to view so we can create links back to main study page
model.addAttribute("study", studyRepository.findOne(studyId));
return "add_standard_snp_association";
}
use of uk.ac.ebi.spot.goci.curation.model.SnpAssociationStandardMultiForm in project goci by EBISPOT.
the class SingleSnpMultiSnpAssociationServiceTest method testCreateSingleForm.
@Test
public void testCreateSingleForm() throws Exception {
assertThat(snpAssociationFormService.createForm(BETA_SINGLE_ASSOCIATION)).isInstanceOf(SnpAssociationStandardMultiForm.class);
SnpAssociationStandardMultiForm form = (SnpAssociationStandardMultiForm) snpAssociationFormService.createForm(BETA_SINGLE_ASSOCIATION);
// Check values we would expect in form
assertThat(form.getAssociationId()).as("Check form ID").isEqualTo(BETA_SINGLE_ASSOCIATION.getId());
assertThat(form.getBetaDirection()).as("Check form BETA DIRECTION").isEqualTo(BETA_SINGLE_ASSOCIATION.getBetaDirection());
assertThat(form.getBetaUnit()).as("Check form BETA UNIT").isEqualTo(BETA_SINGLE_ASSOCIATION.getBetaUnit());
assertThat(form.getBetaNum()).as("Check form BETA NUM").isEqualTo(BETA_SINGLE_ASSOCIATION.getBetaNum());
assertThat(form.getSnpType()).as("Check form SNP TYPE").isEqualTo(BETA_SINGLE_ASSOCIATION.getSnpType());
assertThat(form.getMultiSnpHaplotype()).as("Check form MULTI SNP HAPLOTYPE").isEqualTo(BETA_SINGLE_ASSOCIATION.getMultiSnpHaplotype());
assertThat(form.getSnpApproved()).as("Check form SNP APPROVED").isEqualTo(BETA_SINGLE_ASSOCIATION.getSnpApproved());
assertThat(form.getPvalueExponent()).as("Check form PVALUE EXPONENT").isEqualTo(BETA_SINGLE_ASSOCIATION.getPvalueExponent());
assertThat(form.getPvalueMantissa()).as("Check form PVALUE MANTISSA").isEqualTo(BETA_SINGLE_ASSOCIATION.getPvalueMantissa());
assertThat(form.getStandardError()).as("Check form STANDARD ERROR").isEqualTo(BETA_SINGLE_ASSOCIATION.getStandardError());
assertThat(form.getRange()).as("Check form RANGE").isEqualTo(BETA_SINGLE_ASSOCIATION.getRange());
assertThat(form.getPvalueDescription()).as("Check form PVALUE DESCRIPTION").isEqualTo(BETA_SINGLE_ASSOCIATION.getPvalueDescription());
assertThat(form.getRiskFrequency()).as("Check form RISK FREQUENCY").isEqualTo(BETA_SINGLE_ASSOCIATION.getRiskFrequency());
assertThat(form.getDescription()).as("Check form DESCRIPTION").isEqualTo(BETA_SINGLE_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.getOrPerCopyNum());
assertNull(form.getOrPerCopyRecip());
assertNull(form.getOrPerCopyRecipRange());
assertNull(form.getMultiSnpHaplotypeNum());
// Test locus attributes
assertThat(form.getMultiSnpHaplotypeDescr()).as("Check form MULTI HAPLOTYPE DESCRIPTION").isEqualTo("Single variant");
assertThat(form.getAuthorReportedGenes()).isInstanceOf(Collection.class);
assertThat(form.getAuthorReportedGenes()).contains("NEGR1", "FRS2");
// Test the row values
Collection<SnpFormRow> rows = form.getSnpFormRows();
assertThat(rows).hasSize(1);
assertThat(rows).extracting("snp", "strongestRiskAllele", "proxySnps").containsExactly(tuple("rs579459", "rs579459-?", Collections.singletonList("rs6538678")));
}
use of uk.ac.ebi.spot.goci.curation.model.SnpAssociationStandardMultiForm in project goci by EBISPOT.
the class AssociationController method addMultiSnpsView.
// Generate a empty form page to add multi-snp haplotype
@RequestMapping(value = "/studies/{studyId}/associations/add_multi", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET)
public String addMultiSnpsView(Model model, @PathVariable Long studyId, @RequestParam(required = true) String measurementType) {
// Return form object
SnpAssociationStandardMultiForm emptyForm = new SnpAssociationStandardMultiForm();
emptyForm.setMultiSnpHaplotype(true);
// Measurement type determines whether we render a OR/Beta form
model.addAttribute("form", emptyForm);
model.addAttribute("measurementType", measurementType);
// Also passes back study object to view so we can create links back to main study page
model.addAttribute("study", studyRepository.findOne(studyId));
return "add_multi_snp_association";
}
use of uk.ac.ebi.spot.goci.curation.model.SnpAssociationStandardMultiForm 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 = associationOperationsService.saveAssociationCreatedFromForm(study, newAssociation, 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) {
model.addAttribute("errors", errors);
model.addAttribute("form", snpAssociationStandardMultiForm);
model.addAttribute("criticalErrorsFound", true);
return "add_standard_snp_association";
} else {
return "redirect:/associations/" + newAssociation.getId();
}
}
}
Aggregations