We're Hiring!

Using Python API to work with ROI folders

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please 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

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

Using Python API to work with ROI folders

Postby scottdoy » Tue Nov 20, 2018 4:31 pm

Hi all,

I've been working on Python scripts to download ROIs from / upload ROIs to Omero, mostly based on the code examples listed here: https://docs.openmicroscopy.org/omero/5.4.9/developers/Python.html. From those examples I have working code to retrieve ROIs attached to an image as well as create ROIs and upload them to the server.

My question is: How can I use the Python API to work with ROI folders? By "work with", I mean:

  • Can I retrieve a list of all available folders?
  • When retrieving ROIs, can I specify a folder and retrieve only the ROIs associated with that folder?
  • When creating / uploading ROIs, can I specify a folder that the ROI should be associated with?

I'm currently differentiating groups of ROIs by using a specific fill color and the `setTextValue()` method of each polygon object to attach a "standard" free-text descriptor, but this seems like a fragile way of doing things.

I wasn't able to find any documentation on working with the folders in Python, so any help would be appreciated.

Thanks!
scottdoy
 
Posts: 1
Joined: Wed Oct 24, 2018 1:44 pm

Re: Using Python API to work with ROI folders

Postby mtbc » Wed Nov 21, 2018 10:40 am

Dear Scott,

The BlitzGateway object offers us getQueryService() and getUpdateService() which are both very useful for this kind of workflow.

For all available folders,
Code: Select all
folders = query_service.findAll("Folder", None)

For retrieving the ROIs of the folder with ID 1234,
Code: Select all
params = omero.sys.ParametersI()
params.addId(omero.rtypes.rlong(1234))
rois = query_service.findAllByQuery(
        "SELECT l.child FROM FolderRoiLink l WHERE l.parent.id = :id", params)

For saving/updating a ROI in the folder with ID 1234,
Code: Select all
link = omero.model.FolderRoiLinkI()
link.parent = omero.model.FolderI(1234, False)
link.child = roi
link = update_service.saveAndReturnObject(link)

If the ROI is newly created then that too will be saved along with the link above.

Cheers,
Mark
User avatar
mtbc
Team Member
 
Posts: 282
Joined: Tue Oct 23, 2012 10:59 am
Location: Dundee, Scotland


Return to Developer Discussion

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron