Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArgumentsBuilder in Mutect2 pipeline tool tests #6219

Merged
merged 1 commit into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.apache.commons.math3.random.RandomGenerator;
import org.apache.commons.math3.random.RandomGeneratorFactory;
import org.broadinstitute.hellbender.CommandLineProgramTest;
import org.broadinstitute.hellbender.testutils.ArgumentsBuilder;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -87,11 +88,11 @@ public void testArtificialData(final boolean includeHomAlts) {
final File contaminationTable = createTempFile("contamination", ".table");
final File segmentationsTable = createTempFile("segments", ".table");

final String[] args = {
"-I", psTable.getAbsolutePath(),
"-O", contaminationTable.getAbsolutePath(),
"-" + CalculateContamination.TUMOR_SEGMENTATION_SHORT_NAME, segmentationsTable.getAbsolutePath()
};
final ArgumentsBuilder args = new ArgumentsBuilder()
.addInput(psTable)
.addOutput(contaminationTable)
.addFileArgument(CalculateContamination.TUMOR_SEGMENTATION_SHORT_NAME, segmentationsTable);

runCommandLine(args);

final double calculatedContamination = ContaminationRecord.readFromFile(contaminationTable).get(0).getContamination();
Expand All @@ -111,10 +112,10 @@ public void testSpikeIn(final File pileupSummary, final double spikeIn, final do
final File contaminationTable = createTempFile("contamination", ".table");
final double contamination = spikeIn + baselineContamination;

final String[] args = {
"-I", pileupSummary.getAbsolutePath(),
"-O", contaminationTable.getAbsolutePath(),
};
final ArgumentsBuilder args = new ArgumentsBuilder()
.addInput(pileupSummary)
.addOutput(contaminationTable);

runCommandLine(args);

final double calculatedContamination = ContaminationRecord.readFromFile(contaminationTable).get(0).getContamination();
Expand All @@ -141,12 +142,11 @@ public void testMatchedNormal() {
final double contamination = 0.08 + baselineContamination;
final File contaminationTable = createTempFile("contamination", ".table");

final ArgumentsBuilder args = new ArgumentsBuilder()
.addInput(contaminated)
.addFileArgument(CalculateContamination.MATCHED_NORMAL_SHORT_NAME, normal)
.addOutput(contaminationTable);

final String[] args = {
"-I", contaminated.getAbsolutePath(),
"-" + CalculateContamination.MATCHED_NORMAL_SHORT_NAME, normal.getAbsolutePath(),
"-O", contaminationTable.getAbsolutePath(),
};
runCommandLine(args);

final double calculatedContamination = ContaminationRecord.readFromFile(contaminationTable).get(0).getContamination();
Expand All @@ -158,10 +158,10 @@ public void testSmallGenePanelWithNoHomAlts() {
final File inputPileups = new File(CONTAMINATION_TEST_DATA_DIRECTORY, "small_gene_panel.pileups");
final File contaminationTable = createTempFile("contamination", ".table");

final String[] args = {
"-I", inputPileups.getAbsolutePath(),
"-O", contaminationTable.getAbsolutePath(),
};
final ArgumentsBuilder args = new ArgumentsBuilder()
.addInput(inputPileups)
.addOutput(contaminationTable);

runCommandLine(args);

final double calculatedContamination = ContaminationRecord.readFromFile(contaminationTable).get(0).getContamination();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.broadinstitute.hellbender.CommandLineProgramTest;
import org.broadinstitute.hellbender.exceptions.UserException;
import org.broadinstitute.hellbender.testutils.ArgumentsBuilder;
import org.testng.Assert;
import org.testng.annotations.Test;

Expand All @@ -18,13 +19,14 @@ public class GetPileupSummariesIntegrationTest extends CommandLineProgramTest {
@Test
public void test() {
final File output = createTempFile("output", ".table");
final String[] args = {
"-I", NA12878.getAbsolutePath(),
"-V", thousandGenomes,
"-L", thousandGenomes,
"-O", output.getAbsolutePath(),
"-" + GetPileupSummaries.MAX_SITE_AF_SHORT_NAME, "0.9"
};

final ArgumentsBuilder args = new ArgumentsBuilder()
.addInput(NA12878)
.addVCF(new File(thousandGenomes))
.addIntervalFile(new File(thousandGenomes))
.addOutput(output)
.addNumericArgument(GetPileupSummaries.MAX_SITE_AF_SHORT_NAME, 0.9);

runCommandLine(args);

final ImmutablePair<String, List<PileupSummary>> sampleAndResult = PileupSummary.readFromFile(output);
Expand Down Expand Up @@ -67,12 +69,13 @@ public void test() {
public void testNoAFFieldInHeader() {
final File vcfWithoutAF = new File(publicTestDir, "empty.vcf");
final File output = createTempFile("output", ".table");
final String[] args = {
"-I", NA12878.getAbsolutePath(),
"-V", vcfWithoutAF.getAbsolutePath(),
"-L", vcfWithoutAF.getAbsolutePath(),
"-O", output.getAbsolutePath(),
};

final ArgumentsBuilder args = new ArgumentsBuilder()
.addInput(NA12878)
.addVCF(vcfWithoutAF)
.addIntervalFile(vcfWithoutAF)
.addOutput(output);

runCommandLine(args);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.broadinstitute.hellbender.tools.walkers.mutect;

import org.broadinstitute.hellbender.CommandLineProgramTest;
import org.broadinstitute.hellbender.testutils.ArgumentsBuilder;
import org.testng.Assert;
import org.testng.annotations.Test;

Expand All @@ -24,9 +25,11 @@ public void simpleTest() {
MutectStats.writeToFile(stats1, statsFile1);
MutectStats.writeToFile(stats2, statsFile2);

final List<String> args = Arrays.asList("--" + Mutect2.MUTECT_STATS_SHORT_NAME, statsFile1.getAbsolutePath(),
"--" + Mutect2.MUTECT_STATS_SHORT_NAME, statsFile2.getAbsolutePath(),
"-O", merged.getAbsolutePath());
final ArgumentsBuilder args = new ArgumentsBuilder()
.addFileArgument(Mutect2.MUTECT_STATS_SHORT_NAME, statsFile1)
.addFileArgument(Mutect2.MUTECT_STATS_SHORT_NAME, statsFile2)
.addOutput(merged);

runCommandLine(args);

final List<MutectStats> mergedStats = MutectStats.readFromFile(merged);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
import org.broadinstitute.hellbender.engine.FeatureDataSource;
import org.broadinstitute.hellbender.testutils.ArgumentsBuilder;
import org.broadinstitute.hellbender.tools.walkers.SplitIntervals;
import org.broadinstitute.hellbender.tools.walkers.haplotypecaller.AssemblyBasedCallerArgumentCollection;
import org.broadinstitute.hellbender.tools.walkers.mutect.filtering.FilterMutectCalls;
import org.broadinstitute.hellbender.tools.walkers.mutect.Mutect2;
import org.broadinstitute.hellbender.tools.walkers.mutect.filtering.M2FiltersArgumentCollection;
import org.broadinstitute.hellbender.utils.SimpleInterval;
import org.broadinstitute.hellbender.utils.io.IOUtils;
import org.broadinstitute.hellbender.utils.variant.GATKVCFConstants;
import org.testng.Assert;
Expand Down Expand Up @@ -47,30 +49,29 @@ public void testOnRealBam(final int scatterCount) throws IOException {

// Step 1: SplitIntervals
final File intervalDir = createTempDir("intervals");
runCommandLine(
Arrays.asList(
"-R", b37_reference_20_21,
"-L", intervalList,
"-O", intervalDir.getAbsolutePath(),
"-" + SplitIntervals.SCATTER_COUNT_SHORT_NAME, Integer.toString(scatterCount)),
SplitIntervals.class.getSimpleName());

final ArgumentsBuilder splitIntervalsArgs = new ArgumentsBuilder()
.addReference(b37Reference)
.addIntervalFile(new File(intervalList))
.addOutput(intervalDir)
.addNumericArgument(SplitIntervals.SCATTER_COUNT_SHORT_NAME, scatterCount);

runCommandLine(splitIntervalsArgs, SplitIntervals.class.getSimpleName());

// Step 2: CollectF1R2Counts
final File[] intervals = intervalDir.listFiles();
final List<File> extractedDirs = IntStream.range(0, intervals.length).mapToObj(i -> createTempDir("extracted_" + i)).collect(Collectors.toList());
final List<File> scatteredTarGzs = IntStream.range(0, intervals.length).mapToObj(i -> new File(scatteredDir, "scatter_" + i + ".tar.gz")).collect(Collectors.toList());
for (int i = 0; i < intervals.length; i++){

runCommandLine(Arrays.asList(
"-R", b37_reference_20_21,
"-I", hapmapBamSnippet,
"-L", intervals[i].getAbsolutePath(),
"-O", scatteredTarGzs.get(i).getAbsolutePath()),
CollectF1R2Counts.class.getSimpleName());
final ArgumentsBuilder collectF1R2CountsArgs = new ArgumentsBuilder()
.addReference(b37Reference)
.addInput(new File(hapmapBamSnippet))
.addIntervalFile(intervals[i])
.addOutput(scatteredTarGzs.get(i));

runCommandLine(collectF1R2CountsArgs, CollectF1R2Counts.class.getSimpleName());
IOUtils.extractTarGz(scatteredTarGzs.get(i).toPath(), extractedDirs.get(i).toPath());

final int iFinal = i;
final File refHist = F1R2CountsCollector.getRefHistogramsFromExtractedTar(extractedDirs.get(i)).get(0);

// Ensure that we print every bin, even when the count is 0
Expand All @@ -80,9 +81,9 @@ public void testOnRealBam(final int scatterCount) throws IOException {

// Step 3: LearnReadOrientationModel
final File priorTarGz = createTempFile("prior", ".tar.gz");
final ArgumentsBuilder args = new ArgumentsBuilder();
args.addArgument(StandardArgumentDefinitions.OUTPUT_LONG_NAME, priorTarGz.getAbsolutePath());
IntStream.range(0, intervals.length).forEach(n -> args.addArgument(StandardArgumentDefinitions.INPUT_LONG_NAME, scatteredTarGzs.get(n).getAbsolutePath()));
final ArgumentsBuilder args = new ArgumentsBuilder()
.addOutput(priorTarGz);
IntStream.range(0, intervals.length).forEach(n -> args.addInput(scatteredTarGzs.get(n)));

runCommandLine(args.getArgsList(), LearnReadOrientationModel.class.getSimpleName());

Expand All @@ -97,22 +98,20 @@ public void testOnRealBam(final int scatterCount) throws IOException {
final File filteredVcf = GATKBaseTest.createTempFile("filtered", ".vcf");
final File bamout = GATKBaseTest.createTempFile("SM-CEMAH", ".bam");

new Main().instanceMain(makeCommandLineArgs(
Arrays.asList(
"-I", hapmapBamSnippet,
"-R", b37_reference_20_21,
"-O", unfilteredVcf.getAbsolutePath(),
"-bamout", bamout.getAbsolutePath()),
Mutect2.class.getSimpleName()));
final ArgumentsBuilder mutect2Args = new ArgumentsBuilder()
.addReference(b37Reference)
.addInput(new File(hapmapBamSnippet))
.addOutput(unfilteredVcf)
.addFileArgument(AssemblyBasedCallerArgumentCollection.BAM_OUTPUT_LONG_NAME, bamout);
runCommandLine(mutect2Args, Mutect2.class.getSimpleName());

new Main().instanceMain(makeCommandLineArgs(
Arrays.asList(
"-V", unfilteredVcf.getAbsolutePath(),
"-R", b37_reference_20_21,
"--" + M2FiltersArgumentCollection.ARTIFACT_PRIOR_TABLE_NAME, priorTarGz.getAbsolutePath(),
"-O", filteredVcf.getAbsolutePath()),
FilterMutectCalls.class.getSimpleName()));
final ArgumentsBuilder filterArgs = new ArgumentsBuilder()
.addReference(b37Reference)
.addVCF(unfilteredVcf)
.addFileArgument(M2FiltersArgumentCollection.ARTIFACT_PRIOR_TABLE_NAME, priorTarGz)
.addOutput(filteredVcf);

runCommandLine(filterArgs, FilterMutectCalls.class.getSimpleName());

// These artifacts have been verified manually
// The pair is of type (Position, Expected Source of Prior Probability)
Expand Down Expand Up @@ -152,7 +151,7 @@ public void testTwoSamples() throws Exception {
.addArgument(StandardArgumentDefinitions.INPUT_LONG_NAME, countsTarGz.getAbsolutePath())
.addArgument(StandardArgumentDefinitions.OUTPUT_LONG_NAME, priorsTarGz.getAbsolutePath());

runCommandLine(args.getArgsList(), LearnReadOrientationModel.class.getSimpleName());
runCommandLine(args, LearnReadOrientationModel.class.getSimpleName());

final File extractedPriorsDir = createTempDir("extracted");
IOUtils.extractTarGz(priorsTarGz.toPath(), extractedPriorsDir.toPath());
Expand All @@ -168,24 +167,23 @@ public void testFewSites() throws IOException {
final File extractedDir = createTempDir("extracted");
final File scatteredTarGz = createTempFile("counts", ".tar.gz");

final ArgumentsBuilder collectF1R2Args = new ArgumentsBuilder()
.addReference(b37Reference)
.addInput(new File(hapmapBamSnippet))
.addInterval(new SimpleInterval("20:10000-10001"))
.addOutput(scatteredTarGz);

runCommandLine(Arrays.asList(
"-R", b37_reference_20_21,
"-I", hapmapBamSnippet,
"-L", "20:10000-10001",
"-O", scatteredTarGz.getAbsolutePath()),
CollectF1R2Counts.class.getSimpleName());
runCommandLine(collectF1R2Args, CollectF1R2Counts.class.getSimpleName());

IOUtils.extractTarGz(scatteredTarGz.toPath(), extractedDir.toPath());


// Step 2: LearnReadOrientationModel
final File priorTarGz = createTempFile("prior", ".tar.gz");
final ArgumentsBuilder args = new ArgumentsBuilder()
.addArgument(StandardArgumentDefinitions.OUTPUT_LONG_NAME, priorTarGz.getAbsolutePath())
.addArgument(StandardArgumentDefinitions.INPUT_LONG_NAME, scatteredTarGz.getAbsolutePath());
.addInput(scatteredTarGz)
.addOutput(priorTarGz);

runCommandLine(args.getArgsList(), LearnReadOrientationModel.class.getSimpleName());
runCommandLine(args, LearnReadOrientationModel.class.getSimpleName());

final File extractedPriorDir = createTempDir("extracted_priors");
IOUtils.extractTarGz(priorTarGz.toPath(), extractedPriorDir.toPath());
Expand All @@ -197,22 +195,21 @@ public void testFewSites() throws IOException {
final File filteredVcf = GATKBaseTest.createTempFile("filtered", ".vcf");
final File bamout = GATKBaseTest.createTempFile("SM-CEMAH", ".bam");

new Main().instanceMain(makeCommandLineArgs(
Arrays.asList(
"-I", hapmapBamSnippet,
"-R", b37_reference_20_21,
"-L", "20:24000000-26000000",
"-O", unfilteredVcf.getAbsolutePath(),
"-bamout", bamout.getAbsolutePath()),
Mutect2.class.getSimpleName()));

new Main().instanceMain(makeCommandLineArgs(
Arrays.asList(
"-V", unfilteredVcf.getAbsolutePath(),
"-R", b37_reference_20_21,
"--" + M2FiltersArgumentCollection.ARTIFACT_PRIOR_TABLE_NAME, priorTarGz.getAbsolutePath(),
"-O", filteredVcf.getAbsolutePath()),
FilterMutectCalls.class.getSimpleName()));

final ArgumentsBuilder mutect2Args = new ArgumentsBuilder()
.addReference(b37Reference)
.addInput(new File(hapmapBamSnippet))
.addInterval(new SimpleInterval("20:24000000-26000000"))
.addFileArgument(AssemblyBasedCallerArgumentCollection.BAM_OUTPUT_LONG_NAME, bamout)
.addOutput(unfilteredVcf);
runCommandLine(mutect2Args, Mutect2.class.getSimpleName());

final ArgumentsBuilder filterArgs = new ArgumentsBuilder()
.addReference(b37Reference)
.addVCF(unfilteredVcf)
.addFileArgument(M2FiltersArgumentCollection.ARTIFACT_PRIOR_TABLE_NAME, priorTarGz)
.addOutput(filteredVcf);

runCommandLine(filterArgs, FilterMutectCalls.class.getSimpleName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ public ArgumentsBuilder addInterval(Locatable interval){
return this;
}

public ArgumentsBuilder addIntervalFile(final File interval){
return addFileArgument("L", interval);
}

public ArgumentsBuilder addMask(final File mask){
return addFileArgument(IntervalArgumentCollection.EXCLUDE_INTERVALS_LONG_NAME, mask);
}
Expand Down