Search in sources :

Example 81 with ExperimentalFactor

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

the class ExpressionDataMatrixColumnSort method orderFactorsByExperimentalDesign.

/**
 * @return list of factors, sorted from simplest (fewest number of values from the biomaterials passed in) to least
 * simple. Continuous factors will always be first, and batch factors last.
 */
private static List<ExperimentalFactor> orderFactorsByExperimentalDesign(List<BioMaterial> start, Collection<ExperimentalFactor> factors) {
    if (factors == null || factors.isEmpty()) {
        ExpressionDataMatrixColumnSort.log.warn("No factors supplied for sorting");
        return new LinkedList<>();
    }
    LinkedList<ExperimentalFactor> sortedFactors = new LinkedList<>();
    Collection<ExperimentalFactor> factorsToTake = new HashSet<>(factors);
    while (!factorsToTake.isEmpty()) {
        ExperimentalFactor simplest = ExpressionDataMatrixColumnSort.chooseSimplestFactor(start, factorsToTake);
        if (simplest == null) {
            // none of the factors have more than one factor value. One-sided t-tests ...
            /*
                 * This assertion isn't right -- we now allow this, though we can only have ONE such constant factor.
                 * See bug 2390. Unless we are dealing with a subset, in which case there can be any number of constant
                 * factors within the subset.
                 */
            // assert factors.size() == 1 :
            // "It's possible to have just one factor value, but only if there is only one factor.";
            sortedFactors.addAll(factors);
            return sortedFactors;
        }
        sortedFactors.addLast(simplest);
        factorsToTake.remove(simplest);
    }
    return sortedFactors;
}
Also used : ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor)

Example 82 with ExperimentalFactor

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

the class FactorValueDeletionImpl method deleteFactorValues.

@Override
@Transactional
public void deleteFactorValues(Collection<Long> fvIds) {
    Collection<FactorValue> fvsToDelete = new ArrayList<>();
    for (Long fvId : fvIds) {
        FactorValue fv = factorValueService.load(fvId);
        if (fv == null) {
            throw new IllegalArgumentException("No factor value with id=" + fvId + " could be loaded");
        }
        if (fv.getExperimentalFactor() == null) {
            throw new IllegalStateException("No experimental factor for factor value " + fv.getId());
        }
        /*
             * Delete any diff ex analyses that use this factor.
             */
        ExperimentalFactor ef = experimentalFactorService.load(fv.getExperimentalFactor().getId());
        Collection<DifferentialExpressionAnalysis> analyses = differentialExpressionAnalysisService.findByFactor(ef);
        // Warning: slow.
        for (DifferentialExpressionAnalysis a : analyses) {
            differentialExpressionAnalysisService.remove(a);
        }
        // this gets done by the factorValueService as well, but can't hurt.
        ef.getFactorValues().remove(fv);
        fvsToDelete.add(fv);
    }
    for (FactorValue fv : fvsToDelete) {
        factorValueService.remove(fv);
    }
}
Also used : FactorValue(ubic.gemma.model.expression.experiment.FactorValue) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) ArrayList(java.util.ArrayList) DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis) Transactional(org.springframework.transaction.annotation.Transactional)

Example 83 with ExperimentalFactor

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

the class DifferentialExpressionAnalysisController method runCustom.

