# HG changeset patch
# User goeckslab
# Date 1672255562 0
# Node ID 187918c47051ea76f067e636d72db7dfc7620eae
# Parent 02abff468d60b69261430b64731fe115614d82fa
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/mesmer commit 40737a3341bb2352f4f8560889bb53362fd624be
diff -r 02abff468d60 -r 187918c47051 Dockerfile
--- a/Dockerfile Thu Nov 10 20:38:34 2022 +0000
+++ b/Dockerfile Wed Dec 28 19:26:02 2022 +0000
@@ -1,5 +1,7 @@
-ARG VERSION=0.3.1
+ARG VERSION=0.12.3
-FROM vanvalenlab/deepcell-applications:${VERSION}
+FROM vanvalenlab/deepcell-tf:${VERSION}
+
+RUN pip install imagecodecs zarr
ENTRYPOINT []
diff -r 02abff468d60 -r 187918c47051 macros.xml
--- a/macros.xml Thu Nov 10 20:38:34 2022 +0000
+++ b/macros.xml Wed Dec 28 19:26:02 2022 +0000
@@ -2,7 +2,7 @@
- quay.io/goeckslab/mesmer:@TOOL_VERSION@
+ quay.io/goeckslab/deepcell:@TOOL_VERSION@
@@ -25,16 +25,42 @@
description="Out of Memory" />
-
- @CMD_BEGIN@ --help
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
10.1038/s41587-021-01094-0
- 0.3.1
- 1
- python /usr/src/app/run_app.py mesmer
+ 0.12.3
+ 2
diff -r 02abff468d60 -r 187918c47051 mesmer.xml
--- a/mesmer.xml Thu Nov 10 20:38:34 2022 +0000
+++ b/mesmer.xml Wed Dec 28 19:26:02 2022 +0000
@@ -7,63 +7,189 @@
-
+
+
+import argparse
+import os
+import sys
+
+import numpy as np
+import tifffile
+import zarr
+
+from deepcell.applications import Mesmer
+
+level = 0
+is_ome=False
+#if $image.file_ext == "ome.tiff":
+is_ome=True
+#end if
+
+## Grab params
+nuc_kwargs = {}
+wc_kwargs = {}
+
+
+with tifffile.TiffFile("$image", is_ome=is_ome) as tiff:
+
+ # Read single pyramid level
+ level_array = zarr.open(tiff.aszarr(series = 0, level = level))
+
+ ## grab the nuclear and membrane channels based on their indices add the markers along the channel axis
+ ## Tifffile should always read as (channel,X,Y)
+ #if $compartment_select.compartment != 'whole-cell':
+ nuc_kwargs = {
+ #if $compartment_select.nuclear_options.pixel_expansion != '':
+ 'pixel_expansion': $compartment_select.nuclear_options.pixel_expansion,
+ #end if
+ #for $key, $value in $dict.items($compartment_select.nuclear_options.adv_options)
+ '$key': $value,
+ #end for
+ 'maxima_threshold': $compartment_select.nuclear_options.maxima_threshold
+ }
+ #end if
+
+ nuclear_indices = [int(x) for x in $nuclear_channels.split(',')]
+ nuclear_channels = level_array.oindex[nuclear_indices, :, :]
+ nuclear_channels = np.sum(nuclear_channels, axis = 0)
- #if $membrane_select.membrane_segment == "True":
- --membrane-image '$membrane_select.membrane_image'
- --membrane-channel '$membrane_select.membrane_channel'
+ #if $compartment_select.compartment != 'nuclear':
+ wc_kwargs = {
+ #for $key, $value in $dict.items($compartment_select.wc_options.adv_options)
+ '$key': $value,
+ #end for
+ 'maxima_threshold': $compartment_select.wc_options.maxima_threshold
+ }
+
+ membrane_indices = [int(x) for x in $compartment_select.wc_options.wc_channels.split(',')]
+ membrane_channels = level_array.oindex[membrane_indices, :, :]
+ membrane_channels = np.sum(membrane_channels, axis = 0)
+ #end if
+
+ ## stack the nuclear and membrane composite channels with nuclear in channel 0 and mem in channel 1
+ ## mesmer expects dimensions to be (X,Y,Channel) so axis = -1
+ #if $compartment_select.compartment == 'nuclear':
+ membrane_channels = np.zeros(nuclear_channels.shape)
#end if
- ]]>
+ formatted_image = np.stack((nuclear_channels,membrane_channels), axis=-1)
+
+ ## add batch dimension. Will have to be squeezed out later
+ formatted_image = np.expand_dims(formatted_image, 0)
+
+## Create the application
+app = Mesmer()
+
+## Run segmentation
+mask = app.predict(
+ formatted_image,
+ image_mpp = $image_mpp,
+ compartment = "$compartment_select.compartment",
+ pad_mode = 'constant',
+ postprocess_kwargs_whole_cell = wc_kwargs,
+ postprocess_kwargs_nuclear = nuc_kwargs)
+#if $squeeze:
+mask = np.squeeze(mask)
+#end if
+
+#if $compartment_select.compartment == 'both':
+## split the two-channel mask into separate outputs
+ #if $squeeze:
+tifffile.imsave( "WC_output_mask.tif", mask[:,:,0])
+tifffile.imsave("NU_output_mask.tif", mask[:,:,1])
+ #else:
+tifffile.imsave( "WC_output_mask.tif", mask[:,:,:,0])
+tifffile.imsave("NU_output_mask.tif", mask[:,:,:,1])
+ #end if
+#else:
+## save single-channel mask outputs as a tiff
+tifffile.imsave("mask.tif", mask)
+#end if
+
+
-
-
-
-
-
-
+
+
-
-
-
-
-
+
+
+
+
+
+
-
-
-
+
+
-
+
+
+
+
+
+
+
+
-
+
+ compartment_select['compartment'] == 'both'
+
+
+ compartment_select['compartment'] == 'both'
+
+
+ compartment_select['compartment'] != 'both'
+
-
-
+
+
-
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+