use of org.apache.commons.lang3.time.StopWatch in project Gemma by PavlidisLab.
the class DEDVController method getDEDVForVisualization.
/**
* AJAX exposed method
*/
public VisualizationValueObject[] getDEDVForVisualization(Collection<Long> eeIds, Collection<Long> geneIds) {
StopWatch watch = new StopWatch();
watch.start();
Collection<ExpressionExperiment> ees = expressionExperimentService.load(eeIds);
if (ees == null || ees.isEmpty())
return null;
Collection<DoubleVectorValueObject> dedvs;
if (geneIds == null || geneIds.isEmpty()) {
dedvs = processedExpressionDataVectorService.getProcessedDataArrays(ees.iterator().next(), SAMPLE_SIZE);
} else {
if (geneIds.size() > MAX_RESULTS_TO_RETURN) {
log.warn(geneIds.size() + " genes for visualization. Too many. Only using first " + MAX_RESULTS_TO_RETURN + " genes. ");
List<Long> reducedGeneIds = new ArrayList<>(geneIds);
geneIds = reducedGeneIds.subList(0, MAX_RESULTS_TO_RETURN);
}
dedvs = processedExpressionDataVectorService.getProcessedDataArrays(ees, geneIds);
}
if (dedvs.isEmpty()) {
return null;
}
Long time = watch.getTime();
watch.reset();
watch.start();
if (time > 100) {
log.info("Retrieved " + dedvs.size() + " DEDVs for " + eeIds.size() + " EEs" + (geneIds == null ? " sample" : " for " + geneIds.size() + " genes ") + " in " + time + " ms (times <100ms not reported).");
}
Map<Long, LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>>> layouts = experimentalDesignVisualizationService.sortVectorDataByDesign(dedvs);
time = watch.getTime();
watch.reset();
watch.start();
if (time > 100) {
log.info("Ran sortVectorDataByDesign on " + dedvs.size() + " DEDVs for " + eeIds.size() + " EEs" + " in " + time + " ms (times <100ms not reported).");
}
watch.stop();
time = watch.getTime();
if (time > 100) {
log.info("Ran sortLayoutSamplesByFactor on " + layouts.size() + " layouts" + " in " + time + " ms (times <100ms not reported).");
}
return makeVisCollection(dedvs, geneIds, null, layouts);
}
use of org.apache.commons.lang3.time.StopWatch in project Gemma by PavlidisLab.
the class DEDVController method makeDiffVisCollection.
/**
* Takes the DEDVs and put them in point objects and normalize the values. returns a map of eeid to visValueObject.
* Currently removes multiple hits for same gene. Tries to pick best DEDV. Organizes the experiments from lowest to
* higest p-value
*
* @param validatedProbes (bad name)
*/
private VisualizationValueObject[] makeDiffVisCollection(Collection<DoubleVectorValueObject> dedvs, List<Long> genes, Map<Long, Collection<DifferentialExpressionValueObject>> validatedProbes, Map<Long, LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>>> layouts) {
StopWatch watch = new StopWatch();
watch.start();
Map<Long, Collection<DoubleVectorValueObject>> vvoMap = new HashMap<>();
Map<Long, ExpressionExperimentValueObject> eeMap = new HashMap<>();
// Organize by expression experiment
for (DoubleVectorValueObject dvvo : dedvs) {
ExpressionExperimentValueObject ee = dvvo.getExpressionExperiment();
eeMap.put(ee.getId(), ee);
if (!vvoMap.containsKey(ee.getId())) {
vvoMap.put(ee.getId(), new HashSet<DoubleVectorValueObject>());
}
vvoMap.get(ee.getId()).add(dvvo);
}
class EE2PValue implements Comparable<EE2PValue> {
Long EEId;
double pValue;
public EE2PValue() {
super();
}
public EE2PValue(Long eeid, double pValue) {
this();
this.EEId = eeid;
this.pValue = pValue;
}
@Override
public int compareTo(EE2PValue o) {
if (this.pValue > o.getPValue())
return 1;
else if (this.pValue > o.getPValue())
return -1;
else
return 0;
}
public Long getEEId() {
return EEId;
}
public double getPValue() {
return pValue;
}
}
List<EE2PValue> sortedEE = new ArrayList<>();
// Need to sort the expression experiments by lowest p-value
for (Long eeId : vvoMap.keySet()) {
Collection<DifferentialExpressionValueObject> devos = validatedProbes.get(eeId);
double minP = 1;
if (devos != null && !devos.isEmpty()) {
for (DifferentialExpressionValueObject devo : devos) {
if (minP > devo.getP()) {
minP = devo.getP();
}
}
}
sortedEE.add(new EE2PValue(eeId, minP));
}
Collections.sort(sortedEE);
VisualizationValueObject[] result = new VisualizationValueObject[vvoMap.keySet().size()];
List<GeneValueObject> geneValueObjects = getGeneValueObjectList(genes);
// Create collection of visualizationValueObject for flotr on js side
int i = 0;
for (EE2PValue ee2P : sortedEE) {
VisualizationValueObject vvo = new VisualizationValueObject(vvoMap.get(ee2P.getEEId()), geneValueObjects, ee2P.getPValue(), validatedProbes.get(ee2P.getEEId()));
getSampleNames(vvoMap.get(ee2P.getEEId()), vvo, layouts);
if (layouts != null && !layouts.isEmpty() && layouts.containsKey(ee2P.getEEId())) {
LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>> layout = layouts.get(ee2P.getEEId());
this.prepareFactorsForFrontEndDisplay(vvo, layout);
}
if (layouts != null) {
ExpressionExperimentValueObject ee = eeMap.get(ee2P.getEEId());
log.debug("setup experimental design layout profiles for " + ee);
vvo.setUpFactorProfiles(layouts.get(ee.getId()));
}
result[i] = vvo;
i++;
}
Long time = watch.getTime();
if (time > 1000) {
log.info("Created vis value objects in: " + time);
}
return result;
}
use of org.apache.commons.lang3.time.StopWatch in project Gemma by PavlidisLab.
the class DEDVController method handleRequestInternal.
/**
* Handle case of text export of the results.
*/
@RequestMapping("/downloadDEDV.html")
protected ModelAndView handleRequestInternal(HttpServletRequest request) {
StopWatch watch = new StopWatch();
watch.start();
// might not be any
Collection<Long> geneIds = ControllerUtils.extractIds(request.getParameter("g"));
// might not be there
Collection<Long> eeIds = ControllerUtils.extractIds(request.getParameter("ee"));
ModelAndView mav = new ModelAndView(new TextView());
if (eeIds == null || eeIds.isEmpty()) {
mav.addObject("text", "Input empty for finding DEDVs: " + geneIds + " and " + eeIds);
return mav;
}
String threshSt = request.getParameter("thresh");
String resultSetIdSt = request.getParameter("rs");
Double thresh = 100.0;
if (StringUtils.isNotBlank(threshSt)) {
try {
thresh = Double.parseDouble(threshSt);
} catch (NumberFormatException e) {
throw new RuntimeException("Threshold was not a valid value: " + threshSt);
}
}
Map<ExpressionExperimentValueObject, Map<Long, Collection<DoubleVectorValueObject>>> result;
if (request.getParameter("pca") != null) {
int component = Integer.parseInt(request.getParameter("component"));
Long eeId = eeIds.iterator().next();
Map<ProbeLoading, DoubleVectorValueObject> topLoadedVectors = this.svdService.getTopLoadedVectors(eeId, component, thresh.intValue());
if (topLoadedVectors == null)
return null;
mav.addObject("text", format4File(topLoadedVectors.values()));
return mav;
}
/*
* The following should be set if we're viewing diff. ex results.
*/
Long resultSetId = null;
if (StringUtils.isNumeric(resultSetIdSt)) {
resultSetId = Long.parseLong(resultSetIdSt);
}
if (resultSetId != null) {
/*
* Diff ex case.
*/
Long eeId = eeIds.iterator().next();
Collection<DoubleVectorValueObject> diffExVectors = processedExpressionDataVectorService.getDiffExVectors(resultSetId, thresh, MAX_RESULTS_TO_RETURN);
if (diffExVectors == null || diffExVectors.isEmpty()) {
mav.addObject("text", "No results");
return mav;
}
/*
* Organize the vectors in the same way expected by the ee+gene type of request.
*/
ExpressionExperimentValueObject ee = expressionExperimentService.loadValueObject(expressionExperimentService.load(eeId));
result = new HashMap<>();
Map<Long, Collection<DoubleVectorValueObject>> gmap = new HashMap<>();
for (DoubleVectorValueObject dv : diffExVectors) {
for (Long g : dv.getGenes()) {
if (!gmap.containsKey(g)) {
gmap.put(g, new HashSet<DoubleVectorValueObject>());
}
gmap.get(g).add(dv);
}
}
result.put(ee, gmap);
} else {
// Generic listing.
result = getDEDV(eeIds, geneIds);
}
if (result == null || result.isEmpty()) {
mav.addObject("text", "No results");
return mav;
}
mav.addObject("text", format4File(result));
watch.stop();
Long time = watch.getTime();
if (time > 100) {
log.info("Retrieved and Formated" + result.keySet().size() + " DEDVs for eeIDs: " + eeIds + " and GeneIds: " + geneIds + " in : " + time + " ms.");
}
return mav;
}
use of org.apache.commons.lang3.time.StopWatch in project Gemma by PavlidisLab.
the class DEDVController method getDEDVForDiffExVisualization.
/**
* AJAX exposed method - for ProbeLevelDiffExGrid, VisualizationDifferentialWindow,
* DifferentialExpressionAnalysesSummaryTree
*
* @param eeIds FIXME accommodate ExpressionExperimentSubSets. Currently we pass in the "source experiment" so we
* don't get the slice.
* @param geneIds (could be just one)
* @param threshold for 'significance'
* @param factorMap Collection of DiffExpressionSelectedFactorCommand showing which factors to use.
*/
public VisualizationValueObject[] getDEDVForDiffExVisualization(Collection<Long> eeIds, Collection<Long> geneIds, Double threshold, Collection<DiffExpressionSelectedFactorCommand> factorMap) {
if (eeIds.isEmpty() || geneIds.isEmpty())
return null;
StopWatch watch = new StopWatch();
watch.start();
Collection<? extends BioAssaySet> ees = expressionExperimentService.load(eeIds);
if (ees == null || ees.isEmpty())
return null;
Collection<Gene> genes = geneService.load(geneIds);
if (genes == null || genes.isEmpty())
return null;
Collection<DoubleVectorValueObject> dedvs = processedExpressionDataVectorService.getProcessedDataArrays(ees, geneIds);
watch.stop();
Long time = watch.getTime();
log.info("Retrieved " + dedvs.size() + " DEDVs for " + eeIds.size() + " EEs and " + geneIds.size() + " genes in " + time + " ms.");
watch = new StopWatch();
watch.start();
Map<Long, LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>>> layouts;
layouts = experimentalDesignVisualizationService.sortVectorDataByDesign(dedvs);
time = watch.getTime();
if (time > 100) {
log.info("Ran sortVectorDataByDesign on " + dedvs.size() + " DEDVs for 1 EE" + " in " + time + " ms (times <100ms not reported).");
}
// layouts = experimentalDesignVisualizationService.sortLayoutSamplesByFactor( layouts ); // required? yes, see
// GSE11859
time = watch.getTime();
if (time > 100) {
log.info("Ran sortLayoutSamplesByFactor on " + layouts.size() + " layouts" + " in " + time + " ms (times <100ms not reported).");
}
watch = new StopWatch();
watch.start();
Map<Long, Collection<DifferentialExpressionValueObject>> validatedProbes = getProbeDiffExValidation(genes, threshold, factorMap);
watch.stop();
time = watch.getTime();
log.info("Retrieved " + validatedProbes.size() + " valid probes in " + time + " ms.");
return makeDiffVisCollection(dedvs, new ArrayList<>(geneIds), validatedProbes, layouts);
}
use of org.apache.commons.lang3.time.StopWatch in project Gemma by PavlidisLab.
the class DEDVController method getProbeLinkValidation.
/**
* Identify which probes were 'responsible' for the coexpression links.
* FIXME change this to actually compute the correlations.
*
* @return map of EEID -> collection ProbeIDs which underlie the stored coexpression links.
*/
private Map<Long, Collection<Long>> getProbeLinkValidation(Collection<ExpressionExperiment> ees, Gene queryGene, Gene coexpressedGene, Collection<DoubleVectorValueObject> dedvs) {
StopWatch watch = new StopWatch();
watch.start();
Map<Long, Collection<Long>> coexpressedEE2ProbeIds = new HashMap<>();
Map<Long, Collection<Long>> queryEE2ProbeIds = new HashMap<>();
/*
* Get the probes for the vectors, organize by ee.
*/
for (DoubleVectorValueObject dedv : dedvs) {
ExpressionExperimentValueObject ee = dedv.getExpressionExperiment();
if (dedv.getGenes().contains(queryGene.getId())) {
if (!queryEE2ProbeIds.containsKey(ee.getId())) {
queryEE2ProbeIds.put(ee.getId(), new HashSet<Long>());
}
queryEE2ProbeIds.get(ee.getId()).add(dedv.getDesignElement().getId());
} else if (dedv.getGenes().contains(coexpressedGene.getId())) {
if (!coexpressedEE2ProbeIds.containsKey(ee.getId())) {
coexpressedEE2ProbeIds.put(ee.getId(), new HashSet<Long>());
}
coexpressedEE2ProbeIds.get(ee.getId()).add(dedv.getDesignElement().getId());
} else {
log.error("Dedv doesn't belong to coexpressed or query gene. QueryGene= " + queryGene + "CoexpressedGene= " + coexpressedGene + "DEDV " + dedv.getId() + " has genes: " + dedv.getGenes());
}
}
Map<Long, Collection<Long>> validatedProbes = new HashMap<>();
for (ExpressionExperiment ee : ees) {
Collection<Long> queryProbeIds = queryEE2ProbeIds.get(ee.getId());
Collection<Long> coexpressedProbeIds = coexpressedEE2ProbeIds.get(ee.getId());
if (queryProbeIds == null || queryProbeIds.isEmpty()) {
log.warn("Unexpectedly no probes for " + queryGene + " in " + ee);
continue;
}
if (coexpressedProbeIds == null || coexpressedProbeIds.isEmpty()) {
log.warn("Unexpectedly no probes for " + coexpressedGene + " in " + ee);
}
/*
* Note: this does a probe-level query FIXME if we don't store data at probe-level we can't do this.
*/
// Collection<Long> probesInLinks = this.geneCoexpressionService.getCoexpressedProbes( queryProbeIds,
// coexpressedProbeIds, ee, queryGene.getTaxon().getCommonName() );
// if ( probesInLinks.isEmpty() ) {
// log.warn( "Unexpectedly no probes for link between " + queryGene + " -and- " + coexpressedGene + " in "
// + ee );
// }
//
// validatedProbes.put( ee.getId(), probesInLinks );
// FIXME FIXME
}
watch.stop();
Long time = watch.getTime();
if (time > 1000) {
log.info("Validation of probes for " + ees.size() + " experiments in " + time + "ms.");
}
return validatedProbes;
}
Aggregations