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;
}
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");
}
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);
}
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");
}
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");
}
Aggregations