Search in sources :

Example 11 with DiseaseTrait

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

the class SolrIndexer method mapTraits.

Integer mapTraits() {
    Sort sort = new Sort(new Sort.Order("trait"));
    Pageable pager = new PageRequest(0, pageSize, sort);
    Page<DiseaseTrait> diseaseTraitPage = diseaseTraitRepository.findAll(pager);
    traitMapper.map(diseaseTraitPage.getContent());
    while (diseaseTraitPage.hasNext()) {
        if (maxPages != -1 && diseaseTraitPage.getNumber() >= maxPages - 1) {
            break;
        }
        pager = pager.next();
        diseaseTraitPage = diseaseTraitRepository.findAll(pager);
        traitMapper.map(diseaseTraitPage.getContent());
        if (sysOutLogging) {
            System.out.print(".");
        }
    }
    return (int) diseaseTraitPage.getTotalElements();
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) DiseaseTrait(uk.ac.ebi.spot.goci.model.DiseaseTrait) Sort(org.springframework.data.domain.Sort)

Example 12 with DiseaseTrait

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

the class StudyDataService method updateStudyDiseaseTraitByAccessionId.

public Study updateStudyDiseaseTraitByAccessionId(String trait, String accessionId) {
    Study study = this.getStudyByAccessionId(accessionId).orElseThrow(() -> new ResourceNotFoundException("Study", accessionId));
    DiseaseTrait diseaseTrait = Optional.ofNullable(diseaseTraitRepository.findByTraitIgnoreCase(trait)).orElseThrow(() -> new ResourceNotFoundException("Disease Trait", trait));
    study.setDiseaseTrait(diseaseTrait);
    studyRepository.save(study);
    log.info("Study with accession Id: {} found and updated", accessionId);
    return study;
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) DiseaseTrait(uk.ac.ebi.spot.goci.model.DiseaseTrait) ResourceNotFoundException(uk.ac.ebi.spot.goci.curation.exception.ResourceNotFoundException)

Example 13 with DiseaseTrait

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

the class ViewController method masterdetailPage.

@GetMapping("/disease-traits")
public String masterdetailPage(Model model) {
    List<Map<String, Object>> dataList = new ArrayList<>();
    List<DiseaseTraitProjection> projections = diseaseTraitRepository.findAllOrOrderByStudiesLargest(new PageRequest(0, 30));
    projections.forEach(x -> {
        Map<String, Object> result = new HashMap<>();
        result.put("trait", x.getTrait());
        result.put("studies", x.getStudiesCount());
        dataList.add(result);
    });
    List<Long> ids = new ArrayList<>();
    AtomicInteger count = new AtomicInteger(1);
    projections.forEach(projection -> {
        if (count.get() <= 4) {
            ids.add(projection.getId());
            count.getAndIncrement();
        }
    });
    List<DiseaseTrait> diseaseTraits = diseaseTraitRepository.findAllByIdIsIn(ids);
    List<Object> parents = new ArrayList<>();
    diseaseTraits.forEach(diseaseTrait -> {
        String trait = diseaseTrait.getTrait();
        List<Map<String, Object>> children = new ArrayList<>();
        diseaseTrait.getStudies().forEach(study -> {
            Map<String, Object> child = new HashMap<>();
            child.put("name", study.getPublicationId().getPubmedId());
            child.put(VALUE, 40);
            children.add(child);
        });
        Map<String, Object> parent = new LinkedHashMap<>();
        parent.put("name", trait + " (" + children.size() + ")");
        parent.put(VALUE, 102);
        parent.put("children", children);
        parents.add(parent);
    });
    List<Object> parents2 = new ArrayList<>();
    Map<String, Object> parenta = new LinkedHashMap<>();
    parenta.put("name", "core");
    parenta.put(VALUE, "10");
    parenta.put("children", parents);
    parents2.add(parenta);
    model.addAttribute("dataList", dataList);
    model.addAttribute("mapData", parents2);
    return "disease-traits";
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DiseaseTrait(uk.ac.ebi.spot.goci.model.DiseaseTrait) DiseaseTraitProjection(uk.ac.ebi.spot.goci.model.projection.DiseaseTraitProjection) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 14 with DiseaseTrait

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

the class DiseaseTraitDtoAssembler method disassemble.

public static DiseaseTrait disassemble(DiseaseTraitDto diseaseTraitDTO) {
    DiseaseTrait diseaseTrait = new DiseaseTrait();
    diseaseTrait.setTrait(diseaseTraitDTO.getTrait());
    return diseaseTrait;
}
Also used : DiseaseTrait(uk.ac.ebi.spot.goci.model.DiseaseTrait)

Example 15 with DiseaseTrait

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

the class DiseaseTraitDtoAssembler method disassemble.

public static List<DiseaseTrait> disassemble(MultipartFile multipartFile) {
    CsvMapper mapper = new CsvMapper();
    CsvSchema schema = FileHandler.getSchemaFromMultiPartFile(multipartFile);
    List<DiseaseTraitDto> diseaseTraitDtos;
    try {
        InputStream inputStream = multipartFile.getInputStream();
        MappingIterator<DiseaseTraitDto> iterator = mapper.readerFor(DiseaseTraitDto.class).with(schema).readValues(inputStream);
        diseaseTraitDtos = iterator.readAll();
    } catch (IOException ex) {
        throw new FileUploadException("Could not read the file");
    }
    List<DiseaseTrait> diseaseTraits = new ArrayList<>();
    diseaseTraitDtos.forEach(diseaseTraitDTO -> {
        DiseaseTrait diseaseTrait = new DiseaseTrait();
        diseaseTrait.setTrait(diseaseTraitDTO.getTrait());
        diseaseTraits.add(diseaseTrait);
    });
    return diseaseTraits;
}
Also used : CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) DiseaseTrait(uk.ac.ebi.spot.goci.model.DiseaseTrait) InputStream(java.io.InputStream) CsvMapper(com.fasterxml.jackson.dataformat.csv.CsvMapper) ArrayList(java.util.ArrayList) DiseaseTraitDto(uk.ac.ebi.spot.goci.curation.dto.DiseaseTraitDto) IOException(java.io.IOException) FileUploadException(uk.ac.ebi.spot.goci.curation.exception.FileUploadException)

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