Commit 3decab94 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

convert AddOrReplaceReadGroups to biopet function

parent dfed2154
package nl.lumc.sasc.biopet.extensions.picard
import java.io.File
import nl.lumc.sasc.biopet.core.config.Configurable
import org.broadinstitute.gatk.utils.commandline.{ Input, Output, Argument }
class AddOrReplaceReadGroups(val root: Configurable) extends Picard {
javaMainClass = "picard.sam.AddOrReplaceReadGroups"
@Input(doc = "The input SAM or BAM files to analyze.", required = true)
var input: File = _
@Output(doc = "The output file to bam file to", required = true)
var output: File = _
@Argument(doc = "Sort order of output file Required. Possible values: {unsorted, queryname, coordinate} ", required = true)
var sortOrder: String = _
@Argument(doc = "RGID", required = true)
var RGID: String = _
@Argument(doc = "RGLB", required = true)
var RGLB: String = _
@Argument(doc = "RGPL", required = true)
var RGPL: String = _
@Argument(doc = "RGPU", required = true)
var RGPU: String = _
@Argument(doc = "RGSM", required = true)
var RGSM: String = _
@Argument(doc = "RGCN", required = false)
var RGCN: String = _
@Argument(doc = "RGDS", required = false)
var RGDS: String = _
@Argument(doc = "RGDT", required = false)
var RGDT: String = _
@Argument(doc = "RGPI", required = false)
var RGPI: Option[Int] = _
override def commandLine = super.commandLine +
required("INPUT=", input, spaceSeparated = false) +
required("OUTPUT=", output, spaceSeparated = false) +
required("SORT_ORDER=", sortOrder, spaceSeparated = false) +
required("RGID=", RGID, spaceSeparated = false) +
required("RGLB=", RGLB, spaceSeparated = false) +
required("RGPL=", RGPL, spaceSeparated = false) +
required("RGPU=", RGPU, spaceSeparated = false) +
required("RGSM=", RGSM, spaceSeparated = false) +
optional("RGCN=", RGCN, spaceSeparated = false) +
optional("RGDS=", RGDS, spaceSeparated = false) +
optional("RGDT=", RGDT, spaceSeparated = false) +
optional("RGPI=", RGPI, spaceSeparated = false)
}
object AddOrReplaceReadGroups {
def apply(root: Configurable, input: File, outputDir: String, 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")
if (sortOrder == null) addOrReplaceReadGroups.sortOrder = "coordinate"
else addOrReplaceReadGroups.sortOrder = sortOrder
return addOrReplaceReadGroups
}
}
\ No newline at end of file
......@@ -6,12 +6,11 @@ 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.picard.{MarkDuplicates, SortSam, MergeSamFiles}
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
import org.broadinstitute.gatk.queue.QScript
import org.broadinstitute.gatk.utils.commandline.{ Input, Argument, ClassType }
import org.broadinstitute.gatk.queue.extensions.picard.{ AddOrReplaceReadGroups }
import scala.math._
class Mapping(val root: Configurable) extends QScript with BiopetQScript {
......@@ -202,11 +201,11 @@ class Mapping(val root: Configurable) extends QScript with BiopetQScript {
} else if (aligner == "star") {
val starCommand = Star(this, R1, if (paired) R2 else null, outputDir, isIntermediate = true, deps = deps)
add(starCommand)
bamFiles :+= addAddOrReplaceReadGroups(List(starCommand.outputSam), new File(chunkDir + outputName + ".bam"), chunkDir)
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(List(star2pass._1), new File(chunkDir + outputName + ".bam"), chunkDir)
bamFiles :+= addAddOrReplaceReadGroups(star2pass._1, chunkDir)
} else throw new IllegalStateException("Option Alginer: '" + aligner + "' is not valid")
}
if (!skipFlexiprep) {
......@@ -259,14 +258,9 @@ class Mapping(val root: Configurable) extends QScript with BiopetQScript {
// return mergeSam.output
// }
def addAddOrReplaceReadGroups(inputSam: List[File], outputFile: File, dir: String): File = {
val addOrReplaceReadGroups = new AddOrReplaceReadGroups
addOrReplaceReadGroups.input = inputSam
addOrReplaceReadGroups.output = outputFile
def addAddOrReplaceReadGroups(inputSam: File, outputDir: String): File = {
val addOrReplaceReadGroups = AddOrReplaceReadGroups(this, inputSam, outputDir)
addOrReplaceReadGroups.createIndex = true
addOrReplaceReadGroups.memoryLimit = 2
addOrReplaceReadGroups.nCoresRequest = 2
addOrReplaceReadGroups.jobResourceRequests :+= "h_vmem=4G"
addOrReplaceReadGroups.RGID = RGID
addOrReplaceReadGroups.RGLB = RGLB
......
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