Skip to content

Commit

Permalink
Add tests for int overflow input and combined inputs lead to overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ldgauthier committed Jun 10, 2022
1 parent 17a5726 commit de85ab0
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,26 @@ protected static int getOptionalInteger(final Map<String, String> bindings, fina
}
}

protected static long getRequiredLong(final Map<String, String> bindings, final String key) {
if ( bindings.containsKey(key) ) {
try{
return Long.valueOf(bindings.get(key));
} catch (NumberFormatException e){
throw new UserException.MalformedFile("Malformed tranches file. Invalid value for key " + key);
}
} else {
throw new UserException.MalformedFile("Malformed tranches file. Missing required key " + key);
}
}

protected static long getOptionalLong(final Map<String, String> bindings, final String key, final int defaultValue) {
try{
return Long.valueOf(bindings.getOrDefault(key, String.valueOf(defaultValue)));
} catch (NumberFormatException e){
throw new UserException.MalformedFile("Malformed tranches file. Invalid value for key " + key);
}
}

protected double getTruthSensitivity() {
return accessibleTruthSites > 0 ? callsAtTruthSites / (1.0*accessibleTruthSites) : 0.0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ public static List<VQSLODTranche> readTranches(final GATKPath f) throws IOExcept
}
tranches.add(new VQSLODTranche(
getRequiredDouble(bindings, "minVQSLod"),
getOptionalInteger(bindings, "numKnown", -1),
getOptionalLong(bindings, "numKnown", -1),
getOptionalDouble(bindings, "knownTiTv", -1.0),
getRequiredInteger(bindings, "numNovel"),
getRequiredLong(bindings, "numNovel"),
getRequiredDouble(bindings, "novelTiTv"),
getOptionalInteger(bindings, "accessibleTruthSites", -1),
getOptionalInteger(bindings, "callsAtTruthSites", -1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
import org.broadinstitute.hellbender.GATKBaseTest;
import org.broadinstitute.hellbender.testutils.IntegrationTestSpec;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
* Created by gauthier on 7/18/17.
Expand All @@ -16,45 +20,36 @@ public class GatherTranchesIntegrationTest extends CommandLineProgramTest {

private static final String testDir = GATKBaseTest.publicTestDir + "/large/VQSR/";

@Test
public void testCombine2Shards() throws Exception {
final File recal1 = new File(testDir + "snpTranches.scattered.txt"); //this is the output of VariantRecalibratorIntegrationTest.testVariantRecalibratorSNPscattered
final File recal2 = new File(testDir + "snpTranches.scattered.2.txt"); //this is a copy of the above
@DataProvider(name = "testInputs")
public Object[][] getTestInputs () {
return new Object[][]{
{Arrays.asList(new File(testDir + "snpTranches.scattered.txt"), new File(testDir + "snpTranches.scattered.txt")),
new File(testDir + "expected/snpTranches.gathered.txt"), "SNP"},

final File recal_original = new File(testDir + "expected/snpTranches.gathered.txt");
{Arrays.asList(new File(testDir + "indels.0.tranches"), new File(testDir + "indels.1.tranches")),
new File(testDir + "expected/indels.gathered.tranches"), "INDEL"},

final ArgumentsBuilder args = new ArgumentsBuilder();
args.addRaw("--input");
args.addRaw(recal1.getAbsolutePath());
args.addRaw("--input");
args.addRaw(recal2.getAbsolutePath());
args.add("mode", "SNP");
{Arrays.asList(new File(testDir + "test-single-giant-input-snps.tranches")),
new File(testDir + "expected/singleOverflow.tranches"), "SNP"},

final File outFile = GATKBaseTest.createTempFile("gatheredTranches", ".txt");
args.addOutput(outFile);
final Object res = this.runCommandLine(args.getArgsArray());
Assert.assertEquals(res, 0);
IntegrationTestSpec.assertEqualTextFiles(outFile, recal_original);
{Arrays.asList(new File(testDir + "test-very-large-one-snps.tranches"), new File(testDir + "test-very-large-two-snps.tranches")),
new File(testDir + "expected/testSummedOverflow.tranches"), "SNP"}
};
}

@Test
public void testCombine2IndelTranches() throws Exception {
final File tranches1 = new File(testDir + "indels.0.tranches");
final File tranches2 = new File(testDir + "indels.1.tranches");

final File recal_original = new File(testDir + "expected/indels.gathered.tranches");

@Test (dataProvider = "testInputs")
public void testGatherTranches(List<File> inputs, File expected, String mode) throws IOException {
final ArgumentsBuilder args = new ArgumentsBuilder();
args.addRaw("--input");
args.addRaw(tranches1.getAbsolutePath());
args.addRaw("--input");
args.addRaw(tranches2.getAbsolutePath());
args.add("mode", "INDEL");
for (File inFile : inputs) {
args.addRaw("--input");
args.addRaw(inFile);
}
args.add("mode", mode);

final File outFile = GATKBaseTest.createTempFile("gatheredTranches", ".txt");
args.addOutput(outFile);
final Object res = this.runCommandLine(args.getArgsArray());
Assert.assertEquals(res, 0);
IntegrationTestSpec.assertEqualTextFiles(outFile, recal_original);
IntegrationTestSpec.assertEqualTextFiles(outFile, expected);
}
}
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown

0 comments on commit de85ab0

Please sign in to comment.