Skip to content

Commit

Permalink
add: dictionary exception and corresponding test
Browse files Browse the repository at this point in the history
  • Loading branch information
sanashah007 committed Aug 26, 2024
1 parent 7a7a7d0 commit 4c573e0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
* <pre>
* java -jar GtfToBed.jar \
* -gtf-path input.gtf \
* -sequence-dictionary dictionary.dict \
* -R dictionary.dict \
* -sort-transcript \
* -output output.bed \
* </pre>
Expand Down Expand Up @@ -98,6 +98,9 @@ public class GtfToBed extends FeatureWalker<GencodeGtfFeature> {
//stores either gene or transcript ID and summary information about the feature
private final Map<String, GtfInfo> featureInfoMap = new HashMap<>();

//Sequence dictionary
private SAMSequenceDictionary sequenceDictionary = null;

@Override
protected boolean isAcceptableFeatureType(Class<? extends Feature> featureType) {
return featureType.isAssignableFrom(GencodeGtfFeature.class);
Expand Down Expand Up @@ -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<String, GtfInfo> karyotypeIdToInfo = getSortedMap(sequenceDictionary);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String> 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);
}
}

0 comments on commit 4c573e0

Please sign in to comment.