name: trimgalore
description: | 
  A wrapper tool around Cutadapt and FastQC to consistently apply quality and adapter trimming to FastQ files. 
keywords: ["trimming", "adapters"]
links:
  homepage: https://github.com/FelixKrueger/TrimGalore
  documentation: https://github.com/FelixKrueger/TrimGalore/blob/master/Docs/Trim_Galore_User_Guide.md
  repository: https://github.com/FelixKrueger/TrimGalore
license: GPL-3.0 
requirements:
  commands: [trim_galore]

argument_groups:
  - name: Input
    arguments:   
    - name: "--input"
      type: file
      description: Input files. Note that paired-end files need to be supplied in a pairwise fashion, e.g. file1_1.fq file1_2.fq SRR2_1.fq.gz SRR2_2.fq.gz
      required: true
      multiple: true
      example: sample1_r1.fq;sample1_r2.fq;sample2_r1.fq;sample2_r2.fq
  - name: Trimming options
    arguments: 
      - name: --quality
        alternatives: -q
        type: integer
        description: Trim low-quality ends (below the specified Phred score) from reads in addition to adapter removal. For RRBS samples, quality trimming will be performed first, and adapter trimming is carried in a second round. Other files are quality and adapter trimmed in a single pass. The algorithm is the same as the one used by BWA (Subtract INT from all qualities; compute partial sums from all indices to the end of the sequence; cut sequence at the index at which the sum is minimal). 
        example: 20
        required: false
      - name: --phred33
        type: boolean
        description: Instructs Cutadapt to use ASCII+33 quality scores as Phred scores (Sanger/Illumina 1.9+ encoding) for quality trimming. 
        required: false
      - name: --phred64
        type: boolean
        description: Instructs Cutadapt to use ASCII+64 quality scores as Phred scores (Illumina 1.5 encoding) for quality trimming.
        required: false
      - name: --fastqc
        type: boolean
        description: Run FastQC in the default mode on the FastQ file once trimming is complete.
        required: false
      - name: --fastqc_args
        type: string
        description: Passes extra arguments to FastQC. If more than one argument is to be passed to FastQC they must be in the form "arg1 arg2 ...". Passing extra arguments will automatically invoke FastQC, so --fastqc does not have to be specified separately.
        required: false
        example: "--nogroup --outdir /home/"
      - name: --adapter
        alternatives: -a
        type: string
        description: |
          Adapter sequence to be trimmed. If not specified explicitly, Trim Galore will try to auto-detect whether the Illumina universal, Nextera transposase or Illumina small RNA adapter sequence was used. A single base may also be given as e.g. -a A{10}, to be expanded to -a AAAAAAAAAA. 
          At a special request, multiple adapters can also be specified like so: 
            -a  " AGCTCCCG -a TTTCATTATAT -a TTTATTCGGATTTAT" -a2 " AGCTAGCG -a TCTCTTATAT -a TTTCGGATTTAT", 
          or so:
            -a "file:../multiple_adapters.fa" -a2 "file:../different_adapters.fa"
          Potentially in conjucntion with the parameter "-n 3" to trim all adapters. 
                example: 20
        required: false
        example: AGCTCCCG
      - name: --adapter2 
        alternatives: -a2
        type: string
        description: Optional adapter sequence to be trimmed off read 2 of paired-end files. This option requires '--paired' to be specified as well. If the libraries to be trimmed are smallRNA then a2 will be set to the Illumina small RNA 5' adapter automatically (GATCGTCGGACT). A single base may also be given as e.g. -a2 A{10}, to be expanded to -a2 AAAAAAAAAA.
        required: false
        example: AGCTCCCG
      - name: --illumina
        type: boolean
        description: Adapter sequence to be trimmed is the first 13bp of the Illumina universal adapter 'AGATCGGAAGAGC' instead of the default auto-detection of adapter sequence.
        required: false
      - name: --stranded_illumina 
        type: boolean
        description: Adapter sequence to be trimmed is the first 13bp of the Illumina stranded mRNA or Total RNA adapter 'ACTGTCTCTTATA' instead of the default auto-detection of adapter sequence. 
        required: false
      - name: --nextera
        type: boolean
        description: Adapter sequence to be trimmed is the first 12bp of the Nextera adapter 'CTGTCTCTTATA' instead of the default auto-detection of adapter sequence.
        required: false
      - name: --small_rna 
        type: boolean
        description: Adapter sequence to be trimmed is the first 12bp of the Illumina Small RNA 3' Adapter 'TGGAATTCTCGG' instead of the default auto-detection of adapter sequence. Selecting to trim smallRNA adapters will also lower the --length value to 18bp. If the smallRNA libraries are paired-end then a automatically (GATCGTCGGACT) unless -a 2 had been defined explicitly.
      - name: --consider_already_trimmed 
        type: integer
        description: During adapter auto-detection, the limit set by this argument allows the user to set a threshold up to which the file is considered already adapter-trimmed. If no adapter sequence exceeds this threshold, no additional adapter trimming will be performed (technically, the adapter is set to '-a X'). Quality trimming is still performed as usual.
        required: false
      - name: --max_length 
        type: integer
        description: Discard reads that are longer than the specified value after trimming. This is only advised for smallRNA sequencing to remove non-small RNA sequences.
        required: false
      - name: --stringency 
        type: integer
        description: Overlap with adapter sequence required to trim a sequence. Defaults to a very stringent setting of 1, i.e. even a single bp of overlapping sequence will be trimmed off from the 3' end of any read.
        required: false
        example: 1
      - name: --error_rate
        alternatives: -e 
        type: double
        description: Maximum allowed error rate (no. of errors divided by the length of the matching region)
        required: false
        example: 0.1
      - name: --gzip
        type: boolean
        description: Compress the output file with GZIP. If the input files are GZIP-compressed the output files will automatically be GZIP compressed as well. As of v0.2.8 the compression will take place on the fly.
        required: false
      - name: --dont_gzip 
        type: boolean
        description: Output files won't be compressed with GZIP. This option overrides --gzip.
        required: false
      - name: --length 
        type: integer 
        description: Discard reads that became shorter than the specified length because of either quality or adapter trimming. A value of '0' effectively disables this behaviour. For paired-end files, both reads of a read-pair need to be longer than the specified length to be printed out to validated paired-end files. If only one read became too short there is the possibility of keeping such unpaired single-end reads using the --retain_unpaired option.
        required: false
        example: 20 
      - name: --max_n 
        type: integer
        description: The total number of Ns a read may contain before it will be removed altogether.In a paired-end setting, either read exceeding this limit will result in the entire pair being removed from the trimmed output files. If COUNT is a number between 0 and 1, it is interpreted as a fraction of the read length.
        required: false
      - name: --trim_n
        type: boolean
        description: Removes Ns from either side of the read. This option does currently not work in RRBS mode.
        required: false
      - name: --no_report_file
        type: boolean
        description: If specified no report file will be generated.
        required: false
      - name: --suppress_warn
        type: boolean
        description: If specified any output to STDOUT or STDERR will be suppressed.
        required: false
      - name: --clip_R1
        type: integer
        description: Instructs TrimGalore to remove given number of bp from the 5' end of read 1 (or single-end reads). This may be useful if the qualities were very poor, or if there is some sort of unwanted bias at the 5' end. 
        required: false
      - name: --clip_R2 
        type: integer
        description: Instructs TrimGalore to remove given number bp from the 5' end of read 2 (paired-end reads only). This may be useful if the qualities were very poor, or if there is some sort of unwanted bias at the 5' end. For paired-end BS-Seq, it is recommended to remove the first few bp because the end-repair reaction may introduce a bias towards low methylation. 
        required: false
      - name: --three_prime_clip_R1 
        type: integer
        description: Instructs Trim Galore to remove spacified number of bp from the 3' end of read 1 (or single-end reads) AFTER adapter/quality trimming has been performed. This may remove some  bias from the 3' end that is not directly related to adapter sequence or basecall quality.
        required: false
      - name: --three_prime_clip_R2 
        type: integer
        description: Instructs Trim Galore to remove <int> bp from the 3' end of read 2 AFTER adapter/quality trimming has been performed. This may remove some unwanted bias from the 3' end that is not directly related to adapter sequence or basecall quality.
        required: false
      - name: --nextseq 
        type: integer 
        description: This enables the option '--nextseq-trim=3'CUTOFF' within Cutadapt, which will set a quality cutoff (that is normally given with -q instead), but qualities of G bases are ignored. This trimming is in common for the NextSeq- and NovaSeq-platforms, where basecalls without any signal are called as high-quality G bases. This is mutually exlusive with '-q INT'.
        required: false
      - name: --basename
        type: string
        description: Use specified name (PREFERRED_NAME) as the basename for output files, instead of deriving the filenames from the input files. Single-end data would be called PREFERRED_NAME_trimmed.fq(.gz), or PREFERRED_NAME_val_1.fq(.gz) and PREFERRED_NAME_val_2.fq(.gz) for paired-end data. --basename only works when 1 file (single-end) or 2 files (paired-end) are specified, but not for longer lists.
        required: false
      - name: --cores
        alternatives: -j
        type: integer
        description: Number of cores to be used for trimming
        required: false
        example: 1
  - name: Specific trimming options without adapter/quality trimming
    arguments: 
      - name: --hardtrim5 
        type: integer
        description: Instead of performing adapter-/quality trimming, this option will simply hard-trim sequences to <int> bp at the 5'-end. Once hard-trimming of files is complete, Trim Galore will exit. Hard-trimmed output files will end in .<int>_5prime.fq(.gz). 
        required: false
      - name: --hardtrim3 
        type: integer
        description: Instead of performing adapter-/quality trimming, this option will simply hard-trim sequences to <int> bp at the 3'-end. Once hard-trimming of files is complete, Trim Galore will exit. Hard-trimmed output files will end in .<int>_3prime.fq(.gz). 
        required: false
      - name: --clock
        type: boolean
        description: In this mode, reads are trimmed in a specific way that is currently used for the Mouse Epigenetic Clock.
        required: false
      - name: --polyA
        type: boolean
        description: This is a new, still experimental, trimming mode to identify and remove poly-A tails from sequences. When --polyA is selected, Trim Galore attempts to identify from the first supplied sample whether sequences contain more often a stretch of either 'AAAAAAAAAA' or 'TTTTTTTTTT'. This determines if Read 1 of a paired-end end file, or single-end files, are trimmed for PolyA or PolyT. In case of paired-end sequencing, Read2 is trimmed for the complementary base from the start of the reads. The auto-detection uses a default of A{20} for Read1 (3'-end trimming) and T{150} for Read2 (5'-end trimming). These values may be changed manually using the options -a and -a2. In addition to trimming the sequences, white spaces are replaced with _ and it records in the read ID how many bases were trimmed so it can later be used to identify PolyA trimmed sequences. This is currently done by writing tags to both the start ("32:A:") and end ("_PolyA:32") of the reads. The poly-A trimming mode expects that sequences were both adapter and quality  before looking for Poly-A tails, and it is the user's responsibility to carry out an initial round of trimming. 
        required: false
      - name: --implicon    
        type: boolean
        description: | 
          This is a special mode of operation for paired-end data, such as required for the IMPLICON method, where a UMI sequence is getting transferred from the start of Read 2 to the readID of both reads. Following this, Trim Galore will exit. In it's current implementation, the UMI carrying reads come in the following format
            Read 1  5' FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 3'
            Read 2  3' UUUUUUUUFFFFFFFFFFFFFFFFFFFFFFFFFFFF 5'
          Where UUUUUUUU is a random 8-mer unique molecular identifier (UMI) and FFFFFFF... is the actual fragment to be sequenced. The UMI of Read 2 (R2) is written into the read ID of both reads and removed from the actual sequence.
        required: false
  - name: RRBS-specific options
    arguments: 
      - name: --rrbs 
        type: boolean
        description: Specifies that the input file was an MspI digested RRBS sample (recognition site is CCGG). Single-end or Read 1 sequences (paired-end) which were adapter-trimmed will have a further 2 bp removed from their 3' end. Sequences which were merely trimmed because of poor quality will not be shortened further. Read 2 of paired-end libraries will in addition have the first 2 bp removed from the 5' end (by setting '--clip_r2 2'). This is to avoid using artificial methylation calls from the filled-in cytosine positions close to the 3' MspI site in sequenced fragments. This option is not recommended for users of the Tecan Ovation RRBS Methyl-Seq with TrueMethyl oxBS 1-16 kit (see below).
        required: false
      - name: --non_directional
        type: boolean
        description: Selecting this option for non-directional RRBS libraries will screen quality-trimmed sequences for 'CAA' or 'CGA' at the start of the read and, if found, removes the first two basepairs. Like with the option '--rrbs' this avoids using cytosine positions that were filled-in during the end-repair step. '--non_directional' requires '--rrbs' to be specified as well. Note that this option does not set '--clip_r2 2' in paired-end mode.
        required: false
      - name: --keep 
        type: boolean
        description: Keep the quality trimmed intermediate file. 
        required: false
  - name: Paired-end specific options
    arguments: 
      - name: --paired 
        type: boolean
        description: This option performs length trimming of quality/adapter/RRBS trimmed reads for paired-end files. To pass the validation test, both sequences of a sequence pair are required to have a certain minimum length which is governed by the option --length (see above). If only one read passes this length threshold the other read can be rescued (see option --retain_unpaired). Using this option lets you discard too short read pairs without disturbing the sequence-by-sequence order of FastQ files which is required by many aligners. Trim Galore expects paired-end files to be supplied in a pairwise fashion, e.g. file1_1.fq file1_2.fq SRR2_1.fq.gz SRR2_2.fq.gz ... .
        required: false
      - name: --retain_unpaired  
        type: boolean
        description: If only one of the two paired-end reads became too short, the longer read will be written to either '.unpaired_1.fq' or '.unpaired_2.fq' output files. The length cutoff for unpaired single-end reads is governed by the parameters -r1/--length_1 and -r2/--length_2. 
        required: false
      - name: --length_1
        alternatives: -r1
        type: integer 
        description: Unpaired single-end read length cutoff needed for read 1 to be written to '.unpaired_1.fq' output file. These reads may be mapped in single-end mode.
        example: 35 
        required: false
      - name: --length_2
        alternatives: -r2
        type: integer 
        description: Unpaired single-end read length cutoff needed for read 2 to be written to '.unpaired_2.fq' output file. These reads may be mapped in single-end mode.
        required: false
        example: 35   
  - name: Output
    arguments:
      - name: --output_dir
        alternatives: -o
        type: file
        description: If specified all output will be written to this directory instead of the current directory. 
        direction: output
        required: false
        default: trimmed_output
      - name: --trimmed_r1
        type: file
        required: false
        description: Output file for read 1. Only works when 1 file (single-end) or 2 files (paired-end) are specified, but not for longer lists.
        direction: output
        example: read_1.fastq
      - name: --trimmed_r2
        type: file
        required: false
        description: Output file for read 2. Only works when 1 file (single-end) or 2 files (paired-end) are specified, but not for longer lists.
        direction: output
        example: read_2.fastq
      - name: --trimming_report_r1
        type: file
        required: false
        description: Trimming report for read 1. Only works when 1 file (single-end) or 2 files (paired-end) are specified, but not for longer lists.
        direction: output
        example: read_1.trimming_report.txt
      - name: --trimming_report_r2
        type: file
        description: Trimming report for read 1. Only works when 1 file (single-end) or 2 files (paired-end) are specified, but not for longer lists.
        direction: output
        required: false
        example: read_2.trimming_report.txt
      - name: --trimmed_fastqc_html_1
        type: file
        required: false
        description: FastQC report for trimmed (single-end) reads (or read 1 for paired-end). Only works when 1 file (single-end) or 2 files (paired-end) are specified, but not for longer lists.
        direction: output
        example: read_1.fastqc.html
      - name: --trimmed_fastqc_html_2
        type: file
        description: FastQC report for trimmed reads (read2 for paired-end). Only works when 1 file (single-end) or 2 files (paired-end) are specified, but not for longer lists.
        direction: output
        required: false
        example: read_2.fastqc.html
      - name: --trimmed_fastqc_zip_1
        type: file
        required: false
        description: FastQC results for trimmed (single-end) reads (or read 1 for paired-end). Only works when 1 file (single-end) or 2 files (paired-end) are specified, but not for longer lists.
        direction: output
        example: read_1.fastqc.zip
      - name: --trimmed_fastqc_zip_2
        type: file
        description: FastQC results for trimmed reads (read2 for paired-end). Only works when 1 file (single-end) or 2 files (paired-end) are specified, but not for longer lists.
        direction: output
        required: false
        example: read_2.fastqc.zip
      - name: --unpaired_r1
        type: file
        required: false
        description: Output file for unpired read 1. Only works when 1 file (single-end) or 2 files (paired-end) are specified, but not for longer lists.
        direction: output
        example: unpaired_read_1.fastq
      - name: --unpaired_r2
        type: file
        required: false
        description: Output file for unpaired read 2. Only works when 1 file (single-end) or 2 files (paired-end) are specified, but not for longer lists.
        direction: output
        example: unpaired_read_2.fastq

resources:
  - type: bash_script
    path: script.sh

test_resources:
  - type: bash_script
    path: test.sh
    
engines:
- type: docker
  image: quay.io/biocontainers/trim-galore:0.6.9--hdfd78af_0
  setup:
    - type: docker
      run: |
        echo "TrimGalore: `trim_galore --version | sed -n 's/.*version\s\+\([0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/p'`" > /var/software_versions.txt

runners:
  - type: executable
  - type: nextflow