Search in sources :

Example 1 with ExperimentalFactorValueObject

use of ubic.gemma.model.expression.experiment.ExperimentalFactorValueObject in project Gemma by PavlidisLab.

the class DifferentialExpressionAnalysisCli method getSubsetFactor.

private ExperimentalFactor getSubsetFactor(ExpressionExperiment ee) {
    ExperimentalFactorService efs = this.getBean(ExperimentalFactorService.class);
    ExperimentalFactor subsetFactor = null;
    if (StringUtils.isNotBlank(this.subsetFactorName)) {
        Collection<ExperimentalFactor> experimentalFactors = ee.getExperimentalDesign().getExperimentalFactors();
        for (ExperimentalFactor experimentalFactor : experimentalFactors) {
            // has already implemented way of figuring out human-friendly name of factor value.
            ExperimentalFactorValueObject fvo = new ExperimentalFactorValueObject(experimentalFactor);
            if (ignoreBatch && BatchInfoPopulationServiceImpl.isBatchFactor(experimentalFactor)) {
                AbstractCLI.log.info("Ignoring batch factor:" + experimentalFactor);
                continue;
            }
            if (subsetFactorName.equals(experimentalFactor.getName().replaceAll(" ", "_"))) {
                subsetFactor = experimentalFactor;
            } else if (fvo.getCategory() != null && subsetFactorName.equals(fvo.getCategory().replaceAll(" ", "_"))) {
                subsetFactor = experimentalFactor;
            }
        }
        if (subsetFactor == null)
            throw new IllegalArgumentException("Didn't find factor for provided subset factor name");
        return subsetFactor;
    } else if (this.subsetFactorId != null) {
        subsetFactor = efs.load(subsetFactorId);
        if (subsetFactor == null) {
            throw new IllegalArgumentException("No factor for id=" + subsetFactorId);
        }
        return subsetFactor;
    }
    return null;
}
Also used : ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) ExperimentalFactorValueObject(ubic.gemma.model.expression.experiment.ExperimentalFactorValueObject) ExperimentalFactorService(ubic.gemma.persistence.service.expression.experiment.ExperimentalFactorService)

Example 2 with ExperimentalFactorValueObject

use of ubic.gemma.model.expression.experiment.ExperimentalFactorValueObject in project Gemma by PavlidisLab.

the class DifferentialExpressionSearchTaskImpl method filterAnalyses.

/**
 * If there are multiple analyses for an experiment, pick the one(s) that "don't overlap" (see implementation for
 * details, evolving). No database hits.
 *
 * @param analyses, all from a single experiment
 * @return a collection with either 0 or a small number of non-conflicting analyses.
 */
