Commit 7f2580f2 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Fixing code warning from ide

parent 2b7a4f2f
......@@ -31,9 +31,9 @@ abstract class BiopetCommandLineFunction extends BiopetCommandLineFunctionTrait
* @return Command to run
*/
final def commandLine: String = {
preCmdInternal
preCmdInternal()
val cmd = cmdLine
addJobReportBinding("command", cmd)
return cmd
cmd
}
}
......@@ -17,9 +17,9 @@ package nl.lumc.sasc.biopet.core
import java.io.File
import nl.lumc.sasc.biopet.core.config.Configurable
import org.broadinstitute.gatk.queue.QException
import org.broadinstitute.gatk.queue.function.CommandLineFunction
import org.broadinstitute.gatk.utils.commandline.{ Input, Argument }
import org.broadinstitute.gatk.utils.commandline.Input
import scala.collection.mutable
import scala.sys.process.{ Process, ProcessLogger }
import scala.util.matching.Regex
import java.io.FileInputStream
......@@ -50,15 +50,15 @@ trait BiopetCommandLineFunctionTrait extends CommandLineFunction with Configurab
* Can override this method. This is executed just before the job is ready to run.
* Can check on run time files from pipeline here
*/
protected[core] def beforeCmd {}
protected[core] def beforeCmd() {}
/** Can override this method. This is executed after the script is done en queue starts to generate the graph */
protected[core] def beforeGraph {}
protected[core] def beforeGraph() {}
/** Set default output file, threads and vmem for current job */
override def freezeFieldValues() {
preProcesExecutable
beforeGraph
preProcessExecutable()
beforeGraph()
if (jobOutputFile == null) jobOutputFile = new File(firstOutput.getAbsoluteFile.getParent, "." + firstOutput.getName + "." + configName + ".out")
if (threads == 0) threads = getThreads(defaultThreads)
......@@ -95,7 +95,7 @@ trait BiopetCommandLineFunctionTrait extends CommandLineFunction with Configurab
/**
* Checks executable. Follow full CanonicalPath, checks if it is existing and do a md5sum on it to store in job report
*/
protected[core] def preProcesExecutable {
protected[core] def preProcessExecutable() {
if (!BiopetCommandLineFunctionTrait.executableMd5Cache.contains(executable)) {
try if (executable != null) {
if (!BiopetCommandLineFunctionTrait.executableCache.contains(executable)) {
......@@ -135,10 +135,9 @@ trait BiopetCommandLineFunctionTrait extends CommandLineFunction with Configurab
}
/** executes checkExecutable method and fill job report */
final protected def preCmdInternal {
preProcesExecutable
beforeCmd
final protected def preCmdInternal() {
preProcessExecutable()
beforeCmd()
addJobReportBinding("cores", nCoresRequest match {
case Some(n) if n > 0 => n
......@@ -157,7 +156,7 @@ trait BiopetCommandLineFunctionTrait extends CommandLineFunction with Configurab
protected val versionExitcode = List(0)
/** Executes the version command */
private[core] def getVersionInternal(): Option[String] = {
private[core] def getVersionInternal: Option[String] = {
if (versionCommand == null || versionRegex == null) None
else getVersionInternal(versionCommand, versionRegex)
}
......@@ -173,7 +172,7 @@ trait BiopetCommandLineFunctionTrait extends CommandLineFunction with Configurab
"\n output log: \n stdout: \n" + stdout.toString +
"\n stderr: \n" + stderr.toString
val process = Process(versionCommand).run(ProcessLogger(stdout append _ + "\n", stderr append _ + "\n"))
if (!versionExitcode.contains(process.exitValue)) {
if (!versionExitcode.contains(process.exitValue())) {
logger.warn("getVersion give exit code " + process.exitValue + ", version not found \n" + outputLog)
return None
}
......@@ -184,13 +183,13 @@ trait BiopetCommandLineFunctionTrait extends CommandLineFunction with Configurab
}
}
logger.warn("getVersion give a exit code " + process.exitValue + " but no version was found, executable correct? \n" + outputLog)
return None
None
}
/** Get version from cache otherwise execute the version command */
def getVersion: Option[String] = {
if (!BiopetCommandLineFunctionTrait.executableCache.contains(executable))
preProcesExecutable
preProcessExecutable()
if (!BiopetCommandLineFunctionTrait.versionCache.contains(versionCommand))
getVersionInternal match {
case Some(version) => BiopetCommandLineFunctionTrait.versionCache += versionCommand -> version
......@@ -207,8 +206,8 @@ trait BiopetCommandLineFunctionTrait extends CommandLineFunction with Configurab
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
if (maxThreads > threads) threads
else maxThreads
}
/**
......@@ -220,15 +219,14 @@ trait BiopetCommandLineFunctionTrait extends CommandLineFunction with Configurab
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
if (maxThreads > threads) threads
else maxThreads
}
}
/** stores global caches */
object BiopetCommandLineFunctionTrait {
import scala.collection.mutable.Map
private[core] val versionCache: Map[String, String] = Map()
private[core] val executableMd5Cache: Map[String, String] = Map()
private[core] val executableCache: Map[String, String] = Map()
private[core] val versionCache: mutable.Map[String, String] = mutable.Map()
private[core] val executableMd5Cache: mutable.Map[String, String] = mutable.Map()
private[core] val executableCache: mutable.Map[String, String] = mutable.Map()
}
......@@ -23,6 +23,9 @@ import org.apache.log4j.Logger
import nl.lumc.sasc.biopet.{ FullVersion, LastCommitHash }
import nl.lumc.sasc.biopet.core.BiopetExecutable._
/**
* This is the main trait for the biopet executable
*/
trait BiopetExecutable extends Logging {
def pipelines: List[MainCommand]
......@@ -74,7 +77,7 @@ trait BiopetExecutable extends Logging {
def getCommand(module: String, name: String): MainCommand = {
checkModule(module)
val command = modules(module).find(p => p.commandName.toLowerCase == name.toLowerCase)
if (command == None) {
if (command.isEmpty) {
System.err.println(s"ERROR: command '$name' does not exist in module '$module'\n" + usage(module))
System.exit(1)
}
......@@ -82,22 +85,20 @@ trait BiopetExecutable extends Logging {
}
args match {
case Array("version") => {
case Array("version") =>
println("version: " + FullVersion)
}
case Array("license") => {
case Array("license") =>
println(getLicense)
}
case Array(module, name, passArgs @ _*) => {
case Array(module, name, passArgs @ _*) =>
try {
getCommand(module, name).main(passArgs.toArray)
} catch {
case e: Exception => {
case e: Exception =>
val sWriter = new StringWriter()
val pWriter = new PrintWriter(sWriter)
e.printStackTrace(pWriter)
pWriter.close()
val trace = (sWriter.toString.split("\n"))
val trace = sWriter.toString.split("\n")
if (!logger.isDebugEnabled) {
trace.filterNot(_.startsWith("\tat")).foreach(logger.error(_))
......@@ -106,20 +107,17 @@ trait BiopetExecutable extends Logging {
trace.foreach(logger.debug(_))
}
sys.exit(1)
}
}
}
case Array(module) => {
case Array(module) =>
System.err.println(usage(module))
sys.exit(1)
}
case _ => {
case _ =>
System.err.println(usage())
sys.exit(1)
}
}
}
/** This function checks if current build is based on a dirty repository (uncommitted changes) */
def checkDirtyBuild(logger: Logger): Unit =
if (LastCommitHash.endsWith("-dirty")) {
logger.warn("***********************************************************")
......
......@@ -33,17 +33,17 @@ trait BiopetJavaCommandLineFunction extends JavaCommandLineFunction with BiopetC
/** Creates command to execute extension */
override def commandLine: String = {
preCmdInternal
preCmdInternal()
val cmd = super.commandLine
val finalCmd = executable + cmd.substring(cmd.indexOf(" "))
return cmd
cmd
}
def javaVersionCommand: String = executable + " -version"
def getJavaVersion: Option[String] = {
if (!BiopetCommandLineFunctionTrait.executableCache.contains(executable))
preProcesExecutable
preProcessExecutable()
if (!BiopetCommandLineFunctionTrait.versionCache.contains(javaVersionCommand))
getVersionInternal(javaVersionCommand, """java version "(.*)"""".r) match {
case Some(version) => BiopetCommandLineFunctionTrait.versionCache += javaVersionCommand -> version
......
......@@ -16,14 +16,15 @@
package nl.lumc.sasc.biopet.core
import java.io.File
import java.io.PrintWriter
import nl.lumc.sasc.biopet.core.config.{ ConfigValueIndex, Config, Configurable }
import nl.lumc.sasc.biopet.core.report.{ ReportBuilderExtension, ReportBuilder }
import org.broadinstitute.gatk.utils.commandline.Argument
import nl.lumc.sasc.biopet.core.config.Configurable
import nl.lumc.sasc.biopet.core.report.ReportBuilderExtension
import org.broadinstitute.gatk.queue.QSettings
import org.broadinstitute.gatk.queue.function.QFunction
import org.broadinstitute.gatk.queue.function.scattergather.ScatterGatherableFunction
import org.broadinstitute.gatk.queue.util.{ Logging => GatkLogging }
import org.broadinstitute.gatk.queue.util.{Logging => GatkLogging}
import org.broadinstitute.gatk.utils.commandline.Argument
import scala.collection.mutable.ListBuffer
/** Base for biopet pipeline */
......@@ -53,10 +54,10 @@ trait BiopetQScript extends Configurable with GatkLogging {
var functions: Seq[QFunction]
/** Init for pipeline */
def init
def init()
/** Pipeline itself */
def biopetScript
def biopetScript()
/** Returns the extension to make the report */
def reportClass: Option[ReportBuilderExtension] = None
......@@ -65,19 +66,18 @@ trait BiopetQScript extends Configurable with GatkLogging {
final def script() {
outputDir = config("output_dir")
outputDir = outputDir.getAbsoluteFile
init
biopetScript
init()
biopetScript()
if (disableScatter) for (function <- functions) function match {
case f: ScatterGatherableFunction => f.scatterCount = 1
case _ =>
}
for (function <- functions) function match {
case f: BiopetCommandLineFunctionTrait => {
f.preProcesExecutable
f.beforeGraph
case f: BiopetCommandLineFunctionTrait =>
f.preProcessExecutable()
f.beforeGraph()
f.commandLine
}
case _ =>
}
......@@ -87,7 +87,7 @@ trait BiopetQScript extends Configurable with GatkLogging {
reportClass.foreach(add(_))
BiopetQScript.checkErrors
BiopetQScript.checkErrors()
}
/** Get implemented from org.broadinstitute.gatk.queue.QScript */
......@@ -96,11 +96,7 @@ trait BiopetQScript extends Configurable with GatkLogging {
/** Get implemented from org.broadinstitute.gatk.queue.QScript */
def addAll(functions: scala.Traversable[org.broadinstitute.gatk.queue.function.QFunction])
/**
* Function to set isIntermediate and add in 1 line
* @param function
* @param isIntermediate
*/
/** Function to set isIntermediate and add in 1 line */
def add(function: QFunction, isIntermediate: Boolean = false) {
function.isIntermediate = isIntermediate
add(function)
......@@ -115,8 +111,8 @@ object BiopetQScript extends Logging {
errors.append(new Exception(msg))
}
protected def checkErrors: Unit = {
if (!errors.isEmpty) {
protected def checkErrors(): Unit = {
if (errors.nonEmpty) {
logger.error("*************************")
logger.error("Biopet found some errors:")
if (logger.isDebugEnabled) {
......
......@@ -17,10 +17,9 @@ package nl.lumc.sasc.biopet.core
import java.io.File
import nl.lumc.sasc.biopet.core.config.{ Config }
import nl.lumc.sasc.biopet.core.summary.{ SummaryQScript, Summarizable }
import nl.lumc.sasc.biopet.utils.ConfigUtils
import org.broadinstitute.gatk.utils.commandline.{ Argument }
import org.broadinstitute.gatk.utils.commandline.Argument
/** This trait creates a structured way of use multisample pipelines */
trait MultiSampleQScript extends SummaryQScript {
......@@ -107,11 +106,7 @@ trait MultiSampleQScript extends SummaryQScript {
}
}
/**
* Creates a sample file with given suffix
* @param suffix
* @return
*/
/** Creates a sample file with given suffix */
def createFile(suffix: String) = new File(sampleDir, sampleId + suffix)
/** Returns sample directory */
......@@ -158,14 +153,14 @@ trait MultiSampleQScript extends SummaryQScript {
/** Prefix full path with sample and library for jobs that's are created in current state */
override protected[core] def configFullPath: List[String] = {
val s = currentSample match {
val sample = currentSample match {
case Some(s) => "samples" :: s :: Nil
case _ => Nil
}
val l = currentLib match {
val lib = currentLib match {
case Some(l) => "libraries" :: l :: Nil
case _ => Nil
}
s ::: l ::: super.configFullPath
sample ::: lib ::: super.configFullPath
}
}
......@@ -15,12 +15,12 @@
*/
package nl.lumc.sasc.biopet.core
import org.apache.log4j.{ PatternLayout, Appender, WriterAppender, FileAppender }
import org.broadinstitute.gatk.queue.util.{ Logging => GatkLogging }
import java.io.{ PrintWriter, File }
import java.io.{File, PrintWriter}
import nl.lumc.sasc.biopet.core.config.Config
import nl.lumc.sasc.biopet.core.workaround.BiopetQCommandLine
import scala.collection.JavaConversions._
import org.apache.log4j.{PatternLayout, WriterAppender}
import org.broadinstitute.gatk.queue.util.{Logging => GatkLogging}
/** Wrapper around executable from Queue */
trait PipelineCommand extends MainCommand with GatkLogging {
......@@ -33,7 +33,7 @@ trait PipelineCommand extends MainCommand with GatkLogging {
/** Class can be used directly from java with -cp option */
def main(args: Array[String]): Unit = {
val argsSize = args.size
val argsSize = args.length
for (t <- 0 until argsSize) {
if (args(t) == "-config" || args(t) == "--config_file") {
if (t >= argsSize) throw new IllegalStateException("-config needs a value")
......
......@@ -7,10 +7,14 @@ import nl.lumc.sasc.biopet.core.config.Configurable
import scala.collection.JavaConversions._
/**
* This trait is used for pipelines and extension that use a reference based on one fasta file.
* The fasta file can contain multiple contigs.
*
* Created by pjvan_thof on 4/6/15.
*/
trait Reference extends Configurable {
/** Returns species, default to unknown_species */
def referenceSpecies: String = {
root match {
case r: Reference if r.referenceSpecies != "unknown_species" => r.referenceSpecies
......@@ -18,16 +22,17 @@ trait Reference extends Configurable {
}
}
/** Return referencename, default to unknown_ref */
def referenceName: String = {
root match {
case r: Reference if r.referenceName != "unknown_ref" => r.referenceName
case _ => {
case _ =>
val default: String = config("default", default = "unknown_ref", path = List("references", referenceSpecies))
config("reference_name", default = default, path = super.configPath)
}
}
}
/** All config values will get a prefix */
override def subPath = {
referenceConfigPath ::: super.subPath
}
......@@ -37,8 +42,10 @@ trait Reference extends Configurable {
List("references", referenceSpecies, referenceName)
}
/** When set override this on true the pipeline with raise an exception when fai index is not found */
protected def faiRequired = false
/** When set override this on true the pipeline with raise an exception when dict index is not found */
protected def dictRequired = false
/** Returns the fasta file */
......
......@@ -36,20 +36,18 @@ trait ToolCommand extends MainCommand with Logging {
case "error" => logger.setLevel(org.apache.log4j.Level.ERROR)
case _ =>
}
} text ("Log level") validate { x =>
x match {
case "debug" | "info" | "warn" | "error" => success
case _ => failure("Log level must be <debug/info/warn/error>")
}
} text "Log level" validate {
case "debug" | "info" | "warn" | "error" => success
case _ => failure("Log level must be <debug/info/warn/error>")
}
opt[Unit]('h', "help") foreach { _ =>
System.err.println(this.usage)
sys.exit(1)
} text ("Print usage")
} text "Print usage"
opt[Unit]('v', "version") foreach { _ =>
System.err.println("Version: " + FullVersion)
sys.exit(1)
} text ("Print version")
} text "Print version"
}
protected type Args <: AbstractArgs
......
......@@ -17,8 +17,6 @@ package nl.lumc.sasc.biopet.core.summary
import java.io.File
import nl.lumc.sasc.biopet.core.config.Configurable
/**
* Trait for class to let them accept into a Summary
*
......@@ -40,7 +38,7 @@ trait Summarizable {
* @param v1 Value of new map
* @param v2 Value of old map
* @param key Key of value
* @return
* @return combined value
*/
def resolveSummaryConflict(v1: Any, v2: Any, key: String): Any = {
throw new IllegalStateException("Merge can not have same key by default")
......
......@@ -5,6 +5,8 @@ import java.io.File
import nl.lumc.sasc.biopet.utils.ConfigUtils
/**
* This class can read in a summary and extract values from it
*
* Created by pjvan_thof on 3/26/15.
*/
class Summary(file: File) {
......@@ -12,7 +14,7 @@ class Summary(file: File) {
lazy val samples: Set[String] = {
ConfigUtils.getValueFromPath(map, List("samples")) match {
case Some(samples) => ConfigUtils.any2map(samples).keySet
case Some(s) => ConfigUtils.any2map(s).keySet
case _ => Set()
}
}
......
......@@ -23,6 +23,8 @@ import nl.lumc.sasc.biopet.extensions.Md5sum
import scala.collection.mutable
/**
* This trait is used for qscript / pipelines that will produce a summary
*
* Created by pjvan_thof on 2/14/15.
*/
trait SummaryQScript extends BiopetQScript {
......@@ -65,7 +67,7 @@ trait SummaryQScript extends BiopetQScript {
*
* @param summarizable summarizable to add to summary for this pipeline
* @param name Name of module
* @param sampleId
* @param sampleId Id of sample
*/
def addSummarizable(summarizable: Summarizable, name: String, sampleId: Option[String]): Unit = {
addSummarizable(summarizable, name, sampleId, None)
......@@ -76,24 +78,21 @@ trait SummaryQScript extends BiopetQScript {
*
* @param summarizable summarizable to add to summary for this pipeline
* @param name Name of module
* @param sampleId
* @param libraryId
* @param sampleId Id of sample
* @param libraryId Id of libary
*/
def addSummarizable(summarizable: Summarizable, name: String, sampleId: Option[String], libraryId: Option[String]): Unit = {
if (libraryId.isDefined) require(sampleId.isDefined) // Library always require a sample
summarizables += (name, sampleId, libraryId) -> (summarizable :: summarizables.getOrElse((name, sampleId, libraryId), Nil))
}
/**
* Add an other qscript to merge in output summary
* @param summaryQScript
*/
/** Add an other qscript to merge in output summary */
def addSummaryQScript(summaryQScript: SummaryQScript): Unit = {
summaryQScripts :+= summaryQScript
}
/** Add jobs to qscript to execute summary, also add checksum jobs */
def addSummaryJobs: Unit = {
def addSummaryJobs(): Unit = {
val writeSummary = new WriteSummary(this)
def addChecksum(file: File): Unit = {
......@@ -119,7 +118,7 @@ trait SummaryQScript extends BiopetQScript {
for ((_, summarizableList) <- summarizables; summarizable <- summarizableList) {
summarizable match {
case f: BiopetCommandLineFunctionTrait => f.beforeGraph
case f: BiopetCommandLineFunctionTrait => f.beforeGraph()
case _ =>
}
}
......@@ -141,8 +140,7 @@ trait SummaryQScript extends BiopetQScript {
}
object SummaryQScript {
import scala.collection.mutable.Map
/** Cache to have no duplicate jobs */
protected[summary] val md5sumCache: Map[File, File] = Map()
protected[summary] val md5sumCache: mutable.Map[File, File] = mutable.Map()
}
\ No newline at end of file
package nl.lumc.sasc.biopet.core.summary
import java.math.BigDecimal
/**
* This case class is used for easy access and calculations on those values
*
* Created by pjvan_thof on 4/23/15.
*/
case class SummaryValue(val value: Option[Any]) {
case class SummaryValue(value: Option[Any]) {
def this(path: List[String],
summary: Summary,
......@@ -18,6 +18,7 @@ case class SummaryValue(val value: Option[Any]) {