Search in sources :

Example 1 with EffectCreatingAnnotator

use of org.molgenis.data.annotation.core.EffectCreatingAnnotator in project molgenis by molgenis.

the class CrudRepositoryAnnotator method annotate.

private void annotate(RepositoryAnnotator annotator, Repository<Entity> repository, DatabaseAction action) {
    if (!repository.getCapabilities().contains(WRITABLE)) {
        throw new UnsupportedOperationException("Currently only writable repositories can be annotated");
    }
    try {
        EntityType entityType = dataService.getMeta().getEntityType(repository.getName());
        if (annotator instanceof EffectCreatingAnnotator) {
            targetMetaData = ((EffectCreatingAnnotator) annotator).getTargetEntityType(entityType);
            if (!dataService.hasRepository(targetMetaData.getId())) {
                // add new entities to new repo
                Repository externalRepository = dataService.getMeta().createRepository(targetMetaData);
                permissionSystemService.giveUserWriteMetaPermissions(targetMetaData);
                runAsSystem(() -> dataService.getMeta().updateEntityType(externalRepository.getEntityType()));
                iterateOverEntitiesAndAnnotate(repository, annotator, DatabaseAction.ADD);
            } else {
                throw new UnsupportedOperationException("This entity has already been annotated with " + annotator.getSimpleName());
            }
        } else {
            runAsSystem(() -> dataService.getMeta().updateEntityType(addAnnotatorMetaDataToRepositories(entityType, attributeFactory, annotator)));
            iterateOverEntitiesAndAnnotate(dataService.getRepository(repository.getName()), annotator, action);
        }
    } catch (AnnotationException ae) {
        deleteResultEntity(annotator, targetMetaData);
        throw new UiAnnotationException(ae);
    } catch (Exception e) {
        deleteResultEntity(annotator, targetMetaData);
        throw new RuntimeException(e);
    }
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Repository(org.molgenis.data.Repository) EffectCreatingAnnotator(org.molgenis.data.annotation.core.EffectCreatingAnnotator) UiAnnotationException(org.molgenis.data.annotation.core.exception.UiAnnotationException) UiAnnotationException(org.molgenis.data.annotation.core.exception.UiAnnotationException) AnnotationException(org.molgenis.data.annotation.core.exception.AnnotationException) UiAnnotationException(org.molgenis.data.annotation.core.exception.UiAnnotationException) AnnotationException(org.molgenis.data.annotation.core.exception.AnnotationException)

Example 2 with EffectCreatingAnnotator

use of org.molgenis.data.annotation.core.EffectCreatingAnnotator in project molgenis by molgenis.

the class CmdLineAnnotatorUtils method getOutputAttributeMetadatasForAnnotator.

private static List<Attribute> getOutputAttributeMetadatasForAnnotator(RepositoryAnnotator annotator, EntityTypeFactory entityTypeFactory, AttributeFactory attributeFactory, List<String> attributesToInclude, VcfRepository vcfRepo) {
    if (!attributesToInclude.isEmpty()) {
        checkSelectedOutputAttributeNames(annotator, attributesToInclude, vcfRepo);
    }
    // If the annotator e.g. SnpEff creates an external repository, collect the output metadata into an mref
    // entity
    // This allows for the header to be written as 'EFFECT annotations: <ouput_attributes> | <ouput_attributes>'
    List<Attribute> outputMetaData = newArrayList();
    if (annotator instanceof EffectCreatingAnnotator || annotator instanceof EffectBasedAnnotator) {
        EntityType effectRefEntity = entityTypeFactory.create(annotator.getSimpleName() + "_EFFECTS");
        for (Attribute outputAttribute : annotator.getOutputAttributes()) {
            effectRefEntity.addAttribute(outputAttribute);
        }
        Attribute effect = attributeFactory.create().setName(EFFECT);
        effect.setDataType(MREF).setRefEntity(effectRefEntity);
        outputMetaData.add(effect);
    } else {
        outputMetaData = annotator.getOutputAttributes();
    }
    return outputMetaData;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute) EffectCreatingAnnotator(org.molgenis.data.annotation.core.EffectCreatingAnnotator) EffectBasedAnnotator(org.molgenis.data.annotation.core.EffectBasedAnnotator)

Aggregations

EffectCreatingAnnotator (org.molgenis.data.annotation.core.EffectCreatingAnnotator)2 EntityType (org.molgenis.data.meta.model.EntityType)2 Repository (org.molgenis.data.Repository)1 EffectBasedAnnotator (org.molgenis.data.annotation.core.EffectBasedAnnotator)1 AnnotationException (org.molgenis.data.annotation.core.exception.AnnotationException)1 UiAnnotationException (org.molgenis.data.annotation.core.exception.UiAnnotationException)1 Attribute (org.molgenis.data.meta.model.Attribute)1