use of ubic.gemma.model.expression.experiment.FreeTextExpressionExperimentResultsValueObject in project Gemma by PavlidisLab.
the class ExpressionExperimentSearchServiceImpl method searchExperimentsAndExperimentGroups.
@Override
public List<SearchResultDisplayObject> searchExperimentsAndExperimentGroups(String query, Long taxonId) {
List<SearchResultDisplayObject> displayResults = new LinkedList<>();
// session-bound sets (not autogen sets until handling of large searches is fixed)
if (StringUtils.isBlank(query)) {
return this.searchExperimentsAndExperimentGroupBlankQuery(taxonId);
}
Map<Class<?>, List<SearchResult>> results = this.initialSearch(query, taxonId);
List<SearchResultDisplayObject> experimentSets = this.getExpressionExperimentSetResults(results);
List<SearchResultDisplayObject> experiments = this.getExpressionExperimentResults(results);
if (experimentSets.isEmpty() && experiments.isEmpty()) {
return displayResults;
}
/*
* ALL RESULTS BY TAXON GROUPS
*/
// if >1 result, add a group whose members are all experiments returned from search
Map<Long, Set<Long>> eeIdsByTaxonId = new HashMap<>();
// add every individual experiment to the set, grouped by taxon and also altogether.
for (SearchResultDisplayObject srdo : experiments) {
// group by the Parent Taxon, for things like salmonid - see bug 3286
Long taxId;
if (srdo.getParentTaxonId() != null) {
taxId = srdo.getParentTaxonId();
} else {
taxId = srdo.getTaxonId();
}
if (!eeIdsByTaxonId.containsKey(taxId)) {
eeIdsByTaxonId.put(taxId, new HashSet<Long>());
}
ExpressionExperimentValueObject eevo = (ExpressionExperimentValueObject) srdo.getResultValueObject();
eeIdsByTaxonId.get(taxId).add(eevo.getId());
}
// for each group
for (SearchResultDisplayObject eesSRO : experimentSets) {
ExpressionExperimentSetValueObject set = (ExpressionExperimentSetValueObject) eesSRO.getResultValueObject();
/*
* This is security filtered.
*/
Collection<Long> ids = EntityUtils.getIds(expressionExperimentSetService.getExperimentValueObjectsInSet(set.getId()));
// to account for security filtering.
set.setSize(ids.size());
if (!eeIdsByTaxonId.containsKey(set.getTaxonId())) {
eeIdsByTaxonId.put(set.getTaxonId(), new HashSet<Long>());
}
eeIdsByTaxonId.get(set.getTaxonId()).addAll(ids);
}
// make an entry for each taxon
Long taxonId2;
for (Map.Entry<Long, Set<Long>> entry : eeIdsByTaxonId.entrySet()) {
taxonId2 = entry.getKey();
Taxon taxon = taxonService.load(taxonId2);
if (taxon != null && entry.getValue().size() > 0) {
FreeTextExpressionExperimentResultsValueObject ftvo = new FreeTextExpressionExperimentResultsValueObject("All " + taxon.getCommonName() + " results for '" + query + "'", "All " + taxon.getCommonName() + " experiments found for your query", taxon.getId(), taxon.getCommonName(), entry.getValue(), query);
int numWithDifferentialExpressionAnalysis = differentialExpressionAnalysisService.getExperimentsWithAnalysis(entry.getValue()).size();
assert numWithDifferentialExpressionAnalysis <= entry.getValue().size();
int numWithCoexpressionAnalysis = coexpressionAnalysisService.getExperimentsWithAnalysis(entry.getValue()).size();
ftvo.setNumWithCoexpressionAnalysis(numWithCoexpressionAnalysis);
ftvo.setNumWithDifferentialExpressionAnalysis(numWithDifferentialExpressionAnalysis);
displayResults.add(new SearchResultDisplayObject(ftvo));
}
}
displayResults.addAll(experimentSets);
displayResults.addAll(experiments);
if (displayResults.isEmpty()) {
ExpressionExperimentSearchServiceImpl.log.info("No results for search: " + query);
} else {
ExpressionExperimentSearchServiceImpl.log.info("Results for search: " + query + " size=" + displayResults.size() + " entry0: " + ((SearchResultDisplayObject) (displayResults.toArray())[0]).getName() + " valueObject:" + ((SearchResultDisplayObject) (displayResults.toArray())[0]).getResultValueObject().toString());
}
return displayResults;
}
Aggregations