Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,7 @@ protected Object doWork() {
if (pythonProcessOutput.getExitValue() != 0) {
// We restart once if the inference diverged
if (pythonProcessOutput.getExitValue() == DIVERGED_INFERENCE_EXIT_CODE) {
final Random generator = new Random(STARTING_SEED);
final int nextGCNVSeed = generator.nextInt();
final int nextGCNVSeed = generateRetrySeed();
logger.info("The inference failed to converge and will be restarted once with a different random seed.");
pythonProcessOutput = executor.executeScriptAndGetOutput(
new Resource(script, GermlineCNVCaller.class),
Expand Down Expand Up @@ -478,6 +477,10 @@ private List<File> writeIntervalSubsetReadCountFiles() {
return intervalSubsetReadCountFiles;
}

static int generateRetrySeed() {
return new Random().nextInt(Integer.MAX_VALUE);
}

private List<String> composePythonArguments(final List<File> intervalSubsetReadCountFiles, final int randomSeed) {
final String outputDirArg = CopyNumberArgumentValidationUtils.addTrailingSlashIfNecessary(outputDir.getAbsolutePath());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.broadinstitute.hellbender.tools.copynumber;

import org.broadinstitute.hellbender.GATKBaseTest;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.util.HashSet;
import java.util.Set;

/**
* Unit tests for {@link GermlineCNVCaller}.
*/
public final class GermlineCNVCallerUnitTest extends GATKBaseTest {

@Test
public void testGenerateRetrySeedIsNonNegative() {
for (int i = 0; i < 1000; i++) {
final int seed = GermlineCNVCaller.generateRetrySeed();
Assert.assertTrue(seed >= 0, "Retry seed must be non-negative (valid for numpy RandomState), but got: " + seed);
}
}

@Test
public void testGenerateRetrySeedIsLessThanMaxInt() {
for (int i = 0; i < 1000; i++) {
final int seed = GermlineCNVCaller.generateRetrySeed();
Assert.assertTrue(seed < Integer.MAX_VALUE, "Retry seed must be less than Integer.MAX_VALUE, but got: " + seed);
}
}

@Test
public void testGenerateRetrySeedIsNonDeterministic() {
final Set<Integer> seeds = new HashSet<>();
for (int i = 0; i < 100; i++) {
seeds.add(GermlineCNVCaller.generateRetrySeed());
}
Assert.assertTrue(seeds.size() > 1, "Retry seeds should not all be identical across calls");
}
}