We're Hiring!

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

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 edit LineData ROIs in OMERO from Java/MATLAB?

Postby Kouichi_C_Nakamura » Thu Jan 24, 2019 5:28 pm

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

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

Postby jburel » Sun Jan 27, 2019 10:27 pm

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
User avatar
jburel
Team Member
 
Posts: 348
Joined: Thu May 21, 2009 6:38 pm
Location: dundee

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

Postby Kouichi_C_Nakamura » Mon Jan 28, 2019 11:02 am

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


Return to User Discussion

Who is online

Users browsing this forum: Google [Bot] and 0 guests

cron