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);
}
}
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));
}
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 « 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()) + " « " + 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());
}
}
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);
}
}
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();
}
Aggregations