Search in sources :

Example 51 with FactorValue

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

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

Example 53 with FactorValue

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

the class CharacteristicBrowserController method populateParentInformation.

private void populateParentInformation(AnnotationValueObject avo, Object parent) {
    if (parent == null) {
        avo.setParentLink("[Parent hidden or not available, " + avo.getObjectClass() + " ID=" + avo.getId() + "]");
    } else if (parent instanceof ExpressionExperiment) {
        ExpressionExperiment ee = (ExpressionExperiment) parent;
        avo.setParentName(String.format("Experiment: %s", ee.getName()));
        avo.setParentLink(AnchorTagUtil.getExpressionExperimentLink(ee.getId(), avo.getParentName()));
    } else if (parent instanceof BioMaterial) {
        BioMaterial bm = (BioMaterial) parent;
        avo.setParentName(String.format("BioMat: %s", bm.getName()));
        avo.setParentLink(AnchorTagUtil.getBioMaterialLink(bm.getId(), avo.getParentName()));
        ExpressionExperiment ee = expressionExperimentService.findByBioMaterial(bm);
        if (ee != null) {
            avo.setParentOfParentName(String.format("%s", ee.getName()));
            // avo.setParentOfParentDescription( ee.getDescription() );
            avo.setParentOfParentLink(AnchorTagUtil.getExpressionExperimentLink(ee.getId(), avo.getParentOfParentName()));
        } else {
            log.warn("Expression experiment for " + bm + " was null");
        }
    } else if (parent instanceof FactorValue) {
        FactorValue fv = (FactorValue) parent;
        avo.setParentDescription(String.format("FactorValue: %s &laquo; Exp.Factor: %s", (fv.getValue() == null ? "" : ": " + fv.getValue()), fv.getExperimentalFactor().getName()));
        ExpressionExperiment ee = experimentalDesignService.getExpressionExperiment(fv.getExperimentalFactor().getExperimentalDesign());
        avo.setParentOfParentName(String.format("Experimental Design for: %s", ee.getName()));
        avo.setParentOfParentLink(AnchorTagUtil.getExperimentalDesignLink(fv.getExperimentalFactor().getExperimentalDesign().getId(), avo.getParentName()) + "&nbsp;&laquo;&nbsp;" + AnchorTagUtil.getExpressionExperimentLink(ee.getId(), String.format("%s (%s)", StringUtils.abbreviate(ee.getName(), 80), ee.getShortName())));
    } else if (parent instanceof ExperimentalFactor) {
        ExperimentalFactor ef = (ExperimentalFactor) parent;
        avo.setParentLink(AnchorTagUtil.getExperimentalDesignLink(ef.getExperimentalDesign().getId(), "Exp Fac: " + ef.getName() + " (" + StringUtils.abbreviate(ef.getDescription(), 50) + ")"));
        ExpressionExperiment ee = experimentalDesignService.getExpressionExperiment(ef.getExperimentalDesign());
        avo.setParentOfParentName(String.format("%s (%s)", StringUtils.abbreviate(ee.getName(), 80), ee.getShortName()));
        avo.setParentOfParentLink(AnchorTagUtil.getExpressionExperimentLink(ee.getId(), avo.getParentOfParentName()));
    } else if (parent instanceof PhenotypeAssociation) {
        PhenotypeAssociation pa = (PhenotypeAssociation) parent;
        avo.setParentLink("PhenotypeAssoc: " + pa.getGene().getOfficialSymbol());
        avo.setParentDescription(pa.getId().toString());
    }
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) FactorValue(ubic.gemma.model.expression.experiment.FactorValue) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) PhenotypeAssociation(ubic.gemma.model.association.phenotype.PhenotypeAssociation) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment)

Example 54 with FactorValue

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

the class ExpressionExperimentQCController method getCategories.

/**
 * Support method for writeDetailedFactorAnalysis
 *
 * @param categories map of factor ID to text value. Strings will be unique, but possibly abbreviated and/or munged.
 */
private void getCategories(Map<Long, ExperimentalFactor> efIdMap, Long efId, Map<Long, String> categories) {
    ExperimentalFactor ef = efIdMap.get(efId);
    if (ef == null)
        return;
    int maxCategoryLabelLength = 10;
    for (FactorValue fv : ef.getFactorValues()) {
        String value = fv.getValue();
        if (StringUtils.isBlank(value) || value.equals("null")) {
            for (Characteristic c : fv.getCharacteristics()) {
                if (StringUtils.isNotBlank(c.getValue())) {
                    if (StringUtils.isNotBlank(value)) {
                        value = value + "; " + c.getValue();
                    } else {
                        value = c.getValue();
                    }
                }
            }
        }
        if (StringUtils.isBlank(value)) {
            value = fv.toString() + "--??";
        }
        if (value.startsWith(ExperimentalDesignUtils.BATCH_FACTOR_NAME_PREFIX)) {
            value = value.replaceFirst(ExperimentalDesignUtils.BATCH_FACTOR_NAME_PREFIX, "");
        } else {
            value = StringUtils.abbreviate(value, maxCategoryLabelLength);
        }
        while (categories.values().contains(value)) {
            // make unique, kludge, will end up with string of ++++
            value = value + "+";
        }
        categories.put(fv.getId(), value);
    }
}
Also used : FactorValue(ubic.gemma.model.expression.experiment.FactorValue) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) Characteristic(ubic.gemma.model.common.description.Characteristic)

Example 55 with FactorValue

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

the class DesignMatrixRowValueObject method getFactorValueString.

private String getFactorValueString(Collection<FactorValue> factorValues) {
    StringBuilder buf = new StringBuilder();
    for (Iterator<FactorValue> i = factorValues.iterator(); i.hasNext(); ) {
        FactorValue fv = i.next();
        buf.append(getFactorValueString(fv));
        if (i.hasNext())
            buf.append(", ");
    }
    return buf.toString();
}
Also used : FactorValue(ubic.gemma.model.expression.experiment.FactorValue)

Aggregations

FactorValue (ubic.gemma.model.expression.experiment.FactorValue)55 ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)30 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)27 Test (org.junit.Test)12 VocabCharacteristic (ubic.gemma.model.common.description.VocabCharacteristic)8 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)8 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)8 HashSet (java.util.HashSet)7 Characteristic (ubic.gemma.model.common.description.Characteristic)6 DifferentialExpressionAnalysis (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis)5 ArrayList (java.util.ArrayList)4 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)4 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)4 FactorValueValueObject (ubic.gemma.model.expression.experiment.FactorValueValueObject)4 StopWatch (org.apache.commons.lang3.time.StopWatch)3 DifferentialExpressionAnalysisResult (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult)3 ExpressionAnalysisResultSet (ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)3 AnnotationValueObject (ubic.gemma.model.common.description.AnnotationValueObject)3 Measurement (ubic.gemma.model.common.measurement.Measurement)3 BioAssaySet (ubic.gemma.model.expression.experiment.BioAssaySet)3