Search in sources :

Example 1 with AnalysisDTO

use of uk.ac.ebi.spot.goci.curation.dto.AnalysisDTO 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;
}
Also used : ArrayList(java.util.ArrayList) AnalysisDTO(uk.ac.ebi.spot.goci.curation.dto.AnalysisDTO) AnalysisCacheDto(uk.ac.ebi.spot.goci.curation.dto.AnalysisCacheDto)

Example 2 with AnalysisDTO

use of uk.ac.ebi.spot.goci.curation.dto.AnalysisDTO 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;
}
Also used : FileValidationException(uk.ac.ebi.spot.goci.curation.exception.FileValidationException) AnalysisDTO(uk.ac.ebi.spot.goci.curation.dto.AnalysisDTO) AnalysisCacheDto(uk.ac.ebi.spot.goci.curation.dto.AnalysisCacheDto)

Example 3 with AnalysisDTO

use of uk.ac.ebi.spot.goci.curation.dto.AnalysisDTO 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();
}
Also used : DataIntegrityException(uk.ac.ebi.spot.goci.curation.exception.DataIntegrityException) java.util(java.util) Logger(org.slf4j.Logger) Cacheable(org.springframework.cache.annotation.Cacheable) LoggerFactory(org.slf4j.LoggerFactory) LevenshteinDistance(org.apache.commons.text.similarity.LevenshteinDistance) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) DiseaseTrait(uk.ac.ebi.spot.goci.model.DiseaseTrait) Service(org.springframework.stereotype.Service) CosineDistance(org.apache.commons.text.similarity.CosineDistance) Study(uk.ac.ebi.spot.goci.model.Study) StudyRepository(uk.ac.ebi.spot.goci.repository.StudyRepository) Pageable(org.springframework.data.domain.Pageable) EntityType(uk.ac.ebi.spot.goci.curation.constants.EntityType) AnalysisDTO(uk.ac.ebi.spot.goci.curation.dto.AnalysisDTO) DiseaseTraitRepository(uk.ac.ebi.spot.goci.repository.DiseaseTraitRepository) AnalysisCacheDto(uk.ac.ebi.spot.goci.curation.dto.AnalysisCacheDto) DiseaseTraitDto(uk.ac.ebi.spot.goci.curation.dto.DiseaseTraitDto) DiseaseTrait(uk.ac.ebi.spot.goci.model.DiseaseTrait) LevenshteinDistance(org.apache.commons.text.similarity.LevenshteinDistance) AnalysisDTO(uk.ac.ebi.spot.goci.curation.dto.AnalysisDTO) CosineDistance(org.apache.commons.text.similarity.CosineDistance) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 4 with AnalysisDTO

use of uk.ac.ebi.spot.goci.curation.dto.AnalysisDTO in project goci by EBISPOT.

the class FileHandler method serializeDiseaseTraitAnalysisFile.

public static List<AnalysisDTO> serializeDiseaseTraitAnalysisFile(FileUploadRequest fileUploadRequest) {
    CsvMapper mapper = new CsvMapper();
    CsvSchema schema = getSchemaFromMultiPartFile(fileUploadRequest.getMultipartFile());
    List<AnalysisDTO> analysisDTOS;
    try {
        InputStream inputStream = fileUploadRequest.getMultipartFile().getInputStream();
        MappingIterator<AnalysisDTO> iterator = mapper.readerFor(AnalysisDTO.class).with(schema).readValues(inputStream);
        analysisDTOS = iterator.readAll();
    } catch (IOException e) {
        throw new FileUploadException("Could not read the file");
    }
    return analysisDTOS;
}
Also used : CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) InputStream(java.io.InputStream) CsvMapper(com.fasterxml.jackson.dataformat.csv.CsvMapper) AnalysisDTO(uk.ac.ebi.spot.goci.curation.dto.AnalysisDTO) IOException(java.io.IOException) FileUploadException(uk.ac.ebi.spot.goci.curation.exception.FileUploadException)

Aggregations

AnalysisDTO (uk.ac.ebi.spot.goci.curation.dto.AnalysisDTO)4 AnalysisCacheDto (uk.ac.ebi.spot.goci.curation.dto.AnalysisCacheDto)3 CsvMapper (com.fasterxml.jackson.dataformat.csv.CsvMapper)1 CsvSchema (com.fasterxml.jackson.dataformat.csv.CsvSchema)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 Collectors (java.util.stream.Collectors)1 CosineDistance (org.apache.commons.text.similarity.CosineDistance)1 LevenshteinDistance (org.apache.commons.text.similarity.LevenshteinDistance)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Cacheable (org.springframework.cache.annotation.Cacheable)1 Page (org.springframework.data.domain.Page)1 Pageable (org.springframework.data.domain.Pageable)1 Service (org.springframework.stereotype.Service)1 EntityType (uk.ac.ebi.spot.goci.curation.constants.EntityType)1 DiseaseTraitDto (uk.ac.ebi.spot.goci.curation.dto.DiseaseTraitDto)1 DataIntegrityException (uk.ac.ebi.spot.goci.curation.exception.DataIntegrityException)1