Search in sources :

Example 11 with SearchSettings

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

the class GeneCoreServiceImpl method searchGenes.

/**
 * Search for genes (by name or symbol)
 *
 * @param taxonId, can be null to not constrain by taxon
 * @return Collection of Gene entity objects
 */
@Override
public Collection<GeneValueObject> searchGenes(String query, Long taxonId) {
    Taxon taxon = null;
    if (taxonId != null) {
        taxon = this.taxonService.load(taxonId);
    }
    SearchSettings settings = SearchSettingsImpl.geneSearch(query, taxon);
    List<SearchResult> geneSearchResults = this.searchService.search(settings).get(Gene.class);
    Collection<Gene> genes = new HashSet<>();
    if (geneSearchResults == null || geneSearchResults.isEmpty()) {
        GeneCoreServiceImpl.log.info("No Genes for search: " + query + " taxon=" + taxonId);
        return new HashSet<>();
    }
    GeneCoreServiceImpl.log.info("Gene search: " + query + " taxon=" + taxonId + ", " + geneSearchResults.size() + " found");
    for (SearchResult sr : geneSearchResults) {
        Gene g = (Gene) sr.getResultObject();
        g = geneService.thaw(g);
        genes.add(g);
        GeneCoreServiceImpl.log.debug("Gene search result: " + g.getOfficialSymbol());
    }
    Collection<GeneValueObject> geneValueObjects = geneService.loadValueObjects(genes);
    GeneCoreServiceImpl.log.debug("Gene search: " + geneValueObjects.size() + " value objects returned.");
    return geneValueObjects;
}
Also used : GeneValueObject(ubic.gemma.model.genome.gene.GeneValueObject) 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) HashSet(java.util.HashSet)

Example 12 with SearchSettings

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

the class SearchServiceTest method testGeneUriSearch.

/**
 * Tests that gene uris get handled correctly
 */
@Test
public void testGeneUriSearch() {
    try {
        this.setup();
    } catch (Exception e) {
        e.printStackTrace();
    }
    SearchSettings settings = SearchSettings.Factory.newInstance();
    settings.setQuery(SearchServiceTest.GENE_URI + this.geneNcbiId);
    settings.setSearchGenes(true);
    Map<Class<?>, List<SearchResult>> found = this.searchService.search(settings);
    assertTrue(!found.isEmpty());
    for (SearchResult sr : found.get(Gene.class)) {
        if (sr.getResultObject().equals(gene)) {
            this.tearDown();
            return;
        }
    }
    this.tearDown();
    fail("Didn't get expected result from search");
}
Also used : SearchSettings(ubic.gemma.model.common.search.SearchSettings) Test(org.junit.Test) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest)

Example 13 with SearchSettings

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

the class SearchServiceTest method setup.

public void setup() throws Exception {
    try (InputStream is = this.getClass().getResourceAsStream("/data/loader/ontology/fma.test.owl")) {
        assert is != null;
        ontologyService.getFmaOntologyService().loadTermsInNameSpace(is);
    }
    ee = this.getTestPersistentBasicExpressionExperiment();
    VocabCharacteristic eeCharSpinalCord = VocabCharacteristic.Factory.newInstance();
    eeCharSpinalCord.setCategory(SearchServiceTest.SPINAL_CORD);
    eeCharSpinalCord.setCategoryUri(SearchServiceTest.SPINAL_CORD);
    eeCharSpinalCord.setValue(SearchServiceTest.SPINAL_CORD);
    eeCharSpinalCord.setValueUri(SearchServiceTest.SPINAL_CORD);
    characteristicService.create(eeCharSpinalCord);
    VocabCharacteristic eeCharGeneURI = VocabCharacteristic.Factory.newInstance();
    eeCharGeneURI.setCategory(SearchServiceTest.GENE_URI);
    eeCharGeneURI.setCategoryUri(SearchServiceTest.GENE_URI);
    eeCharGeneURI.setValue(SearchServiceTest.GENE_URI);
    eeCharGeneURI.setValueUri(SearchServiceTest.GENE_URI);
    characteristicService.create(eeCharGeneURI);
    VocabCharacteristic eeCharCortexURI = VocabCharacteristic.Factory.newInstance();
    eeCharCortexURI.setCategory(SearchServiceTest.BRAIN_CAVITY);
    eeCharCortexURI.setCategoryUri(SearchServiceTest.BRAIN_CAVITY);
    eeCharCortexURI.setValue(SearchServiceTest.BRAIN_CAVITY);
    eeCharCortexURI.setValueUri(SearchServiceTest.BRAIN_CAVITY);
    characteristicService.create(eeCharCortexURI);
    Collection<Characteristic> chars = new HashSet<>();
    chars.add(eeCharSpinalCord);
    chars.add(eeCharGeneURI);
    chars.add(eeCharCortexURI);
    ee.setCharacteristics(chars);
    eeService.update(ee);
    gene = this.getTestPersistentGene();
    this.geneNcbiId = RandomStringUtils.randomNumeric(8);
    gene.setNcbiGeneId(new Integer(geneNcbiId));
    geneService.update(gene);
    thePastUserQuery = UserQuery.Factory.newInstance();
    Calendar calendar = Calendar.getInstance();
    // the past
    calendar.set(Calendar.YEAR, 1979);
    calendar.set(Calendar.MONTH, 1);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    thePastUserQuery.setLastUsed(calendar.getTime());
    SearchSettings settings = SearchSettings.Factory.newInstance();
    settings.noSearches();
    // should hit 'cavity of brain'.
    settings.setQuery("Brain");
    settings.setSearchExperiments(true);
    settings.setUseCharacteristics(true);
    settings.setUseIndices(false);
    settings.setUseDatabase(false);
    thePastUserQuery.setSearchSettings(settings);
    thePastUserQuery.setUrl("someUrl");
    // the future
    calendar.add(Calendar.YEAR, 2000);
    theFutureUserQuery = UserQuery.Factory.newInstance();
    theFutureUserQuery.setLastUsed(calendar.getTime());
    SearchSettings futureSettings = SearchSettings.Factory.newInstance();
    futureSettings.noSearches();
    // should hit 'cavity of brain'.
    futureSettings.setQuery("Brain");
    futureSettings.setSearchExperiments(true);
    futureSettings.setUseCharacteristics(true);
    theFutureUserQuery.setSearchSettings(futureSettings);
    theFutureUserQuery.setUrl("someUrl");
    // save to db to load later to test if the pipes are clean
    userQueryService.create(thePastUserQuery);
    userQueryService.create(theFutureUserQuery);
}
Also used : InputStream(java.io.InputStream) Characteristic(ubic.gemma.model.common.description.Characteristic) VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) SearchSettings(ubic.gemma.model.common.search.SearchSettings)