public String runCustom(Long id, Collection<Long> factorids, boolean includeInteractions, Long subsetFactorId) {
    if (factorids.isEmpty()) {
        throw new IllegalArgumentException("You must provide at least one factor to analyze");
    }
    ExpressionExperiment ee = expressionExperimentService.load(id);
    if (ee == null) {
        throw new IllegalArgumentException("Cannot access experiment with id=" + id);
    }
    ee = expressionExperimentService.thawLite(ee);
    /*
         * Get the factors matching the factorids
         */
    Collection<ExperimentalFactor> factors = new HashSet<>();
    for (ExperimentalFactor ef : ee.getExperimentalDesign().getExperimentalFactors()) {
        if (factorids.contains(ef.getId())) {
            factors.add(ef);
        }
    }
    if (factors.size() != factorids.size()) {
        throw new IllegalArgumentException("Unknown factors?");
    }
    ExperimentalFactor subsetFactor = null;
    if (subsetFactorId != null) {
        for (ExperimentalFactor ef : ee.getExperimentalDesign().getExperimentalFactors()) {
            if (subsetFactorId.equals(ef.getId())) {
                subsetFactor = ef;
                break;
            }
        }
        if (subsetFactor == null) {
            throw new IllegalArgumentException("Unknown subset factor?");
        }
        if (factors.contains(subsetFactor)) {
            throw new IllegalArgumentException("Subset factor must not be one of the factors used in the analysis");
        }
    }
    DifferentialExpressionAnalysisTaskCommand cmd = new DifferentialExpressionAnalysisTaskCommand(ee);
    boolean rnaSeq = expressionExperimentService.isRNASeq(ee);
    cmd.setUseWeights(rnaSeq);
    cmd.setFactors(factors);
    cmd.setSubsetFactor(subsetFactor);
    for (ExperimentalFactor ef : factors) {
        if (BatchInfoPopulationServiceImpl.isBatchFactor(ef)) {
            /*
                 * This is a policy and I am pretty sure it makes sense!
                 */
            DifferentialExpressionAnalysisController.log.warn("Removing interaction term because it includes 'batch'");
            includeInteractions = false;
        }
    }
    cmd.setIncludeInteractions(includeInteractions);
    DifferentialExpressionAnalysisController.log.info("Initializing analysis");
    this.experimentReportService.evictFromCache(ee.getId());
    return taskRunningService.submitRemoteTask(cmd);
}
Also used : DifferentialExpressionAnalysisTaskCommand(ubic.gemma.core.tasks.analysis.diffex.DifferentialExpressionAnalysisTaskCommand) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) HashSet(java.util.HashSet)

Example 84 with ExperimentalFactor

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

the class DifferentialExpressionAnalysisController method determineAnalysisType.

/**
 * Ajax method. Pick the analysis type when we want it to be completely automated.
 *
 * @param id id
 * @return analysis info
 */
public DifferentialExpressionAnalyzerInfo determineAnalysisType(Long id) {
    ExpressionExperiment ee = expressionExperimentService.load(id);
    if (ee == null) {
        throw new IllegalArgumentException("Cannot access experiment with id=" + id);
    }
    ee = expressionExperimentService.thawLite(ee);
    Collection<ExperimentalFactor> factorsWithoutBatch = ExperimentalDesignUtils.factorsWithoutBatch(ee.getExperimentalDesign().getExperimentalFactors());
    AnalysisType analyzer = this.analysisSelectionAndExecutionService.determineAnalysis(ee, factorsWithoutBatch, null, true);
    DifferentialExpressionAnalyzerInfo result = new DifferentialExpressionAnalyzerInfo();
    // we include all factors here, so that batch can be used for subsetting (up to client)
    for (ExperimentalFactor factor : ee.getExperimentalDesign().getExperimentalFactors()) {
        result.getFactors().add(new ExperimentalFactorValueObject(factor));
    }
    if (analyzer == null) {
        /*
             * Either there are no viable automatic choices, or there are no usable factors...
             */
        if (factorsWithoutBatch.size() < 2) {
            throw new IllegalStateException("This data set does not seem suitable for analysis.");
        }
        result.setType(AnalysisType.GENERICLM.toString());
    } else {
        result.setType(analyzer.toString());
    }
    return result;
}
Also used : AnalysisType(ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalyzerServiceImpl.AnalysisType) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) ExperimentalFactorValueObject(ubic.gemma.model.expression.experiment.ExperimentalFactorValueObject) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment)

Example 85 with ExperimentalFactor

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

the class CharacteristicBrowserController method findCharacteristicsCustom.

/**
 * @param searchFVs       Search factor values that lack characteristics -- that is, search the factorValue.value.
 * @param searchCategories Should the Category be searched, not just the Value?
 */
