Commit 10d0ce96 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Adding merge strategies

parent 60615f7d
......@@ -65,10 +65,10 @@ class MergeSamFiles(val root: Configurable) extends Picard {
object MergeSamFiles {
/** Returns default MergeSamFiles */
def apply(root: Configurable, input: List[File], outputDir: File, sortOrder: String = null): MergeSamFiles = {
def apply(root: Configurable, input: List[File], outputFile: File, sortOrder: String = null): MergeSamFiles = {
val mergeSamFiles = new MergeSamFiles(root)
mergeSamFiles.input = input
mergeSamFiles.output = new File(outputDir, input.head.getName.stripSuffix(".bam").stripSuffix(".sam") + ".merge.bam")
mergeSamFiles.output = outputFile
if (sortOrder == null) mergeSamFiles.sortOrder = "coordinate"
else mergeSamFiles.sortOrder = sortOrder
mergeSamFiles
......
......@@ -244,7 +244,7 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
add(md)
addSummarizable(md, "mark_duplicates")
} else if (skipMarkduplicates && chunking) {
val mergeSamFile = MergeSamFiles(this, bamFiles, outputDir)
val mergeSamFile = MergeSamFiles(this, bamFiles, new File(outputDir, outputName + ".merge.bam"))
add(mergeSamFile)
bamFile = mergeSamFile.output
}
......
......@@ -5,7 +5,7 @@ import java.io.File
import htsjdk.samtools.SamReaderFactory
import nl.lumc.sasc.biopet.core.{PipelineCommand, Reference, MultiSampleQScript}
import nl.lumc.sasc.biopet.extensions.Ln
import nl.lumc.sasc.biopet.extensions.picard.{AddOrReplaceReadGroups, SamToFastq}
import nl.lumc.sasc.biopet.extensions.picard.{MarkDuplicates, MergeSamFiles, AddOrReplaceReadGroups, SamToFastq}
import nl.lumc.sasc.biopet.pipelines.bammetrics.BamMetrics
import nl.lumc.sasc.biopet.utils.Logging
import nl.lumc.sasc.biopet.utils.config.Configurable
......@@ -21,11 +21,20 @@ class MultisampleMapping(val root: Configurable) extends QScript
with Reference { qscript =>
def this() = this(null)
def mergeStrategy: MultisampleMapping.MergeStrategy.Value = {
val value: String = config("merge_strategy", default = "preprocessmarkduplicates")
MultisampleMapping.MergeStrategy.values.find(_.toString.toLowerCase == value) match {
case Some(v) => v
case _ => throw new IllegalArgumentException(s"merge_strategy '$value' does not exist")
}
}
def init: Unit = {
}
def biopetScript: Unit = {
addSamplesJobs() // This executes jobs for all samples
addSummaryJobs()
}
def addMultiSampleJobs: Unit = {
......@@ -66,6 +75,8 @@ class MultisampleMapping(val root: Configurable) extends QScript
case _ => None
}
def preProcessBam = bamFile
def addJobs: Unit = {
if (inputR1.isDefined) {
mapping.foreach { m =>
......@@ -139,8 +150,29 @@ class MultisampleMapping(val root: Configurable) extends QScript
def summaryStats: Map[String, Any] = Map()
def executeSamplePreProcess: Boolean = libraries.flatMap(_._2.bamFile).size > 1
def bamFile = if (libraries.flatMap(_._2.bamFile).nonEmpty &&
mergeStrategy != MultisampleMapping.MergeStrategy.None)
Some(new File(sampleDir, s"$sampleId.bam"))
else None
def preProcessBam = bamFile
def addJobs: Unit = {
addPerLibJobs() // This add jobs for each library
mergeStrategy match {
case MultisampleMapping.MergeStrategy.MergeSam =>
add(MergeSamFiles(qscript, libraries.flatMap(_._2.bamFile).toList, bamFile.get))
case MultisampleMapping.MergeStrategy.PreProcessMergeSam =>
add(MergeSamFiles(qscript, libraries.flatMap(_._2.preProcessBam).toList, bamFile.get))
case MultisampleMapping.MergeStrategy.MarkDuplicates =>
add(MarkDuplicates(qscript, libraries.flatMap(_._2.bamFile).toList, bamFile.get))
case MultisampleMapping.MergeStrategy.PreProcessMarkDuplicates =>
add(MarkDuplicates(qscript, libraries.flatMap(_._2.preProcessBam).toList, bamFile.get))
case _ =>
}
}
}
}
......@@ -148,7 +180,7 @@ class MultisampleMapping(val root: Configurable) extends QScript
object MultisampleMapping extends PipelineCommand {
object MergeStrategy extends Enumeration {
val None, MergeSam, MarkDuplicates = Value
val None, MergeSam, MarkDuplicates, PreProcessMergeSam, PreProcessMarkDuplicates = Value
}
def fileMustBeAbsulute(file: Option[File]): Option[File] = {
......
......@@ -125,7 +125,7 @@ class Sage(val root: Configurable) extends QScript with MultiSampleQScript {
val bamFile: File = if (libraryBamfiles.size == 1) libraryBamfiles.head
else if (libraryBamfiles.size > 1) {
val mergeSamFiles = MergeSamFiles(qscript, libraryBamfiles, sampleDir)
val mergeSamFiles = MergeSamFiles(qscript, libraryBamfiles, new File(sampleDir, s"$sampleId.bam"))
qscript.add(mergeSamFiles)
mergeSamFiles.output
} else null
......
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