Search in sources :

Example 16 with BibliographicReference

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

the class ExpressionExperimentPrimaryPubCli method doWork.

@Override
protected Exception doWork(String[] args) {
    Exception err = processCommandLine(args);
    if (err != null)
        return err;
    ExpressionExperimentService ees = this.getBean(ExpressionExperimentService.class);
    Persister ph = this.getPersisterHelper();
    PubMedXMLFetcher fetcher = new PubMedXMLFetcher();
    // collect some statistics
    Collection<String> nullPubCount = new ArrayList<>();
    Collection<String> samePubCount = new ArrayList<>();
    Collection<String> diffPubCount = new ArrayList<>();
    Collection<String> failedEe = new ArrayList<>();
    ExpressionExperimentBibRefFinder finder = new ExpressionExperimentBibRefFinder();
    for (BioAssaySet bioassay : expressionExperiments) {
        if (!(bioassay instanceof ExpressionExperiment)) {
            log.info(bioassay.getName() + " is not an ExpressionExperiment");
            continue;
        }
        ExpressionExperiment experiment = (ExpressionExperiment) bioassay;
        // if ( experiment.getPrimaryPublication() != null ) continue;
        if (experiment.getPrimaryPublication() == null) {
            log.warn(experiment + " has no existing primary publication");
        }
        experiment = ees.thawLite(experiment);
        // get from GEO or get from a file
        BibliographicReference ref = fetcher.retrieveByHTTP(pubmedIds.get(experiment.getShortName()));
        if (ref == null) {
            if (this.pubmedIdFilename != null) {
                log.warn("Pubmed ID for " + experiment.getShortName() + " was not found in " + this.pubmedIdFilename);
            }
            ref = finder.locatePrimaryReference(experiment);
            if (ref == null) {
                log.error("No ref for " + experiment);
                failedEe.add(experiment.getShortName());
                continue;
            }
        }
        // collect some statistics
        if (experiment.getPrimaryPublication() == null) {
            nullPubCount.add(experiment.getShortName());
        } else if (experiment.getPrimaryPublication().getPubAccession().getAccession().equals(pubmedIds.get(experiment.getShortName()).toString())) {
            samePubCount.add(experiment.getShortName());
        } else {
            diffPubCount.add(experiment.getShortName());
        }
        try {
            log.info("Found pubAccession " + ref.getPubAccession().getAccession() + " for " + experiment);
            ref = (BibliographicReference) ph.persist(ref);
            experiment.setPrimaryPublication(ref);
            ees.update(experiment);
        } catch (Exception e) {
            log.error(experiment.getShortName() + " (id=" + experiment.getId() + ") update failed.");
            e.printStackTrace();
        }
    }
    // print statistics
    log.info("\n\n========== Summary ==========");
    log.info("Total number of experiments: " + expressionExperiments.size());
    log.info("Same publication: " + samePubCount.size());
    log.info("Diff publication: " + diffPubCount.size());
    log.info("No initial publication: " + nullPubCount.size());
    log.info("No publications found: " + failedEe.size());
    log.info("\n\n========== Details ==========");
    log.info("Diff publication: " + Arrays.toString(diffPubCount.toArray()));
    log.info("No initial publication: " + Arrays.toString(nullPubCount.toArray()));
    log.info("No publications found: " + Arrays.toString(failedEe.toArray()));
    return null;
}
Also used : ExpressionExperimentBibRefFinder(ubic.gemma.core.loader.entrez.pubmed.ExpressionExperimentBibRefFinder) BioAssaySet(ubic.gemma.model.expression.experiment.BioAssaySet) ArrayList(java.util.ArrayList) ExpressionExperimentService(ubic.gemma.persistence.service.expression.experiment.ExpressionExperimentService) PubMedXMLFetcher(ubic.gemma.core.loader.entrez.pubmed.PubMedXMLFetcher) Persister(ubic.gemma.persistence.persister.Persister) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) BibliographicReference(ubic.gemma.model.common.description.BibliographicReference) IOException(java.io.IOException)

Example 17 with BibliographicReference

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

the class GeneralSearchControllerImpl method fillValueObjects.

