Search in sources :

Example 41 with BibliographicReference

use of ubic.gemma.model.common.description.BibliographicReference in project Gemma by PavlidisLab.

the class BibliographicReferenceControllerImpl method show.

@Override
public ModelAndView show(HttpServletRequest request, HttpServletResponse response) {
    String pubMedId = request.getParameter("accession");
    String gemmaId = request.getParameter("id");
    if (StringUtils.isBlank(pubMedId) && StringUtils.isBlank(gemmaId)) {
        throw new EntityNotFoundException("Must provide a gamma database id or a PubMed id");
    }
    if (!StringUtils.isBlank(gemmaId)) {
        return new ModelAndView("bibRefView").addObject("bibliographicReferenceId", gemmaId);
    }
    BibliographicReference bibRef = bibliographicReferenceService.findByExternalId(pubMedId);
    if (bibRef == null) {
        bibRef = this.pubMedXmlFetcher.retrieveByHTTP(Integer.parseInt(pubMedId));
        if (bibRef == null) {
            throw new EntityNotFoundException("Could not locate reference with pubmed id=" + pubMedId + ", either in Gemma or at NCBI");
        }
    }
    // bibRef = bibliographicReferenceService.thawRawAndProcessed( bibRef );
    // BibliographicReferenceValueObject bibRefVO = new BibliographicReferenceValueObject( bibRef );
    boolean isIncomplete = bibRef.getPublicationDate() == null;
    this.addMessage(request, "object.found", new Object[] { messagePrefix, pubMedId });
    return new ModelAndView("bibRefView").addObject("bibliographicReferenceId", bibRef.getId()).addObject("existsInSystem", Boolean.TRUE).addObject("incompleteEntry", isIncomplete).addObject("byAccession", Boolean.TRUE).addObject("accession", pubMedId);
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) EntityNotFoundException(ubic.gemma.web.util.EntityNotFoundException) BibliographicReference(ubic.gemma.model.common.description.BibliographicReference)

Example 42 with BibliographicReference

use of ubic.gemma.model.common.description.BibliographicReference in project Gemma by PavlidisLab.

the class BibliographicReferenceControllerImpl method delete.

@Override
public ModelAndView delete(HttpServletRequest request, HttpServletResponse response) {
    String pubMedId = request.getParameter("acc");
    if (pubMedId == null) {
        // should be a validation error.
        throw new EntityNotFoundException("Must provide a PubMed Id");
    }
    BibliographicReference bibRef = bibliographicReferenceService.findByExternalId(pubMedId);
    if (bibRef == null) {
        String message = "There is no reference with accession=" + pubMedId + " in the system any more.";
        this.saveMessage(request, message);
        return new ModelAndView("bibRefView").addObject("errors", message);
    }
    return this.doDelete(request, bibRef);
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) EntityNotFoundException(ubic.gemma.web.util.EntityNotFoundException) BibliographicReference(ubic.gemma.model.common.description.BibliographicReference)

Example 43 with BibliographicReference

use of ubic.gemma.model.common.description.BibliographicReference in project Gemma by PavlidisLab.

the class PubMedQueryControllerImpl method onSubmit.

@Override
@RequestMapping(method = RequestMethod.POST)
public ModelAndView onSubmit(HttpServletRequest request, PubMedSearchCommand command, BindingResult result, SessionStatus status) {
    // in the future we can search in other ways.
    String accession = command.getAccession();
    if (StringUtils.isBlank(accession)) {
        result.rejectValue("search", "errors.pubmed.noaccession", "Accession was missing");
        return new ModelAndView("bibRefSearch");
    }
    // first see if we already have it in the system.
    BibliographicReference bibRefFound = bibliographicReferenceService.findByExternalId(accession);
    if (bibRefFound != null) {
        request.setAttribute("existsInSystem", Boolean.TRUE);
        this.saveMessage(request, "bibliographicReference.alreadyInSystem", accession, "Already in Gemma");
    } else {
        request.setAttribute("existsInSystem", Boolean.FALSE);
        try {
            bibRefFound = this.pubMedXmlFetcher.retrieveByHTTP(Integer.parseInt(accession));
            if (bibRefFound == null) {
                log.debug(accession + " not found in NCBI");
                result.rejectValue("accession", "bibliographicReference.notfoundInNCBI", "Not found in NCBI");
                return new ModelAndView("bibRefSearch", result.getModel());
            }
            this.saveMessage(request, "bibliographicReference.found", accession, "Found");
        } catch (NumberFormatException e) {
            result.rejectValue("accession", "error.integer", "Not a number");
            return new ModelAndView("bibRefSearch", result.getModel());
        }
    }
    status.setComplete();
    return new ModelAndView("bibRefView").addObject("bibliographicReference", bibRefFound);
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) BibliographicReference(ubic.gemma.model.common.description.BibliographicReference) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 44 with BibliographicReference

