use of uk.ac.ebi.spot.goci.model.Study in project goci by EBISPOT.
the class DefaultGWASOWLPublisher method publishGWASData.
public OWLOntology publishGWASData() throws OWLConversionException {
// create new ontology
OWLOntology conversion = getConverter().createConversionOntology();
// grab all studies from the DAO
getLog().debug("Fetching studies that require conversion to OWL using StudyRepository...");
Collection<Study> studies = getStudyService().deepFindPublishedStudies();
// TODO : check with Tony probably better to do it at the Repository/Service level
// Discard studies which are not associated with a disease trait and those which haven't been published yet
// by the GWAS catalog.
Iterator<Study> iterator = studies.iterator();
while (iterator.hasNext()) {
Study study = iterator.next();
// Remove study which have no diseaseTrait.
if (study.getDiseaseTrait() == null) {
iterator.remove();
getLog().error("Study '" + study.getId() + "' has no disease trait");
} else if (study.getHousekeeping().getCatalogPublishDate() == null) {
iterator.remove();
getLog().error("Study '" + study.getId() + "' has not yet been published");
} else // Remove studies that have been unpublished
if (study.getHousekeeping().getCatalogUnpublishDate() != null) {
iterator.remove();
getLog().error("Study '" + study.getId() + "' has been unpublished");
}
// }else {
//
// //Remove study which have no associations where pvalue is not null.
// Collection<Association> associations = study.getAssociations();
// Iterator<Association> associationIterator = associations.iterator();
// int associationCount = 0;
// while (associationIterator.hasNext()) {
// Association association = associationIterator.next();
//
// if (association.getPvalueExponent() != null && association.getPvalueMantissa() != null) {
// associationCount++;
// }
// }
// if (associationCount == 0) {
// iterator.remove();
// }
// }
}
getLog().debug("Query complete, got " + studies.size() + " studies");
// if studies limit is not set, convert all data, else filter to first n studies and associated data
if (getStudiesLimit() == -1 && FilterProperties.getDateFilter() == null && FilterProperties.getPvalueFilter() == null) {
System.out.println("Converting all available data");
// grab all other data from the DAO
getLog().debug("Fetching traits that require conversion to OWL using AssociationRepository...");
Collection<Association> traitAssociations = getAssociationService().findReallyAll();
// TODO check with Tony how to do that in a better way from service or repository (how to not get associations linked to study with no trait.
// Discard all the associations which are linked to study which are not linked to a disease trait or haven't
// been published yet in the GWAS catalog.
Iterator<Association> associationIterator = traitAssociations.iterator();
while (associationIterator.hasNext()) {
Association association = associationIterator.next();
if (association.getStudy().getDiseaseTrait() == null) {
associationIterator.remove();
} else if (association.getStudy().getHousekeeping().getCatalogPublishDate() == null) {
associationIterator.remove();
} else if (association.getStudy().getHousekeeping().getCatalogUnpublishDate() != null) {
associationIterator.remove();
}
}
getLog().debug("Fetching SNPs that require conversion to OWL using SingleNucleotidePolymorphismRepository...");
Collection<SingleNucleotidePolymorphism> snps = getSingleNucleotidePolymorphismService().findAll();
getLog().debug("All data fetched");
// convert this data, starting with SNPs (no dependencies) and working up to studies
getLog().debug("Starting conversion to OWL...");
getLog().debug("Converting SNPs...");
getConverter().addSNPsToOntology(snps, conversion);
getLog().debug("Converting Trait Associations...");
getConverter().addAssociationsToOntology(traitAssociations, conversion);
getLog().debug("Converting Studies...");
getConverter().addStudiesToOntology(studies, conversion);
getLog().debug("All conversion done!");
return conversion;
} else {
System.out.println("Data conforming to the filter only");
return filterAndPublishGWASData(conversion, studies);
}
}
use of uk.ac.ebi.spot.goci.model.Study in project goci by EBISPOT.
the class SolrIndexer method mapAllStudies.
private int mapAllStudies(ExecutorService taskExecutor, Collection<String> pubmedIds) throws InterruptedException {
// Sort sort = new Sort(new Sort.Order(Sort.Direction.DESC, "publicationId.publicationDate"));
if (runStudies) {
Pageable pager = new PageRequest(0, pageSize);
if (!pubmedIds.isEmpty()) {
int totalElements = 0;
for (String pmid : pubmedIds) {
Page<Study> studyPage = studyService.findPublishedStudiesByPublicationId(pmid, pager);
CountDownLatch latch = new CountDownLatch(studyPage.getTotalPages());
taskExecutor.execute(new StudyThread(studyPage.getContent(), latch, pager.getPageNumber()));
if (sysOutLogging) {
System.out.println("mapping " + studyPage.getTotalPages() + " study pages");
}
while (studyPage.hasNext()) {
// pass parsing of page off to thread
if (maxPages != -1 && studyPage.getNumber() >= maxPages - 1) {
break;
}
pager = pager.next();
studyPage = studyService.findPublishedStudiesByPublicationId(pmid, pager);
taskExecutor.execute(new StudyThread(studyPage.getContent(), latch, pager.getPageNumber()));
}
latch.await();
totalElements += studyPage.getTotalElements();
}
return totalElements;
} else {
Page<Study> studyPage = studyService.findPublishedStudies(pager);
CountDownLatch latch = new CountDownLatch(studyPage.getTotalPages());
taskExecutor.execute(new StudyThread(studyPage.getContent(), latch, pager.getPageNumber()));
if (sysOutLogging) {
System.out.println("mapping " + studyPage.getTotalPages() + " study pages");
}
while (studyPage.hasNext()) {
// pass parsing of page off to thread
if (maxPages != -1 && studyPage.getNumber() >= maxPages - 1) {
break;
}
pager = pager.next();
studyPage = studyService.findPublishedStudies(pager);
taskExecutor.execute(new StudyThread(studyPage.getContent(), latch, pager.getPageNumber()));
}
latch.await();
return (int) studyPage.getTotalElements();
}
} else {
return 0;
}
}
use of uk.ac.ebi.spot.goci.model.Study in project goci by EBISPOT.
the class OldDiseaseTraitController method viewDiseaseTraitToDelete.
// Delete a disease trait
@RequestMapping(value = "/{diseaseTraitId}/delete", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET)
public String viewDiseaseTraitToDelete(Model model, @PathVariable Long diseaseTraitId) {
DiseaseTrait diseaseTraitToView = diseaseTraitRepository.findOne(diseaseTraitId);
Collection<Study> studiesLinkedToTrait = studyRepository.findByDiseaseTraitId(diseaseTraitId);
model.addAttribute("studies", studiesLinkedToTrait);
model.addAttribute("totalStudies", studiesLinkedToTrait.size());
model.addAttribute("diseaseTrait", diseaseTraitToView);
return "delete_disease_trait";
}
use of uk.ac.ebi.spot.goci.model.Study in project goci by EBISPOT.
the class MappingErrorComparisonService method compareOldVersusNewErrors.
/**
* Method used to compare errors from a previous mapping run. Looking for SNPs with new errors, or SNPs with a
* different type of error.
*
* @param oldErrors collection of all association reports in database before mapping to latest Ensembl release
*/
public void compareOldVersusNewErrors(Collection<AssociationReport> oldErrors, boolean isLSF, Integer min, Integer max) {
// Find all the latest association reports containing mapping errors
getLog().debug("Method used to compare errors from a previous mapping run");
Collection<AssociationReport> newAssociationReports = getnewAssociationReports(isLSF, min, max);
Map<Long, AssociationReport> associationIdToNewAssociationReportMap = createNewReportsMap(newAssociationReports);
Collection<MappingErrorComparisonReport> comparisonReports = new ArrayList<>();
// Create report
for (AssociationReport oldErrorReport : oldErrors) {
MappingErrorComparisonReport mappingErrorComparisonReport = new MappingErrorComparisonReport();
// Establish association and study details
Long associationId = oldErrorReport.getAssociation().getId();
Study study = studyRepository.findByAssociationsId(associationId);
String pubmedId = study.getPublicationId().getPubmedId();
Long studyId = study.getId();
mappingErrorComparisonReport.setStudyId(studyId);
mappingErrorComparisonReport.setAssociationId(associationId);
mappingErrorComparisonReport.setPubmedId(pubmedId);
// Compare errors
AssociationReport newErrorReport = associationIdToNewAssociationReportMap.get(associationId);
String oldSnpError = oldErrorReport.getSnpError();
String newSnpError = newErrorReport.getSnpError();
Boolean differenceInSnpErrors = compareDifferences(oldSnpError, newSnpError);
if (differenceInSnpErrors) {
mappingErrorComparisonReport.setOldSnpError(oldSnpError);
mappingErrorComparisonReport.setNewSnpError(newSnpError);
}
String oldSnpGeneOnDiffChr = oldErrorReport.getSnpGeneOnDiffChr();
String newSnpGeneOnDiffChr = newErrorReport.getSnpGeneOnDiffChr();
Boolean differenceInSnpGeneOnDiffChr = compareDifferences(oldSnpGeneOnDiffChr, newSnpGeneOnDiffChr);
if (differenceInSnpGeneOnDiffChr) {
mappingErrorComparisonReport.setOldSnpGeneOnDiffChr(oldSnpGeneOnDiffChr);
mappingErrorComparisonReport.setNewSnpGeneOnDiffChr(newSnpGeneOnDiffChr);
}
String oldNoGeneForSymbol = oldErrorReport.getNoGeneForSymbol();
String newNoGeneForSymbol = newErrorReport.getNoGeneForSymbol();
Boolean differenceNoGeneForSymbol = compareDifferences(oldNoGeneForSymbol, newNoGeneForSymbol);
if (differenceNoGeneForSymbol) {
mappingErrorComparisonReport.setOldNoGeneForSymbol(oldNoGeneForSymbol);
mappingErrorComparisonReport.setNewNoGeneForSymbol(newNoGeneForSymbol);
}
String oldGeneError = oldErrorReport.getGeneError();
String newGeneError = newErrorReport.getGeneError();
Boolean differenceGeneError = compareDifferences(oldGeneError, newGeneError);
if (differenceGeneError) {
mappingErrorComparisonReport.setOldGeneError(oldGeneError);
mappingErrorComparisonReport.setNewGeneError(newGeneError);
}
String oldRestServiceError = oldErrorReport.getRestServiceError();
String newRestServiceError = newErrorReport.getRestServiceError();
Boolean differenceRestServiceError = compareDifferences(oldRestServiceError, newRestServiceError);
if (differenceRestServiceError) {
mappingErrorComparisonReport.setOldRestServiceError(oldRestServiceError);
mappingErrorComparisonReport.setNewRestServiceError(newRestServiceError);
}
String oldSuspectVariationError = oldErrorReport.getSuspectVariationError();
String newSuspectVariationError = newErrorReport.getSuspectVariationError();
Boolean differenceSuspectVariationError = compareDifferences(oldSuspectVariationError, newSuspectVariationError);
if (differenceSuspectVariationError) {
mappingErrorComparisonReport.setOldSuspectVariationError(oldSuspectVariationError);
mappingErrorComparisonReport.setNewSuspectVariationError(newSuspectVariationError);
}
// Only add reports if a significant difference has been found
if (differenceInSnpErrors || differenceInSnpGeneOnDiffChr || differenceNoGeneForSymbol || differenceGeneError || differenceRestServiceError || differenceSuspectVariationError) {
comparisonReports.add(mappingErrorComparisonReport);
}
}
getLog().debug("create file");
createFile(comparisonReports);
}
use of uk.ac.ebi.spot.goci.model.Study in project goci by EBISPOT.
the class DefaultPubMedSearchService method findPublicationSummary.
public Study findPublicationSummary(String pubmedId) throws PubmedLookupException {
String summaryString;
if (pubmedRoot != null && pubmedGwasSummary != null) {
summaryString = pubmedRoot.concat(pubmedGwasSummary);
} else {
throw new PubmedLookupException("Unable to search pubmed - no URL configured. " + "Set pubmed.root, pubmed.gwas.summary and pubmed.xml.version in your config!");
}
Document response = null;
// Run query and create study object
try {
response = dispatchSearch(summaryString.replace("{idlist}", pubmedId) + xmlVersion);
NodeList docSumNodes = response.getElementsByTagName("DocumentSummary");
// The document summary is present then we should have a publication
if (docSumNodes.getLength() > 0) {
Study newStudy = new Study();
// Assuming here we only have one document summary as pubmed id should correspond to one publication
Node docSumNode = docSumNodes.item(0);
// Initialize study attributes
String pmid = null;
String title = "";
Date pubDate = null;
String author = "";
String publication = "";
// Get the ID element (should only be one, take first regardless)
Element study = (Element) docSumNode;
pmid = study.getAttribute("uid");
if (study.getElementsByTagName("error").item(0) != null) {
author = null;
title = null;
publication = null;
pubDate = null;
} else {
title = study.getElementsByTagName("Title").item(0).getTextContent();
publication = study.getElementsByTagName("Source").item(0).getTextContent();
author = study.getElementsByTagName("SortFirstAuthor").item(0).getTextContent();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String date = study.getElementsByTagName("SortPubDate").item(0).getTextContent();
if (date.contains("/")) {
date = date.replace("/", "-");
}
java.util.Date studyDate = null;
try {
studyDate = format.parse(date);
} catch (ParseException e1) {
e1.printStackTrace();
}
pubDate = new Date(studyDate.getTime());
}
if (pmid != null) {
if (author != null && pubDate != null && publication != null && title != null) {
// THOR
// newStudy.setAuthor(author);
// newStudy.setPubmedId(pmid);
// newStudy.setPublication(publication);
// newStudy.setTitle(title);
// newStudy.setPublicationDate(pubDate);
}
}
return newStudy;
} else {
throw new PubmedLookupException("Couldn't find pubmed id " + pubmedId + " in PubMed");
}
} catch (IOException e) {
throw new PubmedLookupException("Couldn't find pubmed id " + pubmedId + " in PubMed", e);
}
}
Aggregations