Skip to content
Snippets Groups Projects
samtools.wdl 4.44 KiB
Newer Older
Ruben Vorderman's avatar
Ruben Vorderman committed
version 1.0
Cats's avatar
Cats committed

task BgzipAndIndex {
    input {
        File inputFile
        String outputDir
        String type = "vcf"
    }

    String outputGz = outputDir + "/" + basename(inputFile) + ".gz"

    command {
        bgzip -c ~{inputFile} > ~{outputGz}
        tabix ~{outputGz} -p ~{type}
    }

    output {
        File compressed = outputGz
        File index = outputGz + ".tbi"
    }
}

Ruben Vorderman's avatar
Ruben Vorderman committed
task Index {
    input {
        String? preCommand
        File bamFilePath
        String? bamIndexPath
    }
pjvan_thof's avatar
pjvan_thof committed
    command {
Peter van 't Hof's avatar
Peter van 't Hof committed
        set -e -o pipefail
Ruben Vorderman's avatar
Ruben Vorderman committed
        ~{preCommand}
        samtools index ~{bamFilePath} ~{bamIndexPath}
pjvan_thof's avatar
pjvan_thof committed
    }

    output {
        File indexFile = if defined(bamIndexPath)
            then select_first([bamIndexPath])
            else bamFilePath + ".bai"
pjvan_thof's avatar
pjvan_thof committed
task Merge {
Ruben Vorderman's avatar
Ruben Vorderman committed
    input {
        String? preCommand
        Array[File]+ bamFiles
        String outputBamPath
    }
pjvan_thof's avatar
pjvan_thof committed
    command {
Peter van 't Hof's avatar
Peter van 't Hof committed
        set -e -o pipefail
Ruben Vorderman's avatar
Ruben Vorderman committed
        ~{preCommand}
        samtools merge ~{outputBamPath} ~{sep=' ' bamFiles}
pjvan_thof's avatar
pjvan_thof committed
    }

    output {
pjvan_thof's avatar
pjvan_thof committed
        File outputBam = outputBamPath
pjvan_thof's avatar
pjvan_thof committed
    }
Peter van 't Hof's avatar
Peter van 't Hof committed
}

task Markdup {
Ruben Vorderman's avatar
Ruben Vorderman committed
    input {
        String? preCommand
        File inputBam
        String outputBamPath
    }
Peter van 't Hof's avatar
Peter van 't Hof committed

    command {
Peter van 't Hof's avatar
Peter van 't Hof committed
        set -e -o pipefail
Ruben Vorderman's avatar
Ruben Vorderman committed
        ~{preCommand}
        samtools markdup ~{inputBam} ~{outputBamPath}
Peter van 't Hof's avatar
Peter van 't Hof committed
    }

    output {
        File outputBam = outputBamPath
    }
}

task Flagstat {
Ruben Vorderman's avatar
Ruben Vorderman committed
    input {
        String? preCommand
        File inputBam
        String outputPath
    }
Peter van 't Hof's avatar
Peter van 't Hof committed

    command {
Peter van 't Hof's avatar
Peter van 't Hof committed
        set -e -o pipefail
Ruben Vorderman's avatar
Ruben Vorderman committed
        ~{preCommand}
        mkdir -p $(dirname ~{outputPath})
        samtools flagstat ~{inputBam} > ~{outputPath}
Peter van 't Hof's avatar
Peter van 't Hof committed
    }

    output {
        File flagstat = outputPath
    }
}
Ruben Vorderman's avatar
Ruben Vorderman committed

Ruben Vorderman's avatar
Ruben Vorderman committed
    input {
        String? preCommand
        File inputBam
        String outputRead1
        String? outputRead2
        String? outputRead0
        Int? includeFilter
        Int? excludeFilter
        Int? excludeSpecificFilter
        Boolean? appendReadNumber
        Boolean? outputQuality
        Int? compressionLevel
        Int threads = 1
        Int memory = 1
Ruben Vorderman's avatar
Ruben Vorderman committed
    }
Ruben Vorderman's avatar
Ruben Vorderman committed

    command {
Ruben Vorderman's avatar
Ruben Vorderman committed
        ~{preCommand}
Ruben Vorderman's avatar
Ruben Vorderman committed
        samtools fastq \
Ruben Vorderman's avatar
Ruben Vorderman committed
        ~{true="-1" false="-s" defined(outputRead2)} ~{outputRead1} \
        ~{"-2 " + outputRead2} \
        ~{"-0 " + outputRead0} \
        ~{"-f " + includeFilter} \
        ~{"-F " + excludeFilter} \
        ~{"-G " + excludeSpecificFilter} \
        ~{true="-N" false="-n" appendReadNumber} \
        ~{true="-O" false="" outputQuality} \
        ~{"-c " + compressionLevel} \
        ~{"--threads " + threads} \
Ruben Vorderman's avatar
Ruben Vorderman committed
        ~{inputBam}
Ruben Vorderman's avatar
Ruben Vorderman committed
    }
    output {
        File read1 = outputRead1
        File? read2 = outputRead2
        File? read0 = outputRead0
    }
Ruben Vorderman's avatar
Ruben Vorderman committed
    runtime {
        cpu: threads
        memory: memory
Ruben Vorderman's avatar
Ruben Vorderman committed
    }
Ruben Vorderman's avatar
Ruben Vorderman committed
    parameter_meta {
        preCommand: "A command that is run before the task. Can be used to activate environments"
        inputBam: "The bam file to process."
        outputRead1: "If only outputRead1 is given '-s' flag is assumed. Else '-1'."
        includeFilter: "Include reads with ALL of these flags. Corresponds to '-f'"
        excludeFilter: "Exclude reads with ONE OR MORE of these flags. Corresponds to '-F'"
        excludeSpecificFilter: "Exclude reads with ALL of these flags. Corresponds to '-G'"
        appendReadNumber: "Append /1 and /2 to the read name, or don't. Corresponds to '-n/N"

    }
}
task Tabix {
    input {
        String inputFile
        String type = "vcf"
    }

    command {
        tabix ~{inputFile} -p ~{type}
    }

    output {
        File index = inputFile + ".tbi"
    }
}

Ruben Vorderman's avatar
Ruben Vorderman committed
    input {
        String? preCommand
        File inFile
        File? referenceFasta
        String outputFileName
        Boolean? outputBam
        Boolean? uncompressedBamOutput
        Int? includeFilter
        Int? excludeFilter
        Int? excludeSpecificFilter
        Int threads = 1
        Int memory = 1
Ruben Vorderman's avatar
Ruben Vorderman committed
    }

    command {
Ruben Vorderman's avatar
Ruben Vorderman committed
        set -e -o pipefail
        ~{preCommand}
        samtools view \
        ~{"-T " + referenceFasta} \
        ~{"-o " + outputFileName} \
        ~{true="-b " false="" outputBam} \
        ~{true="-u " false="" uncompressedBamOutput} \
        ~{"-f " + includeFilter} \
        ~{"-F " + excludeFilter} \
        ~{"-G " + excludeSpecificFilter} \
Cats's avatar
Cats committed
        ~{"--threads " + (threads - 1)} \
Ruben Vorderman's avatar
Ruben Vorderman committed
        ~{inFile}

    output {
        File outputFile = outputFileName
    }
        cpu: threads
        memory: memory