How to unlink a MapAnnotation from an Dataset with Gateway?
Posted:
Tue Jan 29, 2019 11:13 am
by Kouichi_C_Nakamura
Hello again,
I've made a MapAnnotation and attached it to a wrong dataset using Java Gateway, ``DataManagerFacility.attachAnnotation()``.
I think I can delete that MapAnnotation using ``DataManagerFacility.delete()`` and create a new one to be attached to the right dataset.
But if I want to keep the MapAnnotationI object, while de-attaching or unlinking it from the wrong dataset, how could I do that?
In the session-client approach, ``unlinkAnnotations()`` can be used. But I cannot find the equivalent in Gateway tools.
Best,
Kouichi
Re: How to unlink a MapAnnotation from an Dataset with Gatew
Posted:
Wed Jan 30, 2019 3:59 pm
by Dominik
Unfortunately that's not possible with the Java gateway at the moment. A workaround (quite cumbersome unfortunately) would be using an HQL query to get the annotation link, deleting it via a 'Delete2' command and then creating another annotation link again.
Here's an example moving a MapAnnotation from one image to another:
- Code: Select all
BrowseFacility bf = gw.getFacility(BrowseFacility.class);
MetadataFacility mf = gw.getFacility(MetadataFacility.class);
DataManagerFacility df = gw.getFacility(DataManagerFacility.class);
ImageData fromImg = bf.getImage(userCtx, 1);
ImageData toImg = bf.getImage(userCtx, 2);
MapAnnotationData mad = (MapAnnotationData) mf
.getAnnotations(userCtx, fromImg).iterator().next();
String query = "select link from ImageAnnotationLink link where link.child.id = :annoId and link.parent.id = :imgId";
ParametersI params = new ParametersI();
params.add("annoId", omero.rtypes.rlong(mad.getId()));
params.add("imgId", omero.rtypes.rlong(fromImg.getId()));
ImageAnnotationLinkI link = (ImageAnnotationLinkI) gw
.getQueryService(userCtx).findByQuery(query, params);
ChildOption opt = Requests.option().excludeType("Annotation").build();
Delete2 cmd = Requests.delete().target(link).option(opt).build();
try {
CmdCallbackI cb = gw.submit(userCtx, cmd);
cb.loop(10, 500);
} catch (Throwable e) {
e.printStackTrace();
}
link = new ImageAnnotationLinkI();
link.setChild(mad.asAnnotation());
link.setParent(toImg.asImage());
df.saveAndReturnObject(userCtx, link);
Regards,
Dominik
Re: How to unlink a MapAnnotation from an Dataset with Gatew
Posted:
Wed Jan 30, 2019 4:43 pm
by Dominik
In fact, there's actually a slightly shorter way: You don't have to delete the link, you can just change the parent of the link (in that case you have to load the link together with its nodes, see modified query):
- Code: Select all
String query = "select link from ImageAnnotationLink link join fetch link.child as c join fetch link.parent as p where c.id = :annoId and p.id = :imgId";
ParametersI params = new ParametersI();
params.add("annoId", omero.rtypes.rlong(mad.getId()));
params.add("imgId", omero.rtypes.rlong(fromImg.getId()));
ImageAnnotationLinkI link = (ImageAnnotationLinkI) gw
.getQueryService(userCtx).findByQuery(query, params);
link.setParent(toImg.asImage());
df.saveAndReturnObject(userCtx, link);
Regards,
Dominik
Re: How to unlink a MapAnnotation from an Dataset with Gatew
Posted:
Wed Jan 30, 2019 5:04 pm
by Kouichi_C_Nakamura
Wow, I was expecting a simpler solution. Nevertheless, thank you for the detailed answer.
Best,
Kouichi