Search in sources :

Example 16 with Characteristic

use of ubic.gemma.model.common.description.Characteristic in project Gemma by PavlidisLab.

the class CharacteristicBrowserController method browse.

public JsonReaderResponse<AnnotationValueObject> browse(ListBatchCommand batch) {
    Integer count = characteristicService.countAll();
    List<AnnotationValueObject> results = new ArrayList<>();
    Collection<Characteristic> records;
    if (StringUtils.isNotBlank(batch.getSort())) {
        String o = batch.getSort();
        String orderBy;
        switch(o) {
            case "className":
                orderBy = "category";
                break;
            case "termName":
                orderBy = "value";
                break;
            case "evidenceCode":
                orderBy = "evidenceCode";
                break;
            default:
                throw new IllegalArgumentException("Unknown sort field: " + o);
        }
        boolean descending = batch.getDir() != null && batch.getDir().equalsIgnoreCase("DESC");
        records = characteristicService.browse(batch.getStart(), batch.getLimit(), orderBy, descending);
    } else {
        records = characteristicService.browse(batch.getStart(), batch.getLimit());
    }
    Map<Characteristic, Object> charToParent = characteristicService.getParents(records);
    for (Object o : records) {
        Characteristic c = (Characteristic) o;
        Object parent = charToParent.get(c);
        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);
    }
    return new JsonReaderResponse<>(results, count);
}
Also used : Characteristic(ubic.gemma.model.common.description.Characteristic) VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) AnnotationValueObject(ubic.gemma.model.common.description.AnnotationValueObject) ArrayList(java.util.ArrayList) AnnotationValueObject(ubic.gemma.model.common.description.AnnotationValueObject) JsonReaderResponse(ubic.gemma.web.remote.JsonReaderResponse)

Example 17 with Characteristic

use of ubic.gemma.model.common.description.Characteristic in project Gemma by PavlidisLab.

the class CharacteristicBrowserController method populateClassValues.

private void populateClassValues(Characteristic c, AnnotationValueObject avo) {
    if (c instanceof VocabCharacteristic) {
        VocabCharacteristic vc = (VocabCharacteristic) c;
        avo.setClassUri(vc.getCategoryUri());
        avo.setTermUri(vc.getValueUri());
        avo.setObjectClass(VocabCharacteristic.class.getSimpleName());
    } else {
        avo.setObjectClass(Characteristic.class.getSimpleName());
    }
}
Also used : Characteristic(ubic.gemma.model.common.description.Characteristic) VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic)

Example 18 with Characteristic

use of ubic.gemma.model.common.description.Characteristic in project Gemma by PavlidisLab.

the class CharacteristicUpdateTaskImpl method doUpdate.

