use of uk.ac.ebi.spot.goci.curation.dto.AnalysisCacheDto in project goci by EBISPOT.
the class DiseaseTraitUploadController method similaritySearchAnalysisCsvDownload.
@GetMapping("/analysis/{analysisId}")
@ResponseBody
public Object similaritySearchAnalysisCsvDownload(HttpServletResponse response, @PathVariable String analysisId) throws IOException {
log.info("Retrieving Cached Analysis with ID : {}", analysisId);
List<AnalysisDTO> analysisDTO = new ArrayList<>();
double threshold = 90.0;
AnalysisCacheDto cache = diseaseTraitService.similaritySearch(analysisDTO, analysisId, threshold);
analysisDTO = cache.getAnalysisResult();
analysisDTO.sort(Comparator.comparingDouble(AnalysisDTO::getDegree).reversed());
String result = FileHandler.serializePojoToTsv(analysisDTO);
log.info(result);
response.setContentType("text/csv;charset=utf-8");
response.setHeader("Content-Disposition", "attachment; filename=analysis.csv");
response.getOutputStream().flush();
return result;
}
use of uk.ac.ebi.spot.goci.curation.dto.AnalysisCacheDto in project goci by EBISPOT.
the class DiseaseTraitUploadController method similaritySearchAnalysis.
@PostMapping("/analysis")
public AnalysisCacheDto similaritySearchAnalysis(@Valid FileUploadRequest fileUploadRequest, BindingResult result) {
if (result.hasErrors()) {
throw new FileValidationException(result);
}
List<AnalysisDTO> analysisDTO = FileHandler.serializeDiseaseTraitAnalysisFile(fileUploadRequest);
log.info("{} disease traits were ingested for analysis", analysisDTO.size());
String analysisId = UUID.randomUUID().toString();
AnalysisCacheDto analysisCacheDto = diseaseTraitService.similaritySearch(analysisDTO, analysisId, 50.0);
log.info("Analysis done, retrievable in future with id {}", analysisId);
return analysisCacheDto;
}
use of uk.ac.ebi.spot.goci.curation.dto.AnalysisCacheDto in project goci by EBISPOT.
the class DiseaseTraitService method similaritySearch.
@Cacheable(value = "diseaseTraitAnalysis", key = "#analysisId")
public AnalysisCacheDto similaritySearch(List<AnalysisDTO> diseaseTraitAnalysisDTOS, String analysisId, double threshold) {
LevenshteinDistance lv = new LevenshteinDistance();
CosineDistance cd = new CosineDistance();
List<DiseaseTrait> diseaseTraits = diseaseTraitRepository.findAll();
List<AnalysisDTO> analysisReport = new ArrayList<>();
diseaseTraitAnalysisDTOS.forEach(diseaseTraitAnalysisDTO -> diseaseTraits.forEach(diseaseTrait -> {
String trait = diseaseTrait.getTrait();
String userTerm = diseaseTraitAnalysisDTO.getUserTerm();
double cosineDistance = cd.apply(userTerm, trait);
double levenshteinDistance = ((double) lv.apply(userTerm, trait)) / Math.max(userTerm.length(), trait.length());
double cosineSimilarityPercent = Math.round((1 - cosineDistance) * 100);
double levenshteinSimilarityPercent = Math.round((1 - levenshteinDistance) * 100);
double chosen = Math.max(cosineSimilarityPercent, levenshteinSimilarityPercent);
if (chosen >= threshold) {
AnalysisDTO report = AnalysisDTO.builder().userTerm(userTerm).similarTerm(trait).degree(chosen).build();
analysisReport.add(report);
}
}));
return AnalysisCacheDto.builder().uniqueId(analysisId).analysisResult(analysisReport).build();
}
Aggregations