use of uk.ac.ebi.spot.goci.model.Association in project goci by EBISPOT.
the class AssociationDownloadService method extractGeneticData.
private void extractGeneticData(Association association, StringBuilder line) {
final StringBuilder strongestAllele = new StringBuilder();
final StringBuilder reportedGenes = new StringBuilder();
final StringBuilder rsId = new StringBuilder();
final StringBuilder proxySnpsRsIds = new StringBuilder();
final StringBuilder riskAlleleFrequency = new StringBuilder();
// Set our delimiter for download spreadsheet
final String delimiter;
if (association.getSnpInteraction() != null && association.getSnpInteraction()) {
delimiter = " x ";
} else {
delimiter = "; ";
}
// Interaction specific values
if (association.getSnpInteraction() != null && association.getSnpInteraction()) {
association.getLoci().forEach(locus -> {
Collection<RiskAllele> ra = locus.getStrongestRiskAlleles().stream().sorted((v1, v2) -> Long.compare(v1.getId(), v2.getId())).collect(Collectors.toList());
ra.forEach(riskAllele -> {
if (riskAllele.getRiskFrequency() != null && !riskAllele.getRiskFrequency().isEmpty()) {
String frequency = riskAllele.getRiskFrequency();
setOrAppend(riskAlleleFrequency, frequency, delimiter);
} else {
setOrAppend(riskAlleleFrequency, "NR", delimiter);
}
});
Collection<String> currentLocusGenes = new ArrayList<>();
String commaSeparatedGenes = "";
locus.getAuthorReportedGenes().forEach(gene -> {
currentLocusGenes.add(gene.getGeneName().trim());
});
if (!currentLocusGenes.isEmpty()) {
commaSeparatedGenes = String.join(", ", currentLocusGenes);
setOrAppend(reportedGenes, commaSeparatedGenes, delimiter);
} else {
setOrAppend(reportedGenes, "NR", delimiter);
}
});
} else {
// Single study or a haplotype
association.getLoci().forEach(locus -> {
Collection<RiskAllele> ra = locus.getStrongestRiskAlleles().stream().sorted((v1, v2) -> Long.compare(v1.getId(), v2.getId())).collect(Collectors.toList());
ra.forEach(riskAllele -> {
setOrAppend(riskAlleleFrequency, "", "");
});
locus.getAuthorReportedGenes().forEach(gene -> {
setOrAppend(reportedGenes, gene.getGeneName().trim(), ", ");
});
});
}
// Set attributes common to all associations
association.getLoci().forEach(locus -> {
Collection<RiskAllele> ra = locus.getStrongestRiskAlleles().stream().sorted((v1, v2) -> Long.compare(v1.getId(), v2.getId())).collect(Collectors.toList());
ra.forEach(riskAllele -> {
setOrAppend(strongestAllele, riskAllele.getRiskAlleleName(), delimiter);
SingleNucleotidePolymorphism snp = riskAllele.getSnp();
setOrAppend(rsId, snp.getRsId(), delimiter);
Collection<String> currentLocusProxies = new ArrayList<>();
String colonSeparatedProxies = "";
if (riskAllele.getProxySnps() != null) {
for (SingleNucleotidePolymorphism proxySnp : riskAllele.getProxySnps()) {
currentLocusProxies.add(proxySnp.getRsId());
}
}
if (!currentLocusProxies.isEmpty()) {
colonSeparatedProxies = String.join(", ", currentLocusProxies);
setOrAppend(proxySnpsRsIds, colonSeparatedProxies, delimiter);
} else {
setOrAppend(proxySnpsRsIds, "NR", delimiter);
}
});
});
line.append(reportedGenes.toString());
line.append("\t");
line.append(strongestAllele.toString());
line.append("\t");
line.append(rsId.toString());
line.append("\t");
line.append(proxySnpsRsIds.toString());
line.append("\t");
line.append(riskAlleleFrequency.toString());
line.append("\t");
}
use of uk.ac.ebi.spot.goci.model.Association in project goci by EBISPOT.
the class AssociationEventsViewService method createViews.
@Override
public List<EventView> createViews(Long studyId) {
List<EventView> views = new ArrayList<>();
Collection<Association> associations = studyRepository.findOne(studyId).getAssociations();
if (!associations.isEmpty()) {
// For each association gather up the events into a collection of views
associations.forEach(association -> {
Collection<Event> events = association.getEvents();
Long associationId = association.getId();
Collection<SingleNucleotidePolymorphism> snps = singleNucleotidePolymorphismRepository.findByRiskAllelesLociAssociationId(associationId);
String associationSummary;
StringJoiner snpJoiner = new StringJoiner(", ");
snps.forEach(singleNucleotidePolymorphism -> {
snpJoiner.add(singleNucleotidePolymorphism.getRsId());
});
associationSummary = snpJoiner.toString();
events.forEach(event -> {
String eventName = eventTypeService.translateEventByEventType(event.getEventType());
EventView eventView = new AssociationEventView(eventName, event.getEventDate(), associationId, event.getUser().getEmail(), associationSummary);
views.add(eventView);
});
});
}
return views;
}
use of uk.ac.ebi.spot.goci.model.Association in project goci by EBISPOT.
the class StudyOperationsService method assignStudyStatus.
/**
* Assign status to a study
*/
public String assignStudyStatus(Study study, StatusAssignment statusAssignment, SecureUser userFromRequest) {
CurationStatus newStatus = curationStatusRepository.findOne(statusAssignment.getStatusId());
CurationStatus currentStudyStatus = study.getHousekeeping().getCurationStatus();
String message = null;
// If the current and new status are different
if (newStatus != null && newStatus != currentStudyStatus) {
// Get housekeeping object and assign new status
Housekeeping housekeeping = study.getHousekeeping();
if (newStatus.getStatus().equals("Publish study")) {
// Run pre-publish checks first
Collection<Association> associations = associationRepository.findByStudyId(study.getId());
message = publishStudyCheckService.runChecks(study, associations);
// if checks pass then update the status and save objects
if (message == null) {
housekeeping.setCurationStatus(newStatus);
updateStatus(study, housekeeping, userFromRequest);
}
} else {
housekeeping.setCurationStatus(newStatus);
updateStatus(study, housekeeping, userFromRequest);
}
} else {
message = "Current status and new status are the same, no change required";
}
return message;
}
Aggregations