@SuppressWarnings("unchecked")
private void fillValueObjects(Class<?> entityClass, List<SearchResult> results, SearchSettings settings) {
    StopWatch timer = new StopWatch();
    timer.start();
    Collection<?> vos;
    if (ExpressionExperiment.class.isAssignableFrom(entityClass)) {
        vos = this.filterEE(expressionExperimentService.loadValueObjects(EntityUtils.getIds(results), false), settings);
        if (!SecurityUtil.isUserAdmin()) {
            auditableUtil.removeTroubledEes((Collection<ExpressionExperimentValueObject>) vos);
        }
    } else if (ArrayDesign.class.isAssignableFrom(entityClass)) {
        vos = this.filterAD(arrayDesignService.loadValueObjectsByIds(EntityUtils.getIds(results)), settings);
        if (!SecurityUtil.isUserAdmin()) {
            auditableUtil.removeTroubledArrayDesigns((Collection<ArrayDesignValueObject>) vos);
        }
    } else if (CompositeSequence.class.isAssignableFrom(entityClass)) {
        Collection<CompositeSequenceValueObject> css = new ArrayList<>();
        for (SearchResult sr : results) {
            CompositeSequenceValueObject csvo = compositeSequenceService.loadValueObject((CompositeSequence) sr.getResultObject());
            css.add(csvo);
        }
        vos = css;
    } else if (BibliographicReference.class.isAssignableFrom(entityClass)) {
        Collection<BibliographicReference> bss = bibliographicReferenceService.load(EntityUtils.getIds(results));
        bss = bibliographicReferenceService.thaw(bss);
        vos = bibliographicReferenceService.loadValueObjects(bss);
    } else if (Gene.class.isAssignableFrom(entityClass)) {
        Collection<Gene> genes = geneService.load(EntityUtils.getIds(results));
        genes = geneService.thawLite(genes);
        vos = geneService.loadValueObjects(genes);
    } else if (Characteristic.class.isAssignableFrom(entityClass)) {
        Collection<CharacteristicValueObject> cvos = new ArrayList<>();
        for (SearchResult sr : results) {
            Characteristic ch = (Characteristic) sr.getResultObject();
            cvos.add(new CharacteristicValueObject(ch));
        }
        vos = cvos;
    } else if (CharacteristicValueObject.class.isAssignableFrom(entityClass)) {
        Collection<CharacteristicValueObject> cvos = new ArrayList<>();
        for (SearchResult sr : results) {
            CharacteristicValueObject ch = (CharacteristicValueObject) sr.getResultObject();
            cvos.add(ch);
        }
        vos = cvos;
    } else if (BioSequenceValueObject.class.isAssignableFrom(entityClass)) {
        return;
    } else if (GeneSet.class.isAssignableFrom(entityClass)) {
        vos = geneSetService.getValueObjects(EntityUtils.getIds(results));
    } else if (ExpressionExperimentSet.class.isAssignableFrom(entityClass)) {
        vos = experimentSetService.loadValueObjects(experimentSetService.load(EntityUtils.getIds(results)));
    } else if (FactorValue.class.isAssignableFrom(entityClass)) {
        Collection<FactorValueValueObject> fvo = new ArrayList<>();
        for (SearchResult sr : results) {
            fvo.add(new FactorValueValueObject((FactorValue) sr.getResultObject()));
        }
        vos = fvo;
    } else {
        throw new UnsupportedOperationException("Don't know how to make value objects for class=" + entityClass);
    }
    if (vos == null || vos.isEmpty()) {
        // it causing front end errors, if vos is empty make sure to get rid of all search results
        for (Iterator<SearchResult> it = results.iterator(); it.hasNext(); ) {
            it.next();
            it.remove();
        }
        return;
    }
    // retained objects...
    Map<Long, Object> idMap = EntityUtils.getIdMap(vos);
    for (Iterator<SearchResult> it = results.iterator(); it.hasNext(); ) {
        SearchResult sr = it.next();
        if (!idMap.containsKey(sr.getId())) {
            it.remove();
            continue;
        }
        sr.setResultObject(idMap.get(sr.getId()));
    }
    if (timer.getTime() > 1000) {
        BaseFormController.log.info("Value object conversion after search: " + timer.getTime() + "ms");
    }
}
Also used : CharacteristicValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject) CompositeSequenceValueObject(ubic.gemma.model.expression.designElement.CompositeSequenceValueObject) Gene(ubic.gemma.model.genome.Gene) ExpressionExperimentValueObject(ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject) BioSequenceValueObject(ubic.gemma.model.genome.sequenceAnalysis.BioSequenceValueObject) FactorValueValueObject(ubic.gemma.model.expression.experiment.FactorValueValueObject) FactorValue(ubic.gemma.model.expression.experiment.FactorValue) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) Characteristic(ubic.gemma.model.common.description.Characteristic) SearchResult(ubic.gemma.core.search.SearchResult) BibliographicReference(ubic.gemma.model.common.description.BibliographicReference) StopWatch(org.apache.commons.lang3.time.StopWatch) ExpressionExperimentSet(ubic.gemma.model.analysis.expression.ExpressionExperimentSet) ArrayDesignValueObject(ubic.gemma.model.expression.arrayDesign.ArrayDesignValueObject) SearchSettingsValueObject(ubic.gemma.model.common.search.SearchSettingsValueObject) FactorValueValueObject(ubic.gemma.model.expression.experiment.FactorValueValueObject) BioSequenceValueObject(ubic.gemma.model.genome.sequenceAnalysis.BioSequenceValueObject) ExpressionExperimentValueObject(ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject) CompositeSequenceValueObject(ubic.gemma.model.expression.designElement.CompositeSequenceValueObject) CharacteristicValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject)

Example 18 with BibliographicReference

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

the class BibliographicReferenceControllerImpl method add.

