We're Hiring!

Is there a way to retrieve OME-XML directly from OMERO?

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.

Is there a way to retrieve OME-XML directly from OMERO?

Postby Kouichi_C_Nakamura » Sat Nov 17, 2018 9:50 am

From webclient, using General > Download > Export as OME-TIFF, one can generate a OME-TIFF file on the server and then download it. Using command line tools etc, one can then extract the embedded OME-XML metadata.

I wonder if there is a way to directly extract OME-XML from an image in OMERO using Java API. But I could not find relevant Java class in API. Is there any way to achieve this by programming?
Last edited by Kouichi_C_Nakamura on Sat Nov 17, 2018 5:58 pm, edited 1 time in total.
Kouichi_C_Nakamura
 
Posts: 165
Joined: Thu Oct 19, 2017 1:35 pm

Re: Is there a way to retrieve OME-XML directly from OMERO?

Postby jburel » Sat Nov 17, 2018 5:35 pm

Hi Kouichi

You are correct, neither insight nor web expose the option to export the Image as OME-XML.
You can do it using the Exporter service
Follow some pseudo-code using the Java Gateway
Code: Select all
final int INC = 262144 //Maximum size of pixels read at once
SecurityContext ctx;
File f;
ExporterPrx store = gateway.getExporterService(ctx)
long size = store.generateXml();
FileOutputStream stream = new FileOutputStream(f);
for (offset = 0; (offset+INC) < size;) {
    stream.write(store.read(offset, INC));
    offset += INC;
}
stream.write(store.read(offset, (int) (size-offset)));
stream.close();


I hope it is helpful

Cheers

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

Re: Is there a way to retrieve OME-XML directly from OMERO?

Postby Kouichi_C_Nakamura » Sat Nov 17, 2018 8:14 pm

Thank you for the code snippet.

I've translated it into MATLAB code without understanding what's happening.

Code: Select all
userName = '********';

password = input('password:','s');

host = 'demo.openmicroscopy.org';

INC = 262144; % //Maximum size of pixels read at once



[gateway,user,cred] = loadOmeroGateway(userName, password, host);

ctx = omero.gateway.SecurityContext(user.getGroupId()); % 'omero.gateway.SecurityContext'
store = gateway.getExporterService(ctx); % 'omero.api.ExporterPrxHelper'

SIZE = store.generateXml(); %102

f = java.io.File('out.xml');

stream = java.io.FileOutputStream(f);

offset = 0;
while offset+INC < SIZE
    stream.write(store.read(offset, INC));
    offset = offset + INC;
end

stream.write(store.read(offset, int32(SIZE-offset)));
stream.close();


using loadOmeroGateway.m of mine:
https://gist.github.com/kouichi-c-nakam ... ogateway-m

This resulted in

Code: Select all
<?xml version="1.0" encoding="UTF-8"?><OME xmlns="http://www.openmicroscopy.org/Schemas/OME/2016-06"/>


I need to specify an image before retrieving XML. How could I do that?
Kouichi_C_Nakamura
 
Posts: 165
Joined: Thu Oct 19, 2017 1:35 pm

Re: Is there a way to retrieve OME-XML directly from OMERO?

Postby jburel » Sat Nov 17, 2018 9:54 pm

Hi Kouichi

Sorry I forgot a line
You need to add the following after creating the Exporter Service
Code: Select all
store.addImage(imageID);
User avatar
jburel
Team Member
 
Posts: 348
Joined: Thu May 21, 2009 6:38 pm
Location: dundee

Re: Is there a way to retrieve OME-XML directly from OMERO?

Postby Kouichi_C_Nakamura » Sat Nov 17, 2018 10:46 pm

WORKED LIKE A MAGIC! Thank you so much, Jmarie.

Best,
Kouichi

Code: Select all
imageID = 56134;

[gateway,user,cred] = loadOmeroGateway(userName, password, host);

ctx = omero.gateway.SecurityContext(user.getGroupId()); % 'omero.gateway.SecurityContext'
store = gateway.getExporterService(ctx); % 'omero.api.ExporterPrxHelper'

store.addImage(imageID);

SIZE = store.generateXml(); %102

f = java.io.File('out.xml');

stream = java.io.FileOutputStream(f);

offset = 0;
while offset+INC < SIZE
    stream.write(store.read(offset, INC));
    offset = offset + INC;
end

stream.write(store.read(offset, int32(SIZE-offset)));
stream.close();

gateway.close();

bfTiffComment('out.xml','Indent','on','outxmlfile','auto')


bfTiffComment.m is here:
https://gist.github.com/kouichi-c-nakam ... fcomment-m
Kouichi_C_Nakamura
 
Posts: 165
Joined: Thu Oct 19, 2017 1:35 pm

Re: Is there a way to retrieve OME-XML directly from OMERO?

Postby jburel » Mon Nov 19, 2018 11:36 am

Hi Kouichi

Great that it works
Thanks for letting us know
We will add an example to our documentation.

Cheers

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


Return to User Discussion

Who is online

Users browsing this forum: No registered users and 0 guests