We're Hiring!

How to unlink a MapAnnotation from an Dataset with Gateway?

General user discussion about using the OMERO platform to its fullest. Please ask new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

There are workflow guides for various OMERO functions on our help site - http://help.openmicroscopy.org

You should find answers to any basic questions about using the clients there.

How to unlink a MapAnnotation from an Dataset with Gateway?

Postby Kouichi_C_Nakamura » Tue Jan 29, 2019 11:13 am

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
Kouichi_C_Nakamura
 
Posts: 165
Joined: Thu Oct 19, 2017 1:35 pm

Re: How to unlink a MapAnnotation from an Dataset with Gatew

Postby Dominik » Wed Jan 30, 2019 3:59 pm

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
User avatar
Dominik
Team Member
 
Posts: 149
Joined: Mon Feb 10, 2014 11:26 am

Re: How to unlink a MapAnnotation from an Dataset with Gatew

Postby Dominik » Wed Jan 30, 2019 4:43 pm

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
User avatar
Dominik
Team Member
 
Posts: 149
Joined: Mon Feb 10, 2014 11:26 am

Re: How to unlink a MapAnnotation from an Dataset with Gatew

Postby Kouichi_C_Nakamura » Wed Jan 30, 2019 5:04 pm

Wow, I was expecting a simpler solution. Nevertheless, thank you for the detailed answer.

Best,
Kouichi
Kouichi_C_Nakamura
 
Posts: 165
Joined: Thu Oct 19, 2017 1:35 pm


Return to User Discussion

Who is online

Users browsing this forum: No registered users and 1 guest