Search in sources :

Example 6 with DiseaseTrait

use of uk.ac.ebi.spot.goci.model.DiseaseTrait in project goci by EBISPOT.

the class SolrIndexer method mapAllTraits.

private int mapAllTraits(ExecutorService taskExecutor, Collection<String> pubmedIds) throws InterruptedException {
    // Sort sort = new Sort(new Sort.Order("trait"));
    if (runTraits) {
        Pageable pager = new PageRequest(0, pageSize);
        if (!pubmedIds.isEmpty()) {
            int totalElements = 0;
            for (String pmid : pubmedIds) {
                Page<DiseaseTrait> diseaseTraitPage = diseaseTraitRepository.findByStudiesPublicationIdPubmedId(pmid, pager);
                CountDownLatch latch = new CountDownLatch(diseaseTraitPage.getTotalPages());
                taskExecutor.execute(new TraitThread(diseaseTraitPage.getContent(), latch, pager.getPageNumber()));
                if (sysOutLogging) {
                    System.out.println("mapping " + diseaseTraitPage.getTotalPages() + " disease trait pages");
                }
                while (diseaseTraitPage.hasNext()) {
                    if (maxPages != -1 && diseaseTraitPage.getNumber() >= maxPages - 1) {
                        break;
                    }
                    pager = pager.next();
                    diseaseTraitPage = diseaseTraitRepository.findByStudiesPublicationIdPubmedId(pmid, pager);
                    taskExecutor.execute(new TraitThread(diseaseTraitPage.getContent(), latch, pager.getPageNumber()));
                }
                totalElements += diseaseTraitPage.getTotalElements();
                latch.await();
            }
            return totalElements;
        } else {
            Page<DiseaseTrait> diseaseTraitPage = diseaseTraitRepository.findAll(pager);
            CountDownLatch latch = new CountDownLatch(diseaseTraitPage.getTotalPages());
            taskExecutor.execute(new TraitThread(diseaseTraitPage.getContent(), latch, pager.getPageNumber()));
            if (sysOutLogging) {
                System.out.println("mapping " + diseaseTraitPage.getTotalPages() + " disease trait pages");
            }
            while (diseaseTraitPage.hasNext()) {
                if (maxPages != -1 && diseaseTraitPage.getNumber() >= maxPages - 1) {
                    break;
                }
                pager = pager.next();
                diseaseTraitPage = diseaseTraitRepository.findAll(pager);
                taskExecutor.execute(new TraitThread(diseaseTraitPage.getContent(), latch, pager.getPageNumber()));
            }
            latch.await();
            return (int) diseaseTraitPage.getTotalElements();
        }
    } else {
        return 0;
    }
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) DiseaseTrait(uk.ac.ebi.spot.goci.model.DiseaseTrait)

Example 7 with DiseaseTrait

use of uk.ac.ebi.spot.goci.model.DiseaseTrait 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 8 with DiseaseTrait

use of uk.ac.ebi.spot.goci.model.DiseaseTrait in project goci by EBISPOT.

the class DiseaseTraitController method allDiseaseTraits.

//Return all disease traits
@RequestMapping(produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET)
public String allDiseaseTraits(Model model) {
    Sort sort = sortByTraitAsc();
    List<DiseaseTrait> allDiseaseTraits = diseaseTraitRepository.findAll(sort);
    model.addAttribute("diseaseTraits", allDiseaseTraits);
    model.addAttribute("totaldiseaseTraits", allDiseaseTraits.size());
    // Return an empty DiseaseTrait object so user can add a new one
    model.addAttribute("diseaseTrait", new DiseaseTrait());
    return "disease_traits";
}
Also used : DiseaseTrait(uk.ac.ebi.spot.goci.model.DiseaseTrait) Sort(org.springframework.data.domain.Sort) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with DiseaseTrait

use of uk.ac.ebi.spot.goci.model.DiseaseTrait in project goci by EBISPOT.

the class DiseaseTraitController method viewDiseaseTrait.

// Edit disease trait
@RequestMapping(value = "/{diseaseTraitId}", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET)
public String viewDiseaseTrait(Model model, @PathVariable Long diseaseTraitId) {
    DiseaseTrait diseaseTraitToView = diseaseTraitRepository.findOne(diseaseTraitId);
    model.addAttribute("diseaseTrait", diseaseTraitToView);
    return "edit_disease_trait";
}
Also used : DiseaseTrait(uk.ac.ebi.spot.goci.model.DiseaseTrait) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with DiseaseTrait

use of uk.ac.ebi.spot.goci.model.DiseaseTrait in project goci by EBISPOT.

the class DiseaseTraitController method addDiseaseTrait.

// Add a new disease trait
@RequestMapping(produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST)
public String addDiseaseTrait(@Valid @ModelAttribute DiseaseTrait diseaseTrait, BindingResult bindingResult, Model model, RedirectAttributes redirectAttributes) {
    // Check if it exists already
    DiseaseTrait existingDiseaseTrait = diseaseTraitRepository.findByTraitIgnoreCase(diseaseTrait.getTrait());
    String existingTrait = null;
    if (existingDiseaseTrait != null) {
        existingTrait = existingDiseaseTrait.getTrait();
    }
    // Catch a null or empty value being entered
    if (bindingResult.hasErrors()) {
        model.addAttribute("diseaseTraits", diseaseTraitRepository.findAll(sortByTraitAsc()));
        return "disease_traits";
    } else if (existingTrait != null && !existingTrait.isEmpty()) {
        String message = "Trait already exists in database: database value = " + existingTrait + ", value entered = " + diseaseTrait.getTrait();
        redirectAttributes.addFlashAttribute("diseaseTraitExists", message);
        return "redirect:/diseasetraits";
    } else // Save disease trait
    {
        diseaseTraitRepository.save(diseaseTrait);
        String message = "Trait " + diseaseTrait.getTrait() + " added to database";
        redirectAttributes.addFlashAttribute("diseaseTraitSaved", message);
        return "redirect:/diseasetraits";
    }
}
Also used : DiseaseTrait(uk.ac.ebi.spot.goci.model.DiseaseTrait) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DiseaseTrait (uk.ac.ebi.spot.goci.model.DiseaseTrait)22 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 PageRequest (org.springframework.data.domain.PageRequest)4 Pageable (org.springframework.data.domain.Pageable)4 Sort (org.springframework.data.domain.Sort)4 Study (uk.ac.ebi.spot.goci.model.Study)4 ControllerLinkBuilder (org.springframework.hateoas.mvc.ControllerLinkBuilder)2 ResponseEntity (org.springframework.http.ResponseEntity)2 DiseaseTraitDto (uk.ac.ebi.spot.goci.curation.dto.DiseaseTraitDto)2 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 URI (java.net.URI)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors (java.util.stream.Collectors)1 CosineDistance (org.apache.commons.text.similarity.CosineDistance)1 LevenshteinDistance (org.apache.commons.text.similarity.LevenshteinDistance)1