diff --git a/src/test/java/org/broadinstitute/hellbender/tools/walkers/conversion/GtfToBedIntegrationTest.java b/src/test/java/org/broadinstitute/hellbender/tools/walkers/conversion/GtfToBedIntegrationTest.java index 599fd1b7347..4f4792ed668 100644 --- a/src/test/java/org/broadinstitute/hellbender/tools/walkers/conversion/GtfToBedIntegrationTest.java +++ b/src/test/java/org/broadinstitute/hellbender/tools/walkers/conversion/GtfToBedIntegrationTest.java @@ -1,148 +1,78 @@ package org.broadinstitute.hellbender.tools.walkers.conversion; import org.broadinstitute.hellbender.CommandLineProgramTest; -import org.broadinstitute.hellbender.testutils.ArgumentsBuilder; +import org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions; import org.broadinstitute.hellbender.testutils.IntegrationTestSpec; -import org.testng.Assert; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import java.io.*; +import java.util.ArrayList; +import java.util.List; public class GtfToBedIntegrationTest extends CommandLineProgramTest { - final File outputFile = createTempFile("outputBed", ".bed"); - - private static final File mapk1 = new File(ConversionTestUtils.getMapk1Gtf()); - private static final File decoys = new File(ConversionTestUtils.getDecoySampleGtf()); - private static final File manyTranscripts = new File(ConversionTestUtils.getManyTranscriptsGtf()); - private static final File mouse = new File(ConversionTestUtils.getMouseGtf()); - private static final File mouseDictionary = new File(ConversionTestUtils.getMouseDict()); - private static final File dictionary = new File(ConversionTestUtils.getReferenceDict()); - private static final File expectedDecoysGeneBed = new File(ConversionTestUtils.getDecoySamplesGeneBed()); - private static final File expectedDecoysTranscriptBed = new File(ConversionTestUtils.getDecoySamplesTranscriptBed()); - private static final File expectedMapk1GeneBed = new File(ConversionTestUtils.getMapk1GeneBed()); - private static final File expectedMapk1TranscriptBed = new File(ConversionTestUtils.getMapk1TranscriptBed()); - private static final File expectedManyTranscriptsBed = new File (ConversionTestUtils.getManyTranscriptsBed()); - private static final File expectedNotBasicBed = new File(ConversionTestUtils.getNotBasicBed()); - private static final File expectedMouseBed = new File(ConversionTestUtils.getMouseBed()); - - // tests specifically mapk1 gene - @Test - public void testMapk1Gene() throws IOException { - runMapk1(false); - } - - // tests transcripts in mapk1 gene - @Test - public void testMapk1Transcript() throws IOException { - runMapk1(true); - } - - // tests a sample of decoy genes (gene) - decoy = any gene that doesn't start with "chr" - @Test - public void testDecoyGenes() throws IOException { - runDecoySample(false); - } - - // tests a sample of decoy genes (transcript) - @Test - public void testDecoyTranscripts() throws IOException { - runDecoySample(true); - } - - // tests a gene with many transcripts and a gene in another chr - @Test - public void testManyTranscripts() throws IOException { - runManyTranscripts(); - } - - @Test - public void testNotBasic() throws IOException { - runNotBasic(); - } - - @Test - public void testMouse() throws IOException { - runMouse(); - } - - private void runMapk1(boolean transcript) throws IOException { - final ArgumentsBuilder argsBuilder = new ArgumentsBuilder() - .add(GtfToBed.INPUT_LONG_NAME, mapk1) - .add(GtfToBed.SEQUENCE_DICTIONARY_LONG_NAME, dictionary) - .add(GtfToBed.SORT_BY_TRANSCRIPT_LONG_NAME, transcript) - .add(GtfToBed.SORT_BY_BASIC_LONG_NAME, true) - .addOutput(outputFile); - runCommandLine(argsBuilder); - - if (transcript) { - Assert.assertEquals(countLines(outputFile), 3); - IntegrationTestSpec.assertEqualTextFiles(expectedMapk1TranscriptBed, outputFile); - } else { - Assert.assertEquals(countLines(outputFile), 1); - IntegrationTestSpec.assertEqualTextFiles(expectedMapk1GeneBed, outputFile); - } - } - - private void runDecoySample(boolean transcript) throws IOException { - final ArgumentsBuilder argsBuilder = new ArgumentsBuilder() - .add(GtfToBed.INPUT_LONG_NAME, decoys) - .add(GtfToBed.SEQUENCE_DICTIONARY_LONG_NAME, dictionary) - .add(GtfToBed.SORT_BY_TRANSCRIPT_LONG_NAME, transcript) - .add(GtfToBed.SORT_BY_BASIC_LONG_NAME, true) - .addOutput(outputFile); - countLines(outputFile); - runCommandLine(argsBuilder); - - if (transcript) { - Assert.assertEquals(countLines(outputFile), 20); - IntegrationTestSpec.assertEqualTextFiles(expectedDecoysTranscriptBed, outputFile); - - } else { - Assert.assertEquals(countLines(outputFile), 19); - IntegrationTestSpec.assertEqualTextFiles(expectedDecoysGeneBed, outputFile); + private static final String mapk1 = ConversionTestUtils.getMapk1Gtf(); + private static final String decoys = ConversionTestUtils.getDecoySampleGtf(); + private static final String manyTranscripts = ConversionTestUtils.getManyTranscriptsGtf(); + private static final String mouse = ConversionTestUtils.getMouseGtf(); + private static final String mouseDictionary = ConversionTestUtils.getMouseDict(); + private static final String dictionary = ConversionTestUtils.getReferenceDict(); + private static final String expectedDecoysGeneBed = ConversionTestUtils.getDecoySamplesGeneBed(); + private static final String expectedDecoysTranscriptBed = ConversionTestUtils.getDecoySamplesTranscriptBed(); + private static final String expectedMapk1GeneBed = ConversionTestUtils.getMapk1GeneBed(); + private static final String expectedMapk1TranscriptBed = ConversionTestUtils.getMapk1TranscriptBed(); + private static final String expectedManyTranscriptsBed = ConversionTestUtils.getManyTranscriptsBed(); + private static final String expectedNotBasicBed = ConversionTestUtils.getNotBasicBed(); + private static final String expectedMouseBed = ConversionTestUtils.getMouseBed(); + + private static class GtfToBedTest { + final String input; + final String SD; + final String transcript; + final String basic; + final String expected; + + private GtfToBedTest(String input, String SD, String transcript, String basic, String expected) { + this.input = input; + this.SD = SD; + this.transcript = transcript; + this.basic = basic; + this.expected = expected; } } - private void runManyTranscripts() throws IOException { - final ArgumentsBuilder argsBuilder = new ArgumentsBuilder() - .add(GtfToBed.INPUT_LONG_NAME, manyTranscripts) - .add(GtfToBed.SEQUENCE_DICTIONARY_LONG_NAME, dictionary) - .add(GtfToBed.SORT_BY_TRANSCRIPT_LONG_NAME, true) - .add(GtfToBed.SORT_BY_BASIC_LONG_NAME, true) - .addOutput(outputFile); - runCommandLine(argsBuilder); - IntegrationTestSpec.assertEqualTextFiles(expectedManyTranscriptsBed, outputFile); - - } - - private void runNotBasic() throws IOException { - final ArgumentsBuilder argsBuilder = new ArgumentsBuilder() - .add(GtfToBed.INPUT_LONG_NAME, manyTranscripts) - .add(GtfToBed.SEQUENCE_DICTIONARY_LONG_NAME, dictionary) - .add(GtfToBed.SORT_BY_TRANSCRIPT_LONG_NAME, true) - .add(GtfToBed.SORT_BY_BASIC_LONG_NAME, false) - .addOutput(outputFile); - runCommandLine(argsBuilder); - IntegrationTestSpec.assertEqualTextFiles(expectedNotBasicBed, outputFile); + @DataProvider(name = "GtfToBedTestProvider") + public Object[][] equalRangeData() { + List tests = new ArrayList<>(); + tests.add(new Object[]{new GtfToBedTest(mapk1, dictionary, String.valueOf(false), String.valueOf(true), expectedMapk1GeneBed)}); + tests.add(new Object[]{new GtfToBedTest(mapk1, dictionary, String.valueOf(true), String.valueOf(true), expectedMapk1TranscriptBed)}); + tests.add(new Object[]{new GtfToBedTest(decoys, dictionary, String.valueOf(false), String.valueOf(true), expectedDecoysGeneBed)}); + tests.add(new Object[]{new GtfToBedTest(decoys, dictionary, String.valueOf(true), String.valueOf(true), expectedDecoysTranscriptBed)}); + tests.add(new Object[]{new GtfToBedTest(manyTranscripts, dictionary, String.valueOf(true), String.valueOf(true), expectedManyTranscriptsBed)}); + tests.add(new Object[]{new GtfToBedTest(manyTranscripts, dictionary, String.valueOf(true), String.valueOf(false), expectedNotBasicBed)}); + tests.add(new Object[]{new GtfToBedTest(mouse, mouseDictionary, String.valueOf(true), String.valueOf(false), expectedMouseBed)}); + + return tests.toArray(new Object[][]{}); } - private void runMouse() throws IOException { - final ArgumentsBuilder argsBuilder = new ArgumentsBuilder() - .add(GtfToBed.INPUT_LONG_NAME, mouse) - .add(GtfToBed.SEQUENCE_DICTIONARY_LONG_NAME, mouseDictionary) - .add(GtfToBed.SORT_BY_TRANSCRIPT_LONG_NAME, true) - .add(GtfToBed.SORT_BY_BASIC_LONG_NAME, false) - .addOutput(outputFile); - runCommandLine(argsBuilder); - IntegrationTestSpec.assertEqualTextFiles(expectedMouseBed, outputFile); - } - - private int countLines(File file) throws IOException { - BufferedReader reader = new BufferedReader(new FileReader(file)); - int lines = 0; - while (reader.readLine() != null) { - lines++; - } - return lines; + @Test(dataProvider = "GtfToBedTestProvider") + public void testGtfToBed(GtfToBedTest params) throws IOException { + final File outputFile = createTempFile("outputBed", ".bed"); + final ArrayList args = new ArrayList<>(); + + args.add("--" + GtfToBed.INPUT_LONG_NAME); + args.add(new File (params.input).getAbsolutePath()); + args.add("--" + StandardArgumentDefinitions.SEQUENCE_DICTIONARY_NAME); + args.add(new File (params.SD).getAbsolutePath()); + args.add("--" + GtfToBed.SORT_BY_TRANSCRIPT_LONG_NAME); + args.add(params.transcript); + args.add("--" + GtfToBed.SORT_BY_BASIC_LONG_NAME); + args.add(params.basic); + args.add("--" + StandardArgumentDefinitions.OUTPUT_LONG_NAME); + args.add(outputFile.getAbsolutePath()); + + runCommandLine(args); + + IntegrationTestSpec.assertEqualTextFiles(new File(params.expected), outputFile); } }