use of ubic.gemma.core.search.SearchResultDisplayObject in project Gemma by PavlidisLab.
the class GeneSearchServiceImpl method addEntryForAllResults.
/**
* Get a list of SearchResultDisplayObjects that summarise all the results found (one per taxon), so at front end
* user can "select all"
*
* @param query query
* @param genes genes
* @param geneSets gene sets
* @param phenotypeSrDos phenotype display objects
* @param srDos display objects
* @return list of search result display objects
*/
private List<SearchResultDisplayObject> addEntryForAllResults(String query, Collection<SearchResultDisplayObject> genes, Collection<SearchResultDisplayObject> geneSets, List<SearchResultDisplayObject> srDos, List<SearchResultDisplayObject> phenotypeSrDos) {
List<SearchResultDisplayObject> summaryResultEntries = new ArrayList<>();
// if >1 result, add a group whose members are all genes returned from search
if ((genes.size() + geneSets.size() + srDos.size()) > 1) {
Map<Long, Set<Long>> geneIdsByTaxonId = new HashMap<>();
// add every individual gene to the set
for (SearchResultDisplayObject srDo : genes) {
if (!geneIdsByTaxonId.containsKey(srDo.getTaxonId())) {
geneIdsByTaxonId.put(srDo.getTaxonId(), new HashSet<Long>());
}
Long id = (srDo.getResultValueObject() instanceof GeneValueObject) ? ((GeneValueObject) srDo.getResultValueObject()).getId() : new Long(-1);
if (id != -1) {
geneIdsByTaxonId.get(srDo.getTaxonId()).add(id);
}
}
// if there's a group, get the number of members
this.updateGeneIdsByTaxonId(geneSets, geneIdsByTaxonId);
this.updateGeneIdsByTaxonId(srDos, geneIdsByTaxonId);
this.updateGeneIdsByTaxonId(phenotypeSrDos, geneIdsByTaxonId);
// make an entry for each taxon
Long taxonId;
Taxon taxon;
for (Map.Entry<Long, Set<Long>> entry : geneIdsByTaxonId.entrySet()) {
taxonId = entry.getKey();
assert taxonId != null;
taxon = taxonService.load(taxonId);
// don't make groups for 1 gene
if (taxon != null && entry.getValue().size() > 1) {
FreeTextGeneResultsValueObject byTaxFtVo = new FreeTextGeneResultsValueObject("All " + taxon.getCommonName() + " results for '" + query + "'", "All " + taxon.getCommonName() + " genes found for your query", taxon.getId(), taxon.getCommonName(), entry.getValue(), query);
summaryResultEntries.add(new SearchResultDisplayObject(byTaxFtVo));
}
}
}
return summaryResultEntries;
}
use of ubic.gemma.core.search.SearchResultDisplayObject in project Gemma by PavlidisLab.
the class GeneSearchServiceImpl method getGOGroupResults.
/**
* updates goSets & srDos with GO results
*
* @param query query
* @param taxon taxon
* @return list of search result display objects
*/
private List<SearchResultDisplayObject> getGOGroupResults(String query, Taxon taxon) {
StopWatch timer = new StopWatch();
timer.start();
List<SearchResultDisplayObject> srDos = new ArrayList<>();
if (taxon != null) {
if (query.toUpperCase().startsWith("GO")) {
GeneSearchServiceImpl.log.debug("Getting results from geneSetSearch.findByGoId for GO prefixed query: " + query);
GeneSet goSet = geneSetSearch.findByGoId(query, taxon);
if (goSet != null && goSet.getMembers() != null && goSet.getMembers().size() > 0) {
SearchResultDisplayObject sdo = this.makeGoGroupSearchResult(goSet, query, query, taxon);
srDos.add(sdo);
}
} else {
GeneSearchServiceImpl.log.debug("Getting results from geneSetSearch.findByGoTermName for " + query);
for (GeneSet geneSet : geneSetSearch.findByGoTermName(query, taxon, GeneSearchServiceImpl.MAX_GO_TERMS_TO_PROCESS, GeneSearchServiceImpl.MAX_GO_GROUP_SIZE)) {
// (should probably do this check elsewhere in case it speeds things up)
if (geneSet.getMembers() != null && geneSet.getMembers().size() != 0) {
SearchResultDisplayObject sdo = this.makeGoGroupSearchResult(geneSet, null, query, taxon);
srDos.add(sdo);
}
}
}
} else {
// taxon is null, search without taxon as a constraint and bag up the results based on taxon
GeneSearchServiceImpl.log.debug("getting results from geneSetSearch.findByGoId for GO prefixed query: " + query + " with null taxon");
if (query.toUpperCase().startsWith("GO")) {
GeneSet goSet = geneSetSearch.findByGoId(query, null);
if (goSet == null) {
return srDos;
}
// this gene set has genes from all the different taxons, organize them
Collection<GeneSet> taxonSpecificSets = this.organizeMultiTaxaSetIntoTaxonSpecificSets(goSet);
for (GeneSet taxonGeneSet : taxonSpecificSets) {
if (taxonGeneSet != null && taxonGeneSet.getMembers() != null && taxonGeneSet.getMembers().size() > 0) {
SearchResultDisplayObject sdo = this.makeGoGroupSearchResult(taxonGeneSet, query, query, taxonGeneSet.getMembers().iterator().next().getGene().getTaxon());
srDos.add(sdo);
}
}
} else {
GeneSearchServiceImpl.log.debug("getting results from geneSetSearch.findByGoTermName for " + query + " with null taxon");
for (GeneSet geneSet : geneSetSearch.findByGoTermName(query, null, GeneSearchServiceImpl.MAX_GO_TERMS_TO_PROCESS, GeneSearchServiceImpl.MAX_GO_GROUP_SIZE)) {
// geneSet will have genes from different taxons inside, organize them.
Collection<GeneSet> taxonSpecificSets = this.organizeMultiTaxaSetIntoTaxonSpecificSets(geneSet);
for (GeneSet taxonGeneSet : taxonSpecificSets) {
if (geneSet.getMembers() != null && taxonGeneSet.getMembers().size() != 0) {
SearchResultDisplayObject sdo = this.makeGoGroupSearchResult(taxonGeneSet, null, query, taxonGeneSet.getMembers().iterator().next().getGene().getTaxon());
srDos.add(sdo);
}
}
}
}
}
Collections.sort(srDos);
if (timer.getTime() > 500)
GeneSearchServiceImpl.log.info("GO search: " + srDos.size() + " results in " + timer.getTime() + "ms");
return srDos;
}
use of ubic.gemma.core.search.SearchResultDisplayObject in project Gemma by PavlidisLab.
the class GeneSearchServiceImpl method getPhenotypeAssociationSearchResults.
/**
* updates goSets & srDos with GO results
*
* @param query query
* @param taxon taxon
* @return list of search result display objects
*/
private List<SearchResultDisplayObject> getPhenotypeAssociationSearchResults(String query, Taxon taxon) {
List<SearchResultDisplayObject> phenotypeSrDos = new ArrayList<>();
// if taxon==null then it grabs results for all taxons
Collection<GeneSetValueObject> geneSets = geneSetSearch.findByPhenotypeName(query, taxon);
for (GeneSetValueObject geneSet : geneSets) {
// (should probably do this check elsewhere in case it speeds things up)
if (geneSet.getGeneIds() != null && geneSet.getGeneIds().size() != 0) {
SearchResultDisplayObject sdo = this.makePhenotypeAssociationGroupSearchResult(geneSet, query, taxon);
phenotypeSrDos.add(sdo);
// phenotypeSets.add( geneSet );
}
}
Collections.sort(phenotypeSrDos);
return phenotypeSrDos;
}
use of ubic.gemma.core.search.SearchResultDisplayObject in project Gemma by PavlidisLab.
the class GeneSearchServiceImpl method setUserOwnedForGeneSets.
private void setUserOwnedForGeneSets(Collection<SearchResultDisplayObject> geneSets, Map<Long, Boolean> isSetOwnedByUser) {
if (SecurityUtil.isUserLoggedIn()) {
for (SearchResultDisplayObject srDo : geneSets) {
Long id = (srDo.getResultValueObject() instanceof DatabaseBackedGeneSetValueObject) ? ((GeneSetValueObject) srDo.getResultValueObject()).getId() : new Long(-1);
srDo.setUserOwned(isSetOwnedByUser.get(id));
}
}
}
use of ubic.gemma.core.search.SearchResultDisplayObject in project Gemma by PavlidisLab.
the class ExpressionExperimentSearchServiceImpl method getAllTaxonExperimentGroup.
@Override
public List<SearchResultDisplayObject> getAllTaxonExperimentGroup(Long taxonId) {
List<SearchResultDisplayObject> setResults = new LinkedList<>();
Taxon taxon = taxonService.load(taxonId);
Collection<ExpressionExperimentSet> sets = expressionExperimentSetService.findByName("Master set for " + taxon.getCommonName().toLowerCase());
SearchResultDisplayObject newSRDO;
for (ExpressionExperimentSet set : sets) {
expressionExperimentSetService.thaw(set);
if (set.getTaxon().getId().equals(taxonId)) {
ExpressionExperimentSetValueObject eevo = expressionExperimentSetService.loadValueObject(set);
newSRDO = new SearchResultDisplayObject(eevo);
newSRDO.setUserOwned(securityService.isPrivate(set));
((ExpressionExperimentSetValueObject) newSRDO.getResultValueObject()).setIsPublic(securityService.isPublic(set));
setResults.add(newSRDO);
}
}
Collections.sort(setResults);
return setResults;
}
Aggregations