Search in sources :

Example 6 with DifferentialExpressionValueObject

use of ubic.gemma.model.analysis.expression.diff.DifferentialExpressionValueObject 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 7 with DifferentialExpressionValueObject

use of ubic.gemma.model.analysis.expression.diff.DifferentialExpressionValueObject in project Gemma by PavlidisLab.

the class DEDVController method getProbeDiffExValidation.

/**
 * This is probably no longer being really used?
 */
private Map<Long, Collection<DifferentialExpressionValueObject>> getProbeDiffExValidation(Collection<Gene> genes, Double threshold, Collection<DiffExpressionSelectedFactorCommand> factorMap) {
    if (factorMap == null)
        throw new IllegalArgumentException("Factor information is missing, please make sure factors are selected.");
    Map<Long, Collection<DifferentialExpressionValueObject>> validatedProbes = new HashMap<>();
    Collection<Long> wantedFactors = new HashSet<>();
    for (DiffExpressionSelectedFactorCommand factor : factorMap) {
        wantedFactors.add(factor.getEfId());
    }
    for (Gene gene : genes) {
        Collection<DifferentialExpressionValueObject> differentialExpression = geneDifferentialExpressionService.getDifferentialExpression(gene, threshold, factorMap);
        for (DifferentialExpressionValueObject diffVo : differentialExpression) {
            assert diffVo.getCorrP() <= threshold;
            Long eeId = diffVo.getExpressionExperiment().getId();
            if (!validatedProbes.containsKey(eeId)) {
                validatedProbes.put(eeId, new HashSet<DifferentialExpressionValueObject>());
            }
            Collection<ExperimentalFactorValueObject> factors = diffVo.getExperimentalFactors();
            for (ExperimentalFactorValueObject fac : factors) {
                if (wantedFactors.contains(fac.getId())) {
                    validatedProbes.get(eeId).add(diffVo);
                }
            }
        }
    }
    return validatedProbes;
}
Also used : DifferentialExpressionValueObject(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionValueObject) DiffExpressionSelectedFactorCommand(ubic.gemma.core.analysis.expression.diff.DiffExpressionSelectedFactorCommand) Gene(ubic.gemma.model.genome.Gene)

Example 8 with DifferentialExpressionValueObject

use of ubic.gemma.model.analysis.expression.diff.DifferentialExpressionValueObject in project Gemma by PavlidisLab.

the class DifferentialExpressionSearchController method getDifferentialExpressionWithoutBatch.

/**
 * AJAX entry which returns results on a non-meta analysis basis. That is, the differential expression results for
 * the gene with the id, geneId, are returned. This method is just like getDifferentialExpression but any analyses
 * with the 'batch' factor are filtered out because they are not biologically relevant
 */
public Collection<DifferentialExpressionValueObject> getDifferentialExpressionWithoutBatch(Long geneId, double threshold, Integer limit) {
    Collection<DifferentialExpressionValueObject> analyses = getDifferentialExpression(geneId, threshold, limit);
    // for each DifferentialExpressionValueObject, check if its factors includes a batch factor and if so, remove
    // the batch factor
    Collection<DifferentialExpressionValueObject> toRemove = new ArrayList<>();
    for (DifferentialExpressionValueObject analysis : analyses) {
        for (ExperimentalFactorValueObject factor : analysis.getExperimentalFactors()) {
            if (ExperimentalDesignUtils.isBatch(factor)) {
                toRemove.add(analysis);
            }
        }
    }
    analyses.removeAll(toRemove);
    return analyses;
}
Also used : DifferentialExpressionValueObject(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionValueObject) ExpressionExperimentExperimentalFactorValueObject(ubic.gemma.web.controller.expression.experiment.ExpressionExperimentExperimentalFactorValueObject)

Example 9 with DifferentialExpressionValueObject

use of ubic.gemma.model.analysis.expression.diff.DifferentialExpressionValueObject in project Gemma by PavlidisLab.

the class ProcessedExpressionDataVectorServiceImpl method getDiffExVectors.