private Collection<DifferentialExpressionAnalysisValueObject> filterAnalyses(Collection<DifferentialExpressionAnalysisValueObject> analyses) {
    // easy case.
    if (analyses.size() == 1)
        return analyses;
    Collection<DifferentialExpressionAnalysisValueObject> filtered = new HashSet<>();
    Long subsetFactor = null;
    Map<DifferentialExpressionAnalysisValueObject, Collection<ExperimentalFactorValueObject>> analysisFactorsUsed = new HashMap<>();
    for (DifferentialExpressionAnalysisValueObject analysis : analyses) {
        /*
             * If the experiment has more than one subsetted analysis, we only used one.
             */
        if (analysis.isSubset()) {
            if (subsetFactor == null || analysis.getSubsetFactorValue().getId().equals(subsetFactor)) {
                filtered.add(analysis);
                DifferentialExpressionSearchTaskImpl.log.info("Selecting subsetanalysis: " + analysis + " " + analysis.getSubsetFactorValue());
            } else {
                DifferentialExpressionSearchTaskImpl.log.info("Skipping: subsetanalysis" + analysis + " " + analysis.getSubsetFactorValue());
            }
            subsetFactor = analysis.getSubsetFactorValue().getFactorId();
        } else {
            List<DiffExResultSetSummaryValueObject> resultSets = this.filterResultSets(analysis);
            Collection<ExperimentalFactorValueObject> factorsUsed = new HashSet<>();
            for (DiffExResultSetSummaryValueObject rs : resultSets) {
                if (this.isBatch(rs))
                    continue;
                Collection<ExperimentalFactorValueObject> facts = rs.getExperimentalFactors();
                for (ExperimentalFactorValueObject f : facts) {
                    if (ExperimentalDesignUtils.isBatch(f))
                        continue;
                    factorsUsed.add(f);
                }
            }
            if (factorsUsed.isEmpty())
                continue;
            analysisFactorsUsed.put(analysis, factorsUsed);
        }
    }
    /*
         * If we got a subsetted group of analyses, just use them
         */
    if (!filtered.isEmpty()) {
        DifferentialExpressionSearchTaskImpl.log.info("Using subsetted analyses for " + analyses.iterator().next().getBioAssaySetId() + "(" + analyses.size() + " analyses)");
        return filtered;
    }
    if (analysisFactorsUsed.isEmpty()) {
        // noinspection ConstantConditions // Defensiveness for future changes
        assert filtered.isEmpty();
        DifferentialExpressionSearchTaskImpl.log.info("No analyses were usable for " + analyses.iterator().next().getBioAssaySetId());
        return filtered;
    }
    // noinspection ConstantConditions // Defensiveness for future changes
    assert !analysisFactorsUsed.isEmpty();
    DifferentialExpressionAnalysisValueObject best = null;
    for (DifferentialExpressionAnalysisValueObject candidate : analysisFactorsUsed.keySet()) {
        if (best == null || analysisFactorsUsed.get(best).size() < analysisFactorsUsed.get(candidate).size()) {
            best = candidate;
        }
    }
    if (best != null) {
        filtered.add(best);
        DifferentialExpressionSearchTaskImpl.log.info("Selecting :" + best);
    }
    return filtered;
}
Also used : ExperimentalFactorValueObject(ubic.gemma.model.expression.experiment.ExperimentalFactorValueObject)

Example 3 with ExperimentalFactorValueObject

use of ubic.gemma.model.expression.experiment.ExperimentalFactorValueObject in project Gemma by PavlidisLab.

the class DifferentialExpressionSearchTaskImpl method markCellsBlack.

private void markCellsBlack(DiffExResultSetSummaryValueObject resultSet, Long geneId, DifferentialExpressionGenesConditionsValueObject searchResult, Double correctedPvalue, Double pValue, int numProbes, int numProbesDiffExpressed) {
    /*
         * Note that if the resultSet has more than one experimental factor, it is an interaction term.
         */
    assert resultSet.getExperimentalFactors().size() == 1 : "Should not have been passed an interaction term";
    ExperimentalFactorValueObject experimentalFactor = resultSet.getExperimentalFactors().iterator().next();
    Collection<FactorValueValueObject> factorValues = experimentalFactor.getValues();
    for (FactorValueValueObject factorValue : factorValues) {
        String conditionId = DifferentialExpressionGenesConditionsValueObject.constructConditionId(resultSet.getResultSetId(), factorValue.getId());
        searchResult.addBlackCell(geneId, conditionId, correctedPvalue, pValue, numProbes, numProbesDiffExpressed);
    }
}
Also used : FactorValueValueObject(ubic.gemma.model.expression.experiment.FactorValueValueObject) ExperimentalFactorValueObject(ubic.gemma.model.expression.experiment.ExperimentalFactorValueObject)

Example 4 with ExperimentalFactorValueObject

use of ubic.gemma.model.expression.experiment.ExperimentalFactorValueObject in project Gemma by PavlidisLab.

the class DifferentialExpressionValueObject method toString.

@Override
public String toString() {
    StringBuilder buf = new StringBuilder();
    if (gene == null) {
        buf.append("-\t");
    } else if (StringUtils.isNotBlank(gene.getOfficialSymbol())) {
        buf.append(gene.getOfficialSymbol());
    } else if (StringUtils.isNotBlank(gene.getOfficialName())) {
        buf.append(gene.getOfficialName());
    } else {
        buf.append(gene.getName());
    }
    buf.append("\t");
    if (StringUtils.isNotBlank(expressionExperiment.getShortName())) {
        buf.append(expressionExperiment.getShortName()).append("\t");
    }
    buf.append(probe).append("\t");
    int i = 0;
    for (ExperimentalFactorValueObject f : experimentalFactors) {
        buf.append(f.getName());
        if (i < (experimentalFactors.size() - 1)) {
            buf.append(", ");
        } else {
            buf.append("\t");
        }
        i++;
    }
    buf.append(p);
    return buf.toString();
}
Also used : ExperimentalFactorValueObject(ubic.gemma.model.expression.experiment.ExperimentalFactorValueObject)

