Search in sources :

Example 1 with SearchResult

use of ubic.gemma.core.search.SearchResult in project Gemma by PavlidisLab.

the class ArrayDesignControllerImpl method filter.

@Override
@RequestMapping("/filterArrayDesigns.html")
public ModelAndView filter(HttpServletRequest request, HttpServletResponse response) {
    StopWatch overallWatch = new StopWatch();
    overallWatch.start();
    String filter = request.getParameter("filter");
    // Validate the filtering search criteria.
    if (StringUtils.isBlank(filter)) {
        return new ModelAndView(new RedirectView("/arrays/showAllArrayDesigns.html", true)).addObject("message", "No search criteria provided");
    }
    Collection<SearchResult> searchResults = searchService.search(SearchSettingsImpl.arrayDesignSearch(filter)).get(ArrayDesign.class);
    if ((searchResults == null) || (searchResults.size() == 0)) {
        return new ModelAndView(new RedirectView("/arrays/showAllArrayDesigns.html", true)).addObject("message", "No search criteria provided");
    }
    StringBuilder list = new StringBuilder();
    if (searchResults.size() == 1) {
        ArrayDesign arrayDesign = arrayDesignService.load(searchResults.iterator().next().getId());
        return new ModelAndView(new RedirectView("/arrays/showArrayDesign.html?id=" + arrayDesign.getId(), true)).addObject("message", "Matched one : " + arrayDesign.getName() + "(" + arrayDesign.getShortName() + ")");
    }
    for (SearchResult ad : searchResults) {
        list.append(ad.getId()).append(",");
    }
    overallWatch.stop();
    Long overallElapsed = overallWatch.getTime();
    log.info("Generating the AD list:  (" + list + ") took: " + overallElapsed / 1000 + "s ");
    return new ModelAndView(new RedirectView("/arrays/showAllArrayDesigns.html?id=" + list, true)).addObject("message", searchResults.size() + " Platforms matched your search.");
}
Also used : ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) SearchResult(ubic.gemma.core.search.SearchResult) StopWatch(org.apache.commons.lang3.time.StopWatch) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with SearchResult

use of ubic.gemma.core.search.SearchResult in project Gemma by PavlidisLab.

the class PhenotypeAssociationManagerServiceImpl method findGenesWithEvidence.

@Override
@Transactional(readOnly = true)
public Collection<GeneEvidenceValueObject> findGenesWithEvidence(String query, Long taxonId) {
    if (query == null || query.length() == 0) {
        throw new IllegalArgumentException("No search query provided");
    }
    // make sure it does an inexact search
    String newQuery = query + "%";
    Taxon taxon = null;
    if (taxonId != null) {
        taxon = this.taxonService.load(taxonId);
    }
    SearchSettings settings = SearchSettingsImpl.geneSearch(newQuery, taxon);
    List<SearchResult> geneSearchResults = this.searchService.search(settings).get(Gene.class);
    Collection<Gene> genes = new HashSet<>();
    if (geneSearchResults == null || geneSearchResults.isEmpty()) {
        return new HashSet<>();
    }
    for (SearchResult sr : geneSearchResults) {
        genes.add((Gene) sr.getResultObject());
    }
    Collection<GeneEvidenceValueObject> geneEvidenceValueObjects = new HashSet<>();
    for (Gene g : genes) {
        GeneEvidenceValueObject geneEvidenceValueObject = new GeneEvidenceValueObject(g, this.convert2ValueObjects(g.getPhenotypeAssociations()));
        geneEvidenceValueObjects.add(geneEvidenceValueObject);
    }
    Collection<GeneEvidenceValueObject> geneValueObjectsFilter = new ArrayList<>();
    for (GeneEvidenceValueObject gene : geneEvidenceValueObjects) {
        if (gene.getEvidence() != null && gene.getEvidence().size() != 0) {
            geneValueObjectsFilter.add(gene);
        }
    }
    return geneValueObjectsFilter;
}
Also used : Gene(ubic.gemma.model.genome.Gene) Taxon(ubic.gemma.model.genome.Taxon) SearchSettings(ubic.gemma.model.common.search.SearchSettings) SearchResult(ubic.gemma.core.search.SearchResult) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with SearchResult

