forked from ome/omero-user-scripts
/
Unlink_Images.py
92 lines (70 loc) · 2.85 KB
/
Unlink_Images.py
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
# coding=utf-8
"""
-----------------------------------------------------------------------------
Copyright (C) 2013 Glencoe Software, Inc. 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.
------------------------------------------------------------------------------
Unlink Images from a given Plate.
"""
import omero
import omero.clients
from omero.rtypes import rlong
from omero.rtypes import rstring
from omero.sys import ParametersI
import omero.scripts as scripts
assert omero
def run():
"""
"""
data_types = [rstring("Plate")]
client = scripts.client(
"Unlink_Images.py",
"Unlink Images from a given Plate",
scripts.String("Data_Type", optional=False, grouping="1",
description="The data type you want to work with.",
values=data_types,
default="Plate"),
scripts.List("IDs", optional=False, grouping="2",
description="List of Plate IDs").ofType(rlong(0)),
version="0.1",
authors=["Chris Allan"],
institutions=["Glencoe Software Inc."],
contact="support@glencoesoftware.com",
)
try:
script_params = {}
for key in client.getInputKeys():
if client.getInput(key):
script_params[key] = client.getInput(key, unwrap=True)
session = client.getSession()
update_service = session.getUpdateService()
query_service = session.getQueryService()
count = 0
for plate_id in script_params["IDs"]:
params = ParametersI()
params.addId(plate_id)
plate = query_service.findByQuery(
"SELECT p from Plate AS p "
"LEFT JOIN FETCH p.wells as w "
"LEFT JOIN FETCH w.wellSamples as ws "
"WHERE p.id = :id", params)
for well in plate.copyWells():
count += well.sizeOfWellSamples()
well.clearWellSamples()
update_service.saveObject(plate)
client.setOutput("Message", rstring(
"Unlinking of %d Image(s) successful." % count))
finally:
client.closeSession()
if __name__ == "__main__":
run()