Search in sources :

Example 6 with SearchSettings

use of ubic.gemma.model.common.search.SearchSettings in project Gemma by PavlidisLab.

the class GeneralSearchControllerImpl method showForm.

@Deprecated
@Override
@RequestMapping(value = "/searcher.html", method = RequestMethod.GET)
protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception {
    if (request.getParameter("query") != null || request.getParameter("termUri") != null) {
        SearchSettings csc = (SearchSettings) this.formBackingObject(request);
        csc.setQuery(request.getParameter("query"));
        csc.setTermUri(request.getParameter("termUri"));
        String taxon = request.getParameter("taxon");
        if (taxon != null)
            csc.setTaxon(taxonService.findByScientificName(taxon));
        String scope = request.getParameter("scope");
        if (StringUtils.isNotBlank(scope)) {
            char[] scopes = scope.toCharArray();
            for (char scope1 : scopes) {
                switch(scope1) {
                    case 'G':
                        csc.setSearchGenes(true);
                        break;
                    case 'E':
                        csc.setSearchExperiments(true);
                        break;
                    case 'S':
                        csc.setSearchBioSequences(true);
                        break;
                    case 'P':
                        csc.setSearchProbes(true);
                        break;
                    case 'A':
                        csc.setSearchPlatforms(true);
                        break;
                    case 'M':
                        csc.setSearchGeneSets(true);
                        break;
                    case 'N':
                        csc.setSearchExperimentSets(true);
                        break;
                    default:
                        break;
                }
            }
        }
        return this.doSearch(request, response, csc, errors);
    }
    return new ModelAndView("generalSearch");
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) SearchSettings(ubic.gemma.model.common.search.SearchSettings) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with SearchSettings

use of ubic.gemma.model.common.search.SearchSettings in project Gemma by PavlidisLab.

the class GeneSearchServiceImpl method searchMultipleGenesGetMap.

@Override
public Map<String, GeneValueObject> searchMultipleGenesGetMap(Collection<String> query, Long taxonId) {
    Taxon taxon = taxonService.load(taxonId);
    if (taxon == null)
        throw new IllegalArgumentException("No such taxon with id=" + taxonId);
    // this deals with the simple cases. For remainder we look a little harder
    Map<String, GeneValueObject> queryToGenes = geneService.findByOfficialSymbols(query, taxonId);
    for (String line : query) {
        line = StringUtils.strip(line);
        if (StringUtils.isBlank(line)) {
            continue;
        }
        String queryAsKey = line.toLowerCase();
        if (queryToGenes.containsKey(queryAsKey)) {
            // already found.
            continue;
        }
        if (queryToGenes.size() >= GeneSearchServiceImpl.MAX_GENES_PER_QUERY) {
            GeneSearchServiceImpl.log.warn("Too many genes, stopping (limit=" + GeneSearchServiceImpl.MAX_GENES_PER_QUERY + ')');
            break;
        }
        // searching one gene at a time is a bit slow; we do a quick search for symbols.
        SearchSettings settings = SearchSettingsImpl.geneSearch(line, taxon);
        List<SearchResult> geneSearchResults = searchService.speedSearch(settings).get(Gene.class);
        if (geneSearchResults == null || geneSearchResults.isEmpty()) {
            // an empty set is an indication of no results.
            queryToGenes.put(queryAsKey, null);
        } else if (geneSearchResults.size() == 1) {
            // Just one result so add it
            Gene g = (Gene) geneSearchResults.iterator().next().getResultObject();
            queryToGenes.put(queryAsKey, new GeneValueObject(g));
        } else {
            // like grin1, grin2, grin3, grin (given the search term was grin)
            for (SearchResult sr : geneSearchResults) {
                Gene srGene = (Gene) sr.getResultObject();
                if (srGene.getTaxon().equals(taxon) && srGene.getOfficialSymbol().equalsIgnoreCase(line)) {
                    queryToGenes.put(queryAsKey, new GeneValueObject(srGene));
                    // found so done
                    break;
                }
            }
        }
    }
    return queryToGenes;
}
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)

Example 8 with SearchSettings

use of ubic.gemma.model.common.search.SearchSettings in project Gemma by PavlidisLab.

the class GeneSearchServiceImpl method searchGenesAndGeneGroups.

