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());
}
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());
}
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")));
}
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;
}
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());
}
Aggregations