Warning: Can't synchronize with repository "(default)" (/home/git/ome.git does not appear to be a Git repository.). Look in the Trac log for more information.

Ticket #2893: wells44.py

File wells44.py, 3.9 KB (added by jmoore, 12 years ago)

Wells.py updated for use with 4.3/4.4

Line 
1import omero
2from omero_sys_ParametersI import ParametersI
3
4import time
5import sys
6import itertools
7import logging
8
9LOGFORMAT =  """%(asctime)s %(levelname)-5.5s [%(name)40s] (%(threadName)-10s) %(message)s"""
10logging.basicConfig(level=10, format=LOGFORMAT)
11
12class Test(object):
13
14    def __init__(self, user, password, host="localhost"):
15        self.client = omero.client(host)
16        self.session = self.client.createSession(user, password)
17        self.update = self.session.getUpdateService()
18        self.query = self.session.getQueryService()
19
20    def create_screen(self):
21        s = omero.model.ScreenI()
22        s.name = omero.rtypes.rstring("test-screen")
23        s = self.update.saveAndReturnObject(s)
24        return s.id
25
26    def create_acquisition(self, plate_id):
27        ac = omero.model.PlateAcquisitionI()
28        ac.startTime = omero.rtypes.rtime(time.time() * 1e3)
29        ac.endTime = omero.rtypes.rtime(time.time() * 1e3)
30        ac.plate = omero.model.PlateI(plate_id, False)
31        ac = self.update.saveAndReturnObject(ac)
32        return ac.id
33
34    def create_plate(self, rows=1, cols=1):
35        p = omero.model.PlateI()
36        p.name = omero.rtypes.rstring("test-plate")
37        for r in range(rows):
38            for c in range(cols):
39                w = omero.model.WellI()
40                w.plate = p
41                w.column = omero.rtypes.rint(c)
42                w.row = omero.rtypes.rint(r)
43                p.addWell(w)
44
45        p = self.update.saveAndReturnObject(p)
46        return p.id
47
48    def get_well(self, plate_id, row, col):
49        query = '''
50        select w from Well w
51        left outer join fetch w.wellSamples
52        where w.row = :row and
53        w.column = :col and
54        w.plate.id = :pid'''
55        params = ParametersI()
56        params.add('pid', plate_id)
57        params.add('row', omero.rtypes.rint(row))
58        params.add('col', omero.rtypes.rint(col))
59        return self.query.findByQuery(query, params)
60
61    def create_image(self):
62        i = omero.model.ImageI()
63        i.name = omero.rtypes.rstring("test-image")
64        i.acquisitionDate = omero.rtypes.rtime(time.time()*1e3)
65        i = self.update.saveAndReturnObject(i)
66        return i.id
67
68    def create_well_sample(self, plate_id, acquisition_id, row, col):
69        w = self.get_well(plate_id, row, col)
70        image_id = self.create_image()
71
72        ws = omero.model.WellSampleI()
73        ws.well = omero.model.WellI(w.id, False)
74        ws.image = omero.model.ImageI(image_id, False)
75        ws.plateAcquisition = omero.model.PlateAcquisitionI(acquisition_id, False)
76        w.addWellSample(ws)
77        w = self.update.saveAndReturnObject(w)
78
79        ws = w.getWellSample(w.sizeOfWellSamples()-1)
80        ws = omero.model.WellSampleI(ws.id.val, False)
81
82        return ws.id
83
84
85def main(rows, cols, samples):
86    logging.info("login")
87    test = Test(*sys.argv[1:])
88    logging.info("create screen")
89    screen_id = test.create_screen()
90    logging.info("create plate")
91    plate_id = test.create_plate(rows, cols)
92    logging.info("create acquisition")
93    acquisition_id = test.create_acquisition(plate_id)
94    for r, c, s in itertools.product(range(rows),
95                                     range(cols),
96                                     range(samples)):
97        logging.info("creating sample-%i for well %i,%i" % (s, r, c))
98        test.create_well_sample(plate_id, acquisition_id, r, c)
99
100
101if __name__ == "__main__":
102    # create 1x1 plate with 2 samples
103    import threading
104    import random
105
106    stop=[False]
107    class T(threading.Thread):
108        def run(self):
109            while not stop[0]:
110                cols=random.choice([2,3,4])
111                rows=random.choice([2,3,4])
112                samples=random.choice([2,4,8])
113                main(2,2,8)
114
115
116threads = [T() for x in range(8)]
117for t in threads: t.start()
118
119try:
120    sys.stdin.read()
121except KeyboardInterrupt:
122    pass
123stop[0] = True
124
125for t in threads: t.join()

1.3.13-PRO © 2008-2011 Agilo Software all rights reserved (this page was served in: 0.31354 sec.)

We're Hiring!