Search in sources :

Example 1 with FactorValueValueObject

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

the class GeneralSearchControllerImpl method fillValueObjects.

@SuppressWarnings("unchecked")
private void fillValueObjects(Class<?> entityClass, List<SearchResult> results, SearchSettings settings) {
    StopWatch timer = new StopWatch();
    timer.start();
    Collection<?> vos;
    if (ExpressionExperiment.class.isAssignableFrom(entityClass)) {
        vos = this.filterEE(expressionExperimentService.loadValueObjects(EntityUtils.getIds(results), false), settings);
        if (!SecurityUtil.isUserAdmin()) {
            auditableUtil.removeTroubledEes((Collection<ExpressionExperimentValueObject>) vos);
        }
    } else if (ArrayDesign.class.isAssignableFrom(entityClass)) {
        vos = this.filterAD(arrayDesignService.loadValueObjectsByIds(EntityUtils.getIds(results)), settings);
        if (!SecurityUtil.isUserAdmin()) {
            auditableUtil.removeTroubledArrayDesigns((Collection<ArrayDesignValueObject>) vos);
        }
    } else if (CompositeSequence.class.isAssignableFrom(entityClass)) {
        Collection<CompositeSequenceValueObject> css = new ArrayList<>();
        for (SearchResult sr : results) {
            CompositeSequenceValueObject csvo = compositeSequenceService.loadValueObject((CompositeSequence) sr.getResultObject());
            css.add(csvo);
        }
        vos = css;
    } else if (BibliographicReference.class.isAssignableFrom(entityClass)) {
        Collection<BibliographicReference> bss = bibliographicReferenceService.load(EntityUtils.getIds(results));
        bss = bibliographicReferenceService.thaw(bss);
        vos = bibliographicReferenceService.loadValueObjects(bss);
    } else if (Gene.class.isAssignableFrom(entityClass)) {
        Collection<Gene> genes = geneService.load(EntityUtils.getIds(results));
        genes = geneService.thawLite(genes);
        vos = geneService.loadValueObjects(genes);
    } else if (Characteristic.class.isAssignableFrom(entityClass)) {
        Collection<CharacteristicValueObject> cvos = new ArrayList<>();
        for (SearchResult sr : results) {
            Characteristic ch = (Characteristic) sr.getResultObject();
            cvos.add(new CharacteristicValueObject(ch));
        }
        vos = cvos;
    } else if (CharacteristicValueObject.class.isAssignableFrom(entityClass)) {
        Collection<CharacteristicValueObject> cvos = new ArrayList<>();
        for (SearchResult sr : results) {
            CharacteristicValueObject ch = (CharacteristicValueObject) sr.getResultObject();
            cvos.add(ch);
        }
        vos = cvos;
    } else if (BioSequenceValueObject.class.isAssignableFrom(entityClass)) {
        return;
    } else if (GeneSet.class.isAssignableFrom(entityClass)) {
        vos = geneSetService.getValueObjects(EntityUtils.getIds(results));
    } else if (ExpressionExperimentSet.class.isAssignableFrom(entityClass)) {
        vos = experimentSetService.loadValueObjects(experimentSetService.load(EntityUtils.getIds(results)));
    } else if (FactorValue.class.isAssignableFrom(entityClass)) {
        Collection<FactorValueValueObject> fvo = new ArrayList<>();
        for (SearchResult sr : results) {
            fvo.add(new FactorValueValueObject((FactorValue) sr.getResultObject()));
        }
        vos = fvo;
    } else {
        throw new UnsupportedOperationException("Don't know how to make value objects for class=" + entityClass);
    }
    if (vos == null || vos.isEmpty()) {
        // it causing front end errors, if vos is empty make sure to get rid of all search results
        for (Iterator<SearchResult> it = results.iterator(); it.hasNext(); ) {
            it.next();
            it.remove();
        }
        return;
    }
    // retained objects...
    Map<Long, Object> idMap = EntityUtils.getIdMap(vos);
    for (Iterator<SearchResult> it = results.iterator(); it.hasNext(); ) {
        SearchResult sr = it.next();
        if (!idMap.containsKey(sr.getId())) {
            it.remove();
            continue;
        }
        sr.setResultObject(idMap.get(sr.getId()));
    }
    if (timer.getTime() > 1000) {
        BaseFormController.log.info("Value object conversion after search: " + timer.getTime() + "ms");
    }
}
Also used : CharacteristicValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject) CompositeSequenceValueObject(ubic.gemma.model.expression.designElement.CompositeSequenceValueObject) Gene(ubic.gemma.model.genome.Gene) ExpressionExperimentValueObject(ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject) BioSequenceValueObject(ubic.gemma.model.genome.sequenceAnalysis.BioSequenceValueObject) FactorValueValueObject(ubic.gemma.model.expression.experiment.FactorValueValueObject) FactorValue(ubic.gemma.model.expression.experiment.FactorValue) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) Characteristic(ubic.gemma.model.common.description.Characteristic) SearchResult(ubic.gemma.core.search.SearchResult) BibliographicReference(ubic.gemma.model.common.description.BibliographicReference) StopWatch(org.apache.commons.lang3.time.StopWatch) ExpressionExperimentSet(ubic.gemma.model.analysis.expression.ExpressionExperimentSet) ArrayDesignValueObject(ubic.gemma.model.expression.arrayDesign.ArrayDesignValueObject) SearchSettingsValueObject(ubic.gemma.model.common.search.SearchSettingsValueObject) FactorValueValueObject(ubic.gemma.model.expression.experiment.FactorValueValueObject) BioSequenceValueObject(ubic.gemma.model.genome.sequenceAnalysis.BioSequenceValueObject) ExpressionExperimentValueObject(ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject) CompositeSequenceValueObject(ubic.gemma.model.expression.designElement.CompositeSequenceValueObject) CharacteristicValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject)

