Search in sources :

Example 6 with SnpAssociationStandardMultiForm

use of uk.ac.ebi.spot.goci.curation.model.SnpAssociationStandardMultiForm in project goci by EBISPOT.

the class AssociationControllerTest method addStandardSnpsWithNoErrors.

// @Test
// public void addStandardSnpsWithErrors() throws Exception {
// 
// AssociationValidationView associationValidationView =
// new AssociationValidationView("OR", "Value is empty", false);
// Collection<AssociationValidationView> errors = Collections.singletonList(associationValidationView);
// 
// // Stubbing
// when(studyRepository.findOne(Matchers.anyLong())).thenReturn(STUDY);
// when(currentUserDetailsService.getUserFromRequest(Matchers.any(HttpServletRequest.class))).thenReturn(
// SECURE_USER);
// when(associationOperationsService.checkSnpAssociationFormErrors(Matchers.any(SnpAssociationStandardMultiForm.class),
// Matchers.anyString()))
// .thenReturn(Collections.EMPTY_LIST);
// when(singleSnpMultiSnpAssociationService.createAssociation(Matchers.any(SnpAssociationStandardMultiForm.class)))
// .thenReturn(ASSOCIATION);
// when(associationOperationsService.saveAssociationCreatedFromForm(STUDY, ASSOCIATION, SECURE_USER, "")).thenReturn(
// errors);
// 
// when(ensemblRestTemplateService.getRelease()).thenReturn("88");
// mockMvc.perform(post("/studies/1234/associations/add_standard").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_standard_snp_association"));
// 
// //verify properties of bound object
// ArgumentCaptor<SnpAssociationStandardMultiForm> formArgumentCaptor =
// ArgumentCaptor.forClass(SnpAssociationStandardMultiForm.class);
// verify(associationOperationsService).checkSnpAssociationFormErrors(formArgumentCaptor.capture(),
// Matchers.anyString());
// verify(singleSnpMultiSnpAssociationService).createAssociation(formArgumentCaptor.capture());
// verify(studyRepository, times(1)).findOne(Matchers.anyLong());
// verify(currentUserDetailsService, times(1)).getUserFromRequest(Matchers.any(HttpServletRequest.class));
// verify(associationOperationsService, times(1)).saveAssociationCreatedFromForm(Matchers.any(Study.class),
// Matchers.any(Association.class),
// Matchers.any(SecureUser.class),
// Matchers.anyString());
// }
@Test
public void addStandardSnpsWithNoErrors() throws Exception {
    AssociationValidationView associationValidationView = new AssociationValidationView("SNP", "SNP identifier rs34tt is not valid", true);
    List<AssociationValidationView> errors = Collections.singletonList(associationValidationView);
    // Stubbing
    when(studyRepository.findOne(Matchers.anyLong())).thenReturn(STUDY);
    when(currentUserDetailsService.getUserFromRequest(Matchers.any(HttpServletRequest.class))).thenReturn(SECURE_USER);
    when(associationOperationsService.checkSnpAssociationFormErrors(Matchers.any(SnpAssociationStandardMultiForm.class), Matchers.anyString())).thenReturn(Collections.EMPTY_LIST);
    when(singleSnpMultiSnpAssociationService.createAssociation(Matchers.any(SnpAssociationStandardMultiForm.class))).thenReturn(ASSOCIATION);
    when(associationOperationsService.saveAssociationCreatedFromForm(STUDY, ASSOCIATION, SECURE_USER, "88")).thenReturn(errors);
    mockMvc.perform(post("/studies/1234/associations/add_standard").param("measurementType", "or")).andExpect(status().is3xxRedirection()).andExpect(model().attributeExists("study")).andExpect(model().attributeExists("measurementType")).andExpect(view().name("redirect:/associations/100"));
    // verify properties of bound object
    ArgumentCaptor<SnpAssociationStandardMultiForm> formArgumentCaptor = ArgumentCaptor.forClass(SnpAssociationStandardMultiForm.class);
    verify(associationOperationsService).checkSnpAssociationFormErrors(formArgumentCaptor.capture(), Matchers.anyString());
    verify(singleSnpMultiSnpAssociationService).createAssociation(formArgumentCaptor.capture());
    verify(studyRepository, times(1)).findOne(Matchers.anyLong());
    verify(currentUserDetailsService, times(1)).getUserFromRequest(Matchers.any(HttpServletRequest.class));
    verify(associationOperationsService, times(1)).saveAssociationCreatedFromForm(Matchers.any(Study.class), Matchers.any(Association.class), Matchers.any(SecureUser.class), Matchers.anyString());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) 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 7 with SnpAssociationStandardMultiForm