private TaskResult doUpdate() {
    Collection<AnnotationValueObject> avos = taskCommand.getAnnotationValueObjects();
    if (avos.size() == 0)
        return new TaskResult(taskCommand, false);
    log.info("Updating " + avos.size() + " characteristics or uncharacterized factor values...");
    StopWatch timer = new StopWatch();
    timer.start();
    Collection<Characteristic> asChars = convertToCharacteristic(avos);
    Collection<FactorValue> factorValues = convertToFactorValuesWithCharacteristics(avos);
    if (asChars.size() == 0 && factorValues.size() == 0) {
        log.info("Nothing to update");
        return new TaskResult(taskCommand, false);
    }
    for (FactorValue factorValue : factorValues) {
        factorValueService.update(factorValue);
    }
    if (asChars.size() == 0)
        return new TaskResult(taskCommand, true);
    Map<Characteristic, Object> charToParent = characteristicService.getParents(asChars);
    for (Characteristic cFromClient : asChars) {
        Long characteristicId = cFromClient.getId();
        if (characteristicId == null) {
            continue;
        }
        Characteristic cFromDatabase = characteristicService.load(characteristicId);
        if (cFromDatabase == null) {
            log.warn("No such characteristic with id=" + characteristicId);
            continue;
        }
        VocabCharacteristic vcFromClient = (cFromClient instanceof VocabCharacteristic) ? (VocabCharacteristic) cFromClient : null;
        VocabCharacteristic vcFromDatabase = (cFromDatabase instanceof VocabCharacteristic) ? (VocabCharacteristic) cFromDatabase : null;
        /*
             * if one of the characteristics is a VocabCharacteristic and the other is not, we have to change the
             * characteristic in the database so that it matches the one from the client; since we can't change the
             * class of the object, we have to remove the old characteristic and make a new one of the appropriate
             * class.
             */
        Object parent = charToParent.get(cFromDatabase);
        /*
             * Check needed because Characteristics are not securable.
             */
        if (parent != null && Securable.class.isAssignableFrom(parent.getClass()) && !securityService.isEditable((Securable) parent)) {
            throw new AccessDeniedException("Access is denied");
        }
        if (vcFromClient != null && vcFromDatabase == null) {
            VocabCharacteristic vc = VocabCharacteristic.Factory.newInstance();
            vc.setValue(StringUtils.strip(cFromDatabase.getValue()));
            vc.setEvidenceCode(cFromDatabase.getEvidenceCode());
            vc.setDescription(cFromDatabase.getDescription());
            vc.setCategory(cFromDatabase.getCategory());
            vc.setName(cFromDatabase.getName());
            vcFromDatabase = (VocabCharacteristic) characteristicService.create(vc);
            removeFromParent(cFromDatabase, parent);
            characteristicService.remove(cFromDatabase);
            addToParent(vcFromDatabase, parent);
            cFromDatabase = vcFromDatabase;
        } else if (vcFromClient == null && vcFromDatabase != null) {
            // don't copy AuditTrail or Status to avoid cascade error... vcFromDatabase.getAuditTrail()
            cFromDatabase = characteristicService.create(Characteristic.Factory.newInstance(vcFromDatabase.getName(), vcFromDatabase.getDescription(), null, StringUtils.strip(vcFromDatabase.getValue()), vcFromDatabase.getCategory(), vcFromDatabase.getCategoryUri(), vcFromDatabase.getEvidenceCode()));
            removeFromParent(vcFromDatabase, parent);
            characteristicService.remove(vcFromDatabase);
            addToParent(cFromDatabase, parent);
        }
        /*
             * at this point, cFromDatabase points to the class-corrected characteristic in the database that must be
             * updated with the information coming from the client.
             */
        assert cFromDatabase != null;
        cFromDatabase.setValue(cFromClient.getValue());
        cFromDatabase.setCategory(cFromClient.getCategory());
        if (cFromDatabase instanceof VocabCharacteristic) {
            vcFromDatabase = (VocabCharacteristic) cFromDatabase;
            if (vcFromClient != null) {
                if (vcFromDatabase.getValueUri() == null || vcFromDatabase.getValueUri() == null || !vcFromDatabase.getValueUri().equals(vcFromClient.getValueUri())) {
                    log.info("Characteristic value update: " + vcFromDatabase + " " + vcFromDatabase.getValueUri() + " -> " + vcFromClient.getValueUri() + " associated with " + parent);
                    vcFromDatabase.setValueUri(vcFromClient.getValueUri());
                }
                if (vcFromDatabase.getCategory() == null || vcFromDatabase.getCategoryUri() == null || !vcFromDatabase.getCategoryUri().equals(vcFromClient.getCategoryUri())) {
                    log.info("Characteristic category update: " + vcFromDatabase + " " + vcFromDatabase.getCategoryUri() + " -> " + vcFromClient.getCategoryUri() + " associated with " + parent);
                    vcFromDatabase.setCategoryUri(vcFromClient.getCategoryUri());
                }
            }
        }
        if (cFromClient.getEvidenceCode() == null) {
            // characteristic has been manually updated
            cFromDatabase.setEvidenceCode(GOEvidenceCode.IC);
        } else {
            if (!cFromDatabase.getEvidenceCode().equals(cFromClient.getEvidenceCode())) {
                log.info("Characteristic evidence code update: " + cFromDatabase + " " + cFromDatabase.getEvidenceCode() + " -> " + cFromClient.getEvidenceCode());
            }
            // let them change it.
            cFromDatabase.setEvidenceCode(cFromClient.getEvidenceCode());
        }
        characteristicService.update(cFromDatabase);
    }
    timer.stop();
    if (timer.getTime() > 1000) {
        log.info("Update took: " + timer.getTime());
    }
    return new TaskResult(taskCommand, true);
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) FactorValue(ubic.gemma.model.expression.experiment.FactorValue) Characteristic(ubic.gemma.model.common.description.Characteristic) VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) AnnotationValueObject(ubic.gemma.model.common.description.AnnotationValueObject) VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) StopWatch(org.apache.commons.lang3.time.StopWatch) TaskResult(ubic.gemma.core.job.TaskResult) AnnotationValueObject(ubic.gemma.model.common.description.AnnotationValueObject)

