Mercurial > repos > goeckslab > mesmer
comparison mesmer.xml @ 2:187918c47051 draft
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/mesmer commit 40737a3341bb2352f4f8560889bb53362fd624be
author | goeckslab |
---|---|
date | Wed, 28 Dec 2022 19:26:02 +0000 |
parents | 02abff468d60 |
children | c60b810d570d |
comparison
equal
deleted
inserted
replaced
1:02abff468d60 | 2:187918c47051 |
---|---|
5 <import>macros.xml</import> | 5 <import>macros.xml</import> |
6 </macros> | 6 </macros> |
7 | 7 |
8 <expand macro="requirements"/> | 8 <expand macro="requirements"/> |
9 <expand macro="stdio"/> | 9 <expand macro="stdio"/> |
10 <expand macro="version_cmd"/> | |
11 | 10 |
12 <command detect_errors="exit_code"><![CDATA[ | 11 <command detect_errors="exit_code"><![CDATA[ |
13 ln -s '$nuclear_image' 'input.tif' && | 12 python $script |
14 @CMD_BEGIN@ | |
15 --output-directory ./ | |
16 --output-name 'mask.tif' | |
17 --nuclear-image 'input.tif' | |
18 --nuclear-channel $nuclear_channel | |
19 --compartment $compartment | |
20 --image-mpp $image_mpp | |
21 $squeeze | |
22 | |
23 #if $membrane_select.membrane_segment == "True": | |
24 --membrane-image '$membrane_select.membrane_image' | |
25 --membrane-channel '$membrane_select.membrane_channel' | |
26 #end if | |
27 ]]></command> | 13 ]]></command> |
28 | 14 <configfiles> |
15 <configfile name="script"> | |
16 import argparse | |
17 import os | |
18 import sys | |
19 | |
20 import numpy as np | |
21 import tifffile | |
22 import zarr | |
23 | |
24 from deepcell.applications import Mesmer | |
25 | |
26 level = 0 | |
27 is_ome=False | |
28 #if $image.file_ext == "ome.tiff": | |
29 is_ome=True | |
30 #end if | |
31 | |
32 ## Grab params | |
33 nuc_kwargs = {} | |
34 wc_kwargs = {} | |
35 | |
36 | |
37 with tifffile.TiffFile("$image", is_ome=is_ome) as tiff: | |
38 | |
39 # Read single pyramid level | |
40 level_array = zarr.open(tiff.aszarr(series = 0, level = level)) | |
41 | |
42 ## grab the nuclear and membrane channels based on their indices add the markers along the channel axis | |
43 ## Tifffile should always read as (channel,X,Y) | |
44 #if $compartment_select.compartment != 'whole-cell': | |
45 nuc_kwargs = { | |
46 #if $compartment_select.nuclear_options.pixel_expansion != '': | |
47 'pixel_expansion': $compartment_select.nuclear_options.pixel_expansion, | |
48 #end if | |
49 #for $key, $value in $dict.items($compartment_select.nuclear_options.adv_options) | |
50 '$key': $value, | |
51 #end for | |
52 'maxima_threshold': $compartment_select.nuclear_options.maxima_threshold | |
53 } | |
54 #end if | |
55 | |
56 nuclear_indices = [int(x) for x in $nuclear_channels.split(',')] | |
57 nuclear_channels = level_array.oindex[nuclear_indices, :, :] | |
58 nuclear_channels = np.sum(nuclear_channels, axis = 0) | |
59 | |
60 #if $compartment_select.compartment != 'nuclear': | |
61 wc_kwargs = { | |
62 #for $key, $value in $dict.items($compartment_select.wc_options.adv_options) | |
63 '$key': $value, | |
64 #end for | |
65 'maxima_threshold': $compartment_select.wc_options.maxima_threshold | |
66 } | |
67 | |
68 membrane_indices = [int(x) for x in $compartment_select.wc_options.wc_channels.split(',')] | |
69 membrane_channels = level_array.oindex[membrane_indices, :, :] | |
70 membrane_channels = np.sum(membrane_channels, axis = 0) | |
71 #end if | |
72 | |
73 ## stack the nuclear and membrane composite channels with nuclear in channel 0 and mem in channel 1 | |
74 ## mesmer expects dimensions to be (X,Y,Channel) so axis = -1 | |
75 #if $compartment_select.compartment == 'nuclear': | |
76 membrane_channels = np.zeros(nuclear_channels.shape) | |
77 #end if | |
78 formatted_image = np.stack((nuclear_channels,membrane_channels), axis=-1) | |
79 | |
80 ## add batch dimension. Will have to be squeezed out later | |
81 formatted_image = np.expand_dims(formatted_image, 0) | |
82 | |
83 ## Create the application | |
84 app = Mesmer() | |
85 | |
86 ## Run segmentation | |
87 mask = app.predict( | |
88 formatted_image, | |
89 image_mpp = $image_mpp, | |
90 compartment = "$compartment_select.compartment", | |
91 pad_mode = 'constant', | |
92 postprocess_kwargs_whole_cell = wc_kwargs, | |
93 postprocess_kwargs_nuclear = nuc_kwargs) | |
94 | |
95 #if $squeeze: | |
96 mask = np.squeeze(mask) | |
97 #end if | |
98 | |
99 #if $compartment_select.compartment == 'both': | |
100 ## split the two-channel mask into separate outputs | |
101 #if $squeeze: | |
102 tifffile.imsave( "WC_output_mask.tif", mask[:,:,0]) | |
103 tifffile.imsave("NU_output_mask.tif", mask[:,:,1]) | |
104 #else: | |
105 tifffile.imsave( "WC_output_mask.tif", mask[:,:,:,0]) | |
106 tifffile.imsave("NU_output_mask.tif", mask[:,:,:,1]) | |
107 #end if | |
108 #else: | |
109 ## save single-channel mask outputs as a tiff | |
110 tifffile.imsave("mask.tif", mask) | |
111 #end if | |
112 </configfile> | |
113 </configfiles> | |
29 <inputs> | 114 <inputs> |
30 <param name="nuclear_image" type="data" format="tiff, ome.tiff" label="Image containing the nuclear marker(s)"/> | 115 <param name="image" type="data" format="tiff, ome.tiff" label="Image containing the all marker(s)"/> |
31 <param name="nuclear_channel" type="integer" value="0" label="The numerical index of the channel(s) from nuclear-image"/> | 116 <param name="nuclear_channels" type="text" value="0" label="The numerical indices of the channel(s) for the nuclear markers" help="No quotes, separated by comma. e.g. 0, 1."/> |
32 <param name="compartment" type="select" label="Compartment for segmentation prediction: "> | |
33 <option selected="true" value="whole-cell">Whole cell</option> | |
34 <option value="nuclear">Nuclear</option> | |
35 </param> | |
36 <param name="image_mpp" type="float" value="0.5" label="Resolution of the image in microns-per-pixel"/> | 117 <param name="image_mpp" type="float" value="0.5" label="Resolution of the image in microns-per-pixel"/> |
37 <param name="squeeze" type="boolean" truevalue="--squeeze" falsevalue="" checked="false" label="Whether to np.squeeze the outputs before saving"/> | 118 <param name="squeeze" type="boolean" checked="true" label="Whether to np.squeeze the outputs before saving"/> |
38 <conditional name="membrane_select"> | 119 <conditional name="compartment_select"> |
39 <param name="membrane_segment" type="select" label="Segment with Cell Membrane"> | 120 <param name="compartment" type="select" label="Compartment for segmentation prediction: "> |
40 <option selected="True" value="False">No</option> | 121 <option selected="true" value="whole-cell">Whole cell</option> |
41 <option value="True">Yes</option> | 122 <option value="nuclear">Nuclear</option> |
123 <option value="both">Both</option> | |
42 </param> | 124 </param> |
43 <when value="True"> | 125 <when value="nuclear"> |
44 <param name="membrane_image" type="data" format="tiff, ome.tiff" label="The path to an image containing the membrane marker(s)"/> | 126 <expand macro="nuclear_options_macro"/> |
45 <param name="membrane_channel" type="integer" value="0" label="The numerical index of the channel(s) from membrane-image"/> | |
46 </when> | 127 </when> |
47 <when value="False" /> | 128 <when value="whole-cell"> |
129 <expand macro="wc_options_macro"/> | |
130 </when> | |
131 <when value="both"> | |
132 <expand macro="nuclear_options_macro"/> | |
133 <expand macro="wc_options_macro"/> | |
134 </when> | |
48 </conditional> | 135 </conditional> |
49 </inputs> | 136 </inputs> |
137 | |
50 <outputs> | 138 <outputs> |
51 <data format="tiff" name="mask" from_work_dir="mask.tif" label="${tool.name} on ${on_string}: Mask"/> | 139 <data format="tiff" name="nu_mask" from_work_dir="NU_output_mask.tif" label="${tool.name} on ${on_string}: Nuclear Mask"> |
140 <filter>compartment_select['compartment'] == 'both'</filter> | |
141 </data> | |
142 <data format="tiff" name="wc_mask" from_work_dir="WC_output_mask.tif" label="${tool.name} on ${on_string}: Whole Cell Mask"> | |
143 <filter>compartment_select['compartment'] == 'both'</filter> | |
144 </data> | |
145 <data format="tiff" name="mask" from_work_dir="mask.tif" label="${tool.name} on ${on_string}: Mask"> | |
146 <filter>compartment_select['compartment'] != 'both'</filter> | |
147 </data> | |
52 </outputs> | 148 </outputs> |
53 <tests> | 149 <tests> |
54 <test> | 150 <test> |
55 <param name="nuclear_image" value="test.tiff" /> | 151 <param name="image" value="deepcell_test.tiff" ftype="tiff"/> |
56 <param name="compartment" value="nuclear" /> | 152 <param name="compartment" value="nuclear" /> |
57 <param name="membrane_segment" value="False" /> | |
58 <param name="image_mpp" value="0.65" /> | 153 <param name="image_mpp" value="0.65" /> |
59 <param name="squeeze" value="--squeeze" /> | 154 <param name="squeeze" value="True" /> |
60 <output name="mask" ftype="tiff"> | 155 <output name="mask" ftype="tiff"> |
61 <assert_contents> | 156 <assert_contents> |
62 <has_size value="360000" delta="1000" /> | 157 <has_size value="1049000" delta="1000" /> |
63 </assert_contents> | 158 </assert_contents> |
64 </output> | 159 </output> |
65 </test> | 160 </test> |
66 </tests> | 161 <test> |
162 <param name="image" value="deepcell_test.tiff" ftype="tiff"/> | |
163 <param name="compartment" value="whole-cell" /> | |
164 <param name="wc_channels" value="0, 1" /> | |
165 <param name="maxima_threshold" value="0.075" /> | |
166 <param name="image_mpp" value="0.65" /> | |
167 <param name="squeeze" value="True" /> | |
168 <output name="mask" ftype="tiff"> | |
169 <assert_contents> | |
170 <has_size value="1049000" delta="1000" /> | |
171 </assert_contents> | |
172 </output> | |
173 </test> | |
174 <test> | |
175 <param name="image" value="deepcell_test.tiff" ftype="tiff"/> | |
176 <param name="compartment" value="both" /> | |
177 <param name="image_mpp" value="0.65" /> | |
178 <param name="wc_channels" value="1" /> | |
179 <param name="nuclear_channels" value="0" /> | |
180 <param name="squeeze" value="True" /> | |
181 <output name="wc_mask" ftype="tiff"> | |
182 <assert_contents> | |
183 <has_size value="1049000" delta="1000" /> | |
184 </assert_contents> | |
185 </output> | |
186 <output name="nu_mask" ftype="tiff"> | |
187 <assert_contents> | |
188 <has_size value="1049000" delta="1000" /> | |
189 </assert_contents> | |
190 </output> | |
191 </test> | |
192 </tests> | |
67 <help><![CDATA[ | 193 <help><![CDATA[ |
68 ------ | 194 ------ |
69 Mesmer | 195 Mesmer |
70 ------ | 196 ------ |
71 | 197 |