Search in sources :

Example 1 with ExperimentalFactorService

use of ubic.gemma.persistence.service.expression.experiment.ExperimentalFactorService 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 ExperimentalFactorService

use of ubic.gemma.persistence.service.expression.experiment.ExperimentalFactorService 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

ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)2 ExperimentalFactorValueObject (ubic.gemma.model.expression.experiment.ExperimentalFactorValueObject)2 ExperimentalFactorService (ubic.gemma.persistence.service.expression.experiment.ExperimentalFactorService)2 HashSet (java.util.HashSet)1