Skip to content

Instantly share code, notes, and snippets.

@emilroz
Created November 5, 2014 12:42
Show Gist options
  • Save emilroz/b46c7a617802d1c80559 to your computer and use it in GitHub Desktop.
Save emilroz/b46c7a617802d1c80559 to your computer and use it in GitHub Desktop.
Retrieve Original Metadata from OMERO using MATLAB toolbox
function [global_metadata, series_metadata] = ...
getOriginalMetadata(client, session, image_id)
% GETORIGINALMETADATA Retrieves the global and the series orignal metadata.
%
% author: Emil Rozbicki <[email protected]
% Copyright (C) 2014 Glencoe Software, Inc.
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
%
% 1. Redistributions of source code must retain the above copyright notice, this
% list of conditions and the following disclaimer.
% 2. Redistributions in binary form must reproduce the above copyright notice,
% this list of conditions and the following disclaimer in the documentation
% and/or other materials provided with the distribution.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
% ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
% WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
% DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
% ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
% (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
% LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
% ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
% SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
% Check input
% Check input
ip = inputParser;
ip.addRequired('client');
ip.addRequired('session');
ip.addRequired('image_id', @(x) isnumeric(x));
ip.parse(client, session, image_id);
req = omero.cmd.OriginalMetadataRequest;
req.imageId = image_id;
handle = session.submit(req);
callback = omero.cmd.CmdCallbackI(client, handle);
rsp = callback.loop(10, 500);
global_metadata = '';
series_metadata = '';
global_data = rsp.globalMetadata;
if global_data.size() > 1
key_iterator = global_data.keySet().iterator();
global_metadata = cell(global_data.size(), 2);
counter = 1;
for i=1:global_data.size()
key = key_iterator.next();
value = global_data.get(key).getValue();
%fprintf('%s = %s\n', key, char(value));
global_metadata{counter, 1} = char(key);
global_metadata{counter, 2} = char(value);
counter = counter + 1;
end
end
series_data = rsp.seriesMetadata;
if series_data.size() > 0
key_iterator = series.keySet().iterator();
series_metadata = cell(data.size(), 2);
counter = 1;
for i=1:series_data.size()
key = key_iterator.next();
value = series_data.get(key).getValue();
%fprintf('%s = %s\n', key, char(value));
global_metadata{counter, 1} = char(key);
global_metadata{counter, 2} = char(value);
counter = counter + 1;
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment