Skip to content
Snippets Groups Projects
samtools.wdl 2.85 KiB
Newer Older
pjvan_thof's avatar
pjvan_thof committed
task Index {
Peter van 't Hof's avatar
Peter van 't Hof committed
    String? preCommand
Cats's avatar
Cats committed
    File bamFilePath
Cats's avatar
Cats committed
    String bamIndexPath
Cats's avatar
Cats committed

pjvan_thof's avatar
pjvan_thof committed
    command {
Peter van 't Hof's avatar
Peter van 't Hof committed
        set -e -o pipefail
        ${preCommand}
Cats's avatar
Cats committed
        samtools index ${bamFilePath} ${bamIndexPath}
pjvan_thof's avatar
pjvan_thof committed
    }

    output {
Cats's avatar
Cats committed
        File indexFile = bamIndexPath
pjvan_thof's avatar
pjvan_thof committed
task Merge {
Peter van 't Hof's avatar
Peter van 't Hof committed
    String? preCommand
pjvan_thof's avatar
pjvan_thof committed
    Array[File]+ bamFiles
pjvan_thof's avatar
pjvan_thof committed
    String outputBamPath

    command {
Peter van 't Hof's avatar
Peter van 't Hof committed
        set -e -o pipefail
        ${preCommand}
        if [ ${length(bamFiles)} -gt 1 ]
          then
            samtools merge ${outputBamPath} ${sep=' ' bamFiles}
          else
            ln -sf ${bamFiles} ${outputBamPath}
        fi
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 {
Peter van 't Hof's avatar
Peter van 't Hof committed
    String? preCommand
Peter van 't Hof's avatar
Peter van 't Hof committed
    File inputBam
    String outputBamPath

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

    output {
        File outputBam = outputBamPath
    }
}

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

    command {
Peter van 't Hof's avatar
Peter van 't Hof committed
        set -e -o pipefail
        ${preCommand}
Peter van 't Hof's avatar
Peter van 't Hof committed
        samtools flagstat ${inputBam} > ${outputPath}
    }

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

task fastq {
    String? preCommand
    File inputBam
    String outputRead1
    String? outputRead2
    String? outputRead0
    Int? includeFilter
    Int? excludeFilter
    Int? excludeSpecificFilter
    Boolean? appendReadNumber
    Boolean? outputQuality
    Int? compressionLevel
    Int? threads
    Int? memory
    Int totalThreads = select_first([threads, 1])

    command {
        ${preCommand}
        samtools fastq \
        ${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 " + totalThreads} \
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: totalThreads
        memory: select_first([memory, 1])
    }
    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"

    }
}