@Override
public ModelAndView add(HttpServletRequest request, HttpServletResponse response) {
    // FIXME: allow use of the primary key as well.
    String pubMedId = request.getParameter("accession");
    if (StringUtils.isBlank(pubMedId)) {
        throw new EntityNotFoundException("Must provide a PubMed Id");
    }
    BibliographicReference bibRef = bibliographicReferenceService.findByExternalId(pubMedId);
    BibliographicReferenceValueObject vo;
    if (bibRef == null) {
        bibRef = this.pubMedXmlFetcher.retrieveByHTTP(Integer.parseInt(pubMedId));
        if (bibRef == null) {
            throw new EntityNotFoundException("Could not locate reference with pubmed id=" + pubMedId);
        }
        vo = new BibliographicReferenceValueObject((BibliographicReference) persisterHelper.persist(bibRef));
        this.saveMessage(request, "Added " + pubMedId + " to the system.");
    } else if (StringUtils.isNotBlank(request.getParameter("refresh"))) {
        vo = this.update(pubMedId);
        this.saveMessage(request, "Updated record for pubmed id " + pubMedId);
    } else {
        throw new IllegalArgumentException("Action not understood");
    }
    return new ModelAndView("bibRefView").addObject("bibliographicReferenceId", vo.getId()).addObject("existsInSystem", Boolean.TRUE).addObject("bibliographicReference", vo);
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) BibliographicReferenceValueObject(ubic.gemma.model.common.description.BibliographicReferenceValueObject) EntityNotFoundException(ubic.gemma.web.util.EntityNotFoundException) BibliographicReference(ubic.gemma.model.common.description.BibliographicReference)

Example 19 with BibliographicReference

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

the class BibliographicReferenceControllerImpl method showAllForExperiments.

@Override
public ModelAndView showAllForExperiments(HttpServletRequest request, HttpServletResponse response) {
    Map<ExpressionExperiment, BibliographicReference> eeToBibRefs = bibliographicReferenceService.getAllExperimentLinkedReferences();
    // map sorted in natural order of the keys
    SortedMap<CitationValueObject, Collection<ExpressionExperimentValueObject>> citationToEEs = new TreeMap<>();
    for (Entry<ExpressionExperiment, BibliographicReference> entry : eeToBibRefs.entrySet()) {
        if (entry.getValue().getTitle() == null || entry.getValue().getTitle().isEmpty() || entry.getValue().getAuthorList() == null || entry.getValue().getAuthorList().isEmpty()) {
            continue;
        }
        CitationValueObject cvo = CitationValueObject.convert2CitationValueObject(entry.getValue());
        if (!citationToEEs.containsKey(cvo)) {
            citationToEEs.put(cvo, new ArrayList<ExpressionExperimentValueObject>());
        }
        ExpressionExperiment ee = entry.getKey();
        ee.setBioAssays(null);
        ee.setAccession(null);
        ee.setExperimentalDesign(null);
        citationToEEs.get(cvo).add(new ExpressionExperimentValueObject(ee));
    }
    return new ModelAndView("bibRefAllExperiments").addObject("citationToEEs", citationToEEs);
}
Also used : ExpressionExperimentValueObject(ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject) CitationValueObject(ubic.gemma.model.common.description.CitationValueObject) ModelAndView(org.springframework.web.servlet.ModelAndView) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) BibliographicReference(ubic.gemma.model.common.description.BibliographicReference)

Example 20 with BibliographicReference

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

the class BibliographicReferenceControllerImpl method browse.

@Override
public JsonReaderResponse<BibliographicReferenceValueObject> browse(ListBatchCommand batch) {
    Integer count = this.bibliographicReferenceService.countAll();
    List<BibliographicReference> records = this.getBatch(batch);
    Map<BibliographicReference, Collection<ExpressionExperiment>> relatedExperiments = this.bibliographicReferenceService.getRelatedExperiments(records);
    List<BibliographicReferenceValueObject> valueObjects = new ArrayList<>();
    for (BibliographicReference ref : records) {
        ref = this.bibliographicReferenceService.thaw(ref);
        BibliographicReferenceValueObject vo = new BibliographicReferenceValueObject(ref);
        if (relatedExperiments.containsKey(ref)) {
            vo.setExperiments(expressionExperimentService.loadValueObjects(relatedExperiments.get(ref)));
        }
        valueObjects.add(vo);
        // adding phenotype information to the Bibliographic Reference
        Collection<PhenotypeAssociation> phenotypeAssociations = this.phenotypeAssociationService.findPhenotypesForBibliographicReference(vo.getPubAccession());
        Collection<BibliographicPhenotypesValueObject> bibliographicPhenotypesValueObjects = BibliographicPhenotypesValueObject.phenotypeAssociations2BibliographicPhenotypesValueObjects(phenotypeAssociations);
        vo.setBibliographicPhenotypes(bibliographicPhenotypesValueObjects);
    }
    return new JsonReaderResponse<>(valueObjects, count);
}
Also used : PhenotypeAssociation(ubic.gemma.model.association.phenotype.PhenotypeAssociation) BibliographicReferenceValueObject(ubic.gemma.model.common.description.BibliographicReferenceValueObject) JsonReaderResponse(ubic.gemma.web.remote.JsonReaderResponse) BibliographicReference(ubic.gemma.model.common.description.BibliographicReference) BibliographicPhenotypesValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.BibliographicPhenotypesValueObject)

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