Help making a Screen/Plate/Well/Image from nothing

Hello everyone,

We are building a number of tools around OMERO using Python and rely heavily on ephemeral OMERO instances for testing. While it is possible to import test data for testing purposes, we would prefer to keep the test data very simple and generated by the test code itself as pytest fixtures.

Right now I am trying to figure out how to create a “minimal” screen that consists of one screen, one plate, one well, one well sample and one image. My code seems to work all the way up through the WellSample step and then I get errors. I am wondering if you can give me some direction.

The code (imports not shown here, but assume that I have done them correctly :wink: ):

    # Create Screen
    screen_name = "screen_" + timestamp
    screen = ScreenWrapper(conn, ScreenI())
    screen.setName(screen_name)
    screen.save()
    screen_id = screen.getId()

    # Create Plate
    plate_name = "plate_" + timestamp
    plate = PlateWrapper(conn, PlateI())
    plate.setName(plate_name)
    plate.save()
    plate_id = plate.getId()
    link = ScreenPlateLinkI()
    link.setParent(ScreenI(screen_id, False))
    link.setChild(PlateI(plate_id, False))
    conn.getUpdateService().saveObject(link)

    # Create Well
    well = WellWrapper(conn, WellI())
    well.setColumn(rint(1))
    well.setRow(rint(1))
    well.setPlate(PlateI(plate_id, False))
    well.save()
#   plate.addWell(WellI(well.getId(), False))

    # Create Well Sample with Image
    ws = WellSampleWrapper(conn, WellSampleI())
    ws.setWell(WellI(well.getId(), False))
    ws.setPosX(LengthI(0, UnitsLength.PIXEL))
    ws.setPosY(LengthI(0, UnitsLength.PIXEL))
    ws.setImage(ImageI(im_id1, False)) # im_id1 comes from an image fixture
    ws.save()
#   well.addWellSample(WellSampleI(ws.getId(), False))

The error is quite long, but seems to boil down to this:

    message =  Wrapped Exception: (org.springframework.orm.hibernate3.HibernateSystemException):
Exception occurred inside getter of ome.model.screen.Well.wellSamples; nested exception is org.hibernate.PropertyAccessException: Exception occurred inside getter of ome.model.screen.Well.wellSamples
}

I can send the full trace if that is useful, but I expect I am just missing something simple. Any direction would be helpful!

Also, I have a couple of lines commented there…are those necessary?

# plate.addWell(WellI(well.getId(), False))

and

# well.addWellSample(WellSampleI(ws.getId(), False))

In case it’s useful we’ve got several helper methods that we use for our own Python integration tests:
https://github.com/ome/omero-py/blob/8d711f577d1000aad49ea794324b49450c952878/src/omero/testlib/init.py

Examples of using that library in an external plugin to create screens/plates for tests include:

1 Like

Thanks for the tips here, @manics! We’ll definitely take a look at the code you linked to and see whether we can make good use of it.

Still, I was hoping for something more minimal and using as much BlitzGateway as possible, along the lines of what I was attempting to do. For testing purposes as I noted, but also as reference in case we need to organize images that exist in OMERO into Screens down the road (e.g., if the data are not in a format that BioFormats can recognize and interpret.) Something that would like look the excellent examples you have in your documentation here.

Thanks again for the links, though. It is definitely helpful to see how you guys are doing things.

Hi,
Another example at https://github.com/ome/omero-scripts/blob/5a2c392d0e4bc5ee451ac18f9866ad68b53ec46d/omero/util_scripts/Dataset_To_Plate.py#L60

In fact, you might find that script useful, for organising images from a Dataset into a Plate. It ships with OMERO out of the box.

I think maybe you just need to not call well.save() or ws.save() and instead call well.addWellSample() first, then well.save().

Hope that works,
Will.

1 Like

That was exactly what I was looking for, @will-moore, thank you!

I had forgotten that I knew about that script :laughing:

I got everything working and will have an excellent launching point when we start needed to deal with a lot of screen data. And thanks again @manics, although it wasn’t what I was looking for, I fell deep down an OMERO testing rabbit hole (in a good way :slight_smile:)

Just for the sake of completeness, here is where the code ended up:

    update_service = conn.getUpdateService()

    # Create Screen
    screen_name = "screen_" + timestamp
    screen = ScreenWrapper(conn, ScreenI())
    screen.setName(screen_name)
    screen.save()
    screen_id = screen.getId()

    # Create Plate
    plate_name = "plate_" + timestamp
    plate = PlateWrapper(conn, PlateI())
    plate.setName(plate_name)
    plate.save()
    plate_id = plate.getId()
    link = ScreenPlateLinkI()
    link.setParent(ScreenI(screen_id, False))
    link.setChild(PlateI(plate_id, False))
    update_service.saveObject(link)

    # Create Well
    #well = WellWrapper(conn, WellI())
    well = WellI()
    well.setPlate(PlateI(plate_id, False))
    well.setColumn(rint(1))
    well.setRow(rint(1))
    well.setPlate(PlateI(plate_id, False))

    # Create Well Sample with Image
    ws = WellSampleI()
    ws.setImage(ImageI(im_id))
    well.addWellSample(ws)
    update_service.saveObject(well)