Skip to content

Commit

Permalink
Fix NPE in VariantEval when run with no intervals/reference
Browse files Browse the repository at this point in the history
* Fixes an NPE that happened when using certain evaluators with VariantEval and not specifying a reference or intervals
* Fixes #6212
  • Loading branch information
lbergelson committed Dec 9, 2019
1 parent d9fd22f commit 396636e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.broadinstitute.hellbender.utils.SimpleInterval;
import org.broadinstitute.hellbender.utils.Utils;
import org.broadinstitute.hellbender.utils.io.IOUtils;
import org.broadinstitute.hellbender.utils.logging.OneShotLogger;
import org.broadinstitute.hellbender.utils.samples.PedigreeValidationType;
import org.broadinstitute.hellbender.utils.samples.SampleDB;
import org.broadinstitute.hellbender.utils.samples.SampleDBBuilder;
Expand Down Expand Up @@ -235,7 +236,7 @@ public class VariantEval extends MultiVariantWalker {
/**
* File containing tribble-readable features for the IntervalStratificiation
*/
@Argument(fullName="strat-intervals", shortName="strat-intervals", doc="File containing tribble-readable features for the IntervalStratificiation", optional=true)
@Argument(fullName="strat-intervals", shortName="strat-intervals", doc="File containing tribble-readable features for the IntervalStratification", optional=true)
public FeatureInput<Feature> intervalsFile = null;

/**
Expand Down Expand Up @@ -304,6 +305,8 @@ protected void initializeDrivingVariants() {
// maintain the mapping of FeatureInput to name used in output file
Map<FeatureInput<VariantContext>, String> inputToNameMap = new HashMap<>();

private final OneShotLogger territoryUnknownWarningLogger = new OneShotLogger(logger);

/**
* Initialize the stratifications, evaluations, evaluation contexts, and reporting object
*/
Expand Down Expand Up @@ -819,7 +822,13 @@ public SampleDB getSampleDB() {
}

public long getnProcessedLoci() {
return getTraversalIntervals().stream().mapToLong(SimpleInterval::size).sum();
if(getTraversalIntervals() == null) {
territoryUnknownWarningLogger.warn("No reference or intervals were provided so it is not clear how much genomic " +
"territory the input covered. Values that rely on the size of the input territory will not be correct.");
return 0;
} else {
return getTraversalIntervals().stream().mapToLong(SimpleInterval::size).sum();
}
}

public FeatureInput<Feature> getKnownCNVsFile() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,4 +666,16 @@ public void testOutputFileCreation() throws IOException {
new File(getToolTestDataDir() + "expected/" + "testPrintMissingComp" + ".expected.txt"));
}

@Test
public void testCountWithNoReferenceOrIntervals() {
//Test for https://github.com/broadinstitute/gatk/issues/6212 just make sure we don't crash.
final String vcf = getTestFilePath("/CEU.trio.callsForVE.vcf");
final ArgumentsBuilder args = new ArgumentsBuilder();
args.addOutput( createTempFile("out",".stuff"))
.addArgument("eval", vcf)
.addArgument("EV", "CountVariants");

runCommandLine(args);
}

}

0 comments on commit 396636e

Please sign in to comment.