/
createPlate.m
98 lines (88 loc) · 3.67 KB
/
createPlate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
function plate = createPlate(session, name, varargin)
% CREATEPLATE Create a new plate and uploads it onto the OMERO server
%
% plate = createPlate(session, name) create a new plate with the
% input name, uploads it onto the server and returns the loaded plate.
%
% plate = createPlate(session, name, 'group', groupId) specifies the
% group context in which the plate should be created.
%
% plate = createPlate(session, name, screen) creates a plate and
% links it to the input screen. The group context is specified by the
% screen group.
%
% plate = createPlate(session, name, screenId) creates a plate and
% links it to the screen specified by the input identifier. The group
% context is specified by the screen group.
%
% Examples:
%
% % Create a plate in the context of the current session group
% plate = createPlate(session, 'my-plate');
% % Create a plate in the context of the specified group
% plate = createPlate(session, 'my-plate', 'group', groupId);
% % Create a plate and link it to an existing screen
% plate = createPlate(session, 'my-plate', screen);
% plate = createPlate(session, 'my-plate', screenId);
%
% See also: CREATEOBJECT, CREATESCREEN
% Copyright (C) 2013-2019 University of Dundee & Open Microscopy Environment.
% All rights reserved.
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License along
% with this program; if not, write to the Free Software Foundation, Inc.,
% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
% Input check
isValidScreen = @(x) isscalar(x) && ...
(isnumeric(x) || isa(x, 'omero.model.ScreenI'));
ip = inputParser;
ip.addRequired('name', @ischar);
ip.addOptional('screen', [], isValidScreen);
ip.addParameter('context', java.util.HashMap, @(x) isa(x, 'java.util.HashMap'));
ip.addParameter('group', [], @(x) isempty(x) || (isscalar(x) && isnumeric(x)));
ip.parse(name, varargin{:});
if ~isempty(ip.Results.screen)
% Retrieve the screen
if isnumeric(ip.Results.screen)
screen = getScreens(session, ip.Results.screen);
assert(~isempty(screen), 'Cannot find screen %g', ip.Results.screen);
else
screen = ip.Results.screen;
end
% Determine group from the parent screen
groupId = screen.getDetails().getGroup().getId().getValue();
if ~isempty(ip.Results.group)
if ~isempty(groupId)
assert(isequal(groupId, ip.Results.group),...
'Input group is different from the screen group.');
end
groupId = ip.Results.group;
end
% Create context for uploading
context = ip.Results.context;
context.put('omero.group', java.lang.String(num2str(groupId)));
% Create plate object
plate = omero.model.PlateI();
plate.setName(rstring(name));
% Create screen/plate link
link = omero.model.ScreenPlateLinkI();
link.setParent(omero.model.ScreenI(screen.getId().getValue(), false));
link.setChild(plate);
link = session.getUpdateService().saveAndReturnObject(link, context);
% Return the plate
plate = link.getChild();
else
% Delegate object creation
plate = createObject(session, 'plate', name,...
'context', ip.Results.context, 'group', ip.Results.group);
end