Commit 34f65445 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Moved aligners to functions and added Bowtie

parent 81fd15f8
package nl.lumc.sasc.biopet.extensions.aligners
import nl.lumc.sasc.biopet.core.BiopetCommandLineFunction
import nl.lumc.sasc.biopet.core.config.Configurable
import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
import java.io.File
class Bowtie(val root: Configurable) extends BiopetCommandLineFunction {
@Input(doc = "Fastq file R1", shortName = "R1")
var R1: File = _
@Input(doc = "Fastq file R2", shortName = "R2", required = false)
var R2: File = _
@Input(doc = "The reference file for the bam files.", shortName = "R")
var reference: File = config("reference", required = true)
@Output(doc = "Output file SAM", shortName = "output")
var output: File = _
executable = config("exe", default = "bowtie", freeVar = false)
override val versionRegex = """Version: (.*)""".r
override val versionExitcode = List(0, 1)
override def versionCommand = executable + " --version"
override val defaultVmem = "6G"
override val defaultThreads = 8
var sam: Boolean = config("sam", default = true)
var sam_RG: String = _
def cmdLine = {
required(executable) +
optional("--threads", nCoresRequest) +
conditional(sam, "--sam") +
required("--sam-RG", sam_RG) +
required(reference) +
required(R1) +
optional(R2) +
" > " + required(output)
}
}
\ No newline at end of file
......@@ -59,10 +59,10 @@ class AddOrReplaceReadGroups(val root: Configurable) extends Picard {
}
object AddOrReplaceReadGroups {
def apply(root: Configurable, input: File, outputDir: String, sortOrder: String = null): AddOrReplaceReadGroups = {
def apply(root: Configurable, input: File, output: File, sortOrder: String = null): AddOrReplaceReadGroups = {
val addOrReplaceReadGroups = new AddOrReplaceReadGroups(root)
addOrReplaceReadGroups.input = input
addOrReplaceReadGroups.output = new File(outputDir, input.getName.stripSuffix(".bam").stripSuffix(".sam") + ".sorted.bam")
addOrReplaceReadGroups.output = output
if (sortOrder == null) addOrReplaceReadGroups.sortOrder = "coordinate"
else addOrReplaceReadGroups.sortOrder = sortOrder
return addOrReplaceReadGroups
......
......@@ -23,10 +23,10 @@ class SortSam(val root: Configurable) extends Picard {
}
object SortSam {
def apply(root: Configurable, input: File, outputDir: String, sortOrder: String = null): SortSam = {
def apply(root: Configurable, input: File, output: File, sortOrder: String = null): SortSam = {
val sortSam = new SortSam(root)
sortSam.input = input
sortSam.output = new File(outputDir, input.getName.stripSuffix(".bam").stripSuffix(".sam") + ".sorted.bam")
sortSam.output = output
if (sortOrder == null) sortSam.sortOrder = "coordinate"
else sortSam.sortOrder = sortOrder
return sortSam
......
......@@ -5,7 +5,7 @@ import java.io.File
import java.util.Date
import nl.lumc.sasc.biopet.core.{ BiopetQScript, PipelineCommand }
import nl.lumc.sasc.biopet.core.apps.FastqSplitter
import nl.lumc.sasc.biopet.extensions.aligners.{ Bwa, Star }
import nl.lumc.sasc.biopet.extensions.aligners.{ Bwa, Star , Bowtie}
import nl.lumc.sasc.biopet.extensions.picard.{MarkDuplicates, SortSam, MergeSamFiles, AddOrReplaceReadGroups}
import nl.lumc.sasc.biopet.pipelines.bammetrics.BamMetrics
import nl.lumc.sasc.biopet.pipelines.flexiprep.Flexiprep
......@@ -182,27 +182,15 @@ class Mapping(val root: Configurable) extends QScript with BiopetQScript {
fastq_R2_output :+= R2
}
if (aligner == "bwa") {
val bwaCommand = new Bwa(this)
bwaCommand.R1 = R1
if (paired) bwaCommand.R2 = R2
bwaCommand.deps = deps
bwaCommand.R = getReadGroup
bwaCommand.output = new File(chunkDir + outputName + ".sam")
add(bwaCommand, isIntermediate = true)
val sortSam = SortSam(this, bwaCommand.output, chunkDir)
if (chunking || !skipMarkduplicates) sortSam.isIntermediate = true
add(sortSam)
bamFiles :+= sortSam.output
} else if (aligner == "star") {
val starCommand = Star(this, R1, if (paired) R2 else null, outputDir, isIntermediate = true, deps = deps)
add(starCommand)
bamFiles :+= addAddOrReplaceReadGroups(starCommand.outputSam, chunkDir)
} else if (aligner == "star-2pass") {
val star2pass = Star._2pass(this, R1, if (paired) R2 else null, chunkDir, isIntermediate = true, deps = deps)
addAll(star2pass._2)
bamFiles :+= addAddOrReplaceReadGroups(star2pass._1, chunkDir)
} else throw new IllegalStateException("Option Alginer: '" + aligner + "' is not valid")
val outputBam = new File(chunkDir + outputName + ".bam")
bamFiles :+= outputBam
aligner match {
case "bwa" => addBwa(R1, R2, outputBam, deps)
case "bowtie" => addBowtie(R1, R2, outputBam, deps)
case "star" => addStar(R1, R2, outputBam, deps)
case "star-2pass" => addStar2pass(R1, R2, outputBam, deps)
case _ => throw new IllegalStateException("Option Alginer: '" + aligner + "' is not valid")
}
}
if (!skipFlexiprep) {
flexiprep.runFinalize(fastq_R1_output, fastq_R2_output)
......@@ -224,8 +212,48 @@ class Mapping(val root: Configurable) extends QScript with BiopetQScript {
outputFiles += ("finalBamFile" -> bamFile)
}
def addAddOrReplaceReadGroups(inputSam: File, outputDir: String): File = {
val addOrReplaceReadGroups = AddOrReplaceReadGroups(this, inputSam, outputDir)
def addBwa(R1:File, R2:File, output:File, deps:List[File]): File = {
val bwaCommand = new Bwa(this)
bwaCommand.R1 = R1
if (paired) bwaCommand.R2 = R2
bwaCommand.deps = deps
bwaCommand.R = getReadGroup
bwaCommand.output = this.swapExt(output.getParent, output, ".bam", ".sam")
add(bwaCommand, isIntermediate = true)
val sortSam = SortSam(this, bwaCommand.output, output)
if (chunking || !skipMarkduplicates) sortSam.isIntermediate = true
add(sortSam)
return sortSam.output
}
def addBowtie(R1:File, R2:File, output:File, deps:List[File]): File = {
val bowtie = new Bowtie(this)
bowtie.R1 = R1
if (paired) bowtie.R2 = R2
bowtie.deps = deps
bowtie.sam_RG = getReadGroup
bowtie.output = this.swapExt(output.getParent, output, ".bam", ".sam")
add(bowtie, isIntermediate = true)
val sortSam = SortSam(this, bowtie.output, output)
if (chunking || !skipMarkduplicates) sortSam.isIntermediate = true
add(sortSam)
return sortSam.output
}
def addStar(R1:File, R2:File, output:File, deps:List[File]): File = {
val starCommand = Star(this, R1, if (paired) R2 else null, outputDir, isIntermediate = true, deps = deps)
add(starCommand)
return addAddOrReplaceReadGroups(starCommand.outputSam, output)
}
def addStar2pass(R1:File, R2:File, output:File, deps:List[File]): File = {
val starCommand = Star._2pass(this, R1, if (paired) R2 else null, outputDir, isIntermediate = true, deps = deps)
addAll(starCommand._2)
return addAddOrReplaceReadGroups(starCommand._1, output)
}
def addAddOrReplaceReadGroups(input: File, output: File): File = {
val addOrReplaceReadGroups = AddOrReplaceReadGroups(this, input, output)
addOrReplaceReadGroups.createIndex = true
addOrReplaceReadGroups.RGID = RGID
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment