Skip to content

Commit

Permalink
Added argument to disable RscriptExecutor but still output rscript fi…
Browse files Browse the repository at this point in the history
…le (#7900)

Fixes #7697. Added argument option to generate and output rscript file without running it.
  • Loading branch information
orlicohen authored Jun 24, 2022
1 parent e81a361 commit a28dfff
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,12 @@ public class VariantRecalibrator extends MultiVariantWalker {
@VisibleForTesting
protected int max_attempts = 1;

@Advanced
@Argument(fullName="dont-run-rscript",
doc="Disable the RScriptExecutor to allow RScript to be generated but not run",
optional=true)
private boolean disableRScriptExecutor = false;

/////////////////////////////
// Debug Arguments
/////////////////////////////
Expand Down Expand Up @@ -403,9 +409,9 @@ public void onTraversalStart() {
if (RSCRIPT_FILE != null) {
rScriptExecutor = new RScriptExecutor();
if(!rScriptExecutor.externalExecutableExists()) {
Utils.warnUser(logger, String.format(
"Rscript not found in environment path. %s will be generated but PDF plots will not.",
RSCRIPT_FILE));
if(!disableRScriptExecutor) {
throw new UserException("Rscript not found in environment path. Fix executor or run with --dont-run-rscript argument to generate rscript file without running.");
}
}
}

Expand Down Expand Up @@ -719,12 +725,14 @@ public Object onTraversalSuccess() {
//skip R plots for scattered tranches because the format is different and the R code parses them
logger.info("Tranches plot will not be generated since we are running in scattered mode");
} else if (RSCRIPT_FILE != null) { //we don't use the RSCRIPT_FILE for tranches, but here it's an indicator if we're setup to run R
// Execute the RScript command to plot the table of truth values
rScriptExecutor.addScript(new Resource(PLOT_TRANCHES_RSCRIPT, VariantRecalibrator.class));
rScriptExecutor.addArgs(TRANCHES_FILE.getAbsoluteFile(), TARGET_TITV);
// Print out the command line to make it clear to the user what is being executed and how one might modify it
logger.info("Executing: " + rScriptExecutor.getApproximateCommandLine());
rScriptExecutor.exec();
if(!disableRScriptExecutor) {
// Execute the RScript command to plot the table of truth values
rScriptExecutor.addScript(new Resource(PLOT_TRANCHES_RSCRIPT, VariantRecalibrator.class));
rScriptExecutor.addArgs(TRANCHES_FILE.getAbsoluteFile(), TARGET_TITV);
// Print out the command line to make it clear to the user what is being executed and how one might modify it
logger.info("Executing: " + rScriptExecutor.getApproximateCommandLine());
rScriptExecutor.exec();
}
}
return true;
}
Expand Down Expand Up @@ -1136,9 +1144,11 @@ private void createVisualizationScript(

// Execute Rscript command to generate the clustering plots
final RScriptExecutor executor = new RScriptExecutor();
executor.addScript(RSCRIPT_FILE);
logger.info("Executing: " + executor.getApproximateCommandLine());
executor.exec();
if(!disableRScriptExecutor) {
executor.addScript(RSCRIPT_FILE);
logger.info("Executing: " + executor.getApproximateCommandLine());
executor.exec();
}
}

// The Arrange function is how we place the 4 model plots on one page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
import org.broadinstitute.hellbender.CommandLineProgramTest;
import org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions;
import org.broadinstitute.hellbender.exceptions.UserException;
import org.broadinstitute.hellbender.testutils.ArgumentsBuilder;
import org.broadinstitute.hellbender.utils.Utils;
import org.broadinstitute.hellbender.testutils.IntegrationTestSpec;
import org.broadinstitute.hellbender.utils.io.IOUtils;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -31,6 +35,11 @@
*/
public class VariantRecalibratorIntegrationTest extends CommandLineProgramTest {

private final String tmpDir = createTempDir(this.getTestedClassName()).getAbsolutePath();
private final String modelReportFilename = tmpDir + "/snpSampledModel.report";
private final String modelReportRecal = getLargeVQSRTestDataDir() + "expected/snpSampledRecal.vcf";
private final String modelReportTranches = getLargeVQSRTestDataDir() + "expected/snpSampledTranches.txt";

private final String[] VQSRSNPParamsWithResources =
new String[] {
"--variant",
Expand Down Expand Up @@ -148,6 +157,23 @@ public class VariantRecalibratorIntegrationTest extends CommandLineProgramTest {
"--" + StandardArgumentDefinitions.ADD_OUTPUT_VCF_COMMANDLINE, "false"
};


final private String[] variantRecalibratorSamplingParams = {
" --variant " + getLargeVQSRTestDataDir() + "phase1.projectConsensus.chr20.1M-10M.raw.snps.vcf" +
" -L 20:1,000,000-10,000,000" +
" --resource:known,known=true,prior=10.0 " + getLargeVQSRTestDataDir() + "dbsnp_132_b37.leftAligned.20.1M-10M.vcf" +
" --resource:truth_training1,truth=true,training=true,prior=15.0 " + getLargeVQSRTestDataDir() + "sites_r27_nr.b37_fwd.20.1M-10M.vcf" +
" --resource:truth_training2,training=true,truth=true,prior=12.0 " + getLargeVQSRTestDataDir() + "Omni25_sites_1525_samples.b37.20.1M-10M.vcf" +
" -an QD -an HaplotypeScore -an HRun" +
" --trust-all-polymorphic" + // for speed
" --output %s" +
" -tranches-file %s" +
" --output-model " + modelReportFilename +
" -mode SNP --max-gaussians 3" + //reduce max gaussians so we have negative training data with the sampled input
" -sample-every 2" +
" --" + StandardArgumentDefinitions.ADD_OUTPUT_VCF_COMMANDLINE +" false"
};

@Override
public String getToolTestDataDir(){
return toolsTestDir + "walkers/VQSR/";
Expand Down Expand Up @@ -359,35 +385,41 @@ public void testBothAggregateRecalMode() throws IOException {
spec.executeTest("testBothRecalMode", this);
}

private final String tmpDir = createTempDir(this.getTestedClassName()).getAbsolutePath();
private final String modelReportFilename = tmpDir + "/snpSampledModel.report";
private final String modelReportRecal = getLargeVQSRTestDataDir() + "expected/snpSampledRecal.vcf";
private final String modelReportTranches = getLargeVQSRTestDataDir() + "expected/snpSampledTranches.txt";

@Test
public void testVariantRecalibratorSampling() throws IOException {
final String inputFile = getLargeVQSRTestDataDir() + "phase1.projectConsensus.chr20.1M-10M.raw.snps.vcf";
final String args = StringUtils.join(variantRecalibratorSamplingParams, " ");

final IntegrationTestSpec spec = new IntegrationTestSpec(
" --variant " + inputFile +
" -L 20:1,000,000-10,000,000" +
" --resource:known,known=true,prior=10.0 " + getLargeVQSRTestDataDir() + "dbsnp_132_b37.leftAligned.20.1M-10M.vcf" +
" --resource:truth_training1,truth=true,training=true,prior=15.0 " + getLargeVQSRTestDataDir() + "sites_r27_nr.b37_fwd.20.1M-10M.vcf" +
" --resource:truth_training2,training=true,truth=true,prior=12.0 " + getLargeVQSRTestDataDir() + "Omni25_sites_1525_samples.b37.20.1M-10M.vcf" +
" -an QD -an HaplotypeScore -an HRun" +
" --trust-all-polymorphic" + // for speed
" --output %s" +
" -tranches-file %s" +
" --output-model " + modelReportFilename +
" -mode SNP --max-gaussians 3" + //reduce max gaussians so we have negative training data with the sampled input
" -sample-every 2" +
" --" + StandardArgumentDefinitions.ADD_OUTPUT_VCF_COMMANDLINE +" false",
args,
Arrays.asList(
modelReportRecal,
modelReportTranches));
spec.executeTest("testVariantRecalibratorSampling"+ inputFile, this);
}


@Test
public void testVariantRecalibratorRScriptOutput() throws IOException {
final String inputFile = getLargeVQSRTestDataDir() + "phase1.projectConsensus.chr20.1M-10M.raw.snps.vcf";
final File unrunRscript = createTempFile("rscriptOutput", ".R");
final String args = StringUtils.join(variantRecalibratorSamplingParams, " ");

final IntegrationTestSpec spec = new IntegrationTestSpec(
args +
" --dont-run-rscript " +
" --rscript-file " + unrunRscript,
Arrays.asList(
modelReportRecal,
modelReportTranches));

spec.executeTest("testVariantRecalibratorRscriptOutput"+ inputFile, this);
Assert.assertTrue(Files.exists(IOUtils.fileToPath(unrunRscript)), "Rscript file was not generated.");
Assert.assertTrue(Files.size(IOUtils.fileToPath(unrunRscript)) > 0, "Rscript file was empty.");
}


@Test(dependsOnMethods = {"testVariantRecalibratorSampling"})
public void testVariantRecalibratorModelInput() throws IOException {
final String inputFile = getLargeVQSRTestDataDir() + "phase1.projectConsensus.chr20.1M-10M.raw.snps.vcf";
Expand Down

0 comments on commit a28dfff

Please sign in to comment.