Commit a56f8228 authored by Chris Cheshire's avatar Chris Cheshire
Browse files

Update trimgalore

parent 446f5776
Loading
Loading
Loading
Loading
+68 −59
Original line number Diff line number Diff line
/*
 * -----------------------------------------------------
 *  Utility functions used in nf-core DSL2 module files
 * -----------------------------------------------------
 */
//
//  Utility functions used in nf-core DSL2 module files
//

/*
 * Extract name of software tool from process name using $task.process
 */
//
// Extract name of software tool from process name using $task.process
//
def getSoftwareName(task_process) {
    return task_process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()
}

/*
 * Function to initialise default values and to generate a Groovy Map of available options for nf-core modules
 */
//
// Function to initialise default values and to generate a Groovy Map of available options for nf-core modules
//
def initOptions(Map args) {
    def Map options = [:]
    options.args            = args.args ?: ''
    options.args2           = args.args2 ?: ''
    options.publish_by_id = args.publish_by_id ?: false
    options.args3           = args.args3 ?: ''
    options.publish_by_meta = args.publish_by_meta ?: []
    options.publish_dir     = args.publish_dir ?: ''
    options.publish_files   = args.publish_files
    options.suffix          = args.suffix ?: ''
    return options
}

/*
 * Tidy up and join elements of a list to return a path string
 */
//
// Tidy up and join elements of a list to return a path string
//
def getPathFromList(path_list) {
    def paths = path_list.findAll { item -> !item?.trim().isEmpty() }      // Remove empty entries
    paths     = paths.collect { it.trim().replaceAll("^[/]+|[/]+\$", "") } // Trim whitespace and trailing slashes
    return paths.join('/')
}

/*
 * Function to save/publish module results
 */