use of ubic.gemma.model.common.description.BibliographicReference in project Gemma by PavlidisLab.

the class SearchServiceImpl method expressionExperimentSearch.

/**
 * A general search for expression experiments. This search does both an database search and a compass search.
 * A problem with this is that we cap the number of results that can be returned. This could be a limitation for
 * applications like building data set groups. Thus MAX_CHARACTERISTIC_SEARCH_RESULTS should not be too low.
 *
 * @return {@link Collection}
 */
private Collection<SearchResult> expressionExperimentSearch(final SearchSettings settings) {
    StopWatch watch = this.startTiming();
    SearchServiceImpl.log.info("Starting search for " + settings.getQuery() + " in taxon: " + settings.getTaxon());
    Collection<SearchResult> results = new HashSet<>();
    if (settings.getUseDatabase()) {
        results.addAll(this.databaseExpressionExperimentSearch(settings));
        if (watch.getTime() > 1000)
            SearchServiceImpl.log.info("Expression Experiment database search for '" + settings + "' took " + watch.getTime() + " ms, " + results.size() + " hits.");
        watch.reset();
        watch.start();
    }
    if (settings.getUseIndices() && results.size() < SearchServiceImpl.MAX_CHARACTERISTIC_SEARCH_RESULTS) {
        results.addAll(this.compassExpressionSearch(settings));
        if (watch.getTime() > 1000)
            SearchServiceImpl.log.info("Expression Experiment index search for '" + settings + "' took " + watch.getTime() + " ms, " + results.size() + " hits.");
        watch.reset();
        watch.start();
    }
    if (results.size() < SearchServiceImpl.MAX_CHARACTERISTIC_SEARCH_RESULTS) {
        /*
             * Try a more thorough search. This is slower; calls to ontologySearchAnnotatedObject take a long time
             */
        if (settings.getUseCharacteristics()) {
            results.addAll(this.characteristicExpressionExperimentSearch(settings));
        }
        if (watch.getTime() > 1000)
            SearchServiceImpl.log.info("Expression Experiment ontology search for '" + settings + "' took " + watch.getTime() + " ms, " + results.size() + " hits.");
        watch.reset();
        watch.start();
    }
    /*
         * Find data sets that match the platform
         */
    if (results.size() == 0) {
        Collection<SearchResult> matchingPlatforms = this.arrayDesignSearch(settings, null);
        for (SearchResult adRes : matchingPlatforms) {
            if (adRes.getResultObject() instanceof ArrayDesign) {
                ArrayDesign ad = (ArrayDesign) adRes.getResultObject();
                Collection<ExpressionExperiment> expressionExperiments = this.arrayDesignService.getExpressionExperiments(ad);
                if (expressionExperiments.size() > 0)
                    results.addAll(this.dbHitsToSearchResult(expressionExperiments, null));
            }
        }
        if (watch.getTime() > 1000)
            SearchServiceImpl.log.info("Expression Experiment platform search for '" + settings + "' took " + watch.getTime() + " ms, " + results.size() + " hits.");
        watch.reset();
        watch.start();
    }
    if (results.size() == 0) {
        /*
             * Search for bib refs
             */
        List<BibliographicReferenceValueObject> bibrefs = bibliographicReferenceService.search(settings.getQuery());
        if (!bibrefs.isEmpty()) {
            Collection<BibliographicReference> refs = new HashSet<>();
            Collection<SearchResult> r = this.compassBibliographicReferenceSearch(settings);
            for (SearchResult searchResult : r) {
                refs.add((BibliographicReference) searchResult.getResultObject());
            }
            Map<BibliographicReference, Collection<ExpressionExperiment>> relatedExperiments = this.bibliographicReferenceService.getRelatedExperiments(refs);
            for (Entry<BibliographicReference, Collection<ExpressionExperiment>> e : relatedExperiments.entrySet()) {
                results.addAll(this.dbHitsToSearchResult(e.getValue(), null));
            }
            if (watch.getTime() > 1000)
                SearchServiceImpl.log.info("Expression Experiment publication search for '" + settings + "' took " + watch.getTime() + " ms, " + results.size() + " hits.");
            watch.reset();
            watch.start();
        }
    }
    watch.stop();
    if (watch.getTime() > 1000)
        SearchServiceImpl.log.info("Expression Experiment search for '" + settings + "' took " + watch.getTime() + " ms, " + results.size() + " hits.");
    return results;
}
Also used : ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) BibliographicReferenceValueObject(ubic.gemma.model.common.description.BibliographicReferenceValueObject) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) BibliographicReference(ubic.gemma.model.common.description.BibliographicReference) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 45 with BibliographicReference

