<tool id="recetox_aplcms_correct_time" name="recetox-aplcms - correct time" version="@TOOL_VERSION@+galaxy2" profile="21.09">
    <description>correct retention time across samples for peak alignment</description>
    <macros>
        <import>macros.xml</import>
        <import>help.xml</import>
    </macros>
    <edam_operations>
        <edam_operation>operation_3628</edam_operation>
    </edam_operations>
    <expand macro="annotation"/>
    <expand macro="creator"/>
    <expand macro="requirements"/>

    <command detect_errors="aggressive"><![CDATA[
        Rscript -e 'source("${__tool_directory__}/utils.R")' -e 'source("${run_script}")'
    ]]></command>
    <configfiles>
         <configfile name="run_script"><![CDATA[
              features_table <- load_data_from_parquet_file('$features_table')
              sample_name <- load_sample_name(features_table)

              if(is.na(sample_name)) {
                  message("The file does not contain sample name.")
              }

              template_features <- load_data_from_parquet_file('$template')

              corrected_table <- correct_time(
                   this.feature = features_table,
                   template_features = template_features,
                   mz_tol_relative = $mz_tol_relative_ppm * 1e-06,
                   rt_tol_relative = $rt_tol
              )

              corrected_table <- save_sample_name(corrected_table, sample_name)
              save_data_as_parquet_file(corrected_table, '$output_file')
         ]]></configfile>
    </configfiles>

    <inputs>
        <param label="Input clustered features table" name="features_table" type="data" format="parquet"
               help="Mass spectrometry clustered features table." />
        <param label="Input template features table" name="template" type="data" format="parquet"
               help="Template features table." />
        <expand macro="tolerances"/>
    </inputs>

    <outputs>
        <data label="${($features_table.element_identifier).rsplit('.',1)[0]}.parquet" name="output_file" format="parquet" />
    </outputs>

    <tests>

    </tests>

    <help>
        <![CDATA[
            @CORRECT_TIME_HELP@

            @GENERAL_HELP@
        ]]>
    </help>

    <expand macro="citations"/>
</tool>
