Page 1 of 1

Interacting with Matlab

PostPosted: Fri Mar 04, 2011 6:48 pm
by sdrulhe
Dear CoUsers,
Could anyone post a basic Matlab script to interact with OME.server ? Something about:
- import or retrieve images from a given given data set, and a given project, stored on a given server?
- for the import : how to specify metadata
- for the retrieval : how to also retrieve time, channel, etc...
I would appreciate a lot for a helping hand :)
Yours,
S D

Re: Interacting with Matlab

PostPosted: Mon Mar 07, 2011 6:31 pm
by jmoore
Hi S D,

for a very simple matlab example you might start by looking at Main.m under the examples. For importing, you will either need to use the GUI client, the CLI client, or the library. You can read more under http://trac.openmicroscopy.org.uk/ome/wiki/ImportLibrary.

Cheers,
~Josh

Re: Interacting with Matlab

PostPosted: Sat Mar 12, 2011 8:45 pm
by sdrulhe
Thanks.
Question: in Insight, I can choose the group I am working with on a given server. I don't see how to select this from a Matlab point of view. it seems that I can just connect to the last group I was working with under Insight...
Code: Select all
loadOmero;
client = omero.client(serverName, serverPort);
session = client.createSession(userID,userPwd);
gateway = session.createGateway;

Re: Interacting with Matlab

PostPosted: Mon Mar 14, 2011 8:41 am
by jmoore
sdrulhe wrote:Thanks.

Sure, no problem.

Question: in Insight, I can choose the group I am working with on a given server. I don't see how to select this from a Matlab point of view. it seems that I can just connect to the last group I was working with under Insight...
Code: Select all
loadOmero;
client = omero.client(serverName, serverPort);
session = client.createSession(userID,userPwd);
gateway = session.createGateway;


If you are working from the develop or dev_4_2 branches of git, or from any of the recent "trunk" or "4.2" builds from Hudson, then you can set the group by passing the "omero.group" property to omero.client:
Code: Select all
   p = java.util.Properties();
   p.setProperty('omero.host', 'example.com');
   p.setProperty('omero.user', 'me');
   p.setProperty('omero.pass', 'super_secret!');
   p.setProperty('omero.group', 'my-group');
   c = loadOmero(p);

If you are working from the released 4.2 version, that will not be possible due to a bug (#2951), and instead you will have to use setSecurityContext:
Code: Select all
client = omero.client(serverName, serverPort);
session = client.createSession(userID,userPwd);
session.setSecurityContext(omero.model.ExperimenterGroupI(GROUP_ID_HERE, false));
gateway = session.createGateway;


Cheers,
~Josh.

Re: Interacting with Matlab

PostPosted: Mon Mar 14, 2011 12:50 pm
by sdrulhe
Great...
I am working with the last release:
Code: Select all
>> disp(omeroVersion);
4.3.0-DEV-956e9264

The second method gives the following result:
Code: Select all
??? No constructor 'omero.model.ExperimenterGroupI' with matching signature found.

Error in ==> OMEtemplatescript at 18
session.setSecurityContext(omero.model.ExperimenterGroupI(groupID, false));

This works:
Code: Select all
p = java.util.Properties();
p.setProperty('omero.host', serverName);
%p.setProperty('omero.port', serverPort);
p.setProperty('omero.user', userID);
p.setProperty('omero.pass', userPwd);
p.setProperty('omero.group', groupID);
[client,session,gateway] = loadOmero(p);
clear p

I did not find how to setup the server port, nor where to look for this... My attempt to define an omero.port failed. :)

Re: Interacting with Matlab

PostPosted: Mon Mar 14, 2011 4:07 pm
by jmoore
sdrulhe wrote:The second method gives the following result:
Code: Select all
??? No constructor 'omero.model.ExperimenterGroupI' with matching signature found.

Error in ==> OMEtemplatescript at 18
session.setSecurityContext(omero.model.ExperimenterGroupI(groupID, false));


What's the type of groupID? If it's omero.rtypes.rlong, you'll need to unwrap it:
Code: Select all
>> loadOmero
--------------------------
OmeroMatlab Toolbox
4.3.0-DEV-808325d1
--------------------------
>> omero.model.ExperimenterGroupI(1, false)

ans =

omero.model.ExperimenterGroupI@1aaa2594

>> groupID = omero.rtypes.rlong(1)

groupID =

omero.rtypes$RLongI@1

>> omero.model.ExperimenterGroupI(groupID.getValue(), false)

ans =

omero.model.ExperimenterGroupI@626f144
>>


This works:
Code: Select all
p = java.util.Properties();
p.setProperty('omero.host', serverName);
%p.setProperty('omero.port', serverPort);
p.setProperty('omero.user', userID);
p.setProperty('omero.pass', userPwd);
p.setProperty('omero.group', groupID);
[client,session,gateway] = loadOmero(p);
clear p

I did not find how to setup the server port, nor where to look for this... My attempt to define an omero.port failed. :)

I'd assume it's a similar issue with the type. Could you try converting serverPort to a string?

Cheers,
~Josh

Re: Interacting with Matlab

PostPosted: Tue Mar 15, 2011 12:50 am
by sdrulhe
What's the type of groupID? If it's omero.rtypes.rlong, you'll need to unwrap it

The type is Matlab string. Don't get how to make it be omero.rtypes.rlong if it is what I need to do.
I'd assume it's a similar issue with the type. Could you try converting serverPort to a string?

Exact, well done!
Now it works perfectly, thanks! :D

Re: Interacting with Matlab

PostPosted: Tue Mar 15, 2011 7:23 am
by jmoore
sdrulhe wrote:
What's the type of groupID? If it's omero.rtypes.rlong, you'll need to unwrap it

The type is Matlab string. Don't get how to make it be omero.rtypes.rlong if it is what I need to do.

Ah, ok. No, the type should be long or java.lang.Long. So, java.lang.Long.valueOf() or similar should work.

I'd assume it's a similar issue with the type. Could you try converting serverPort to a string?

Exact, well done!
Now it works perfectly, thanks! :D

Glad to hear it.
~Josh.