use of ubic.gemma.model.common.description.Characteristic in project Gemma by PavlidisLab.
the class CharacteristicDaoImpl method getParents.
@Override
public Map<Characteristic, Object> getParents(Class<?> parentClass, Collection<Characteristic> characteristics) {
Map<Characteristic, Object> charToParent = new HashMap<>();
if (characteristics == null || characteristics.size() == 0) {
return charToParent;
}
if (AbstractDao.log.isDebugEnabled()) {
Collection<String> uris = new HashSet<>();
for (Characteristic c : characteristics) {
if (c instanceof VocabCharacteristic) {
VocabCharacteristic vc = (VocabCharacteristic) c;
if (vc.getValueUri() == null)
continue;
uris.add(vc.getValueUri());
}
}
AbstractDao.log.debug("For class=" + parentClass.getSimpleName() + ": " + characteristics.size() + " Characteristics have URIS:\n" + StringUtils.join(uris, "\n"));
}
StopWatch timer = new StopWatch();
timer.start();
for (Collection<Characteristic> batch : new BatchIterator<>(characteristics, CharacteristicDaoImpl.BATCH_SIZE)) {
this.batchGetParents(parentClass, batch, charToParent);
}
if (timer.getTime() > 1000) {
AbstractDao.log.info("Fetch parents of characteristics: " + timer.getTime() + "ms for " + characteristics.size() + " elements for class=" + parentClass.getSimpleName());
}
return charToParent;
}
use of ubic.gemma.model.common.description.Characteristic 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.common.description.Characteristic in project Gemma by PavlidisLab.
the class ExperimentalDesignControllerImpl method createFactorValue.
@Override
public void createFactorValue(EntityDelegator e) {
if (e == null || e.getId() == null)
return;
ExperimentalFactor ef = experimentalFactorService.load(e.getId());
if (ef == null) {
throw new EntityNotFoundException("Experimental factor with ID=" + e.getId() + " could not be accessed for editing");
}
Collection<Characteristic> chars = new HashSet<>();
for (FactorValue fv : ef.getFactorValues()) {
// noinspection LoopStatementThatDoesntLoop // No, but its an effective way of doing this
for (Characteristic c : fv.getCharacteristics()) {
chars.add(this.createTemplateCharacteristic(c));
break;
}
}
if (chars.isEmpty()) {
if (ef.getCategory() == null) {
throw new IllegalArgumentException("You cannot create new factor values on a experimental factor that is not defined by a formal Category");
}
chars.add(this.createTemplateCharacteristic(ef.getCategory()));
}
FactorValue fv = FactorValue.Factory.newInstance();
fv.setExperimentalFactor(ef);
fv.setCharacteristics(chars);
ExpressionExperiment ee = experimentalDesignService.getExpressionExperiment(ef.getExperimentalDesign());
// this is just a placeholder factor value; use has to edit it.
expressionExperimentService.addFactorValue(ee, fv);
}
use of ubic.gemma.model.common.description.Characteristic in project Gemma by PavlidisLab.
the class ExperimentalDesignControllerImpl method getFactorValuesWithCharacteristics.
@Override
public Collection<FactorValueValueObject> getFactorValuesWithCharacteristics(EntityDelegator e) {
Collection<FactorValueValueObject> result = new HashSet<>();
if (e == null || e.getId() == null) {
return result;
}
ExperimentalFactor ef = this.experimentalFactorService.load(e.getId());
if (ef == null) {
return result;
}
for (FactorValue value : ef.getFactorValues()) {
if (value.getCharacteristics().size() > 0) {
for (Characteristic c : value.getCharacteristics()) {
result.add(new FactorValueValueObject(value, c));
}
} else {
// We just use the experimental factor's characteristic.
Characteristic category = value.getExperimentalFactor().getCategory();
if (category == null) {
category = Characteristic.Factory.newInstance();
category.setValue(value.getExperimentalFactor().getName());
}
result.add(new FactorValueValueObject(value));
}
}
return result;
}
use of ubic.gemma.model.common.description.Characteristic in project Gemma by PavlidisLab.
the class ExperimentalDesignControllerImpl method getFactorValues.
@Override
public Collection<FactorValueValueObject> getFactorValues(EntityDelegator e) {
// FIXME I'm not sure why this keeps getting called with empty fields.
if (e == null || e.getId() == null)
return new HashSet<>();
ExperimentalFactor ef = this.experimentalFactorService.load(e.getId());
if (ef == null)
return new HashSet<>();
Collection<FactorValueValueObject> result = new HashSet<>();
for (FactorValue value : ef.getFactorValues()) {
Characteristic efCategory = value.getExperimentalFactor().getCategory();
if (efCategory == null) {
efCategory = Characteristic.Factory.newInstance();
efCategory.setValue(value.getExperimentalFactor().getName());
}
result.add(new FactorValueValueObject(value, efCategory));
}
return result;
}
Aggregations