Skip to content

Commit

Permalink
Merge 57d20ec into d6e5a45
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlLevik committed Feb 3, 2020
2 parents d6e5a45 + 57d20ec commit 6a794ac
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
14 changes: 14 additions & 0 deletions HISTORY.rst
Expand Up @@ -2,6 +2,20 @@
History
=======

Unreleased / master
-------------------

* Object model for Screening tables
* set_role
* New module for crystal imaging: xtalimaging

5.5.0 (2020-01-07)
------------------

New methods:
* upsert_program_message
* upsert_sample_image_auto_score

5.4.1 (2019-11-12)
------------------

Expand Down
5 changes: 5 additions & 0 deletions ispyb/interface/factory.py
Expand Up @@ -42,6 +42,11 @@ def mx_screening(self):
"""MX screening tables"""
return self._get_data_area("mxscreening", "MXScreening")

@property
def xtal_imaging(self):
"""Crystal imaging tables"""
return self._get_data_area("xtalimaging", "XtalImaging")

@property
def shipping(self):
"""Shipping tables"""
Expand Down
69 changes: 69 additions & 0 deletions ispyb/sp/xtalimaging.py
@@ -0,0 +1,69 @@
from __future__ import absolute_import, division, print_function

from ispyb.interface.dataarea import DataArea


class XtalImaging(DataArea):
"""provides methods for accessing crystal imaging tables."""

def upsert_sample_image(
self,
id=None,
sample_id=None,
inspection_id=None,
microns_per_pixel_x=None,
microns_per_pixel_y=None,
image_full_path=None,
comments=None,
):
"""Store new or update existing sample image.
:param image_full_path: The full path to the sample image
:return: The sample_image_id.
"""
return self.get_connection().call_sp_write(
procname="upsert_sample_image",
args=[
id,
sample_id,
inspection_id,
microns_per_pixel_x,
microns_per_pixel_y,
image_full_path,
comments,
],
)

def upsert_sample_image_auto_score(
self, image_full_path, schema_name, score_class, probability
):
"""Store new or update existing automatic score for a sample image.
:param image_full_path: The full path to the sample image
:param schema_name: The name of the scoring schema, e.g. MARCO
:param score_class: A string that describes the thing we're scoring, e.g. crystal, clear, precipitant, other
:param probability: A float indicating the probability that the image contains the score_class
"""
self.get_connection().call_sp_write(
procname="upsert_sample_image_auto_score",
args=[image_full_path, schema_name, score_class, probability],
)

def retrieve_container_for_barcode(self, barcode):
"""Retrieve info about the container indetified by the give barcode."""
return self.get_connection().call_sp_retrieve(
procname="retrieve_container_for_barcode", args=[barcode]
)

def retrieve_container_for_inspection_id(self, inspection_id):
"""Retrieve info about the container identified by container inspection ID"""
return self.get_connection().call_sp_retrieve(
procname="retrieve_container_for_inspection_id", args=[inspection_id]
)

def retrieve_sample_for_container_id_and_location(self, container_id, location):
"""Retrieve info about the sample identified by the given container ID and its location."""
return self.get_connection().call_sp_retrieve(
procname="retrieve_sample_for_container_id_and_location",
args=[container_id, location],
)
39 changes: 39 additions & 0 deletions tests/test_xtalimaging.py
@@ -0,0 +1,39 @@
from __future__ import absolute_import, division, print_function


def test_xtal_imaging(testdb):
testdb.set_role("ispyb_import")
xtalimaging = testdb.xtal_imaging

container = xtalimaging.retrieve_container_for_barcode("test_plate2")
cid = container[0]["containerId"]

assert cid is not None
assert cid > 0

sample = xtalimaging.retrieve_sample_for_container_id_and_location(
container_id=cid, location=1
)
sid = sample[0]["sampleId"]

assert sid is not None
assert sid > 0

si_full_path = "/dls/i03/data/2018/cm14451-99/something_new.jpg"
siid = xtalimaging.upsert_sample_image(
sample_id=sid,
microns_per_pixel_x=12.03,
microns_per_pixel_y=12.04,
image_full_path=si_full_path,
)

assert siid is not None
assert siid > 0

xtalimaging.upsert_sample_image_auto_score(si_full_path, "MARCO", "crystal", 0.65)

container = xtalimaging.retrieve_container_for_inspection_id(4)
cid2 = container[0]["containerId"]

assert cid2 is not None
assert cid2 == 34874

0 comments on commit 6a794ac

Please sign in to comment.