use of org.broadinstitute.hellbender.utils.runtime.ProcessSettings in project gatk by broadinstitute.
the class RScriptExecutor method exec.
public boolean exec() {
if (!RSCRIPT_EXISTS) {
if (!ignoreExceptions) {
throw new UserException.CannotExecuteRScript(RSCRIPT_MISSING_MESSAGE);
} else {
logger.warn("Skipping: " + getApproximateCommandLine());
return false;
}
}
List<File> tempFiles = new ArrayList<>();
try {
File tempLibSourceDir = IOUtils.tempDir("RlibSources.", "");
File tempLibInstallationDir = IOUtils.tempDir("Rlib.", "");
tempFiles.add(tempLibSourceDir);
tempFiles.add(tempLibInstallationDir);
StringBuilder expression = new StringBuilder("tempLibDir = '").append(tempLibInstallationDir).append("';");
if (!this.libraries.isEmpty()) {
List<String> tempLibraryPaths = new ArrayList<>();
for (RScriptLibrary library : this.libraries) {
File tempLibrary = library.writeLibrary(tempLibSourceDir);
tempFiles.add(tempLibrary);
tempLibraryPaths.add(tempLibrary.getAbsolutePath());
}
expression.append("install.packages(");
expression.append("pkgs=c('").append(StringUtils.join(tempLibraryPaths, "', '")).append("'), lib=tempLibDir, repos=NULL, type='source', ");
// Install faster by eliminating cruft.
expression.append("INSTALL_opts=c('--no-libs', '--no-data', '--no-help', '--no-demo', '--no-exec')");
expression.append(");");
for (RScriptLibrary library : this.libraries) {
expression.append("library('").append(library.getLibraryName()).append("', lib.loc=tempLibDir);");
}
}
for (Resource script : this.scriptResources) {
File tempScript = IOUtils.writeTempResource(script);
tempFiles.add(tempScript);
expression.append("source('").append(tempScript.getAbsolutePath()).append("');");
}
for (File script : this.scriptFiles) {
expression.append("source('").append(script.getAbsolutePath()).append("');");
}
String[] cmd = new String[this.args.size() + 3];
int i = 0;
cmd[i++] = RSCRIPT_BINARY;
cmd[i++] = "-e";
cmd[i++] = expression.toString();
for (String arg : this.args) cmd[i++] = arg;
ProcessSettings processSettings = new ProcessSettings(cmd);
//if debug is enabled, output the stdout and stdder, otherwise capture it to a buffer
if (logger.isDebugEnabled()) {
processSettings.getStdoutSettings().printStandard(true);
processSettings.getStderrSettings().printStandard(true);
} else {
processSettings.getStdoutSettings().setBufferSize(8192);
processSettings.getStderrSettings().setBufferSize(8192);
}
ProcessController controller = ProcessController.getThreadLocal();
if (logger.isDebugEnabled()) {
logger.debug("Executing:");
for (String arg : cmd) logger.debug(" " + arg);
}
ProcessOutput po = controller.exec(processSettings);
int exitValue = po.getExitValue();
logger.debug("Result: " + exitValue);
if (exitValue != 0) {
StringBuilder message = new StringBuilder();
message.append(String.format("\nRscript exited with %d\nCommand Line: %s", exitValue, String.join(" ", cmd)));
//if debug was enabled the stdout/error were already output somewhere
if (!logger.isDebugEnabled()) {
message.append(String.format("\nStdout: %s\nStderr: %s", po.getStdout().getBufferString(), po.getStderr().getBufferString()));
}
throw new RScriptExecutorException(message.toString());
}
return true;
} catch (GATKException e) {
if (!ignoreExceptions) {
throw e;
} else {
logger.warn(e.getMessage());
return false;
}
} finally {
for (File temp : tempFiles) FileUtils.deleteQuietly(temp);
}
}
use of org.broadinstitute.hellbender.utils.runtime.ProcessSettings in project gatk by broadinstitute.
the class GenotypeGVCFsIntegrationTest method runProcess.
private static void runProcess(ProcessController processController, String[] command) {
final ProcessSettings prs = new ProcessSettings(command);
prs.getStderrSettings().printStandard(true);
prs.getStdoutSettings().printStandard(true);
final ProcessOutput output = processController.exec(prs);
Assert.assertEquals(output.getExitValue(), 0, "Process exited with non-zero value. Command: " + Arrays.toString(command) + "\n");
}
use of org.broadinstitute.hellbender.utils.runtime.ProcessSettings in project gatk-protected by broadinstitute.
the class GenotypeGVCFsIntegrationTest method runProcess.
private static void runProcess(ProcessController processController, String[] command) {
final ProcessSettings prs = new ProcessSettings(command);
prs.getStderrSettings().printStandard(true);
prs.getStdoutSettings().printStandard(true);
final ProcessOutput output = processController.exec(prs);
Assert.assertEquals(output.getExitValue(), 0, "Process exited with non-zero value. Command: " + Arrays.toString(command) + "\n");
}
Aggregations