Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

csv to label properties #63

Merged
merged 6 commits into from
Nov 30, 2020
Merged

Conversation

will-moore
Copy link
Member

@will-moore will-moore commented Nov 19, 2020

Takes a csv file with 1 row per Mask (e.g. exported from OMERO with Batch_ROI_Export) and uses it to
add properties to the labels metadata in ome-zarr.
You need to specify which column of the csv contains an ID that matches a specified ID of each properties dict.

E.g. if you have exported labels from OMERO with ome/omero-cli-zarr#50 then each properties dict will have e.g. "omero:shapeId": 123 and this will correspond to the shape_id column of the Batch_ROI_Export.csv.

You also want to specify columns from the csv to use, e.g. "area (pixels),X,Y,Width,Height".
You can also specify the column types (as in https://github.com/ome/omero-metadata/) to specify the data-type for each column (string by default).

  • d: DoubleColumn, for floating point numbers
  • l: LongColumn, for integer numbers
  • s: StringColumn, for text
  • b: BoolColumn, for true/false

Use e.g. #d as a suffix in the column name to denote a float column, no spaces etc:

"area (pixels)#d,well_label#s,Width#l,Height#l"

If you have a Plate exported to ome-zarr as "251.zarr", then you can do this:

ome_zarr csv_to_labels plate251_ch1.csv shape_id "area (pixels)#d,well_label#s,Width#l,Height#l" 251.zarr omero:shapeId

Then you can open a Well (field 0) in napari, and the properties will be read by #61 cc @DragaDoncila and you will be able to see the properties from the csv (bottom left) when you mouse over a label

napari 251.zarr/A/1/0

Screenshot 2020-11-19 at 09 13 55

You can then use the properties to update label colors:

layer = viewer.layers[-1]

for c, value in enumerate(layer.properties["area (pixels)"]):
    index = layer.properties["index"][c]
    if value > 2500:
        layer.color[index] = np.array([1, 0, 1, 1], dtype=np.float32)
    elif value < 2000:
        layer.color[index] = np.array([1, 1, 1, 1], dtype=np.float32)
    else:
        layer.color[index] = np.array([0, 1, 0, 1], dtype=np.float32)
   
# force refresh
layer.color_mode = "direct"

Screenshot 2020-11-19 at 13 28 40

TODO:

  • Also support single Images in ome-zarr instead of whole Plate
  • Parse csv number columns as numbers

@will-moore will-moore changed the title read csv file to label props on a zarr plate csv to label properties Nov 20, 2020
@will-moore will-moore marked this pull request as ready for review November 20, 2020 10:26
@joshmoore joshmoore added this to In progress in OME Zarr HCS (Fall 2020) Nov 23, 2020
@joshmoore
Copy link
Member

Something like this was needed to omit missing labels:

(o) [jamoore@pilot-zarr1-dev 2551.zarr]$ (cd /data/josh/ome-zarr-py/; git diff)
diff --git a/ome_zarr/csv.py b/ome_zarr/csv.py
index de287e3..bdcb012 100644
--- a/ome_zarr/csv.py
+++ b/ome_zarr/csv.py
@@ -127,7 +127,10 @@ def dict_to_zarr(

     for path_to_labels in labels_paths:

-        label_group = zarr_open(path_to_labels)
+        try:
+            label_group = zarr_open(path_to_labels)
+        except:
+            continue
         attrs = label_group.attrs.asdict()
         properties = attrs.get("image-label", {}).get("properties")
         if properties is None:

@will-moore
Copy link
Member Author

Ah, Thanks. Yes, I've just viewed the plate with labels and noticed that some Wells are missing labels:

napari https://s3.embassy.ebi.ac.uk/idr/zarr/v0.1/plates/2551.zarr

Screenshot 2020-11-29 at 22 08 40

@joshmoore
Copy link
Member

Considering the test of 2551 successful since the source plate (2551 above) is also missing those labels. Merging for the next tag.

@joshmoore joshmoore merged commit 85436bb into ome:master Nov 30, 2020
OME Zarr HCS (Fall 2020) automation moved this from In progress to Done Nov 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants