Search in sources :

Example 31 with HDF5File

use of org.broadinstitute.hdf5.HDF5File in project gatk-protected by broadinstitute.

the class NormalizeSomaticReadCountsIntegrationTest method assertTangentNormalized.

private void assertTangentNormalized(final ReadCountCollection actualReadCounts, final ReadCountCollection preTangentNormalized, final RealMatrix betaHats, final File ponFile) {
    try (final HDF5File ponReader = new HDF5File(ponFile)) {
        final PCACoveragePoN pon = new HDF5PCACoveragePoN(ponReader);
        final RealMatrix inCounts = reorderTargetsToPoNOrder(preTangentNormalized, pon.getPanelTargetNames());
        final RealMatrix actual = reorderTargetsToPoNOrder(actualReadCounts, pon.getPanelTargetNames());
        final RealMatrix ponMat = pon.getReducedPanelCounts();
        final RealMatrix projection = ponMat.multiply(betaHats);
        final RealMatrix expected = inCounts.subtract(projection);
        Assert.assertEquals(actual.getRowDimension(), expected.getRowDimension());
        Assert.assertEquals(actual.getColumnDimension(), expected.getColumnDimension());
        for (int i = 0; i < actual.getRowDimension(); i++) {
            Assert.assertEquals(actual.getRow(i), expected.getRow(i));
        }
    }
}
Also used : HDF5PCACoveragePoN(org.broadinstitute.hellbender.tools.pon.coverage.pca.HDF5PCACoveragePoN) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) RealMatrix(org.apache.commons.math3.linear.RealMatrix) PCACoveragePoN(org.broadinstitute.hellbender.tools.pon.coverage.pca.PCACoveragePoN) HDF5PCACoveragePoN(org.broadinstitute.hellbender.tools.pon.coverage.pca.HDF5PCACoveragePoN) HDF5File(org.broadinstitute.hdf5.HDF5File)

Example 32 with HDF5File

use of org.broadinstitute.hdf5.HDF5File in project gatk-protected by broadinstitute.

the class NormalizeSomaticReadCountsIntegrationTest method assertBetaHatsRobustToOutliers.

/**
     * Asserts that the calculation of beta hats is not significantly affected by zero-coverage outlier counts
     * We perform this check by randomly setting some coverages to zero in copy ratio space (-infinity in log space).
     * betaHats imputes 0 in log space (1 in copy ratio space) whenever coverage is below a certain low threshold
     * and should thus be robust to this type of noise.
     */
private void assertBetaHatsRobustToOutliers(final ReadCountCollection preTangentNormalized, final File ponFile) {
    try (final HDF5File ponReader = new HDF5File(ponFile)) {
        final PCACoveragePoN pon = new HDF5PCACoveragePoN(ponReader);
        final List<String> ponTargets = pon.getPanelTargetNames();
        final RealMatrix input = reorderTargetsToPoNOrder(preTangentNormalized, ponTargets);
        // randomly set some entries to zero in copy-ratio space (-infinity in log space)
        final Random random = new Random(13);
        final double noiseProportion = 0.01;
        final RealMatrix noisyInput = input.copy();
        noisyInput.walkInOptimizedOrder(new DefaultRealMatrixChangingVisitor() {

            @Override
            public double visit(final int row, final int column, final double value) {
                return random.nextDouble() < noiseProportion ? Double.NEGATIVE_INFINITY : value;
            }
        });
        final RealMatrix betaHats = PCATangentNormalizationUtils.calculateBetaHats(pon.getReducedPanelPInverseCounts(), input, PCATangentNormalizationUtils.EPSILON);
        final RealMatrix noisyBetaHats = PCATangentNormalizationUtils.calculateBetaHats(pon.getReducedPanelPInverseCounts(), noisyInput, PCATangentNormalizationUtils.EPSILON);
        final RealMatrix difference = betaHats.subtract(noisyBetaHats);
        difference.walkInOptimizedOrder(new DefaultRealMatrixPreservingVisitor() {

            @Override
            public void visit(final int row, int column, double value) {
                Assert.assertEquals(value, 0, 0.01);
            }
        });
    }
}
Also used : HDF5PCACoveragePoN(org.broadinstitute.hellbender.tools.pon.coverage.pca.HDF5PCACoveragePoN) DefaultRealMatrixPreservingVisitor(org.apache.commons.math3.linear.DefaultRealMatrixPreservingVisitor) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) RealMatrix(org.apache.commons.math3.linear.RealMatrix) DefaultRealMatrixChangingVisitor(org.apache.commons.math3.linear.DefaultRealMatrixChangingVisitor) PCACoveragePoN(org.broadinstitute.hellbender.tools.pon.coverage.pca.PCACoveragePoN) HDF5PCACoveragePoN(org.broadinstitute.hellbender.tools.pon.coverage.pca.HDF5PCACoveragePoN) HDF5File(org.broadinstitute.hdf5.HDF5File)

Example 33 with HDF5File

use of org.broadinstitute.hdf5.HDF5File in project gatk-protected by broadinstitute.

the class HDF5LibraryUnitTest method testMakeNaNDouble.

@Test()
public void testMakeNaNDouble() throws IOException {
    final File testFile = File.createTempFile("hdf5", ".hd5");
    HDF5File file = new HDF5File(testFile, HDF5File.OpenMode.CREATE);
    file.makeGroup("test-group/double-group");
    Assert.assertTrue(file.makeDouble("test-group/double-group/my-double", Double.NaN));
    System.err.println(testFile);
    file.close();
    final long time = System.currentTimeMillis();
    Assert.assertTrue(testFile.length() > 0);
    Assert.assertTrue(testFile.lastModified() <= time);
    file = new HDF5File(testFile, HDF5File.OpenMode.READ_ONLY);
    final double theDouble = file.readDouble("test-group/double-group/my-double");
    Assert.assertTrue(Double.isNaN(theDouble));
    file.close();
}
Also used : HDF5File(org.broadinstitute.hdf5.HDF5File) File(java.io.File) HDF5File(org.broadinstitute.hdf5.HDF5File) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 34 with HDF5File