Example 14 with SearchSettings

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

the class SearchServiceTest method testURIChildSearch.

/**
 * Test we find EE tagged with a child term that matches the given uri.
 */
@Test
public void testURIChildSearch() {
    try {
        this.setup();
    } catch (Exception e) {
        e.printStackTrace();
    }
    SearchSettings settings = SearchSettings.Factory.newInstance();
    // OrganComponent of Neuraxis; superclass of
    settings.setQuery("http://purl.obolibrary.org/obo/FMA_83153");
    // 'spinal cord'.
    settings.setSearchExperiments(true);
    Map<Class<?>, List<SearchResult>> found = this.searchService.search(settings);
    assertTrue(!found.isEmpty());
    for (SearchResult sr : found.get(ExpressionExperiment.class)) {
        if (sr.getResultObject().equals(ee)) {
            this.tearDown();
            return;
        }
    }
    this.tearDown();
    fail("Didn't get expected result from search");
}
Also used : SearchSettings(ubic.gemma.model.common.search.SearchSettings) Test(org.junit.Test) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest)

Example 15 with SearchSettings

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

the class SearchServiceTest method testSearchByBibRefIdProblemsB.

@Test
public void testSearchByBibRefIdProblemsB() {
    try {
        this.setup();
    } catch (Exception e) {
        e.printStackTrace();
    }
    PubMedXMLFetcher fetcher = new PubMedXMLFetcher();
    BibliographicReference bibref = fetcher.retrieveByHTTP(22780917);
    bibref = (BibliographicReference) persisterHelper.persist(bibref);
    assertTrue(bibref.getAbstractText().contains("d to chromosome 22q12. Our results confirm chromosome 22q12 as the solitary locus for FFEVF"));
    IndexerTaskCommand c = new IndexerTaskCommand();
    c.setIndexBibRef(true);
    indexerTask.setTaskCommand(c);
    indexerTask.execute();
    SearchSettings settings = SearchSettings.Factory.newInstance();
    settings.noSearches();
    settings.setQuery("confirm chromosome 22q12");
    settings.setSearchBibrefs(true);
    Map<Class<?>, List<SearchResult>> found = this.searchService.search(settings);
    assertTrue(!found.isEmpty());
    for (SearchResult sr : found.get(BibliographicReference.class)) {
        if (sr.getResultObject().equals(bibref)) {
            this.tearDown();
            return;
        }
    }
    this.tearDown();
    fail("Didn't get expected result from search");
}
Also used : IndexerTaskCommand(ubic.gemma.core.tasks.maintenance.IndexerTaskCommand) SearchSettings(ubic.gemma.model.common.search.SearchSettings) PubMedXMLFetcher(ubic.gemma.core.loader.entrez.pubmed.PubMedXMLFetcher) BibliographicReference(ubic.gemma.model.common.description.BibliographicReference) Test(org.junit.Test) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest)

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