Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 31 additions & 33 deletions maintenance/preparation/idr0021-data-prep.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,57 +43,47 @@ In the webclient, create a Project 'idr0021' and add the 10 new Datasets created
Add Map Annotations from IDR
============================

Edit the script [idr_get_map_annotations.py](../scripts/idr_get_map_annotations.py) with the ID of the 'idr0021' Project created
above. This will get map annotations from all images in the [idr0021](https://idr.openmicroscopy.org/webclient/?show=project-51) and create identical map annotations on the corresponding images.
Run the script [idr_get_map_annotations.py](../scripts/idr_get_map_annotations.py) with the ID of the 'idr0021' Project created
above. See the script for usage details. This will get map annotations from all images in the [idr0021](https://idr.openmicroscopy.org/webclient/?show=project-51) and create identical map annotations on the corresponding images.


Rename Channels from Map Annotations
====================================

We can now use the map annotations to rename channels on all images.
Edit the ```project_id``` and run the [channel_names_from_maps.py](../scripts/channel_names_from_maps.py)
script on the local data.
Run the [channel_names_from_maps.py](../scripts/channel_names_from_maps.py)
script on the local data, passing in the `Project ID`.


Analyse in Fiji and save ROIs in OMERO
======================================

Run [analyse_particles_for_another_user.jy](../../practical/jython/analyse_particles_for_another_user.jy) in Fiji with the
appropriate credentials on a Dataset at a time, updating the dataset_id each time.
First we need to delete an Image that is the only Z-stack and is analyzed differently from the others:
```NEDD1ab_NEDD1141_I_012_SIR.dv``` in Dataset ```NEDD1-C1```.

This will Analyse Particles and create ROIs on all channels of each Image.
Run [idr0021.groovy](https://github.com/ome/omero-guide-fiji/blob/master/scripts/groovy/idr0021.groovy) in Fiji with the
appropriate credentials on the `idr0021` Project.

This script also creates a summary OMERO.table one row per image containing measurements results
e.g. the bounding box of the biggest ROI.
The table is linked to the Project. The output is also saved as a CSV file and linked to the Project.
This will Analyse Particles and create ROIs on all channels of each Image, using Channel names to pick the correct
Channel for each Image.


Create Map Annotations and Table from ROIs
==========================================

First we need to delete an outlier Image that causes
[problems in OMERO.parade](https://github.com/ome/omero-parade/issues/26). Delete
```NEDD1ab_NEDD1141_I_012_SIR```. This image is the only Z-stack and no blobs are found
so the Polygon created covers the whole plane.

The [batch_roi_export_to_table.py](../../practical/python/server/batch_roi_export_to_table.py) script needs to be installed on the server. Run this from the webclient, selecting the ```idr0021``` Project to create a single Table on this Project, that has rows for all Images in the Project.

This script uses the Channel Names to pick a Channel that matches the Dataset name
for each Image. This is the Channel that needs to be analysed and is used to filter Shapes created
by Fiji.

This script also creates Map annotations and can create a CSV (could be shown in workshop).
Options for these are handled by checkboxes at the bottom of the script dialog.
This script also creates a summary OMERO.table on the `idr0021` Project, named `Summary_from_Fiji`.
This can be seen under the `Attachments` tab for the Project, with an `eye` icon that will open the table.
The table has one row per image containing measurements results
e.g. the area of the bounding box of the biggest ROI.
The output is also saved as a CSV file and linked to the Project.


Delete ROIs and Map annotations for 1 Dataset
=============================================

Edit and run the following scripts on the first Dataset
to remove Map Annotations and ROIs from all Images in that Dataset so we can show them being
created in the workshop:
If you wish to remove ROIs from all Images in a Dataset so we can show them being
created in the workshop use the Dataset ID:

$ omero delete Dataset/Image/Roi:DATASET_ID

If you wish to do this for all users, using the Dataset name for each user, use:

- [delete_annotations.py](../scripts/delete_annotations.py)
- [delete_ROIs.py](../scripts/delete_ROIs.py)

The data is now ready to be presented in a workshop and analysed with ```OMERO.parade```.
Expand All @@ -109,9 +99,17 @@ and import this:

$ path/to/omero import INMAC384-DAPI-CM-eGFP_59223_1

Alternatively, you can copy a Plate from IDR, copying only the first Z and T index of each Image, using
[idr_copy_plate.py](../scripts/idr_copy_plate.py). This will ask for login details of the server where you
wish to copy the Plate. IDR [Plate 422](http://idr.openmicroscopy.org/webclient/?show=plate-422) is a
suitable Plate:

$ python maintenance/scripts/idr_copy_plate.py 422

We need to populate an OMERO.table on the Plate to demonstrate filtering with
OMERO.parade. For that we will use the [channel_minmax_to_table.py](../scripts/channel_minmax_to_table.py). Run the command line script with the Plate ID:
OMERO.parade. For that we will use the [channel_minmax_to_table.py](../scripts/channel_minmax_to_table.py).
Run the command line script with the Plate ID:

$ python maintenance/scripts/channel_minmax_to_table.py username password --server server.address plate_id
$ python maintenance/scripts/channel_minmax_to_table.py PLATE_ID

This should create an Annotation on the Plate called ``Channels_Min_Max_Intensity``.
140 changes: 68 additions & 72 deletions maintenance/scripts/channel_minmax_to_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import argparse
import omero
from omero.cli import cli_login
from omero.rtypes import rstring
import omero.grid
from omero.gateway import BlitzGateway
Expand All @@ -29,58 +30,57 @@
NAMESPACE = "openmicroscopy.org/omero/bulk_annotations"


def run(username, password, plate_id, host, port):

conn = BlitzGateway(username, password, host=host, port=port)
def run(conn, plate_id):

query_service = conn.getQueryService()

# Create a name for the Original File
tablename = "Channels_Min_Max_Intensity"

# Go through all wells in Plate, adding row for each
plate = conn.getObject("Plate", plate_id)
wellIds = []
rowData = []
chCount = 0
for well in plate._listChildren():
well = omero.gateway.WellWrapper(conn, well)
image = well.getImage()
if image is None:
continue
wellIds.append(well.id)
chCount = image.getSizeC()
row = []
print("well, image", well.id, image.id)

params = omero.sys.ParametersI()
params.addId(image.getPixelsId())
query = """select pixels from Pixels as pixels
left outer join fetch pixels.channels as channels
join fetch channels.statsInfo where pixels.id=:id"""
result = query_service.findAllByQuery(query, params)

row = []
for pix in result:
for ch in pix.iterateChannels():
si = ch.statsInfo
row.extend([si.globalMin.val, si.globalMax.val])
rowData.append(row)

print('wellIds', wellIds)
print('rowData', rowData)

# Now we know how many channels, we can make the table
col1 = omero.grid.WellColumn('Well', '', [])
columns = [col1]
colNames = []
for chIdx in range(chCount):
for name in ['Ch%sMin' % chIdx, 'Ch%sMax' % chIdx]:
colNames.append(name)
columns.append(omero.grid.LongColumn(name, '', []))

table = conn.c.sf.sharedResources().newTable(1, tablename)
orig_file = None
try:
conn.connect()
query_service = conn.getQueryService()

# Create a name for the Original File
tablename = "Channels_Min_Max_Intensity"

# Go through all wells in Plate, adding row for each
plate = conn.getObject("Plate", plate_id)
wellIds = []
rowData = []
chCount = 0
for well in plate._listChildren():
well = omero.gateway.WellWrapper(conn, well)
image = well.getImage()
if image is None:
continue
wellIds.append(well.id)
chCount = image.getSizeC()
row = []
print("well, image", well.id, image.id)

params = omero.sys.ParametersI()
params.addId(image.getPixelsId())
query = """select pixels from Pixels as pixels
left outer join fetch pixels.channels as channels
join fetch channels.statsInfo where pixels.id=:id"""
result = query_service.findAllByQuery(query, params)

row = []
for pix in result:
for ch in pix.iterateChannels():
si = ch.statsInfo
row.extend([si.globalMin.val, si.globalMax.val])
rowData.append(row)

print('wellIds', wellIds)
print('rowData', rowData)

# Now we know how many channels, we can make the table
col1 = omero.grid.WellColumn('Well', '', [])
columns = [col1]
colNames = []
for chIdx in range(chCount):
for name in ['Ch%sMin' % chIdx, 'Ch%sMax' % chIdx]:
colNames.append(name)
columns.append(omero.grid.LongColumn(name, '', []))

table = conn.c.sf.sharedResources().newTable(1, tablename)
table.initialize(columns)

# Add Data from above
Expand All @@ -94,37 +94,33 @@ def run(username, password, plate_id, host, port):

print("Adding data: ", len(data))
table.addData(data)
table.close()

print("table closed...")
orig_file = table.getOriginalFile()
fileAnn = omero.model.FileAnnotationI()
fileAnn.ns = rstring(NAMESPACE)
fileAnn.setFile(omero.model.OriginalFileI(orig_file.id.val, False))
fileAnn = conn.getUpdateService().saveAndReturnObject(fileAnn)
link = omero.model.PlateAnnotationLinkI()
link.setParent(omero.model.PlateI(plate_id, False))
link.setChild(omero.model.FileAnnotationI(fileAnn.id.val, False))

print("save link...")
conn.getUpdateService().saveAndReturnObject(link)

except Exception as exc:
print("Error while changing names: %s" % str(exc))
finally:
conn.close()
table.close()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the table could now never be closed if an error is thrown during the save step below

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was also possible before that it didn't get closed if an exception was thrown between table creation and closing.
But yes, a try/finally would be safer. I'll add that...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9632c0d


if orig_file is None:
print("Table creation failed")
fileAnn = omero.model.FileAnnotationI()
fileAnn.ns = rstring(NAMESPACE)
fileAnn.setFile(omero.model.OriginalFileI(orig_file.id.val, False))
fileAnn = conn.getUpdateService().saveAndReturnObject(fileAnn)
link = omero.model.PlateAnnotationLinkI()
link.setParent(omero.model.PlateI(plate_id, False))
link.setChild(omero.model.FileAnnotationI(fileAnn.id.val, False))

print("save link...")
conn.getUpdateService().saveAndReturnObject(link)


def main(args):
parser = argparse.ArgumentParser()
parser.add_argument('username')
parser.add_argument('password')
parser.add_argument('plate_id')
parser.add_argument('--server', default="workshop.openmicroscopy.org",
help="OMERO server hostname")
parser.add_argument('--port', default=4064, help="OMERO server port")
args = parser.parse_args(args)
run(args.username, args.password, args.plate_id, args.server, args.port)
with cli_login() as cli:
conn = BlitzGateway(client_obj=cli._client)
run(conn, args.plate_id)


if __name__ == '__main__':
Expand Down
21 changes: 8 additions & 13 deletions maintenance/scripts/idr_copy_plate.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import argparse
import omero
from omero.cli import cli_login
from omero.gateway import BlitzGateway
from omero.rtypes import rint, rstring
from omero.model import PlateI
Expand Down Expand Up @@ -69,12 +70,8 @@ def add_images_to_plate(update_service, plate, images, row, column):
update_service.saveObject(ws)


def run(username, password, plate_id, host, port):
def run(conn, plate_id):
"""Run the script."""
# Create connection to training server
conn = BlitzGateway(username, password, host=host, port=port)
conn.connect()

# Create connection to IDR server
# NB: conn.connect() not working on IDR. Do it like this
idr_client = omero.client(host="idr.openmicroscopy.org", port=4064)
Expand Down Expand Up @@ -104,21 +101,19 @@ def run(username, password, plate_id, host, port):
add_images_to_plate(update_service, plate, new_imgs,
idr_well.row, idr_well.column)

conn.close()
idr_conn.close()
print("Created Plate:", plate.id.val)


def main(args):
"""Entry point. Parse args and run."""
parser = argparse.ArgumentParser()
parser.add_argument('username')
parser.add_argument('password')
parser.add_argument('plate_id')
parser.add_argument('--server', default="workshop.openmicroscopy.org",
help="OMERO server hostname")
parser.add_argument('--port', default=4064, help="OMERO server port")

args = parser.parse_args(args)
run(args.username, args.password, args.plate_id, args.server, args.port)

with cli_login() as cli:
conn = BlitzGateway(client_obj=cli._client)
run(conn, args.plate_id)


if __name__ == '__main__':
Expand Down
Loading