Search in sources :

Example 21 with Study

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.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);
}
Also used : MappingErrorComparisonReport(uk.ac.ebi.spot.goci.model.MappingErrorComparisonReport) Study(uk.ac.ebi.spot.goci.model.Study) AssociationReport(uk.ac.ebi.spot.goci.model.AssociationReport) ArrayList(java.util.ArrayList)

Example 22 with Study

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

the class StudyController method duplicateStudy.

// Duplicate a study
@RequestMapping(value = "/{studyId}/duplicate", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET)
public String duplicateStudy(@PathVariable Long studyId, RedirectAttributes redirectAttributes, HttpServletRequest request) {
    // Find study user wants to duplicate, based on the ID
    Study studyToDuplicate = studyRepository.findOne(studyId);
    Study duplicateStudy = studyDuplicationService.duplicateStudy(studyToDuplicate, currentUserDetailsService.getUserFromRequest(request));
    // Add duplicate message
    String message = "Study is a duplicate of " + studyToDuplicate.getAuthor() + ", PMID: " + studyToDuplicate.getPubmedId();
    redirectAttributes.addFlashAttribute("duplicateMessage", message);
    return "redirect:/studies/" + duplicateStudy.getId();
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with Study

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);
    }
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) Association(uk.ac.ebi.spot.goci.model.Association) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) SingleNucleotidePolymorphism(uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism)

Example 24 with Study

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) {
                    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);
    }
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) PubmedLookupException(uk.ac.ebi.spot.goci.service.exception.PubmedLookupException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) IOException(java.io.IOException) Document(org.w3c.dom.Document) Date(java.sql.Date) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 25 with Study

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

the class StudyDuplicationServiceTest method duplicateStudy.

@Test
public void duplicateStudy() throws Exception {
    // Stubbing
    when(housekeepingOperationsService.createHousekeeping()).thenReturn(NEW_HOUSEKEEPING);
    when(ancestryRepository.findByStudyId(STUDY_TO_DUPLICATE.getId())).thenReturn(Arrays.asList(ETH1, ETH2));
    Study duplicateStudy = studyDuplicationService.duplicateStudy(STUDY_TO_DUPLICATE, SECURE_USER);
    // Verification
    verify(studyTrackingOperationService, times(1)).update(STUDY_TO_DUPLICATE, SECURE_USER, "STUDY_DUPLICATION");
    verify(studyRepository, times(1)).save(STUDY_TO_DUPLICATE);
    verify(studyTrackingOperationService, times(1)).create(duplicateStudy, SECURE_USER);
    verify(housekeepingOperationsService, times(1)).createHousekeeping();
    verify(ancestryRepository, times(1)).findByStudyId(STUDY_TO_DUPLICATE.getId());
    verify(ancestryRepository, times(2)).save(Matchers.any(Ancestry.class));
    verify(housekeepingOperationsService, times(1)).saveHousekeeping(duplicateStudy, duplicateStudy.getHousekeeping());
    // Assertions;
    assertThat(duplicateStudy).isEqualToIgnoringGivenFields(STUDY_TO_DUPLICATE, "housekeeping", "ancestries", "id", "author", "notes");
    assertEquals(duplicateStudy.getNotes().size(), 1);
    assertThat(duplicateStudy.getAuthor()).isEqualTo(STUDY_TO_DUPLICATE.getAuthor().concat(" DUP"));
    assertThat(duplicateStudy.getId()).isNotEqualTo(STUDY_TO_DUPLICATE.getId());
    assertThat(duplicateStudy.getHousekeeping().getStudyAddedDate()).isToday();
    /// Check ancestry
    assertThat(duplicateStudy.getAncestries()).extracting("id", "numberOfIndividuals", //                                                              "ancestralGroup",
    "description", //                                                               "countryOfRecruitment",
    "type").contains(tuple(null, 100, //                                "European",
    "ETH1 description", //                                "Ireland", "Ireland",
    "initial"), tuple(null, 200, //                                "European",
    "ETH2 description", //                                "U.K.", "U.K.",
    "replication"));
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) Ancestry(uk.ac.ebi.spot.goci.model.Ancestry) Test(org.junit.Test)

Aggregations

Study (uk.ac.ebi.spot.goci.model.Study)44 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)20 ArrayList (java.util.ArrayList)7 Association (uk.ac.ebi.spot.goci.model.Association)7 Housekeeping (uk.ac.ebi.spot.goci.model.Housekeeping)6 MultiStudyNoteForm (uk.ac.ebi.spot.goci.curation.model.MultiStudyNoteForm)5 Date (java.util.Date)4 Test (org.junit.Test)4 Ancestry (uk.ac.ebi.spot.goci.model.Ancestry)4 NoteSubject (uk.ac.ebi.spot.goci.model.NoteSubject)4 SecureUser (uk.ac.ebi.spot.goci.model.SecureUser)4 SingleNucleotidePolymorphism (uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism)4 ParseException (java.text.ParseException)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Service (org.springframework.stereotype.Service)3 StudyNoteForm (uk.ac.ebi.spot.goci.curation.model.StudyNoteForm)3 RiskAllele (uk.ac.ebi.spot.goci.model.RiskAllele)3 StudyNote (uk.ac.ebi.spot.goci.model.StudyNote)3 IOException (java.io.IOException)2