public Collection<AnnotationValueObject> findCharacteristicsCustom(String valuePrefix, boolean searchNos, boolean searchEEs, boolean searchBMs, boolean searchFVs, boolean searchPAs, boolean searchFVVs, boolean searchCategories) {
    List<AnnotationValueObject> results = new ArrayList<>();
    if (StringUtils.isBlank(valuePrefix)) {
        return results;
    }
    Collection<Characteristic> chars = characteristicService.findByValue(valuePrefix);
    if (searchCategories) {
        chars.addAll(characteristicService.findByCategory(valuePrefix));
    }
    Map<Characteristic, Object> charToParent = characteristicService.getParents(chars);
    for (Object o : chars) {
        Characteristic c = (Characteristic) o;
        Object parent = charToParent.get(c);
        if ((searchEEs && parent instanceof ExpressionExperiment) || (searchBMs && parent instanceof BioMaterial) || (searchFVs && (parent instanceof FactorValue || parent instanceof ExperimentalFactor)) || (searchNos && parent == null) || (searchPAs && parent instanceof PhenotypeAssociation)) {
            AnnotationValueObject avo = new AnnotationValueObject();
            avo.setId(c.getId());
            avo.setClassName(c.getCategory());
            avo.setTermName(c.getValue());
            if (c.getEvidenceCode() != null)
                avo.setEvidenceCode(c.getEvidenceCode().toString());
            populateClassValues(c, avo);
            if (parent != null) {
                populateParentInformation(avo, parent);
            }
            results.add(avo);
        }
    }
    if (searchFVVs) {
        // non-characteristics.
        Collection<FactorValue> factorValues = factorValueService.findByValue(valuePrefix);
        for (FactorValue factorValue : factorValues) {
            if (factorValue.getCharacteristics().size() > 0)
                continue;
            if (StringUtils.isBlank(factorValue.getValue()))
                continue;
            AnnotationValueObject avo = new AnnotationValueObject();
            avo.setId(factorValue.getId());
            avo.setTermName(factorValue.getValue());
            avo.setObjectClass(FactorValue.class.getSimpleName());
            populateParentInformation(avo, factorValue);
            results.add(avo);
        }
    }
    log.info("Characteristic search for: '" + valuePrefix + "*': " + results.size() + " results, returning up to " + MAX_RESULTS);
    return results.subList(0, Math.min(results.size(), MAX_RESULTS));
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) FactorValue(ubic.gemma.model.expression.experiment.FactorValue) Characteristic(ubic.gemma.model.common.description.Characteristic) VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) AnnotationValueObject(ubic.gemma.model.common.description.AnnotationValueObject) ArrayList(java.util.ArrayList) PhenotypeAssociation(ubic.gemma.model.association.phenotype.PhenotypeAssociation) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) AnnotationValueObject(ubic.gemma.model.common.description.AnnotationValueObject)

Aggregations

ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)88 Test (org.junit.Test)31 FactorValue (ubic.gemma.model.expression.experiment.FactorValue)30 DifferentialExpressionAnalysis (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis)26 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)22 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)18 HashSet (java.util.HashSet)17 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)17 ExpressionAnalysisResultSet (ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)16 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)14 DifferentialExpressionAnalysisResult (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult)12 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)11 GeoDomainObjectGeneratorLocal (ubic.gemma.core.loader.expression.geo.GeoDomainObjectGeneratorLocal)10 AlreadyExistsInSystemException (ubic.gemma.core.loader.util.AlreadyExistsInSystemException)10 Before (org.junit.Before)8 Collection (java.util.Collection)7 ContrastResult (ubic.gemma.model.analysis.expression.diff.ContrastResult)6 AnalysisType (ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalyzerServiceImpl.AnalysisType)5 ExperimentalFactorValueObject (ubic.gemma.model.expression.experiment.ExperimentalFactorValueObject)5 InputStream (java.io.InputStream)4