Class PythonScriptExecutor


public class PythonScriptExecutor extends PythonExecutorBase
Generic service for executing Python Scripts.
  • All tools that use PythonScriptExecutor must have a Java-based front-end, with standard GATK (Barclay-based) arguments.
  • Minimize the amount of code written in Python -- as much of each tool's work as possible should be done in Java. In particular, reading/writing final inputs and outputs should happen in Java. This is important to ensure the goal of universal GCS support, consistent Google authentication handling, etc.
  • The names of any files that are created by Python code should be passed in to the python code from Java.
  • All dependencies (Python and native) of Python libraries used should be clearly documented, and included in the default GATK docker image.
NOTE: Serial executions on the same PythonScriptExecutor are each run in a new process. No python state is retained between command/script/module execution. Using -i doesn't buy you anything (for this version of the executor, at least) since the process is terminated after each command completes.
  • Constructor Details

    • PythonScriptExecutor

      public PythonScriptExecutor(boolean ensureExecutableExists)
      Parameters:
      ensureExecutableExists - throw if the python executable cannot be located
    • PythonScriptExecutor

      public PythonScriptExecutor(PythonExecutorBase.PythonExecutableName pythonExecutableName, boolean ensureExecutableExists)
      Parameters:
      pythonExecutableName - name of the python executable to start
      ensureExecutableExists - throw if the python executable cannot be found
  • Method Details

    • executeCommand

      public boolean executeCommand(String command, List<String> pythonProcessArgs, List<String> scriptArgs)
      Execute a python command (-c). No intermediate shell is created.
      Parameters:
      command - python command to be executed
      pythonProcessArgs - args to be passed to the python process
      scriptArgs - args to be passed to the python code
      Returns:
      true if the command succeeds, otherwise false
    • executeModule

      public boolean executeModule(String moduleName, List<String> pythonProcessArgs, List<String> scriptArgs)
      Execute a python module (-m). Modules must be on sys.path
      Parameters:
      moduleName - name of the module to execute
      pythonProcessArgs - args to be passed to the python process
      scriptArgs - args to be passed to the python code
      Returns:
      true if the command succeeds, otherwise false
    • executeScriptAndGetOutput

      public ProcessOutput executeScriptAndGetOutput(Resource scriptResource, List<String> pythonProcessArgs, List<String> scriptArgs)
      Execute a python script from a Resource file and get process output.
      Parameters:
      scriptResource - Resource for the script to execute
      pythonProcessArgs - args to be passed to the python process
      scriptArgs - args to be passed to the python code
      Returns:
      process output of executed Python process
    • executeScript

      public boolean executeScript(Resource scriptResource, List<String> pythonProcessArgs, List<String> scriptArgs)
      Execute a python script from a Resource file.
      Parameters:
      scriptResource - Resource for the script to execute
      pythonProcessArgs - args to be passed to the python process
      scriptArgs - args to be passed to the python code
      Returns:
      true if the command succeeds, otherwise false
    • executeScriptAndGetOutput

      public ProcessOutput executeScriptAndGetOutput(String scriptName, List<String> pythonProcessArgs, List<String> scriptArgs)
      Execute a python script.
      Parameters:
      scriptName - full path name of the script to execute
      pythonProcessArgs - args to be passed to the python process
      scriptArgs - args to be passed to the python code
      Returns:
      process output of executed Python process
    • executeScript

      public boolean executeScript(String scriptName, List<String> pythonProcessArgs, List<String> scriptArgs)
      Execute a python script.
      Parameters:
      scriptName - full path name of the script to execute
      pythonProcessArgs - args to be passed to the python process
      scriptArgs - args to be passed to the python code
      Returns:
      true if the command succeeds
    • executeArgsAndGetOutput

      public ProcessOutput executeArgsAndGetOutput(List<String> rawArgs)
      Executes the Python executor using the values in rawArgs
      Parameters:
      rawArgs - raw command line arguments to be passed to the Python process
      Returns:
      process output of executed Python process
    • executeArgs

      public boolean executeArgs(List<String> rawArgs)
      Executes the Python executor using the values in rawArgs
      Parameters:
      rawArgs - raw command line arguments to be passed to the Python process
      Returns:
      true if the command succeeds, otherwise false
    • getApproximateCommandLine

      public String getApproximateCommandLine()
      Return a (not necessarily executable) string representing the current command line for this executor for error reporting purposes.
      Specified by:
      getApproximateCommandLine in class PythonExecutorBase
      Returns:
      Command line string.
    • checkPythonEnvironmentForPackage

      public static void checkPythonEnvironmentForPackage(String packageName)