view save_images.xml @ 2:609911f19ab2 draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
author bgruening
date Thu, 16 Apr 2020 05:42:00 -0400
parents 6e0f244acd32
children a45d360ae9d9
line wrap: on
line source

<tool id="cp_save_images" name="SaveImages" version="@CP_VERSION@">
    <description>save image or movie files</description>
  
    <macros>
        <import>macros.xml</import>
        <xml name="file_format">
            <param name="file_format" label="Saved file format" type="select">
                <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">
                <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>
    
    <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?:%s\n" % params['subfolder_in_output']
    _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", "w") as f:
        f.writelines(lines)
        f.write(writesi())

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

    <inputs>
        <expand macro="input_pipeline_macro" />
        <conditional name="con_type_of_image">
            <param name="type_of_image" type="select" label="Select the type of image to save" >
                <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="Select 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" >
                <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="Select image name for 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="No">No</option>
                        <option value="Yes">Yes</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" type="text"/>
                <param name="no_of_digits" label="Number of digits" type="integer" value="4" min="0"/>
            </when>
            <when value="Single name">
                <param name="single_file_name" label="Enter single_file_name" type="text">
                  <expand macro="text_validator" />
                </param>
            </when>
        </conditional>
        <param name="overwrite_without_warning" label="Overwrite existing files without warning?" type="select" >
            <option value="No">No</option>
            <option value="Yes">Yes</option>
        </param>
        <param name="when_to_save" label="When to save" type="select" >
            <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="No">No</option>
            <option value="Yes">Yes</option>
        </param>
        <param name="subfolder_in_output" label="Create subfolders in the output folder?" type="select" display="radio">
            <option value="No">No</option>        
        </param>      
    </inputs>

    <outputs>
        <expand macro="output_pipeline_macro" />
    </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.txt" />

        </test>
    </tests>

    <expand macro="help" module="RelateObjects" />
    <expand macro="citations" />

</tool>