Example 19 with Characteristic

use of ubic.gemma.model.common.description.Characteristic in project Gemma by PavlidisLab.

the class CharacteristicUpdateTaskImpl method convertToCharacteristic.

/**
 * Convert incoming AVOs into Characteristics (if the AVO objectClass is not FactorValue)
 */
private Collection<Characteristic> convertToCharacteristic(Collection<AnnotationValueObject> avos) {
    Collection<Characteristic> result = new HashSet<>();
    for (AnnotationValueObject avo : avos) {
        if (avo.getObjectClass() != null && avo.getObjectClass().equals(FactorValue.class.getSimpleName()))
            continue;
        VocabCharacteristic vc = convertAvo2Characteristic(avo);
        result.add(vc);
    }
    return result;
}
Also used : Characteristic(ubic.gemma.model.common.description.Characteristic) VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) AnnotationValueObject(ubic.gemma.model.common.description.AnnotationValueObject) VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) HashSet(java.util.HashSet)

Example 20 with Characteristic

use of ubic.gemma.model.common.description.Characteristic in project Gemma by PavlidisLab.

the class ExpressionPersister method persistExperimentalFactor.

/**
 * Note that this uses 'create', not 'findOrCreate'.
 */
private ExperimentalFactor persistExperimentalFactor(ExperimentalFactor experimentalFactor) {
    if (!this.isTransient(experimentalFactor) || experimentalFactor == null)
        return experimentalFactor;
    assert experimentalFactor.getType() != null;
    this.fillInExperimentalFactorAssociations(experimentalFactor);
    // in case of retry
    Characteristic category = experimentalFactor.getCategory();
    if (this.isTransient(category)) {
        category.setId(null);
        if (category.getAuditTrail() != null && this.isTransient(category.getAuditTrail())) {
            category.getAuditTrail().setId(null);
        }
    }
    assert (!this.isTransient(experimentalFactor.getExperimentalDesign()));
    return experimentalFactorDao.create(experimentalFactor);
}
Also used : Characteristic(ubic.gemma.model.common.description.Characteristic)

Aggregations

Characteristic (ubic.gemma.model.common.description.Characteristic)46 VocabCharacteristic (ubic.gemma.model.common.description.VocabCharacteristic)32 StopWatch (org.apache.commons.lang3.time.StopWatch)7 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)7 CharacteristicValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject)7 AnnotationValueObject (ubic.gemma.model.common.description.AnnotationValueObject)6 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)6 FactorValue (ubic.gemma.model.expression.experiment.FactorValue)6 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 SearchSettingsValueObject (ubic.gemma.model.common.search.SearchSettingsValueObject)4 BioSequenceValueObject (ubic.gemma.model.genome.sequenceAnalysis.BioSequenceValueObject)4 OntologyTerm (ubic.basecode.ontology.model.OntologyTerm)3 BibliographicReferenceValueObject (ubic.gemma.model.common.description.BibliographicReferenceValueObject)3 ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)3 GeneEvidenceValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.GeneEvidenceValueObject)3 ConcurrentHashSet (org.compass.core.util.concurrent.ConcurrentHashSet)2 TaskResult (ubic.gemma.core.job.TaskResult)2 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)2 Treatment (ubic.gemma.model.expression.biomaterial.Treatment)2