Example 2 with FactorValueValueObject

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

the class DifferentialExpressionSearchTaskImpl method filterFactorValues.

/**
 * @param analysis              anaysis
 * @param factorValues          for a factor used for a particular resultset
 * @param baselineFactorValueId id
 * @return fv vos
 */
private List<FactorValueValueObject> filterFactorValues(DifferentialExpressionAnalysisValueObject analysis, Collection<FactorValueValueObject> factorValues, long baselineFactorValueId) {
    List<FactorValueValueObject> filteredFactorValues = new LinkedList<>();
    Collection<FactorValueValueObject> keepForSubSet = this.maybeGetSubSetFactorValuesToKeep(analysis, factorValues.iterator().next().getFactorId());
    for (FactorValueValueObject factorValue : factorValues) {
        if (factorValue.getId().equals(baselineFactorValueId))
            // Skip baseline
            continue;
        // skip fvs not used in the subset, if it is a subset
        if (keepForSubSet != null && !keepForSubSet.contains(factorValue))
            continue;
        filteredFactorValues.add(factorValue);
    }
    return filteredFactorValues;
}
Also used : FactorValueValueObject(ubic.gemma.model.expression.experiment.FactorValueValueObject)

Example 3 with FactorValueValueObject

use of ubic.gemma.model.expression.experiment.FactorValueValueObject 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 FactorValueValueObject

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

the class DifferentialExpressionSearchTaskImpl method addConditionsToSearchResultValueObject.

/**
 * Get information on the conditions to be searched. This is not part of the query for the results themselves, but
 * uses the database to get metadata/summaries about the analyses that will be used. Initializes the searchResult
 * value object. Later, values which are non-missing will be replaced with either 'non-significant' or 'significant'
 * results.
 *
 * @param searchResult to be initialized
 * @return list of the resultSets that should be queried.
 */
