Commit 558d488a authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Convert R2 to Option[File]

parent a37cbb90
......@@ -113,10 +113,10 @@ object Star {
* @return Return Star
*
*/
def apply(configurable: Configurable, R1: File, R2: File, outputDir: File, isIntermediate: Boolean = false, deps: List[File] = Nil): Star = {
def apply(configurable: Configurable, R1: File, R2: Option[File], outputDir: File, isIntermediate: Boolean = false, deps: List[File] = Nil): Star = {
val star = new Star(configurable)
star.R1 = R1
if (R2 != null) star.R2 = R2
R2.foreach(R2 => star.R2 = R2)
star.outputDir = outputDir
star.isIntermediate = isIntermediate
star.deps = deps
......@@ -136,11 +136,11 @@ object Star {
*/
def _2pass(configurable: Configurable,
R1: File,
R2: File,
R2: Option[File],
outputDir: File,
isIntermediate: Boolean = false,
deps: List[File] = Nil): (File, List[Star]) = {
val starCommand_pass1 = Star(configurable, R1, if (R2 != null) R2 else null, new File(outputDir, "aln-pass1"))
val starCommand_pass1 = Star(configurable, R1, R2, new File(outputDir, "aln-pass1"))
starCommand_pass1.isIntermediate = isIntermediate
starCommand_pass1.deps = deps
starCommand_pass1.beforeGraph
......@@ -152,7 +152,7 @@ object Star {
starCommand_reindex.isIntermediate = isIntermediate
starCommand_reindex.beforeGraph
val starCommand_pass2 = Star(configurable, R1, if (R2 != null) R2 else null, new File(outputDir, "aln-pass2"))
val starCommand_pass2 = Star(configurable, R1, R2, new File(outputDir, "aln-pass2"))
starCommand_pass2.genomeDir = starCommand_reindex.outputDir
starCommand_pass2.isIntermediate = isIntermediate
starCommand_pass2.deps = deps
......
......@@ -95,7 +95,7 @@ class Flexiprep(val root: Configurable) extends QScript with SummaryQScript with
def biopetScript() {
runInitialJobs()
val out = if (paired) runTrimClip(outputFiles("fastq_input_R1"), outputFiles("fastq_input_R2"), outputDir)
val out = if (paired) runTrimClip(outputFiles("fastq_input_R1"), Some(outputFiles("fastq_input_R2")), outputDir)
else runTrimClip(outputFiles("fastq_input_R1"), outputDir)
val R1_files = for ((k, v) <- outputFiles if k.endsWith("output_R1")) yield v
......@@ -130,8 +130,8 @@ class Flexiprep(val root: Configurable) extends QScript with SummaryQScript with
* @param chunk
* @return
*/
def runTrimClip(R1_in: File, outDir: File, chunk: String): (File, File, List[File]) =
runTrimClip(R1_in, new File(""), outDir, chunk)
def runTrimClip(R1_in: File, outDir: File, chunk: String): (File, Option[File], List[File]) =
runTrimClip(R1_in, None, outDir, chunk)
/**
* Adds all chunkable jobs of flexiprep
......@@ -139,8 +139,8 @@ class Flexiprep(val root: Configurable) extends QScript with SummaryQScript with
* @param outDir
* @return
*/
def runTrimClip(R1_in: File, outDir: File): (File, File, List[File]) =
runTrimClip(R1_in, new File(""), outDir, "")
def runTrimClip(R1_in: File, outDir: File): (File, Option[File], List[File]) =
runTrimClip(R1_in, None, outDir, "")
/**
* Adds all chunkable jobs of flexiprep
......@@ -149,7 +149,7 @@ class Flexiprep(val root: Configurable) extends QScript with SummaryQScript with
* @param outDir
* @return
*/
def runTrimClip(R1_in: File, R2_in: File, outDir: File): (File, File, List[File]) =
def runTrimClip(R1_in: File, R2_in: Option[File], outDir: File): (File, Option[File], List[File]) =
runTrimClip(R1_in, R2_in, outDir, "")
/**
......@@ -160,14 +160,14 @@ class Flexiprep(val root: Configurable) extends QScript with SummaryQScript with
* @param chunkarg
* @return
*/
def runTrimClip(R1_in: File, R2_in: File, outDir: File, chunkarg: String): (File, File, List[File]) = {
def runTrimClip(R1_in: File, R2_in: Option[File], outDir: File, chunkarg: String): (File, Option[File], List[File]) = {
val chunk = if (chunkarg.isEmpty || chunkarg.endsWith("_")) chunkarg else chunkarg + "_"
var results: Map[String, File] = Map()
var R1: File = new File(R1_in)
var R2: File = if (paired) new File(R2_in) else null
var deps_R1: List[File] = R1 :: Nil
var deps_R2: List[File] = if (paired) R2 :: Nil else Nil
var R1 = R1_in
var R2 = R2_in
var deps_R1 = R1 :: Nil
var deps_R2 = if (paired) R2.get :: Nil else Nil
def deps: List[File] = deps_R1 ::: deps_R2
val seqtkSeq_R1 = SeqtkSeq(this, R1, swapExt(outDir, R1, R1_ext, ".sanger" + R1_ext), fastqc_R1)
......@@ -178,12 +178,12 @@ class Flexiprep(val root: Configurable) extends QScript with SummaryQScript with
deps_R1 ::= R1
if (paired) {
val seqtkSeq_R2 = SeqtkSeq(this, R2, swapExt(outDir, R2, R2_ext, ".sanger" + R2_ext), fastqc_R2)
val seqtkSeq_R2 = SeqtkSeq(this, R2.get, swapExt(outDir, R2.get, R2_ext, ".sanger" + R2_ext), fastqc_R2)
seqtkSeq_R2.isIntermediate = true
add(seqtkSeq_R2)
addSummarizable(seqtkSeq_R2, "seqtkSeq_R2")
R2 = seqtkSeq_R2.output
deps_R2 ::= R2
R2 = Some(seqtkSeq_R2.output)
deps_R2 ::= R2.get
}
val seqstat_R1 = Seqstat(this, R1, outDir)
......@@ -193,7 +193,7 @@ class Flexiprep(val root: Configurable) extends QScript with SummaryQScript with
addSummarizable(seqstat_R1, "seqstat_R1")
if (paired) {
val seqstat_R2 = Seqstat(this, R2, outDir)
val seqstat_R2 = Seqstat(this, R2.get, outDir)
seqstat_R2.isIntermediate = true
seqstat_R2.deps = deps_R2
add(seqstat_R2)
......@@ -213,31 +213,31 @@ class Flexiprep(val root: Configurable) extends QScript with SummaryQScript with
outputFiles += ("cutadapt_R1_stats" -> cutadapt_R1.stats_output)
if (paired) {
val cutadapt_R2 = Cutadapt(this, R2, swapExt(outDir, R2, R2_ext, ".clip" + R2_ext))
val cutadapt_R2 = Cutadapt(this, R2.get, swapExt(outDir, R2.get, R2_ext, ".clip" + R2_ext))
outputFiles += ("cutadapt_R2_stats" -> cutadapt_R2.stats_output)
cutadapt_R2.fastqc = fastqc_R2
cutadapt_R2.isIntermediate = true
cutadapt_R2.deps = deps_R2
add(cutadapt_R2)
addSummarizable(cutadapt_R2, "clipping_R2")
R2 = cutadapt_R2.fastq_output
deps_R2 ::= R2
R2 = Some(cutadapt_R2.fastq_output)
deps_R2 ::= R2.get
val fqSync = new FastqSync(this)
fqSync.refFastq = cutadapt_R1.fastq_input
fqSync.inputFastq1 = cutadapt_R1.fastq_output
fqSync.inputFastq2 = cutadapt_R2.fastq_output
fqSync.outputFastq1 = swapExt(outDir, R1, R1_ext, ".sync" + R1_ext)
fqSync.outputFastq2 = swapExt(outDir, R2, R2_ext, ".sync" + R2_ext)
fqSync.outputFastq2 = swapExt(outDir, R2.get, R2_ext, ".sync" + R2_ext)
fqSync.outputStats = swapExt(outDir, R1, R1_ext, ".sync.stats")
fqSync.deps :::= deps
add(fqSync)
addSummarizable(fqSync, "fastq_sync")
outputFiles += ("syncStats" -> fqSync.outputStats)
R1 = fqSync.outputFastq1
R2 = fqSync.outputFastq2
R2 = Some(fqSync.outputFastq2)
deps_R1 ::= R1
deps_R2 ::= R2
deps_R2 ::= R2.get
}
}
......@@ -246,9 +246,9 @@ class Flexiprep(val root: Configurable) extends QScript with SummaryQScript with
sickle.input_R1 = R1
sickle.output_R1 = swapExt(outDir, R1, R1_ext, ".trim" + R1_ext)
if (paired) {
sickle.input_R2 = R2
sickle.output_R2 = swapExt(outDir, R2, R2_ext, ".trim" + R2_ext)
sickle.output_singles = swapExt(outDir, R2, R2_ext, ".trim.singles" + R1_ext)
sickle.input_R2 = R2.get
sickle.output_R2 = swapExt(outDir, R2.get, R2_ext, ".trim" + R2_ext)
sickle.output_singles = swapExt(outDir, R2.get, R2_ext, ".trim.singles" + R1_ext)
}
sickle.output_stats = swapExt(outDir, R1, R1_ext, ".trim.stats")
sickle.deps = deps
......@@ -256,7 +256,7 @@ class Flexiprep(val root: Configurable) extends QScript with SummaryQScript with
add(sickle)
addSummarizable(sickle, "trimming")
R1 = sickle.output_R1
if (paired) R2 = sickle.output_R2
if (paired) R2 = Some(sickle.output_R2)
}
val seqstat_R1_after = Seqstat(this, R1, outDir)
......@@ -265,14 +265,14 @@ class Flexiprep(val root: Configurable) extends QScript with SummaryQScript with
addSummarizable(seqstat_R1_after, "seqstat_R1_after")
if (paired) {
val seqstat_R2_after = Seqstat(this, R2, outDir)
val seqstat_R2_after = Seqstat(this, R2.get, outDir)
seqstat_R2_after.deps = deps_R2
add(seqstat_R2_after)
addSummarizable(seqstat_R2_after, "seqstat_R2_after")
}
outputFiles += (chunk + "output_R1" -> R1)
if (paired) outputFiles += (chunk + "output_R2" -> R2)
if (paired) outputFiles += (chunk + "output_R2" -> R2.get)
return (R1, R2, deps)
}
......
......@@ -157,26 +157,27 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
var fastq_R1_output: List[File] = Nil
var fastq_R2_output: List[File] = Nil
def removeGz(file: String): String = {
if (file.endsWith(".gz")) file.substring(0, file.lastIndexOf(".gz"))
else if (file.endsWith(".gzip")) file.substring(0, file.lastIndexOf(".gzip"))
def removeGz(file: File): File = {
val absPath = file.getAbsolutePath
if (absPath.endsWith(".gz")) new File(absPath.substring(0, absPath.lastIndexOf(".gz")))
else if (absPath.endsWith(".gzip")) new File(absPath.substring(0, absPath.lastIndexOf(".gzip")))
else file
}
var chunks: Map[File, (String, String)] = Map()
if (chunking) for (t <- 1 to numberChunks.getOrElse(1)) {
val chunkDir = new File(outputDir, "chunks" + File.separator + t)
chunks += (chunkDir -> (removeGz(chunkDir + input_R1.getName),
if (paired) removeGz(chunkDir + input_R2.get.getName) else ""))
val chunks: Map[File, (File, Option[File])] = {
if (chunking) {
(for (t <- 1 to numberChunks.getOrElse(1)) yield {
val chunkDir = new File(outputDir, "chunks" + File.separator + t)
(chunkDir -> (removeGz(new File(chunkDir, input_R1.getName)),
if (paired) Some(removeGz(new File(chunkDir, input_R2.get.getName))) else None))
}).toMap
} else if (skipFlexiprep) {
Map(outputDir -> (
extractIfNeeded(input_R1, flexiprep.outputDir),
if (paired) Some(extractIfNeeded(input_R2.get, outputDir)) else None)
)
} else Map(outputDir -> (input_R1, input_R2))
}
else if (skipFlexiprep) {
chunks += (outputDir -> (
extractIfNeeded(input_R1, flexiprep.outputDir),
if (paired) extractIfNeeded(input_R2.get, outputDir) else "")
)
} else chunks += (outputDir -> (
flexiprep.outputFiles("fastq_input_R1"),
if (paired) flexiprep.outputFiles("fastq_input_R2") else "")
)
if (chunking) {
val fastSplitter_R1 = new FastqSplitter(this)
......@@ -188,7 +189,7 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
if (paired) {
val fastSplitter_R2 = new FastqSplitter(this)
fastSplitter_R2.input = input_R2.get
for ((chunkDir, fastqfile) <- chunks) fastSplitter_R2.output :+= fastqfile._2
for ((chunkDir, fastqfile) <- chunks) fastSplitter_R2.output :+= fastqfile._2.get
fastSplitter_R2.isIntermediate = true
add(fastSplitter_R2)
}
......@@ -205,7 +206,7 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
if (paired) R2 = flexiout._2
deps = flexiout._3
fastq_R1_output :+= R1
fastq_R2_output :+= R2
R2.foreach(R2 => fastq_R2_output :+= R2)
}
val outputBam = new File(chunkDir, outputName + ".bam")
......@@ -267,7 +268,7 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
* @param deps
* @return
*/
def addBwaAln(R1: File, R2: File, output: File, deps: List[File]): File = {
def addBwaAln(R1: File, R2: Option[File], output: File, deps: List[File]): File = {
val bwaAlnR1 = new BwaAln(this)
bwaAlnR1.fastq = R1
bwaAlnR1.deps = deps
......@@ -277,7 +278,7 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
val samFile: File = if (paired) {
val bwaAlnR2 = new BwaAln(this)
bwaAlnR2.fastq = R2
bwaAlnR2.fastq = R2.get
bwaAlnR2.deps = deps
bwaAlnR2.output = swapExt(output.getParent, output, ".bam", ".R2.sai")
bwaAlnR2.isIntermediate = true
......@@ -285,7 +286,7 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
val bwaSampe = new BwaSampe(this)
bwaSampe.fastqR1 = R1
bwaSampe.fastqR2 = R2
bwaSampe.fastqR2 = R2.get
bwaSampe.saiR1 = bwaAlnR1.output
bwaSampe.saiR2 = bwaAlnR2.output
bwaSampe.r = getReadGroupBwa
......@@ -320,10 +321,10 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
* @param deps
* @return
*/
def addBwaMem(R1: File, R2: File, output: File, deps: List[File]): File = {
def addBwaMem(R1: File, R2: Option[File], output: File, deps: List[File]): File = {
val bwaCommand = new BwaMem(this)
bwaCommand.R1 = R1
if (paired) bwaCommand.R2 = R2
if (paired) bwaCommand.R2 = R2.get
bwaCommand.deps = deps
bwaCommand.R = Some(getReadGroupBwa)
bwaCommand.output = swapExt(output.getParent, output, ".bam", ".sam")
......@@ -335,10 +336,9 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
sortSam.output
}
def addGsnap(R1: File, R2: File, output: File, deps: List[File]): File = {
def addGsnap(R1: File, R2: Option[File], output: File, deps: List[File]): File = {
val gsnapCommand = new Gsnap(this)
// FIXME: ideally we should only check for null ~ but apparently it's possible to get a File object with "" as the path
gsnapCommand.input = List(R1, R2).filterNot(x => x == null || x.getPath == "")
gsnapCommand.input = if (paired) List(R1, R2.get) else List(R1)
gsnapCommand.deps = deps
gsnapCommand.output = swapExt(output.getParent, output, ".bam", ".sam")
gsnapCommand.isIntermediate = true
......@@ -360,12 +360,11 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
addAddOrReplaceReadGroups(reorderSam.output, output)
}
def addTophat(R1: File, R2: File, output: File, deps: List[File]): File = {
def addTophat(R1: File, R2: Option[File], output: File, deps: List[File]): File = {
// TODO: merge mapped and unmapped BAM ~ also dealing with validation errors in the unmapped BAM
val tophat = new Tophat(this)
// FIXME: ideally we should only check for null ~ but apparently it's possible to get a File object with "" as the path
tophat.R1 = tophat.R1 :+ R1
if (R2 != null && R2.getPath != "") tophat.R2 = tophat.R2 :+ R2
if (paired) tophat.R2 = tophat.R2 :+ R2.get
tophat.output_dir = new File(outputDir, "tophat_out")
tophat.deps = deps
// always output BAM
......@@ -376,7 +375,7 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
val sortSam = new SortSam(this)
sortSam.input = tophat.outputAcceptedHits
sortSam.output = swapExt(output.getParent, output, ".bam", ".sorted.bam")
sortSam.output = swapExt(output.getParentFile, output, ".bam", ".sorted.bam")
sortSam.sortOrder = "coordinate"
sortSam.isIntermediate = chunking || !skipMarkduplicates
add(sortSam)
......@@ -391,7 +390,7 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
* @param deps
* @return
*/
def addStampy(R1: File, R2: File, output: File, deps: List[File]): File = {
def addStampy(R1: File, R2: Option[File], output: File, deps: List[File]): File = {
var RG: String = "ID:" + readgroupId + ","
RG += "SM:" + sampleId.get + ","
......@@ -405,7 +404,7 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
val stampyCmd = new Stampy(this)
stampyCmd.R1 = R1
if (paired) stampyCmd.R2 = R2
if (paired) stampyCmd.R2 = R2.get
stampyCmd.deps = deps
stampyCmd.readgroup = RG
stampyCmd.sanger = true
......@@ -426,10 +425,10 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
* @param deps
* @return
*/
def addBowtie(R1: File, R2: File, output: File, deps: List[File]): File = {
def addBowtie(R1: File, R2: Option[File], output: File, deps: List[File]): File = {
val bowtie = new Bowtie(this)
bowtie.R1 = R1
if (paired) bowtie.R2 = Some(R2)
if (paired) bowtie.R2 = R2
bowtie.deps = deps
bowtie.output = this.swapExt(output.getParent, output, ".bam", ".sam")
bowtie.isIntermediate = true
......@@ -445,8 +444,8 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
* @param deps
* @return
*/
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)
def addStar(R1: File, R2: Option[File], output: File, deps: List[File]): File = {
val starCommand = Star(this, R1, R2, outputDir, isIntermediate = true, deps = deps)
add(starCommand)
addAddOrReplaceReadGroups(starCommand.outputSam, output)
}
......@@ -459,8 +458,8 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
* @param deps
* @return
*/
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)
def addStar2pass(R1: File, R2: Option[File], output: File, deps: List[File]): File = {
val starCommand = Star._2pass(this, R1, R2, outputDir, isIntermediate = true, deps = deps)
addAll(starCommand._2)
addAddOrReplaceReadGroups(starCommand._1, output)
}
......
Markdown is supported
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