gatk-3.8/public/scala/src/org/broadinstitute/sting/queue/QScript.scala

118 lines
4.5 KiB
Scala
Raw Normal View History

/*
* Copyright (c) 2011, The Broad Institute
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
package org.broadinstitute.sting.queue
import engine.JobRunInfo
import org.broadinstitute.sting.queue.function.QFunction
import annotation.target.field
import util.{StringFileConversions, PrimitiveOptionConversions, Logging}
/**
* Defines a Queue pipeline as a collection of CommandLineFunctions.
*/
trait QScript extends Logging with PrimitiveOptionConversions with StringFileConversions {
Walkers can now specify a class extending from Gatherer to merge custom output formats. Add @Gather(MyGatherer.class) to the walker @Output. JavaCommandLineFunctions can now specify the classpath+mainclass as an alternative to specifying a path to an executable jar. JCLF by default pass on the current classpath and only require the mainclass be specified by the developer extending the JCLF, relieving the QScript author from having to explicitly specify the jar. Like the Picard MergeSamFiles, GATK engine by default is now run from the current classpath. The GATK can still be overridden via .jarFile or .javaClasspath. Walkers from the GATK package are now also embedded into the Queue package. Updated AnalyzeCovariates to make it easier to guess the main class, AnalyzeCovariates instead of AnalyzeCovariatesCLP. Removed the GATK jar argument from the example QScripts. Removed one of the most FAQ when getting started with Scala/Queue, the use of Option[_] in QScripts: 1) Fixed mistaken assumption with java enums. In java enums can be null so they don't need nullable wrappers. 2) Added syntactic sugar for Nullable primitives to the QScript trait. Any variable defined as Option[Int] can just be assigned an Int value or None, ex: myFunc.memoryLimit = 3 Removed other unused code. Re-fixed dry run function ordering. Re-ordered the QCommandline companion object so that IntelliJ doesn't complain about missing main methods. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@5504 348d0f76-0448-11de-a6fe-93d51630548a
2011-03-24 22:03:51 +08:00
// Type aliases so users don't have to import
type File = java.io.File
type CommandLineFunction = org.broadinstitute.sting.queue.function.CommandLineFunction
type InProcessFunction = org.broadinstitute.sting.queue.function.InProcessFunction
type ScatterGatherableFunction = org.broadinstitute.sting.queue.function.scattergather.ScatterGatherableFunction
type SimpleTextGatherFunction = org.broadinstitute.sting.queue.function.scattergather.SimpleTextGatherFunction
// Make sure annotations can be used in class constructors but target the fields
// ex: class MyClass(@Input var myVar: File) {}
// This was implicitly enabled in 2.8.0-RC2 and then updated to this new syntax:
// http://lampsvn.epfl.ch/trac/scala/ticket/3596
// http://lampsvn.epfl.ch/trac/scala/ticket/3421
type Input = org.broadinstitute.sting.commandline.Input @field
type Output = org.broadinstitute.sting.commandline.Output @field
type Argument = org.broadinstitute.sting.commandline.Argument @field
type ArgumentCollection = org.broadinstitute.sting.commandline.ArgumentCollection @field
Walkers can now specify a class extending from Gatherer to merge custom output formats. Add @Gather(MyGatherer.class) to the walker @Output. JavaCommandLineFunctions can now specify the classpath+mainclass as an alternative to specifying a path to an executable jar. JCLF by default pass on the current classpath and only require the mainclass be specified by the developer extending the JCLF, relieving the QScript author from having to explicitly specify the jar. Like the Picard MergeSamFiles, GATK engine by default is now run from the current classpath. The GATK can still be overridden via .jarFile or .javaClasspath. Walkers from the GATK package are now also embedded into the Queue package. Updated AnalyzeCovariates to make it easier to guess the main class, AnalyzeCovariates instead of AnalyzeCovariatesCLP. Removed the GATK jar argument from the example QScripts. Removed one of the most FAQ when getting started with Scala/Queue, the use of Option[_] in QScripts: 1) Fixed mistaken assumption with java enums. In java enums can be null so they don't need nullable wrappers. 2) Added syntactic sugar for Nullable primitives to the QScript trait. Any variable defined as Option[Int] can just be assigned an Int value or None, ex: myFunc.memoryLimit = 3 Removed other unused code. Re-fixed dry run function ordering. Re-ordered the QCommandline companion object so that IntelliJ doesn't complain about missing main methods. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@5504 348d0f76-0448-11de-a6fe-93d51630548a
2011-03-24 22:03:51 +08:00
type Gather = org.broadinstitute.sting.commandline.Gather @field
/**
* Default settings for QFunctions
*/
var qSettings: QSettings = _
/**
* Builds the CommandLineFunctions that will be used to run this script and adds them to this.functions directly or using the add() utility method.
*/
def script()
/**
* A default handler for the onExecutionDone() function. By default this doesn't do anything
*/
def onExecutionDone(jobs: Map[QFunction, JobRunInfo], success: Boolean) {
}
/**
* The command line functions that will be executed for this QScript.
*/
var functions = Seq.empty[QFunction]
/**
* Exchanges the extension on a file.
* @param file File to look for the extension.
* @param oldExtension Old extension to strip off, if present.
* @param newExtension New extension to append.
* @return new File with the new extension in the current directory.
*/
protected def swapExt(file: File, oldExtension: String, newExtension: String) =
new File(file.getName.stripSuffix(oldExtension) + newExtension)
/**
* Exchanges the extension on a file.
* @param dir New directory for the file.
* @param file File to look for the extension.
* @param oldExtension Old extension to strip off, if present.
* @param newExtension New extension to append.
* @return new File with the new extension in dir.
*/
protected def swapExt(dir: File, file: File, oldExtension: String, newExtension: String) =
new File(dir, file.getName.stripSuffix(oldExtension) + newExtension)
/**
* Adds one or more command line functions to be run.
* @param functions Functions to add.
*/
def add(functions: QFunction*) {
functions.foreach(function => function.addOrder = QScript.nextAddOrder)
this.functions ++= functions
}
def addAll(functions: Seq[QFunction]) {
functions.foreach( f => add(f) )
}
}
object QScript {
private var addOrder = 0
private def nextAddOrder = {
addOrder += 1
Seq(addOrder)
}
}