<tool id="cut_trajectory" name="cut trajectory" version="1.0.0" python_template_version="3.5" profile="@GALAXY_VERSION@">
    <macros>
        <token name="@TOOL_VERSION@">2022</token>
        <token name="@GALAXY_VERSION@">21.05</token>
    </macros>
    <requirements>
        <requirement type="package" version="1.1.0">joblib</requirement>
        <requirement type="package" version="@TOOL_VERSION@">gromacs</requirement>
    </requirements>
    <command detect_errors="exit_code"><![CDATA[
        ln -s '$gro_file' '$gro_file.element_identifier' &&
        ln -s '$xtc_file' '$xtc_file.element_identifier' &&
        #if $sub_traj.number_sub_traj == "file":
            ln -s '$sub_traj.nb_sub_traj_file' '$sub_traj.nb_sub_traj_file.element_identifier' &&
        #else:
            ln -s '$sub_traj.check_file_sub_traj' '$sub_traj.check_file_sub_traj.element_identifier' &&
        #end if
        python '$__tool_directory__/cut_trajectory.py'
            --verbose
            --gro_file '$gro_file.element_identifier'
            --xtc_file '$xtc_file.element_identifier'
            --log_output 'out_log/cut_trajectories.log'
            --output_directory 'out/'
            #if $sub_traj.number_sub_traj == "file":
                --nbr_sub_traj '$sub_traj.nb_sub_traj_file.element_identifier'
            #else:
                --nbr_sub_traj '$sub_traj.nb_sub_traj'
                --input_check '$sub_traj.check_file_sub_traj.element_identifier'
                --start_traj '$sub_traj.start_trajectory'
                --end_traj '$sub_traj.end_trajectory'
            #end if
            --group_output $group.select_group
            --number_cpus "\${GALAXY_SLOTS:-1}"
    ]]></command>
    <inputs>
        <param name="gro_file" type="data" format="gro" help="Put your .gro file"/>
        <param name="xtc_file" type="data" format="xtc" help="Put your .xtc file"/>
        <conditional name="sub_traj">
            <param name="number_sub_traj" type="select" label="Number of sub-trajectories">
                <option value="file">with estimation file</option>
                <option value="no_file">without estimation file</option>
            </param>
            <when value="file">
                <param name="nb_sub_traj_file" type="data" format="tabular" label="Number of sub-trajectories file"/>
            </when>
            <when value="no_file">
                <param name="check_file_sub_traj" type="data" format="txt" label="Check file" help="Enter the txt file produced with gmx check.">
                    <validator type="expression" message="Wrong file type">value.extension == "txt"</validator>
                </param>
                <param name="nb_sub_traj" type="integer" value="2" label="Number of sub-trajectories"/>
                <param name="start_trajectory" type="integer" min="0" optional="true" label="Start trajectory" help="Choose the first frame of the trajectory (optional)"/>
                <param name="end_trajectory" type="integer" min="1" optional="true" label="End trajectory" help="Choose the last frame of the trajectory (optional)"/>
            </when>
        </conditional>
        <section name="group" title="Select a group for output">
            <param name="select_group" type="select" display="radio" label="Select a group:">
                <option value="0" selected="true">System</option>
                <option value="1">Protein</option>
                <option value="2">Protein-H</option>
                <option value="3">C-alpha</option>
                <option value="4">Backbone</option>
                <option value="5">MainChain</option>
                <option value="6">MainChain+Cb</option>
                <option value="7">MainChain+H</option>
                <option value="8">SideChain</option>
                <option value="9">SideChain-H</option>
                <option value="10">Prot-Masses</option>
                <option value="11">non-Protein</option>
                <option value="12">Other</option>
                <option value="13">POPC</option>
                <option value="14">POT</option>
                <option value="15">CLA</option>
                <option value="16">TIP3</option>
            </param>
        </section>
    </inputs>
    <outputs>
        <data name="cut_log" format="txt" from_work_dir="out_log/*.log" label="cut_trajectories.log"/>
        <collection name="output_traj" type="list" label="${tool.name} : output trajectories">
            <discover_datasets pattern="(?P&lt;name&gt;.+)\.xtc" directory="out/" ext="xtc"/>
        </collection>
    </outputs>
    <tests>

        <test>
            <param name="select_mode" value="cut"/>
            <param name="gro_file" value="PIP2.1_test.gro"/>
            <param name="xtc_file" value="PIP2.1_test.xtc"/>
            <conditional name="sub_traj">
                <param name="number_sub_traj" value="file"/>
                <param name="nb_sub_traj_file" value="estimated_number_of_sub_trajectories.tsv"/>
            </conditional>
            <section name="group">
                <param name="select_group" value="0"/>
            </section>
            <output name="cut_log" file="cut_trajectories_file.log" ftype="txt" lines_diff="12">
                <assert_contents>
                    <has_n_lines n="163"/>
                    <has_text text="Start cut trajectory"/>
                    <has_text text="Function search_nbr_sub_traj"/>
                    <has_text text="End search_nbr_sub_traj function"/>
                    <has_text text="Function cut_traj"/>
                    <has_text text="End cut_traj function"/>
                    <has_text text="gmx trjconv -f PIP2.1_test.xtc -s PIP2.1_test.gro -b 60 -e 80 -o out/PIP2.1_test_traj_3.xtc"/>
                    <has_text text="Will write xtc: Compressed trajectory (portable xdr format): xtc"/>
                </assert_contents>
            </output>
            <output_collection name="output_traj" type="list">
                <element name="PIP2.1_test_traj_1" file="PIP2.1_test_traj_1.xtc"/>
                <element name="PIP2.1_test_traj_2" file="PIP2.1_test_traj_2.xtc"/>
                <element name="PIP2.1_test_traj_3" file="PIP2.1_test_traj_3.xtc"/>
            </output_collection>
        </test>
        <test>
            <param name="select_mode" value="cut"/>
            <param name="gro_file" value="PIP2.1_test.gro"/>
            <param name="xtc_file" value="PIP2.1_test.xtc"/>
            <conditional name="sub_traj">
                <param name="number_sub_traj" value="no_file"/>
                <param name="nb_sub_traj" value="3"/>
                <param name="check_file_sub_traj" value="PIP2.1_test_check.txt"/>
                <param name="start_trajectory" value="0"/>
                <param name="end_trajectory" value="10"/>
            </conditional>
            <section name="group">
                <param name="select_group" value="0"/>
            </section>
            <output name="cut_log" file="cut_trajectories_no_file.log" ftype="txt" lines_diff="12">
                <assert_contents>
                    <has_n_lines n="161"/>
                    <has_text text="Start cut trajectory"/>
                    <has_text text="Function search_nbr_steps_time_step"/>
                    <has_text text="End search_nbr_steps_time_step functions"/>
                    <has_text text="Function cut_traj"/>
                    <has_text text="End cut_traj function"/>
                    <has_text text="gmx trjconv -f PIP2.1_test.xtc -s PIP2.1_test.gro -b 60 -e 80 -o out/PIP2.1_test_traj_3.xtc"/>
                    <has_text text="Will write xtc: Compressed trajectory (portable xdr format): xtc"/>
                </assert_contents>
            </output>
            <output_collection name="output_traj" type="list">
                <element name="PIP2.1_test_traj_1" file="PIP2.1_test_traj_1.xtc"/>
                <element name="PIP2.1_test_traj_2" file="PIP2.1_test_traj_2.xtc"/>
                <element name="PIP2.1_test_traj_3" file="PIP2.1_test_traj_3.xtc"/>
            </output_collection>
        </test>
    </tests>
    <help><![CDATA[

.. class:: infomark

**What it does**

This tool allows allows to cut a path according to a desired number of sub-trajectories.

_____

.. class:: infomark

**Inputs**

    - gro_file: -gro option. .gro file obtained with GROMACS.
    - xtc_file: -xtc option. .xtc file obtained with GROMACS.
    - with estimation file :
        - Number of sub-trajectories file: -s option. TSV file containing the number of sub-trajectories obtained with the 'Estimate number of sub-trajectories' mode of this tool.
    - without estimation file :
        - Number of sub-trajectories. Choose the number of sub-trajectories.
        - Start trajectory : -start. Choose the first frame of the trajectory (optional).
        - End trajectory : -end. Choose the last frame of the trajectory (optional).
    - Select a group for output. Select the group of atoms in which to cut the trajectory.

_____

.. class:: infomark

**Outputs**

    - 'estimate sub-trajectories or cut trajectory : output trajectories' : collection that contains all the sub-trajectories.
    - 'cut_trajectories.log' : LOG file of the tool execution.

    ]]></help>
    <citations>
        <citation type="doi">10.1093/bioinformatics/btz107</citation>
    </citations>
</tool>
