From 4c573e077848703c1f59e9c1e809455a20333406 Mon Sep 17 00:00:00 2001 From: Sana Shah <54493565+sanashah007@users.noreply.github.com> Date: Mon, 26 Aug 2024 12:08:18 -0700 Subject: [PATCH] add: dictionary exception and corresponding test --- .../tools/walkers/conversion/GtfToBed.java | 16 ++++++++++++---- .../conversion/GtfToBedIntegrationTest.java | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/broadinstitute/hellbender/tools/walkers/conversion/GtfToBed.java b/src/main/java/org/broadinstitute/hellbender/tools/walkers/conversion/GtfToBed.java index 272d27b55b5..656b815af6d 100644 --- a/src/main/java/org/broadinstitute/hellbender/tools/walkers/conversion/GtfToBed.java +++ b/src/main/java/org/broadinstitute/hellbender/tools/walkers/conversion/GtfToBed.java @@ -51,7 +51,7 @@ *
  *     java -jar GtfToBed.jar \
  *     -gtf-path input.gtf \
- *     -sequence-dictionary dictionary.dict \
+ *     -R dictionary.dict \
  *     -sort-transcript \
  *     -output output.bed \
  * 
@@ -98,6 +98,9 @@ public class GtfToBed extends FeatureWalker { //stores either gene or transcript ID and summary information about the feature private final Map featureInfoMap = new HashMap<>(); + //Sequence dictionary + private SAMSequenceDictionary sequenceDictionary = null; + @Override protected boolean isAcceptableFeatureType(Class featureType) { return featureType.isAssignableFrom(GencodeGtfFeature.class); @@ -205,12 +208,17 @@ private void updateGeneInterval(GencodeGtfFeature gtfFeature, int geneStart, int featureInfoMap.put(gtfFeature.getGeneId(), gtfGeneInfo); } + @Override + public void onTraversalStart() { + sequenceDictionary = getBestAvailableSequenceDictionary(); + if(sequenceDictionary == null){ + throw new GATKException("Sequence Dictionary must be specified (" + StandardArgumentDefinitions.SEQUENCE_DICTIONARY_NAME + ")."); + } + } + // runs immediately after it has gone through each line of gtf (apply method) @Override public Object onTraversalSuccess() { - // get dictionary - SAMSequenceDictionary sequenceDictionary = getBestAvailableSequenceDictionary(); - // create linked hash map to store sorted values of idToInfo LinkedHashMap karyotypeIdToInfo = getSortedMap(sequenceDictionary); 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 08fc1c09ef6..ef6af2402a9 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 @@ -2,6 +2,7 @@ import org.broadinstitute.hellbender.CommandLineProgramTest; import org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions; +import org.broadinstitute.hellbender.exceptions.GATKException; import org.broadinstitute.hellbender.testutils.IntegrationTestSpec; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -25,6 +26,7 @@ public class GtfToBedIntegrationTest extends CommandLineProgramTest { private static final String expectedNotBasicBed = ConversionTestUtils.getNotBasicBed(); private static final String expectedMouseBed = ConversionTestUtils.getMouseBed(); + private static class GtfToBedTest { final String input; final String SD; @@ -75,4 +77,21 @@ public void testGtfToBed(GtfToBedTest params) throws IOException { IntegrationTestSpec.assertEqualTextFiles(new File(params.expected), outputFile); } + + @Test(expectedExceptions = GATKException.class) + public void testGtfToBedNoSequenceDictionary() { + final File outputFile = createTempFile("outputBed", ".bed"); + final ArrayList args = new ArrayList<>(); + + args.add("--" + GtfToBed.INPUT_LONG_NAME); + args.add(new File (mapk1).getAbsolutePath()); + args.add("--" + GtfToBed.SORT_BY_TRANSCRIPT_LONG_NAME); + args.add(String.valueOf(true)); + args.add("--" + GtfToBed.USE_BASIC_TRANSCRIPT_LONG_NAME); + args.add(String.valueOf(true)); + args.add("--" + StandardArgumentDefinitions.OUTPUT_LONG_NAME); + args.add(outputFile.getAbsolutePath()); + + runCommandLine(args); + } }