We're Hiring!

Add wellsamples to well throws ConstraintViolationException

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

Add wellsamples to well throws ConstraintViolationException

Postby andersla » Thu Mar 14, 2019 3:14 pm

Hello,
I am trying to add several well-samples to a well but get validation error.
Creating the first wellsample with this code is fine and wellsample is inserted in database. But looping it to add other wellsamples for same well throws error.

In documentation https://docs.openmicroscopy.org/ome-mod ... -well.html (under Wellsample) it says that Index should be unique, but I don't see a way to set the index, It seem to be auto-updated by a trigger.

wellsample = omero.model.WellSampleI()
wellsample.setImage(image) # image is referred to via a search for id above
wellsample.well = well # well is created above
wellsample.setPlateAcquisition(plateaq) # plate aq is created above
well.addWellSample(wellsample)
wellsample = conn.getUpdateService().saveAndReturnObject(wellsample)

Error:

serverStackTrace = ome.conditions.ValidationException: could not insert: [ome.model.screen.WellSample]; SQL [insert into wellsample (creation_id, external_id, group_id, owner_id, permissions, update_id, image, plateAcquisition, posXUnit, posX, posYUnit, posY, timepoint, version, well, well_index, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; constraint [wellsample_well_well_index_key]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [ome.model.screen.WellSample]


All the best,
Anders
andersla
 
Posts: 9
Joined: Wed Feb 13, 2019 8:18 am

Re: Add wellsamples to well throws ConstraintViolationExcept

Postby mtbc » Fri Mar 15, 2019 11:04 am

Dear Anders,

That documentation is for the OME Data Model. The OMERO model does not exactly match: see https://docs.openmicroscopy.org/latest/ ... wellsample instead which has no index. The index is implicitly handled by the order in which you use well.addWellSample(wellsample); you probably don't need to also use wellsample.well = well.

I suspect your problem lies in previous code: especially, if you created and saved a model object but are not now using the updated version. Would you be able to provide a minimal but full script that shows your problem? We could probably then offer an on-point suggestion. You shouldn't have to populate much to reproduce it: just names of plates and images and whatnot. Or just load objects by ID from your DB and we can fill in mock ones at this side to reproduce your issue.

Cheers,
Mark
User avatar
mtbc
Team Member
 
Posts: 282
Joined: Tue Oct 23, 2012 10:59 am
Location: Dundee, Scotland

Re: Add wellsamples to well throws ConstraintViolationExcept

Postby andersla » Mon Mar 18, 2019 1:47 pm

Dear Mark (et al.),
Thanks for your generous offer of helping out!

Here is the code in our git-hub repo ( https://github.com/pharmbio/omero/ )

You should be able to just clone the repo an then docker-compose up (docker and docker-compose needed on system).
And then execute the script, -test images are in the repo.

Please see README at: https://github.com/pharmbio/omero/tree/master/dev for the commands needed to run this dev-project.

Please let me know if I instead should come up with a smaller code snippet for the exact problematic code as you suggested?

I also have a more general question about importing images:

- Whar is your recommended way for an automated process of importing ca 10000 images every day from an automated robot-microscope-screening setup (we use an ImageXpress XLS microscope)?

- Do you have an alternative solution (better?) to what we are trying to accomplish with this import script?

All the best,
Anders
andersla
 
Posts: 9
Joined: Wed Feb 13, 2019 8:18 am

Re: Add wellsamples to well throws ConstraintViolationExcept

Postby wmoore » Mon Mar 18, 2019 3:49 pm

I've added multiple Images per Well support to our Dataset_To_Plate script at https://github.com/ome/scripts/pull/146 (pending review).
Hopefully this will help to add the same functionality to your script?
However, this code currently requires that you add all the images to a new Well in one shot (instead of adding additional images to the Well after creation). Let us know if adding Images after Well creation would be useful?

I noticed that your current script doesn't combine multiple TIFFs into multi-channel images?

One option for importing TIFFs to create multi-channel images is to create the images via the Python API. See example at https://gist.github.com/will-moore/cea1 ... efc649a25b

Another option is to call the import directly via the Python API. See the example at https://gitlab.com/openmicroscopy/incub ... /import.py
You could use a "pattern file" (see https://docs.openmicroscopy.org/bio-for ... -file.html) within each fileset to specify the grouping of multiple TIFFs into a multi-channel image.

Pattern files could also be used with the command-line based import you're currently using.

Regards,

Will
User avatar
wmoore
Team Member
 
Posts: 674
Joined: Mon May 18, 2009 12:46 pm

Re: Add wellsamples to well throws ConstraintViolationExcept

Postby wmoore » Tue Mar 19, 2019 1:35 am

I opened a PR to fix the issue above at https://github.com/pharmbio/omero/pull/1
and added a pattern file at https://github.com/pharmbio/omero/pull/2 as an example of how to group images on import.
User avatar
wmoore
Team Member
 
Posts: 674
Joined: Mon May 18, 2009 12:46 pm

Re: Add wellsamples to well throws ConstraintViolationExcept

Postby andersla » Tue Mar 19, 2019 7:43 am

Thank you!
PR merged an it works fine!

I looked at the python importer and would prefer to use that code instead of calling the cli-import-function that we are using at the moment, but we would like to do in-place imports, and I guess it is not handling in-place imports yet?
I saw some discussion about doing in-place imports at: viewtopic.php?f=4&t=8658&p=20537&hilit=in+place+python#p20537 , but I guess I am not comfortable enough with the Omero-code to write the in-place code myself:-)

If I merge the files with this pattern file and the import function, is that mainly a metadata merge where 3 images are grouped together in the database as a fileset where I can view all channels in the Omero GUI as one image? or is it an actual merge of the files into a single TIF?

We will mainly be using the images for machine learning (not my personal expertise), but I will consult my group about merging the images, I dont know If the ml-algorithms and code being used prefer separate image per color or a merged image.

All the best,
Anders
andersla
 
Posts: 9
Joined: Wed Feb 13, 2019 8:18 am

Re: Add wellsamples to well throws ConstraintViolationExcept

Postby wmoore » Tue Mar 19, 2019 1:19 pm

Hi Anders,

With the 3 tiffs combined to a single image, you can still access each plane of the image separately as a 2D numpy array:

Code: Select all
pixels = conn.getObject('Image', image_id).getPrimaryPixels()
plane = pixels.getPlane(z_index, channel, t_index)


The advantage of combining tiffs to a multi-channel image (and creating tools to work with them) is that your tools will be compatible with other multi-channel images on your server or for use on other OMERO servers with images from other sources.

Regards,
Will.
User avatar
wmoore
Team Member
 
Posts: 674
Joined: Mon May 18, 2009 12:46 pm


Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 1 guest