@Override
public Collection<SearchResultDisplayObject> searchGenesAndGeneGroups(String query, Long taxonId) {
    Taxon taxon = null;
    String taxonName = "";
    if (taxonId != null) {
        taxon = taxonService.load(taxonId);
        if (taxon == null) {
            GeneSearchServiceImpl.log.warn("No such taxon with id=" + taxonId);
        } else {
            taxonName = taxon.getCommonName();
        }
    }
    List<SearchResultDisplayObject> displayResults = new ArrayList<>();
    // session-bound sets
    if (StringUtils.isBlank(query)) {
        return this.searchGenesAndGeneGroupsBlankQuery(taxonId);
    }
    Integer maxGeneralSearchResults = 500;
    /*
         * GET GENES AND GENE SETS
         */
    // SearchSettings settings = SearchSettings.geneSearch( query, taxon );
    SearchSettings settings = SearchSettings.Factory.newInstance();
    settings.setQuery(query);
    settings.noSearches();
    // add searching for genes
    settings.setSearchGenes(true);
    // add searching for geneSets
    settings.setSearchGeneSets(true);
    settings.setMaxResults(maxGeneralSearchResults);
    if (taxon != null)
        // this doesn't work yet
        settings.setTaxon(taxon);
    GeneSearchServiceImpl.log.debug("getting results from searchService for " + query);
    Map<Class<?>, List<SearchResult>> results = searchService.speedSearch(settings);
    List<SearchResult> geneSetSearchResults = new ArrayList<>();
    List<SearchResult> geneSearchResults = new ArrayList<>();
    boolean exactGeneSymbolMatch = false;
    if (!results.isEmpty()) {
        if (results.get(GeneSet.class) != null) {
            geneSetSearchResults.addAll(results.get(GeneSet.class));
        }
        if (results.get(Gene.class) != null) {
            geneSearchResults.addAll(results.get(Gene.class));
        }
        // Check to see if we have an exact match, if so, return earlier abstaining from doing other searches
        for (SearchResult geneResult : results.get(Gene.class)) {
            Gene g = (Gene) geneResult.getResultObject();
            // aliases too?
            if (g != null && g.getOfficialSymbol() != null && g.getOfficialSymbol().startsWith(query.trim())) {
                exactGeneSymbolMatch = true;
                break;
            }
        }
    }
    Collection<SearchResultDisplayObject> genes = new ArrayList<>();
    Collection<SearchResultDisplayObject> geneSets;
    Map<Long, Boolean> isSetOwnedByUser = new HashMap<>();
    if (taxon != null) {
        // filter search results by taxon
        List<SearchResult> taxonCheckedGenes = this.retainGenesOfThisTaxon(taxonId, geneSearchResults);
        // convert result object to a value object to a SearchResultDisplayObject
        for (SearchResult sr : taxonCheckedGenes) {
            genes.add(new SearchResultDisplayObject(sr));
        }
        List<SearchResult> taxonCheckedSets = this.retainGeneSetsOfThisTaxon(taxonId, geneSetSearchResults, isSetOwnedByUser);
        // convert result object to a value object
        for (SearchResult sr : taxonCheckedSets) {
            GeneSet g = (GeneSet) sr.getResultObject();
            DatabaseBackedGeneSetValueObject gsVo = geneSetValueObjectHelper.convertToValueObject(g);
            sr.setResultObject(gsVo);
        }
        geneSets = SearchResultDisplayObject.convertSearchResults2SearchResultDisplayObjects(taxonCheckedSets);
        for (SearchResultDisplayObject srDo : geneSets) {
            // geneSets were filtered by taxon above:
            // if taxonId for geneSet != taxonId param, then gene set was already removed
            srDo.setTaxonId(taxonId);
            srDo.setTaxonName(taxonName);
        }
    } else {
        for (SearchResult sr : geneSearchResults) {
            genes.add(new SearchResultDisplayObject(sr));
        }
        geneSets = new ArrayList<>();
        SearchResultDisplayObject srDo;
        for (SearchResult sr : geneSetSearchResults) {
            GeneSet gs = (GeneSet) sr.getResultObject();
            isSetOwnedByUser.put(gs.getId(), securityService.isOwnedByCurrentUser(gs));
            taxon = geneSetService.getTaxon((GeneSet) sr.getResultObject());
            GeneSetValueObject gsVo = geneSetValueObjectHelper.convertToValueObject(gs);
            srDo = new SearchResultDisplayObject(gsVo);
            srDo.setTaxonId(taxon.getId());
            srDo.setTaxonName(taxon.getCommonName());
            geneSets.add(srDo);
        }
        taxon = null;
    }
    // if a geneSet is owned by the user, mark it as such (used for giving it a special background colour in
    // search results)
    this.setUserOwnedForGeneSets(geneSets, isSetOwnedByUser);
    if (exactGeneSymbolMatch) {
        // get summary results
        GeneSearchServiceImpl.log.info("getting Summary results for " + query);
        List<SearchResultDisplayObject> summaries = this.addEntryForAllResults(query, genes, geneSets, new ArrayList<SearchResultDisplayObject>(), new ArrayList<SearchResultDisplayObject>());
        displayResults.addAll(summaries);
        displayResults.addAll(genes);
        displayResults.addAll(geneSets);
        return displayResults;
    }
    List<SearchResultDisplayObject> srDos;
    // get GO group results
    GeneSearchServiceImpl.log.debug("Getting GO group results for " + query);
    srDos = this.getGOGroupResults(query, taxon);
    List<SearchResultDisplayObject> phenotypeSrDos = new ArrayList<>();
    if (!query.toUpperCase().startsWith("GO")) {
        GeneSearchServiceImpl.log.info("getting Phenotype Association results for " + query);
        phenotypeSrDos = this.getPhenotypeAssociationSearchResults(query, taxon);
    }
    // }
    // get summary results
    GeneSearchServiceImpl.log.debug("Getting Summary results for " + query);
    List<SearchResultDisplayObject> summaryEntries = this.addEntryForAllResults(query, genes, geneSets, srDos, phenotypeSrDos);
    // add all results, keeping order of result types
    displayResults.addAll(summaryEntries);
    displayResults.addAll(geneSets);
    displayResults.addAll(srDos);
    displayResults.addAll(phenotypeSrDos);
    displayResults.addAll(genes);
    if (displayResults.isEmpty()) {
        GeneSearchServiceImpl.log.info("No results for search: " + query + " taxon=" + ((taxon == null) ? null : taxon.getCommonName()));
        return new HashSet<>();
    }
    GeneSearchServiceImpl.log.info("Results for search: " + query + ", size=" + displayResults.size());
    return displayResults;
}
Also used : Gene(ubic.gemma.model.genome.Gene) SearchSettings(ubic.gemma.model.common.search.SearchSettings) Taxon(ubic.gemma.model.genome.Taxon) SearchResult(ubic.gemma.core.search.SearchResult) SearchResultDisplayObject(ubic.gemma.core.search.SearchResultDisplayObject)

