Skip to content
Snippets Groups Projects
Commit cb2f2556 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Fixed zipped input files

parent 6f39a8ed
No related branches found
No related tags found
No related merge requests found
...@@ -321,18 +321,21 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S ...@@ -321,18 +321,21 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
} }
def addGsnap(R1: File, R2: Option[File], output: File): File = { def addGsnap(R1: File, R2: Option[File], output: File): File = {
val zcatR1 = extractIfNeeded(R1, output.getParentFile)
val zcatR2 = if (paired) Some(extractIfNeeded(R2.get, output.getParentFile)) else None
val gsnapCommand = new Gsnap(this) val gsnapCommand = new Gsnap(this)
gsnapCommand.input = if (paired) List(R1, R2.get) else List(R1) gsnapCommand.input = if (paired) List(zcatR1._2, zcatR2.get._2) else List(zcatR1._2)
gsnapCommand.output = swapExt(output.getParent, output, ".bam", ".sam") gsnapCommand.output = swapExt(output.getParentFile, output, ".bam", ".sam")
gsnapCommand.isIntermediate = true
add(gsnapCommand)
val reorderSam = new ReorderSam(this) val reorderSam = new ReorderSam(this)
reorderSam.input = gsnapCommand.output reorderSam.input = gsnapCommand.output
reorderSam.output = swapExt(output.getParent, output, ".sorted.bam", ".reordered.bam") reorderSam.output = swapExt(output.getParentFile, output, ".sorted.bam", ".reordered.bam")
add(reorderSam)
addAddOrReplaceReadGroups(reorderSam.output, output) val ar = addAddOrReplaceReadGroups(reorderSam.output, output)
val pipe = new BiopetFifoPipe(this, (zcatR1._1 :: (if (paired) zcatR2.get._1 else None) ::
Some(gsnapCommand) :: Some(ar._1) :: Some(reorderSam) :: Nil).flatten)
add(pipe)
ar._2
} }
def addTophat(R1: File, R2: Option[File], output: File): File = { def addTophat(R1: File, R2: Option[File], output: File): File = {
...@@ -374,7 +377,9 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S ...@@ -374,7 +377,9 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
reorderSam.output = swapExt(output.getParent, output, ".merge.bam", ".reordered.bam") reorderSam.output = swapExt(output.getParent, output, ".merge.bam", ".reordered.bam")
add(reorderSam) add(reorderSam)
addAddOrReplaceReadGroups(reorderSam.output, output) val ar = addAddOrReplaceReadGroups(reorderSam.output, output)
add(ar._1)
ar._2
} }
/** Adds stampy jobs */ /** Adds stampy jobs */
def addStampy(R1: File, R2: Option[File], output: File): File = { def addStampy(R1: File, R2: Option[File], output: File): File = {
...@@ -405,31 +410,49 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S ...@@ -405,31 +410,49 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
/** Adds bowtie jobs */ /** Adds bowtie jobs */
def addBowtie(R1: File, R2: Option[File], output: File): File = { def addBowtie(R1: File, R2: Option[File], output: File): File = {
val zcatR1 = extractIfNeeded(R1, output.getParentFile)
val zcatR2 = if (paired) Some(extractIfNeeded(R2.get, output.getParentFile)) else None
zcatR1._1.foreach(add(_))
zcatR2.foreach(_._1.foreach(add(_)))
val bowtie = new Bowtie(this) val bowtie = new Bowtie(this)
bowtie.R1 = R1 bowtie.R1 = zcatR1._2
if (paired) bowtie.R2 = R2 if (paired) bowtie.R2 = Some(zcatR2.get._2)
bowtie.output = this.swapExt(output.getParent, output, ".bam", ".sam") bowtie.output = this.swapExt(output.getParentFile, output, ".bam", ".sam")
bowtie.isIntermediate = true bowtie.isIntermediate = true
add(bowtie) val ar = addAddOrReplaceReadGroups(bowtie.output, output)
addAddOrReplaceReadGroups(bowtie.output, output) val pipe = new BiopetFifoPipe(this, (Some(bowtie) :: Some(ar._1) :: Nil).flatten)
add(pipe)
ar._2
} }
/** Adds Star jobs */ /** Adds Star jobs */
def addStar(R1: File, R2: Option[File], output: File): File = { def addStar(R1: File, R2: Option[File], output: File): File = {
val starCommand = Star(this, R1, R2, outputDir, isIntermediate = true) val zcatR1 = extractIfNeeded(R1, output.getParentFile)
add(starCommand) val zcatR2 = if (paired) Some(extractIfNeeded(R2.get, output.getParentFile)) else None
addAddOrReplaceReadGroups(starCommand.outputSam, output) val starCommand = Star(this, zcatR1._2, zcatR2.map(_._2), outputDir, isIntermediate = true)
val ar = addAddOrReplaceReadGroups(starCommand.outputSam, output)
val pipe = new BiopetFifoPipe(this, (zcatR1._1 :: (if (paired) zcatR2.get._1 else None) ::
Some(starCommand) :: Some(ar._1) :: Nil).flatten)
add(pipe)
ar._2
} }
/** Adds Start 2 pass jobs */ /** Adds Start 2 pass jobs */
def addStar2pass(R1: File, R2: Option[File], output: File): File = { def addStar2pass(R1: File, R2: Option[File], output: File): File = {
val starCommand = Star._2pass(this, R1, R2, outputDir, isIntermediate = true) val zcatR1 = extractIfNeeded(R1, output.getParentFile)
val zcatR2 = if (paired) Some(extractIfNeeded(R2.get, output.getParentFile)) else None
zcatR1._1.foreach(add(_))
zcatR2.foreach(_._1.foreach(add(_)))
val starCommand = Star._2pass(this, zcatR1._2, zcatR2.map(_._2), outputDir, isIntermediate = true)
addAll(starCommand._2) addAll(starCommand._2)
addAddOrReplaceReadGroups(starCommand._1, output) val ar = addAddOrReplaceReadGroups(starCommand._1, output)
add(ar._1)
ar._2
} }
/** Adds AddOrReplaceReadGroups */ /** Adds AddOrReplaceReadGroups */
def addAddOrReplaceReadGroups(input: File, output: File): File = { def addAddOrReplaceReadGroups(input: File, output: File): (AddOrReplaceReadGroups, File) = {
val addOrReplaceReadGroups = AddOrReplaceReadGroups(this, input, output) val addOrReplaceReadGroups = AddOrReplaceReadGroups(this, input, output)
addOrReplaceReadGroups.createIndex = true addOrReplaceReadGroups.createIndex = true
...@@ -441,9 +464,8 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S ...@@ -441,9 +464,8 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
if (readgroupSequencingCenter.isDefined) addOrReplaceReadGroups.RGCN = readgroupSequencingCenter.get if (readgroupSequencingCenter.isDefined) addOrReplaceReadGroups.RGCN = readgroupSequencingCenter.get
if (readgroupDescription.isDefined) addOrReplaceReadGroups.RGDS = readgroupDescription.get if (readgroupDescription.isDefined) addOrReplaceReadGroups.RGDS = readgroupDescription.get
if (!skipMarkduplicates) addOrReplaceReadGroups.isIntermediate = true if (!skipMarkduplicates) addOrReplaceReadGroups.isIntermediate = true
add(addOrReplaceReadGroups)
addOrReplaceReadGroups.output (addOrReplaceReadGroups, addOrReplaceReadGroups.output)
} }
/** Returns readgroup for bwa */ /** Returns readgroup for bwa */
...@@ -468,22 +490,18 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S ...@@ -468,22 +490,18 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
* @param runDir directory to extract when needed * @param runDir directory to extract when needed
* @return returns extracted file * @return returns extracted file
*/ */
def extractIfNeeded(file: File, runDir: File): File = { def extractIfNeeded(file: File, runDir: File): (Option[BiopetCommandLineFunction], File) = {
if (file == null) file require(file != null)
else if (file.getName.endsWith(".gz") || file.getName.endsWith(".gzip")) { if (file.getName.endsWith(".gz") || file.getName.endsWith(".gzip")) {
var newFile: File = swapExt(runDir, file, ".gz", "") var newFile: File = swapExt(runDir, file, ".gz", "")
if (file.getName.endsWith(".gzip")) newFile = swapExt(runDir, file, ".gzip", "") if (file.getName.endsWith(".gzip")) newFile = swapExt(runDir, file, ".gzip", "")
val zcatCommand = Zcat(this, file, newFile) val zcatCommand = Zcat(this, file, newFile)
zcatCommand.isIntermediate = true (Some(zcatCommand), newFile)
add(zcatCommand)
newFile
} else if (file.getName.endsWith(".bz2")) { } else if (file.getName.endsWith(".bz2")) {
val newFile = swapExt(runDir, file, ".bz2", "") val newFile = swapExt(runDir, file, ".bz2", "")
val pbzip2 = Pbzip2(this, file, newFile) val pbzip2 = Pbzip2(this, file, newFile)
pbzip2.isIntermediate = true (Some(pbzip2), newFile)
add(pbzip2) } else (None, file)
newFile
} else file
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment