Search in sources :

Example 91 with SimpleInterval

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);
}
Also used : AllelicCountCollection(org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCountCollection) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 92 with SimpleInterval

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);
}
Also used : IntStream(java.util.stream.IntStream) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) java.util(java.util) ReadCountCollection(org.broadinstitute.hellbender.tools.exome.ReadCountCollection) ModeledSegment(org.broadinstitute.hellbender.tools.exome.ModeledSegment) Assert(org.testng.Assert) RandomGenerator(org.apache.commons.math3.random.RandomGenerator) RandomGeneratorFactory(org.apache.commons.math3.random.RandomGeneratorFactory) Target(org.broadinstitute.hellbender.tools.exome.Target) Test(org.testng.annotations.Test) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) Collectors(java.util.stream.Collectors) ReadCountCollection(org.broadinstitute.hellbender.tools.exome.ReadCountCollection) RandomGenerator(org.apache.commons.math3.random.RandomGenerator) Target(org.broadinstitute.hellbender.tools.exome.Target) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) ModeledSegment(org.broadinstitute.hellbender.tools.exome.ModeledSegment) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) Test(org.testng.annotations.Test)

Example 93 with SimpleInterval

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;
}
Also used : SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval)

Example 94 with SimpleInterval

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);
    }
}
Also used : SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) IOException(java.io.IOException) UserException(org.broadinstitute.hellbender.exceptions.UserException) File(java.io.File) AllelicCount(org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCount) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 95 with SimpleInterval

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 } };
}
Also used : IntervalList(htsjdk.samtools.util.IntervalList) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) AllelicCount(org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCount) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) Interval(htsjdk.samtools.util.Interval) DataProvider(org.testng.annotations.DataProvider)

Aggregations

SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)545 Test (org.testng.annotations.Test)287 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)202 File (java.io.File)102 ArrayList (java.util.ArrayList)66 DataProvider (org.testng.annotations.DataProvider)64 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)60 Collectors (java.util.stream.Collectors)53 java.util (java.util)41 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)40 AllelicCount (org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCount)40 UserException (org.broadinstitute.hellbender.exceptions.UserException)39 VariantContext (htsjdk.variant.variantcontext.VariantContext)36 IntStream (java.util.stream.IntStream)34 Target (org.broadinstitute.hellbender.tools.exome.Target)34 IOException (java.io.IOException)32 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)28 Assert (org.testng.Assert)27 Locatable (htsjdk.samtools.util.Locatable)26 List (java.util.List)26