Example 9 with SearchSettings

use of ubic.gemma.model.common.search.SearchSettings in project Gemma by PavlidisLab.

the class ExpressionExperimentSearchServiceImpl method initialSearch.

private Map<Class<?>, List<SearchResult>> initialSearch(String query, Long taxonId) {
    SearchSettings settings = SearchSettingsImpl.expressionExperimentSearch(query);
    // add searching for experimentSets
    settings.setSearchExperimentSets(true);
    Taxon taxonParam;
    if (taxonId != null) {
        taxonParam = taxonService.load(taxonId);
        settings.setTaxon(taxonParam);
    }
    return searchService.search(settings);
}
Also used : Taxon(ubic.gemma.model.genome.Taxon) SearchSettings(ubic.gemma.model.common.search.SearchSettings)

Example 10 with SearchSettings

use of ubic.gemma.model.common.search.SearchSettings in project Gemma by PavlidisLab.

the class ExpressionExperimentSearchServiceImpl method searchExpressionExperiments.

@Override
public Collection<ExpressionExperimentValueObject> searchExpressionExperiments(String query) {
    SearchSettings settings = SearchSettingsImpl.expressionExperimentSearch(query);
    List<SearchResult> experimentSearchResults = searchService.search(settings).get(ExpressionExperiment.class);
    if (experimentSearchResults == null || experimentSearchResults.isEmpty()) {
        ExpressionExperimentSearchServiceImpl.log.info("No experiments for search: " + query);
        return new HashSet<>();
    }
    ExpressionExperimentSearchServiceImpl.log.info("Experiment search: " + query + ", " + experimentSearchResults.size() + " found");
    Collection<ExpressionExperimentValueObject> experimentValueObjects = expressionExperimentService.loadValueObjects(EntityUtils.getIds(experimentSearchResults), true);
    ExpressionExperimentSearchServiceImpl.log.info("Experiment search: " + experimentValueObjects.size() + " value objects returned.");
    return experimentValueObjects;
}
Also used : ExpressionExperimentValueObject(ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject) SearchSettings(ubic.gemma.model.common.search.SearchSettings) SearchResult(ubic.gemma.core.search.SearchResult)

Aggregations

SearchSettings (ubic.gemma.model.common.search.SearchSettings)19 Test (org.junit.Test)7 SearchResult (ubic.gemma.core.search.SearchResult)7 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)7 Gene (ubic.gemma.model.genome.Gene)5 Taxon (ubic.gemma.model.genome.Taxon)5 BibliographicReference (ubic.gemma.model.common.description.BibliographicReference)4 PubMedXMLFetcher (ubic.gemma.core.loader.entrez.pubmed.PubMedXMLFetcher)3 IndexerTaskCommand (ubic.gemma.core.tasks.maintenance.IndexerTaskCommand)3 Transactional (org.springframework.transaction.annotation.Transactional)2 InputStream (java.io.InputStream)1 HashSet (java.util.HashSet)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1 SearchResultDisplayObject (ubic.gemma.core.search.SearchResultDisplayObject)1 Auditable (ubic.gemma.model.common.Auditable)1 AuditEvent (ubic.gemma.model.common.auditAndSecurity.AuditEvent)1 BibliographicReferenceValueObject (ubic.gemma.model.common.description.BibliographicReferenceValueObject)1 Characteristic (ubic.gemma.model.common.description.Characteristic)1