use of org.broadinstitute.hdf5.HDF5File in project gatk-protected by broadinstitute.

the class HDF5LibraryUnitTest method testReMakeDoubleArray.

@Test()
public void testReMakeDoubleArray() throws IOException {
    final File testFile = File.createTempFile("hdf5", ".hd5");
    HDF5File file = new HDF5File(testFile, HDF5File.OpenMode.CREATE);
    file.makeGroup("test-group/double-group");
    final double[] testValues1 = new double[] { 1.1, -2.2, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 0.0111e10 - 10 };
    final double[] testValues2 = new double[] { 11.1, -22.2, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 1.0111e10 - 10 };
    Assert.assertTrue(file.makeDoubleArray("test-group/double-group/my-double", testValues1));
    System.err.println(testFile);
    file.close();
    final long time = System.currentTimeMillis();
    Assert.assertTrue(testFile.length() > 0);
    Assert.assertTrue(testFile.lastModified() <= time);
    file = new HDF5File(testFile, HDF5File.OpenMode.READ_WRITE);
    final double[] theDoubles1 = file.readDoubleArray("test-group/double-group/my-double");
    Assert.assertEquals(theDoubles1, testValues1.clone());
    Assert.assertFalse(file.makeDoubleArray("test-group/double-group/my-double", testValues2));
    final double[] theDoubles2 = file.readDoubleArray("test-group/double-group/my-double");
    Assert.assertEquals(theDoubles2, testValues2.clone());
    file.close();
}
Also used : HDF5File(org.broadinstitute.hdf5.HDF5File) File(java.io.File) HDF5File(org.broadinstitute.hdf5.HDF5File) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 35 with HDF5File

use of org.broadinstitute.hdf5.HDF5File in project gatk-protected by broadinstitute.

the class HDF5LibraryUnitTest method testIsPresent.

@Test(dependsOnMethods = { "testCreateGroup", "testMakeDouble" })
public void testIsPresent() {
    final File testFile = BaseTest.createTempFile("hdf5", ".hd5");
    final HDF5File file = new HDF5File(testFile, HDF5File.OpenMode.CREATE);
    Assert.assertFalse(file.isPresent("test-group"));
    Assert.assertFalse(file.isPresent("test-group/lola-run"));
    Assert.assertFalse(file.isPresent("test-group/lola-run/bernie-follows"));
    Assert.assertFalse(file.isPresent("test-group/lola-run/jill-follows"));
    file.makeGroup("test-group/lola-run");
    Assert.assertTrue(file.isPresent("test-group"));
    Assert.assertTrue(file.isPresent("test-group/lola-run"));
    Assert.assertFalse(file.isPresent("test-group/lola-run/bernie-follows"));
    Assert.assertFalse(file.isPresent("test-group/lola-run/jill-follows"));
    file.makeDouble("test-group/lola-run/bernie-follows", 0.1);
    Assert.assertTrue(file.isPresent("test-group"));
    Assert.assertTrue(file.isPresent("test-group/lola-run"));
    Assert.assertTrue(file.isPresent("test-group/lola-run/bernie-follows"));
    Assert.assertFalse(file.isPresent("test-group/lola-run/jill-follows"));
    Assert.assertFalse(file.isPresent("test-group/lola-run/bernie-follows/and-so-does-jill"));
    file.close();
    final HDF5File file2 = new HDF5File(testFile, HDF5File.OpenMode.READ_ONLY);
    Assert.assertTrue(file2.isPresent("test-group"));
    Assert.assertTrue(file2.isPresent("test-group/lola-run"));
    Assert.assertTrue(file2.isPresent("test-group/lola-run/bernie-follows"));
    Assert.assertFalse(file2.isPresent("test-group/lola-run/jill-follows"));
    Assert.assertFalse(file2.isPresent("test-group/lola-run/bernie-follows/and-so-does-jill"));
    file2.close();
}
Also used : HDF5File(org.broadinstitute.hdf5.HDF5File) File(java.io.File) HDF5File(org.broadinstitute.hdf5.HDF5File) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

HDF5File (org.broadinstitute.hdf5.HDF5File)82 Test (org.testng.annotations.Test)58 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)56 File (java.io.File)32 Array2DRowRealMatrix (org.apache.commons.math3.linear.Array2DRowRealMatrix)24 RealMatrix (org.apache.commons.math3.linear.RealMatrix)24 HDF5PCACoveragePoN (org.broadinstitute.hellbender.tools.pon.coverage.pca.HDF5PCACoveragePoN)20 BeforeTest (org.testng.annotations.BeforeTest)20 PCACoveragePoN (org.broadinstitute.hellbender.tools.pon.coverage.pca.PCACoveragePoN)16 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)10 HDF5Library (org.broadinstitute.hdf5.HDF5Library)6 UserException (org.broadinstitute.hellbender.exceptions.UserException)6 ArrayList (java.util.ArrayList)4 List (java.util.List)4 OptionalInt (java.util.OptionalInt)4 StandardArgumentDefinitions (org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions)4 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 DoubleStream (java.util.stream.DoubleStream)2 IntStream (java.util.stream.IntStream)2