view save_images.xml @ 6:27edbb90ab2b draft default tip

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
author bgruening
date Sun, 05 Nov 2023 09:26:05 +0000
parents 33f4fa1413fb
children
line wrap: on
line source

<tool id="cp_save_images" name="SaveImages" version="@CP_VERSION@+galaxy@VERSION_SUFFIX@">
    <description>with CellProfiler</description>

    <macros>
        <import>macros.xml</import>
        <token name="@VERSION_SUFFIX@">2</token>
        <xml name="file_format">
            <param name="file_format" label="Saved the format to save the image(s)" type="select">
                <help>
                    <![CDATA[
                        - Only tiff supports saving as 16-bit or 32-bit. tiff is a "lossless" file format.
                        <br> - png is also a "lossless" file format and it tends to produce smaller files without losing any image data.
                        <br> - jpeg is also small but is a "lossy" file format and should not be used for any images that will undergo further quantitative analysis.
                        <br> - Select npy to save an illumination correction image generated by CorrectIlluminationCalculate.
                        ]]>
                </help>
                <option value="jpeg">jpeg</option>
                <option value="npy">npy</option>
                <option value="png">png</option>
                <option value="tiff">tiff</option>
            </param>
        </xml>
        <xml name="bit_depth">
            <param name="bit_depth" label="Image bit depth" type="select">
                <help>
                    <![CDATA[
                        Select the bit-depth at which you want to save the images.
                        <br> - 32-bit floating point saves the image as floating-point decimals with 32-bit precision. When the input data is integer or binary type, pixel values are scaled within the range (0, 1). Floating point data is not rescaled.
                        <br> - 16-bit integer and 32-bit floating point images are supported only for TIFF formats.
                        ]]>
                </help>
                <option value="8-bit integer">8-bit integer</option>
                <option value="16-bit integer">16-bit integer</option>
                <option value="32-bit floating point">32-bit floating point</option>
            </param>
        </xml>
    </macros>

    <edam_operations>
        <edam_operation>operation_3443</edam_operation>
    </edam_operations>
    <xrefs>
        <xref type="bio.tools">CellProfiler</xref>
        <xref type="biii">cellprofiler</xref>
    </xrefs>

    <expand macro="py_requirements"/>
    <expand macro="cmd_modules" />

    <configfiles>
        <inputs name="inputs" />
        <configfile name="script_file">
import json
import sys
import os

FOURSPACES=@SPACES@

input_json_path = sys.argv[1]
input_pipeline= sys.argv[2]

params = json.load(open(input_json_path, "r"))

def writesi():
    _str = "\nSaveImages:[module_num:%d|svn_version:\\'Unknown\\'|variable_revision_number:13|show_window:False|notes:\\x5B\\x5D|batch_state:array(\\x5B\\x5D, dtype=uint8)|enabled:True|wants_pause:False]\n" % new_count

    _str += FOURSPACES + "Select the type of image to save:%s\n" % params['con_type_of_image']['type_of_image']

    _str += FOURSPACES + "Select the image to save:%s\n" % params['image_to_save']

    method_for_constructing = params['con_method_for_constructing']['method_for_constructing']
    _str += FOURSPACES + "Select method for constructing file names:%s\n" % method_for_constructing

    if method_for_constructing == "From image filename":
        img_name_file_prefix = params['con_method_for_constructing']['name_for_file_prefix']
        append_suffix = params['con_method_for_constructing']['con_append_suffix']['append_suffix']

        if append_suffix == "Yes":
            text_append = params['con_method_for_constructing']['con_append_suffix']['text_to_append']
        else:
            text_append = ""
    else:
        img_name_file_prefix = "None"
        append_suffix = "No"
        text_append = ""

    _str += FOURSPACES + "Select image name for file prefix:%s\n" % img_name_file_prefix

    if method_for_constructing == "Sequential numbers":
        file_prefix = params['con_method_for_constructing']['file_prefix']
        no_of_digits = params['con_method_for_constructing']['no_of_digits']

        _str += FOURSPACES + "Enter file prefix:%s\n" % file_prefix
    elif method_for_constructing == "Single name":
        _str += FOURSPACES + "Enter single file name:%s\n" % params['con_method_for_constructing']['single_file_name']

        no_of_digits = 4
    else:
        _str += FOURSPACES + "Enter single file name:OrigBlue\n"
        no_of_digits = 4
        append_suffix = params['con_method_for_constructing']['con_append_suffix']['append_suffix']

    _str += FOURSPACES + "Number of digits:%d\n" % no_of_digits
    _str += FOURSPACES + "Append a suffix to the image file name?:%s\n" % append_suffix
    _str += FOURSPACES + "Text to append to the image name:%s\n" % text_append

    save_format = params['con_type_of_image']['con_save_file_format']['file_format']

    _str += FOURSPACES + "Saved file format:%s\n" % save_format

    if save_format == "tiff":
        bit_depth = params['con_type_of_image']['con_save_file_format']['bit_depth']
    else:
        bit_depth = "8-bit integer"

    _str += FOURSPACES + "Output file location:Default Output Folder\\x7Coutput\n"
    _str += FOURSPACES + "Image bit depth:%s\n" % bit_depth
    _str += FOURSPACES + "Overwrite existing files without warning?:%s\n" % params['overwrite_without_warning']
    _str += FOURSPACES + "When to save:%s\n" % params['when_to_save']
    _str += FOURSPACES + "Record the file and path information to the saved image?:%s\n" % params['record_info']
    _str += FOURSPACES + "Create subfolders in the output folder?:No\n"
    _str += FOURSPACES + "Base image folder:Elsewhere...\n"

    return _str

