Commit 02b571a4 authored by bow's avatar bow
Browse files

Update code style using scalariform

parent 96ccc270
......@@ -2,63 +2,63 @@ package nl.lumc.sasc.biopet.pipelines.bammetrics
import nl.lumc.sasc.biopet.pipelines.bammetrics.scripts.CoverageStats
import org.broadinstitute.gatk.queue.QScript
import nl.lumc.sasc.biopet.core.{BiopetQScript, PipelineCommand}
import nl.lumc.sasc.biopet.core.{ BiopetQScript, PipelineCommand }
import java.io.File
import nl.lumc.sasc.biopet.core.apps.{BedToInterval, BiopetFlagstat}
import nl.lumc.sasc.biopet.core.apps.{ BedToInterval, BiopetFlagstat }
import nl.lumc.sasc.biopet.core.config.Configurable
import nl.lumc.sasc.biopet.function.bedtools.{BedtoolsCoverage, BedtoolsIntersect}
import nl.lumc.sasc.biopet.function.picard.{CollectInsertSizeMetrics, CollectGcBiasMetrics, CalculateHsMetrics, CollectAlignmentSummaryMetrics}
import nl.lumc.sasc.biopet.function.bedtools.{ BedtoolsCoverage, BedtoolsIntersect }
import nl.lumc.sasc.biopet.function.picard.{ CollectInsertSizeMetrics, CollectGcBiasMetrics, CalculateHsMetrics, CollectAlignmentSummaryMetrics }
import nl.lumc.sasc.biopet.function.samtools.SamtoolsFlagstat
class BamMetrics(val root:Configurable) extends QScript with BiopetQScript {
class BamMetrics(val root: Configurable) extends QScript with BiopetQScript {
def this() = this(null)
@Input(doc="Bam File", shortName="BAM",required=true)
@Input(doc = "Bam File", shortName = "BAM", required = true)
var inputBam: File = _
@Input(doc="Bed tracks targets", shortName="target",required=false)
@Input(doc = "Bed tracks targets", shortName = "target", required = false)
var bedFiles: List[File] = Nil
@Input(doc="Bed tracks bait", shortName="bait",required=false)
@Input(doc = "Bed tracks bait", shortName = "bait", required = false)
var baitBedFile: File = _
@Argument(doc="",required=false)
@Argument(doc = "", required = false)
var wholeGenome = false
def init() {
for (file <- configfiles) globalConfig.loadConfigFile(file)
if (outputDir == null) throw new IllegalStateException("Missing Output directory on BamMetrics module")
else if (!outputDir.endsWith("/")) outputDir += "/"
}
def biopetScript() {
add(SamtoolsFlagstat(this, inputBam, outputDir))
add(BiopetFlagstat(this, inputBam, outputDir))
add(CollectGcBiasMetrics(this, inputBam, outputDir))
add(CollectInsertSizeMetrics(this, inputBam, outputDir))
add(CollectAlignmentSummaryMetrics(this, inputBam, outputDir))
val baitIntervalFile = if (baitBedFile != null) new File(outputDir, baitBedFile.getName.stripSuffix(".bed") + ".interval") else null
if (baitIntervalFile != null)
add(BedToInterval(this, baitBedFile, inputBam, outputDir), true)
for (bedFile <- bedFiles) {
val targetDir = outputDir + bedFile.getName.stripSuffix(".bed") + "/"
val targetInterval = BedToInterval(this, bedFile, inputBam, targetDir)
add(targetInterval, true)
add(CalculateHsMetrics(this, inputBam, if (baitIntervalFile != null) baitIntervalFile
else targetInterval.output, targetInterval.output, targetDir))
else targetInterval.output, targetInterval.output, targetDir))
val strictOutputBam = new File(targetDir, inputBam.getName.stripSuffix(".bam") + ".overlap.strict.bam")
add(BedtoolsIntersect(this, inputBam, bedFile, strictOutputBam, minOverlap = config("strictintersectoverlap", default=1.0)), true)
add(BedtoolsIntersect(this, inputBam, bedFile, strictOutputBam, minOverlap = config("strictintersectoverlap", default = 1.0)), true)
add(SamtoolsFlagstat(this, strictOutputBam))
add(BiopetFlagstat(this, strictOutputBam, targetDir))
val looseOutputBam = new File(targetDir, inputBam.getName.stripSuffix(".bam") + ".overlap.loose.bam")
add(BedtoolsIntersect(this, inputBam, bedFile, looseOutputBam, minOverlap = config("looseintersectoverlap", default=0.01)), true)
add(BedtoolsIntersect(this, inputBam, bedFile, looseOutputBam, minOverlap = config("looseintersectoverlap", default = 0.01)), true)
add(SamtoolsFlagstat(this, looseOutputBam))
add(BiopetFlagstat(this, looseOutputBam, targetDir))
val coverageFile = new File(targetDir, inputBam.getName.stripSuffix(".bam") + ".coverage")
add(BedtoolsCoverage(this, inputBam, bedFile, coverageFile, true), true)
add(CoverageStats(this, coverageFile, targetDir))
......@@ -68,12 +68,12 @@ class BamMetrics(val root:Configurable) extends QScript with BiopetQScript {
object BamMetrics extends PipelineCommand {
override val pipeline = "/nl/lumc/sasc/biopet/pipelines/bammetrics/BamMetrics.class"
def apply(root:Configurable, bamFile:File, outputDir:String) : BamMetrics = {
def apply(root: Configurable, bamFile: File, outputDir: String): BamMetrics = {
val bamMetrics = new BamMetrics(root)
bamMetrics.inputBam = bamFile
bamMetrics.outputDir = outputDir
bamMetrics.init
bamMetrics.biopetScript
return bamMetrics
......
......@@ -2,27 +2,27 @@ package nl.lumc.sasc.biopet.pipelines.bammetrics.scripts
import nl.lumc.sasc.biopet.core.config.Configurable
import nl.lumc.sasc.biopet.function.PythonCommandLineFunction
import org.broadinstitute.gatk.utils.commandline.{Input, Output}
import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
import java.io.File
class CoverageStats(val root:Configurable) extends PythonCommandLineFunction {
class CoverageStats(val root: Configurable) extends PythonCommandLineFunction {
setPythonScript("bedtools_cov_stats.py")
@Input(doc="Input file")
@Input(doc = "Input file")
var input: File = _
@Output(doc="output File")
@Output(doc = "output File")
var output: File = _
@Output(doc="plot File (png)")
@Output(doc = "plot File (png)")
var plot: File = _
def cmdLine = getPythonCommand +
required(input) + required("--plot", plot) + " > " + required(output)
}
object CoverageStats {
def apply(root:Configurable, input:File, outputDir:String) : CoverageStats = {
def apply(root: Configurable, input: File, outputDir: String): CoverageStats = {
val coverageStats = new CoverageStats(root)
coverageStats.input = input
coverageStats.output = new File(outputDir, input.getName + ".stats")
......
package nl.lumc.sasc.biopet.core
abstract class BiopetCommandLineFunction extends BiopetCommandLineFunctionTrait {
abstract class BiopetCommandLineFunction extends BiopetCommandLineFunctionTrait {
protected def cmdLine: String
final def commandLine: String = {
preCmdInternal
......
......@@ -10,45 +10,45 @@ import scala.util.matching.Regex
trait BiopetCommandLineFunctionTrait extends CommandLineFunction with Configurable {
analysisName = getClass.getSimpleName
@Input(doc="deps", required=false)
@Input(doc = "deps", required = false)
var deps: List[File] = Nil
@Argument(doc="Threads", required=false)
@Argument(doc = "Threads", required = false)
var threads = 0
val defaultThreads = 1
@Argument(doc="Vmem", required=false)
@Argument(doc = "Vmem", required = false)
var vmem: String = _
val defaultVmem: String = ""
@Argument(doc="Executable")
@Argument(doc = "Executable")
var executable: String = _
protected def beforeCmd {
}
protected def afterGraph {
}
override def freezeFieldValues() {
checkExecutable
afterGraph
jobOutputFile = new File(firstOutput.getParent + "/." + firstOutput.getName + "." + analysisName + ".out")
jobOutputFile = new File(firstOutput.getParent + "/." + firstOutput.getName + "." + analysisName + ".out")
if (threads == 0) threads = getThreads(defaultThreads)
if (threads > 1) nCoresRequest = Option(threads)
if (vmem == null) {
vmem = config("vmem")
if (vmem == null && !defaultVmem.isEmpty) vmem = defaultVmem
}
if (vmem != null) jobResourceRequests :+= "h_vmem=" + vmem
jobName = this.analysisName + ":" + firstOutput.getName
super.freezeFieldValues()
}
protected def checkExecutable {
try if (executable != null) {
val buffer = new StringBuffer()
......@@ -66,22 +66,22 @@ trait BiopetCommandLineFunctionTrait extends CommandLineFunction with Configurab
case ioe: java.io.IOException => logger.warn("Could not use 'which', check on executable skipped: " + ioe)
}
}
final protected def preCmdInternal {
checkExecutable
//for (input <- this.inputs) if (!input.exists) throw new IllegalStateException("Input: " + input + " for " + analysisName + " is missing")
//logger.debug("Config for " + analysisName + ": " + localConfig)
beforeCmd
addJobReportBinding("cores", if (nCoresRequest.get.toInt > 0) nCoresRequest.get.toInt else 1)
addJobReportBinding("version", getVersion)
}
protected def versionCommand: String = null
protected val versionRegex: Regex = null
protected val versionExitcode = List(0) // Can select multiple
def getVersion : String = {
def getVersion: String = {
if (versionCommand == null || versionRegex == null) return "N/A"
val buffer = new StringBuffer()
val process = Process(versionCommand).run(ProcessLogger(buffer append _))
......@@ -91,25 +91,25 @@ trait BiopetCommandLineFunctionTrait extends CommandLineFunction with Configurab
}
val lines = versionCommand lines_! ProcessLogger(buffer append _)
for (line <- lines) {
line match {
line match {
case versionRegex(m) => return m
case _ =>
case _ =>
}
}
logger.warn("Version command: '" + versionCommand + "' give a exit code " + process.exitValue + " but no version was found, executable oke?")
return "N/A"
}
def getThreads(default:Int) : Int = {
val maxThreads: Int = config("maxthreads", default=8)
val threads: Int = config("threads", default=default)
def getThreads(default: Int): Int = {
val maxThreads: Int = config("maxthreads", default = 8)
val threads: Int = config("threads", default = default)
if (maxThreads > threads) return threads
else return maxThreads
}
def getThreads(default:Int, module:String) : Int = {
val maxThreads: Int = config("maxthreads", default=8, submodule=module)
val threads: Int = config("threads", default=default, submodule=module)
def getThreads(default: Int, module: String): Int = {
val maxThreads: Int = config("maxthreads", default = 8, submodule = module)
val threads: Int = config("threads", default = default, submodule = module)
if (maxThreads > threads) return threads
else return maxThreads
}
......
......@@ -4,12 +4,12 @@ import org.broadinstitute.gatk.queue.function.JavaCommandLineFunction
abstract class BiopetJavaCommandLineFunction extends JavaCommandLineFunction with BiopetCommandLineFunctionTrait {
executable = "java"
override def commandLine: String = {
preCmdInternal
val cmd = super.commandLine
val finalCmd = executable + cmd.substring(cmd.indexOf(" "))
// addJobReportBinding("command", cmd)
// addJobReportBinding("command", cmd)
return cmd
}
}
......@@ -32,7 +32,7 @@ import org.broadinstitute.gatk.queue.util._
import org.broadinstitute.gatk.queue.QCommandPlugin
import org.broadinstitute.gatk.queue.QScript
import org.broadinstitute.gatk.queue.QScriptManager
import org.broadinstitute.gatk.queue.engine.{QStatusMessenger, QGraphSettings, QGraph}
import org.broadinstitute.gatk.queue.engine.{ QStatusMessenger, QGraphSettings, QGraph }
import collection.JavaConversions._
import org.broadinstitute.gatk.utils.classloader.PluginManager
import org.broadinstitute.gatk.utils.exceptions.UserException
......@@ -40,7 +40,7 @@ import org.broadinstitute.gatk.utils.io.IOUtils
import org.broadinstitute.gatk.utils.help.ApplicationDetails
import java.io.FileOutputStream
import java.net.URL
import java.util.{ResourceBundle, Arrays}
import java.util.{ ResourceBundle, Arrays }
import org.broadinstitute.gatk.utils.text.TextFormattingUtils
import org.apache.commons.io.FilenameUtils
......@@ -84,11 +84,11 @@ object BiopetQCommandLine extends Logging {
* Entry point of Queue. Compiles and runs QScripts passed in to the command line.
*/
class BiopetQCommandLine extends CommandLineProgram with Logging {
@Input(fullName="script", shortName="S", doc="QScript scala file", required=false)
@Input(fullName = "script", shortName = "S", doc = "QScript scala file", required = false)
@ClassType(classOf[File])
var scripts: Seq[File] = Nil
var pipelineName: String = _
@ArgumentCollection
val settings = new QGraphSettings
......@@ -155,8 +155,7 @@ class BiopetQCommandLine extends CommandLineProgram with Logging {
// TODO: Default command plugin argument?
val remoteFileConverter = (
for (commandPlugin <- allCommandPlugins if (commandPlugin.remoteFileConverter != null))
yield commandPlugin.remoteFileConverter
).headOption.getOrElse(null)
yield commandPlugin.remoteFileConverter).headOption.getOrElse(null)
if (remoteFileConverter != null)
loadArgumentsIntoObject(remoteFileConverter)
......@@ -267,37 +266,35 @@ class BiopetQCommandLine extends CommandLineProgram with Logging {
override def getArgumentTypeDescriptors =
Arrays.asList(new ScalaCompoundArgumentTypeDescriptor)
override def getApplicationDetails : ApplicationDetails = {
override def getApplicationDetails: ApplicationDetails = {
new ApplicationDetails(createQueueHeader(),
Seq.empty[String],
ApplicationDetails.createDefaultRunningInstructions(getClass.asInstanceOf[Class[CommandLineProgram]]),
"")
Seq.empty[String],
ApplicationDetails.createDefaultRunningInstructions(getClass.asInstanceOf[Class[CommandLineProgram]]),
"")
}
private def createQueueHeader() : Seq[String] = {
private def createQueueHeader(): Seq[String] = {
Seq(String.format("Queue v%s, Compiled %s", getQueueVersion, getBuildTimestamp),
"Copyright (c) 2012 The Broad Institute",
"For support and documentation go to http://www.broadinstitute.org/gatk")
"Copyright (c) 2012 The Broad Institute",
"For support and documentation go to http://www.broadinstitute.org/gatk")
}
private def getQueueVersion : String = {
val stingResources : ResourceBundle = TextFormattingUtils.loadResourceBundle("StingText")
private def getQueueVersion: String = {
val stingResources: ResourceBundle = TextFormattingUtils.loadResourceBundle("StingText")
if ( stingResources.containsKey("org.broadinstitute.sting.queue.QueueVersion.version") ) {
if (stingResources.containsKey("org.broadinstitute.sting.queue.QueueVersion.version")) {
stingResources.getString("org.broadinstitute.sting.queue.QueueVersion.version")
}
else {
} else {
"<unknown>"
}
}
private def getBuildTimestamp : String = {
val stingResources : ResourceBundle = TextFormattingUtils.loadResourceBundle("StingText")
private def getBuildTimestamp: String = {
val stingResources: ResourceBundle = TextFormattingUtils.loadResourceBundle("StingText")
if ( stingResources.containsKey("build.timestamp") ) {
if (stingResources.containsKey("build.timestamp")) {
stingResources.getString("build.timestamp")
}
else {
} else {
"<unknown>"
}
}
......
......@@ -8,19 +8,19 @@ import org.broadinstitute.gatk.queue.QSettings
import org.broadinstitute.gatk.queue.function.QFunction
trait BiopetQScript extends Configurable {
@Argument(doc="Config Json file",shortName="config", required=false)
@Argument(doc = "Config Json file", shortName = "config", required = false)
val configfiles: List[File] = Nil
@Argument(doc="Output directory", shortName="outputDir", required=true)
@Argument(doc = "Output directory", shortName = "outputDir", required = true)
var outputDir: String = _
var outputFiles:Map[String,File] = Map()
var outputFiles: Map[String, File] = Map()
var qSettings: QSettings
def init
def biopetScript
final def script() {
for (file <- configfiles) globalConfig.loadConfigFile(file)
if (!outputDir.endsWith("/")) outputDir += "/"
......@@ -33,12 +33,11 @@ trait BiopetQScript extends Configurable {
writer.close()
for (line <- configReport.split("\n")) logger.debug(line)
}
def add(functions: QFunction*) // Gets implemeted at org.broadinstitute.sting.queue.QScript
def add(function: QFunction, isIntermediate:Boolean = false) {
def add(function: QFunction, isIntermediate: Boolean = false) {
function.isIntermediate = isIntermediate
add(function)
}
}
......@@ -4,33 +4,34 @@ import java.io.File
import nl.lumc.sasc.biopet.core.config.Configurable
trait MultiSampleQScript extends BiopetQScript {
var samples:Map[String,Any] = Map()
final def runSamplesJobs : Map[String,Map[String,File]] = {
var output: Map[String,Map[String,File]] = Map()
var samples: Map[String, Any] = Map()
final def runSamplesJobs: Map[String, Map[String, File]] = {
var output: Map[String, Map[String, File]] = Map()
samples = config("samples")
if (samples == null) samples = Map()
if (globalConfig.contains("samples")) for ((key,value) <- samples) {
if (globalConfig.contains("samples")) for ((key, value) <- samples) {
var sample = Configurable.any2map(value)
if (!sample.contains("ID")) sample += ("ID" -> key)
if (sample("ID") == key) {
var files:Map[String,List[File]] = runSingleSampleJobs(sample)
var files: Map[String, List[File]] = runSingleSampleJobs(sample)
} else logger.warn("Key is not the same as ID on value for sample")
} else logger.warn("No Samples found in config")
}
else logger.warn("No Samples found in config")
return output
}
def runSingleSampleJobs(sampleConfig:Map[String,Any]) : Map[String,List[File]]
def runSingleSampleJobs(sample:String) : Map[String,List[File]] ={
def runSingleSampleJobs(sampleConfig: Map[String, Any]): Map[String, List[File]]
def runSingleSampleJobs(sample: String): Map[String, List[File]] = {
return runSingleSampleJobs(Configurable.any2map(samples(sample)))
}
final def runRunsJobs(sampleConfig:Map[String,Any]) : Map[String,Map[String,File]] = {
var output: Map[String,Map[String,File]] = Map()
final def runRunsJobs(sampleConfig: Map[String, Any]): Map[String, Map[String, File]] = {
var output: Map[String, Map[String, File]] = Map()
val sampleID = sampleConfig("ID")
if (sampleConfig.contains("runs")) {
val runs = Configurable.any2map(sampleConfig("runs"))
for ((key,value) <- runs) {
for ((key, value) <- runs) {
var run = Configurable.any2map(value)
if (!run.contains("ID")) run += ("ID" -> key)
if (run("ID") == key) {
......@@ -40,5 +41,5 @@ trait MultiSampleQScript extends BiopetQScript {
} else logger.warn("No runs found in config for sample: " + sampleID)
return output
}
def runSingleRunJobs(runConfig:Map[String,Any], sampleConfig:Map[String,Any]) : Map[String,File]
def runSingleRunJobs(runConfig: Map[String, Any], sampleConfig: Map[String, Any]): Map[String, File]
}
......@@ -11,17 +11,17 @@ import java.io.FileOutputStream
import org.broadinstitute.gatk.queue.util.Logging
trait PipelineCommand extends Logging {
// val src = ""
// val extension = ".scala"
// val src = ""
// val extension = ".scala"
val pipeline = ""
def main(args: Array[String]): Unit = {
// val tempFile = java.io.File.createTempFile(src + ".", extension)
// val is = getClass.getResourceAsStream(src + extension)
// val os = new FileOutputStream(tempFile)
// org.apache.commons.io.IOUtils.copy(is, os)
// os.close()
// val tempFile = java.io.File.createTempFile(src + ".", extension)
// val is = getClass.getResourceAsStream(src + extension)
// val os = new FileOutputStream(tempFile)
// org.apache.commons.io.IOUtils.copy(is, os)
// os.close()
var argv: Array[String] = Array()
//argv ++= Array("-S", tempFile.getAbsolutePath)
argv ++= Array("-S", pipeline)
......
......@@ -5,58 +5,58 @@ import htsjdk.samtools.SAMSequenceRecord
import java.io.File
import nl.lumc.sasc.biopet.core.BiopetJavaCommandLineFunction
import nl.lumc.sasc.biopet.core.config.Configurable
import org.broadinstitute.gatk.utils.commandline.{Input, Output}
import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
import java.io.PrintWriter
import scala.io.Source
class BedToInterval(val root:Configurable) extends BiopetJavaCommandLineFunction {
class BedToInterval(val root: Configurable) extends BiopetJavaCommandLineFunction {
javaMainClass = getClass.getName
@Input(doc="Input Bed file", required = true)
@Input(doc = "Input Bed file", required = true)
var input: File = _
@Input(doc="Bam File", required = true)
var bamFile:File = _
@Output(doc="Output interval list", required = true)
@Input(doc = "Bam File", required = true)
var bamFile: File = _
@Output(doc = "Output interval list", required = true)
var output: File = _
override val defaultVmem = "8G"