Skip to content
Snippets Groups Projects
bwa.wdl 3.26 KiB
Newer Older
Ruben Vorderman's avatar
Ruben Vorderman committed
version 1.0
pjvan_thof's avatar
pjvan_thof committed

ffinfo's avatar
ffinfo committed
import "common.wdl" as common
ffinfo's avatar
ffinfo committed

Ruben Vorderman's avatar
Ruben Vorderman committed
    input {
        String? preCommand
ffinfo's avatar
ffinfo committed
        FastqPair inputFastq
ffinfo's avatar
ffinfo committed
        BwaIndex bwaIndex
Ruben Vorderman's avatar
Ruben Vorderman committed
        String outputPath
        String? readgroup
Cats's avatar
Cats committed

ffinfo's avatar
ffinfo committed
        String? picardJar

Cats's avatar
Cats committed
        Int threads = 1
        Int memory = 8
ffinfo's avatar
ffinfo committed
        Int picardMemory = 4
Ruben Vorderman's avatar
Ruben Vorderman committed
    }
Ruben Vorderman's avatar
Ruben Vorderman committed

ffinfo's avatar
ffinfo committed
    String picardPrefix = if defined(picardJar)
ffinfo's avatar
ffinfo committed
        then "java -Xmx" + picardMemory + "G -jar " + picardJar
        else "picard -Xmx" + picardMemory + "G"

ffinfo's avatar
ffinfo committed
    # Post alt script from bwa
    String altCommand = if (defined(bwaIndex.altIndex)) then "| bwa-postalt " + bwaIndex.altIndex else ""

    # setNmMdAndUqTags is only required if alt sequences are added
    String setNmMdAndUqTagsCommand = picardPrefix + " SetNmMdAndUqTags " +
                                             " INPUT=/dev/stdin OUTPUT=" + outputPath +
                                             " CREATE_INDEX=true" +
                                             " R=" + bwaIndex.fastaFile

    String sortSamCommand = picardPrefix + " SortSam " +
ffinfo's avatar
ffinfo committed
                 " INPUT=/dev/stdin SORT_ORDER=coordinate " +
ffinfo's avatar
ffinfo committed
                 if(defined(bwaIndex.altIndex)) then " OUTPUT=/dev/stdout "
                 else " OUTPUT=" + outputPath + " CREATE_INDEX=true "
ffinfo's avatar
ffinfo committed

ffinfo's avatar
ffinfo committed
    String picardCommand = if (defined(bwaIndex.altIndex)) then sortSamCommand + " | " + setNmMdAndUqTagsCommand
    else sortSamCommand
ffinfo's avatar
ffinfo committed

ffinfo's avatar
ffinfo committed
    String readgroupArg = if (defined(readgroup)) then "-R '" + readgroup + "'" else ""

pjvan_thof's avatar
pjvan_thof committed
    command {
        set -e -o pipefail
Ruben Vorderman's avatar
Ruben Vorderman committed
        mkdir -p $(dirname ~{outputPath})
        ~{preCommand}
        bwa mem ~{"-t " + threads} \
ffinfo's avatar
ffinfo committed
        ~{readgroupArg} \
ffinfo's avatar
ffinfo committed
        ~{bwaIndex.fastaFile} \
ffinfo's avatar
ffinfo committed
        ~{inputFastq.R1} \
        ~{inputFastq.R2} \
ffinfo's avatar
ffinfo committed
        ~{altCommand} \
ffinfo's avatar
ffinfo committed
        | ~{picardCommand}
pjvan_thof's avatar
pjvan_thof committed
    }

    output {
ffinfo's avatar
ffinfo committed
        IndexedBamFile bamFile = object {
          file: outputPath,
          index: sub(outputPath, ".bam$", ".bai")
pjvan_thof's avatar
pjvan_thof committed
    }
Cats's avatar
Cats committed
    runtime{
Cats's avatar
Cats committed
        cpu: threads
ffinfo's avatar
ffinfo committed
        memory: memory + picardMemory + picardMemory
Cats's avatar
Cats committed
    }
pjvan_thof's avatar
pjvan_thof committed
}
Ruben Vorderman's avatar
Ruben Vorderman committed
    input {
        File fasta
        String? preCommand
        String? constructionAlgorithm
        Int? blockSize
        String? outputDir
    }

    String fastaFilename = basename(fasta)
    String outputFile = if (defined(outputDir)) then outputDir + "/" + fastaFilename else fasta

    command {
        set -e -o pipefail
Ruben Vorderman's avatar
Ruben Vorderman committed
        ~{"mkdir -p " + outputDir}
        ~{preCommand}
        if [[ ! '~{outputDir}' =  '' ]]
Ruben Vorderman's avatar
Ruben Vorderman committed
            ln -sf ~{fasta} ~{outputDir + "/"}~{fastaFilename}
        bwa index \
Ruben Vorderman's avatar
Ruben Vorderman committed
        ~{"-a " + constructionAlgorithm} \
        ~{"-b" + blockSize} \
        ~{outputFile}
ffinfo's avatar
ffinfo committed
        BwaIndex outputIndex = object {
            fastaFile: outputFile,
            indexFiles: [outputFile + ".bwt",outputFile + ".pac",outputFile + ".sa",outputFile + ".amb",outputFile + ".ann"]
ffinfo's avatar
ffinfo committed
        }
    parameter_meta {
        fasta: "Fasta file to be indexed"
        constructionAlgorithm: "-a STR    BWT construction algorithm: bwtsw, is or rb2 [auto]"
        blockSize: "-b INT    block size for the bwtsw algorithm (effective with -a bwtsw) [10000000]"
        outputDir: "index will be created in this output directory"
    }
}

ffinfo's avatar
ffinfo committed
struct BwaIndex {
    File fastaFile
    Array[File] indexFiles
ffinfo's avatar
ffinfo committed
    File? altIndex