use of org.apache.commons.lang3.StringUtils.EMPTY in project Gemma by PavlidisLab.
the class GeneSearchServiceImpl method getGOGroupGenes.
@Override
public Collection<Gene> getGOGroupGenes(String goQuery, Taxon taxon) {
StopWatch timer = new StopWatch();
timer.start();
Collection<Taxon> taxaForPhenotypeAssoc = new ArrayList<>();
Collection<Gene> genes = new ArrayList<>();
// if taxon isn't set, get go groups for each possible taxon
if (taxon == null) {
taxaForPhenotypeAssoc.addAll(taxonService.loadAllTaxaWithGenes());
} else {
taxaForPhenotypeAssoc.add(taxon);
}
for (Taxon taxonForPA : taxaForPhenotypeAssoc) {
for (GeneSet geneSet : geneSetSearch.findByGoTermName(goQuery, taxonForPA, GeneSearchServiceImpl.MAX_GO_TERMS_TO_PROCESS, GeneSearchServiceImpl.MAX_GO_GROUP_SIZE)) {
// don't bother adding empty groups
if (geneSet.getMembers() != null && geneSet.getMembers().size() != 0) {
for (GeneSetMember geneMember : geneSet.getMembers()) {
genes.add(geneMember.getGene());
}
}
}
}
GeneSearchServiceImpl.log.info("GO search: " + timer.getTime() + "ms");
return genes;
}
use of org.apache.commons.lang3.StringUtils.EMPTY in project Gemma by PavlidisLab.
the class ExperimentalDesignVisualizationServiceImpl method sortVectorDataByDesign.
@Override
public Map<Long, LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>>> sortVectorDataByDesign(Collection<DoubleVectorValueObject> dedVs) {
if (dedVs == null) {
return new HashMap<>(0);
}
Map<Long, LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>>> returnedLayouts = new HashMap<>(dedVs.size());
StopWatch timer = new StopWatch();
timer.start();
/*
* This is shared across experiments that might show up in the dedVs; this should be okay...saves computation.
* This is the only slow part.
*/
this.prepare(dedVs);
/*
* This loop is not a performance issue.
*/
Map<DoubleVectorValueObject, List<BioAssayValueObject>> newOrderingsForBioAssayDimensions = new HashMap<>();
for (DoubleVectorValueObject vec : dedVs) {
if (vec.isReorganized()) {
continue;
}
assert !vec.getBioAssays().isEmpty();
LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>> layout = null;
if (cachedLayouts.containsKey(vec.getExpressionExperiment().getId())) {
layout = cachedLayouts.get(vec.getExpressionExperiment().getId());
} else if (vec.getExpressionExperiment().getClass().isInstance(ExpressionExperimentSubsetValueObject.class)) {
// subset.
layout = cachedLayouts.get(((ExpressionExperimentSubsetValueObject) vec.getExpressionExperiment()).getSourceExperiment());
}
if (layout == null || layout.isEmpty()) {
log.error("Did not find cached layout for " + vec.getId());
continue;
}
List<BioAssayValueObject> newOrdering = new ArrayList<>(layout.keySet());
newOrdering.retainAll(vec.getBioAssays());
/*
* This can happen if the vectors are out of whack with the bioassays - e.g. two platforms were used but
* merging is not done. See bug 3775. Skipping the ordering is not the right thing to do.
*/
if (newOrdering.isEmpty()) {
boolean allNaN = this.allNaN(vec);
if (allNaN) {
// reordering will have no effect.
continue;
}
/*
* Add to the layout.
*/
layout = this.extendLayout(vec, vec.getExpressionExperiment().getId());
newOrdering = new ArrayList<>(layout.keySet());
newOrdering.retainAll(vec.getBioAssays());
assert !newOrdering.isEmpty();
}
newOrderingsForBioAssayDimensions.put(vec, newOrdering);
Map<BioAssayValueObject, Integer> ordering = this.getOrdering(newOrdering);
Long eeId;
// might be subset id.
eeId = vec.getExpressionExperiment().getId();
if (!returnedLayouts.containsKey(eeId)) {
if (vec.isSliced()) {
LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>> trimmedLayout = new LinkedHashMap<>();
for (BioAssayValueObject baVo : newOrdering) {
trimmedLayout.put(baVo, layout.get(baVo));
}
returnedLayouts.put(eeId, trimmedLayout);
} else {
returnedLayouts.put(eeId, layout);
}
}
/*
* Might be a faster way.
*/
double[] data = vec.getData();
double[] dol = ArrayUtils.clone(data);
// assert ordering.size() == data.length : "got " + ordering.size() + " expected " + data.length;
List<BioAssayValueObject> oldOrdering = vec.getBioAssayDimension().getBioAssays();
int j = 0;
if (log.isTraceEnabled())
log.trace("Old order: " + StringUtils.join(ArrayUtils.toObject(data), ","));
for (BioAssayValueObject ba : oldOrdering) {
if (ordering.get(ba) == null) {
assert Double.isNaN(dol[j]);
j++;
continue;
}
assert ordering.containsKey(ba);
assert ordering.get(ba) != null;
Integer targetIndex = ordering.get(ba);
data[targetIndex] = dol[j++];
}
if (log.isTraceEnabled())
log.trace("New order: " + StringUtils.join(ArrayUtils.toObject(data), ","));
vec.setReorganized(true);
}
for (DoubleVectorValueObject vec : dedVs) {
if (vec.getBioAssayDimension().isReordered())
continue;
List<BioAssayValueObject> newOrdering = newOrderingsForBioAssayDimensions.get(vec);
if (newOrdering == null)
// data was empty, etc.
continue;
vec.getBioAssayDimension().reorder(newOrdering);
}
if (timer.getTime() > 1500) {
log.info("Sort vectors by design: " + timer.getTime() + "ms");
}
return returnedLayouts;
}
use of org.apache.commons.lang3.StringUtils.EMPTY in project Gemma by PavlidisLab.
the class CoexpressionDaoImpl method getCoexpressionFromDbViaGenes2.
/**
* Alternative method: query twice, once to get the coexpression basics and then again to get the support details,
* instead of using a join.
*
* @param populateTestedInDetails populate tested in details
* @param stringency stringency
* @param geneIds gene IDs
* @param t taxon
*/
private Map<Long, List<CoexpressionValueObject>> getCoexpressionFromDbViaGenes2(Collection<Long> geneIds, Taxon t, int stringency, boolean populateTestedInDetails) {
StopWatch timer = new StopWatch();
timer.start();
List<Object[]> q1results = this.getRawCoexpressionFromDbViaGenes(geneIds, t, stringency);
CoexpressionDaoImpl.log.debug(q1results.size() + " raw coexpression results for " + geneIds.size() + " genes at support>=" + stringency + " " + timer.getTime() + "ms");
if (q1results.isEmpty()) {
return new HashMap<>();
}
List<Object[]> supportDetails = new ArrayList<>();
/*
* Because we are not trimming the results at all here, this can be a lot of data to iterate over, even at
* high stringencies. For example, for 20 genes at a stringency of 5, because the query above does not
* constrain to data sets, there can be >500 per gene, or >100k links in total. Fetching the support details
* here is rather wasteful if we are not retaining the results, but we don't know that until we know which
* data sets are supporting.
*/
BatchIterator<Object[]> batches = BatchIterator.batches(q1results, CoexpressionDaoImpl.BATCH_SIZE);
int n = 1;
for (Collection<Object[]> batch : batches) {
StopWatch timer2 = new StopWatch();
timer2.start();
List<Long> supportDetailsIds = new ArrayList<>();
for (Object[] oa : batch) {
Long supportDetailsId = ((BigInteger) oa[5]).longValue();
supportDetailsIds.add(supportDetailsId);
}
// Note: should never be empty
String sqlQuery2 = "select ID,BYTES from " + CoexpressionQueryUtils.getSupportDetailsTableName(t) + " where ID in (:ids)";
SQLQuery query2 = this.getSessionFactory().getCurrentSession().createSQLQuery(sqlQuery2);
query2.setParameterList("ids", supportDetailsIds.toArray());
supportDetails.addAll(query2.list());
if (timer2.getTime() > 1000) {
CoexpressionDaoImpl.log.debug("Fetch batch " + n + " of support details: " + timer2.getTime() + "ms");
}
n++;
}
CoexpressionDaoImpl.log.debug("Fetched details for " + supportDetails.size() + " coexpressions, " + n + " batches");
if (timer.getTime() > 5000) {
CoexpressionDaoImpl.log.info("Coexpression query: " + geneIds.size() + " genes took " + timer.getTime() + "ms: " + q1results.size() + " results");
}
timer.reset();
timer.start();
// it might be better to do this in the loop above, incrementally per batch.
Map<Long, List<CoexpressionValueObject>> results = this.convertToValueObjects(q1results, supportDetails, geneIds);
if (timer.getTime() > 100) {
CoexpressionDaoImpl.log.info("Convert to value objects " + q1results.size() + " results: " + timer.getTime() + "ms");
}
timer.reset();
timer.start();
for (Long g : results.keySet()) {
List<CoexpressionValueObject> gc = results.get(g);
Collections.sort(gc);
if (populateTestedInDetails) {
this.populateTestedInDetails(gc);
}
}
if (timer.getTime() > 100) {
CoexpressionDaoImpl.log.info("Filter, sort and finish " + q1results.size() + " results: " + timer.getTime() + "ms");
}
return results;
}
use of org.apache.commons.lang3.StringUtils.EMPTY in project molgenis by molgenis.
the class SortaController method retrieveSortaJobResults.
@PostMapping("/match/retrieve")
@ResponseBody
public EntityCollectionResponse retrieveSortaJobResults(@RequestBody SortaServiceRequest sortaServiceRequest) {
List<Map<String, Object>> entityMaps = new ArrayList<>();
String sortaJobExecutionId = sortaServiceRequest.getSortaJobExecutionId();
String filterQuery = sortaServiceRequest.getFilterQuery();
String ontologyIri = sortaServiceRequest.getOntologyIri();
EntityPager entityPager = sortaServiceRequest.getEntityPager();
SortaJobExecution sortaJobExecution = findSortaJobExecution(sortaJobExecutionId);
String resultEntityName = sortaJobExecution.getResultEntityName();
double threshold = sortaJobExecution.getThreshold();
boolean isMatched = sortaServiceRequest.isMatched();
QueryRule queryRuleInputEntities = new QueryRule(Arrays.asList(new QueryRule(VALIDATED, EQUALS, isMatched), new QueryRule(isMatched ? OR : AND), new QueryRule(SCORE, isMatched ? GREATER_EQUAL : LESS, threshold)));
List<QueryRule> queryRuleInputEntitiesInOneMatchingTask = singletonList(queryRuleInputEntities);
// Add filter to the query if query string is not empty
if (isNotEmpty(filterQuery)) {
Iterable<String> filteredInputTermIds = dataService.findAll(sortaJobExecution.getSourceEntityName(), new QueryImpl<>().search(filterQuery)).map(inputEntity -> inputEntity.getString(SortaServiceImpl.DEFAULT_MATCHING_IDENTIFIER)).collect(Collectors.toList());
QueryRule previousQueryRule = new QueryRule(queryRuleInputEntitiesInOneMatchingTask);
QueryRule queryRuleFilterInput = new QueryRule(MatchingTaskContentMetaData.INPUT_TERM, Operator.IN, filteredInputTermIds);
queryRuleInputEntitiesInOneMatchingTask = Arrays.asList(previousQueryRule, new QueryRule(Operator.AND), queryRuleFilterInput);
}
Query<Entity> query = new QueryImpl<>(queryRuleInputEntitiesInOneMatchingTask);
long count = dataService.count(resultEntityName, query);
int start = entityPager.getStart();
int num = entityPager.getNum();
Stream<Entity> findAll = dataService.findAll(sortaJobExecution.getResultEntityName(), query.offset(start).pageSize(num).sort(new Sort().on(VALIDATED, DESC).on(SCORE, DESC)));
findAll.forEach(mappingEntity -> {
Map<String, Object> outputEntity = new HashMap<>();
outputEntity.put("inputTerm", getEntityAsMap(mappingEntity.getEntity(INPUT_TERM)));
outputEntity.put("matchedTerm", getEntityAsMap(mappingEntity));
Object matchedTerm = mappingEntity.get(MATCHED_TERM);
if (matchedTerm != null) {
outputEntity.put("ontologyTerm", SortaServiceUtil.getEntityAsMap(sortaService.getOntologyTermEntity(matchedTerm.toString(), ontologyIri)));
}
entityMaps.add(outputEntity);
});
EntityPager pager = new EntityPager(start, num, count, null);
return new EntityCollectionResponse(pager, entityMaps, "/match/retrieve", ontologyTermMetaData, permissionService, dataService);
}
use of org.apache.commons.lang3.StringUtils.EMPTY in project xwiki-platform by xwiki.
the class ExecutionContextCopier method copy.
@Override
public ExecutionContext copy(ExecutionContext originalExecutionContext) throws CloneFailedException {
try {
ExecutionContext clonedExecutionContext = this.executionContextManager.clone(originalExecutionContext);
// XWikiContext
// The above clone just creates and initializes an empty XWiki Context, so it needs special handling.
XWikiContext xwikiContext = (XWikiContext) originalExecutionContext.getProperty(XWikiContext.EXECUTIONCONTEXT_KEY);
XWikiContext clonedXWikiContext = xwikiContextCloner.copy(xwikiContext);
clonedExecutionContext.setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, clonedXWikiContext);
// VelocityContext
// Reset the VelocityContext from the EC by removing it and calling the Velocity ECInitializer which is
// normally called by the execution of the ECInitializers by ECManager.clone(). This ensures a clean new
// VC is created. It'll get filled when VelocityContextManager.getVelocityContext() is called by whatever
// code need the VC.
clonedExecutionContext.removeProperty(VelocityExecutionContextInitializer.VELOCITY_CONTEXT_ID);
this.velocityExecutionContextInitializer.initialize(clonedExecutionContext);
return clonedExecutionContext;
} catch (Exception e) {
throw new CloneFailedException(String.format("Failed to clone [%s]", originalExecutionContext), e);
}
}
Aggregations