Mercurial > repos > bgruening > cellpose
changeset 3:c793edde4284 draft default tip
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/cellpose commit 3f2ba60f101c923896ca95ed62981fcbb0a5ced3
line wrap: on
line diff
--- a/cellpose.xml Sat Mar 15 17:23:55 2025 +0000 +++ b/cellpose.xml Fri Dec 12 12:36:21 2025 +0000 @@ -1,14 +1,8 @@ <tool id="cellpose" name="Run generalist cell and nucleus segmentation" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="23.02"> - <description>with Cellpose</description> + <description>with Cellpose 3</description> <macros> <token name="@TOOL_VERSION@">3.1.0</token> - <token name="@VERSION_SUFFIX@">1</token> - <xml name="channel"> - <option value="0" selected="true">grayscale/None</option> - <option value="1">red</option> - <option value="2">green</option> - <option value="3">blue</option> - </xml> + <token name="@VERSION_SUFFIX@">2</token> </macros> <requirements> <container type="docker">quay.io/biocontainers/cellpose:@TOOL_VERSION@</container> @@ -27,7 +21,6 @@ python '$__tool_directory__/cp_segmentation.py' --inputs '$inputs' --img_path ./image.${img_in.ext} - --img_format '${img_in.ext}' --output_dir ./segmentation ]]> </command> @@ -35,20 +28,16 @@ <inputs name="inputs" /> </configfiles> <inputs> - <param name="img_in" type="data" format="ome.tiff,tiff,jpg,png" label="Choose the image file for segmention (usually after registration)"/> + <param name="img_in" type="data" format="ome.tiff,tiff,jpg,png" label="Choose the image file for segmentation (usually after registration)"> + <validator type="dataset_metadata_in_range" metadata_name="channels" min="0" max="1" message="Input image is not single channel."/> + <validator type="dataset_metadata_in_range" metadata_name="frames" min="0" max="1" message="Input image is a multi-frame image sequence, must be a single-frame image."/> + </param> <param name="model_type" type="select" label="Choose the pre-trained model type"> <option value="nuclei" selected="true">nuclei</option> <option value="cyto">cyto</option> <option value="cyto2">cyto2</option> <option value="cyto3">cyto3</option> </param> - <param argument="chan" type="select" label="Select the channel to segment" help="In this case, the default is grayscale"> - <expand macro="channel"/> - </param> - <param argument="chan2" type="select" optional="true" label="Select the channel for nuclei segmatation" help="In this case, the default is None"> - <expand macro="channel"/> - </param> - <param name="chan_first" type="boolean" truevalue="booltrue" falsevalue="boolfalse" checked="false" label="Use the reshaped data with channel as the first dimension?"/> <param name="show_segmentation" type="boolean" truevalue="booltrue" falsevalue="boolfalse" checked="true" label="Whether to show segmentation?"/> <param name="use_gpu" type="boolean" truevalue="booltrue" falsevalue="boolfalse" checked="false" label="Whether to use GPU?" /> <section name="options" title="Advanced Options" expanded="False"> @@ -72,77 +61,72 @@ </outputs> <tests> <test expect_num_outputs="2"> - <param name="img_in" value="img02.png"/> + <param name="img_in" value="img01_XY_cyto.png"/> <param name="model_type" value="cyto"/> - <param name="chan" value="2"/> - <param name="chan2" value="3"/> - <output name="cp_mask" file="img02_cp_masks_cyto.tif" compare="image_diff"/> - <output name="cp_segm" file="img02_cp_segm_cyto.png" compare="image_diff"/> + <output name="cp_mask" file="img01_XY_cyto_masks.tiff" compare="image_diff"/> + <output name="cp_segm" file="img01_XY_cyto_segm.png" compare="image_diff"/> </test> <test expect_num_outputs="2"> - <param name="img_in" value="img02.png"/> + <param name="img_in" value="img01_XY_cyto.png"/> <param name="model_type" value="cyto2"/> - <param name="chan" value="2"/> - <param name="chan2" value="3"/> - <output name="cp_mask" file="img02_cp_masks_cyto2.tif" compare="image_diff"/> - <output name="cp_segm" file="img02_cp_segm_cyto2.png" compare="image_diff"/> + <output name="cp_mask" file="img01_XY_cyto2_masks.tiff" compare="image_diff"/> + <output name="cp_segm" file="img01_XY_cyto2_segm.png" compare="image_diff"/> </test> <test expect_num_outputs="2"> - <param name="img_in" value="img02.png"/> + <param name="img_in" value="img01_XY_cyto.png"/> <param name="model_type" value="cyto3"/> - <param name="chan" value="2"/> - <param name="chan2" value="3"/> - <output name="cp_mask" file="img02_cp_masks_cyto3.tif" compare="image_diff"/> - <output name="cp_segm" file="img02_cp_segm_cyto3.png" compare="image_diff"/> + <output name="cp_mask" file="img01_XY_cyto3_masks.tiff" compare="image_diff"/> + <output name="cp_segm" file="img01_XY_cyto3_segm.png" compare="image_diff"/> </test> <test expect_num_outputs="2"> - <param name="img_in" value="img02.png"/> + <param name="img_in" value="img02_XY_nuclei.png"/> <param name="model_type" value="nuclei"/> - <param name="chan" value="2"/> - <param name="chan2" value="3"/> - <output name="cp_mask" file="img02_cp_masks_nuclei.tif" compare="image_diff"/> - <output name="cp_segm" file="img02_cp_segm_nuclei.png" compare="image_diff"/> + <output name="cp_mask" file="img02_XY_nuclei_masks.tiff" compare="image_diff"/> + <output name="cp_segm" file="img02_XY_nuclei_segm.png" compare="image_diff"/> </test> <test expect_num_outputs="2"> - <param name="img_in" value="img02.png"/> + <param name="img_in" value="img01_XY_cyto.png"/> <param name="model_type" value="cyto"/> - <param name="chan" value="2"/> - <param name="chan2" value="1"/> - <output name="cp_mask" file="img02_cp_masks_chan.tif" compare="image_diff"/> - <output name="cp_segm" file="img02_cp_segm_chan.png" compare="image_diff"/> - </test> - <test expect_num_outputs="2"> - <param name="img_in" value="img02.png"/> - <param name="model_type" value="cyto"/> - <param name="chan" value="2"/> - <param name="chan2" value="3"/> <section name="options"> <param name="diameter" value="50"/> </section> - <output name="cp_mask" file="img02_cp_masks_diameter.tif" compare="image_diff"/> - <output name="cp_segm" file="img02_cp_segm_diameter.png" compare="image_diff"/> + <output name="cp_mask" file="img01_XY_cyto_dia_masks.tiff" compare="image_diff"/> + <output name="cp_segm" file="img01_XY_cyto_dia_segm.png" compare="image_diff"/> </test> <test expect_num_outputs="2"> - <param name="img_in" value="img02.png"/> + <param name="img_in" value="img01_XY_cyto.png"/> <param name="use_gpu" value="true"/> <param name="model_type" value="cyto"/> - <param name="chan" value="2"/> - <param name="chan2" value="3"/> - <output name="cp_mask" file="img02_cp_masks_gpu.tif" compare="image_diff"/> - <output name="cp_segm" file="img02_cp_segm_gpu.png" compare="image_diff"/> + <output name="cp_mask" file="img01_XY_cyto_gpu_masks.tiff" compare="image_diff"/> + <output name="cp_segm" file="img01_XY_cyto_gpu_segm.png" compare="image_diff"/> </test> <test expect_num_outputs="1"> - <param name="img_in" value="img02.png"/> + <param name="img_in" value="img01_XY_cyto.png"/> <param name="model_type" value="cyto"/> - <param name="chan" value="2"/> - <param name="chan2" value="3"/> <param name="show_segmentation" value="false"/> - <output name="cp_mask" file="img02_cp_masks_cyto.tif" compare="image_diff"/> + <output name="cp_mask" file="img01_XY_cyto_masks.tiff" compare="image_diff"/> + </test> + <test expect_num_outputs="2"> + <param name="img_in" value="img03_CXY_nuclei.tiff"/> + <param name="model_type" value="nuclei"/> + <output name="cp_mask" file="img03_CXY_nuclei_masks.tiff" compare="image_diff"/> + <output name="cp_segm" file="img03_CXY_nuclei_segm.png" compare="image_diff"/> + </test> + <test expect_num_outputs="2"> + <param name="img_in" value="img04_XYC_nuclei.tiff"/> + <param name="model_type" value="nuclei"/> + <output name="cp_mask" file="img04_XYC_nuclei_masks.tiff" compare="image_diff"/> + <output name="cp_segm" file="img04_XYC_nuclei_segm.png" compare="image_diff"/> </test> </tests> <help> <![CDATA[ Cellpose: A generalist algorithm for cell and nucleus segmentation. + **Important:** + Only singlechannel 2-D images are supported. If a channel axis is present, it must be a singleton axis (axis of length 1) and it must be either the first or the last axis within the axes layout (e.g., YX, YXC, or CYX). Other layouts are not accepted (e.g. CYXZ, XYCZ). + In case of multichannel images, it is necessary to priorly extract the channel for segmentation using the `Split image along axes`_ tool. + + .. _Split image along axes: ?tool_id=toolshed.g2.bx.psu.edu%2Frepos%2Fimgteam%2Fsplit_image%2Fip_split_image ]]> </help> <citations>
--- a/cp_segmentation.py Sat Mar 15 17:23:55 2025 +0000 +++ b/cp_segmentation.py Fri Dec 12 12:36:21 2025 +0000 @@ -14,7 +14,7 @@ import numpy as np import skimage.io import torch -from cellpose import models, plot, transforms +from cellpose import models, plot # Apply PyTorch guidelines for reproducibility torch.backends.cudnn.benchmark = True @@ -22,7 +22,7 @@ torch.manual_seed(0) -def main(inputs, img_path, img_format, output_dir): +def main(inputs, img_path, output_dir): """ Parameter --------- @@ -30,8 +30,6 @@ File path to galaxy tool parameter img_path : str File path for the input image - img_format : str - One of the ['ome.tiff', 'tiff', 'png', 'jpg'] output_dir : str Folder to save the outputs. """ @@ -42,27 +40,13 @@ gpu = params['use_gpu'] model_type = params['model_type'] - chan = params['chan'] - chan2 = params['chan2'] - chan_first = params['chan_first'] - if chan is None: - channels = None - else: - channels = [int(chan), int(chan2) if chan2 is not None else None] - options = params['options'] - img = skimage.io.imread(img_path) print(f"Image shape: {img.shape}") - # transpose to Ly x Lx x nchann and reshape based on channels - if img_format.endswith('tiff'): - img = np.transpose(img, (1, 2, 0)) - img = transforms.reshape(img, channels=channels, chan_first=chan_first) - print(f"Image shape: {img.shape}") model = models.Cellpose(gpu=gpu, model_type=model_type) - masks, flows, styles, diams = model.eval(img, channels=channels, **options) + masks, flows, styles, diams = model.eval(img, channels=[0, 0], **options) # save masks to tiff with warnings.catch_warnings(): @@ -73,16 +57,12 @@ # make segmentation show # if params['show_segmentation']: img = skimage.io.imread(img_path) - # uniform image - if img_format.endswith('tiff'): - img = np.transpose(img, (1, 2, 0)) - img = transforms.reshape(img, channels=channels, chan_first=chan_first) maski = masks flowi = flows[0] - fig = plt.figure(figsize=(12, 3)) + fig = plt.figure(figsize=(8, 2)) # can save images (set save_dir=None if not) - plot.show_segmentation(fig, img, maski, flowi, channels=channels) + plot.show_segmentation(fig, img, maski, flowi, channels=[0, 0]) fig.savefig(os.path.join(output_dir, 'segm_show.png'), dpi=300) plt.close(fig) @@ -91,8 +71,7 @@ aparser = argparse.ArgumentParser() aparser.add_argument("-i", "--inputs", dest="inputs", required=True) aparser.add_argument("-p", "--img_path", dest="img_path") - aparser.add_argument("-f", "--img_format", dest="img_format") aparser.add_argument("-O", "--output_dir", dest="output_dir") args = aparser.parse_args() - main(args.inputs, args.img_path, args.img_format, args.output_dir) + main(args.inputs, args.img_path, args.output_dir)
