Page 1 of 1

How to edit LineData ROIs in OMERO from Java/MATLAB?

PostPosted: Thu Jan 24, 2019 5:28 pm
by Kouichi_C_Nakamura
Hello again,

I'm trying to edit LineData ROIs in 33 images programmatically using MATLAB. I want to add text and turn them yellow.

Using Java Gateway, I've come close to the end, but could not use saveAndRrturnObject successfully.

rois is ArrayList of many omero.gateway.model.ROIdata objects. In the snippet below, I'm trying to obtain Shape of that LineData ROIs.

Code: Select all

j = rois.iterator();

k = 0;
ind = zeros(1,2);

while j.hasNext()
    k = k + 1;
    roi = j.next();
    alist = roi.getShapes(0,0);
   
    % Do something
    shape = alist.get(0);
   
    if isa(shape,'omero.gateway.model.LineData')
        % disp(methods(shape) )
       
        switch shape.getX1()
            case 15000
                assert(shape.getX2() == 15000)
               
                shape.setText('Bregma') % set new text
                disp(k)
                ind(1) = k - 1;

        end
       
       
    end
   
end

bregma = rois.get(ind(1)).getShapes(0,0).get(0)


bregma =
omero.gateway.model.LineData (id=102625)

Code: Select all
ss1 = bregma.getShapeSettings;
ss1.setStroke(java.awt.Color.YELLOW) % set new stroke color


dm = getGatewayFacility(gateway,'DataManagerFacility'); % https://gist.github.com/kouichi-c-nakamura/1fee6b8b33a227d47854224fa185bb94
ctx = omero.gateway.SecurityContext(user.getGroupId());

roidata = rois.get(ind(1));

roidata =
omero.gateway.model.ROIData (id=102625)

Code: Select all
dm.saveAndReturnObject(ctx, roidata ) % does not work


Java error message (excerpt)

Code: Select all
Cannot update the object.omero.OptimisticLockException

serverStackTrace = "ome.conditions.OptimisticLockException: You are not authorized to change the update event for ome.model.roi.Line:Id_102625 from ome.model.meta.Event:Id_26965 to ome.model.meta.Event:Id_22508

You may need to reload the object before continuing.

at ome.security.basic.OmeroInterceptor.managedEvent(OmeroInterceptor.java:1195)


Can anybody show me a way forward, please?

Thank you,
Kouichi

Re: How to edit LineData ROIs in OMERO from Java/MATLAB?

PostPosted: Sun Jan 27, 2019 10:27 pm
by jburel
Dear Kouichi

The error means that the object needs to be reloaded in order to be saved. Saving the "roi graph" is not a simple as one will expect.
Did you try to use the Java Gateway? it has a method ``saveROIs`` that implements the various steps required to avoid the error you reported when saving a ROI.
See https://github.com/openmicroscopy/openm ... ility.java


Cheers

Jmarie

Re: How to edit LineData ROIs in OMERO from Java/MATLAB?

PostPosted: Mon Jan 28, 2019 11:02 am
by Kouichi_C_Nakamura
Thanks a lot, Jmarie,

Using omero.gateway.facility.ROIFacility.saveROIs(), the editing just worked as I expected; I was able to add Text to and change the color of the stroke of two LineData ROIs.

MATLAB code
https://gist.github.com/kouichi-c-nakam ... b7409f5a63

Cheers,
Kouichi