Class PythonScriptExecutor
java.lang.Object
org.broadinstitute.hellbender.utils.runtime.ScriptExecutor
org.broadinstitute.hellbender.utils.python.PythonExecutorBase
org.broadinstitute.hellbender.utils.python.PythonScriptExecutor
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.broadinstitute.hellbender.utils.python.PythonExecutorBase
PythonExecutorBase.PythonExecutableName
-
Field Summary
Fields inherited from class org.broadinstitute.hellbender.utils.python.PythonExecutorBase
PYTHON_EXTENSION
Fields inherited from class org.broadinstitute.hellbender.utils.runtime.ScriptExecutor
externalScriptExecutableName, ignoreExceptions
-
Constructor Summary
ConstructorsConstructorDescriptionPythonScriptExecutor
(boolean ensureExecutableExists) PythonScriptExecutor
(PythonExecutorBase.PythonExecutableName pythonExecutableName, boolean ensureExecutableExists) -
Method Summary
Modifier and TypeMethodDescriptionstatic void
checkPythonEnvironmentForPackage
(String packageName) boolean
executeArgs
(List<String> rawArgs) Executes the Python executor using the values inrawArgs
executeArgsAndGetOutput
(List<String> rawArgs) Executes the Python executor using the values inrawArgs
boolean
Execute a python command (-c).boolean
Execute a python module (-m).boolean
Execute a python script.boolean
Execute a python script from a Resource file.executeScriptAndGetOutput
(String scriptName, List<String> pythonProcessArgs, List<String> scriptArgs) Execute a python script.executeScriptAndGetOutput
(Resource scriptResource, List<String> pythonProcessArgs, List<String> scriptArgs) Execute a python script from a Resource file and get process output.Return a (not necessarily executable) string representing the current command line for this executor for error reporting purposes.Methods inherited from class org.broadinstitute.hellbender.utils.python.PythonExecutorBase
getScriptException
Methods inherited from class org.broadinstitute.hellbender.utils.runtime.ScriptExecutor
executableMissing, executeCuratedArgs, executeCuratedArgsAndGetOutput, externalExecutableExists, getExceptionMessageFromScriptError, setIgnoreExceptions
-
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 startensureExecutableExists
- 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 executedpythonProcessArgs
- args to be passed to the python processscriptArgs
- 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 executepythonProcessArgs
- args to be passed to the python processscriptArgs
- 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 executepythonProcessArgs
- args to be passed to the python processscriptArgs
- 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 executepythonProcessArgs
- args to be passed to the python processscriptArgs
- 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 executepythonProcessArgs
- args to be passed to the python processscriptArgs
- 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 executepythonProcessArgs
- args to be passed to the python processscriptArgs
- args to be passed to the python code- Returns:
- true if the command succeeds
-
executeArgsAndGetOutput
Executes the Python executor using the values inrawArgs
- Parameters:
rawArgs
- raw command line arguments to be passed to the Python process- Returns:
- process output of executed Python process
-
executeArgs
Executes the Python executor using the values inrawArgs
- Parameters:
rawArgs
- raw command line arguments to be passed to the Python process- Returns:
- true if the command succeeds, otherwise false
-
getApproximateCommandLine
Return a (not necessarily executable) string representing the current command line for this executor for error reporting purposes.- Specified by:
getApproximateCommandLine
in classPythonExecutorBase
- Returns:
- Command line string.
-
checkPythonEnvironmentForPackage
-