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);
}
}
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;
}
Aggregations