1 package org.broadinstitute.hellbender.tools.spark.pipelines; 2 3 import org.apache.commons.io.FileUtils; 4 import org.broadinstitute.hellbender.CommandLineProgramTest; 5 import org.broadinstitute.hellbender.testutils.ArgumentsBuilder; 6 import org.testng.Assert; 7 import org.testng.annotations.DataProvider; 8 import org.testng.annotations.Test; 9 10 import java.io.ByteArrayOutputStream; 11 import java.io.File; 12 import java.io.PrintStream; 13 import java.nio.charset.StandardCharsets; 14 15 public final class CountVariantsSparkIntegrationTest extends CommandLineProgramTest { 16 17 public static final File COUNT_VARIANTS_VCF = new File(getTestDataDir(), "count_variants.vcf"); 18 19 @Override getTestedClassName()20 public String getTestedClassName() { 21 return CountVariantsSpark.class.getSimpleName(); 22 } 23 24 @Test(dataProvider = "filenames", groups = "spark") test(final File fileIn, final long expected)25 public void test(final File fileIn, final long expected) throws Exception { 26 final File outputTxt = createTempFile("count_variants", ".txt"); 27 ArgumentsBuilder args = new ArgumentsBuilder(); 28 args.addVCF(fileIn); 29 args.addOutput(outputTxt); 30 this.runCommandLine(args.getArgsArray()); 31 32 final String readIn = FileUtils.readFileToString(outputTxt.getAbsoluteFile(), StandardCharsets.UTF_8); 33 Assert.assertEquals((int)Integer.valueOf(readIn), expected); 34 } 35 36 @DataProvider(name="filenames") filenames()37 public Object[][] filenames() { 38 return new Object[][]{ 39 {COUNT_VARIANTS_VCF, 26L}, 40 {new File(getTestDataDir(), "count_variants.blockgz.gz"), 26L}, 41 {new File(dbsnp_138_b37_1_65M_vcf), 1375319L}, 42 }; 43 } 44 45 @DataProvider(name="intervals") intervals()46 public Object[][] intervals(){ 47 File vcf = new File(largeFileTestDir, "dbsnp_138.b37.20.21.vcf"); 48 File vcf_gz = new File(largeFileTestDir, "dbsnp_138.b37.20.21.vcf.blockgz.gz"); 49 return new Object[][]{ 50 new Object[]{vcf, "", 9594L}, // no intervals specified 51 new Object[]{vcf, "-L 20", 5657L}, 52 new Object[]{vcf, "-L 20:10200000-11000000", 933L}, 53 new Object[]{vcf, "-L 21", 3937L}, 54 new Object[]{vcf, "-L 20 -L 21", 9594L}, 55 new Object[]{vcf, "-XL 20", 3937L}, 56 new Object[]{vcf_gz, "", 9594L}, // no intervals specified 57 new Object[]{vcf_gz, "-L 20", 5657L}, 58 new Object[]{vcf_gz, "-L 20:10200000-11000000", 933L}, 59 new Object[]{vcf_gz, "-L 21", 3937L}, 60 new Object[]{vcf_gz, "-L 20 -L 21", 9594L}, 61 new Object[]{vcf_gz, "-XL 20", 3937L}, 62 }; 63 } 64 65 @Test(dataProvider = "intervals", groups = "spark") testCountVariantsWithIntervals(final File fileIn, final String intervalArgs, final long expected)66 public void testCountVariantsWithIntervals(final File fileIn, final String intervalArgs, final long expected) throws Exception { 67 final File outputTxt = createTempFile("count_variants", ".txt"); 68 ArgumentsBuilder args = new ArgumentsBuilder(); 69 args.addVCF(fileIn); 70 args.addRaw(intervalArgs); 71 args.addReference(new File(largeFileTestDir, "human_g1k_v37.20.21.fasta")); 72 args.addOutput(outputTxt); 73 this.runCommandLine(args.getArgsArray()); 74 75 final ByteArrayOutputStream baosErr = new ByteArrayOutputStream(); 76 final PrintStream err = System.err; 77 try { 78 System.setErr(new PrintStream(baosErr)); 79 80 this.runCommandLine(args.getArgsArray()); 81 82 final String readIn = FileUtils.readFileToString(outputTxt.getAbsoluteFile(), StandardCharsets.UTF_8); 83 Assert.assertEquals((int)Integer.valueOf(readIn), expected); 84 String errString = baosErr.toString(); 85 Assert.assertFalse(errString.contains("Warning: using GzipCodec, which is not splittable,"), errString); 86 } finally { 87 System.setErr(err); //put this back in 88 } 89 } 90 91 @Test(groups = "spark") testNoNPRWhenOutputIsUnspecified()92 public void testNoNPRWhenOutputIsUnspecified(){ 93 ArgumentsBuilder args = new ArgumentsBuilder(); 94 args.addVCF(COUNT_VARIANTS_VCF); 95 this.runCommandLine(args.getArgsArray()); 96 } 97 } 98