use of org.broadinstitute.hellbender.utils.SimpleInterval in project gatk-protected by broadinstitute.
the class AllelicPanelOfNormalsUnitTest method testPoNHyperparameterInitialization.
@Test
public void testPoNHyperparameterInitialization() {
LoggingUtils.setLoggingLevel(Log.LogLevel.INFO);
final AllelicPanelOfNormals allelicPoN = new AllelicPanelOfNormals(new AllelicCountCollection(ALLELIC_PON_NORMAL_COUNTS_FILE));
final SimpleInterval firstSite = new SimpleInterval("1", 1, 1);
//all sites in PoN are from chr1
final SimpleInterval siteNotInPoN = new SimpleInterval("2", 1, 1);
// test initialization of hyperparameters for first site in PoN (a = 1218, r = 1317)
final double alphaAtFirstSite = allelicPoN.getAlpha(firstSite);
final double betaAtFirstSite = allelicPoN.getBeta(firstSite);
Assert.assertEquals(alphaAtFirstSite, ALPHA_EXPECTED_AT_FIRST_SITE, DELTA);
Assert.assertEquals(betaAtFirstSite, BETA_EXPECTED_AT_FIRST_SITE, DELTA);
// test initialization of MLE hyperparameters (which are default values for sites not in PoN)
final double alphaNotInPoN = allelicPoN.getAlpha(siteNotInPoN);
final double betaNotInPoN = allelicPoN.getBeta(siteNotInPoN);
final double meanBias = allelicPoN.getGlobalMeanBias();
final double biasVariance = allelicPoN.getGlobalBiasVariance();
Assert.assertEquals(alphaNotInPoN, MLE_ALPHA_EXPECTED, DELTA);
Assert.assertEquals(betaNotInPoN, MLE_BETA_EXPECTED, DELTA);
Assert.assertEquals(meanBias, MLE_MEAN_BIAS_EXPECTED, DELTA);
Assert.assertEquals(biasVariance, MLE_BIAS_VARIANCE_EXPECTED, DELTA);
}
use of org.broadinstitute.hellbender.utils.SimpleInterval in project gatk-protected by broadinstitute.
the class CopyRatioSegmenterUnitTest method testSegmentation.
@Test
public void testSegmentation() {
final RandomGenerator rng = RandomGeneratorFactory.createRandomGenerator(new Random(563));
final List<Double> trueWeights = Arrays.asList(0.2, 0.5, 0.3);
final List<Double> trueLog2CopyRatios = Arrays.asList(-2.0, 0.0, 1.4);
final double trueMemoryLength = 1e5;
final double trueStandardDeviation = 0.2;
final CopyRatioHMM trueModel = new CopyRatioHMM(trueLog2CopyRatios, trueWeights, trueMemoryLength, trueStandardDeviation);
final int chainLength = 10000;
final List<SimpleInterval> positions = randomPositions("chr1", chainLength, rng, trueMemoryLength / 4);
final List<Integer> trueStates = trueModel.generateHiddenStateChain(positions);
final List<Double> trueLog2CopyRatioSequence = trueStates.stream().map(n -> trueLog2CopyRatios.get(n)).collect(Collectors.toList());
final List<Double> data = trueLog2CopyRatioSequence.stream().map(cr -> generateData(trueStandardDeviation, cr, rng)).collect(Collectors.toList());
final List<Target> targets = positions.stream().map(Target::new).collect(Collectors.toList());
final ReadCountCollection rcc = new ReadCountCollection(targets, Arrays.asList("SAMPLE"), new Array2DRowRealMatrix(data.stream().mapToDouble(x -> x).toArray()));
final CopyRatioSegmenter segmenter = new CopyRatioSegmenter(10, rcc);
final List<ModeledSegment> segments = segmenter.getModeledSegments();
final double[] segmentCopyRatios = segments.stream().flatMap(s -> Collections.nCopies((int) s.getTargetCount(), s.getSegmentMeanInLog2CRSpace()).stream()).mapToDouble(x -> x).toArray();
final double averageCopyRatioError = IntStream.range(0, trueLog2CopyRatioSequence.size()).mapToDouble(n -> Math.abs(segmentCopyRatios[n] - trueLog2CopyRatioSequence.get(n))).average().getAsDouble();
Assert.assertEquals(averageCopyRatioError, 0, 0.025);
}
use of org.broadinstitute.hellbender.utils.SimpleInterval in project gatk-protected by broadinstitute.
the class CopyRatioSegmenterUnitTest method randomPositions.
public static List<SimpleInterval> randomPositions(final String contig, final int chainLength, final RandomGenerator rng, final double separationScale) {
final List<SimpleInterval> positions = new ArrayList<>();
int position = 1;
for (int n = 0; n < chainLength; n++) {
position += rng.nextInt((int) separationScale);
final SimpleInterval interval = new SimpleInterval(contig, position, position);
positions.add(interval);
}
return positions;
}
use of org.broadinstitute.hellbender.utils.SimpleInterval in project gatk-protected by broadinstitute.
the class BayesianHetPulldownCalculatorUnitTest method testGetHetPulldown.
@Test
public void testGetHetPulldown() {
Pulldown testPulldown, expectedPulldown;
File tempFile;
/* write Pulldown to file while checking the results */
try {
/* test 1: normal, loose threshold */
testPulldown = calculator.getHetPulldown(NORMAL_BAM_FILE, 2);
tempFile = File.createTempFile("testPulldownNormalLoose", ".txt");
testPulldown.write(tempFile, AllelicCountTableColumn.AllelicCountTableVerbosity.FULL);
expectedPulldown = new Pulldown(normalHeader);
expectedPulldown.add(new AllelicCount(new SimpleInterval("1", 11522, 11522), 7, 4, Nucleotide.G, Nucleotide.A, 11, 18.38));
expectedPulldown.add(new AllelicCount(new SimpleInterval("1", 12098, 12098), 8, 6, Nucleotide.G, Nucleotide.T, 14, 28.84));
expectedPulldown.add(new AllelicCount(new SimpleInterval("1", 14630, 14630), 9, 8, Nucleotide.T, Nucleotide.G, 17, 39.39));
expectedPulldown.add(new AllelicCount(new SimpleInterval("2", 14689, 14689), 6, 9, Nucleotide.T, Nucleotide.G, 15, 28.23));
expectedPulldown.add(new AllelicCount(new SimpleInterval("2", 14982, 14982), 6, 5, Nucleotide.G, Nucleotide.C, 11, 24.54));
Assert.assertEquals(new Pulldown(tempFile, normalHeader), expectedPulldown);
/* test 2: normal, tight threshold */
testPulldown = calculator.getHetPulldown(NORMAL_BAM_FILE, 12);
tempFile = File.createTempFile("testPulldownNormalTight", ".txt");
testPulldown.write(tempFile, AllelicCountTableColumn.AllelicCountTableVerbosity.FULL);
expectedPulldown = new Pulldown(normalHeader);
expectedPulldown.add(new AllelicCount(new SimpleInterval("1", 12098, 12098), 8, 6, Nucleotide.G, Nucleotide.T, 14, 28.84));
expectedPulldown.add(new AllelicCount(new SimpleInterval("1", 14630, 14630), 9, 8, Nucleotide.T, Nucleotide.G, 17, 39.39));
expectedPulldown.add(new AllelicCount(new SimpleInterval("2", 14689, 14689), 6, 9, Nucleotide.T, Nucleotide.G, 15, 28.23));
Assert.assertEquals(new Pulldown(tempFile, normalHeader), expectedPulldown);
/* test 3: tumor, loose threshold */
testPulldown = calculator.getHetPulldown(TUMOR_BAM_FILE, 2);
tempFile = File.createTempFile("testPulldownTumorLoose", ".txt");
testPulldown.write(tempFile, AllelicCountTableColumn.AllelicCountTableVerbosity.FULL);
expectedPulldown = new Pulldown(tumorHeader);
expectedPulldown.add(new AllelicCount(new SimpleInterval("1", 11522, 11522), 7, 4, Nucleotide.G, Nucleotide.A, 11, 15.63));
expectedPulldown.add(new AllelicCount(new SimpleInterval("1", 12098, 12098), 8, 6, Nucleotide.G, Nucleotide.T, 14, 24.72));
expectedPulldown.add(new AllelicCount(new SimpleInterval("1", 14630, 14630), 9, 8, Nucleotide.T, Nucleotide.G, 17, 33.89));
expectedPulldown.add(new AllelicCount(new SimpleInterval("2", 14689, 14689), 6, 9, Nucleotide.T, Nucleotide.G, 15, 24.11));
expectedPulldown.add(new AllelicCount(new SimpleInterval("2", 14982, 14982), 6, 5, Nucleotide.G, Nucleotide.C, 11, 21.10));
Assert.assertEquals(new Pulldown(tempFile, normalHeader), expectedPulldown);
/* test 4: tumor, tight threshold */
testPulldown = calculator.getHetPulldown(TUMOR_BAM_FILE, 12);
tempFile = File.createTempFile("testPulldownTumorTight", ".txt");
testPulldown.write(tempFile, AllelicCountTableColumn.AllelicCountTableVerbosity.FULL);
expectedPulldown = new Pulldown(tumorHeader);
expectedPulldown.add(new AllelicCount(new SimpleInterval("1", 14630, 14630), 9, 8, Nucleotide.T, Nucleotide.G, 17, 33.89));
Assert.assertEquals(new Pulldown(tempFile, normalHeader), expectedPulldown);
} catch (final IOException e) {
throw new UserException.CouldNotCreateOutputFile("Could not write pulldown to to file.", e);
}
}
use of org.broadinstitute.hellbender.utils.SimpleInterval in project gatk-protected by broadinstitute.
the class HetPulldownCalculatorUnitTest method inputGetTumorHetPulldown15.
@DataProvider(name = "inputGetTumorHetPulldownMin15")
public Object[][] inputGetTumorHetPulldown15() {
final Pulldown tumorHetPulldown = new Pulldown(normalHeader);
tumorHetPulldown.add(new AllelicCount(new SimpleInterval("1", 14630, 14630), 9, 8));
tumorHetPulldown.add(new AllelicCount(new SimpleInterval("2", 14689, 14689), 6, 9));
final IntervalList normalHetIntervals = new IntervalList(tumorHeader);
normalHetIntervals.add(new Interval("1", 14630, 14630));
normalHetIntervals.add(new Interval("2", 14689, 14689));
return new Object[][] { { normalHetIntervals, tumorHetPulldown } };
}
Aggregations