use of uk.ac.ebi.spot.goci.curation.model.SnpAssociationStandardMultiForm in project goci by EBISPOT.

the class AssociationControllerTest method editAssociationWithWarnings.

@Test
public void editAssociationWithWarnings() throws Exception {
    // Warnings will not prevent a save
    AssociationValidationView associationValidationView = new AssociationValidationView("SNP", "SNP identifier rs34tt is not valid", true);
    List<AssociationValidationView> errors = Collections.singletonList(associationValidationView);
    // Stubbing
    when(studyRepository.findOne(Matchers.anyLong())).thenReturn(STUDY);
    when(associationRepository.findOne(Matchers.anyLong())).thenReturn(ASSOCIATION);
    when(currentUserDetailsService.getUserFromRequest(Matchers.any(HttpServletRequest.class))).thenReturn(SECURE_USER);
    when(associationOperationsService.checkSnpAssociationFormErrors(Matchers.any(SnpAssociationStandardMultiForm.class), Matchers.anyString())).thenReturn(Collections.EMPTY_LIST);
    when(singleSnpMultiSnpAssociationService.createAssociation(Matchers.any(SnpAssociationStandardMultiForm.class))).thenReturn(EDITED_ASSOCIATION);
    when(associationOperationsService.saveEditedAssociationFromForm(STUDY, EDITED_ASSOCIATION, ASSOCIATION.getId(), SECURE_USER, "")).thenReturn(errors);
    mockMvc.perform(post("/associations/100").param("associationtype", "multi")).andExpect(status().is3xxRedirection()).andExpect(view().name("redirect:/associations/100"));
    // verify properties of bound object
    ArgumentCaptor<SnpAssociationStandardMultiForm> formArgumentCaptor = ArgumentCaptor.forClass(SnpAssociationStandardMultiForm.class);
    verify(associationOperationsService).checkSnpAssociationFormErrors(formArgumentCaptor.capture(), Matchers.anyString());
    verify(singleSnpMultiSnpAssociationService).createAssociation(formArgumentCaptor.capture());
    verify(studyRepository, times(1)).findOne(Matchers.anyLong());
    verify(associationRepository, times(1)).findOne(Matchers.anyLong());
    verify(currentUserDetailsService, times(1)).getUserFromRequest(Matchers.any(HttpServletRequest.class));
    verify(associationOperationsService, times(1)).saveEditedAssociationFromForm(Matchers.any(Study.class), Matchers.any(Association.class), Matchers.anyLong(), Matchers.any(SecureUser.class), Matchers.anyString());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) 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 8 with SnpAssociationStandardMultiForm

use of uk.ac.ebi.spot.goci.curation.model.SnpAssociationStandardMultiForm 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")));
}
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 9 with SnpAssociationStandardMultiForm

use of uk.ac.ebi.spot.goci.curation.model.SnpAssociationStandardMultiForm 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;
}
Also used : RiskAllele(uk.ac.ebi.spot.goci.model.RiskAllele) ArrayList(java.util.ArrayList) GenomicContext(uk.ac.ebi.spot.goci.model.GenomicContext) SnpMappingForm(uk.ac.ebi.spot.goci.curation.model.SnpMappingForm) SnpAssociationStandardMultiForm(uk.ac.ebi.spot.goci.curation.model.SnpAssociationStandardMultiForm) SnpFormRow(uk.ac.ebi.spot.goci.curation.model.SnpFormRow) Gene(uk.ac.ebi.spot.goci.model.Gene) SingleNucleotidePolymorphism(uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism) Locus(uk.ac.ebi.spot.goci.model.Locus) Location(uk.ac.ebi.spot.goci.model.Location)

