Search in sources :

Example 26 with DoubleVectorValueObject

use of ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject in project Gemma by PavlidisLab.

the class DEDVController method getDEDVForVisualizationByProbe.

/**
 * AJAX exposed method
 */
public VisualizationValueObject[] getDEDVForVisualizationByProbe(Collection<Long> eeIds, Collection<Long> probeIds) {
    if (eeIds.isEmpty() || probeIds.isEmpty())
        return null;
    StopWatch watch = new StopWatch();
    watch.start();
    Collection<ExpressionExperiment> ees = expressionExperimentService.load(eeIds);
    if (ees == null || ees.isEmpty())
        return null;
    Collection<CompositeSequence> probes = this.compositeSequenceService.load(probeIds);
    if (probes == null || probes.isEmpty())
        return null;
    Collection<DoubleVectorValueObject> dedvs = processedExpressionDataVectorService.getProcessedDataArraysByProbe(ees, probes);
    Map<Long, LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>>> layouts = experimentalDesignVisualizationService.sortVectorDataByDesign(dedvs);
    watch.stop();
    Long time = watch.getTime();
    log.info("Retrieved " + dedvs.size() + " DEDVs for " + eeIds.size() + " EEs and " + probeIds.size() + " genes in " + time + " ms.");
    return makeVisCollection(dedvs, null, null, layouts);
}
Also used : CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) DoubleVectorValueObject(ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 27 with DoubleVectorValueObject

use of ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject in project Gemma by PavlidisLab.

the class DEDVController method getSampleNames.

/**
 * Get the names we'll use for the columns of the vectors.
 */
private void getSampleNames(Collection<DoubleVectorValueObject> vectors, VisualizationValueObject vvo, Map<Long, LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>>> layouts) {
    for (DoubleVectorValueObject vec : vectors) {
        List<String> sampleNames = new ArrayList<>();
        if (layouts != null && layouts.get(vec.getExpressionExperiment().getId()) != null) {
            // if same sample was run more than
            Collection<BioMaterialValueObject> seenSamples = new HashSet<>();
            for (BioAssayValueObject ba : layouts.get(vec.getExpressionExperiment().getId()).keySet()) {
                if (seenSamples.contains(ba.getSample())) {
                    continue;
                }
                seenSamples.add(ba.getSample());
                sampleNames.add(ba.getName());
            }
            if (sampleNames.size() > 0) {
                assert sampleNames.size() == vec.getData().length;
                log.debug(sampleNames.size() + " sample names!");
                vvo.setSampleNames(sampleNames);
            }
        } else {
            sampleNames = getSampleNames(vec);
            if (sampleNames.size() > 0) {
                log.debug(sampleNames.size() + " sample names!");
                vvo.setSampleNames(sampleNames);
            }
        }
    }
}
Also used : BioAssayValueObject(ubic.gemma.model.expression.bioAssay.BioAssayValueObject) BioMaterialValueObject(ubic.gemma.model.expression.biomaterial.BioMaterialValueObject) DoubleVectorValueObject(ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject)

Example 28 with DoubleVectorValueObject

use of ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject in project Gemma by PavlidisLab.

the class DEDVController method getDEDV.

/**
 * Given a collection of expression experiment Ids and a geneId returns a map of DEDV value objects to a collection
 * of genes. The EE info is in the value object. FIXME handle subsets.
 */
public Map<ExpressionExperimentValueObject, Map<Long, Collection<DoubleVectorValueObject>>> getDEDV(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> dedvMap;
    if (geneIds == null || geneIds.isEmpty()) {
        dedvMap = processedExpressionDataVectorService.getProcessedDataArrays(ees.iterator().next(), 50);
    } else {
        dedvMap = processedExpressionDataVectorService.getProcessedDataArrays(ees, geneIds);
    }
    /*
         * Don't reorganize them -- the headings will be wrong.
         */
    Map<Long, LinkedHashMap<BioAssay, LinkedHashMap<ExperimentalFactor, Double>>> layouts = null;
    // 
    // layouts= experimentalDesignVisualizationService .sortVectorDataByDesign( dedvMap );
    watch.stop();
    Long time = watch.getTime();
    if (time > 1000) {
        log.info("Retrieved " + dedvMap.size() + " DEDVs from " + eeIds.size() + " EEs in " + time + " ms.");
    }
    return makeVectorMap(dedvMap, layouts);
}
Also used : DoubleVectorValueObject(ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 29 with DoubleVectorValueObject

use of ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject 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)

Example 30 with DoubleVectorValueObject

use of ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject in project Gemma by PavlidisLab.

the class DEDVController method getDEDVForDiffExVisualizationByExperiment.

/**
 * AJAX exposed method Batch factor value analyses are filtered out; for
 * ProbeLevelDiffExGrid:VisualizationDifferentialWindow.
 */
public VisualizationValueObject[] getDEDVForDiffExVisualizationByExperiment(Long eeId, Long geneId, Double threshold, Boolean isSubset) {
    if (geneId == null) {
        throw new IllegalArgumentException("Gene ID cannot be null");
    }
    StopWatch watch = new StopWatch();
    watch.start();
    BioAssaySet ee;
    if (isSubset) {
        ee = expressionExperimentSubSetService.load(eeId);
    } else {
        ee = expressionExperimentService.load(eeId);
    }
    if (ee == null)
        // access denied, etc.
        return new VisualizationValueObject[] {};
    if (threshold == null) {
        log.warn("Threshold was null, using default");
        threshold = DEFAULT_THRESHOLD;
    }
    Collection<DoubleVectorValueObject> dedvs;
    Gene g = geneService.load(geneId);
    if (g == null)
        return null;
    Collection<Long> genes = new ArrayList<>();
    genes.add(geneId);
    Collection<BioAssaySet> ees = new ArrayList<>();
    ees.add(ee);
    dedvs = processedExpressionDataVectorService.getProcessedDataArrays(ees, genes);
    Long time = watch.getTime();
    watch.reset();
    watch.start();
    if (time > 100) {
        log.info("Retrieved " + dedvs.size() + " DEDVs for " + ee.getId() + " and " + "one gene in " + time + " ms (times <100ms not reported).");
    }
    Map<Long, LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>>> layouts;
    layouts = experimentalDesignVisualizationService.sortVectorDataByDesign(dedvs);
    time = watch.getTime();
    watch.reset();
    watch.start();
    if (time > 100) {
        log.info("Ran sortVectorDataByDesign on " + dedvs.size() + " DEDVs for 1 EE" + " in " + time + " ms (times <100ms not reported).");
    }
    time = watch.getTime();
    watch.reset();
    watch.start();
    if (time > 100) {
        log.info("Ran sortLayoutSamplesByFactor on " + layouts.size() + " layouts" + " in " + time + " ms (times <100ms not reported).");
    }
    Map<Long, Collection<DifferentialExpressionValueObject>> validatedProbes = new HashMap<>();
    validatedProbes.put(ee.getId(), geneDifferentialExpressionService.getDifferentialExpression(g, ees, threshold, null));
    watch.stop();
    time = watch.getTime();
    if (time > 100) {
        log.info("Retrieved " + validatedProbes.size() + " valid probes in " + time + " ms.");
    }
    return makeDiffVisCollection(dedvs, new ArrayList<>(genes), validatedProbes, layouts);
}
Also used : StopWatch(org.apache.commons.lang3.time.StopWatch) Gene(ubic.gemma.model.genome.Gene) DoubleVectorValueObject(ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject)

Aggregations

DoubleVectorValueObject (ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject)31 StopWatch (org.apache.commons.lang3.time.StopWatch)13 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)9 Test (org.junit.Test)6 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)6 BioAssayValueObject (ubic.gemma.model.expression.bioAssay.BioAssayValueObject)6 AlreadyExistsInSystemException (ubic.gemma.core.loader.util.AlreadyExistsInSystemException)5 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)5 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)5 Gene (ubic.gemma.model.genome.Gene)5 ExpressionDataDoubleMatrix (ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix)4 ExperimentExpressionLevelsValueObject (ubic.gemma.model.expression.bioAssayData.ExperimentExpressionLevelsValueObject)4 GeneValueObject (ubic.gemma.model.genome.gene.GeneValueObject)4 InputStream (java.io.InputStream)3 Transactional (org.springframework.transaction.annotation.Transactional)3 DoubleMatrixReader (ubic.basecode.io.reader.DoubleMatrixReader)3 GeoDomainObjectGenerator (ubic.gemma.core.loader.expression.geo.GeoDomainObjectGenerator)3 GeoDomainObjectGeneratorLocal (ubic.gemma.core.loader.expression.geo.GeoDomainObjectGeneratorLocal)3 ProbeLoading (ubic.gemma.model.analysis.expression.pca.ProbeLoading)3 VisualizationValueObject (ubic.gemma.web.controller.visualization.VisualizationValueObject)3