Search in sources :

Example 1 with VisualizationValueObject

use of ubic.gemma.web.controller.visualization.VisualizationValueObject 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;
}
Also used : VisualizationValueObject(ubic.gemma.web.controller.visualization.VisualizationValueObject) DifferentialExpressionValueObject(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionValueObject) StopWatch(org.apache.commons.lang3.time.StopWatch) GeneValueObject(ubic.gemma.model.genome.gene.GeneValueObject) BioAssayValueObject(ubic.gemma.model.expression.bioAssay.BioAssayValueObject) DoubleVectorValueObject(ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject)

Example 2 with VisualizationValueObject

use of ubic.gemma.web.controller.visualization.VisualizationValueObject in project Gemma by PavlidisLab.

the class DEDVController method getDEDVForCoexpressionVisualization.

/**
 * AJAX exposed method
 */
public VisualizationValueObject[] getDEDVForCoexpressionVisualization(Collection<Long> eeIds, Long queryGeneId, Long coexpressedGeneId) {
    StopWatch watch = new StopWatch();
    watch.start();
    Collection<ExpressionExperiment> ees = expressionExperimentService.load(eeIds);
    if (ees == null || ees.isEmpty())
        return new VisualizationValueObject[0];
    Gene queryGene = geneService.load(queryGeneId);
    Gene coexpressedGene = geneService.load(coexpressedGeneId);
    List<Long> genes = new ArrayList<>();
    genes.add(queryGeneId);
    genes.add(coexpressedGeneId);
    if (genes.isEmpty())
        return new VisualizationValueObject[0];
    Collection<DoubleVectorValueObject> dedvs = processedExpressionDataVectorService.getProcessedDataArrays(ees, genes);
    Map<Long, LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>>> layouts;
    layouts = experimentalDesignVisualizationService.sortVectorDataByDesign(dedvs);
    // layouts = experimentalDesignVisualizationService.sortLayoutSamplesByFactor( layouts );
    watch.stop();
    Long time = watch.getTime();
    if (dedvs.size() == 0) {
        log.warn("No expression profiles (DEDVs) were available for the experiments:  " + eeIds + " and genes(s) " + queryGene.getOfficialSymbol() + ", " + coexpressedGene.getOfficialSymbol());
        return new VisualizationValueObject[0];
    }
    if (time > 1000) {
        log.info("Retrieved " + dedvs.size() + " DEDVs for " + eeIds.size() + " EEs and " + genes.size() + " genes in " + time + " ms.");
    }
    Map<Long, Collection<Long>> validatedProbes = getProbeLinkValidation(ees, queryGene, coexpressedGene, dedvs);
    return makeVisCollection(dedvs, genes, validatedProbes, layouts);
}
Also used : VisualizationValueObject(ubic.gemma.web.controller.visualization.VisualizationValueObject) StopWatch(org.apache.commons.lang3.time.StopWatch) Gene(ubic.gemma.model.genome.Gene) DoubleVectorValueObject(ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject)

Example 3 with VisualizationValueObject

use of ubic.gemma.web.controller.visualization.VisualizationValueObject in project Gemma by PavlidisLab.

the class DEDVController method makeVisCollection.

/**
 * 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.
 */
private VisualizationValueObject[] makeVisCollection(Collection<DoubleVectorValueObject> dedvs, Collection<Long> genes, Map<Long, Collection<Long>> validatedProbes, Map<Long, LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>>> layouts) {
    Map<Long, List<DoubleVectorValueObject>> vvoMap = new HashMap<>();
    // Organize by expression experiment
    if (dedvs == null || dedvs.isEmpty())
        return new VisualizationValueObject[1];
    for (DoubleVectorValueObject dvvo : dedvs) {
        // FIXME: we can probably use this information, and do away with carrying so much Layout information around?
        // assert dvvo.isReorganized() && dvvo.getBioAssayDimension().isReordered(); // not always true!!
        ExpressionExperimentValueObject ee = dvvo.getExpressionExperiment();
        if (!vvoMap.containsKey(ee.getId())) {
            vvoMap.put(ee.getId(), new ArrayList<DoubleVectorValueObject>());
        }
        vvoMap.get(ee.getId()).add(dvvo);
    }
    List<GeneValueObject> geneValueObjects;
    if (genes == null || genes.isEmpty()) {
        geneValueObjects = new ArrayList<>(getGeneValueObjectsUsed(dedvs).values());
    } else {
        geneValueObjects = getGeneValueObjectList(new ArrayList<>(genes));
    }
    StopWatch timer = new StopWatch();
    timer.start();
    VisualizationValueObject[] result = new VisualizationValueObject[vvoMap.keySet().size()];
    // Create collection of visualizationValueObject for flotr on js side
    int i = 0;
    for (Long ee : vvoMap.keySet()) {
        Collection<Long> validatedProbeList = null;
        if (validatedProbes != null) {
            validatedProbeList = validatedProbes.get(ee);
        }
        Collection<DoubleVectorValueObject> vectors = vvoMap.get(ee);
        VisualizationValueObject vvo = new VisualizationValueObject(vectors, geneValueObjects, validatedProbeList);
        if (vectors.size() > 0) {
            getSampleNames(vectors, vvo, layouts);
            if (vectors.size() > 0 && layouts != null && !layouts.isEmpty() && layouts.containsKey(ee)) {
                // Set up the experimental designinfo so we can show it above the graph.
                LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>> layout = layouts.get(ee);
                this.prepareFactorsForFrontEndDisplay(vvo, layout);
            }
        }
        /*
             * Set up the experimental design info so we can show it above the graph.
             */
        if (layouts != null && layouts.get(ee) != null) {
            vvo.setUpFactorProfiles(layouts.get(ee));
        }
        result[i] = vvo;
        i++;
    }
    long time = timer.getTime();
    if (time > 1000) {
        log.info("Created vis value objects in: " + time);
    }
    return result;
}
Also used : VisualizationValueObject(ubic.gemma.web.controller.visualization.VisualizationValueObject) StopWatch(org.apache.commons.lang3.time.StopWatch) GeneValueObject(ubic.gemma.model.genome.gene.GeneValueObject) BioAssayValueObject(ubic.gemma.model.expression.bioAssay.BioAssayValueObject) DoubleVectorValueObject(ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject)

Aggregations

StopWatch (org.apache.commons.lang3.time.StopWatch)3 DoubleVectorValueObject (ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject)3 VisualizationValueObject (ubic.gemma.web.controller.visualization.VisualizationValueObject)3 BioAssayValueObject (ubic.gemma.model.expression.bioAssay.BioAssayValueObject)2 GeneValueObject (ubic.gemma.model.genome.gene.GeneValueObject)2 DifferentialExpressionValueObject (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionValueObject)1 Gene (ubic.gemma.model.genome.Gene)1