2010-06-15 12:43:46 +08:00
|
|
|
package org.broadinstitute.sting.queue.function
|
|
|
|
|
|
|
|
|
|
import java.io.File
|
|
|
|
|
import org.broadinstitute.sting.queue.util._
|
|
|
|
|
import org.broadinstitute.sting.queue.engine.{CommandLineRunner, QGraph}
|
2010-06-23 02:39:20 +08:00
|
|
|
import java.lang.reflect.Field
|
2010-06-15 12:43:46 +08:00
|
|
|
|
2010-06-23 02:39:20 +08:00
|
|
|
trait CommandLineFunction extends InputOutputFunction with DispatchFunction {
|
2010-06-15 12:43:46 +08:00
|
|
|
/**
|
|
|
|
|
* Repeats parameters with a prefix/suffix if they are set otherwise returns "".
|
|
|
|
|
* Skips null, Nil, None. Unwraps Some(x) to x. Everything else is called with x.toString.
|
|
|
|
|
*/
|
|
|
|
|
protected def repeat(prefix: String, params: Seq[_], suffix: String = "", separator: String = "") =
|
|
|
|
|
params.filter(param => hasValue(param)).map(param => prefix + toValue(param) + suffix).mkString(separator)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns parameter with a prefix/suffix if it is set otherwise returns "".
|
|
|
|
|
* Does not output null, Nil, None. Unwraps Some(x) to x. Everything else is called with x.toString.
|
|
|
|
|
*/
|
|
|
|
|
protected def optional(prefix: String, param: Any, suffix: String = "") =
|
|
|
|
|
if (hasValue(param)) prefix + toValue(param) + suffix else ""
|
|
|
|
|
|
2010-06-23 02:39:20 +08:00
|
|
|
def missingValues = {
|
|
|
|
|
val missingInputs = missingFields(inputFields)
|
|
|
|
|
val missingOutputs = missingFields(outputFields)
|
2010-06-15 12:43:46 +08:00
|
|
|
missingInputs | missingOutputs
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-23 02:39:20 +08:00
|
|
|
private def missingFields(fields: List[Field]) = {
|
2010-06-15 12:43:46 +08:00
|
|
|
var missing = Set.empty[String]
|
2010-06-23 02:39:20 +08:00
|
|
|
for (field <- fields) {
|
|
|
|
|
val isOptional = ReflectionUtils.hasAnnotation(field, classOf[Optional])
|
2010-06-15 12:43:46 +08:00
|
|
|
if (!isOptional)
|
2010-06-23 02:39:20 +08:00
|
|
|
if (!hasValue(ReflectionUtils.getValue(this, field)))
|
|
|
|
|
missing += field.getName
|
2010-06-15 12:43:46 +08:00
|
|
|
}
|
|
|
|
|
missing
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-23 02:39:20 +08:00
|
|
|
protected def hasFieldValue(field: Field) = hasValue(this.getFieldValue(field))
|
|
|
|
|
|
2010-06-15 12:43:46 +08:00
|
|
|
private def hasValue(param: Any) = param match {
|
|
|
|
|
case null => false
|
|
|
|
|
case Nil => false
|
|
|
|
|
case None => false
|
|
|
|
|
case _ => true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private def toValue(param: Any): String = param match {
|
|
|
|
|
case null => ""
|
|
|
|
|
case Nil => ""
|
|
|
|
|
case None => ""
|
|
|
|
|
case Some(x) => x.toString
|
|
|
|
|
case x => x.toString
|
|
|
|
|
}
|
|
|
|
|
}
|