diff --git a/omeroweb/webclient/views.py b/omeroweb/webclient/views.py index 0978f6d4e0..0dfb072c91 100755 --- a/omeroweb/webclient/views.py +++ b/omeroweb/webclient/views.py @@ -1468,6 +1468,23 @@ def load_plate(request, o1_type=None, o1_id=None, conn=None, **kwargs): template = None if "plate" in kw or "acquisition" in kw: fields = manager.getNumberOfFields() + if "acquisition" in kw: + # need to offset the index for 0-indexing at acquisition level + qs = conn.getQueryService() + p = omero.sys.ParametersI() + p.add("acqid", rlong(o1_id)) + query = ( + "SELECT max(index(ws)) - min(index(ws)) " + "FROM Well w " + "JOIN w.wellSamples ws " + "WHERE ws.plateAcquisition.id = :acqid " + "GROUP BY w.id" + ) + res = [r[0].getValue() for r in qs.projection(query, p, conn.SERVICE_OPTS)] + if len(res) >= 1: + # The range of the fields is set for the current acquisition + fields = (0, max(res)) + if fields is not None: form_well_index = WellIndexForm(initial={"index": index, "range": fields}) if index == 0: diff --git a/omeroweb/webgateway/plategrid.py b/omeroweb/webgateway/plategrid.py index ac076045ef..27a9bf6631 100644 --- a/omeroweb/webgateway/plategrid.py +++ b/omeroweb/webgateway/plategrid.py @@ -25,12 +25,15 @@ class PlateGrid(object): methods useful for displaying the contents of the plate as a grid. """ - def __init__(self, conn, pid, fid, acqid, thumbprefix="", plate_layout=None): + def __init__(self, conn, pid, fid, thumbprefix="", plate_layout=None, acqid=0): """ Constructor param: plate_layout is "expand" to expand plate to multiple of 8 x 12 or "shrink" to ignore all wells before the first row/column + + acqid: the acquisition ID. Using it, the field index (fid) must + be in the range [0, max_sample_per_well] for that acquisition. """ self.plate = conn.getObject("plate", int(pid)) self._conn = conn @@ -58,11 +61,22 @@ def metadata(self): "join ws.image img " "join img.details.owner author " "where well.plate.id = :id " - "and index(ws) = :wsidx" ) if self.acquisition > 0: + # Offseting index per well for the plateacquisition + query += ( + "and ws.plateAcquisition.id = :acqid " + "and index(ws) - (" + " SELECT MIN(index(ws_inner)) " + " FROM Well well_inner " + " JOIN well_inner.wellSamples ws_inner " + " WHERE ws_inner.plateAcquisition.id = :acqid " + " AND well_inner.id = well.id " + ") = :wsidx " + ) params.add("acqid", rlong(self.acquisition)) - query += " and ws.plateAcquisition.id = :acqid" + else: + query += "and index(ws) = :wsidx " results = q.projection(query, params, self._conn.SERVICE_OPTS) min_row = 0 diff --git a/omeroweb/webgateway/views.py b/omeroweb/webgateway/views.py index f0cb0b8c68..7d82712744 100644 --- a/omeroweb/webgateway/views.py +++ b/omeroweb/webgateway/views.py @@ -1675,9 +1675,9 @@ def get_thumb_url(iid): conn, pid, field, - acquisition, thumbprefix=kwargs.get("urlprefix", get_thumb_url), plate_layout=layout, + acqid=acquisition ) plate = plateGrid.plate