PythonCommandLineFunction.scala 1.94 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/**
 * Biopet is built on top of GATK Queue for building bioinformatic
 * pipelines. It is mainly intended to support LUMC SHARK cluster which is running
 * SGE. But other types of HPC that are supported by GATK Queue (such as PBS)
 * should also be able to execute Biopet tools and pipelines.
 *
 * Copyright 2014 Sequencing Analysis Support Core - Leiden University Medical Center
 *
 * Contact us at: sasc@lumc.nl
 *
 * A dual licensing mode is applied. The source code within this project that are
 * not part of GATK Queue is freely available for non-commercial use under an AGPL
 * license; For commercial users or users who do not want to follow the AGPL
 * license, please contact us to obtain a separate license.
 */
16
package nl.lumc.sasc.biopet.extensions
17
18
19

import java.io.FileOutputStream
import java.io.File
bow's avatar
bow committed
20
import org.broadinstitute.gatk.utils.commandline.{ Input }
Peter van 't Hof's avatar
Peter van 't Hof committed
21
import nl.lumc.sasc.biopet.core.BiopetCommandLineFunction
22
23
24
import scala.collection.JavaConversions._

trait PythonCommandLineFunction extends BiopetCommandLineFunction {
bow's avatar
bow committed
25
  @Input(doc = "Python script", required = false)
26
  var python_script: File = _
bow's avatar
bow committed
27
28
29
30

  executable = config("exe", default = "python", submodule = "python")

  protected var python_script_name: String = _
Wai Yi Leung's avatar
Wai Yi Leung committed
31
32
33
34
35
36
37
38
  def setPythonScript(script: String) {
    python_script = new File(script)
    if (!python_script.exists()) {
      setPythonScript(script, "")
    } else {
      python_script_name = script
    }
  }
bow's avatar
bow committed
39
  def setPythonScript(script: String, subpackage: String) {
40
41
42
43
44
45
46
47
    python_script_name = script
    python_script = new File(".queue/tmp/" + subpackage + python_script_name)
    if (!python_script.getParentFile.exists) python_script.getParentFile.mkdirs
    val is = getClass.getResourceAsStream(subpackage + python_script_name)
    val os = new FileOutputStream(python_script)
    org.apache.commons.io.IOUtils.copy(is, os)
    os.close()
  }
bow's avatar
bow committed
48
49

  def getPythonCommand(): String = {
Peter van 't Hof's avatar
Peter van 't Hof committed
50
    required(executable) + required(python_script)
51
52
  }
}