use of ubic.gemma.core.search.SearchResult 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;
}
use of ubic.gemma.core.search.SearchResult 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;
}
use of ubic.gemma.core.search.SearchResult in project Gemma by PavlidisLab.
the class GeneSearchServiceImpl method retainGeneSetsOfThisTaxon.
private List<SearchResult> retainGeneSetsOfThisTaxon(Long taxonId, List<SearchResult> geneSetSearchResults, Map<Long, Boolean> isSetOwnedByUser) {
List<SearchResult> taxonCheckedSets = new ArrayList<>();
for (SearchResult sr : geneSetSearchResults) {
GeneSet gs = (GeneSet) sr.getResultObject();
GeneSetValueObject gsVo = geneSetValueObjectHelper.convertToValueObject(gs);
isSetOwnedByUser.put(gs.getId(), securityService.isOwnedByCurrentUser(gs));
if (Objects.equals(gsVo.getTaxonId(), taxonId)) {
taxonCheckedSets.add(sr);
}
}
return taxonCheckedSets;
}
use of ubic.gemma.core.search.SearchResult in project Gemma by PavlidisLab.
the class GeneServiceImpl method loadFullyPopulatedValueObject.
@Override
@Transactional(readOnly = true)
public GeneValueObject loadFullyPopulatedValueObject(Long id) {
Gene gene = this.geneDao.load(id);
if (gene == null) {
return null;
}
gene = this.geneDao.thaw(gene);
GeneValueObject gvo = GeneValueObject.convert2ValueObject(gene);
Collection<GeneAlias> aliasObjects = gene.getAliases();
Collection<String> aliasStrings = new ArrayList<>();
for (GeneAlias ga : aliasObjects) {
aliasStrings.add(ga.getAlias());
}
gvo.setAliases(aliasStrings);
if (gene.getMultifunctionality() != null) {
gvo.setMultifunctionalityRank(gene.getMultifunctionality().getRank());
}
Long compositeSequenceCount = this.getCompositeSequenceCountById(id);
gvo.setCompositeSequenceCount(compositeSequenceCount.intValue());
Integer platformCount = this.geneDao.getPlatformCountById(id);
gvo.setPlatformCount(platformCount);
Collection<GeneSet> geneSets = this.geneSetSearch.findByGene(gene);
Collection<GeneSetValueObject> gsVos = new ArrayList<>();
// noinspection CollectionAddAllCanBeReplacedWithConstructor // Constructor can't handle subclasses
gsVos.addAll(geneSetValueObjectHelper.convertToLightValueObjects(geneSets, false));
gvo.setGeneSets(gsVos);
Collection<Gene> geneHomologues = this.homologeneService.getHomologues(gene);
geneHomologues = this.thawLite(geneHomologues);
Collection<GeneValueObject> homologues = this.loadValueObjects(geneHomologues);
gvo.setHomologues(homologues);
Collection<PhenotypeAssociation> pas = gene.getPhenotypeAssociations();
Collection<CharacteristicValueObject> cVos = new HashSet<>();
for (PhenotypeAssociation pa : pas) {
cVos.addAll(CharacteristicValueObject.characteristic2CharacteristicVO(pa.getPhenotypes()));
}
gvo.setPhenotypes(cVos);
if (gvo.getNcbiId() != null) {
SearchSettingsImpl s = new SearchSettingsImpl();
s.setTermUri("http://purl.org/commons/record/ncbi_gene/" + gvo.getNcbiId());
s.noSearches();
s.setSearchExperiments(true);
Map<Class<?>, List<SearchResult>> r = searchService.search(s);
if (r.containsKey(ExpressionExperiment.class)) {
List<SearchResult> hits = r.get(ExpressionExperiment.class);
gvo.setAssociatedExperimentCount(hits.size());
}
}
GeneCoexpressionNodeDegreeValueObject nodeDegree = coexpressionService.getNodeDegree(gene);
if (nodeDegree != null) {
gvo.setNodeDegreesPos(nodeDegree.asIntArrayPos());
gvo.setNodeDegreesNeg(nodeDegree.asIntArrayNeg());
gvo.setNodeDegreePosRanks(nodeDegree.asDoubleArrayPosRanks());
gvo.setNodeDegreeNegRanks(nodeDegree.asDoubleArrayNegRanks());
}
return gvo;
}
use of ubic.gemma.core.search.SearchResult 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;
}
Aggregations