private List<DiffExResultSetSummaryValueObject> addConditionsToSearchResultValueObject(DifferentialExpressionGenesConditionsValueObject searchResult) {
    StopWatch watch = new StopWatch("addConditionsToSearchResultValueObject");
    watch.start("Add conditions to search result value object");
    List<DiffExResultSetSummaryValueObject> usedResultSets = new LinkedList<>();
    int i = 0;
    DifferentialExpressionSearchTaskImpl.log.info("Loading " + experimentGroupName + " experiments...");
    // database hit: important that this be fast.
    Map<ExpressionExperimentDetailsValueObject, Collection<DifferentialExpressionAnalysisValueObject>> analyses = differentialExpressionAnalysisService.getAnalysesByExperiment(EntityUtils.getIds(experimentGroup));
    experiment: for (ExpressionExperimentDetailsValueObject bas : analyses.keySet()) {
        Collection<DifferentialExpressionAnalysisValueObject> analysesForExperiment = this.filterAnalyses(analyses.get(bas));
        if (analysesForExperiment.isEmpty()) {
            continue;
        }
        /*
             * There will often just be one analysis for the experiment. Exception would be when there is subsetting.
             */
        for (DifferentialExpressionAnalysisValueObject analysis : analysesForExperiment) {
            List<DiffExResultSetSummaryValueObject> resultSets = this.filterResultSets(analysis);
            usedResultSets.addAll(resultSets);
            if (resultSets.isEmpty()) {
                DifferentialExpressionSearchTaskImpl.log.info("No resultSets usable for " + bas.getId());
            }
            for (DiffExResultSetSummaryValueObject resultSet : resultSets) {
                // sanity check.
                assert resultSet.getNumberOfDiffExpressedProbes() != null;
                // interactions not okay
                assert resultSet.getExperimentalFactors().size() == 1;
                ExperimentalFactorValueObject factor = resultSet.getExperimentalFactors().iterator().next();
                Collection<FactorValueValueObject> factorValues = this.filterFactorValues(analysis, factor.getValues(), resultSet.getBaselineGroup().getId());
                if (factorValues.isEmpty()) {
                    /*
                         * This can only happen if there is just a baseline factorvalue. Even for one-sided tests //
                         * that // won't be the case.
                         */
                    DifferentialExpressionSearchTaskImpl.log.warn("Nothing usable for resultSet=" + resultSet.getResultSetId());
                    continue;
                }
                for (FactorValueValueObject factorValue : factorValues) {
                    Condition condition = searchResult.new Condition(bas, analysis, resultSet, factorValue);
                    condition.setExperimentGroupName(experimentGroupName);
                    /*
                         * SANITY CHECKS these fields should be filled in. If not, we are going to skip the results.
                         */
                    if (condition.getNumberDiffExpressedProbes() == -1) {
                        DifferentialExpressionSearchTaskImpl.log.warn(bas + ": Error: No hit list sizes for resultSet with ID=" + resultSet.getResultSetId());
                        continue;
                    }
                    if (condition.getNumberOfProbesOnArray() == null || condition.getNumberDiffExpressedProbes() == null) {
                        DifferentialExpressionSearchTaskImpl.log.error(bas + ": Error: Null counts for # diff ex probe or # probes on array, Skipping");
                        continue experiment;
                    } else if (condition.getNumberOfProbesOnArray() < condition.getNumberDiffExpressedProbes()) {
                        DifferentialExpressionSearchTaskImpl.log.error(bas + ": Error: More diff expressed probes than probes on array. Skipping.");
                        continue experiment;
                    }
                    searchResult.addCondition(condition);
                    i++;
                }
            }
        }
    }
    watch.stop();
    if (watch.getTotalTimeMillis() > 100) {
        // This does not include getting the actual diff ex results.
        DifferentialExpressionSearchTaskImpl.log.info("Get information on conditions/analyses for " + i + " factorValues: " + watch.getTotalTimeMillis() + "ms");
    }
    return usedResultSets;
}
Also used : FactorValueValueObject(ubic.gemma.model.expression.experiment.FactorValueValueObject) Condition(ubic.gemma.core.tasks.visualization.DifferentialExpressionGenesConditionsValueObject.Condition) ExpressionExperimentDetailsValueObject(ubic.gemma.model.expression.experiment.ExpressionExperimentDetailsValueObject) ExperimentalFactorValueObject(ubic.gemma.model.expression.experiment.ExperimentalFactorValueObject) StopWatch(org.springframework.util.StopWatch)

Example 5 with FactorValueValueObject

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

the class BioAssayDimensionValueObject method makeDummyBioAssayDimension.