@Override
public List<DoubleVectorValueObject> getDiffExVectors(Long resultSetId, Double threshold, int maxNumberOfResults) {
    ExpressionAnalysisResultSet ar = differentialExpressionResultService.loadAnalysisResultSet(resultSetId);
    if (ar == null) {
        Log.warn(this.getClass(), "No diff ex result set with ID=" + resultSetId);
        return null;
    }
    differentialExpressionResultService.thawLite(ar);
    BioAssaySet analyzedSet = ar.getAnalysis().getExperimentAnalyzed();
    List<DifferentialExpressionValueObject> ee2probeResults = differentialExpressionResultService.findInResultSet(ar, threshold, maxNumberOfResults, ProcessedExpressionDataVectorServiceImpl.DIFFEX_MIN_NUMBER_OF_RESULTS);
    Collection<Long> probes = new HashSet<>();
    // Map<CompositeSequenceId, pValue>
    // using id instead of entity for map key because want to use a value object for retrieval later
    Map<Long, Double> pvalues = new HashMap<>();
    for (DifferentialExpressionValueObject par : ee2probeResults) {
        probes.add(par.getProbeId());
        pvalues.put(par.getProbeId(), par.getP());
    }
    Collection<DoubleVectorValueObject> processedDataArraysByProbe = this.getProcessedDataArraysByProbeIds(analyzedSet, probes);
    List<DoubleVectorValueObject> dedvs = new ArrayList<>(processedDataArraysByProbe);
    /*
         * Resort
         */
    for (DoubleVectorValueObject v : dedvs) {
        v.setPvalue(pvalues.get(v.getDesignElement().getId()));
    }
    Collections.sort(dedvs, new Comparator<DoubleVectorValueObject>() {

        @Override
        public int compare(DoubleVectorValueObject o1, DoubleVectorValueObject o2) {
            if (o1.getPvalue() == null)
                return -1;
            if (o2.getPvalue() == null)
                return 1;
            return o1.getPvalue().compareTo(o2.getPvalue());
        }
    });
    return dedvs;
}
Also used : DifferentialExpressionValueObject(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionValueObject) ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet) BioAssaySet(ubic.gemma.model.expression.experiment.BioAssaySet) DoubleVectorValueObject(ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject)

Example 10 with DifferentialExpressionValueObject

use of ubic.gemma.model.analysis.expression.diff.DifferentialExpressionValueObject in project Gemma by PavlidisLab.

the class DifferentialExpressionMetaAnalysisValueObject method toString.

@Override
public String toString() {
    StringBuilder buf = new StringBuilder();
    buf.append("# MetaP = ").append(this.getFisherPValue()).append("\n");
    for (DifferentialExpressionValueObject result : this.getProbeResults()) {
        buf.append(result).append("\n");
    }
    return buf.toString();
}
Also used : DifferentialExpressionValueObject(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionValueObject)

Aggregations

DifferentialExpressionValueObject (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionValueObject)14 StopWatch (org.apache.commons.lang3.time.StopWatch)8 DoubleArrayList (cern.colt.list.DoubleArrayList)6 Element (org.w3c.dom.Element)2 DoubleVectorValueObject (ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject)2 BioAssaySet (ubic.gemma.model.expression.experiment.BioAssaySet)2 Gene (ubic.gemma.model.genome.Gene)2 GeneValueObject (ubic.gemma.model.genome.gene.GeneValueObject)2 DiffExpressionSelectedFactorCommand (ubic.gemma.core.analysis.expression.diff.DiffExpressionSelectedFactorCommand)1 ExpressionExperimentSet (ubic.gemma.model.analysis.expression.ExpressionExperimentSet)1 ExpressionAnalysisResultSet (ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)1 BioAssayValueObject (ubic.gemma.model.expression.bioAssay.BioAssayValueObject)1 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)1 ExpressionExperimentValueObject (ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject)1 Taxon (ubic.gemma.model.genome.Taxon)1 ExpressionExperimentExperimentalFactorValueObject (ubic.gemma.web.controller.expression.experiment.ExpressionExperimentExperimentalFactorValueObject)1 VisualizationValueObject (ubic.gemma.web.controller.visualization.VisualizationValueObject)1