view cutadapt.xml @ 33:135b80fb1ac2 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/cutadapt commit 7143af903be8405ca77d524b343e0973304be693
author iuc
date Fri, 14 Oct 2022 12:50:14 +0000
parents 5915ea1ec9b1
children 9845c649f41b
line wrap: on
line source

<tool id="cutadapt" name="Cutadapt" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="20.01">
    <description>Remove adapter sequences from FASTQ/FASTA</description>
    <macros>
        <import>macros.xml</import>
    </macros>
    <expand macro='edam_ontology' />
    <expand macro='xrefs'/>
    <expand macro='requirements' />
    <version_command>cutadapt --version</version_command>

    <command detect_errors="exit_code"><![CDATA[
## Link in the input and output files, so Cutadapt can tell their type

#import re
#set read1 = "input_f"
#set read2 = "input_r"
#set paired = False
#set library_type = str($library.type)
#if $library_type == 'paired':
    #set paired = True
    #set input_1 = $library.input_1
    #set input_2 = $library.input_2
    ## Avoid the paired read input files sharing the same name, else the program still runs but 
    ## uses inaccurate results by using only 1 of 2 files.
    #set read1 = re.sub('[^\w\-\s]', '_', str($library.input_1.element_identifier))
    #set read2 = re.sub('[^\w\-\s]', '_', str($library.input_2.element_identifier))
    #if read1 == read2:
        #set read1 = read1 + "_1"
        #set read2 = read2 + "_2"
    #end if
#else if $library_type == 'paired_collection'
    #set paired = True
    #set input_1 = $library.input_1.forward
    #set input_2 = $library.input_1.reverse
    #set read1 = re.sub('[^\w\-\s]', '_', str($library.input_1.name)) + "_1"
    #set read2 = re.sub('[^\w\-\s]', '_', str($library.input_1.name)) + "_2"
#else
    #set input_1 = $library.input_1
    #set read1 = re.sub('[^\w\-\s]', '_', str($library.input_1.element_identifier))
#end if

#if $input_1.is_of_type("fastq.gz", "fastqsanger.gz"):
    #set ext = ".fq.gz"
#else if $input_1.is_of_type("fastq.bz2", "fastqsanger.bz2"):
    #set ext = ".fq.bz2"
#else if $input_1.is_of_type('fasta'):
    #set ext = ".fa"
#else:
    #set ext = ".fq"
#end if
#set read1 = $read1 + $ext
#set out1 = "out1" + $ext
#set rest_output = "rest_output" + $ext
#set wild_output = "wild_output" + $ext
#set too_short_output = "too_short_output" + $ext
#set too_long_output = "too_long_output" + $ext
#set untrimmed_output = "untrimmed_output" + $ext
ln -f -s '${input_1}' '$read1' &&

#if $paired:
    #if $input_2.is_of_type("fastq.gz", "fastqsanger.gz"):
        #set ext2 = ".fq.gz"
    #else if $input_2.is_of_type("fastq.bz2", "fastqsanger.bz2"):
        #set ext2 = ".fq.gz"
    #else if $input_2.is_of_type('fasta'):
        #set ext2 = ".fa"
    #else:
        #set ext2 = ".fq"
    #end if
    #set read2 = $read2 + $ext2
    #set out2 = "out2" + $ext2
    #set too_short_paired_output = "too_short_paired_output" + $ext2
    #set too_long_paired_output = "too_long_paired_output" + $ext2
    #set untrimmed_paired_output = "untrimmed_paired_output" + $ext2
    ln -f -s '${input_2}' '$read2' &&
#end if

## Run Cutadapt

#if 'multiple_output' in $output_selector:
    mkdir split &&
#end if

cutadapt

-j=\${GALAXY_SLOTS:-4}

#if 'json_stats' in $output_selector:
        --json stats.json
#end if

#if str( $library.type ) == "single":
    @read1_options@
    #if 'multiple_output' in $output_selector:
        --output='split/{name}.${input_1.ext}'
    #else:
        --output='$out1'
    #end if
#else:
    @read1_options@
    @read2_options@
    --output='$out1'
    --paired-output='$out2'
#end if

--error-rate=$adapter_options.error_rate
--times=$adapter_options.times
--overlap=$adapter_options.overlap
$adapter_options.no_indels
$adapter_options.match_read_wildcards
--action=$adapter_options.action
$adapter_options.revcomp

$filter_options.discard_trimmed
$filter_options.discard_untrimmed

#if str($filter_options.minimum_length) and str($filter_options.length_R2_options.length_R2_status) == 'True':
    --minimum-length=$filter_options.minimum_length:$filter_options.length_R2_options.R2_minimum
#else if str($filter_options.minimum_length):
    --minimum-length=$filter_options.minimum_length
#end if
#if str($filter_options.maximum_length) and str($filter_options.length_R2_options.length_R2_status) == 'True':
    --maximum-length=$filter_options.maximum_length:$filter_options.length_R2_options.R2_maximum
#else if str($filter_options.maximum_length):
    --maximum-length=$filter_options.maximum_length
#end if
#if str($filter_options.max_n):
    --max-n=$filter_options.max_n
#end if
#if str( $library.type ) != "single":
    #if $filter_options.pair_filter:
        --pair-filter=$filter_options.pair_filter
    #end if
#end if
#if str($filter_options.max_expected_errors):
    --max-expected-errors=$filter_options.max_expected_errors
#end if
$filter_options.discard_cassava

#if str($read_mod_options.quality_cutoff) != '0':
   --quality-cutoff=$read_mod_options.quality_cutoff
#end if
#if str($read_mod_options.nextseq_trim) != '0':
    --nextseq-trim=$read_mod_options.nextseq_trim
#end if
$read_mod_options.trim_n
#if $read_mod_options.strip_suffix != ''
    --strip-suffix $read_mod_options.strip_suffix
#end if
#if str($read_mod_options.shorten_options.shorten_values) == 'True':
    #if str($read_mod_options.shorten_options.shorten_end) == '3prime'
        --length=$read_mod_options.shorten_options.length
    #else
        --length=-$read_mod_options.shorten_options.length
    #end if
#end if
#if str($read_mod_options.length_tag) != '':
    --length-tag='$read_mod_options.length_tag'
#end if
#if str($read_mod_options.rename) != '':
    --rename='$read_mod_options.rename'
#end if
$read_mod_options.zero_cap


'${read1}'
#if $paired:
    '${read2}'
    #if $library.r2.quality_cutoff2:
        -Q=$library.r2.quality_cutoff2
    #end if
#end if

#if 'report' in $output_selector:
    > report.txt
#end if
    ]]></command>
    <inputs>

        <!-- Reads -->
        <conditional name="library">
            <param name="type" type="select" label="Single-end or Paired-end reads?">
                <option value="single">Single-end</option>
                <option value="paired">Paired-end</option>
                <option value="paired_collection">Paired-end Collection</option>
            </param>

            <when value="single">
                <param name="input_1" format="@FASTQ_TYPES@" type="data" label="FASTQ/A file" help="Should be of datatype &quot;fastq.gz&quot; or &quot;fasta&quot;" />
                <expand macro="single_end_options" />
            </when>

            <when value="paired">
                <param name="input_1" format="@FASTQ_TYPES@" type="data" label="FASTQ/A file #1" help="Should be of datatype &quot;fastq.gz&quot;or &quot;fasta&quot;" />
                <param name="input_2" format="@FASTQ_TYPES@" type="data" label="FASTQ/A file #2" help="Should be of datatype &quot;fastq.gz&quot;or &quot;fasta&quot;" />
                <expand macro="paired_end_options" />
            </when>

            <when value="paired_collection">
                <param name="input_1" format="@FASTQ_TYPES@" type="data_collection" collection_type="paired" label="Paired Collection" help="Should be of datatype &quot;fastq.gz&quot; or &quot;fasta&quot;" />
                <expand macro="paired_end_options" />
            </when>

        </conditional>

        <!-- Adapter Options -->
        <section name="adapter_options" title="Adapter Options">
            <param name="action" type="select" label="What to do if a match is found">
                <option value="trim" selected="True">Trim: trim adapter and upstream or downstream sequence</option>
                <option value="retain">Retain: the read is trimmed, but the adapter sequence is not removed</option>
                <option value="mask">Mask: mask adapters with 'N' characters instead of trimming them</option>
                <option value="lowercase">Lowercase: convert to lowercase</option>
                <option value="none">None: leave unchanged</option>
            </param>
            <param name="internal" type="select" label="Disallow internal adaptor ocurrences" help="The non-internal 5’ and 3’ adapter types disallow internal occurrences of the adapter sequence. The adapter must always be at one of the ends of the read, but partial occurrences are also ok.">
                <option value="X">Enabled</option>
                <option value="" selected="True">Disabled</option>
            </param>
            <param argument="--error-rate" type="float" min="0" max="1" value="0.1" label="Maximum error rate" help="Maximum allowed error rate (no. of errors divided by the length of the matching region)." />
            <param argument="--no-indels" type="boolean" value="False" truevalue="--no-indels" falsevalue="" label="Do not allow indels (Use ONLY with anchored 5' (front) adapters)." help="Do not allow indels in the alignments. That is, allow only mismatches. This option is currently only supported for anchored 5' adapters ('^ADAPTER') (default: both mismatches and indels are allowed)." />
            <param argument="--times" type="integer" min="1" value="1" label="Match times" help="Try to remove adapters at most COUNT times. Useful when an adapter gets appended multiple times." />
            <param argument="--overlap" type="integer" min="1" value="3" label="Minimum overlap length" help="Minimum overlap length. If the overlap between the adapter and the sequence is shorter than LENGTH, the read is not modified. This reduces the number of bases trimmed purely due to short random adapter matches." />
                <param name="match_read_wildcards" type="select"  label="Match wildcards" help="Allow 'N's as matches. Default: in the adapters but not in the reads">
                <option value=" " selected="True">In the adapters but not in the reads</option>
                <option value="--match-read-wildcards">In the adapters and in the reads</option>
                <option value="--no-match-adapter-wildcards">Nowhere</option>
            </param>
            <param argument="--revcomp" type="boolean" value="False" truevalue="--revcomp" falsevalue="" label="Look for adapters in the reverse complement" help="Check both the read and its reverse complement for adapter matches. If match is on reverse-complemented version, output that one. Default: check only read." />
        </section>

        <!-- Filter Options -->
        <section name="filter_options" title="Filter Options">
            <param argument="--discard-trimmed" type="boolean" value="False" truevalue="--discard-trimmed" falsevalue="" label="Discard Trimmed Reads" help="Discard reads that contain the adapter instead of trimming them. Use the 'Minimum overlap length' option in order to avoid throwing away too many randomly matching reads!" />
            <param argument="--discard_untrimmed" type="boolean" value="False" truevalue="--discard-untrimmed" falsevalue="" label="Discard Untrimmed Reads" help="Discard reads that do not contain the adapter." />
            <param argument="--minimum-length" type="integer" min="0" optional="True" value="" label="Minimum length (R1)" help="Discard trimmed reads that are shorter than LENGTH.  Reads that are too short even before adapter removal are also discarded." />
            <param argument="--maximum-length" type="integer" min="0" optional="True" value="" label="Maximum length (R1)" help="Discard trimmed reads that are longer than LENGTH.  Reads that are too long even before adapter removal are also discarded." />
            <conditional name="length_R2_options">
                <param name="length_R2_status" type="select" label="Specify a minimum/maximum length for reverse reads (R2)" help="When trimming paired-end reads, the minimum/maximum lengths for R1 and R2 can be specified separately. If not provided, the same minimum length applies to both reads.">
                    <option value="True">Enabled</option>
                    <option value="False" selected="True">Disabled</option>
                </param>
                <when value="True">
                    <param name="R2_minimum" type="integer" min="0" value="" optional="True" label="Minimum length (R2)" />
                    <param name="R2_maximum" type="integer" min="0" value="" optional="True" label="Maximum length (R2)" />
                </when>
                <when value="False">
                </when>
            </conditional>
            <param argument="--max-n" type="float" min="0" optional="True" label="Max N" help="Discard reads with more than this number of 'N' bases. A number between 0 and 1 is interpreted as a fraction of the read length." />
            <param argument="--pair-filter" type="select" optional="True" label="Pair filter" help="Which of the reads in a paired-end read have to match the filtering criterion in order for the pair to be filtered. Default: any">
                <option value="any" selected="True">Any: a read pair is discarded (or redirected) if one of the reads (R1 or R2) fulfills the filtering criterion. </option>
                <option value="both">Both: filtering criteria must apply to both reads in order for a read pair to be discarded. </option>
                <option value="first">First: will make a decision about the read pair by inspecting whether the filtering criterion applies to the first read, ignoring the second read.</option>

            </param>
            <param argument="--max-expected-errors" type="integer" min="0" optional="True" value="" label="Max expected errors" help="Discard reads whose expected number of errors (computed from quality values) exceeds this value." />
            <param argument="--discard-cassava" type="boolean" truevalue="--discard-cassava" falsevalue="" checked="False" label="Discard CASAVA filtering" help="Discard reads that did not pass CASAVA filtering (header has :Y:)." />
        </section>

        <!-- Read Modification Options -->
        <section name="read_mod_options" title="Read Modification Options">
            <param argument="--quality-cutoff" type="text" value="0" label="Quality cutoff" help=" Trim low-quality bases from 5' and/or 3' ends of each read before adapter removal. Applied to both reads for paired-end data, unless a separate value for the second read is specified. If one value is given, only the 3' end is trimmed. If two comma-separated cutoffs are given, the 5' end is trimmed with the first cutoff, the 3' end with the second.">
                <sanitizer>
                    <valid initial="string.digits"><add value="," /></valid>
                </sanitizer>
                <validator type="regex">[0-9,]+</validator>
            </param>
            <param argument="--nextseq-trim" type="integer" value="0" label="NextSeq trimming" help="Experimental option for quality trimming of NextSeq data. This is necessary because that machine cannot distinguish between G and reaching the end of the fragment (it encodes G as ‘black’). This option works like regular quality trimming (where one would use -q 20 instead), except that the qualities of G bases are ignored." />
            <param argument="--trim-n" type="boolean" truevalue="--trim-n" falsevalue="" checked="False" label="Trim Ns" help="Trim N's on ends of reads." />
            <param argument="--strip-suffix" label="Strip suffix" type="text" help="Remove this suffix from read names if present." />
            <conditional name="shorten_options">
                <param name="shorten_values" type="select" label="Shortening reads to a fixed length" help="If you want to remove a fixed number of bases from each read, use the –cut option instead.">
                    <option value="True">Enabled</option>
                    <option value="False" selected="True">Disabled</option>
                </param>
                <when value="True">
                    <param argument="--length" type="integer" value="0" label="Length" help="Shorten reads to this length. This modification is applied after adapter trimming." />
                    <param name="shorten_end" type="select" label="End at which to apply the slice">
                        <option value="3prime">3' ends</option>
                        <option value="5prime">5' ends</option>
                    </param>
                </when>
                <when value="False">
                </when>
            </conditional>
            <param argument="--length-tag" label="Length tag" type="text" optional="True" help="Search for TAG followed by a decimal number in the name of the read (description/comment field of the FASTA or FASTQ file). Replace the decimal number with the correct length of the trimmed read. For example, use --length-tag 'length=' to search for fields like 'length=123'." >
                <sanitizer invalid_char="">
                    <valid initial="string.letters,string.digits">
                        <add value="/" />
                        <add value="+" />
                        <add value="-" />
                        <add value="=" />
                        <add value=" " />
                        <add value="_" />
                    </valid>
                </sanitizer>
                <validator type="regex">[A-Za-z0-9 =-_/+]+</validator>
            </param>
            <param argument="--rename" label="Rename reads" type="text" optional="True" help="This option can be used to rename both single-end and paired-end reads. ">
                <sanitizer invalid_char="">
                    <valid initial="string.letters,string.digits">
                        <add value="{" />
                        <add value="}" />
                        <add value="_" />
                        <add value="=" />
                        <add value=" " />
                    </valid>
                </sanitizer>
                <validator type="regex">[A-Za-z0-9 {}=_]+</validator>
            </param>
            <param argument="--zero-cap" type="boolean" truevalue="--zero-cap" falsevalue="" checked="False" label="Change negative quality values to zero" />
        </section>

        <!-- Output Options -->
        <param name="output_selector" type="select" multiple="True" display="checkboxes" label="Outputs selector">
            <option value="report">Report: Cutadapt's per-adapter statistics. You can use this file with MultiQC.</option>
            <option value="info_file">Info file: write information about each read and its adapter matches.</option>
            <option value="rest_file">Rest of read: when the adapter matches in the middle of a read, write the rest (after the adapter).</option>
            <option value="wildcard_file">Wildcard file: when the adapter has wildcard bases (Ns) write adapter bases matching wildcard positions.</option>
            <option value="too_short_file">Too short reads: write reads that are too short according to minimum length specified (default: discard reads).</option>
            <option value="too_long_file">Too long reads: write reads that are too long (according to maximum length specified)</option>
            <option value="untrimmed_file">Untrimmed reads: write reads that do not contain the adapter to a separate file, instead of writing them to the regular output file (default: output to same file as trimmed)</option>
            <option value="multiple_output">Multiple output: create a separate file for each adapter trimmed (default: all trimmed reads are in a single file)</option>
            <option value="json_stats">Statistics in JSON format</option>
        </param>
    </inputs>

    <outputs>
        <data name="out1" format="fastqsanger" metadata_source="input_1" from_work_dir="out1*" label="${tool.name} on ${on_string}: Read 1 Output">
            <filter>library['type'] != 'paired_collection' and 'multiple_output' not in output_selector</filter>
            <expand macro="inherit_format_1" />
        </data>

        <data name="out2" format="fastqsanger" metadata_source="input_2" from_work_dir="out2*" label="${tool.name} on ${on_string}: Read 2 Output" >
            <filter>library['type'] == 'paired' and 'multiple_output' not in output_selector</filter>
            <expand macro="inherit_format_2" />
        </data>

        <collection name="out_pairs" type="paired" format_source="input_1" label="${tool.name} on ${on_string}: Reads">
            <filter>library['type'] == 'paired_collection' and 'multiple_output' not in output_selector</filter>
            <data name="forward" from_work_dir="out1.fq*" />
            <data name="reverse" from_work_dir="out2.fq*" />
        </collection>
        
        <data name="report" format="txt" from_work_dir="report.txt" label="${tool.name} on ${on_string}: Report">
            <filter>output_selector and 'report' in output_selector</filter>
        </data>
        <data  name="info_file" format="txt" metadata_source="input_1" label="${tool.name} on ${on_string}: Info File" >
            <filter>output_selector and 'info_file' in output_selector</filter>
        </data>

        <data name="rest_output" format="fastqsanger" metadata_source="input_1" from_work_dir="rest_output*" label="${tool.name} on ${on_string}: Rest of Reads (R1 only)" >
            <filter>output_selector and 'rest_file' in output_selector</filter>
            <expand macro="inherit_format_1" />
        </data>

        <data name="wild_output" format="txt" metadata_source="input_1" from_work_dir="wild_output*" label="${tool.name} on ${on_string}: Wildcard File" >
            <filter>output_selector and 'wildcard_file' in output_selector</filter>
        </data>

        <data name="untrimmed_output" format="fastqsanger" metadata_source="input_1" from_work_dir="untrimmed_output*" label="${tool.name} on ${on_string}: Untrimmed Read 1" >
            <filter>output_selector and 'untrimmed_file' in output_selector</filter>
            <expand macro="inherit_format_1" />
        </data>
        <data name="untrimmed_paired_output" format="fastqsanger" metadata_source="input_2" from_work_dir="untrimmed_paired_output*" label="${tool.name} on ${on_string}: Untrimmed Read 2" >
            <filter>library['type'] == 'paired' or library['type'] == 'paired_collection'</filter>
            <filter>output_selector and 'untrimmed_file' in output_selector </filter>
            <expand macro="inherit_format_2" />
        </data>

        <data name="too_short_output" format="fastqsanger" metadata_source="input_1" from_work_dir="too_short_output*" label="${tool.name} on ${on_string}: Too Short Read 1" >
            <filter>output_selector and 'too_short_file' in output_selector</filter>
            <expand macro="inherit_format_1" />
        </data>
        <data name="too_short_paired_output" format="fastqsanger" metadata_source="input_2" from_work_dir="too_short_paired_output*" label="${tool.name} on ${on_string}: Too Short Read 2" >
            <filter>library['type'] == 'paired' or library['type'] == 'paired_collection'</filter>
            <filter>output_selector and 'too_short_file' in output_selector</filter>
            <expand macro="inherit_format_2" />
        </data>
        <data name="too_long_output" format="fastqsanger" metadata_source="input_1" from_work_dir="too_long_output*" label="${tool.name} on ${on_string}: Too Long Read 1" >
            <filter>output_selector and 'too_long_file' in output_selector</filter>
            <expand macro="inherit_format_1" />
        </data>
        <data name="too_long_paired_output" format="fastqsanger" metadata_source="input_2" from_work_dir="too_long_paired_output*" label="${tool.name} on ${on_string}: Too Long Read 2" >
            <filter>library['type'] == 'paired' or library['type'] == 'paired_collection'</filter>
            <filter>output_selector and 'too_long_file' in output_selector</filter>
            <expand macro="inherit_format_2" />
        </data>
        <data name="json_stats" format="json" from_work_dir="stats.json" label="${tool.name} on ${on_string}: Statistics (JSON)" >
            <filter>output_selector and 'json_stats' in output_selector</filter>
        </data>
        <collection name="split_output" type="list" label="${tool.name} on ${on_string}: Split outputs" format="fastqsanger" >
            <discover_datasets pattern="(?P&lt;designation&gt;.+)\.(?P&lt;ext&gt;fastq.*)" directory="split" />
            <filter>output_selector and 'multiple_output' in output_selector</filter>
        </collection>
    </outputs>

    <tests>
        <!-- Ensure fastq works -->
        <test expect_num_outputs="1">
            <param name="type" value="single" />
            <param name="input_1" ftype="fastq" value="cutadapt_small.fastq" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="AGATCGGAAGAGC"/>
                    </conditional>
                </repeat>
            </section>
            <output name="out1" file="cutadapt_small.out" ftype="fastq"/>
        </test>
        <!-- Ensure single end fastq.gz works -->
        <test expect_num_outputs="1">
            <param name="type" value="single" />
            <param name="input_1" ftype="fastq.gz" value="bwa-mem-fastq1.fq.gz" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="AGATCGGAAGAGC"/>
                    </conditional>
                </repeat>
            </section>
            <output name="out1" decompress="True" file="cutadapt_out1.fq.gz" ftype="fastq.gz"/>
        </test>
        <!-- Ensure paired end fastq.gz works -->
        <test expect_num_outputs="2">
            <param name="type" value="paired" />
            <param name="input_1" ftype="fastq.gz" value="bwa-mem-fastq1.fq.gz" />
            <param name="input_2" ftype="fastq.gz" value="bwa-mem-fastq2.fq.gz" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="AGATCGGAAGAGC"/>
                    </conditional>
                </repeat>
            </section>
            <section name="r2">
                <repeat name="adapters2">
                    <conditional name="adapter_source2">
                        <param name="adapter_source_list2" value="user"/>
                        <param name="adapter2" value="AGATCGGAAGAGC"/>
                    </conditional>
                </repeat>
            </section>
            <output name="out1" decompress="True" file="cutadapt_out1.fq.gz" ftype="fastq.gz"/>
            <output name="out2" decompress="True" file="cutadapt_out2.fq.gz" ftype="fastq.gz"/>
            <assert_command>
                <not_has_text text="--discard-trimmed"/>
                <not_has_text text="--discard-untrimmed"/>
                <not_has_text text="--minimum-length"/>
                <not_has_text text="--maximum-length"/>
                <not_has_text text="--max-n"/>
                <has_text text="--pair-filter=any"/>
            </assert_command>
        </test>
        <!-- Ensure paired collection works -->
        <test expect_num_outputs="3">
            <param name="type" value="paired_collection" />
            <param name="input_1">
                <collection type="paired">
                    <element name="forward" ftype="fastq.gz" value="bwa-mem-fastq1.fq.gz" />
                    <element name="reverse" ftype="fastq.gz" value="bwa-mem-fastq2.fq.gz" />
                </collection>
            </param>
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="AGATCGGAAGAGC"/>
                    </conditional>
                </repeat>
            </section>
            <section name="r2">
                <repeat name="adapters2">
                    <conditional name="adapter_source2">
                        <param name="adapter_source_list2" value="user"/>
                        <param name="adapter2" value="AGATCGGAAGAGC"/>
                    </conditional>
                </repeat>
            </section>
            <output_collection name="out_pairs" type="paired" count="2">
                <element name="forward" decompress="true" file="cutadapt_out1.fq.gz" ftype="fastq.gz">
                    <assert_contents>
                        <has_size value="12000" delta="2000" />
                    </assert_contents>
                </element>
                <element name="reverse" decompress="true" file="cutadapt_out2.fq.gz" ftype="fastq.gz">
                    <assert_contents>
                        <has_size value="12000" delta="2000" />
                    </assert_contents>
                </element>
            </output_collection>
        </test>
        <!-- Ensure built-in adapters work -->
        <test expect_num_outputs="1">
            <param name="type" value="single" />
            <param name="input_1" ftype="fastq" value="cutadapt_small.fastq" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="builtin"/>
                        <param name="adapter" value="TGTAGGCC"/>
                    </conditional>
                </repeat>
            </section>
            <output name="out1" file="cutadapt_builtin.out" ftype="fastq"/>
        </test>
        <!-- Ensure discard file output works -->
        <test expect_num_outputs="1">
            <param name="input_1" ftype="fastq" value="cutadapt_small.fastq" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="TTAGACATATCTCCGTCG"/>
                    </conditional>
                </repeat>
            </section>
            <section name="filter_options">
                <param name="discard_trimmed" value="True"/>
            </section>
            <output name="out1" file="cutadapt_discard.out" ftype="fastq"/>
            <assert_command>
                <has_text text="--discard-trimmed"/>
            </assert_command>
        </test>
        <!-- Ensure rest file output works, test json output -->
        <test expect_num_outputs="3">
            <param name="input_1" ftype="fasta" value="cutadapt_rest.fa" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="AAAGATG"/>
                    </conditional>
                </repeat>
            </section>
            <param name="output_selector" value="rest_file,json_stats"/>
            <output name="out1" file="cutadapt_rest.out" ftype="fasta"/>
            <!--allow for differing cutadapt and python version as well as two lines containing the number of cores -->
            <output name="json_stats" file="cutadapt_rest.json" ftype="json" lines_diff="8"/>
            <output name="rest_output" file="cutadapt_rest2.out" ftype="fasta"/>
        </test>
        <!-- Ensure nextseq-trim option works -->
        <test expect_num_outputs="1">
            <param name="type" value="single" />
            <param name="input_1" ftype="fastq.gz" value="bwa-mem-fastq1.fq.gz" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="AGATCGGAAGAGC"/>
                    </conditional>
                </repeat>
            </section>
            <param name="nextseq_trim" value="20" />
            <output name="out1" decompress="True" file="cutadapt_nextseq_out.fq.gz" ftype="fastq.gz"/>
        </test>
        <!-- Ensure Report and Info file output work -->
        <test expect_num_outputs="3">
            <param name="type" value="single" />
            <param name="input_1" ftype="fastq" value="cutadapt_small.fastq" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="AGATCGGAAGAGC"/>
                    </conditional>
                </repeat>
            </section>
            <param name="output_selector" value="report,info_file" />
            <output name="out1" value="cutadapt_small.out" ftype="fastq"/>
            <output name="report">
                <assert_contents>
                    <has_text text="Summary"/>
                </assert_contents>
            </output>
            <output name="info_file" value="cutadapt_info_out.txt" ftype="txt"/>
        </test>


        <test expect_num_outputs="1">
            <conditional name="library">
                <param name="type" value="single" />
                <param name="input_1" ftype="fastq" value="cutadapt_in_split.fastq" />
                <section name="r1" >
                    <repeat name="front_adapters">
                        <conditional name="front_adapter_source">
                            <param name="front_adapter_source_list" value="user"/>
                            <param name="front_adapter_name" value="A1" />
                            <param name="front_adapter" value="^GTCGGTAA" />
                        </conditional>
                    </repeat>
                    <repeat name="front_adapters">
                        <conditional name="front_adapter_source">
                            <param name="front_adapter_source_list" value="user"/>
                            <param name="front_adapter_name" value="A2" />
                            <param name="front_adapter" value="^AGGTCACT" />
                        </conditional>
                    </repeat>
                </section>
            </conditional>
            <param name="output_selector" value="multiple_output" />
            <output_collection name="split_output" type="list" count="3">
                   <element name="A1" value="A1.fastq" ftype="fastq">
                   </element>
                   <element name="A2" value="A2.fastq" ftype="fastq">
                   </element>
                   <element name="unknown" value="unknown.fastq" ftype="fastq">
                   </element>
             </output_collection>
        </test>

        <test expect_num_outputs="1">
            <conditional name="library">
                <param name="type" value="single" />
                <param name="input_1" ftype="fastq.gz" value="cutadapt_in_split.fastq.gz" />
                <section name="r1" >
                    <repeat name="front_adapters">
                        <conditional name="front_adapter_source">
                            <param name="front_adapter_source_list" value="file"/>
                            <param name="front_adapter_file" ftype="fasta"  value="barcodes.fasta" />
                        </conditional>
                    </repeat>
                </section>
            </conditional>
            <param name="output_selector" value="multiple_output" />
            <output_collection name="split_output" type="list" count="3">
                   <element name="A1"  decompress="True" file="A1.fastq.gz" ftype="fastq.gz">
                   </element>
                   <element name="A2" decompress="True" file="A2.fastq.gz" ftype="fastq.gz">
                   </element>
                   <element name="unknown" decompress="True" file="unknown.fastq.gz" ftype="fastq.gz">
                   </element>
             </output_collection>
        </test>

        <!-- Ensure untrimmed file output works -->
        <test expect_num_outputs="2">
            <param name="type" value="single" />
            <param name="input_1" ftype="fastq" value="cutadapt_small.fastq" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="AAAT"/>
                    </conditional>
                </repeat>
            </section>
            <param name="output_selector" value="untrimmed_file" />
            <output name="out1" file="cutadapt_trimmed.out" ftype="fastq"/>
            <output name="untrimmed_output" file="cutadapt_untrimmed.out" ftype="fastq"/>
        </test>
        <!-- Ensure untrimmed gzip file output works -->
        <test expect_num_outputs="2">
            <param name="type" value="single" />
            <param name="input_1" ftype="fastq.gz" value="bwa-mem-fastq1.fq.gz" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="AGATCGGAAGAGC"/>
                    </conditional>
                </repeat>
            </section>
            <param name="output_selector" value="untrimmed_file" />
            <output name="out1" decompress="True" file="cutadapt_trimmed.out.gz" ftype="fastq.gz"/>
            <!--
                Do not use the decompress option for this assertion, since it does NOT test that the file is compressed
                See discussion at https://github.com/galaxyproject/galaxy/issues/7671
                `delta="4000" is more than the difference between gzip level 1 and gzip level 9, but much less than the
                difference between level 1 compression and no compression
            -->
            <output name="untrimmed_output" file="cutadapt_untrimmed.out.gz" compare="sim_size" delta="4000" ftype="fastq.gz"/>
        </test>
        <!-- same as 1st test with paired data + filter options (because of discard_untrimmed no comparison is done) -->
        <test expect_num_outputs="2">
            <param name="type" value="paired" />
            <param name="input_1" ftype="fastq.gz" value="bwa-mem-fastq1.fq.gz" />
            <param name="input_2" ftype="fastq.gz" value="bwa-mem-fastq2.fq.gz" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="AGATCGGAAGAGC"/>
                    </conditional>
                </repeat>
            </section>
            <section name="r2">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list2" value="user"/>
                        <param name="adapter2" value="AGATCGGAAGAGC"/>
                    </conditional>
                </repeat>
            </section>
            <section name="filter_options">
                <param name="discard_untrimmed" value="true"/>
                <param name="minimun_length" value="1"/>
                <param name="maximum_length" value="1000"/>
                <param name="max_n" value="0"/>
                <param name="pair_filter" value="both"/>
            </section>
            <assert_command>
                <has_text text="--discard-untrimmed"/>
                <has_text text="--maximum-length=1000"/>
                <has_text text="--max-n=0"/>
                <has_text text="--pair-filter=both"/>
            </assert_command>
        </test>
        <!-- Test cut option -->
        <test expect_num_outputs="1">
            <param name="type" value="single" />
            <param name="input_1" ftype="fastq" value="cutadapt_small.fastq" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="AGATCGGAAGAGC"/>
                    </conditional>
                </repeat>
                <param name="cut" value="5"/>
            </section>
            <output name="out1" file="cutadapt_small_cut.out" ftype="fastq"/>
        </test>
        <!-- Test rename options -->
        <test expect_num_outputs="1">
            <param name="type" value="single" />
            <param name="input_1" ftype="fastq" value="cutadapt_small.fastq" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="AGATCGGAAGAGC"/>
                    </conditional>
                </repeat>
                <param name="cut" value="5"/>
            </section>
            <section name="read_mod_options">
                <param name="rename" value="{id} barcode={cut_prefix}"/>
            </section>
            <output name="out1" file="cutadapt_small_rename.out" ftype="fastq">
                <assert_contents>
                    <has_text text="@prefix:1_13_1259/1 barcode=AGCCG"/>
                </assert_contents>
            </output>
        </test>
        <!-- Test action options -->
        <test expect_num_outputs="1">
            <param name="type" value="single" />
            <param name="input_1" ftype="fastq" value="cutadapt_small.fastq" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="CGTCCGAANTAG"/>
                    </conditional>
                </repeat>
            </section>
            <section name="adapter_options">
                <param name="action" value="retain"/>
            </section>
            <output name="out1" file="cutadapt_action_retain.out" ftype="fastq"/>
        </test>
           <test expect_num_outputs="1">
            <param name="type" value="single" />
            <param name="input_1" ftype="fastq" value="cutadapt_small.fastq" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="CGTCCGAANTAG"/>
                    </conditional>
                </repeat>
            </section>
            <section name="adapter_options">
                <param name="action" value="mask"/>
            </section>
            <output name="out1" file="cutadapt_action_mask.out" ftype="fastq"/>
        </test>
        <test expect_num_outputs="1">
            <param name="type" value="single" />
            <param name="input_1" ftype="fastq" value="cutadapt_small.fastq" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="CGTCCGAANTAG"/>
                    </conditional>
                </repeat>
            </section>
            <section name="adapter_options">
                <param name="action" value="lowercase"/>
            </section>
            <output name="out1" file="cutadapt_action_lowercase.out" ftype="fastq"/>
        </test>
        <test expect_num_outputs="1">
            <param name="type" value="single" />
            <param name="input_1" ftype="fastq" value="cutadapt_small.fastq" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="CGTCCGAANTAG"/>
                    </conditional>
                </repeat>
            </section>
            <section name="adapter_options">
                <param name="action" value="none"/>
            </section>
            <output name="out1" file="cutadapt_action_none.out" ftype="fastq"/>
        </test>
        <!-- Test revcomp options -->
        <test expect_num_outputs="1">
            <param name="type" value="single" />
            <param name="input_1" ftype="fastq" value="cutadapt_small.fastq" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="TAAACAGATTAGT"/>
                    </conditional>
                </repeat>
            </section>
            <section name="adapter_options">
                <param name="revcomp" value="true"/>
            </section>
            <output name="out1" file="cutadapt_revcomp.out" ftype="fastq"/>
        </test>
        <!-- Test minimum lenghth paired-reads -->
        <test expect_num_outputs="2">
            <param name="type" value="paired" />
            <param name="input_1" ftype="fastq.gz" value="bwa-mem-fastq1_assimetric.fq.gz" />
            <param name="input_2" ftype="fastq.gz" value="bwa-mem-fastq2_assimetric.fq.gz" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="ATCTGGTTCC"/>
                    </conditional>
                </repeat>
            </section>
            <section name="r2">
                <repeat name="adapters2">
                    <conditional name="adapter_source2">
                        <param name="adapter_source_list2" value="user"/>
                        <param name="adapter2" value="CTACAAG"/>
                    </conditional>
                </repeat>
            </section>
            <section name="filter_options">
                <param name="minimum_length" value="30"/>
                <param name="pair_filter" value="both"/>
                <conditional name="length_R2_options">
                    <param name="length_R2_status" value="True"/>
                    <param name="R2_minimum" value="10"/>
                </conditional>
            </section>
            <output name="out1" decompress="True" file="cutadapt_out1_min_length.fq.gz" ftype="fastq.gz"/>
            <output name="out2" decompress="True" file="cutadapt_out2_min_length.fq.gz" ftype="fastq.gz"/>
            <assert_command>
                <has_text text="--minimum-length=30:10"/>
                <has_text text="--pair-filter=both"/>
            </assert_command>
        </test>
        <!-- Test maximum lenghth paired-reads -->
        <test expect_num_outputs="2">
            <param name="type" value="paired" />
            <param name="input_1" ftype="fastq.gz" value="bwa-mem-fastq1_assimetric.fq.gz" />
            <param name="input_2" ftype="fastq.gz" value="bwa-mem-fastq2_assimetric.fq.gz" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="AGATCGGAAGAGC"/>
                    </conditional>
                </repeat>
            </section>
            <section name="r2">
                <repeat name="adapters2">
                    <conditional name="adapter_source2">
                        <param name="adapter_source_list2" value="user"/>
                        <param name="adapter2" value="AGATCGGAAGAGC"/>
                    </conditional>
                </repeat>
            </section>
            <section name="filter_options">
                <param name="pair_filter" value="both"/>
                <param name="maximum_length" value="50"/>
                <conditional name="length_R2_options">
                    <param name="length_R2_status" value="True"/>
                    <param name="R2_maximum" value="30"/>
                </conditional>
            </section>
            <output name="out1" decompress="True" file="cutadapt_out1_max_length.fq.gz" ftype="fastq.gz"/>
            <output name="out2" decompress="True" file="cutadapt_out2_max_length.fq.gz" ftype="fastq.gz"/>
            <assert_command>
                <has_text text="--maximum-length=50:30"/>
                <has_text text="--pair-filter=both"/>
            </assert_command>
        </test>
        <!-- Test combination maximum and minimum length paired reads -->
        <test expect_num_outputs="2">
            <param name="type" value="paired" />
            <param name="input_1" ftype="fastq.gz" value="bwa-mem-fastq1_assimetric.fq.gz" />
            <param name="input_2" ftype="fastq.gz" value="bwa-mem-fastq2_assimetric.fq.gz" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="AGATCGGAAGAGC"/>
                    </conditional>
                </repeat>
            </section>
            <section name="r2">
                <repeat name="adapters2">
                    <conditional name="adapter_source2">
                        <param name="adapter_source_list2" value="user"/>
                        <param name="adapter2" value="AGATCGGAAGAGC"/>
                    </conditional>
                </repeat>
            </section>
            <section name="filter_options">
                <param name="pair_filter" value="both"/>
                <param name="minimum_length" value="10"/>
                <param name="maximum_length" value="50"/>
                <conditional name="length_R2_options">
                    <param name="length_R2_status" value="True"/>
                    <param name="R2_maximum" value="30"/>
                </conditional>
            </section>
            <output name="out1" decompress="True" file="cutadapt_out1_max_min_01.fq.gz" ftype="fastq.gz"/>
            <output name="out2" decompress="True" file="cutadapt_out2_max_min_01.fq.gz" ftype="fastq.gz"/>
            <assert_command>
                <has_text text="--minimum-length=10:"/>
                <has_text text="--maximum-length=50:30"/>
                <has_text text="--pair-filter=both"/>
            </assert_command>
        </test>
        <test expect_num_outputs="2">
            <param name="type" value="paired" />
            <param name="input_1" ftype="fastq.gz" value="bwa-mem-fastq1_assimetric.fq.gz" />
            <param name="input_2" ftype="fastq.gz" value="bwa-mem-fastq2_assimetric.fq.gz" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="AGATCGGAAGAGC"/>
                    </conditional>
                </repeat>
            </section>
            <section name="r2">
                <repeat name="adapters2">
                    <conditional name="adapter_source2">
                        <param name="adapter_source_list2" value="user"/>
                        <param name="adapter2" value="AGATCGGAAGAGC"/>
                    </conditional>
                </repeat>
            </section>
            <section name="filter_options">
                <param name="pair_filter" value="both"/>
                <param name="minimum_length" value="10"/>
                <param name="maximum_length" value="50"/>
                <conditional name="length_R2_options">
                    <param name="length_R2_status" value="True"/>
                    <param name="R2_minimum" value="10"/>
                </conditional>
            </section>
            <output name="out1" decompress="True" file="cutadapt_out1_max_min_02.fq.gz" ftype="fastq.gz"/>
            <output name="out2" decompress="True" file="cutadapt_out2_max_min_02.fq.gz" ftype="fastq.gz"/>
            <assert_command>
                <has_text text="--minimum-length=10:10"/>
                <has_text text="--maximum-length=50:"/>
                <has_text text="--pair-filter=both"/>
            </assert_command>
        </test>
        <!-- Test length options -->
        <test expect_num_outputs="1">
            <param name="type" value="single" />
            <param name="input_1" ftype="fastq" value="cutadapt_small.fastq" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="AGCCGCTANGACG"/>
                    </conditional>
                </repeat>
            </section>
            <section name="read_mod_options">
                <conditional name="shorten_options">
                    <param name="shorten_values" value="True"/>
                    <param name="shorten_end" value="3prime"/>
                    <param name="length" value="10"/>
                </conditional>
            </section>
            <output name="out1" file="cutadapt_shorten_3prime.out" ftype="fastq"/>
        </test>
        <test expect_num_outputs="1">
            <param name="type" value="single" />
            <param name="input_1" ftype="fastq" value="cutadapt_small.fastq" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="AGCCGCTANGACG"/>
                    </conditional>
                </repeat>
            </section>
            <section name="read_mod_options">
                <conditional name="shorten_options">
                    <param name="shorten_values" value="True"/>
                    <param name="shorten_end" value="5prime"/>
                    <param name="length" value="10"/>
                </conditional>
            </section>
            <output name="out1" file="cutadapt_shorten_5prime.out" ftype="fastq"/>
        </test>
        <!-- Test max expected errors options -->
        <test expect_num_outputs="1">
            <param name="type" value="single" />
            <param name="input_1" ftype="fastq" value="cutadapt_small.fastq" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="AGCGGCTTAGACG"/>
                    </conditional>
                </repeat>
            </section>
            <section name="filter_options">
                <param name="max_expected_errors" value="10"/>
            </section>
            <output name="out1" file="cutadapt_shorten_expected_errors.out" ftype="fastq"/>
        </test>
        <!-- Test disallow internal adaptors option -->
        <test expect_num_outputs="1">
            <param name="type" value="single" />
            <param name="input_1" ftype="fastq" value="cutadapt_small.fastq" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="GAANTAGCTACCAC"/>
                    </conditional>
                </repeat>
            </section>
            <section name="adapter_options">
                <param name="internal" value="X"/>
            </section>
            <output name="out1" file="cutadapt_shorten_internal_adapters.out" ftype="fastq"/>
            <assert_command>
                <has_text text="GAANTAGCTACCACX"/>
            </assert_command>
        </test>
        <test expect_num_outputs="2">
            <param name="type" value="paired" />
            <param name="input_1" ftype="fastq.gz" value="bwa-mem-fastq1_assimetric.fq.gz" />
            <param name="input_2" ftype="fastq.gz" value="bwa-mem-fastq2_assimetric.fq.gz" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="AGATCGGAAGAGC"/>
                    </conditional>
                </repeat>
            </section>
            <section name="r2">
                <repeat name="adapters2">
                    <conditional name="adapter_source2">
                        <param name="adapter_source_list2" value="user"/>
                        <param name="adapter2" value="AGATCGGAAGAGC"/>
                    </conditional>
                </repeat>
            </section>
            <section name="adapter_options">
                <param name="internal" value="X"/>
            </section>
            <output name="out1" decompress="True" file="cutadapt_out1_internal_adapter.fq.gz" ftype="fastq.gz"/>
            <output name="out2" decompress="True" file="cutadapt_out2_internal_adapter.fq.gz" ftype="fastq.gz"/>
            <assert_command>
                <has_text text="AGATCGGAAGAGCX"/>
            </assert_command>
        </test>
        <test expect_num_outputs="1">
            <param name="type" value="single" />
            <param name="input_1" ftype="fastq" value="cutadapt_small.fastq" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="builtin"/>
                        <param name="adapter" value="TGTAGGCC"/>
                    </conditional>
                </repeat>
            </section>
            <section name="adapter_options">
                <param name="internal" value="X"/>
            </section>
            <output name="out1" file="cutadapt_builtin_internal_adapter.out" ftype="fastq"/>
            <assert_command>
                <has_text text="TGTAGGCCX"/>
            </assert_command>
        </test>
        <!-- Ensure individual per adapter noindels parameter works -->
        <test expect_num_outputs="3">
            <param name="type" value="paired_collection" />
            <param name="input_1">
                <collection type="paired">
                    <element name="forward" ftype="fastq.gz" value="bwa-mem-fastq1.fq.gz" />
                    <element name="reverse" ftype="fastq.gz" value="bwa-mem-fastq2.fq.gz" />
                </collection>
            </param>
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="AGATCGGAAGAGC"/>
                    </conditional>
                    <param name="single_noindels" value=";noindels" />
                </repeat>
            </section>
            <section name="r2">
                <repeat name="adapters2">
                    <conditional name="adapter_source2">
                        <param name="adapter_source_list2" value="user"/>
                        <param name="adapter2" value="AGATCGGAAGAGC"/>
                    </conditional>
                    <param name="single_noindels" value=";noindels" />
                </repeat>
            </section>
            <output_collection name="out_pairs" type="paired">
                <element name="forward" decompress="True" file="cutadapt_out1.fq.gz" ftype="fastq.gz" />
                <element name="reverse" decompress="True" file="cutadapt_out2.fq.gz" ftype="fastq.gz" />
            </output_collection>
        </test>
        <!-- Ensure specifying quality cutoff (for both reads) works -->
        <test expect_num_outputs="3">
            <param name="type" value="paired_collection" />
            <param name="input_1">
                <collection type="paired">
                    <element name="forward" ftype="fastq.gz" value="bwa-mem-fastq1.fq.gz" />
                    <element name="reverse" ftype="fastq.gz" value="bwa-mem-fastq2.fq.gz" />
                </collection>
            </param>
            <param name="quality_cutoff" value="5" />
            <section name="r1">
                <repeat name="adapters">
                    <conditional name="adapter_source">
                        <param name="adapter_source_list" value="user"/>
                        <param name="adapter" value="AGATCGGAAGAGC"/>
                    </conditional>
                </repeat>
            </section>
            <section name="r2">
                <repeat name="adapters2">
                    <conditional name="adapter_source2">
                        <param name="adapter_source_list2" value="user"/>
                        <param name="adapter2" value="AGATCGGAAGAGC"/>
                    </conditional>
                </repeat>
                <param name="quality_cutoff2" value="15,20"/>
            </section>
            <output_collection name="out_pairs" type="paired">
                <element name="forward" decompress="True" file="cutadapt_out1.fq.gz" ftype="fastq.gz" />
                <element name="reverse" decompress="True" file="cutadapt_out2_cutoff.fq.gz" ftype="fastq.gz" />
            </output_collection>
        </test>
    </tests>

    <help><![CDATA[

.. class:: infomark

**What it does**

-------------------

**Cutadapt** finds and removes adapter sequences, primers, poly-A tails and other types of unwanted sequence from your high-throughput sequencing reads.

Cleaning your data in this way is often required: Reads from small-RNA sequencing contain the 3’ sequencing adapter because the read is longer than the molecule that is sequenced, such as in microRNA, or CRISPR data, or Poly-A tails that are useful for pulling out RNA from your sample but often you don’t want them to be in your reads.

Cutadapt_ helps with these trimming tasks by finding the adapter or primer sequences in an error-tolerant way. It can also modify and filter reads in various ways. Cutadapt searches for the adapter in all reads and removes it when it finds it. Unless you use a filtering option, all reads that were present in the input file will also be present in the output file, some of them trimmed, some of them not. Even reads that were trimmed entirely (because the adapter was found in the very beginning) are output. All of this can be changed with options in the tool form above.

The tool is based on the **Open Source** Cutadapt_ tool. See the complete `Cutadapt documentation`_ for additional details. If you use Cutadapt, please cite *Marcel, 2011* under **Citations** below.

-------------------

**Inputs**

-------------------

Input files for Cutadapt need to be:

- FASTQ.GZ, FASTQ.BZ2, FASTQ or FASTA

To trim an adapter, input the ADAPTER sequence in plain text or in a FASTA file e.g. AACCGGTT (with the characters: **$**, **^**, **...**, if anchored or linked).

    =============================================   ===================
    **Option**                                      **Sequence**
    ---------------------------------------------   -------------------
    3’ (End) Adapter                                ADAPTER
    Anchored 3’ Adapter                             ADAPTER$

    5’ (Front) Adapter                              ADAPTER
    Anchored 5’ Adapter                             ^ADAPTER

    5’ or 3’ (Both possible)                        ADAPTER

    Linked Adapter - 3' (End) only                  ADAPTER1...ADAPTER2
    Non-anchored Linked Adapter - 5' (Front) only   ADAPTER1...ADAPTER2
    =============================================   ===================

Below is an illustration of the allowed adapter locations relative to the read and depending on the adapter type:

.. image:: $PATH_TO_IMAGES/adapters.svg


-------------------

*Example: Illumina TruSeq Adapters*

-------------------

If you have reads containing Illumina TruSeq adapters, for example, follow these steps.


For Single-end reads as well as the first reads of Paired-end data:

**Read 1**

In the **3' (End) Adapters** option above, insert A + the “TruSeq Indexed Adapter” prefix that is common to all Indexed Adapter sequences, e.g insert:

AGATCGGAAGAGCACACGTCTGAACTCCAGTCAC


For the second reads of Paired-end data:

**Read 2**

In the **3' (End) Adapters** option above, insert the reverse complement of the “TruSeq Universal Adapter”:

AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGTAGATCTCGGTGGTCGCCGTATCATT

The adapter sequences can be found in the document `Illumina TruSeq Adapters De-Mystified`_.

-----------

**Outputs**

-----------

- Trimmed reads

Optionally, under **Output Options** you can choose to output

    * Report
    * Info file


**Report**

Cutadapt can output per-adapter statistics if you select to output the report above.

Example:

    ::
        
        This is cutadapt 3.4 with Python 3.9.2

        Command line parameters: -j=1 -a AGATCGGAAGAGC -A AGATCGGAAGAGC --output=out1.fq.gz --paired-output=out2.fq.gz --error-rate=0.1 --times=1 
        --overlap=3 --action=trim --minimum-length=30:40 --pair-filter=both --cut=0 bwa-mem-fastq1_assimetric_fq_gz.fq.gz bwa-mem-fastq2_assimetric_fq_gz.fq.gz
        
        Processing reads on 1 core in paired-end mode ...
        Finished in 0.01 s (129 µs/read; 0.46 M reads/minute).

        === Summary ===

        Total read pairs processed:                 99
        Read 1 with adapter:                       2 (2.0%)
        Read 2 with adapter:                       4 (4.0%)
        Pairs that were too short:                   3 (3.0%)
        Pairs written (passing filters):            96 (97.0%)

        Total basepairs processed:        48,291 bp
        Read 1:        24,147 bp
        Read 2:        24,144 bp
        Total written (filtered):         48,171 bp (99.8%)
        Read 1:        24,090 bp
        Read 2:        24,081 bp


**Info file**

The info file contains information about the found adapters. The output is a tab-separated text file. Each line corresponds to one read of the input file.

Columns contain the following data:

    * **1st**:   Read name
    * **2nd**:   Number of errors
    * **3rd**:   0-based start coordinate of the adapter match
    * **4th**:   0-based end coordinate of the adapter match
    * **5th**:   Sequence of the read to the left of the adapter match (can be empty)
    * **6th**:   Sequence of the read that was matched to the adapter
    * **7th**:   Sequence of the read to the right of the adapter match (can be empty)
    * **8th**:   Name of the found adapter
    * **9th**:   Quality values corresponding to sequence left of the adapter match (can be empty)
    * **10th**:  Quality values corresponding to sequence matched to the adapter (can be empty)
    * **11th**:  Quality values corresponding to sequence to the right of the adapter (can be empty)

The concatenation of columns 5-7 yields the full read sequence. Column 8 identifies the found adapter. Adapters without a name are numbered starting from 1. Fields 9-11 are empty if quality values are not available. Concatenating them yields the full sequence of quality values.

If no adapter was found, the format is as follows:

     #. Read name
     #. The value -1
     #. The read sequence
     #. Quality values

When parsing the file, be aware that additional columns may be added in the future. Note also that some fields can be empty, resulting in consecutive tabs within a line.

If the --times option is used and greater than 1, each read can appear more than once in the info file. There will be one line for each found adapter, all with identical read names. Only for the first of those lines will the concatenation of columns 5-7 be identical to the original read sequence (and accordingly for columns 9-11). For subsequent lines, the shown sequence are the ones that were used in subsequent rounds of adapter trimming, that is, they get successively shorter.


--------------------

**Rename Reads**

--------------------


The --rename option expects a template string such as {id} extra_info {adapter_name} as a parameter. It can contain regular text and placeholders that consist of a name enclosed in curly braces ({placeholdername}).

The read name will be set to the template string in which the placeholders are replaced with the actual values relevant for the current read.

The following placeholders are currently available for single-end reads:

        * {header} – the full, unchanged header
        * {id} – the read ID, that is, the part of the header before the first whitespace
        * {comment} – the part of the header after the whitespace following the ID
        * {adapter_name} – the name of adapter that was found in this read or no_adapter if there was none adapter match. If you use --times to do multiple rounds of adapter matching, this is the name of the last found adapter.
        * {match_sequence} – the sequence of the read that matched the adapter (including errors). If there was no adapter match, this is set to an empty string. If you use a linked adapter, this is to the two matching strings, separated by a comma.
        * {cut_prefix} – the prefix removed by the --cut (or -u) option (that is, when used with a positive length argument)
        * {cut_suffix} – the suffix removed by the --cut (or -u) option (that is, when used with a negative length argument)
        * {rc} – this is replaced with the string rc if the read was reverse complemented. This only applies when reverse complementing was requested

If the --rename option is used with paired-end data, the template is applied separately to both R1 and R2. That is, for R1, the placeholders are replaced with values from R1, and for R2, the placeholders are replaced with values from R2. For example, {comment} becomes R1’s comment in R1 and it becomes R2’s comment in R2.

For paired-end data, the placeholder {rn} is available (“read number”), and it is replaced with 1 in R1 and with 2 in R2.

In addition, it is possible to write a placeholder as {r1.placeholdername} or {r2.placeholdername}, which always takes the replacement value from R1 or R2, respectively.
The {r1.placeholder} and {r2.placeholder} notation is available for all placeholders except {rn} and {id} because the read ID needs to be identical for both reads.

--------------------

**More Information**

--------------------

See the excellent `Cutadapt documentation`_

.. _Cutadapt: https://cutadapt.readthedocs.io/en/stable/
.. _`Cutadapt documentation`: https://cutadapt.readthedocs.io/en/latest/index.html
.. _`Illumina TruSeq Adapters De-Mystified`: http://tucf-genomics.tufts.edu/documents/protocols/TUCF_Understanding_Illumina_TruSeq_Adapters.pdf


--------------------

**Galaxy Wrapper Development**

--------------------

Author: Lance Parsons <lparsons@princeton.edu>

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