Skip to content
Snippets Groups Projects
Commit 9e5f2608 authored by bow's avatar bow
Browse files

Improve main command line interface

parent 46cfaf0e
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,7 @@ import nl.lumc.sasc.biopet.pipelines.sage.Sage
object BiopetExecutable {
val pipelines: Map[String,PipelineCommand] = Map(
val pipelines: Map[String, PipelineCommand] = Map(
"flexiprep" -> Flexiprep,
"mapping" -> Mapping,
"gentrap" -> Gentrap,
......@@ -29,25 +29,80 @@ object BiopetExecutable {
"sage" -> Sage,
"basty" -> Basty
)
val tools: Map[String, ToolCommand] = Map(
)
/**
* @param args the command line arguments
*/
def main(args: Array[String]): Unit = {
def toBulletedList(m: Map[String, Any], kind: String = "", bullet: String = "-") =
"Available %s:\n ".format(kind) + bullet + " " +
m.keys.toVector.sorted.mkString("\n " + bullet + " ")
lazy val pipelineList: String = toBulletedList(pipelines, "pipelines")
lazy val toolList: String = toBulletedList(tools, "tools")
lazy val addendum: String =
"""Questions or comments? Email sasc@lumc.nl or check out the project page at https://git.lumc.nl/biopet/biopet.git"""".stripMargin
lazy val baseUsage: String =
"""
|Usage: java -jar BiopetFramework.jar {pipeline,tool} {pipeline/tool name} {pipeline/tool-specific options}
|
|%s
|
|%s
""".stripMargin.format("%s", addendum)
lazy val mainUsage: String =
baseUsage.format(pipelineList + "\n\n" + toolList)
lazy val pipelineUsage: String = baseUsage
.replaceFirst("""\{pipeline,tool\}""", "pipeline")
.replace("""pipeline/tool""", "pipeline")
.format(pipelineList)
lazy val toolUsage: String = baseUsage
.replaceFirst("""\{pipeline,tool\}""", "tool")
.replace("""pipeline/tool""", "tool")
.format(toolList)
if (args.isEmpty) {
System.err.println(pipelineList)
System.err.println(mainUsage)
System.exit(1)
}
else if (pipelines.contains(args.head)) pipelines(args.head).main(args.tail)
else {
System.err.println("Pipeline '" + args.head + "' does not exist")
System.err.println(pipelineList)
System.exit(1)
}
def pipelineList: String = {
val pipelinesArray = for ((k,v) <- pipelines) yield k
"Available pipelines:" + pipelinesArray.mkString("\n- ", "\n- ", "\n") + "please supply a valid pipeline"
args match {
case Array("pipeline", pipelineName, pipelineArgs @ _*) =>
if (pipelines.contains(pipelineName))
if (pipelineArgs.isEmpty)
pipelines(pipelineName).main(Array("--help"))
else
pipelines(pipelineName).main(pipelineArgs.toArray)
else
System.err.println(s"ERROR: pipeline '$pipelineName' does not exist")
System.err.println(pipelineUsage)
System.exit(1)
case Array("pipeline") =>
System.err.println(pipelineUsage)
System.exit(1)
case Array("tool", toolName, toolArgs @ _*) =>
if (tools.contains(toolName))
tools(toolName).main(toolArgs.toArray)
else
System.err.println(s"ERROR: tool '$toolName' does not exist")
System.err.println(toolUsage)
System.exit(1)
case Array("tool") =>
System.err.println(toolUsage)
System.exit(1)
case _ =>
println(mainUsage)
System.exit(1)
}
}
}
......@@ -7,9 +7,8 @@ trait PipelineCommand extends Logging {
def main(args: Array[String]): Unit = {
var argv: Array[String] = Array()
//argv ++= Array("-S", tempFile.getAbsolutePath)
argv ++= Array("-S", pipeline)
argv ++= args
return BiopetQCommandLine.main(argv)
BiopetQCommandLine.main(argv)
}
}
\ No newline at end of file
package nl.lumc.sasc.biopet.core
import org.broadinstitute.gatk.queue.util.Logging
abstract trait ToolCommand extends Logging {
lazy val toolName = this.getClass.getName
.split("\\$").last.split("\\.").last
def main(args: Array[String])
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment