1
2
3 """
4 Methods for working with cecog
5
6 Copyright 2010 University of Dundee, Inc. All rights reserved.
7 Use is subject to license terms supplied in LICENSE.txt
8
9 """
10
11 import os
12 import re
13 import sys
14
15 from omero.cli import BaseControl, CLI
16
17 import omero
18 import omero.constants
19
20 from omero.rtypes import rstring
21
22
24 """CeCog integration plugin.
25
26 Provides actions for prepairing data and otherwise integrating with Cecog. See
27 the Run_Cecog_4.1.py script.
28 """
29
30
31
32
33
34 regex_token = re.compile(r'(?P<Token>.+)\.')
35 regex_time = re.compile(r'T(?P<T>\d+)')
36 regex_channel = re.compile(r'_C(?P<C>.+?)(_|$)')
37 regex_zslice = re.compile(r'_Z(?P<Z>\d+)')
38
54
55
56
57
59 """Uses PIL to read multiple planes from a local folder.
60
61 Planes are combined and uploaded to OMERO as new images with additional T, C,
62 Z dimensions.
63
64 It should be run as a local script (not via scripting service) in order that
65 it has access to the local users file system. Therefore need EMAN2 or PIL
66 installed locally.
67
68 Example usage:
69 $ bin/omero cecog merge /Applications/CecogPackage/Data/Demo_data/0037/
70
71 Since this dir does not contain folders, this will upload images in '0037'
72 into a Dataset called Demo_data in a Project called 'Data'.
73
74 $ bin/omero cecog merge /Applications/CecogPackage/Data/Demo_data/
75
76 Since this dir does contain folders, this will look for images in all
77 subdirectories of 'Demo_data' and upload images into a Dataset called
78 Demo_data in a Project called 'Data'.
79
80 Images will be combined in Z, C and T according to the \
81 MetaMorph_PlateScanPackage naming convention.
82 E.g. tubulin_P0037_T00005_Cgfp_Z1_S1.tiff is Point 37, Timepoint 5, Channel \
83 gfp, Z 1. S?
84 see \
85 /Applications/CecogPackage/CecogAnalyzer.app/Contents/Resources/resources/\
86 naming_schemes.conf
87 """
88 """
89 Processes the command args, makes project and dataset then calls
90 uploadDirAsImages() to process and
91 upload the images to OMERO.
92 """
93 from omero.rtypes import unwrap
94 from omero.util.script_utils import uploadDirAsImages
95
96 path = args.path
97 client = self.ctx.conn(args)
98 queryService = client.sf.getQueryService()
99 updateService = client.sf.getUpdateService()
100 pixelsService = client.sf.getPixelsService()
101
102
103
104
105 subDirs = []
106 for f in os.listdir(path):
107 fullpath = path + f
108
109 if os.path.isdir(fullpath):
110 subDirs.append(fullpath)
111
112
113 if len(subDirs) == 0:
114 p = path[:-1]
115 p = os.path.dirname(p)
116 else:
117 if os.path.basename(path) == "":
118 p = path[:-1]
119
120 datasetName = os.path.basename(p)
121 p = p[:-1]
122 p = os.path.dirname(p)
123 projectName = os.path.basename(p)
124 self.ctx.err("Putting images in Project: %s Dataset: %s"
125 % (projectName, datasetName))
126
127
128 dataset = omero.model.DatasetI()
129 dataset.name = rstring(datasetName)
130 dataset = updateService.saveAndReturnObject(dataset)
131
132 project = omero.model.ProjectI()
133 project.name = rstring(projectName)
134 project = updateService.saveAndReturnObject(project)
135
136 link = omero.model.ProjectDatasetLinkI()
137 link.parent = omero.model.ProjectI(project.id.val, False)
138 link.child = omero.model.DatasetI(dataset.id.val, False)
139 updateService.saveAndReturnObject(link)
140
141 if len(subDirs) > 0:
142 for subDir in subDirs:
143 self.ctx.err("Processing images in %s" % subDir)
144 rv = uploadDirAsImages(client.sf, queryService, updateService,
145 pixelsService, subDir, dataset)
146 self.ctx.out("%s" % unwrap(rv))
147
148
149 else:
150 self.ctx.err("Processing images in %s" % path)
151 rv = uploadDirAsImages(client.sf, queryService, updateService,
152 pixelsService, path, dataset)
153 self.ctx.out("%s" % unwrap(rv))
154
155 - def rois(self, args):
156 """Parses an object_details text file, as generated by CeCog Analyzer
157 and saves the data as ROIs on an Image in OMERO.
158
159 Text file is of the form:
160
161 frame objID classLabel className centerX centerY mean sd
162 1 10 6 lateana 1119 41 76.8253796095 \
163 54.9305640673
164
165
166 Example usage:
167 bin/omero cecog rois -f \
168 Data/Demo_output/analyzed/0037/statistics/P0037__object_details.txt -i 502
169 """
170 """
171 Processes the command args, parses the object_details.txt file and
172 creates ROIs on the image specified in OMERO
173 """
174 from omero.util.script_utils import uploadCecogObjectDetails
175 filePath = args.file
176 imageId = args.image
177 if not os.path.exists(filePath):
178 self.ctx.die(654, "Could find the object_details file at %s"
179 % filePath)
180
181 client = self.ctx.conn(args)
182 updateService = client.sf.getUpdateService()
183 ids = uploadCecogObjectDetails(updateService, imageId, filePath)
184 self.ctx.out("Rois created: %s" % len(ids))
185
186
187 try:
188 register("cecog", CecogControl, CecogControl.__doc__)
189 except NameError:
190 if __name__ == "__main__":
191 cli = CLI()
192 cli.register("cecog", CecogControl, CecogControl.__doc__)
193 cli.invoke(sys.argv[1:])
194