private BioAssayDimension makeDummyBioAssayDimension() {
    assert this.id == null;
    BioAssayDimension fakeBd = BioAssayDimension.Factory.newInstance("Placeholder representing: " + name, description, new ArrayList<BioAssay>());
    Map<Long, ExperimentalFactor> fakeEfs = new HashMap<>();
    for (BioAssayValueObject bav : this.bioAssays) {
        BioAssay ba = BioAssay.Factory.newInstance();
        ba.setId(bav.getId());
        ba.setName(bav.getName());
        ba.setDescription("Fake placeholder");
        BioMaterial sampleUsed = BioMaterial.Factory.newInstance();
        BioMaterialValueObject bmVo = bav.getSample();
        assert bmVo != null;
        sampleUsed.setId(bmVo.getId());
        sampleUsed.setName(bmVo.getName());
        sampleUsed.setDescription("Fake placeholder");
        for (IdentifiableValueObject iVo : bmVo.getFactorValueObjects()) {
            FactorValueValueObject fvVo = (FactorValueValueObject) iVo;
            FactorValue fv = FactorValue.Factory.newInstance();
            assert fvVo.getId() != null;
            fv.setId(fvVo.getId());
            assert fvVo.getValue() != null;
            fv.setValue(fvVo.getValue());
            Long efId = fvVo.getFactorId();
            ExperimentalFactor ef;
            if (fakeEfs.containsKey(efId)) {
                ef = fakeEfs.get(efId);
            } else {
                ef = ExperimentalFactor.Factory.newInstance();
                ef.setId(efId);
                ef.setName(fvVo.getCategory());
                ef.setType(fvVo.isMeasurement() ? FactorType.CONTINUOUS : FactorType.CATEGORICAL);
                fakeEfs.put(efId, ef);
            }
            ef.getFactorValues().add(fv);
            fv.setExperimentalFactor(ef);
            sampleUsed.getFactorValues().add(fv);
        }
        ba.setSampleUsed(sampleUsed);
        ArrayDesign ad = ArrayDesign.Factory.newInstance();
        ArrayDesignValueObject adVo = bav.getArrayDesign();
        assert adVo != null;
        ad.setId(adVo.getId());
        ad.setShortName(adVo.getShortName());
        ad.setDescription("Fake placeholder");
        ba.setArrayDesignUsed(ad);
        fakeBd.getBioAssays().add(ba);
    }
    return fakeBd;
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) FactorValueValueObject(ubic.gemma.model.expression.experiment.FactorValueValueObject) FactorValue(ubic.gemma.model.expression.experiment.FactorValue) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) ArrayDesignValueObject(ubic.gemma.model.expression.arrayDesign.ArrayDesignValueObject) BioAssayValueObject(ubic.gemma.model.expression.bioAssay.BioAssayValueObject) IdentifiableValueObject(ubic.gemma.model.IdentifiableValueObject) BioMaterialValueObject(ubic.gemma.model.expression.biomaterial.BioMaterialValueObject) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Aggregations

FactorValueValueObject (ubic.gemma.model.expression.experiment.FactorValueValueObject)6 FactorValue (ubic.gemma.model.expression.experiment.FactorValue)3 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)2 ArrayDesignValueObject (ubic.gemma.model.expression.arrayDesign.ArrayDesignValueObject)2 ExperimentalFactorValueObject (ubic.gemma.model.expression.experiment.ExperimentalFactorValueObject)2 HashSet (java.util.HashSet)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1 StopWatch (org.springframework.util.StopWatch)1 SearchResult (ubic.gemma.core.search.SearchResult)1 Condition (ubic.gemma.core.tasks.visualization.DifferentialExpressionGenesConditionsValueObject.Condition)1 IdentifiableValueObject (ubic.gemma.model.IdentifiableValueObject)1 ExpressionExperimentSet (ubic.gemma.model.analysis.expression.ExpressionExperimentSet)1 BibliographicReference (ubic.gemma.model.common.description.BibliographicReference)1 Characteristic (ubic.gemma.model.common.description.Characteristic)1 SearchSettingsValueObject (ubic.gemma.model.common.search.SearchSettingsValueObject)1 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)1 BioAssayValueObject (ubic.gemma.model.expression.bioAssay.BioAssayValueObject)1 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)1 BioMaterialValueObject (ubic.gemma.model.expression.biomaterial.BioMaterialValueObject)1 CompositeSequenceValueObject (ubic.gemma.model.expression.designElement.CompositeSequenceValueObject)1