view incucyte_stack_and_upload_omero.xml @ 1:3c942429f610 draft default tip

planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/incucyte_stack_and_upload_omero commit de447190f0743b7f6a3b85e13f712fc07682af3c
author lldelisle
date Thu, 21 Dec 2023 17:04:46 +0000
parents e1cba36becb2
children
line wrap: on
line source

<tool id="incucyte_stack_and_upload_omero" name="Stack Incucyte Plate" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="20.01" license="BSD-3">
    <description>And upload to omero</description>
    <macros>
        <token name="@TOOL_VERSION@">20231221</token>
        <token name="@VERSION_SUFFIX@">0</token>
    </macros>
    <requirements>
        <requirement type="package" version="20220414">Fiji</requirement>
        <requirement type="package" version="5.13.1">omero-py</requirement>
        <requirement type="package" version="5.1.0">gawk</requirement>
    </requirements>
    <command detect_errors="exit_code"><![CDATA[
        #import os
        ## the user wants to use a non-public OMERO instance
        ## check if credentials are set in the user-preferences, if not warn the user and exit
        #set $username = $__user__.extra_preferences.get('omero_account|username', "")
        #set $password = $__user__.extra_preferences.get('omero_account|password', "")

        #if str($upload_omero.upload_omero_select) == "yes":
            #if ($username == "" or $password ==""):
                echo "OMERO connection credentials are empty. Set your credentials via: User -> Preferences -> Manage Information" 1>&2 &&
                exit 1 &&
            #end if
            #set $incucyteXMLFile = str($upload_omero.incucyteXMLFile)
            #set $objectiveChoice = str($upload_omero.objectiveChoice)
            #set $startStage = str($upload_omero.startStage)
            #set $plateName = str($upload_omero.plateName)
            #set $ignoreConcentration = str($upload_omero.ignoreConcentration)
            #set $ignorePassage = str($upload_omero.ignorePassage)
            #set $ignoreSeeding = str($upload_omero.ignoreSeeding)
        #else
            #set $incucyteXMLFile = "inexisting.plateMap"
            #set $objectiveChoice = "4x"
            #set $startStage = "72"
            #set $plateName = "Experiment:0"
            #set $ignoreConcentration = "true"
            #set $ignorePassage = "true"
            #set $ignoreSeeding = "true"
        #end if
        
        ## Prefix to directories provided by users
        #set $prefix = "/data/mount_s3/image_storage/"
        ## Prepare input and output directories to match groovy expectations
        mkdir input &&
        mkdir output &&
        #if str($structure.structure_type) == "directory":
            #set $original_file = ""
            #if str($structure.phase_dir_s3) != "":
                #if not os.path.isdir($prefix + "/" + str($structure.phase_dir_s3)):
                    echo "'${prefix}/${structure.phase_dir_s3}'" &&
                    echo "Phase dir $structure.phase_dir_s3 does not exists" &&
                    exit 1 &&
                #end if
                mkdir input/Phase/ &&
                ln -s '${prefix}/${structure.phase_dir_s3}/'*'${structure.pattern}'* input/Phase/ &&
                #set $original_file = str($structure.phase_dir_s3)
            #end if
            #if str($structure.green_dir_s3) != "":
                #if not os.path.isdir($prefix + "/" + str($structure.green_dir_s3)):
                    echo "Green dir $structure.green_dir_s3 does not exists" &&
                    exit 1 &&
                #end if
                mkdir input/Green/ &&
                ln -s '${prefix}/${structure.green_dir_s3}/'*'${structure.pattern}'* input/Green/ &&
                #set $original_file = $original_file + "," + str($structure.green_dir_s3)
            #end if
            #if str($structure.red_dir_s3) != "":
                #if not os.path.isdir($prefix + "/" + str($structure.red_dir_s3)):
                    echo "Red dir $structure.red_dir_s3 does not exists" &&
                    exit 1 &&
                #end if
                mkdir input/Red/ &&
                ln -s '${prefix}/${structure.red_dir_s3}/'*'${structure.pattern}'* input/Red/ &&
                #set $original_file = $original_file + "," + str($structure.red_dir_s3)
            #end if
        #else:
            #if not os.path.isdir($prefix + "/" + str($structure.base_dir)):
                echo "Base dir $structure.base_dir does not exists" &&
                exit 1 &&
            #end if
            #set $original_file = str($structure.base_dir)
            #if str($structure.phase_key) != "":
                mkdir input/Phase/ &&
                ln -s '${prefix}/${structure.base_dir}/'*'${structure.phase_key}'* input/Phase/ &&
            #end if
            #if str($structure.green_key) != "":
                mkdir input/Green/ &&
                ln -s '${prefix}/${structure.base_dir}/'*'${structure.green_key}'* input/Green/ &&
            #end if
            #if str($structure.red_key) != "":
                mkdir input/Red/ &&
                ln -s '${prefix}/${structure.base_dir}/'*'${structure.red_key}'* input/Red/ &&
            #end if
        #end if
        ## Run the groovy
        ImageJ --ij2 --headless --console --run '$__tool_directory__/'stack_buildXml.groovy 
            'base_dir="input/",output_dir="output/",incucyteXMLFile="$incucyteXMLFile",objectiveChoice="$objectiveChoice",nWells="${nWells}",n_images_per_well="${n_images_per_well}",plateName="$plateName",commonKeyValues="original_file=${original_file};start_stage=$startStage",xmlName="$plateName",ignoreConcentration="$ignoreConcentration",ignorePassage="$ignorePassage",ignoreSeeding="$ignoreSeeding"' > output.log
        ## Upload to omero
        #if str($upload_omero.upload_omero_select) == "yes":
            && bash '$__tool_directory__/'upload_omero.sh '$upload_omero.omero_host' '$credentials' '$upload_omero.screen.screen_create' '$upload_omero.screen.screenNameOrID' >> output.log
            ## Copy the companion.ome
            && cp output/*.companion.ome output.companion.ome
        #end if
    ]]></command>
    <configfiles>
        <configfile name="credentials"><![CDATA[
    #set $username = $__user__.extra_preferences.get('omero_account|username', "")
    #set $password = $__user__.extra_preferences.get('omero_account|password', "")
$username
$password
        ]]></configfile>
    </configfiles>
    <inputs>
        <conditional name="structure">
            <param name="structure_type" type="select" label="How are your data organized?" >
                <option value="directory">One directory per channel</option>
                <option value="keyword">All channels into the same directory</option>
            </param>
            <when value="directory">
                <param name="phase_dir_s3" type="text" value="" label="Directory on s3 with Phase images (leave empty if no)" help="For example Pierre/EXP001/My_expe_Phase"/>
                <param name="green_dir_s3" type="text" value="" label="Directory on s3 with Green images (leave empty if no)" help="For example Pierre/EXP001/My_expe_Green"/>
                <param name="red_dir_s3" type="text" value="" label="Directory on s3 with Red images (leave empty if no)" help="For example Pierre/EXP001/My_expe_Red"/>
                <param name="pattern" type="text" value="" label="Pattern to restrict to only some wells" help="For example A2"/>
            </when>
            <when value="keyword">
                <param name="base_dir" type="text" value="" label="Directory on s3 with all images" help="For example Lucille/MyIncucyte/20230213/"/>
                <param name="phase_key" type="text" value="" label="Word that can identify all Phase images (leave empty if no)" help="For example Phase or Brightfield"/>
                <param name="green_key" type="text" value="" label="Word that can identify all Green images (leave empty if no)" help="For example Green or green or GFP"/>
                <param name="red_key" type="text" value="" label="Word that can identify all Red images (leave empty if no)" help="For example Red or red"/>
            </when>
        </conditional>
        <param name="nWells" type="select" label="Number of wells into your plate" >
            <option value="96">96</option>
            <option value="384">384</option>
        </param>
        <param name="n_images_per_well" type="integer" min="1" value="1" label="Maximum number of images per well" />
        <conditional name="upload_omero">
            <param name="upload_omero_select" type="select" label="Upload your images to omero?" >
                <option value="yes">Yes</option>
                <option value="no">No</option>
            </param>
            <when value="yes">
                <param name="incucyteXMLFile" type="data" format="xml" label="Incucyte PlateMap" />
                <param name="objectiveChoice" type="select" label="Select the objective used">
                    <option value="4x">4x</option>
                    <option value="10x">10x</option>
                    <option value="20x">20x</option>
                </param>
                <param name="startStage" type="integer" min="0" value="72" label="Stage in hour at first acquisition"/>
                <param name="omero_host" type="text" label="OMERO host URL">
                    <validator type="regex" message="Enter a valid host location, for example, your.omero.server">^[a-zA-Z0-9._-]*$</validator>
                    <validator type="expression" message="No two dots (..) allowed">'..' not in value</validator>
                </param>
                <param name="plateName" type="text" value="Experiment:0" label="Name of the plate (on omero)" />
                <conditional name="screen">
                    <param name="screen_create" type="select" label="Create the screen on OMERO or use existing one">
                        <option value="create">Create a new one</option>
                        <option value="exists">Use an existing one</option>
                    </param>
                    <when value="create">
                        <param name="screenNameOrID" type="text" value="MyNewScreen" label="Name of the screen (on omero)" />
                    </when>
                    <when value="exists">
                        <param name="screenNameOrID" type="integer" min="0" value="605" label="ID of the screen (on omero)" />
                    </when>
                </conditional>
                <param name="get_stacks_in_galaxy" type="boolean" checked="false" label="Get stacks in galaxy" />
                <param name="ignoreConcentration" type="boolean" checked="true" label="Ignore the concentration of compounds from the plateMap" />
                <param name="ignorePassage" type="boolean" checked="true" label="Ignore the passage number of Cells from the plateMap" />
                <param name="ignoreSeeding" type="boolean" checked="true" label="Ignore the seeding concentration of Cells from the plateMap" />
            </when>
            <when value="no">
                <param name="get_stacks_in_galaxy" type="hidden" value="true"/>
            </when>
        </conditional>
    </inputs>
    <outputs>
        <data name="logfile" format="txt" from_work_dir="output.log" label="${tool.name} on ${on_string}: logfile" />
        <collection name="list_output" type="list" label="${tool.name} on ${on_string}: Stacks">
            <discover_datasets pattern="(?P&lt;designation&gt;.+)\.tif" directory="output/" ext="tiff" />
            <filter>upload_omero['get_stacks_in_galaxy']</filter>
        </collection>
        <data format="xml" name="companion_ome" from_work_dir="output.companion.ome" label="${tool.name} on ${on_string}: companion.ome" >
            <filter>upload_omero['get_stacks_in_galaxy'] and upload_omero['upload_omero_select'] == "yes"</filter>
        </data>
    </outputs>
    <tests>
        <test>
            <conditional name="structure">
                <param name="structure_type" value="directory"/>
                <param name="phase_dir_s3" value="tutu_Phase"/>
                <param name="green_dir_s3" value="toto_Green"/>
            </conditional>
            <conditional name="upload_omero">
                <param name="upload_omero_select" value="no"/>
            </conditional>
            <output name="logfile">
                <assert_contents>
                    <has_line line="No match for B1"/>
                </assert_contents>
            </output>
            <output_collection name="list_output" type="list" count="1">
                <element name="A1_1_merge" ftype="tiff">
                <assert_contents>
                    <has_size value="17574881" delta="1500000"/>
                </assert_contents>
                </element>
            </output_collection>
        </test>
    </tests>
    <help><![CDATA[

.. class:: infomark

**What it does**

It will use images coming from the Incucyte which are on the s3 server to make a "T-stack" per well and upload it to omero with key values in the plateMap.
This wrapper uses ImageJ to combine images (with a groovy) and omero-py to import the images.

Usage
.....


**Input**

- 3 paths of directories (some can be empty of phase, green and red) or one path of directory and 3 keywords (some of them can be empty)
- plateMap generated with the software coming with Incucyte
- objective used (to correctly set the pixel size)
- number of well in your plate (96 or 384), they don't need to be all in your input directories.
- maximum number of images per well
- URL of omero
- Name of the Plate in omero
- Whether the Screen should be created or use an existing one
- Name of the new screen or id of the existing screen
- Whether the concentration of the compounds, the passage and the seeding concentration should be ignored from the plateMap.

**Output**

- A log file with info
- Optionally all images as T-stack and the xml to upload to omero
- On OMERO your images all channels combined and all time points combined into a plate.

**License**

License text::

    *************************************************
    Relative to the generation of the .companion.ome *
    **************************************************
    #%L
    BSD implementations of Bio-Formats readers and writers
    %%
    The functions buildXML, makeImage, makePlate, postProcess and asString has been modified and adapted from
    https://github.com/ome/bioformats/blob/master/components/formats-bsd/test/loci/formats/utests/SPWModelMock.java
    
    Copyright (C) 2005 - 2015 Open Microscopy Environment:
      - Board of Regents of the University of Wisconsin-Madison
      - Glencoe Software, Inc.
      - University of Dundee
    
    @author Chris Allan <callan at blackcat dot ca>
    %%
    
    **************************************************
    Relative to the rest of the script *
    **************************************************
    
    * = AUTHOR INFORMATION =
    Code written by Rémy Dornier, EPFL - SV - PTECH - BIOP
    and Romain Guiet, EPFL - SV - PTECH - BIOP
    and Lucille Delisle, EPFL - SV - UPDUB
    and Pierre Osteil, EPFL - SV - UPDUB
    
    Last modification: 2023-08-24
    
    = COPYRIGHT =
    © All rights reserved. ECOLE POLYTECHNIQUE FEDERALE DE LAUSANNE, Switzerland, BioImaging And Optics Platform (BIOP), 2023
    
    Licensed under the BSD-3-Clause License:
    Redistribution and use in source and binary forms, with or without modification, are permitted provided
    that the following conditions are met:
         1. Redistributions of source code must retain the above copyright notice,
             this list of conditions and the following disclaimer.
         2. Redistributions in binary form must reproduce the above copyright notice,
             this list of conditions and the following disclaimer
             in the documentation and/or other materials provided with the distribution.
         3. Neither the name of the copyright holder nor the names of its contributors
             may be used to endorse or promote products
             derived from this software without specific prior written permission.
    
    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    POSSIBILITY OF SUCH DAMAGE.
    ]]></help>
</tool>