def test_plot_profile(self): script_id = super(TestAnalysisScripts, self).get_script(plot_profile) assert script_id > 0 client, user = self.new_client_and_user() # create a test image size_t = 3 size_x = 100 size_y = 100 session = client.getSession() image = self.create_test_image(size_x, size_y, 1, 2, size_t, session) image_id = image.id.val roi = create_roi(image_id, 0, size_x / 2, 0, size_y / 2, size_t, True) session.getUpdateService().saveAndReturnObject(roi) image_ids = [] image_ids.append(omero.rtypes.rlong(image_id)) args = { "Data_Type": omero.rtypes.rstring("Image"), "IDs": omero.rtypes.rlist(image_ids), "Line_Width": omero.rtypes.rint(2), "Sum_or_Average": omero.rtypes.rstring("Average") } ann = run_script(client, script_id, args, "Line_Data") c = self.new_client(user=user) check_file_annotation(c, ann)
def test_kymograph(self): script_id = super(TestAnalysisScripts, self).get_script(kymograph) assert script_id > 0 client, user = self.new_client_and_user() # create a test image size_t = 3 size_x = 100 size_y = 100 # x,y,z,c,t session = client.getSession() image = self.create_test_image(size_x, size_y, 1, 2, size_t, session) image_id = image.id.val roi = create_roi(image_id, 0, size_x / 2, 0, size_y / 2, size_t, True) session.getUpdateService().saveAndReturnObject(roi) image_ids = [] image_ids.append(omero.rtypes.rlong(image_id)) args = { "Data_Type": omero.rtypes.rstring("Image"), "IDs": omero.rtypes.rlist(image_ids), "Line_Width": omero.rtypes.rint(5) } kymograph_img = run_script(client, script_id, args, "New_Image") # check the result assert kymograph_img is not None assert kymograph_img.getValue().id.val > 0
def test_dataset_to_plate(self, image_names): script_id = super(TestUtilScripts, self).get_script(dataset_to_plate) assert script_id > 0 # root session is root.sf session = self.root.sf client = self.root # create several test images in a dataset dataset = self.make_dataset("dataset_to_plate-test", client=client) # Images will be sorted by name and assigned Column first image_ids = [] for i in image_names: # x,y,z,c,t image = self.create_test_image(100, 100, 1, 1, 1, session, name=i) self.link(dataset, image, client=client) image_ids.append(image.id.val) # Minimum args. dataset_ids = [omero.rtypes.rlong(dataset.id.val)] args = { "Data_Type": wrap("Dataset"), "IDs": wrap(dataset_ids), "First_Axis_Count": wrap(3), } # With more image names, add extra args images_per_well = 1 if (len(image_names)) == 8: images_per_well = 2 args["Images_Per_Well"] = wrap(images_per_well) args["First_Axis_Count"] = wrap(2) args["Column_Names"] = wrap("letter") args["Row_Names"] = wrap("number") d_to_p = run_script(client, script_id, args, "New_Object") # check the result - load all Wells from Plate, check image IDs assert d_to_p is not None plate_id = d_to_p.getValue().id.val # Check names of Images matches Well position images_in_plate = [] conn = BlitzGateway(client_obj=client) plate = conn.getObject("Plate", plate_id) for well in plate.listChildren(): print('well', well) for w in range(images_per_well): if images_per_well == 1: name = well.getWellPos() else: # e.g. "A1_0" name = "%s_%d" % (well.getWellPos(), w) image = well.getImage(w) assert image.getName() == name images_in_plate.append(image.getId()) # and all images were in the Plate images_in_plate.sort() assert images_in_plate == image_ids
def test_movie_figure(self, all_parameters): sid = super(TestFigureExportScripts, self).get_script(movie_figure) assert sid > 0 client, user = self.new_client_and_user() # create several test images in a dataset dataset = self.make_dataset("movieFig-test", client=client) project = self.make_project("movieFig-test", client=client) self.link(project, dataset, client=client) # put some images in dataset session = client.getSession() image_ids = [] for i in range(2): image = self.create_test_image(256, 256, 5, 3, 20, session) image_ids.append(omero.rtypes.rlong(image.id.val)) self.link(dataset, image, client=client) red = omero.rtypes.rint(16711680) t_indexes = [ omero.rtypes.rint(0), omero.rtypes.rint(1), omero.rtypes.rint(5), omero.rtypes.rint(10), omero.rtypes.rint(15) ] if all_parameters: args = { "Data_Type": omero.rtypes.rstring("Image"), "IDs": omero.rtypes.rlist(image_ids), "T_Indexes": omero.rtypes.rlist(t_indexes), "Z_Start": omero.rtypes.rint(1), "Z_End": omero.rtypes.rint(3), "Width": omero.rtypes.rint(150), "Height": omero.rtypes.rint(150), "Image_Labels": omero.rtypes.rstring("Datasets"), "Algorithm": omero.rtypes.rstring("Mean Intensity"), "Stepping": omero.rtypes.rint(1), "Scalebar": omero.rtypes.rint(10), "Format": omero.rtypes.rstring("PNG"), "Figure_Name": omero.rtypes.rstring("movieFigureTest"), "TimeUnits": omero.rtypes.rstring("MINS"), "Overlay_Colour": red, } else: args = { "Data_Type": omero.rtypes.rstring("Image"), "IDs": omero.rtypes.rlist(image_ids), "T_Indexes": omero.rtypes.rlist(t_indexes) } ann = run_script(client, sid, args, "File_Annotation") c = self.new_client(user=user) check_file_annotation(c, ann)
def test_thumbnail_figure(self, data_type, all_parameters): sid = super(TestFigureExportScripts, self).get_script(thumbnail_figure) assert sid > 0 client, user = self.new_client_and_user() # create several test images in a dataset dataset = self.make_dataset("thumbnailFigure-test", client=client) # make some tags tag_ids = [] session = client.getSession() for t in range(5): tag = omero.model.TagAnnotationI() tag.setTextValue(omero.rtypes.rstring("TestTag_%s" % t)) tag = session.getUpdateService().saveAndReturnObject(tag) tag_ids.append(tag.id) # put some images in dataset image_ids = [] for i in range(2): # x,y,z,c,t image = self.create_test_image(100, 100, 1, 1, 1, session) image_ids.append(omero.rtypes.rlong(image.id.val)) self.link(dataset, image, client=client) # add tag t = i % 5 tag = omero.model.TagAnnotationI(tag_ids[t].val, False) self.link(image, tag, client=client) dataset_ids = [omero.rtypes.rlong(dataset.id.val)] ids = image_ids if data_type == "Dataset": ids = dataset_ids if all_parameters: args = { "IDs": omero.rtypes.rlist(ids), "Data_Type": omero.rtypes.rstring(data_type), "Thumbnail_Size": omero.rtypes.rint(16), "Max_Columns": omero.rtypes.rint(6), "Format": omero.rtypes.rstring("PNG"), "Figure_Name": omero.rtypes.rstring("thumbnail-test"), "Tag_IDs": omero.rtypes.rlist(tag_ids) } else: args = { "Data_Type": omero.rtypes.rstring(data_type), "IDs": omero.rtypes.rlist(ids) } ann = run_script(client, sid, args, "File_Annotation") # should have figures attached to dataset and first image. c = self.new_client(user=user) check_file_annotation(c, ann, parent_type=data_type)
def test_movie_roi_figure(self, all_parameters): sid = super(TestFigureExportScripts, self).get_script(movie_roi_figure) assert sid > 0 client, user = self.new_client_and_user() # create several test images in a dataset dataset = self.make_dataset("movieRoiFig-test", client=client) project = self.make_project("movieRoiFig-test", client=client) self.link(project, dataset, client=client) # put some images in dataset image_ids = [] session = client.getSession() for i in range(2): image = self.create_test_image(256, 256, 10, 3, 1, session) image_ids.append(omero.rtypes.rlong(image.id.val)) self.link(dataset, image, client=client) # add roi - x, y, width, height add_rectangle_roi(session.getUpdateService(), 50 + (i * 10), 100 - (i * 10), 50 + (i * 5), 100 - (i * 5), image.id.val) if all_parameters: args = { "Data_Type": omero.rtypes.rstring("Image"), "IDs": omero.rtypes.rlist(image_ids), "ROI_Zoom": omero.rtypes.rfloat(3), "Max_Columns": omero.rtypes.rint(10), "Resize_Images": omero.rtypes.rbool(True), "Width": omero.rtypes.rint(200), "Height": omero.rtypes.rint(200), "Image_Labels": omero.rtypes.rstring("Datasets"), "Show_ROI_Duration": omero.rtypes.rbool(True), # will be ignored since no pixelsize set "Scalebar": omero.rtypes.rint(10), # will be ignored since no pixelsize set "Scalebar_Colour": omero.rtypes.rstring("White"), # won't be found - but should still work "Roi_Selection_Label": omero.rtypes.rstring("fakeTest"), "Algorithm": omero.rtypes.rstring("Mean Intensity"), "Figure_Name": omero.rtypes.rstring("movieROITest") } else: args = { "Data_Type": omero.rtypes.rstring("Image"), "IDs": omero.rtypes.rlist(image_ids) } ann = run_script(client, sid, args, "File_Annotation") c = self.new_client(user=user) check_file_annotation(c, ann)
def test_kymograph_analysis(self): script_id = super(TestAnalysisScripts, self).get_script(kymograph) client, user = self.new_client_and_user() # create a test image size_t = 3 size_x = 100 size_y = 100 # x,y,z,c,t session = client.getSession() image = self.create_test_image(size_x, size_y, 1, 2, size_t, session) image_id = image.id.val roi = create_roi(image_id, 0, size_x / 2, 0, size_y / 2, size_t, True) session.getUpdateService().saveAndReturnObject(roi) image_ids = [] image_ids.append(omero.rtypes.rlong(image_id)) args = { "Data_Type": omero.rtypes.rstring("Image"), "IDs": omero.rtypes.rlist(image_ids), "Line_Width": omero.rtypes.rint(5) } kymograph_img = run_script(client, script_id, args, "New_Image") # now analyse the Kymograph image sid = super(TestAnalysisScripts, self).get_script(kymograph_analysis) assert sid > 0 image_id = kymograph_img.getValue().id.val roi = create_roi(image_id, 0, 2, 0, 2, 1, False) session.getUpdateService().saveAndReturnObject(roi) image_ids = [] image_ids.append(omero.rtypes.rlong(image_id)) args = { "Data_Type": omero.rtypes.rstring("Image"), "IDs": omero.rtypes.rlist(image_ids) } ann = run_script(client, sid, args, "Line_Data") c = self.new_client(user=user) check_file_annotation(c, ann)
def run(self): """ Run Python script """ session = self.bqSession # call script outputs = run_script( session, log, **self.options.__dict__ ) # save output back to BisQue for output in outputs: self.output_resources.append(output)
def test_batch_image_export(self): sid = super(TestExportScripts, self).get_script(batch_image_export) assert sid > 0 client, user = self.new_client_and_user() # x,y,z,c,t image = self.create_test_image(100, 100, 1, 1, 1, client.getSession()) image_ids = [] image_ids.append(rlong(image.id.val)) args = {"Data_Type": rstring("Image"), "IDs": rlist(image_ids)} ann = run_script(client, sid, args, "File_Annotation") c = self.new_client(user=user) check_file_annotation(c, ann)
def test_populate_metadata_for_screen(self): sid = super(TestImportScripts, self).get_script(populate_metadata) assert sid > 0 client, user = self.new_client_and_user() update_service = client.getSession().getUpdateService() plates = self.import_plates(client, plate_cols=3, plate_rows=1) plate = plates[0] name = plate.name.val screen = omero.model.ScreenI() screen.name = omero.rtypes.rstring("test_for_screen") spl = omero.model.ScreenPlateLinkI() spl.setParent(screen) spl.setChild(plate) spl = update_service.saveAndReturnObject(spl) screen_id = spl.getParent().id.val assert screen_id > 0 assert spl.getChild().id.val == plate.id.val cvs_file = create_path("test_screen", ".csv") # create a file annotation with open(cvs_file.abspath(), 'w+') as f: f.write("Well,Plate, Well Type, Facility-Salt-Batch-ID\n") f.write("A01,%s,Treatment,FOOL10041-101-2\n" % name) f.write("A02,%s,Control,\n" % name) f.write("A03,%s,Treatment,FOOL10041-101-2\n" % name) conn = BlitzGateway(client_obj=client) fa = conn.createFileAnnfromLocalFile(cvs_file, mimetype="text/csv") assert fa is not None assert fa.id > 0 link = omero.model.ScreenAnnotationLinkI() link.setParent(omero.model.ScreenI(screen_id, False)) link.setChild(omero.model.FileAnnotationI(fa.id, False)) link = update_service.saveAndReturnObject(link) assert link.id.val > 0 # run the script screen_ids = [] screen_ids.append(spl.getParent().id) args = { "Data_Type": omero.rtypes.rstring("Screen"), "IDs": omero.rtypes.rlist(screen_ids), "File_Annotation": omero.rtypes.rstring(str(fa.id)) } message = run_script(client, sid, args, "Message") assert message is not None assert message.getValue().startswith('Table data populated') conn.close()
def test_dataset_to_plate(self): script_id = super(TestUtilScripts, self).get_script(dataset_to_plate) assert script_id > 0 # root session is root.sf session = self.root.sf client = self.root # create several test images in a dataset dataset = self.make_dataset("dataset_to_plate-test", client=client) n = 10 image_ids = [] for i in range(n): # x,y,z,c,t image = self.create_test_image(100, 100, 1, 1, 1, session) self.link(dataset, image, client=client) image_ids.append(image.id.val) # run the script twice. First with all args... dataset_ids = [omero.rtypes.rlong(dataset.id.val)] args = { "Data_Type": omero.rtypes.rstring("Dataset"), "IDs": omero.rtypes.rlist(dataset_ids) } d_to_p = run_script(client, script_id, args, "New_Object") # check the result assert d_to_p is not None plate_id = d_to_p.getValue().id.val assert plate_id > 0 qs = client.getSession().getQueryService() 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.image as img where well.plate.id = :oid" params = omero.sys.ParametersI() params.addLong('oid', omero.rtypes.rlong(plate_id)) wells = qs.findAllByQuery(query, params) # check the plate assert len(wells) == n count = 0 for w in wells: img = w.getWellSample(0).getImage() assert img is not None id = img.id.val if id in image_ids: count += 1 assert count == n
def test_images_from_rois(self, image_stack, size, tmpdir): if image_stack and size > 3000: # Not supported return script_id = super(TestUtilScripts, self).get_script(images_from_rois) assert script_id > 0 # root session is root.sf session = self.root.sf client = self.root size_x = size + 100 size_y = size + 50 size_z = 5 name = "test&sizeX=%s&sizeY=%s&sizeZ=%s.fake" % (size_x, size_y, size_z) # Supports import of big and small images image_id = self.import_pyramid(tmpdir, name=name, client=client) image_ids = [] image_ids.append(omero.rtypes.rlong(image_id)) # Add rectangle roi = omero.model.RoiI() roi.setImage(omero.model.ImageI(image_id, False)) rect = omero.model.RectangleI() rect.x = omero.rtypes.rdouble(5) rect.y = omero.rtypes.rdouble(10) rect.width = omero.rtypes.rdouble(size) rect.height = omero.rtypes.rdouble(size) roi.addShape(rect) session.getUpdateService().saveAndReturnObject(roi) args = { "Data_Type": omero.rtypes.rstring("Image"), "IDs": omero.rtypes.rlist(image_ids), "Make_Image_Stack": omero.rtypes.rbool(image_stack) } img_from_rois = run_script(client, script_id, args, "Result") # check the result assert img_from_rois is not None new_img = img_from_rois.getValue() new_size_z = new_img.getPrimaryPixels().getSizeZ().getValue() # From a single ROI (without theZ) on Z-stack image... # Should get a single Z image from single ROI if Make_Image_Stack if image_stack: assert new_size_z == 1 else: # Otherwise we use all planes of input image assert new_size_z == size_z
def test_combine_images(self): script_id = super(TestUtilScripts, self).get_script(combine_images) assert script_id > 0 client = self.root image_ids = [] for i in range(2): image = self.create_test_image(100, 100, 2, 3, 4) # x,y,z,c,t image_ids.append(omero.rtypes.rlong(image.id.val)) args = { "Data_Type": omero.rtypes.rstring("Image"), "IDs": omero.rtypes.rlist(image_ids) } combine_img = run_script(client, script_id, args, "Combined_Image") # check the result assert combine_img is not None assert combine_img.getValue().id.val > 0
def test_export_figure_as(self, export_option, tmpdir): """Create images, add to figure and export as TIFF, PNG etc.""" id = super(TestFigureScripts, self).get_script_by_name(path, name) assert id > 0 # client, user = self.new_client_and_user() # Temp workaround for openmicroscopy/openmicroscopy/pull/5720 client = self.client user = self.user script_service = client.sf.getScriptService() assert script_service.getParams(id) is not None # create an image size_t = 1 size_x = 100 size_y = 100 size_z = 1 size_c = 1 session = client.getSession() image = self.create_test_image(size_x, size_y, size_z, size_c, size_t, session) image_id = self.import_pyramid(tmpdir, client=client) query_service = client.sf.getQueryService() big_image = query_service.findByQuery( """select i from Image i left outer join fetch i.pixels as p where i.id = :id""", ParametersI().addId(image_id)) figure_name = "test_export_figure_as_%s" % export_option json = create_figure([image, big_image]) uri = "https://www.openmicroscopy.org/" args = { "Figure_JSON": omero.rtypes.rstring(json), "Export_Option": omero.rtypes.rstring(export_option), "Figure_Name": omero.rtypes.rstring(figure_name), "Webclient_URI": omero.rtypes.rstring(uri) } robj = run_script(client, id, args, "New_Figure") ann = robj.getValue() # New image is returned when it is an OMERO image if export_option is "OMERO": assert isinstance(ann, Image) else: c = self.new_client(user=user) check_file_annotation(c, ann, link_count=2)
def test_images_from_rois(self, image_stack): script_id = super(TestUtilScripts, self).get_script(images_from_rois) assert script_id > 0 # root session is root.sf session = self.root.sf client = self.root size_x = 100 size_y = 100 size_z = 5 image = self.create_test_image(size_x, size_y, size_z, 1, 1) image_id = image.id.val image_ids = [] image_ids.append(omero.rtypes.rlong(image_id)) # Add rectangle roi = omero.model.RoiI() roi.setImage(omero.model.ImageI(image_id, False)) rect = omero.model.RectangleI() rect.x = omero.rtypes.rdouble(0) rect.y = omero.rtypes.rdouble(0) rect.width = omero.rtypes.rdouble(size_x / 2) rect.height = omero.rtypes.rdouble(size_y / 2) roi.addShape(rect) session.getUpdateService().saveAndReturnObject(roi) args = { "Data_Type": omero.rtypes.rstring("Image"), "IDs": omero.rtypes.rlist(image_ids), "Make_Image_Stack": omero.rtypes.rbool(image_stack) } img_from_rois = run_script(client, script_id, args, "Result") # check the result assert img_from_rois is not None new_img = img_from_rois.getValue() new_size_z = new_img.getPrimaryPixels().getSizeZ().getValue() # From a single ROI (without theZ) on Z-stack image... # Should get a single Z image from single ROI if Make_Image_Stack if image_stack: assert new_size_z == 1 else: # Otherwise we use all planes of input image assert new_size_z == size_z
def run_on(key, actually_send=False, confirmation_email=CONFIRMATION_EMAIL_FROM, confirmation_email_on_success=True, confirmation_email_on_fail=True, special_text="", send_default_confirmation=False): input_files = files.io.get(key) assert "template" in input_files, "Need to submit non-empty template" assert "spreadsheet" in input_files, "Need to submit non-empty spreadsheet" output_location = StringIO() kwargs = {} if send_default_confirmation: pass else: kwargs["send_confirmation_to"] = None if "constants" in input_files: kwargs["constants"] = StringIO(input_files["constants"]) success = script.run_script( StringIO(input_files["template"]), StringIO(input_files["spreadsheet"]), output=output_location, actually_send=actually_send, **kwargs ) script_results = special_text + full_file(output_location) if confirmation_email and ((confirmation_email_on_success and success) or (confirmation_email_on_fail and not success)): send_confirmation_email(confirmation_email, script_results) return script_results, success
def test_channel_offsets(self): script_id = super(TestUtilScripts, self).get_script(channel_offsets) assert script_id > 0 client = self.root image = self.create_test_image(100, 100, 2, 3, 4) # x,y,z,c,t image_id = image.id.val image_ids = [] image_ids.append(omero.rtypes.rlong(image_id)) args = { "Data_Type": omero.rtypes.rstring("Image"), "IDs": omero.rtypes.rlist(image_ids), "Channel1_X_shift": omero.rtypes.rint(1), "Channel1_Y_shift": omero.rtypes.rint(1), "Channel2_X_shift": omero.rtypes.rint(2), "Channel2_Y_shift": omero.rtypes.rint(2), "Channel3_X_shift": omero.rtypes.rint(3), "Channel3_Y_shift": omero.rtypes.rint(3), } offset_img = run_script(client, script_id, args, "Image") # check the result assert offset_img is not None assert offset_img.getValue().id.val > 0
def test_roi_figure(self, all_parameters): sid = super(TestFigureExportScripts, self).get_script(roi_figure) assert sid > 0 client, user = self.new_client_and_user() # create several test images in a dataset dataset = self.make_dataset("roiFig-test", client=client) project = self.make_project("roiFig-test", client=client) self.link(project, dataset, client=client) # put some images in dataset image_ids = [] session = client.getSession() for i in range(2): image = self.create_test_image(256, 200, 5, 4, 1, session) image_ids.append(omero.rtypes.rlong(image.id.val)) self.link(dataset, image, client=client) add_rectangle_roi(session.getUpdateService(), 50 + (i * 10), 100 - (i * 10), 50 + (i * 5), 100 - (i * 5), image.id.val) c_names_map = omero.rtypes.rmap({ '0': omero.rtypes.rstring("DAPI"), '1': omero.rtypes.rstring("GFP"), '2': omero.rtypes.rstring("Red"), '3': omero.rtypes.rstring("ACA") }) blue = omero.rtypes.rint(255) red = omero.rtypes.rint(16711680) mrgd_colours_map = omero.rtypes.rmap({'0': blue, '1': blue, '3': red}) if all_parameters: args = { "Data_Type": omero.rtypes.rstring("Image"), "IDs": omero.rtypes.rlist(image_ids), "Channel_Names": c_names_map, "Split_Indexes": omero.rtypes.rlist( [omero.rtypes.rlong(1), omero.rtypes.rlong(2)]), "Split_Panels_Grey": omero.rtypes.rbool(True), "Merged_Colours": mrgd_colours_map, "Merged_Names": omero.rtypes.rbool(True), "Width": omero.rtypes.rint(200), "Height": omero.rtypes.rint(200), "Image_Labels": omero.rtypes.rstring("Datasets"), "Algorithm": omero.rtypes.rstring("Mean Intensity"), "Stepping": omero.rtypes.rint(1), # will be ignored since no pixelsize set "Scalebar": omero.rtypes.rint(10), "Format": omero.rtypes.rstring("PNG"), "Figure_Name": omero.rtypes.rstring("splitViewTest"), "Overlay_Colour": omero.rtypes.rstring("Red"), "ROI_Zoom": omero.rtypes.rfloat(3), # won't be found - but should still work "ROI_Label": omero.rtypes.rstring("fakeTest"), } else: args = { "Data_Type": omero.rtypes.rstring("Image"), "IDs": omero.rtypes.rlist(image_ids) } ann = run_script(client, sid, args, "File_Annotation") c = self.new_client(user=user) check_file_annotation(c, ann)
def test_move_annotations(self, remove, script_runner): script_id = super(TestUtilScripts, self).get_script(move_annotations) assert script_id > 0 # create new Admin and user in same group admin_client, admin = self.new_client_and_user(system=True) group = admin_client.sf.getAdminService().getEventContext().groupId client, user = self.new_client_and_user(group=group) user_id = user.id.val field_count = 2 # User creates Plate and Adds annotations... plate = self.import_plates(client=client, fields=field_count)[0] well_ids = [] for well in plate.copyWells(): well_ids.append(well.id) for well_sample in well.copyWellSamples(): image = well_sample.getImage() # Add annotations tag = omero.model.TagAnnotationI() tag.textValue = omero.rtypes.rstring("testTag") self.link(image, tag, client=client) comment = omero.model.CommentAnnotationI() comment.textValue = omero.rtypes.rstring("test Comment") self.link(image, comment, client=client) rating = omero.model.LongAnnotationI() rating.longValue = omero.rtypes.rlong(5) rating.ns = omero.rtypes.rstring( omero.constants.metadata.NSINSIGHTRATING) self.link(image, rating, client=client) # Either the 'user' or 'root' will run the script if script_runner == 'user': script_runner_client = client else: script_runner_client = admin_client # Run script on each type, with/without removing Annotations for anntype in ('Tag', 'Comment', 'Rating'): args = { "Data_Type": omero.rtypes.rstring("Well"), "IDs": omero.rtypes.rlist(well_ids), "Annotation_Type": omero.rtypes.rstring(anntype), "Remove_Annotations_From_Images": omero.rtypes.rbool(remove) } message = run_script(script_runner_client, script_id, args, "Message") assert message.val == "Moved %s Annotations" % field_count # Check new links are owned by user # and remove annotations from Wells... query_service = client.getSession().getQueryService() query = ("select l from WellAnnotationLink as l" " join fetch l.child as ann" " join fetch l.details.owner as owner" " where l.parent.id in (:ids)") params = omero.sys.ParametersI().addIds(well_ids) links = query_service.findAllByQuery(query, params) link_ids = [l.id.val for l in links] assert len(link_ids) == field_count * 3 for l in links: assert l.getDetails().owner.id.val == user_id delete = Delete2(targetObjects={'WellAnnotationLink': link_ids}) handle = client.sf.submit(delete) client.waitOnCmd(handle, loops=10, ms=500, failonerror=True, failontimeout=False, closehandle=False) # Run again with 'All' annotations. args = { "Data_Type": omero.rtypes.rstring("Plate"), "IDs": omero.rtypes.rlist([plate.id]), "Annotation_Type": omero.rtypes.rstring("All"), "Remove_Annotations_From_Images": omero.rtypes.rbool(remove) } message = run_script(script_runner_client, script_id, args, "Message") # If we've been removing annotations above, # there will be None left to move if remove: expected = "No annotations moved. See info." else: expected = "Moved %s Annotations" % (field_count * 3) assert message.val == expected # Run again - None moved since Annotations are already on Well message = run_script(script_runner_client, script_id, args, "Message") assert message.val == "No annotations moved. See info."
def test_split_view_figure(self, all_parameters): id = super(TestFigureExportScripts, self).get_script(split_view_figure) assert id > 0 client, user = self.new_client_and_user() # create several test images in a dataset dataset = self.make_dataset("thumbnailFigure-test", client=client) project = self.make_project("thumbnailFigure-test", client=client) self.link(project, dataset, client=client) # put some images in dataset session = client.getSession() image_ids = [] for i in range(2): image = self.create_test_image(256, 200, 5, 4, 1, session) image_ids.append(omero.rtypes.rlong(image.id.val)) self.link(dataset, image, client=client) c_names_map = omero.rtypes.rmap({ '0': omero.rtypes.rstring("DAPI"), '1': omero.rtypes.rstring("GFP"), '2': omero.rtypes.rstring("Red"), '3': omero.rtypes.rstring("ACA") }) blue = omero.rtypes.rlong(255) red = omero.rtypes.rlong(16711680) mrgd_colours_map = omero.rtypes.rmap({'0': blue, '1': blue, '3': red}) if all_parameters: args = { "Data_Type": omero.rtypes.rstring("Image"), "IDs": omero.rtypes.rlist(image_ids), "Z_Start": omero.rtypes.rint(0), "Z_End": omero.rtypes.rint(3), "Channel_Names": c_names_map, "Split_Indexes": omero.rtypes.rlist( [omero.rtypes.rint(1), omero.rtypes.rint(2)]), "Split_Panels_Grey": omero.rtypes.rbool(True), "Merged_Colours": mrgd_colours_map, "Merged_Names": omero.rtypes.rbool(True), "Width": omero.rtypes.rint(200), "Height": omero.rtypes.rint(200), "Image_Labels": omero.rtypes.rstring("Datasets"), "Algorithm": omero.rtypes.rstring("Mean Intensity"), "Stepping": omero.rtypes.rint(1), # will be ignored since no pixelsize set "Scalebar": omero.rtypes.rint(10), "Format": omero.rtypes.rstring("PNG"), "Figure_Name": omero.rtypes.rstring("splitViewTest"), } else: args = { "Data_Type": omero.rtypes.rstring("Image"), "IDs": omero.rtypes.rlist(image_ids), "Merged_Colours": mrgd_colours_map, "Format": omero.rtypes.rstring("PNG"), "Figure_Name": omero.rtypes.rstring("splitViewTest") } ann = run_script(client, id, args, "File_Annotation") c = self.new_client(user=user) check_file_annotation(c, ann)
import script TEMPLATE_FILE = "INP/template.txt" SPREADSHEET_FILE = "INP/spreadsheet.csv" template_file = open(TEMPLATE_FILE) spreadsheet_file = open(SPREADSHEET_FILE) script.run_script(template_file, spreadsheet_file)
def test_batch_roi_export(self, all_planes): sid = super(TestExportScripts, self).get_script(batch_roi_export) assert sid > 0 client, user = self.new_client_and_user() session = client.getSession() # x,y,z,c,t size_c = 2 size_z = 3 size_t = 4 image_name = "ROI_image" label_text = "Shape_Text" image = self.create_test_image(100, 100, size_z, size_c, size_t, session, name=image_name) # Add 2 Shapes... A Rectangle and Polygon covering same area polygon = omero.model.PolygonI() polygon.points = rstring("10,10, 91,10, 91,91, 10,91") polygon.textValue = rstring(label_text) rect = omero.model.RectangleI() rect.x = rdouble(10) rect.y = rdouble(10) rect.width = rdouble(81) rect.height = rdouble(81) rect.theZ = rint(1) rect.theT = rint(1) # ...to an ROI roi = omero.model.RoiI() roi.setImage(image) roi.addShape(polygon) roi.addShape(rect) roi = session.getUpdateService().saveAndReturnObject(roi) shapes = roi.copyShapes() polygon = shapes[0] image_ids = [] file_name = "test_batch_roi_export" image_ids.append(rlong(image.id.val)) channels = [rint(c) for c in range(4)] args = { "Data_Type": rstring("Image"), "IDs": rlist(image_ids), # Should ignore Channels out of range. 1-based index "Channels": rlist(channels), "Export_All_Planes": rbool(all_planes), "File_Name": rstring(file_name) } ann = run_script(client, sid, args, "File_Annotation") c = self.new_client(user=user) check_file_annotation(c, ann, file_name="%s.csv" % file_name) file_id = ann.getValue().getFile().id.val csv_text = get_file_contents(self.new_client(user=user), file_id) # Check we have expected number of rows polygon_planes = size_c if all_planes: polygon_planes = size_c * size_z * size_t # Rows: Header + rect with Z/T set + polygon without Z/T row_count = 1 + size_c + polygon_planes assert len(csv_text.split("\n")) == row_count # Check first 2 rows of csv (except Std dev) zt = "," points_min_max_sum_mean = ",,,," area = "6561.0" if all_planes: zt = "1,1" points_min_max_sum_mean = "6561,10.0,90.0,328050.0,50.0" expected = ("image_id,image_name,roi_id,shape_id,type,text," "z,t,channel,area (pixels),length (pixels)," "points,min,max,sum,mean,std_dev," "X,Y,Width,Height,RadiusX,RadiusY,X1,Y1,X2,Y2,Points\n" "%s,\"%s\",%s,%s,polygon,\"%s\",%s,0,%s,,%s,") % ( image.id.val, image_name, roi.id.val, polygon.id.val, label_text, zt, area, points_min_max_sum_mean) assert csv_text.startswith(expected)