From 633aa4a29840dcacae71d89e70ff3995b20b126d Mon Sep 17 00:00:00 2001 From: Chris Norman Date: Fri, 23 Dec 2022 15:18:45 -0500 Subject: [PATCH] Don't require python to just instantiate tool classes. (#8128) * Don't require python to just instantiate tool classes. --- .../hellbender/tools/walkers/vqsr/CNNScoreVariants.java | 8 +++++--- .../hellbender/tools/walkers/vqsr/CNNVariantTrain.java | 6 ++++-- .../tools/walkers/vqsr/CNNVariantWriteTensors.java | 7 +++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/broadinstitute/hellbender/tools/walkers/vqsr/CNNScoreVariants.java b/src/main/java/org/broadinstitute/hellbender/tools/walkers/vqsr/CNNScoreVariants.java index c9741cc38dc..a17da13b0cf 100644 --- a/src/main/java/org/broadinstitute/hellbender/tools/walkers/vqsr/CNNScoreVariants.java +++ b/src/main/java/org/broadinstitute/hellbender/tools/walkers/vqsr/CNNScoreVariants.java @@ -205,9 +205,7 @@ public class CNNScoreVariants extends TwoPassVariantWalker { @Argument(fullName = "python-profile", shortName = "python-profile", doc = "Run the tool with the Python CProfiler on and write results to this file.", optional = true) private File pythonProfileResults; - // Create the Python executor. This doesn't actually start the Python process, but verifies that - // the requestedPython executable exists and can be located. - final StreamingPythonScriptExecutor pythonExecutor = new StreamingPythonScriptExecutor<>(true); + private StreamingPythonScriptExecutor pythonExecutor; private List batchList = new ArrayList<>(inferenceBatchSize); @@ -284,6 +282,10 @@ public void onTraversalStart() { } } + // Create the Python executor. This doesn't actually start the Python process, but verifies that + // the requestedPython executable exists and can be located. + pythonExecutor = new StreamingPythonScriptExecutor<>(true); + final VCFHeader inputHeader = getHeaderForVariants(); if (inputHeader.getGenotypeSamples().size() > 1) { logger.warn("CNNScoreVariants is a single sample tool but the input VCF has more than 1 sample."); diff --git a/src/main/java/org/broadinstitute/hellbender/tools/walkers/vqsr/CNNVariantTrain.java b/src/main/java/org/broadinstitute/hellbender/tools/walkers/vqsr/CNNVariantTrain.java index 169bbe72096..7bb60d7477f 100644 --- a/src/main/java/org/broadinstitute/hellbender/tools/walkers/vqsr/CNNVariantTrain.java +++ b/src/main/java/org/broadinstitute/hellbender/tools/walkers/vqsr/CNNVariantTrain.java @@ -129,17 +129,19 @@ public class CNNVariantTrain extends CommandLineProgram { @Argument(fullName = "annotation-set", shortName = "annotation-set", doc = "Which set of annotations to use.", optional = true) private String annotationSet = "best_practices"; - // Start the Python executor. This does not actually start the Python process, but fails if python can't be located - final PythonScriptExecutor pythonExecutor = new PythonScriptExecutor(true); + private PythonScriptExecutor pythonExecutor; @Override protected void onStartup() { PythonScriptExecutor.checkPythonEnvironmentForPackage("vqsr_cnn"); + // Start the Python executor. This does not actually start the Python process, but fails if python can't be located + pythonExecutor = new PythonScriptExecutor(true); } @Override protected Object doWork() { + final Resource pythonScriptResource = new Resource("training.py", CNNVariantTrain.class); List arguments = new ArrayList<>(Arrays.asList( "--data_dir", inputTensorDir, diff --git a/src/main/java/org/broadinstitute/hellbender/tools/walkers/vqsr/CNNVariantWriteTensors.java b/src/main/java/org/broadinstitute/hellbender/tools/walkers/vqsr/CNNVariantWriteTensors.java index 58618b831f5..0fd0ec79e17 100644 --- a/src/main/java/org/broadinstitute/hellbender/tools/walkers/vqsr/CNNVariantWriteTensors.java +++ b/src/main/java/org/broadinstitute/hellbender/tools/walkers/vqsr/CNNVariantWriteTensors.java @@ -117,16 +117,19 @@ public class CNNVariantWriteTensors extends CommandLineProgram { @Argument(fullName = "max-tensors", shortName = "max-tensors", doc = "Maximum number of tensors to write.", optional = true, minValue = 0) private int maxTensors = 1000000; - // Start the Python executor. This does not actually start the Python process, but fails if python can't be located - final PythonScriptExecutor pythonExecutor = new PythonScriptExecutor(true); + private PythonScriptExecutor pythonExecutor; @Override protected void onStartup() { PythonScriptExecutor.checkPythonEnvironmentForPackage("vqsr_cnn"); + + // Start the Python executor. This does not actually start the Python process, but fails if python can't be located + pythonExecutor = new PythonScriptExecutor(true); } @Override protected Object doWork() { + final Resource pythonScriptResource = new Resource("training.py", CNNVariantWriteTensors.class); List arguments = new ArrayList<>(Arrays.asList( "--reference_fasta", reference,