Example 10 with SnpAssociationStandardMultiForm

use of uk.ac.ebi.spot.goci.curation.model.SnpAssociationStandardMultiForm in project goci by EBISPOT.

the class AssociationControllerTest method addMultiSnpsWithNoErrors.

// @Test
// public void addMultiSnpsWithErrors() throws Exception {
// AssociationValidationView associationValidationView =
// new AssociationValidationView("OR", "Value is empty", false);
// List<AssociationValidationView> errors = Collections.singletonList(associationValidationView);
// 
// // Stubbing
// when(studyRepository.findOne(Matchers.anyLong())).thenReturn(STUDY);
// when(currentUserDetailsService.getUserFromRequest(Matchers.any(HttpServletRequest.class))).thenReturn(
// SECURE_USER);
// when(associationOperationsService.checkSnpAssociationFormErrors(Matchers.any(SnpAssociationStandardMultiForm.class),
// Matchers.anyString()))
// .thenReturn(Collections.EMPTY_LIST);
// when(singleSnpMultiSnpAssociationService.createAssociation(Matchers.any(SnpAssociationStandardMultiForm.class)))
// .thenReturn(ASSOCIATION);
// when(associationOperationsService.saveAssociationCreatedFromForm(STUDY, ASSOCIATION, SECURE_USER, "")).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(singleSnpMultiSnpAssociationService).createAssociation(formArgumentCaptor.capture());
// verify(studyRepository, times(1)).findOne(Matchers.anyLong());
// verify(currentUserDetailsService, times(1)).getUserFromRequest(Matchers.any(HttpServletRequest.class));
// verify(associationOperationsService, times(1)).saveAssociationCreatedFromForm(Matchers.any(Study.class),
// Matchers.any(Association.class),
// Matchers.any(SecureUser.class),
// Matchers.anyString());
// }
@Test
public void addMultiSnpsWithNoErrors() throws Exception {
    AssociationValidationView associationValidationView = new AssociationValidationView("SNP", "SNP identifier rs34tt is not valid", true);
    List<AssociationValidationView> errors = Collections.singletonList(associationValidationView);
    // Stubbing
    when(studyRepository.findOne(Matchers.anyLong())).thenReturn(STUDY);
    when(currentUserDetailsService.getUserFromRequest(Matchers.any(HttpServletRequest.class))).thenReturn(SECURE_USER);
    when(associationOperationsService.checkSnpAssociationFormErrors(Matchers.any(SnpAssociationStandardMultiForm.class), Matchers.anyString())).thenReturn(Collections.EMPTY_LIST);
    when(singleSnpMultiSnpAssociationService.createAssociation(Matchers.any(SnpAssociationStandardMultiForm.class))).thenReturn(ASSOCIATION);
    when(associationOperationsService.saveAssociationCreatedFromForm(STUDY, ASSOCIATION, SECURE_USER, "")).thenReturn(errors);
    mockMvc.perform(post("/studies/1234/associations/add_multi").param("measurementType", "or")).andExpect(status().is3xxRedirection()).andExpect(model().attributeExists("study")).andExpect(model().attributeExists("measurementType")).andExpect(view().name("redirect:/associations/100"));
    // verify properties of bound object
    ArgumentCaptor<SnpAssociationStandardMultiForm> formArgumentCaptor = ArgumentCaptor.forClass(SnpAssociationStandardMultiForm.class);
    verify(associationOperationsService).checkSnpAssociationFormErrors(formArgumentCaptor.capture(), Matchers.anyString());
    verify(singleSnpMultiSnpAssociationService).createAssociation(formArgumentCaptor.capture());
    verify(studyRepository, times(1)).findOne(Matchers.anyLong());
    verify(currentUserDetailsService, times(1)).getUserFromRequest(Matchers.any(HttpServletRequest.class));
    verify(associationOperationsService, times(1)).saveAssociationCreatedFromForm(Matchers.any(Study.class), Matchers.any(Association.class), Matchers.any(SecureUser.class), Matchers.anyString());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) 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)

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