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;
}
}
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();
}
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";
}
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";
}
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";
}
}
Aggregations