use of ubic.gemma.model.common.description.BibliographicReference in project Gemma by PavlidisLab.

the class BibliographicReferenceDaoImpl method find.

@Override
public BibliographicReference find(BibliographicReference bibliographicReference) {
    BusinessKey.checkKey(bibliographicReference);
    Criteria queryObject = this.getSessionFactory().getCurrentSession().createCriteria(BibliographicReference.class);
    /*
         * This syntax allows you to look at an association.
         */
    if (bibliographicReference.getPubAccession() != null) {
        queryObject.createCriteria("pubAccession").add(Restrictions.eq("accession", bibliographicReference.getPubAccession().getAccession()));
    } else {
        throw new NullPointerException("PubAccession cannot be null");
    }
    java.util.List<?> results = queryObject.list();
    Object result = null;
    if (results != null) {
        if (results.size() > 1) {
            throw new org.springframework.dao.InvalidDataAccessResourceUsageException("More than one instance of '" + BibliographicReference.class.getName() + "' with accession " + bibliographicReference.getPubAccession().getAccession() + " was found when executing query");
        } else if (results.size() == 1) {
            result = results.iterator().next();
        }
    }
    return (BibliographicReference) result;
}
Also used : java.util(java.util) BibliographicReferenceValueObject(ubic.gemma.model.common.description.BibliographicReferenceValueObject) Criteria(org.hibernate.Criteria) BibliographicReference(ubic.gemma.model.common.description.BibliographicReference)

Aggregations

BibliographicReference (ubic.gemma.model.common.description.BibliographicReference)45 Test (org.junit.Test)18 BibliographicReferenceValueObject (ubic.gemma.model.common.description.BibliographicReferenceValueObject)9 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)8 PubMedXMLFetcher (ubic.gemma.core.loader.entrez.pubmed.PubMedXMLFetcher)6 IOException (java.io.IOException)5 SimpleDateFormat (java.text.SimpleDateFormat)5 Transactional (org.springframework.transaction.annotation.Transactional)5 ModelAndView (org.springframework.web.servlet.ModelAndView)5 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)5 SearchSettings (ubic.gemma.model.common.search.SearchSettings)4 ArrayList (java.util.ArrayList)3 IndexerTaskCommand (ubic.gemma.core.tasks.maintenance.IndexerTaskCommand)3 DatabaseEntry (ubic.gemma.model.common.description.DatabaseEntry)3 MedicalSubjectHeading (ubic.gemma.model.common.description.MedicalSubjectHeading)3 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)3 URL (java.net.URL)2 Date (java.util.Date)2 StopWatch (org.apache.commons.lang3.time.StopWatch)2 ExternalDatabase (ubic.gemma.model.common.description.ExternalDatabase)2