BiopetExecutable.scala 2.88 KB
Newer Older
1
2
3
4
package nl.lumc.sasc.biopet.core

object BiopetExecutable {

Peter van 't Hof's avatar
Peter van 't Hof committed
5
6
7
8
9
10
11
12
13
14
15
16
17
  val modules: Map[String, List[MainCommand]] = Map(
    "pipeline" -> List(
      nl.lumc.sasc.biopet.pipelines.flexiprep.Flexiprep,
      nl.lumc.sasc.biopet.pipelines.mapping.Mapping,
      nl.lumc.sasc.biopet.pipelines.gentrap.Gentrap,
      nl.lumc.sasc.biopet.pipelines.bammetrics.BamMetrics,
      nl.lumc.sasc.biopet.pipelines.gatk.GatkBenchmarkGenotyping,
      nl.lumc.sasc.biopet.pipelines.gatk.GatkGenotyping,
      nl.lumc.sasc.biopet.pipelines.gatk.GatkVariantcalling,
      nl.lumc.sasc.biopet.pipelines.gatk.GatkPipeline,
      nl.lumc.sasc.biopet.pipelines.gatk.GatkVariantRecalibration,
      nl.lumc.sasc.biopet.pipelines.gatk.GatkVcfSampleCompare,
      nl.lumc.sasc.biopet.pipelines.sage.Sage,
Peter van 't Hof's avatar
Peter van 't Hof committed
18
19
      nl.lumc.sasc.biopet.pipelines.basty.Basty,
      nl.lumc.sasc.biopet.pipelines.yamsvp.Yamsvp),
Peter van 't Hof's avatar
Peter van 't Hof committed
20
    "tool" -> List(
Peter van 't Hof's avatar
Peter van 't Hof committed
21
22
      nl.lumc.sasc.biopet.tools.WipeReads,
      nl.lumc.sasc.biopet.tools.BiopetFlagstat,
Peter van 't Hof's avatar
Peter van 't Hof committed
23
      nl.lumc.sasc.biopet.tools.CheckAllelesVcfInBam,
Peter van 't Hof's avatar
Peter van 't Hof committed
24
25
      nl.lumc.sasc.biopet.tools.VcfToTsv,
      nl.lumc.sasc.biopet.tools.VcfFilter)
Peter van 't Hof's avatar
Peter van 't Hof committed
26
27
  )
  
28
29
30
31
  /**
   * @param args the command line arguments
   */
  def main(args: Array[String]): Unit = {
bow's avatar
bow committed
32

bow's avatar
bow committed
33
    def toBulletedList(m: List[MainCommand], kind: String = "", bullet: String = "-") =
Peter van 't Hof's avatar
Peter van 't Hof committed
34
      "Available %ss:\n  ".format(kind) + bullet + " " + m.map(x => x.commandName).sorted.mkString("\n  " + bullet + " ")
Peter van 't Hof's avatar
Peter van 't Hof committed
35

wyleung's avatar
wyleung committed
36
    def usage(module: String = null): String = {
Peter van 't Hof's avatar
Peter van 't Hof committed
37
38
39
40
41
42
      if (module != null) checkModule(module)
      val usage: String = {
        val set = if (module == null) modules.keySet else Set(module)
        val u = for (m <- set) yield toBulletedList(modules(m), m)
        u.mkString("\n\n")
      }
bow's avatar
bow committed
43
      """
Peter van 't Hof's avatar
Peter van 't Hof committed
44
        |Usage: java -jar BiopetFramework.jar {%s} <name> [args]
bow's avatar
bow committed
45
46
47
        |
        |%s
        |
Peter van 't Hof's avatar
Peter van 't Hof committed
48
        |Questions or comments? Email sasc@lumc.nl or check out the project page at https://git.lumc.nl/biopet/biopet.git
wyleung's avatar
wyleung committed
49
      """.stripMargin.format(modules.keys.mkString(","), usage)
50
    }
bow's avatar
bow committed
51

wyleung's avatar
wyleung committed
52
    def checkModule(module: String) {
Peter van 't Hof's avatar
Peter van 't Hof committed
53
      if (!modules.contains(module)) {
wyleung's avatar
wyleung committed
54
55
        System.err.println(s"ERROR: module '$module' does not exist\n" + usage())
        System.exit(1)
bow's avatar
bow committed
56
      }
57
    }
wyleung's avatar
wyleung committed
58
59

    def getCommand(module: String, name: String): MainCommand = {
Peter van 't Hof's avatar
Peter van 't Hof committed
60
      checkModule(module)
Peter van 't Hof's avatar
Peter van 't Hof committed
61
      val command = modules(module).find(p => p.commandName.toLowerCase == name.toLowerCase)
Peter van 't Hof's avatar
Peter van 't Hof committed
62
63
      if (command == None) {
        System.err.println(s"ERROR: command '$name' does not exist in module '$module'\n" + usage(module))
bow's avatar
bow committed
64
        System.exit(1)
Peter van 't Hof's avatar
Peter van 't Hof committed
65
66
67
      }
      return command.get
    }
wyleung's avatar
wyleung committed
68

Peter van 't Hof's avatar
Peter van 't Hof committed
69
70
    args match {
      case Array(module, name, passArgs @ _*) => {
wyleung's avatar
wyleung committed
71
        getCommand(module, name).main(passArgs.toArray)
Peter van 't Hof's avatar
Peter van 't Hof committed
72
73
      }
      case Array(module) => {
wyleung's avatar
wyleung committed
74
75
        System.err.println(usage(module))
        System.exit(1)
Peter van 't Hof's avatar
Peter van 't Hof committed
76
77
      }
      case _ => {
wyleung's avatar
wyleung committed
78
79
        System.err.println(usage())
        System.exit(1)
Peter van 't Hof's avatar
Peter van 't Hof committed
80
      }
81
82
83
    }
  }
}