Example 5 with ExperimentalFactorValueObject

use of ubic.gemma.model.expression.experiment.ExperimentalFactorValueObject in project Gemma by PavlidisLab.

the class DifferentialExpressionAnalysisCli method guessFactors.

/**
 * Determine which factors to use if given from the command line. Only applicable if analysis is on a single data
 * set.
 */
private Collection<ExperimentalFactor> guessFactors(ExpressionExperiment ee) {
    Collection<ExperimentalFactor> factors = new HashSet<>();
    ExperimentalFactorService efs = this.getBean(ExperimentalFactorService.class);
    if (this.factorNames.size() > 0) {
        if (this.factorIds.size() > 0) {
            throw new IllegalArgumentException("Please provide factor names or ids, not a mixture of each");
        }
        Collection<ExperimentalFactor> experimentalFactors = ee.getExperimentalDesign().getExperimentalFactors();
        for (ExperimentalFactor experimentalFactor : experimentalFactors) {
            // has already implemented way of figuring out human-friendly name of factor value.
            ExperimentalFactorValueObject fvo = new ExperimentalFactorValueObject(experimentalFactor);
            if (ignoreBatch && BatchInfoPopulationServiceImpl.isBatchFactor(experimentalFactor)) {
                AbstractCLI.log.info("Ignoring batch factor:" + experimentalFactor);
                continue;
            }
            if (factorNames.contains(experimentalFactor.getName().replaceAll(" ", "_"))) {
                factors.add(experimentalFactor);
            } else if (fvo.getCategory() != null && factorNames.contains(fvo.getCategory().replaceAll(" ", "_"))) {
                factors.add(experimentalFactor);
            }
        }
        if (factors.size() != factorNames.size()) {
            throw new IllegalArgumentException("Didn't find factors for all the provided factor names");
        }
    } else if (this.factorIds.size() > 0) {
        for (Long factorId : factorIds) {
            if (this.factorNames.size() > 0) {
                throw new IllegalArgumentException("Please provide factor names or ids, not a mixture of each");
            }
            ExperimentalFactor factor = efs.load(factorId);
            if (factor == null) {
                throw new IllegalArgumentException("No factor for id=" + factorId);
            }
            if (!factor.getExperimentalDesign().equals(ee.getExperimentalDesign())) {
                throw new IllegalArgumentException("Factor with id=" + factorId + " does not belong to " + ee);
            }
            if (ignoreBatch && BatchInfoPopulationServiceImpl.isBatchFactor(factor)) {
                AbstractCLI.log.warn("Selected factor looks like a batch, and 'ignoreBatch' is true, skipping:" + factor);
                continue;
            }
            factors.add(factor);
        }
    }
    return factors;
}
Also used : ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) ExperimentalFactorValueObject(ubic.gemma.model.expression.experiment.ExperimentalFactorValueObject) ExperimentalFactorService(ubic.gemma.persistence.service.expression.experiment.ExperimentalFactorService) HashSet(java.util.HashSet)

Aggregations

ExperimentalFactorValueObject (ubic.gemma.model.expression.experiment.ExperimentalFactorValueObject)7 ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)3 FactorValueValueObject (ubic.gemma.model.expression.experiment.FactorValueValueObject)2 ExperimentalFactorService (ubic.gemma.persistence.service.expression.experiment.ExperimentalFactorService)2 HashSet (java.util.HashSet)1 StopWatch (org.springframework.util.StopWatch)1 AnalysisType (ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalyzerServiceImpl.AnalysisType)1 Condition (ubic.gemma.core.tasks.visualization.DifferentialExpressionGenesConditionsValueObject.Condition)1 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)1 ExpressionExperimentDetailsValueObject (ubic.gemma.model.expression.experiment.ExpressionExperimentDetailsValueObject)1