We're Hiring!

access OMERO browser from script

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.

access OMERO browser from script

Postby evenhuis » Fri Mar 15, 2019 10:20 am

Hi,

I'm not sure if this is possible within the constraints of the scripting model in Fiji...

What I'd like to be able to do is:

The user to
  • to connect to OMERO using the plugin
  • select one or more images/dataset/projects
  • run the script in Fiji

The script would then
  • get the connection, context etc from the open OMERO session from the previous step (no ID or password needed)
  • get the selected objects
  • process away...
  • upload images / tables

I'm having trouble finding out if the first step in the script is possible.

Cheers,

Chris
evenhuis
 
Posts: 61
Joined: Tue Jan 30, 2018 4:47 am

Re: access OMERO browser from script

Postby jburel » Mon Mar 18, 2019 10:30 am

Hi Chris

We have training scripts that follow those steps
  • connect
  • read data
  • analyse in Fiji
  • upload results as CVS, tables,
  • save ROI
  • save generated images as OME-TIFF (for some scipts)

For example you can find some groovy scripts at
https://github.com/ome/training-scripts ... cal/groovy
We also have jython scripts https://github.com/ome/training-scripts ... cal/jython

For simplicity during the training session, we edit password and user name in the script.
That will need adjusting

Cheers

Jmarie
User avatar
jburel
Team Member
 
Posts: 348
Joined: Thu May 21, 2009 6:38 pm
Location: dundee

Re: access OMERO browser from script

Postby evenhuis » Tue Mar 19, 2019 12:21 am

Hi Jmarie,

I've had a look at the those scripts but I can't find quite what I want there.

Maybe a picture might help:

Screen Shot 2019-03-19 at 11.02.31 am.png
Screen Shot 2019-03-19 at 11.02.31 am.png (237.39 KiB) Viewed 1166 times


Rather than hard coding OMERO object ID in scripts I'd like to be able to get the IDs of the selected images/datasets in the currently opened Fiji-Plugin viewer.

I've made some progress along this front following the documentation here:
https://docs.openmicroscopy.org/omero/5.4.0/developers/Server/Sessions.html

This Jython script creates a session I can lists the open sessions.
Code: Select all
#@ String(label="Staff/StudentID") username
#@ String(label="Email password", style='password') password

#OMERO Server details
host = "omero-app.research.uts.edu.au"
port = 4064

from ome.api import ISession
from omero import client
from ome.system import Principal

cli= client(host,port)
sessF = cli.createSession(username,password)
sess = sessF.getSessionService()
for open_sess in sess.getMyOpenSessions():
   print(open_sess.getUuid())

admin = sessF.getAdminService()
cxt = admin.getEventContext()
#for  d in dir(sess):
#   print(d)
print(cxt.sessionId)
print(cxt.sessionUuid)



Here is the output without the FIJI plugin open
Code: Select all
Started connection_session.py at Tue Mar 19 10:59:14 AEDT 2019
omero.rtypes$RStringI@a967c5c8
41845
a97663c0-555b-4b60-bafe-04e0bfa3f90b


Here is the output with the plugin viewer open
Code: Select all
Started connection_session.py at Tue Mar 19 11:00:03 AEDT 2019
omero.rtypes$RStringI@7779675f
omero.rtypes$RStringI@639ed5
41847
be7b98b2-eee6-4571-abf9-8ddb9caea852


And here it is another time
Code: Select all
Started connection_session.py at Tue Mar 19 11:00:12 AEDT 2019
omero.rtypes$RStringI@3f631e82
omero.rtypes$RStringI@639ed5
41848
4c0a1340-4c1e-48ab-8474-bda132582229


The second session Uuid is persistent and disappears when the Fiji viewer is closed so this must the the Uuid of the Fiji viewer.

I haven't worked out how to use this get the existing session yet. When I try to create a Principal as in the documents I get lots of errors about refcounts.

Any pointers?

Thanks,

Chris
evenhuis
 
Posts: 61
Joined: Tue Jan 30, 2018 4:47 am

Re: access OMERO browser from script

Postby jburel » Tue Mar 19, 2019 9:43 am

Hi Chris

Thanks for the screenshot and clarifying what you wish to achieve.
This will require some investigations, I have never tried to do that workflow.The plugin does not
record any action in the recorder e.g. selected objects so it might require some adjustments
to the plugin to achieve what you want to do.

Here is an example where principal is used in the Java Gateway to connect
https://github.com/openmicroscopy/openm ... .java#L934