//
// Function to save/publish module results
//
def saveFiles(Map args) {
    if (!args.filename.endsWith('.version.txt')) {
        def ioptions  = initOptions(args.options)
        def path_list = [ ioptions.publish_dir ?: args.publish_dir ]
        if (ioptions.publish_by_id) {
            path_list.add(args.publish_id)
        if (ioptions.publish_by_meta) {
            def key_list = ioptions.publish_by_meta instanceof List ? ioptions.publish_by_meta : args.publish_by_meta
            for (key in key_list) {
                if (args.meta && key instanceof String) {
                    def path = key
                    if (args.meta.containsKey(key)) {
                        path = args.meta[key] instanceof Boolean ? "${key}_${args.meta[key]}".toString() : args.meta[key]
                    }
                    path = path instanceof String ? path : ''
                    path_list.add(path)
                }
            }
        }
        if (ioptions.publish_files instanceof Map) {
            for (ext in ioptions.publish_files) {
+12 −25
Original line number Diff line number Diff line
@@ -11,18 +11,18 @@ process TRIMGALORE {
        mode: params.publish_dir_mode,
        saveAs: { filename -> saveFiles(filename:filename, options:params.options, publish_dir:getSoftwareName(task.process), meta:meta, publish_by_meta:['id']) }

    conda (params.enable_conda ? "bioconda::trim-galore=0.6.6" : null)
    conda (params.enable_conda ? 'bioconda::trim-galore=0.6.7' : null)
    if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
        container "https://depot.galaxyproject.org/singularity/trim-galore:0.6.6--0"
        container "https://depot.galaxyproject.org/singularity/trim-galore:0.6.7--hdfd78af_0"
    } else {
        container "quay.io/biocontainers/trim-galore:0.6.6--0"
        container "quay.io/biocontainers/trim-galore:0.6.7--hdfd78af_0"
    }

    input:
    tuple val(meta), path(reads)

    output:
    tuple val(meta), path("*trimmed.fastq.gz") , emit: reads
    tuple val(meta), path("*.fq.gz")    , emit: reads
    tuple val(meta), path("*report.txt"), emit: log
    path "*.version.txt"                , emit: version

@@ -49,11 +49,7 @@ process TRIMGALORE {

    // Added soft-links to original fastqs for consistent naming in MultiQC
    def software = getSoftwareName(task.process)
    def suffix = options.suffix ? "${options.suffix}.trimmed" : ".trimmed"
    def prefix_1 = "${meta.id}_1${suffix}"
    def prefix_2 = "${meta.id}_2${suffix}"
    def prefix = "${meta.id}${suffix}"
    
    def prefix   = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
    if (meta.single_end) {
        """
        [ ! -f  ${prefix}.fastq.gz ] && ln -s $reads ${prefix}.fastq.gz
@@ -68,8 +64,8 @@ process TRIMGALORE {
        """
    } else {
        """
        [ ! -f  ${meta.id}_1.fastq.gz ] && ln -s ${reads[0]} ${meta.id}_1.fastq.gz
        [ ! -f  ${meta.id}_2.fastq.gz ] && ln -s ${reads[1]} ${meta.id}_2.fastq.gz
        [ ! -f  ${prefix}_1.fastq.gz ] && ln -s ${reads[0]} ${prefix}_1.fastq.gz
        [ ! -f  ${prefix}_2.fastq.gz ] && ln -s ${reads[1]} ${prefix}_2.fastq.gz
        trim_galore \\
            $options.args \\
            --cores $cores \\
@@ -79,18 +75,9 @@ process TRIMGALORE {
            $c_r2 \\
            $tpc_r1 \\
            $tpc_r2 \\
            ${meta.id}_1.fastq.gz \\
            ${meta.id}_2.fastq.gz
            ${prefix}_1.fastq.gz \\
            ${prefix}_2.fastq.gz
        echo \$(trim_galore --version 2>&1) | sed 's/^.*version //; s/Last.*\$//' > ${software}.version.txt

        mv ${meta.id}_1_val_1.fq.gz ${prefix_1}.fastq.gz
        mv ${meta.id}_2_val_2.fq.gz ${prefix_2}.fastq.gz

        [ ! -f  ${meta.id}_1_val_1_fastqc.html ] || mv ${meta.id}_1_val_1_fastqc.html ${meta.id}_1_fastqc${suffix}.html
        [ ! -f  ${meta.id}_2_val_2_fastqc.html ] || mv ${meta.id}_2_val_2_fastqc.html ${meta.id}_2_fastqc${suffix}.html

        [ ! -f  ${meta.id}_1_val_1_fastqc.zip ] || mv ${meta.id}_1_val_1_fastqc.zip ${meta.id}_1_fastqc${suffix}.zip
        [ ! -f  ${meta.id}_2_val_2_fastqc.zip ] || mv ${meta.id}_2_val_2_fastqc.zip ${meta.id}_2_fastqc${suffix}.zip
        """
    }
}
+0 −41
Original line number Diff line number Diff line
@@ -13,47 +13,6 @@ tools:
            MspI-digested RRBS-type (Reduced Representation Bisufite-Seq) libraries.
        homepage: https://www.bioinformatics.babraham.ac.uk/projects/trim_galore/
        documentation: https://github.com/FelixKrueger/TrimGalore/blob/master/Docs/Trim_Galore_User_Guide.md
params:
    - outdir:
        type: string
        description: |
            The pipeline's output directory. By default, the module will
            output files into `$params.outdir/<SOFTWARE>`
    - publish_dir_mode:
        type: string
        description: |
            Value for the Nextflow `publishDir` mode parameter.
            Available: symlink, rellink, link, copy, copyNoFollow, move.
    - enable_conda:
        type: boolean
        description: |
            Run the module with Conda using the software specified
            via the `conda` directive
    - singularity_pull_docker_container:
        type: boolean
        description: |
            Instead of directly downloading Singularity images for use with Singularity,
            force the workflow to pull and convert Docker containers instead.
    - clip_r1:
        type: integer
        description: |
            Instructs Trim Galore to remove bp from the 5' end of read 1
            (or single-end reads)
    - clip_r2:
        type: integer
        description: |
            Instructs Trim Galore to remove bp from the 5' end of read 2
            (paired-end reads only)
    - three_prime_clip_r1:
        type: integer
        description: |
            Instructs Trim Galore to remove bp from the 3' end of read 1
            AFTER adapter/quality trimming has been performed
    - three_prime_clip_r2:
        type: integer
        description: |
            Instructs Trim Galore to re move bp from the 3' end of read 2
            AFTER adapter/quality trimming has been performed
input:
    - meta:
        type: map