use of ubic.gemma.core.search.SearchResult in project Gemma by PavlidisLab.

the class ExpressionExperimentManipulatingCLI method findExpressionExperimentsByQuery.

/**
 * Use the search engine to locate expression experiments.
 */
private Set<BioAssaySet> findExpressionExperimentsByQuery(String query) {
    Set<BioAssaySet> ees = new HashSet<>();
    Collection<SearchResult> eeSearchResults = searchService.search(SearchSettingsImpl.expressionExperimentSearch(query)).get(ExpressionExperiment.class);
    AbstractCLI.log.info(ees.size() + " Expression experiments matched '" + query + "'");
    // Filter out all the ee that are not of correct taxon
    for (SearchResult sr : eeSearchResults) {
        ExpressionExperiment ee = (ExpressionExperiment) sr.getResultObject();
        Taxon t = eeService.getTaxon(ee);
        if (t != null && t.getCommonName().equalsIgnoreCase(taxon.getCommonName())) {
            ees.add(ee);
        }
    }
    return ees;
}
Also used : BioAssaySet(ubic.gemma.model.expression.experiment.BioAssaySet) Taxon(ubic.gemma.model.genome.Taxon) SearchResult(ubic.gemma.core.search.SearchResult) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) HashSet(java.util.HashSet)

Example 4 with SearchResult

use of ubic.gemma.core.search.SearchResult 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 5 with SearchResult

use of ubic.gemma.core.search.SearchResult in project Gemma by PavlidisLab.

the class ExpressionExperimentServiceImpl method filter.

/**
 * returns ids of search results
 *
 * @return collection of ids or an empty collection
 */
@Override
@Transactional(readOnly = true)
public Collection<Long> filter(String searchString) {
    Map<Class<?>, List<SearchResult>> searchResultsMap = searchService.search(SearchSettingsImpl.expressionExperimentSearch(searchString));
    assert searchResultsMap != null;
    Collection<SearchResult> searchResults = searchResultsMap.get(ExpressionExperiment.class);
    Collection<Long> ids = new ArrayList<>(searchResults.size());
    for (SearchResult s : searchResults) {
        ids.add(s.getId());
    }
    return ids;
}
Also used : SearchResult(ubic.gemma.core.search.SearchResult) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

SearchResult (ubic.gemma.core.search.SearchResult)15 SearchSettings (ubic.gemma.model.common.search.SearchSettings)7 Gene (ubic.gemma.model.genome.Gene)7 Taxon (ubic.gemma.model.genome.Taxon)5 StopWatch (org.apache.commons.lang3.time.StopWatch)3 Transactional (org.springframework.transaction.annotation.Transactional)3 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)3 ExpressionExperimentValueObject (ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject)3 CharacteristicValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject)3 HashSet (java.util.HashSet)2 SearchResultDisplayObject (ubic.gemma.core.search.SearchResultDisplayObject)2 SearchSettingsImpl (ubic.gemma.model.common.search.SearchSettingsImpl)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1 RedirectView (org.springframework.web.servlet.view.RedirectView)1 ExpressionExperimentSet (ubic.gemma.model.analysis.expression.ExpressionExperimentSet)1 GeneCoexpressionNodeDegreeValueObject (ubic.gemma.model.association.coexpression.GeneCoexpressionNodeDegreeValueObject)1 PhenotypeAssociation (ubic.gemma.model.association.phenotype.PhenotypeAssociation)1 BibliographicReference (ubic.gemma.model.common.description.BibliographicReference)1 Characteristic (ubic.gemma.model.common.description.Characteristic)1