Cheers

Jmarie
User avatar
jburel
Team Member
 
Posts: 348
Joined: Thu May 21, 2009 6:38 pm
Location: dundee

Re: access OMERO browser from script

Postby jburel » Tue Mar 19, 2019 4:47 pm

Hi Chris

While travelling, I have been looking at some adjustments to the code
so we can record what you will to achieve such workflow
so far in the recorder, I have added
the session key and the selected object e.g.
Code: Select all
0ee07d1c-5a22-4fca-936a-9647f36c38c2();
omero.gateway.model.ExperimenterData (id=2)();
run("Connect to OMERO");
omero.gateway.model.DatasetData (id=2920)();
omero.gateway.model.DatasetData (id=1996)();


I will look at example script to parse the content of the recorder

I forgot to mention in my previous post that you can connect using a sessionId using the Java gateway
Using the section above you will do
Code: Select all
session = "0ee07d1c-5a22-4fca-936a-9647f36c38c2"
def connect_to_omero() {
    "Connect to OMERO"

    credentials = new LoginCredentials()
    credentials.getServer().setHostname(HOST)
    credentials.getServer().setPort(PORT)
    credentials.getUser().setUsername(session)
    credentials.getUser().setPassword(session)
    simpleLogger = new SimpleLogger()
    gateway = new Gateway(simpleLogger)
    gateway.connect(credentials)
    return gateway

}


Cheers

Jmarie
User avatar
jburel
Team Member
 
Posts: 348
Joined: Thu May 21, 2009 6:38 pm
Location: dundee

Re: access OMERO browser from script

Postby evenhuis » Wed Mar 20, 2019 5:59 am

Hi Jmarie,

thanks for that. I was think a bit more about the problem and I think the right way to go may be to get access to the FIJI plugin, rather than the session from the server. I assume that the selections made in the Fiji plugin are not being send to the server, just the action made on them.

What I'm trying to do is to use the OMERO-FIJI plugin like the ROI Manager in Fiji. In pseudo-code:
Code: Select all
import omero.insight-fijiplugin as ROM # Remote Object Manager

conn = ROM.getInstance()   # get the open instance of the FIJI plugin
if( conn is None ):
   print("Log onto OMERO through the plugin please")
   exit(1);

for obj in conn.getObjectsAsArray():
     if( type(obj) == "Image" ):
          img=conn.getObject(obj)


Do you know if it's possible to load the plugin as library like this? I had a look for the java doc for the plugin but had a hard time finding it amongst the other OMERO documentation.

Cheers,

Chris
evenhuis
 
Posts: 61
Joined: Tue Jan 30, 2018 4:47 am

Re: access OMERO browser from script

Postby jburel » Wed Mar 20, 2019 8:44 pm

Hi Chris

In its current implementation it is not possible to do what you described in pseudo-code
I have made some changes so we could get something like

Code: Select all
import org.openmicroscopy.shoola.MainIJPlugin

session = MainIJPlugin.getSessionId()
//session is null if not connected

results = MainIJPlugin.getSelectedObjects()

keys = results.keySet();
type = keys[0]; //datatype e.g. images
ids = results.get(type) // collection of image ID


Then continue the analysis and save the results using a script

Cheers

Jmarie
User avatar
jburel
Team Member
 
Posts: 348
Joined: Thu May 21, 2009 6:38 pm
Location: dundee

Re: access OMERO browser from script

Postby evenhuis » Sun Mar 24, 2019 11:17 pm

Hi Jmarie,

Something like that would awesome. We set users up analysis scripts to run in Fiji and getting the group and image ID set correctly is struggle.

Being able to grab them the browser would make like a lot easier.

Cheers,

Chris

Code: Select all
import org.openmicroscopy.shoola.MainIJPlugin

session = MainIJPlugin.getSessionId()
//session is null if not connected

results = MainIJPlugin.getSelectedObjects()

keys = results.keySet();
type = keys[0]; //datatype e.g. images
ids = results.get(type) // collection of image ID
evenhuis
 
Posts: 61
Joined: Tue Jan 30, 2018 4:47 am

Re: access OMERO browser from script

Postby jburel » Mon Mar 25, 2019 8:43 am

Hi Chris

Thanks for the feedback and pushing it
I will look at adding this approach in the new version we are currently working on

Cheers

Jmarie
User avatar
jburel
Team Member
 
Posts: 348
Joined: Thu May 21, 2009 6:38 pm
Location: dundee


Return to Developer Discussion

Who is online

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

cron