Skip to content

Commit

Permalink
Added check for null sequence dictionaries in the dictionary validati…
Browse files Browse the repository at this point in the history
…on code (#6147)

* added an assertion that the sequcnce dictionary exists in the case that the reference diciotnary is called upon
  • Loading branch information
jamesemery authored Sep 16, 2019
1 parent a2cf4f0 commit f31cf02
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ public static void validateDictionaries( final String name1,
final SAMSequenceDictionary dict2,
final boolean requireSuperset,
final boolean checkContigOrdering ) {
Utils.nonNull(dict1, "Something went wrong with sequence dictionary detection, check that "+name1+" has a valid sequence dictionary");
Utils.nonNull(dict2, "Something went wrong with sequence dictionary detection, check that "+name2+" has a valid sequence dictionary");

final SequenceDictionaryCompatibility type = compareDictionaries(dict1, dict2, checkContigOrdering);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
package org.broadinstitute.hellbender.engine;

import htsjdk.samtools.reference.ReferenceSequenceFileFactory;
import htsjdk.variant.variantcontext.VariantContext;
import htsjdk.variant.vcf.VCFHeader;
import org.apache.commons.lang3.tuple.Pair;
import org.broadinstitute.hellbender.CommandLineProgramTest;
import org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions;
import org.broadinstitute.hellbender.tools.walkers.mutect.Mutect2;
import org.broadinstitute.hellbender.tools.walkers.variantutils.SelectVariants;
import org.broadinstitute.hellbender.testutils.VariantContextTestUtils;
import org.broadinstitute.hellbender.utils.io.IOUtils;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.util.List;

Expand All @@ -35,4 +42,26 @@ public void testSitesOnlyMode() {
Assert.assertFalse(v.hasGenotypes());
}
}

@Test (expectedExceptions = java.lang.IllegalArgumentException.class)
// test asserting that if the reference dictionary exists but is not valid we get a more helpful exception than a null pointer exception
public void testBrokenReferenceDictionaryErrorMessage() throws IOException {
File out = createTempFile("GTStrippedOutput", "vcf");

Path refCopy = Files.copy(IOUtils.getPath(hg19_chr1_1M_Reference), createTempPath("reference", ".fasta"), StandardCopyOption.REPLACE_EXISTING);
Path indexCopy = Files.copy(ReferenceSequenceFileFactory.getFastaIndexFileName(IOUtils.getPath(hg19_chr1_1M_Reference)), ReferenceSequenceFileFactory.getFastaIndexFileName(refCopy));
File emptyDict = new File(ReferenceSequenceFileFactory.getDefaultDictionaryForReferenceSequence(refCopy).toString());
IOUtils.deleteOnExit(indexCopy);

emptyDict.createNewFile();
IOUtils.deleteOnExit(emptyDict.toPath());

String[] args = new String[] {
"-R", refCopy.toString(),
"-I", TEST_DIRECTORY + "CEUTrio.HiSeq.WGS.b37.NA12878.20.21.10000000-10000020.with.unmapped.bam",
"-O", out.getAbsolutePath()
};

runCommandLine(Arrays.asList(args), Mutect2.class.getSimpleName());
}
}

0 comments on commit f31cf02

Please sign in to comment.