with open(input_pipeline) as fin:
    lines = fin.readlines()

    k, v = lines[4].strip().split(':')

    module_count = int(v)
    new_count = module_count + 1
    lines[4] = k + ":%d\n" % new_count

    with open("output.cppipe", "w") as f:
        f.writelines(lines)
        f.write(writesi())

    f.close()
        </configfile>
    </configfiles>

    <inputs>
        <expand macro="input_pipeline_param" />
        <conditional name="con_type_of_image">
            <param name="type_of_image" type="select" label="Select the type of image to save">
                <help>
                    <![CDATA[
                        The following types of images can be saved as a file on the hard drive:
                        <br> - Image: Any of the images produced upstream of SaveImages can be selected for saving. Outlines of objects created by other modules such as Identify modules, Watershed, and various object processing modules can also be saved with this option, but you must use the OverlayOutlines module to create them prior to saving images. Likewise, if you wish to save the objects themselves, you must use the ConvertObjectsToImage module to create a savable image.
                        <br> - Mask: Relevant only if a module that produces masks has been used such as Crop, MaskImage, or MaskObjects. These modules create a mask of the pixels of interest in the image. Saving the mask will produce a binary image in which the pixels of interest are set to 1; all other pixels are set to 0.
                        <br> - Cropping: Relevant only if the Crop module is used. The Crop module also creates a cropping image which is typically the same size as the original image. However, since Crop permits removal of the rows and columns that are left blank, the cropping can be of a different size than the mask.
                        <br> - Movie: A sequence of images can be saved as a TIFF stack.
                        ]]>
                </help>
                <option value="Image">Image</option>
                <option value="Mask">Mask</option>
                <option value="Cropping">Cropping</option>
                <option value="Movie">Movie</option>
            </param>
            <when value="Image">
                <conditional name="con_save_file_format">
                    <expand macro="file_format" />
                    <when value="tiff">
                        <expand macro="bit_depth" />
                    </when>
                    <when value="jpeg" />
                    <when value="npy" />
                    <when value="png" />
                </conditional>
            </when>
            <when value="Mask">
                <expand macro="file_format" />
            </when>
            <when value="Cropping">
                <expand macro="file_format" />
            </when>
            <when value="Movie">
                <expand macro="bit_depth" />
            </when>
        </conditional>
        <param name="image_to_save" label="Enter the name of the image to save" type="text" />
        <conditional name="con_method_for_constructing">
            <param name="method_for_constructing" label="Select method for constructing file names" type="select">
                <help>
                    <![CDATA[
                        Several choices are available for constructing the image file name:
                        <br> - From image filename: The filename will be constructed based on the original filename of an input image specified in NamesAndTypes.
                        You will have the opportunity to prefix or append additional text.
                        If you have metadata associated with your images, you can append text to the image filename using a metadata tag.
                        This is especially useful if you want your output given a unique label according to the metadata corresponding to an image group.
                        The name of the metadata to substitute can be provided for each image for each cycle using the Metadata module.
                        <br> - Sequential numbers: Same as above, but in addition, each filename will have a number appended to the end that corresponds to the image cycle number (starting at 1).
                        <br> - Single name: A single name will be given to the file. Since the filename is fixed, this file will be overwritten with each cycle. In this case, you would probably want to save the image on the last cycle (see the Select how often to save setting). The exception to this is to use a metadata tag to provide a unique label, as mentioned in the From image filename option.
                        ]]>
                </help>
                <option value="From image filename">From image filename</option>
                <option value="Sequential numbers">Sequential numbers</option>
                <option value="Single name">Single name</option>
            </param>
            <when value="From image filename">
                <param name="name_for_file_prefix" label="Enter the image name (from NamesAndTypes) to be used as file prefix" type="text">
                    <expand macro="text_validator" />
                </param>
                <conditional name="con_append_suffix">
                    <param name="append_suffix" type="select" display="radio" label="Append a suffix to the image file name?">
                        <option value="Yes">Yes</option>
                        <option value="No" selected="True">No</option>
                    </param>
                    <when value="Yes">
                        <param name="text_to_append" label="Text to append to the image name" type="text">
                            <expand macro="text_validator" />
                        </param>
                    </when>
                    <when value="No" />
                </conditional>
            </when>
            <when value="Sequential numbers">
                <param name="file_prefix" label="Enter file prefix" value="OrigBlue" type="text"/>
                <param name="no_of_digits" label="Number of digits" type="integer" value="4" min="0" help="Specify the number of digits to be used for the sequential numbering. Zeros will be used to left-pad the digits. If the number specified here is less than that needed to contain the number of image sets, the latter will override the value entered."/>
            </when>
            <when value="Single name">
                <param name="single_file_name" label="Enter single file name" value="OrigBlue" type="text">
                    <expand macro="text_validator" />
                </param>
            </when>
        </conditional>
        <param name="overwrite_without_warning" label="Overwrite existing files without warning?" type="select" display="radio">
            <option value="Yes">Yes</option>
            <option value="No" selected="True">No</option>
        </param>
        <param name="when_to_save" label="When to save" type="select">
            <help>
                <![CDATA[
                    Specify at what point during pipeline execution to save file(s).
                    <br> - Every cycle: Useful for when the image of interest is created every cycle and is not dependent on results from a prior cycle.
                    <br> - First cycle: Useful for when you are saving an aggregate image created on the first cycle, e.g., CorrectIlluminationCalculate with the 'All setting' used on images obtained directly from NamesAndTypes.
                    <br> - Last cycle: Useful for when you are saving an aggregate image completed on the last cycle, e.g., CorrectIlluminationCalculate with the 'All setting' used on intermediate images generated during each cycle.
                    ]]>
            </help>
            <option value="Every cycle">Every cycle</option>
            <option value="First cycle">First cycle</option>
            <option value="Last cycle">Last cycle</option>
        </param>
        <param name="record_info" label="Record the file and path information to the saved image?" type="select" display="radio">
            <option value="Yes">Yes</option>
            <option value="No" selected="True">No</option>
        </param>

    </inputs>

    <outputs>
        <expand macro="output_pipeline_param" />
    </outputs>

    <tests>
        <test>
            <expand macro="test_input_pipeline_param" />

            <conditional name="con_type_of_image">
                <param name="type_of_image" value="Image" />
                <conditional name="con_save_file_format">
                    <param name="file_format" value="tiff" />
                    <param name="bit_depth" value="8-bit integer" />
                </conditional>
            </conditional>
            <param name="image_to_save" value="ImageDisplay" />
            <conditional name="con_method_for_constructing">
                <param name="method_for_constructing" value="From image filename" />
                <param name="name_for_file_prefix" value="DNA" />
                <conditional name="con_append_suffix">
                    <param name="append_suffix" value="Yes" />
                    <param name="text_to_append" value="_nucleiNumbers" />
                </conditional>
            </conditional>
            <param name="overwrite_without_warning" value="Yes" />
            <param name="when_to_save" value="Every cycle" />
            <param name="record_info" value="No" />
            <param name="subfolder_in_output" value="No" />

            <expand macro="test_out_file" file="save_images.cppipe" />

        </test>
    </tests>

    <help>
        <![CDATA[

            .. class:: infomark

            **What it does**

            SaveImages saves image or movie files.
            Because CellProfiler usually performs many image analysis steps on many groups of images, it does not save any of the resulting images to the hard drive unless you specifically choose to do so with the SaveImages module.
            You can save any of the processed images created by CellProfiler during the analysis using this module.
            You can choose from many different image formats for saving your files.
            This allows you to use the module as a file format converter, by loading files in their original format and then saving them in an alternate format.

            @COMMON_HELP@
            ]]>
    </help>

    <expand macro="citations" />

</tool>