view export_to_spreadsheet.xml @ 3:72a7f23f3a79 draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit c3917e27eb1c1deeb381aa0dc8161c07699562fb"
author bgruening
date Mon, 11 May 2020 07:46:16 -0400
parents c956182d4e2c
children d0178bdcd00e
line wrap: on
line source

<tool id="cp_export_to_spreadsheet" name="ExportToSpreadsheet" version="@CP_VERSION@">
    <description>export measurements into one or more files</description>
    <macros>
        <import>macros.xml</import>
        <xml name="metadata_sample_row" >
            <param name="metadata_category" type="select" label="Select the metadata to use as the identifier">
                <option value="FileName">File name</option>

                <option value="Frame">Frame</option>
                <option value="Height">Height</option>
                <option value="MD5Digest">MD5Digest</option>
                <option value="PathName">Path name</option>

                <option value="Scaling">Scaling</option>
                <option value="Series">Series</option>
                <option value="URL">URL</option>
                <option value="Width">Width</option>
            </param>
            <param name="metadata_measurement" type="text" label="Measurements" >
                <help>
                    Choose the measurement that corresponds to the identifier, such as metadata from the Metadata tool. Please see the Metadata tool for more details on metadata collection and usage.

                </help>
            </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 write_etss():
    _str = "\nExportToSpreadsheet:[module_num:%d|svn_version:\\'Unknown\\'|variable_revision_number:12|show_window:True|notes:\\x5B\\x5D|batch_state:array(\\x5B\\x5D, dtype=uint8)|enabled:True|wants_pause:False]\n" % new_count
    _str += FOURSPACES + "Select the column delimiter:%s\n" % params["delimiter"]
    _str += FOURSPACES + "Add image metadata columns to your object data file?:%s\n" % params["add_metadata_column_to_object"]


    _str += FOURSPACES + "Select the measurements to export:No\n"  
    _str += FOURSPACES + "Calculate the per-image mean values for object measurements?:%s\n" % params['calc_mean']
    _str += FOURSPACES + "Calculate the per-image median values for object measurements?:%s\n" % params['calc_median']
    _str += FOURSPACES + "Calculate the per-image standard deviation values for object measurements?:%s\n" % params['calc_standard_deviation']
    _str += FOURSPACES + "Output file location:Default Output Folder\\x7C\n"

    create_gene = params["con_create_gene_pattern"]["create_gene_pattern"]
    _str += FOURSPACES + "Create a GenePattern GCT file?:%s\n" % create_gene
    

    #default values when create gene  is no
    source_sample_row = "Metadata"
    image_as_id = "None"
    metadata_as_id = "None"
    
    if create_gene == "Yes":
        source_sample_row = params["con_create_gene_pattern"]["con_source_sample_row"]["select_source_sample_row_name"]
        if source_sample_row == "Metadata":
            metadata_as_id = params["con_create_gene_pattern"]["con_source_sample_row"]["metadata_category"] + "_" + params["con_create_gene_pattern"]["con_source_sample_row"]["metadata_measurement"]
        else:
            image_as_id = params["con_create_gene_pattern"]["con_source_sample_row"]["image_filename_cat"]

    _str += FOURSPACES + "Select source of sample row name:%s\n" % source_sample_row
    _str += FOURSPACES + "Select the image to use as the identifier:%s\n" % image_as_id
    _str += FOURSPACES + "Select the metadata to use as the identifier:%s\n" % metadata_as_id


    export_all_measurements = params["con_export_all_measurements"]["export_all_measurements"]

    _str += FOURSPACES + "Export all measurement types?:%s\n" % export_all_measurements

    _str += FOURSPACES + "Press button to select measurements:\n"

    _str += FOURSPACES + "Representation of Nan/Inf:%s\n" % params["represent_nan"]
    _str += FOURSPACES + "Add a prefix to file names?:%s\n" % params["con_prefix"]["add_prefix"]

    if "filename_prefix" in params["con_prefix"]:
        _str += FOURSPACES + "Filename prefix:%s\n" % params["con_prefix"]["filename_prefix"]
    else:
        _str += FOURSPACES + "Filename prefix:MyPrefix_\n"

    _str += FOURSPACES + "Overwrite existing files without warning?:%s\n" % params["overwrite_existing_file"]


    use_as_filename = "Yes"

    if export_all_measurements == "Yes":
        _str += FOURSPACES + "Data to export:Do not use\n"
        _str += FOURSPACES + "Combine these object measurements with those of the previous object?:No\n"
        _str += FOURSPACES + "File name:DATA.csv\n"
        _str += FOURSPACES + "Use the object name for the file name?:Yes\n"
    else:
        for dte in params["con_export_all_measurements"]["r_data_to_export"]:
            _str += FOURSPACES + "Data to export:%s\n" % dte["data_to_export"]
            _str += FOURSPACES + "Combine these object measurements with those of the previous object?:No\n"
            
            use_as_filename = dte["con_obj_name_for_filename"]["use_as_filename"]

            if use_as_filename == "No":
                file_name = dte["con_obj_name_for_filename"]["file_name"]
            else:
                file_name = "DATA.csv"

            _str += FOURSPACES + "File name:%s\n" % file_name
            _str += FOURSPACES + "Use the object name for the file name?:%s\n" % use_as_filename

    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(write_etss())

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

    <inputs>
        <expand macro="input_pipeline_param" />
        <param name="delimiter" type="select" label="Select the column delimiter">
            <option value="Comma (&quot;,&quot;)">Comma (",")</option>
            <option value="Tab">Tab</option>
            <sanitizer sanitize="false"/>
        </param>
        <conditional name="con_prefix">
            <param name="add_prefix" type="select" label="Add a prefix to file names?">
                <option value="Yes">Add prefix to the file name</option>
                <option value="No">Do not add prefix to the file name</option>
            </param>
            <when value="Yes">
                <param name="filename_prefix" type="text" value="MyExpt_" label="Enter the prefix to be added to the file names"/>
            </when>
            <when value="No" />
        </conditional>
        <param name="overwrite_existing_file" display="radio" type="select" label="Overwrite existing files without warning?">
            <option value="Yes">Yes</option>
            <option value="No">No</option>
        </param>
        <param name="add_metadata_column_to_object" display="radio" type="select" label="Add image metadata columns to  your object data file?" help="'Image_Metadata_' columns are normally exported in the Image data file, but if you select 'Yes', they will also be exported with the Object data file(s).">
            <option value="Yes">Yes</option>
            <option value="No">No</option>
        </param>
        <param name="represent_nan" type="select" label="Representation of Nan/Inf" help="CellProfiler will produce Inf or NaN values under certain rare circumstances, for instance when calculating the mean intensity of an object within a masked region of an image.">
            <option value="NaN">NaN</option>
            <option value="Null">Null</option>
        </param>
        <param name="calc_mean" type="select" display="radio" label="Calculate the per-image mean values for object measurements?" help="Select 'Yes' to calculate the population mean over all the objects in each image and save that value as an aggregate measurement in the image file.">
            <option value="Yes">Yes</option>
            <option value="No">No</option>
        </param>
        <param name="calc_median" type="select" display="radio" label="Calculate the per-image median values for object measurements?" help="Select 'Yes' to calculate the population median over all the objects in each image and save that value as an aggregate measurement in the image file.">
            <option value="Yes">Yes</option>
            <option value="No">No</option>
        </param>
        <param name="calc_standard_deviation" type="select" display="radio" label="Calculate the per-image standard deviation values for object measurements?" help="Select 'Yes' to calculate the population standard deviation over all the objects in each image and save that value as an aggregate measurement in the image file.">
            <option value="Yes">Yes</option>
            <option value="No">No</option>
        </param>
        <conditional name="con_create_gene_pattern">
            <param name="create_gene_pattern" type="select" display="radio" label="Create a GenePattern GCT file?" help="Select 'Yes' to create a GCT file compatible with GenePattern. The GCT file format is a tab-delimited text file format designed for gene expression datasets; the specifics of the format are described here. By converting your measurements into a GCT file, you can make use of GenePattern’s data visualization and clustering methods.">
                <option value="Yes">Yes</option>
                <option value="No" selected="true">No</option>
            </param>
            <when value="Yes">
                <conditional name="con_source_sample_row">
                    <param name="select_source_sample_row_name" type="select" label="Select source of sample row name">
                        <help>
                            <![CDATA[
                                The first column of the GCT file is the unique identifier for each sample, which is ordinarily the gene name. This information may be specified in one of two ways:
                                <br> - Metadata: If you used the Metadata modules to add metadata to your images, you may specify a metadata tag that corresponds to the identifier for this column.
                                <br> - Image filename: If the gene name is not available, the image filename can be used as a surrogate identifier.
                                ]]>
                        </help>
                        <option value="Metadata">Metadata</option>
                        <option value="Image filename">Image filename</option>
                    </param>
               
                    <when value="Metadata">
                        <expand macro="metadata_sample_row" />
                    </when>
                    <when value="Image filename">
                        <param name="image_filename_cat" type="text" value="None" label="Enter the name of the image to use as the identifier" help="Enter the name of the image image whose filename will be used to identify each sample row. " />  

                    </when>
                </conditional>
            </when>
            <when value="No" />
        </conditional>
        <conditional name="con_export_all_measurements">
            <param name="export_all_measurements" type="select" display="radio" label="Export all measurement types?" help="Select 'Yes' to export every category of measurement. ExportToSpreadsheet will create one data file for each object produced in the pipeline, as well as per-image, per-experiment and object relationships, if relevant.">
                <option value="Yes">Yes</option>
                <option value="No">No</option>
            </param>
            <when value="No">
                <repeat name="r_data_to_export" title="another data set" min="1">
                    <param name="data_to_export" type="select" label="Data to export" help="This option will writ out a file of measurements for the given category.">                        
                        <option value="Image">Image</option>
                        <option value="Experiment">Experiment</option>
                        <option value="Object relationship">Object relationship</option>
                        <option value="Do not use">Do not use</option>
                    </param>
                    <conditional name="con_obj_name_for_filename">
                        <param name="use_as_filename" type="select" display="radio" label="Use the object name for the file name?" help="Select 'Yes' to use the object name as selected above to generate a file name for the spreadsheet.">
                            <option value="Yes">Yes</option>
                            <option value="No">No</option>
                        </param>
                        <when value="No">
                            <param name="file_name" type="text" label="File name" />
                        </when>
                        <when value="Yes" />
                    </conditional>
                </repeat>
            </when>
            <when value="Yes" />
        </conditional>
    </inputs>

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

    <tests>
        <test>
        <!-- create gene pattern =no-->
            <expand macro="test_input_pipeline_param" />
            <param name="delimiter" value="Tab" />
            <param name="output_file_location" value="Default Output Folder" />
            <conditional name="con_prefix">
                <param name="add_prefix" value="No"/>
            </conditional>
            <param name="overwrite_existing_file" value="Yes" />
            <param name="add_metadata_column_to_object" value="Yes" />
            <param name="represent_nan" value="NaN" />
            <conditional name="con_measurement_export">
                <param name="export_measurement" value="No" />
            </conditional>
            <param name="calc_mean" value="Yes" />
            <param name="calc_median" value="Yes" />
            <param name="calc_standard_deviation" value="Yes" />
            <conditional name="con_create_gene_pattern">
                <param name="create_gene_pattern" value="No" />
            </conditional>
            <conditional name="con_export_all_measurements">
                <param name="export_all_measurements" value="Yes" />
            </conditional>
            <expand macro="test_out_file" file="export_to_spreadsheet.cppipe" />
        </test>

        <test>
            <!-- create gene=yes , source of sampe row name= metadata-->
            <expand macro="test_input_pipeline_param" />
            <param name="delimiter" value="Tab" />
            <param name="output_file_location" value="Default Output Folder" />
            <conditional name="con_prefix">
                <param name="add_prefix" value="No"/>
            </conditional>
            <param name="overwrite_existing_file" value="Yes" />
            <param name="add_metadata_column_to_object" value="Yes" />
            <param name="represent_nan" value="NaN" />
            <conditional name="con_measurement_export">
                <param name="export_measurement" value="No" />
            </conditional>
            <param name="calc_mean" value="Yes" />
            <param name="calc_median" value="Yes" />
            <param name="calc_standard_deviation" value="Yes" />
            <conditional name="con_create_gene_pattern">
                <param name="create_gene_pattern" value="Yes" />
                <conditional name="con_source_sample_row">
                    <param name="select_source_sample_row_name" value="Metadata" />
                     <param name="metadata_category" value="FileName" />
                      <param name="metadata_measurement" value="DNA" />
                </conditional>
            </conditional>
            <conditional name="con_export_all_measurements">
                <param name="export_all_measurements" value="Yes" />
            </conditional>
            <expand macro="test_out_file" file="export_to_spreadsheet_create_gene_metadata.cppipe" />
        </test>
        <test>
            <!-- create gene=yes , source of sampe row name= image filename, export all = no-->
            <expand macro="test_input_pipeline_param" />
            <param name="delimiter" value="Tab" />
            <param name="output_file_location" value="Default Output Folder" />
            <conditional name="con_prefix">
                <param name="add_prefix" value="Yes"/>
                <param name="filename_prefix" value="MyExpt_" />
            </conditional>
            <param name="overwrite_existing_file" value="Yes" />
            <param name="add_metadata_column_to_object" value="Yes" />
            <param name="represent_nan" value="NaN" />
            <conditional name="con_measurement_export">
                <param name="export_measurement" value="No" />
            </conditional>
            <param name="calc_mean" value="Yes" />
            <param name="calc_median" value="Yes" />
            <param name="calc_standard_deviation" value="Yes" />
            <conditional name="con_create_gene_pattern">
                <param name="create_gene_pattern" value="Yes" />
                <conditional name="con_source_sample_row">
                    <param name="select_source_sample_row_name" value="Image filename" />
                     <param name="image_filename_cat" value="DNA" />
                </conditional>
            </conditional>
            <conditional name="con_export_all_measurements">
                <param name="export_all_measurements" value="No" />
                <repeat name="r_data_to_export">
                    <param name="data_to_export" value="Image" />
                     <conditional name="con_obj_name_for_filename">
                        <param name="use_as_filename" value="No" />
                        <param name="file_name" value="data.csv" />
                     </conditional>
                </repeat>
            </conditional>
            <expand macro="test_out_file" file="export_to_spreadsheet_create_gene_image_filename.cppipe" />
        </test>

        <test>
            <!--repeat test for multiple data export. create gene=yes , source of sampe row name= image filename, export all = no-->
            <expand macro="test_input_pipeline_param" />
            <param name="delimiter" value="Tab" />
            <param name="output_file_location" value="Default Output Folder" />
            <conditional name="con_prefix">
                <param name="add_prefix" value="Yes"/>
                <param name="filename_prefix" value="MyExpt_" />
            </conditional>
            <param name="overwrite_existing_file" value="Yes" />
            <param name="add_metadata_column_to_object" value="Yes" />
            <param name="represent_nan" value="NaN" />
            <conditional name="con_measurement_export">
                <param name="export_measurement" value="No" />
            </conditional>
            <param name="calc_mean" value="Yes" />
            <param name="calc_median" value="Yes" />
            <param name="calc_standard_deviation" value="Yes" />
            <conditional name="con_create_gene_pattern">
                <param name="create_gene_pattern" value="Yes" />
                <conditional name="con_source_sample_row">
                    <param name="select_source_sample_row_name" value="Image filename" />
                     <param name="image_filename_cat" value="DNA" />
                </conditional>
            </conditional>
            <conditional name="con_export_all_measurements">
                <param name="export_all_measurements" value="No" />
                <repeat name="r_data_to_export">
                    <param name="data_to_export" value="Image" />
                     <conditional name="con_obj_name_for_filename">
                        <param name="use_as_filename" value="No" />
                        <param name="file_name" value="data.csv" />
                     </conditional>
                </repeat>
                <repeat name="r_data_to_export">
                    <param name="data_to_export" value="Experiment" />
                     <conditional name="con_obj_name_for_filename">
                        <param name="use_as_filename" value="Yes" />
                     </conditional>
                </repeat>
            </conditional>
            <expand macro="test_out_file" file="export_to_spreadsheet_multi.cppipe" />
        </test>
    </tests>

    <help>
        <![CDATA[
            .. class:: infomark

            **What it does**

            This tool will convert the measurements to a comma-, tab-, or other character-delimited text format and save them in one or several files, as requested.

            @COMMON_HELP@
            ]]>
    </help>

    <expand macro="citations" />

</tool>