use of uk.ac.ebi.spot.goci.curation.model.SnpAssociationTableView in project goci by EBISPOT.
the class SnpAssociationTableViewService method createSnpAssociationTableView.
/**
* Create object, from Association, that will be returned to view
*
* @param association Association object
*/
public SnpAssociationTableView createSnpAssociationTableView(Association association) {
SnpAssociationTableView snpAssociationTableView = new SnpAssociationTableView();
// For SNP interaction studies snp, proxy snps, risk alleles etc
// should be separated by an 'x'
String delimiter = "; ";
if (association.getSnpInteraction()) {
delimiter = " x ";
}
snpAssociationTableView.setAssociationId(association.getId());
// For each locus relevant attributes
Collection<Locus> loci = association.getLoci();
Collection<String> allLociGenes = new ArrayList<>();
Collection<String> allLociRiskAlleles = new ArrayList<String>();
Collection<String> allLociSnps = new ArrayList<String>();
Collection<String> allLociProxySnps = new ArrayList<String>();
Collection<String> allLociRiskAlleleFrequencies = new ArrayList<String>();
Collection<String> allLociSnpStatuses = new ArrayList<String>();
// By looking at each locus in turn we can keep order in view
for (Locus locus : loci) {
// Store gene names, a locus can have a number of genes attached.
// Per locus create a comma separated list and add to an array.
// Further processing will then delimit this list
// either by ; or 'x' depending on association type
Collection<String> currentlocusGenes = new ArrayList<>();
String commaSeparatedGenes = "";
for (Gene gene : locus.getAuthorReportedGenes()) {
currentlocusGenes.add(gene.getGeneName());
}
if (!currentlocusGenes.isEmpty()) {
commaSeparatedGenes = String.join(", ", currentlocusGenes);
allLociGenes.add(commaSeparatedGenes);
} else {
allLociGenes.add("NR");
}
//This sort ensures that haplotype SNPs are displayed in the correct order
Collection<RiskAllele> ra = locus.getStrongestRiskAlleles().stream().sorted((v1, v2) -> Long.compare(v1.getId(), v2.getId())).collect(Collectors.toList());
for (RiskAllele riskAllele : ra) {
allLociRiskAlleles.add(riskAllele.getRiskAlleleName());
// Based on assumption we only have one locus with a single risk allele attached
if (!association.getMultiSnpHaplotype() && !association.getSnpInteraction()) {
if (riskAllele.getRiskFrequency() != null && !riskAllele.getRiskFrequency().isEmpty()) {
allLociRiskAlleleFrequencies.add(riskAllele.getRiskFrequency());
}
}
// SNPs attached to risk allele
SingleNucleotidePolymorphism snp = riskAllele.getSnp();
allLociSnps.add(snp.getRsId());
// Set proxies if present
Collection<String> currentLocusProxies = new ArrayList<>();
String commaSeparatedProxies = "";
if (riskAllele.getProxySnps() != null) {
for (SingleNucleotidePolymorphism proxySnp : riskAllele.getProxySnps()) {
currentLocusProxies.add(proxySnp.getRsId());
}
}
// Comma separate proxies in view
if (!currentLocusProxies.isEmpty()) {
commaSeparatedProxies = String.join(", ", currentLocusProxies);
allLociProxySnps.add(commaSeparatedProxies);
} else {
allLociProxySnps.add("NR");
}
// Only required for SNP interaction studies
if (association.getSnpInteraction() != null) {
if (association.getSnpInteraction()) {
// Genome wide Vs Limited List
Collection<String> snpStatus = new ArrayList<>();
String commaSeparatedSnpStatus = "";
if (riskAllele.getLimitedList() != null) {
if (riskAllele.getLimitedList()) {
snpStatus.add("LL");
}
}
if (riskAllele.getGenomeWide() != null) {
if (riskAllele.getGenomeWide()) {
snpStatus.add("GW");
}
}
if (!snpStatus.isEmpty()) {
commaSeparatedSnpStatus = String.join(", ", snpStatus);
allLociSnpStatuses.add(commaSeparatedSnpStatus);
} else {
allLociSnpStatuses.add("NR");
}
// Allele risk frequency
if (riskAllele.getRiskFrequency() != null && !riskAllele.getRiskFrequency().isEmpty()) {
allLociRiskAlleleFrequencies.add(riskAllele.getRiskFrequency());
} else {
allLociRiskAlleleFrequencies.add("NR");
}
}
}
}
}
// Create delimited strings for view
String authorReportedGenes = null;
if (allLociGenes.size() > 1) {
authorReportedGenes = String.join(delimiter, allLociGenes);
} else {
authorReportedGenes = String.join("", allLociGenes);
}
snpAssociationTableView.setAuthorReportedGenes(authorReportedGenes);
String strongestRiskAlleles = null;
if (allLociRiskAlleles.size() > 1) {
strongestRiskAlleles = String.join(delimiter, allLociRiskAlleles);
} else {
strongestRiskAlleles = String.join("", allLociRiskAlleles);
}
snpAssociationTableView.setStrongestRiskAlleles(strongestRiskAlleles);
String associationSnps = null;
if (allLociSnps.size() > 1) {
associationSnps = String.join(delimiter, allLociSnps);
} else {
associationSnps = String.join("", allLociSnps);
}
snpAssociationTableView.setSnps(associationSnps);
String associationProxies = null;
if (allLociProxySnps.size() > 1) {
associationProxies = String.join(delimiter, allLociProxySnps);
} else {
associationProxies = String.join("", allLociProxySnps);
}
snpAssociationTableView.setProxySnps(associationProxies);
// Set both risk frequencies
String associationRiskAlleleFrequencies = null;
if (allLociRiskAlleleFrequencies.size() > 1) {
associationRiskAlleleFrequencies = String.join(delimiter, allLociRiskAlleleFrequencies);
} else {
associationRiskAlleleFrequencies = String.join("", allLociRiskAlleleFrequencies);
}
snpAssociationTableView.setRiskAlleleFrequencies(associationRiskAlleleFrequencies);
snpAssociationTableView.setAssociationRiskFrequency(association.getRiskFrequency());
String associationSnpStatuses = null;
if (allLociSnpStatuses.size() > 1) {
associationSnpStatuses = String.join(delimiter, allLociSnpStatuses);
} else {
associationSnpStatuses = String.join("", allLociSnpStatuses);
}
snpAssociationTableView.setSnpStatuses(associationSnpStatuses);
snpAssociationTableView.setPvalueMantissa(association.getPvalueMantissa());
snpAssociationTableView.setPvalueExponent(association.getPvalueExponent());
snpAssociationTableView.setPvalueDescription(association.getPvalueDescription());
Collection<String> efoTraits = new ArrayList<>();
for (EfoTrait efoTrait : association.getEfoTraits()) {
efoTraits.add(efoTrait.getTrait());
}
String associationEfoTraits = null;
associationEfoTraits = String.join(", ", efoTraits);
snpAssociationTableView.setEfoTraits(associationEfoTraits);
// Set OR values
snpAssociationTableView.setOrPerCopyNum(association.getOrPerCopyNum());
snpAssociationTableView.setOrPerCopyRecip(association.getOrPerCopyRecip());
snpAssociationTableView.setOrPerCopyRecipRange(association.getOrPerCopyRecipRange());
// Set beta values
snpAssociationTableView.setBetaNum(association.getBetaNum());
snpAssociationTableView.setBetaDirection(association.getBetaDirection());
snpAssociationTableView.setBetaUnit(association.getBetaUnit());
snpAssociationTableView.setRange(association.getRange());
snpAssociationTableView.setDescription(association.getDescription());
snpAssociationTableView.setStandardError(association.getStandardError());
snpAssociationTableView.setAssociationType(association.getSnpType());
if (association.getMultiSnpHaplotype() != null) {
if (association.getMultiSnpHaplotype()) {
snpAssociationTableView.setMultiSnpHaplotype("Yes");
}
if (!association.getMultiSnpHaplotype()) {
snpAssociationTableView.setMultiSnpHaplotype("No");
}
}
if (association.getSnpInteraction() != null) {
if (association.getSnpInteraction()) {
snpAssociationTableView.setSnpInteraction("Yes");
}
if (!association.getSnpInteraction()) {
snpAssociationTableView.setSnpInteraction("No");
}
}
if (association.getSnpApproved() != null) {
if (association.getSnpApproved()) {
snpAssociationTableView.setSnpApproved("Yes");
}
if (!association.getSnpApproved()) {
snpAssociationTableView.setSnpApproved("No");
}
}
// Get validation warnings
snpAssociationTableView.setValidationWarnings(associationValidationReportService.getWarningSet(association.getId()));
// Get mapping details
if (association.getLastMappingPerformedBy() != null) {
snpAssociationTableView.setLastMappingPerformedBy(association.getLastMappingPerformedBy());
}
snpAssociationTableView.setMappingStatus("false");
if (association.getLastMappingDate() != null) {
snpAssociationTableView.setMappingStatus("true");
}
if (association.getLastMappingDate() != null) {
DateFormat df = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
String dateOfLastMapping = df.format(association.getLastMappingDate());
snpAssociationTableView.setLastMappingDate(dateOfLastMapping);
}
return snpAssociationTableView;
}
use of uk.ac.ebi.spot.goci.curation.model.SnpAssociationTableView in project goci by EBISPOT.
the class PrintControllerTest method viewPrintableDetailsOfStudy.
@Test
public void viewPrintableDetailsOfStudy() throws Exception {
// Set up some basic views
SnpAssociationTableView snpAssociationTableView1 = new SnpAssociationTableView();
snpAssociationTableView1.setBetaNum((float) 0.012);
SnpAssociationTableView snpAssociationTableView2 = new SnpAssociationTableView();
snpAssociationTableView1.setOrPerCopyNum((float) 5.97);
// Stub
when(studyRepository.findOne(STUDY.getId())).thenReturn(STUDY);
Collection<Ancestry> initialStudyAncestryDescriptions = new ArrayList<>();
Collection<Ancestry> replicationStudyAncestryDescriptions = new ArrayList<>();
initialStudyAncestryDescriptions.add(ETH1);
replicationStudyAncestryDescriptions.add(ETH2);
replicationStudyAncestryDescriptions.add(ETH3);
when(ancestryRepository.findByStudyIdAndType(STUDY.getId(), "initial")).thenReturn(initialStudyAncestryDescriptions);
when(ancestryRepository.findByStudyIdAndType(STUDY.getId(), "replication")).thenReturn(replicationStudyAncestryDescriptions);
when(studyPrintService.generatePrintView(STUDY.getId())).thenReturn(Arrays.asList(snpAssociationTableView1, snpAssociationTableView2));
MvcResult mvcResult = this.mockMvc.perform(get("/studies/101/printview").accept(MediaType.TEXT_HTML_VALUE)).andExpect(request().asyncStarted()).andExpect(request().asyncResult("study_printview")).andReturn();
this.mockMvc.perform(asyncDispatch(mvcResult)).andExpect(status().isOk()).andExpect(forwardedUrl("study_printview")).andExpect(model().attributeExists("studiesToPrint")).andExpect(model().attribute("studiesToPrint", instanceOf(Hashtable.class)));
}
use of uk.ac.ebi.spot.goci.curation.model.SnpAssociationTableView in project goci by EBISPOT.
the class StudyPrintService method generatePrintView.
public Collection<SnpAssociationTableView> generatePrintView(Long studyId) {
// Get relevant study details
Study studyToView = studyRepository.findOne(studyId);
// Association information
Collection<Association> associations = new ArrayList<>();
associations.addAll(associationRepository.findByStudyId(studyId));
// For our associations create a table view object and return
Collection<SnpAssociationTableView> snpAssociationTableViews = new ArrayList<SnpAssociationTableView>();
for (Association association : associations) {
SnpAssociationTableView snpAssociationTableView = snpAssociationTableViewService.createSnpAssociationTableView(association);
snpAssociationTableViews.add(snpAssociationTableView);
}
return snpAssociationTableViews;
}
use of uk.ac.ebi.spot.goci.curation.model.SnpAssociationTableView in project goci by EBISPOT.
the class AssociationController method viewStudySnps.
/* Study SNP/Associations */
// Generate list of SNP associations linked to a study
@RequestMapping(value = "/studies/{studyId}/associations", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET)
public String viewStudySnps(Model model, @PathVariable Long studyId, @RequestParam(required = false) Long associationId) {
// Get all associations for a study
Collection<Association> associations = associationRepository.findByStudyId(studyId);
// For our associations create a table view object and return
Collection<SnpAssociationTableView> snpAssociationTableViews = new ArrayList<SnpAssociationTableView>();
for (Association association : associations) {
SnpAssociationTableView snpAssociationTableView = snpAssociationTableViewService.createSnpAssociationTableView(association);
snpAssociationTableViews.add(snpAssociationTableView);
}
model.addAttribute("snpAssociationTableViews", snpAssociationTableViews);
// Determine last viewed association
LastViewedAssociation lastViewedAssociation = associationOperationsService.getLastViewedAssociation(associationId);
model.addAttribute("lastViewedAssociation", lastViewedAssociation);
// Pass back count of associations
Integer totalAssociations = associations.size();
model.addAttribute("totalAssociations", totalAssociations);
// Also passes back study object to view so we can create links back to main study page
model.addAttribute("study", studyRepository.findOne(studyId));
return "study_association";
}
use of uk.ac.ebi.spot.goci.curation.model.SnpAssociationTableView in project goci by EBISPOT.
the class PrintController method getStudyInfoToPrint.
protected ArrayList<Object> getStudyInfoToPrint(Study studyToPrint) {
// Get relevant study details
Long studyId = studyToPrint.getId();
// Get association information
Collection<SnpAssociationTableView> snpAssociationTableViews = studyPrintService.generatePrintView(studyId);
// Get housekeeping and ancestry information
Housekeeping housekeeping = studyToPrint.getHousekeeping();
Collection<StudyNote> studyNotes = studyToPrint.getNotes();
String initialSampleDescription = studyToPrint.getInitialSampleSize();
String replicateSampleDescription = studyToPrint.getReplicateSampleSize();
// Creating a Hashtable
ArrayList<Object> infoToPrint = new ArrayList<Object>();
infoToPrint.add(studyToPrint);
infoToPrint.add(housekeeping);
infoToPrint.add(initialSampleDescription);
infoToPrint.add(replicateSampleDescription);
infoToPrint.add(ancestryRepository.findByStudyIdAndType(studyId, "initial"));
infoToPrint.add(ancestryRepository.findByStudyIdAndType(studyId, "replication"));
infoToPrint.add(snpAssociationTableViews);
infoToPrint.add(studyNotes);
return infoToPrint;
}
Aggregations