use of ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject in project Gemma by PavlidisLab.
the class ProcessedExpressionDataVectorServiceImpl method getExpressionLevels.
@Override
@Transactional(readOnly = true)
public Collection<ExperimentExpressionLevelsValueObject> getExpressionLevels(Collection<ExpressionExperiment> ees, Collection<Gene> genes, boolean keepGeneNonSpecific, String consolidateMode) {
Collection<DoubleVectorValueObject> vectors = this.getProcessedDataArrays(ees, EntityUtils.getIds(genes));
Collection<ExperimentExpressionLevelsValueObject> vos = new ArrayList<>(ees.size());
// Adapted from DEDV controller
for (ExpressionExperiment ee : ees) {
Map<Gene, List<DoubleVectorValueObject>> vectorsPerGene = new HashMap<>();
for (DoubleVectorValueObject v : vectors) {
if (!v.getExpressionExperiment().getId().equals(ee.getId())) {
continue;
}
if (v.getGenes() == null || v.getGenes().isEmpty()) {
continue;
}
for (Gene g : genes) {
if (v.getGenes().contains(g.getId())) {
if (!vectorsPerGene.containsKey(g)) {
vectorsPerGene.put(g, new LinkedList<DoubleVectorValueObject>());
}
vectorsPerGene.get(g).add(v);
}
}
}
vos.add(new ExperimentExpressionLevelsValueObject(ee.getId(), vectorsPerGene, keepGeneNonSpecific, consolidateMode));
}
return vos;
}
use of ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject in project Gemma by PavlidisLab.
the class ExperimentalDesignVisualizationServiceImpl method prepare.
/**
* Gets the bioassay dimensions for the experiments associated with the given vectors. These are cached for later
* re-use.
*/
private void prepare(Collection<DoubleVectorValueObject> dvvOs) {
if (dvvOs == null)
return;
for (DoubleVectorValueObject vec : dvvOs) {
if (vec == null) {
log.debug("DoubleVectorValueObject is null");
continue;
}
if (vec.isReorganized()) {
// wouldn't normally be the case...
continue;
}
ExpressionExperimentValueObject ee = vec.getExpressionExperiment();
/*
* Problem: we can't have two layouts for one experiment, which is actually required if there is more than
* one bioassay dimension. However, this rarely matters. See bug 3775
*/
if (cachedLayouts.containsKey(ee.getId())) {
continue;
} else if (vec.getClass().isInstance(ExpressionExperimentSubsetValueObject.class)) {
ExpressionExperimentSubsetValueObject eesvo = (ExpressionExperimentSubsetValueObject) vec.getExpressionExperiment();
if (eesvo.getSourceExperiment() != null && cachedLayouts.containsKey(eesvo.getSourceExperiment())) {
continue;
}
}
BioAssayDimensionValueObject bioAssayDimension = this.getBioAssayDimensionForVector(vec);
ExpressionExperiment actualEe = this.getExperimentForVector(vec, ee);
assert bioAssayDimension != null;
LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>> experimentalDesignLayout = this.getExperimentalDesignLayout(actualEe, expressionExperimentService.getBioAssayDimensions(actualEe));
cachedLayouts.put(ee.getId(), experimentalDesignLayout);
}
}
use of ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject 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 ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject 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 ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject 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;
}
Aggregations