Search in sources :

Example 11 with SnpAssociationStandardMultiForm

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());
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) SnpAssociationStandardMultiForm(uk.ac.ebi.spot.goci.curation.model.SnpAssociationStandardMultiForm) LastViewedAssociation(uk.ac.ebi.spot.goci.curation.model.LastViewedAssociation) Association(uk.ac.ebi.spot.goci.model.Association) AssociationValidationView(uk.ac.ebi.spot.goci.curation.model.AssociationValidationView) SecureUser(uk.ac.ebi.spot.goci.model.SecureUser) Test(org.junit.Test)

Example 12 with SnpAssociationStandardMultiForm

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";
}
Also used : SnpAssociationStandardMultiForm(uk.ac.ebi.spot.goci.curation.model.SnpAssociationStandardMultiForm) SnpFormRow(uk.ac.ebi.spot.goci.curation.model.SnpFormRow) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with SnpAssociationStandardMultiForm

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")));
}
Also used : SnpAssociationStandardMultiForm(uk.ac.ebi.spot.goci.curation.model.SnpAssociationStandardMultiForm) SnpFormRow(uk.ac.ebi.spot.goci.curation.model.SnpFormRow) Test(org.junit.Test)

Example 14 with SnpAssociationStandardMultiForm

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";
}
Also used : SnpAssociationStandardMultiForm(uk.ac.ebi.spot.goci.curation.model.SnpAssociationStandardMultiForm) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with SnpAssociationStandardMultiForm

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();
        }
    }
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) CheckMappingService(uk.ac.ebi.spot.goci.curation.service.CheckMappingService) LoggerFactory(org.slf4j.LoggerFactory) SnpAssociationInteractionForm(uk.ac.ebi.spot.goci.curation.model.SnpAssociationInteractionForm) Autowired(org.springframework.beans.factory.annotation.Autowired) Valid(javax.validation.Valid) AssociationOperationsService(uk.ac.ebi.spot.goci.curation.service.AssociationOperationsService) PreDestroy(javax.annotation.PreDestroy) Model(org.springframework.ui.Model) Future(java.util.concurrent.Future) AssociationDeletionService(uk.ac.ebi.spot.goci.curation.service.AssociationDeletionService) uk.ac.ebi.spot.goci.model(uk.ac.ebi.spot.goci.model) StudyRepository(uk.ac.ebi.spot.goci.repository.StudyRepository) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) EnsemblRestTemplateService(uk.ac.ebi.spot.goci.service.EnsemblRestTemplateService) DateFormat(java.text.DateFormat) RedirectAttributes(org.springframework.web.servlet.mvc.support.RedirectAttributes) HttpSession(javax.servlet.http.HttpSession) MediaType(org.springframework.http.MediaType) EventsViewService(uk.ac.ebi.spot.goci.curation.service.EventsViewService) PageRequest(org.springframework.data.domain.PageRequest) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Page(org.springframework.data.domain.Page) SnpFormColumn(uk.ac.ebi.spot.goci.curation.model.SnpFormColumn) AssociationUploadErrorView(uk.ac.ebi.spot.goci.curation.model.AssociationUploadErrorView) FileNotFoundException(java.io.FileNotFoundException) Executors(java.util.concurrent.Executors) SingleSnpMultiSnpAssociationService(uk.ac.ebi.spot.goci.curation.service.SingleSnpMultiSnpAssociationService) SnpAssociationTableViewService(uk.ac.ebi.spot.goci.curation.service.SnpAssociationTableViewService) LastViewedAssociation(uk.ac.ebi.spot.goci.curation.model.LastViewedAssociation) SnpInteractionAssociationService(uk.ac.ebi.spot.goci.curation.service.SnpInteractionAssociationService) InitBinder(org.springframework.web.bind.annotation.InitBinder) CurrentUserDetailsService(uk.ac.ebi.spot.goci.curation.service.CurrentUserDetailsService) FileUploadException(uk.ac.ebi.spot.goci.curation.exception.FileUploadException) Async(org.springframework.scheduling.annotation.Async) java.util(java.util) SnpAssociationTableView(uk.ac.ebi.spot.goci.curation.model.SnpAssociationTableView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) SimpleDateFormat(java.text.SimpleDateFormat) BindingResult(org.springframework.validation.BindingResult) Callable(java.util.concurrent.Callable) Controller(org.springframework.stereotype.Controller) SnpAssociationStandardMultiForm(uk.ac.ebi.spot.goci.curation.model.SnpAssociationStandardMultiForm) EfoTraitRepository(uk.ac.ebi.spot.goci.repository.EfoTraitRepository) AssociationService(uk.ac.ebi.spot.goci.service.AssociationService) Value(org.springframework.beans.factory.annotation.Value) AssociationValidationReportService(uk.ac.ebi.spot.goci.curation.service.AssociationValidationReportService) HttpServletRequest(javax.servlet.http.HttpServletRequest) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ExecutorService(java.util.concurrent.ExecutorService) DataIntegrityException(uk.ac.ebi.spot.goci.curation.exception.DataIntegrityException) Logger(org.slf4j.Logger) AssociationUploadService(uk.ac.ebi.spot.goci.curation.service.AssociationUploadService) AssociationRepository(uk.ac.ebi.spot.goci.repository.AssociationRepository) HttpServletResponse(javax.servlet.http.HttpServletResponse) SnpAssociationForm(uk.ac.ebi.spot.goci.curation.model.SnpAssociationForm) EnsemblMappingException(uk.ac.ebi.spot.goci.exception.EnsemblMappingException) SheetProcessingException(uk.ac.ebi.spot.goci.exception.SheetProcessingException) IOException(java.io.IOException) CheckEfoTermAssignmentService(uk.ac.ebi.spot.goci.curation.service.CheckEfoTermAssignmentService) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) StudyAssociationBatchDeletionEventService(uk.ac.ebi.spot.goci.curation.service.StudyAssociationBatchDeletionEventService) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) MapCatalogService(uk.ac.ebi.spot.goci.service.MapCatalogService) SnpFormRow(uk.ac.ebi.spot.goci.curation.model.SnpFormRow) WebDataBinder(org.springframework.web.bind.WebDataBinder) MultipartFile(org.springframework.web.multipart.MultipartFile) AssociationDownloadService(uk.ac.ebi.spot.goci.curation.service.AssociationDownloadService) AssociationValidationView(uk.ac.ebi.spot.goci.curation.model.AssociationValidationView) MappingDetails(uk.ac.ebi.spot.goci.curation.model.MappingDetails) LastViewedAssociation(uk.ac.ebi.spot.goci.curation.model.LastViewedAssociation) AssociationValidationView(uk.ac.ebi.spot.goci.curation.model.AssociationValidationView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SnpAssociationStandardMultiForm (uk.ac.ebi.spot.goci.curation.model.SnpAssociationStandardMultiForm)15 AssociationValidationView (uk.ac.ebi.spot.goci.curation.model.AssociationValidationView)10 LastViewedAssociation (uk.ac.ebi.spot.goci.curation.model.LastViewedAssociation)10 SnpFormRow (uk.ac.ebi.spot.goci.curation.model.SnpFormRow)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 Test (org.junit.Test)7 FileNotFoundException (java.io.FileNotFoundException)5 IOException (java.io.IOException)5 DateFormat (java.text.DateFormat)5 SimpleDateFormat (java.text.SimpleDateFormat)5 java.util (java.util)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 Valid (javax.validation.Valid)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 Qualifier (org.springframework.beans.factory.annotation.Qualifier)5 Value (org.springframework.beans.factory.annotation.Value)5 Sort (org.springframework.data.domain.Sort)5 MediaType (org.springframework.http.MediaType)5