view subset_taxa.xml @ 8:76cb398e9110 draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ampvis2 commit 9fe04d29ea604a152144908dbd20c0754695a025
author iuc
date Sat, 16 Nov 2024 19:54:15 +0000
parents 20a62b3a3038
children
line wrap: on
line source

<tool id="ampvis2_subset_taxa" name="ampvis2 subset data" version="@TOOL_VERSION@+galaxy1" profile="@PROFILE@" license="MIT">
    <description>by taxonomy</description>
    <macros>
        <import>macros.xml</import>
    </macros>
    <expand macro="header"/>
    <command detect_errors="exit_code"><![CDATA[
        Rscript '$rscript'
    ]]></command>
    <configfiles>
        <configfile name="rscript"><![CDATA[
            library(ampvis2, quietly = TRUE)
            data <- readRDS("$data")

            #if $select_param == "option_input_selected_file"
                ## Define the file path (assuming it's a text file with one value per line)
                file_path <- "$selected_taxonomy_list"

                ## Read the file into a character vector, where each line represents a value
                lines <- readLines(file_path)

                ## Remove any leading or trailing whitespace (if necessary)
                tax_vector <- trimws(lines)
            #else
                tax_vector <- unlist(strsplit("$tax_vector", ","))
            #end if
                data <- amp_subset_taxa(
                data,
                tax_vector = tax_vector,
                normalise = $normalise,
                remove = $remove
                )     

            saveRDS(data, "$ampvis")
            @SAVE_TAX_LIST@
        ]]></configfile>
    </configfiles>
    <inputs>
        <expand macro="rds_input_macro"/>
        <!-- add validator -->
        <conditional name="taxonomy_select_type">
            <param name="select_param" type="select" label="Choose taxa input option">
                <option value="option_input_file">Select taxa from taxonomy list file</option>
                <option value="option_input_selected_file">Provide a file with selected taxa</option>
            </param>

            <when value="option_input_selected_file">
                <param name="selected_taxonomy_list" type="data" optional="false" format="tabular" label="Selected taxonomy list" help="A file containing the taxa to subsample. One taxa per line."/>
            </when>
        
            <when value="option_input_file">
                <param name="taxonomy_list" type="data" optional="false" format="tabular" label="Taxonomy list" help="Generated with ampvis2: load"/>
                <expand macro="taxonomy_select_macro" argument="tax_vector" label="Taxa to keep"/>
            </when>
        </conditional>
        
        <expand macro="normalise_macro"/>
        <param argument="remove" type="boolean" truevalue="TRUE" falsevalue="FALSE" checked="false" label="Remove" help="Selected taxa will be removed instead of being the only ones kept in the data."/>
    </inputs>
    <outputs>
        <data name="ampvis" format="ampvis2"/>
        <data name="taxonomy_list_out" format="tabular" label="${tool.name} on ${on_string}: taxonomy list"/>
    </outputs>
    <!-- Test cases -->
    <tests>
        <!-- Test case for using comma-separated taxonomy list -->
        <test expect_num_outputs="2">
            <param name="data" value="AalborgWWTPs.rds" ftype="ampvis2"/> 
            <param name="select_param" value="option_input_file"/>
            <param name="taxonomy_list" value="AalborgWWTPs-taxonomy.list"/> 
            <param name="tax_vector" value="f__Caldilineaceae,p__Elusimicrobia"/>
            <output name="ampvis" value="AalborgWWTPs-subset_taxa.rds" ftype="ampvis2" compare="sim_size"/>
            <output name="taxonomy_list_out" ftype="tabular">
                <assert_contents>
                    <has_text text="f__Caldilineaceae"/>
                    <has_text text="p__Elusimicrobia"/>
                </assert_contents>
            </output>
        </test>

        <!-- Test case for using comma-separated taxonomy list and remove=true -->
        <test expect_num_outputs="2">
            <param name="data" value="AalborgWWTPs.rds" ftype="ampvis2"/> 
            <param name="select_param" value="option_input_file"/>
            <param name="taxonomy_list" value="AalborgWWTPs-taxonomy.list"/> 
            <param name="tax_vector" value="f__Caldilineaceae,p__Elusimicrobia"/>
            <param name="remove" value="true"/>
            <output name="ampvis" value="AalborgWWTPs-subset_taxa.rds" ftype="ampvis2" compare="sim_size"/>
            <output name="taxonomy_list_out" ftype="tabular">
                <assert_contents>
                    <not_has_text text="f__Caldilineaceae"/>
                    <not_has_text text="p__Elusimicrobia"/>
                </assert_contents>
            </output>
        </test>

        <!-- Test case for using selected taxonomy list from a file -->
        <test expect_num_outputs="2">
            <param name="data" value="AalborgWWTPs.rds" ftype="ampvis2"/> 
            <param name="select_param" value="option_input_selected_file"/>
            <param name="selected_taxonomy_list" value="AalborgWWTPs-selected.taxonomy.list"/> 
            <param name="remove" value="true"/>
            <output name="ampvis" value="AalborgWWTPs-subset_taxa.rds" ftype="ampvis2" compare="sim_size"/>
            <output name="taxonomy_list_out" ftype="tabular">
                <assert_contents>
                    <not_has_text text="f__Caldilineaceae"/>
                    <not_has_text text="p__Elusimicrobia"/>
                </assert_contents>
            </output>
        </test>
    </tests>
    <help><![CDATA[
What it does
============

Subsets the data in ampvis2 objects based on taxonomy and returns the subsetted object.

The Galaxy tool calls the `amp_subset_taxa
<https://kasperskytte.github.io/ampvis2/reference/amp_filter_taxa.html>`_ function
of the ampvis2 package.

This tool provides two options for specifying the `subset`:

1. **Provide taxa names matching the taxonomy table**:

The taxonomy subset is done by providing a tax_vector of taxa names which are
then matched to the taxonomy table, where all other taxa not matching the
"Taxa to keep" (``tax_vector``) are removed. If "Remove" is enabled, then the
matching taxa are the ones being removed instead. The taxa names 
will be matched in all columns of the taxonomy table.

2. **Provide a file of selected taxonomies**:

In this option, you can upload a file containing the taxa you wish to subset. 
The file should contain one taxon name per line. 
This option is useful when you have a pre-defined list of taxa stored in a file.
This is useful if you want to use the tool in a workflow or if you automatically generate
a taxonomy selection e.g. with differential abundance tools like MaAsLi2 and you only want to 
plot these taxa.


@HELP_RELATIVE_ABUNDANCES@

Input
=====

@HELP_RDS_INPUT@

@HELP_METADATA_LIST_INPUT@

Output
======

An ampvis2_rds dataset containing subsetted data and an updated taxonomy list dataset.

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