view ramclustr.xml @ 11:da7722f665f4 draft default tip

planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/ramclustr commit bc3445f7c41271b0062c7674108f57708d08dd28
author recetox
date Thu, 30 May 2024 14:52:11 +0000
parents 2d94da58904b
children
line wrap: on
line source

<tool id="ramclustr" name="RAMClustR" version="@TOOL_VERSION@+galaxy7" profile="21.09">
    <description>A feature clustering algorithm for non-targeted mass spectrometric metabolomics data.</description>
    <macros>
        <import>macros.xml</import>
    </macros>
    <expand macro='annotation'/>
    <edam_operations>
        <edam_operation>operation_3557</edam_operation>
        <edam_operation>operation_3435</edam_operation>
        <edam_operation>operation_3432</edam_operation>
        <edam_operation>operation_3465</edam_operation>
    </edam_operations>
    <expand macro="refs"/>
    <expand macro="creator"/>

    <requirements>
        <requirement type="package" version="@TOOL_VERSION@">r-ramclustr</requirement>
        <requirement type="package" version="3.20.0">bioconductor-xcms</requirement>
        <requirement type="package" version="9.0.0">r-arrow</requirement>
    </requirements>

    <command detect_errors="exit_code"><![CDATA[
        Rscript
            -e 'source("${__tool_directory__}/ramclustr_wrapper.R")'
            -e 'source("${ramclustr_method}")'
    ]]>
    </command>
    <configfiles>
        <configfile name="ramclustr_method">
            #if $filetype.type_choice == "xcms":
            obj = load("$filetype.xcms.input_xcms")
            ramclustObj = RAMClustR::rc.get.xcms.data(
                xcmsObj = xdata,
                #if $extras.ExpDes:
                    ExpDes = load_experiment_definition("${$extras.ExpDes}"),
                #end if
                mzdec = $msp_output_details.mzdec,
                ensure.no.na = $extras.replace_zeros
            )
            #else if $filetype.type_choice == "csv":
            ramclustObj = RAMClustR::rc.get.csv.data(
                csv = "$filetype.ms_csv.ms",
                #if $filetype.ms_csv.idmsms:
                    idmsms = "$filetype.ms_csv.idmsms",
                #end if
                #if $filetype.ms_csv.csv_phenoData:
                    phenoData = "$filetype.ms_csv.csv_phenoData",
                #end if
                #if $extras.ExpDes:
                    ExpDes = load_experiment_definition("${$extras.ExpDes}"),
                #end if
                st = $filetype.required.st,
                ensure.no.na = $extras.replace_zeros
            )
            #else if $filetype.type_choice == "recetox-aplcms":
            ramclustObj = read_ramclustr_aplcms(
                ms1_featuredefinitions = "$filetype.ms_dataframe.ms1_featureDefinitions",
                ms1_featurevalues = "$filetype.ms_dataframe.ms1_featureValues",
                ms1_featuredefinitions_ext = "$filetype.ms_dataframe.ms1_featureDefinitions.ext",
                ms1_featurevalues_ext = "$filetype.ms_dataframe.ms1_featureValues.ext",
                #if $filetype.ms_dataframe.df_phenoData:
                    df_phenodata = "$filetype.ms_dataframe.df_phenoData",
                    phenodata_ext = "${filetype.ms_dataframe.df_phenoData.ext}",
                #end if
                #if $extras.ExpDes:
                    exp_des = "${$extras.ExpDes}",
                #end if
                st = $filetype.required.st,
                ensure_no_na = $extras.replace_zeros
            )
            #end if

            #if $extras.replace_zeros == "TRUE":
            ramclustObj = RAMClustR::rc.feature.replace.na(ramclustObj = ramclustObj)
            #end if

            #if $filtering.feature_filter_blanks.filter_blanks == "TRUE":
            ramclustObj = RAMClustR::rc.feature.filter.blanks(
                ramclustObj = ramclustObj,
                qc.tag = "${filtering.feature_filter_blanks.qc_tag}",
                blank.tag = "${filtering.feature_filter_blanks.blank_tag}",
                sn = $filtering.feature_filter_blanks.sn,
                remove.blanks = $filtering.feature_filter_blanks.remove_blanks
            )
            #end if

            #if $normalisation.normalisation_method.normalize != "none":
            ramclustObj = apply_normalisation(
                ramclustr_obj = ramclustObj,
                #if $normalisation.normalisation_method.normalize == "batch.qc":
                    metadata_file = "${$normalisation.normalisation_method.batch_order_qc}",
                    qc_inj_range = $normalisation.normalisation_method.qc_inj_range,
                #end if
                #if $normalisation.normalisation_method.normalize == "qc":
                    metadata_file = "${$normalisation.normalisation_method.batch_order_qc}",
                    p_cut = $normalisation.normalisation_method.p_cut,
                    rsq_cut = $normalisation.normalisation_method.rsq_cut,
                    p_adjust = $normalisation.normalisation_method.p_adjust,
                #end if
                normalize_method = "$normalisation.normalisation_method.normalize"
            )
            #end if

            #if $filtering.feature_filter_cv.filter_cv == "TRUE":
            ramclustObj = RAMClustR::rc.feature.filter.cv(
                ramclustObj = ramclustObj,
                qc.tag = "${filtering.feature_filter_cv.qc_tag}",
                max.cv = $filtering.feature_filter_cv.max_cv
            )
            #end if

            ramclustObj = RAMClustR::rc.ramclustr(
                ramclustObj = ramclustObj,
                st = $filetype.required.st,
                sr = $filetype.required.sr,
                maxt = $filetype.required.maxt,
                deepSplit = $clustering.deepSplit,
                blocksize = $performance.blocksize,
                mult = $performance.mult,
                hmax = $clustering.hmax,
                minModuleSize = $clustering.minModuleSize,
                linkage = "$clustering.linkage",
                cor.method = "$filetype.required.cor_method",
                rt.only.low.n = $extras.rt_only_low_n,
                fftempdir = NULL,
            )

            #if $extras.quality_control == "TRUE":
            ramclustObj = RAMClustR::rc.qc(ramclustObj = ramclustObj)
            #end if
            
            store_output(
                ramclustr_obj = ramclustObj,
                output_merge_msp = $msp_output_details.merge_msp,
                output_spec_abundance = "$spec_abundance",
                #if $msp_output_details.merge_msp:
                    msp_file = "$mass_spectra_merged"
                #else:
                    msp_file = NULL
                #end if
            )
        </configfile>
    </configfiles>
    <inputs>
        <conditional name="filetype">
            <param name="type_choice" type="select" label="Choose input format:">
                <option value="xcms" selected="true">XCMS</option>
                <option value="csv">CSV</option>
                <option value="recetox-aplcms">RECETOX-APLCMS</option>
            </param>
            <when value="xcms">
                <expand macro="parameters_xcms" />
                <section name="required" title="General parameters" expanded="true">
                    <param label="Sigma t" name="st" type="float" optional="true" help="Retention time similarity (optional).
                           A recommended starting point is half the value of your average chromatographic peak width at half max (seconds))."/>
                    <expand macro="parameters_required" />
                </section>
            </when>
            <when value="csv">
                <expand macro="parameters_csv" />
                <section name="required" title="General parameters" expanded="true">
                    <param label="Sigma t" name="st" type="float" value="1" help="Retention time similarity.
                           A recommended starting point is half the value of your average chromatographic peak width at half max (seconds))."/>
                    <expand macro="parameters_required" />
                </section>
            </when>
            <when value="recetox-aplcms">
                <expand macro="parameters_recetox_aplcms" />
                <section name="required" title="General parameters" expanded="true">
                    <param label="Sigma t" name="st" type="float" value="1" help="Retention time similarity.
                           A recommended starting point is half the value of your average chromatographic peak width at half max (seconds))."/>
                    <expand macro="parameters_required" />
                </section>
            </when>
        </conditional>
        <expand macro="main_parameters" />
    </inputs>

    <outputs>
        <data label="Spec Abundance of ${on_string}" name="spec_abundance" format="tsv" />
        <expand macro="output_msp"/>
    </outputs>

    <tests>
        <test expect_num_outputs="2"><!-- TEST 1 -->
            <section name="filetype">
                <param name="type_choice" value="xcms"/>
                <section name="xcms">
                    <param name="input_xcms" value="test1_xcmsObj_1.rdata.xcms.fillpeaks" ftype="rdata.xcms.fillpeaks"/>
                </section>
                <section name="required">
                    <param name="maxt" value="259.8"/>
                </section>
            </section>
            <section name="msp_output_details">
                <param name="mzdec" value="4"/>
            </section>
            <section name="extras">
                <param name="ExpDes" value="lc-ramclustr-define-experiment.csv" ftype="csv"/>
            </section>
            <output name="mass_spectra_merged" file="test1_fill_xcms_1.msp" ftype="msp"/>
            <output name="spec_abundance" file="test1_spec_abundance_xcms_1.tsv" ftype="tsv" compare="sim_size" delta="100"/>
        </test>
        <test expect_num_outputs="2"><!-- TEST 2 -->
            <section name="filetype">
                <param name="type_choice" value="xcms"/>
                <section name="xcms">
                    <param name="input_xcms" value="test2_xcmsObj_2.rdata.xcms.fillpeaks" ftype="rdata.xcms.fillpeaks"/>
                </section>
                <section name="required">
                    <param name="maxt" value="78.4"/>
                </section>
            </section>
            <section name="msp_output_details">
                <param name="mzdec" value="4"/>
            </section>
            <section name="normalisation">
                <section name="normalisation_method">
                    <param name="batch_order_qc" value="test2_sample_metadata_xcms_2.csv" ftype="csv" />
                </section>
            </section>
            <output name="mass_spectra_merged" file="test2_fill_xcms_2.msp" ftype="msp" compare="sim_size" delta="100"/>
            <output name="spec_abundance" file="test2_spec_abundance_xcms_2.tsv" ftype="tsv" compare="sim_size" delta="100"/>
        </test>
        <test expect_num_outputs="2"><!-- TEST 3 -->
            <section name="filetype">
                <param name="type_choice" value="csv"/>
                <section name="ms_csv">
                    <param name="ms" value="test3_csv_test-input_1_2.csv" ftype="csv"/>
                </section>
                <section name="required">
                    <param name="st" value="5.0"/>
                    <param name="maxt" value="1"/>
                </section>
            </section>
            <section name="performance">
                <param name="blocksize" value="1000"/>
                <param name="mult" value="1"/>
            </section>
            <output name="mass_spectra_merged" file="test3_spectra_csv_1.msp" ftype="msp"/>
            <output name="spec_abundance" file="test3_spec_abundance_csv_1.tsv" ftype="tsv"/>
        </test>
        <test expect_num_outputs="2"><!-- TEST 4 -->
            <section name="filetype">
                <param name="type_choice" value="csv"/>
                <section name="ms_csv">
                    <param name="ms" value="test3_csv_test-input_1_2.csv" ftype="csv"/>
                </section>
            </section>
            <output name="mass_spectra_merged" file="test4_spectra_csv_2.msp" ftype="msp" lines_diff="10"/>
        </test>
        <test expect_num_outputs="2"><!-- TEST 5 -->
            <section name="filetype">
                <param name="type_choice" value="recetox-aplcms"/>
                <section name="ms_dataframe">
                    <param name="ms1_featureDefinitions" value="test5_df_featureDefinitions_input.parquet" ftype="parquet"/>
                    <param name="ms1_featureValues" value="test5_df_featureValues_input.parquet" ftype="parquet"/>
                </section>
            </section>
            <output name="mass_spectra_merged" file="test5_spectra.msp" ftype="msp" lines_diff="10"/>
        </test>
        <test expect_num_outputs="3"><!-- TEST 6 -->
            <section name="filetype">
                <param name="type_choice" value="xcms"/>
                <section name="xcms">
                    <param name="input_xcms" value="test6.fillpeaks" ftype="rdata.xcms.fillpeaks"/>
                </section>
            </section>
            <section name="msp_output_details">
                <param name="mzdec" value="4"/>
            </section>
            <section name="extras">
                <param name="quality_control" value="TRUE"/>
            </section>
            <section name="filtering">
                <section name="feature_filter_blanks">
                    <param name="filter_blanks" value="TRUE"/>
                    <param name="blank_tag" value="Blanc"/>
                </section>
                <section name="feature_filter_cv">
                    <param name="filter_cv" value="TRUE"/>
                </section>
            </section>
            <output name="mass_spectra_merged" file="test6_out.msp" ftype="msp"/>
            <output name="spec_abundance">
                <assert_contents>
                    <has_size value="309" delta="10"/>
                </assert_contents>
            </output>
            <output name="pdf_plot">
                <assert_contents>
                    <has_size value="6842" delta="100"/>
                </assert_contents>
            </output>
        </test>
    </tests>

    <help>
        <![CDATA[
            @HELP@

        .. rubric:: **Footnotes**
        .. [1] Correlation, Variance and Covariance - `stats::cor <https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/cor>`_
        .. [2] Hierarchical Clustering - `stats::hclust <https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/hclust>`_
        .. [3] Dynamic Dendrogram Pruning Based on Dendrogram Only - `dynamicTreeCut::cutreeDynamicTree <https://www.rdocumentation.org/packages/dynamicTreeCut/versions/1.63-1/topics/cutreeDynamicTree>`_
        ]]>
    </help>

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