Skip to content

Instantly share code, notes, and snippets.

@emilroz
Last active August 29, 2015 14:15
Show Gist options
  • Save emilroz/234fa8c7d83c3a5e324a to your computer and use it in GitHub Desktop.
Save emilroz/234fa8c7d83c3a5e324a to your computer and use it in GitHub Desktop.
Retrieve a list of image ids contained in a plate.
function well_list_return = ...
getImageListFromPlate(session, plate_id)
% GETIMAGELISTFROMPLATE retrieves a list of image ids belonging to plate id.
%
% well_list_return = getImageListFromPlate(session, plate_id)
% returns 3D array of Image ID of size (# of columns, # of rows, # of
% fields)
%
% author: Emil Rozbicki <[email protected]
% Copyright (C) 2015 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
ip = inputParser;
ip.addRequired('session');
ip.addRequired('plate_id', @(x) isnumeric(x));
ip.parse(session, plate_id);
context = java.util.HashMap;
context.put('omero.group', '-1');
plate = getPlates(session, plate_id, 'group', -1);
if length(plate) == 0
well_list_return = [];
fprintf('Plate not found!')
return
end
size_x = plate.getColumns.getValue();
size_y = plate.getRows.getValue();
queryService = session.getQueryService();
well_query = ...
['select well from Well as well '...
'left outer join fetch well.plate as pt '...
'left outer join fetch well.wellSamples as ws '...
'left outer join fetch ws.plateAcquisition as pa '...
'left outer join fetch ws.image as img '...
'left outer join fetch img.pixels as pix '...
'left outer join fetch pix.pixelsType as pt '...
'where well.plate.id = ', num2str(plate_id)];
well_list = queryService.findAllByQuery(well_query, [], context);
if well_list.size() == 0
disp('Query result 0');
return
end
well = well_list.get(0);
well_samples = well.copyWellSamples();
ws_size = well_samples.size();
well_list_return = zeros(size_x, size_y, ws_size);
for j = 0:well_list.size()-1,
well = well_list.get(j);
well_samples = well.copyWellSamples();
field_image_ids = zeros(ws_size, 1);
for i = 0:well_samples.size()-1,
ws = well_samples.get(i);
field_image_ids(i + 1) = ws.getImage().getId().getValue();
end
row = well.getRow().getValue();
column = well.getColumn().getValue();
well_list_return(column + 1, row + 1, :) = field_image_ids;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment